4.21 Compiler support for literal pools

Literal pools are areas of constant data in a code section.

No single instruction can generate a 4 byte constant, so the compiler generates code that loads these constants from a literal pool.

In the following example, the compiler generates code that loads the integer constant 0xdeadbeef from a literal pool (marked with ***).

int f(void) {
  return 0xdeadbeef;
}


** Section #1 '.text' (SHT_PROGBITS) [SHF_ALLOC + SHF_EXECINSTR]
    Size   : 12 bytes (alignment 4)
    Address: 0x00000000

    $a
    .text
    f
      0x00000000: e59f0000  .... LDR    r0,[pc,#0] ; [0x8] = 0xdeadbeef
      0x00000004: e12fff1e  ../. BX     lr
    $d
      0x00000008: deadbeef  .... DCD  3735928559            ***

An alternative to using literal pools is to generate the constant in a register with a MOVW/MOVT instruction pair:

** Section #1 '.text' (SHT_PROGBITS) [SHF_ALLOC + SHF_EXECINSTR]
    Size   : 12 bytes (alignment 4)
    Address: 0x00000000

    $a
    .text
    f
      0x00000000: e30b0eef  .... MOV    r0,#0xbeef
      0x00000004: e34d0ead  ..M. MOVT   r0,#0xdead
      0x00000008: e12fff1e  ../. BX     lr

In most cases, generating literal pools improves performance and code size. However, in some specific cases you might prefer to generate code without literal pools.

The following compiler options control literal pools:

  • --integer_literal_pools.
  • --string_literal_pools.
  • --branch_tables.
  • --float_literal_pools.
Non-ConfidentialPDF file icon PDF versionARM DUI0472M
Copyright © 2010-2016 ARM Limited or its affiliates. All rights reserved.