NOTICE: The Processors Wiki will End-of-Life in December of 2020. It is recommended to download any files or other content you may need that are hosted on processors.wiki.ti.com. The site is now set to read only.

C6000 Compiler: Memory Access Intrinsics

From Texas Instruments Wiki
Jump to: navigation, search

Introduction[edit]

This page collects together advice and hints about using intrinsics on the C6000 compiler that directly read or write memory.

Unaligned Intrinsics Do Not Guarantee Unaligned Access[edit]

Problem Description[edit]

The unaligned memory access intrinsics do not require the address supplied be aligned on any certain boundary to work correctly. Examples include _mem2, _mem4, and _mem8. If you do supply the address of an object with an underlying type that is aligned, the compiler may use an aligned memory access instruction. For example ...

<syntaxhighlight lang="c"> int *iptr; // ... _mem4(iptr) = ... // memory store </syntaxhighlight>

The compiler may use STNW (unaligned store word), but it may use STW (aligned store word) instead. That's because aligned memory access instructions are cheaper. An unaligned memory access instruction cannot be in parallel with another memory access instruction. Two aligned memory access instruction can be in parallel. The compiler always seeks to use the cheapest instruction allowed. In this case, since iptr is known to point to int type memory locations, and such memory locations are known to be aligned on 4-byte boundaries, the cheaper STW instruction may be used. Use of a unaligned intrinsic does not override what the compiler knows about the alignment of int.

Conservative Solution[edit]

A conservative solution to this problem imposes no constraints on how the input address is supplied. In particular, such an approach imposes no assumptions about alignment.

Always use pointers of type "char *" or "void *" as the argument to unaligned memory access intrinsics. Such pointers assume nothing about the address alignment. Sometimes, the argument to the memory access intrinsic is developed through some computations. For example ...

<syntaxhighlight lang="c"> void fxn(unsigned int *base_ptr, unsigned int bit_len) {

  char *work_ptr = (char *)base_ptr + bit_len;
  // ...
  _mem4(work_ptr) &= ...
  _mem4(work_ptr) |= ...

} </syntaxhighlight>

Techniques in this example worth noting include:

  • base_ptr is points to int
  • work_ptr is points to char
  • The first computation is to cast base_ptr to char *
  • All further arithmetic to compute work_ptr is done with type char *
E2e.jpg {{
  1. switchcategory:MultiCore=
  • For technical support on MultiCore devices, please post your questions in the C6000 MultiCore Forum
  • For questions related to the BIOS MultiCore SDK (MCSDK), please use the BIOS Forum

Please post only comments related to the article C6000 Compiler: Memory Access Intrinsics here.

Keystone=
  • For technical support on MultiCore devices, please post your questions in the C6000 MultiCore Forum
  • For questions related to the BIOS MultiCore SDK (MCSDK), please use the BIOS Forum

Please post only comments related to the article C6000 Compiler: Memory Access Intrinsics here.

C2000=For technical support on the C2000 please post your questions on The C2000 Forum. Please post only comments about the article C6000 Compiler: Memory Access Intrinsics here. DaVinci=For technical support on DaVincoplease post your questions on The DaVinci Forum. Please post only comments about the article C6000 Compiler: Memory Access Intrinsics here. MSP430=For technical support on MSP430 please post your questions on The MSP430 Forum. Please post only comments about the article C6000 Compiler: Memory Access Intrinsics here. OMAP35x=For technical support on OMAP please post your questions on The OMAP Forum. Please post only comments about the article C6000 Compiler: Memory Access Intrinsics here. OMAPL1=For technical support on OMAP please post your questions on The OMAP Forum. Please post only comments about the article C6000 Compiler: Memory Access Intrinsics here. MAVRK=For technical support on MAVRK please post your questions on The MAVRK Toolbox Forum. Please post only comments about the article C6000 Compiler: Memory Access Intrinsics here. For technical support please post your questions at http://e2e.ti.com. Please post only comments about the article C6000 Compiler: Memory Access Intrinsics here.

}}

Hyperlink blue.png Links

Amplifiers & Linear
Audio
Broadband RF/IF & Digital Radio
Clocks & Timers
Data Converters

DLP & MEMS
High-Reliability
Interface
Logic
Power Management

Processors

Switches & Multiplexers
Temperature Sensors & Control ICs
Wireless Connectivity