Literal pool

{{Refimprove|date=February 2013}}

In computer science, and specifically in compiler and assembler design, a literal pool is a lookup table used to hold literals during assembly and execution.

Multiple (local) literal pools are typically used only for computer architectures that lack branch instructions for long jumps, or have a set of instructions optimized for shorter jumps. Examples of such architectures include the IBM System/360 and its successors, which had a number of instructions which took 12-bit address offsets. In this case, the compiler would create a literal table on every 4K page; any branches whose target was less than 4K bytes away could be taken immediately; longer branches required an address lookup via the literal table. The entries in the literal pool are placed into the object relocation table during assembly, and are then resolved at link edit time.

The ARM architecture also makes use of multiple local pools,{{cite web | url=https://sourceware.org/binutils/docs/as.html#ARM_002dDependent | title=Using as, section 9.4 (ARM Dependent Features) }} as does AArch64, the 64-bit extension to the original ARM.{{cite web | url=https://sourceware.org/binutils/docs/as.html#AArch64_002dDependent | title= Using as, section 9.1 (AArch64 Dependent Features) }}

Another architecture making use of multiple local pools is C-SKY, a 32-bit architecture designed for embedded SoCs.{{cite web | url=https://sourceware.org/binutils/docs/as.html#C_002dSKY-Options | title=Using as, section 9.10.1 (C-SKY Dependent Features: Options) }}{{cite web | url=https://www.phoronix.com/news/C-SKY-Linux-4.20-Port-Proposed | last1=Larabel | first1=Michael | title=C-SKY 32-Bit CPUs Aim For Initial Support In Linux 4.20~5.0 | url-status=live | access-date=22 August 2022 | archive-url=https://archive.today/20220822155052/https://www.phoronix.com/news/C-SKY-Linux-4.20-Port-Proposed | archive-date=22 August 2022}}

In certain ways, a literal pool resembles a TOC or a global offset table (GOT), except that the implementation is considerably simpler, and there may be multiple literal tables per object.

Perhaps the most common type of literal pool are the literal pools used by the LDR Rd,=const pseudo-instruction in ARM assembly language{{cite web | url=https://developer.arm.com/documentation/dui0473/m/dom1359731147760 | archive-url=https://archive.today/20220819183624/https://developer.arm.com/documentation/dui0473/m/dom1359731147760 | archive-date=19 August 2022 | title=Writing ARM Assembly Language > Literal pools | url-status=live}}{{cite web | url=https://wwwfiles.iar.com/arm/webic/doc/ewarm_assemblerreference.enu.pdf | access-date=22 August 2022 | title=IAR Assembler User Guide for Arm Limited's ARM Cores (AARM-12) | url-status=live | archive-url=https://web.archive.org/web/20220119153024/https://wwwfiles.iar.com/arm/webic/doc/ewarm_assemblerreference.enu.pdf | archive-date=19 January 2022}} {{webarchive | format=addlarchive | url1=https://archive.today/20220822164942/https://wwwfiles.iar.com/arm/webic/doc/ewarm_assemblerreference.enu.pdf | date1=22 August 2022}}

and similar instructions in IBM System/360 assembly language,{{cite web | url=https://www.ibm.com/docs/en/hla-and-tf/1.6?topic=instruction-literal-pool | title=High Level Assembler for z/OS & z/VM & z/VSE V1R6 (HLASM V1R6) Language Reference: Literal pool | website=IBM | archive-url=https://archive.today/20220819163955/https://www.ibm.com/docs/en/hla-and-tf/1.6?topic=instruction-literal-pool | archive-date=19 August 2022 | url-status=live}}

which are compiled to a LOAD with a PC-relative addressing mode and the constant stored in the literal pool.

On the IBM S/390 and zSeries architecture, the GNU assembler, "as" (which is invoked during the gcc build process) will use general-purpose register R13 to store a pointer to the literal pool.{{cite book | url=https://www.redbooks.ibm.com/redbooks/pdfs/sg246807.pdf | archive-url=https://web.archive.org/web/20210722121154/https://www.redbooks.ibm.com/redbooks/pdfs/sg246807.pdf | archive-date=22 July 2021 | url-status=live | title=Linux on IBM zSeries and S/390: Application Development | date=July 2002 | publisher=IBM | series=IBM Redbooks | first1=Gregory | last1=Geiselhart | first2=Andrea | last2=Grahn | first3=Frans | last3=Handoko | first4=Jörg | last4=Hundertmark |first5=Albert | last5=Krzymowski | first6=Eliuth | last6=Pomar}} {{webarchive | format=addlarchive | url1=https://archive.today/20220819181122/https://www.redbooks.ibm.com/redbooks/pdfs/sg246807.pdf | date=19 August 2022}} {{cite web | url=https://sourceware.org/binutils/docs/as.html#s390-Literal-Pool-Entries | title=Using as (section 9.41.3.8) | url-status=live | archive-url=https://archive.today/20220819182636/https://sourceware.org/binutils/docs/as.html%23s390-Literal-Pool-Entries | archive-date=19 August 2022}}

Often some particular constant value will be used multiple times in a program.

Many linkers, by default, store each unique constant once, in a single combined literal pool; that improves code size.

William von Hagen.

[https://books.google.com/books?id=wQ6r3UTivJgC&q=%22literal+pool%22&pg=PA489 "The Definitive Guide to GCC"].

The Java virtual machine has a "string literal pool" and a "class constant pool".

Jacquie Barker.

[https://books.google.com/books?id=BF6HyZSN7EsC&dq=%22literal+pool%22&pg=PA465 "Beginning Java Objects: From Concepts to Code": "literal pool"].

References

{{reflist}}

{{DEFAULTSORT:Literal Pool}}

Category:Compiler construction

{{Prog-lang-stub}}