Memory Models#

The XCore C/C++ compiler provides memory models to handle:

  • different total sizes of statically allocated application data on any one tile

  • different maximum ranges of jumps and sizes of loops

  • using different memories (internal, external, software-defined).

Memory model is specified per source file (translation unit). It controls the machine code generated from that source file for accessing data and calling functions. Usually all source files of an application will be compiled under the same model.

Small (default)#

xcc test.c ...
xcc test.c -mcmodel=small ...

Machine code is generated assuming that both:

  1. All static data on a tile fits within a contiguous 256KB area.

  2. The maximum range of a branch is 128KB (single-issue) or 256KB (dual-issue).

If either turns out to be untrue, the linker issues an error. The small model generates more efficient machine code than the other models.

Large#

xcc test.c -mcmodel=large ...

Data need not fit within contiguous 256KB. Different data may reside in different memories, for example internal RAM, external DDR, and software-defined memory. Functions anywhere in memory may be called. Compared with the small model, the large model generates less efficient machine code to access data and to call functions, so use the default model when possible.

Hybrid#

xcc test.c -mcmodel=hybrid ...

If the compiler considers it safe to use small-model data access in a particular case, efficient small-model code is generated for that case. Otherwise large-model access is used. Large-model function calls are generated in code. So the hybrid model allows an application to combine efficient access to a contiguous data area (usually in internal RAM) with access to other memories, such as external memory. However, the cases suitable for small-model data access are limited. For example, C extern variables will be accessed with less efficient large-model code. So use the default model when possible.

Indirect access to memory#

The data access described above is direct access to a data object by name. An application will link under the small memory model only if direct accesses to code and data meet the contiguous size conditions. But indirect addressing will always work. For example, in C, a pointer could be obtained to an object anywhere in memory, and used in code compiled under the small model. See example.