2.9. Built-In Functions and Intrinsics

The C29x compiler has many intrinsic functions (also called “built-in functions”) that provide built-in access from C/C++ to assembly instructions or sequences of instructions. All intrinsic functions begin with the prefix __builtin_c29_.

For a list of builtin intrinsics supported by the cl2000 compiler, see the C2000 C29x CPU and Instruction Set User’s Guide (SPRUIY2), which is available through your TI Field Application Engineer.

Note that you can use the __has_builtin function-like preprocessor macro to test for the existence of a built-in function. This, and other preprocessor macros are extensions provided by Clang. It evaluates to 1 if the function is supported or 0 if not. It can be used like this:

#if __has_builtin(__builtin_c29_fast_strlen)
    mystrlen __builtin_c29_fast_strlen( mystr );
#else
    abort();
#endif

See the Clang Language Extensions section of the Clang documentation for details and additional macros and extensions.

2.9.1. Interrupt Control Intrinsics

Table 2.1 Interrupt Control Intrinsics

Intrinsic syntax

Description

unsigned int __builtin_c29_disable_INT()

Disable INT interrupts

unsigned int __builtin_c29_enable_INT()

Enable INT interrupts

void __builtin_c29_restore_INT(
unsigned int ui0 )

Restore previous INT interrupt enable/disable setting as stored in ui0

void __builtin_c29_atomic_enter()

Interrupts are blocked until ATOMIC counter reaches 0 or ATOMIC_END
instruction is executed. NMI interrupts are not blocked.

void __builtin_c29_atomic_mem_enter()

Interrupts are blocked until ATOMIC counter reaches 0 or ATOMIC_END
instruction is executed. NMI interrupts not blocked. Generate side
band strobes to indicate that this is a window of mutually exclusive
(MUTEX) memory operations.

void __builtin_c29_atomic_leave()

Clears ATOMIC counter set by __builtin_c29_atomic_enter()
or __builtin_c29_atomic_mem_enter(.)

2.9.2. String and Memory Intrinsics

Table 2.2 String and Memory Intrinsics

Intrinsic syntax

Description

void __builtin_c29_fast_memcpy(
void *dest,
const void * src,
size_t numBytes )
Optimized instruction sequence for memcpy() function. This has the
same signature as its associated C library function.
int __builtin_c29_fast_strcmp(
const char* str1,
const char* str2 )
Optimized instruction sequence for strcmp() function. This has the
same signature as its associated C library function. It requires
4 bytes of post-padding.
size_t __builtin_c29_fast_strlen(
const char* str )
Optimized instruction sequence for strlen() function. This has the
same signature as its associated C library function. It requires
up to 60 bytes of post-padding.

2.9.3. Arithmetic Intrinsics

The C2000 C29x CPU and Instruction Set User’s Guide (SPRUIY2), which is available through your TI Field Application Engineer, describes the arithmetic instructions available for C29 processors. For each instruction that has a corresponding intrinsic function that can be called from C/C++, the syntax is provided. The arithmetic intrinsics include intrinsics to perform:

  • Integer addition, subtraction, multiplication, and division

  • Absolute and negative value operations

  • Integer comparisons

  • Increment/decrement operations

  • Logarithmic operations

  • Trigonometric operations

  • Square root and inverse power operations

  • Bit counting and searching

  • Bitwise AND, ANDOR, OR, and XOR operations

  • Left and right shifts

  • Cyclic Redundancy Checks (CRC)

Separate versions of the intrinsics operate on various registers and datatypes and/or perform variants such as signed or unsigned integer saturation.

For division operations, the following intrinsics return the quotient and remainder in *quot* and *rem. These functions fall into the following variant categories:

  • Unsigned division: div

  • Traditional (truncated) signed division: tdiv

  • Euclidean signed division: ediv

  • Modulo (floored) signed division: mdiv

void __builtin_c29_div_u32_u32(unsigned *quot, unsigned *rem, unsigned a, unsigned b)
void __builtin_c29_div_u64_u32(unsigned long long *quot, unsigned *rem,
                               unsigned long long a, unsigned b)
void __builtin_c29_div_u64_u64(unsigned long long *quot, unsigned long long *rem,
                               unsigned long long a, unsigned long long b)

void __builtin_c29_tdiv_s32_u32(int *quot, int *rem, int a, unsigned b)
void __builtin_c29_tdiv_s32_s32(int *quot, int *rem, int a, int b)
void __builtin_c29_tdiv_s64_u32(long long *quot, int *rem, long long a, unsigned b)
void __builtin_c29_tdiv_s64_s32(long long *quot, int *rem, long long a, int b)
void __builtin_c29_tdiv_s64_s64(long long *quot, long long *rem, long long a, long long b)

void __builtin_c29_ediv_s64_s32(long long *quot, int *rem, long long a, int b)
void __builtin_c29_ediv_s32_s32(int *quot, int *rem, int a, int b)
void __builtin_c29_ediv_s64_s64(long long *quot, long long *rem, long long a, long long b)

void __builtin_c29_mdiv_s64_s32(long long *quot, int *rem, long long a, int b)
void __builtin_c29_mdiv_s32_s32(int *quot, int *rem, int a, int b)
void __builtin_c29_mdiv_s64_s64(long long *quot, long long *rem, long long a, long long b)

2.9.4. Floating-Point Arithmetic Intrinsics

The C2000 C29x CPU and Instruction Set User’s Guide (SPRUIY2), which is available through your TI Field Application Engineer, describes the floating-point arithmetic instructions available for C29 processors. For each instruction that has a corresponding intrinsic function that can be called from C/C++, the syntax is provided. The floating-point arithmetic intrinsics provided include intrinsics to perform:

  • Floating-point addition, subtraction, and multiplication

  • Floating-point comparisons

  • Absolute value and negation operations

  • Fractional portion extraction

Note

The following intrinsics expand to a sequence of instructions. This is in contrast to other intrinsics listed on this page, which generally correspond to a single instruction. The purpose of the following two intrinsics is to perform more accurate floating point division than the provided floating point division instructions, such as DIVF32.

The following intrinsics return the quotient of the floating point division a/b.

float __builtin_c29_div_f32(float a, float b)

double __builtin_c29_div_f64(double a, double b)

2.9.5. Conversion Intrinsics

The C2000 C29x CPU and Instruction Set User’s Guide (SPRUIY2), which is available through your TI Field Application Engineer, describes the conversion instructions available for C29 processors. For each instruction that has a corresponding intrinsic that can be called from C/C++, the syntax is provided. The conversion intrinsics provided include intrinsics to perform:

  • Convert between 16-bit signed integer and 32-bit float formats

  • Convert between 16-bit unsigned integer and 32-bit float formats

2.9.6. Co-Processor Interface (CPI) Intrinsics

The C2000 C29x CPU and Instruction Set User’s Guide (SPRUIY2), which is available through your TI Field Application Engineer, describes the CPI instructions available for C29 processors. For each instruction that has a corresponding intrinsic function that can be called from C/C++, the syntax is provided. The CPI intrinsics provided include intrinsics to perform:

  • Copy values between registers on the CPU to registers on the CPI Interface port (CIDy)

  • Generate a tag value to be used for data logging.

2.9.7. Other Control Flow Intrinsics

The C2000 C29x CPU and Instruction Set User’s Guide (SPRUIY2), which is available through your TI Field Application Engineer, describes the control flow instructions available for C29 processors. For each instruction that has a corresponding intrinsic function that can be called from C/C++, the syntax is provided. The control flow intrinsics provided include intrinsics to perform:

  • Copy and conditional copy from register to register

  • Test a bit position in a register

  • Perform integer comparison; set flags based on results

  • Perform floating-point comparison; set flags based on results

2.9.8. Load, Store, and Move Intrinsics

The C2000 C29x CPU and Instruction Set User’s Guide (SPRUIY2), which is available through your TI Field Application Engineer, describes the load, store, and move instructions available for C29 processors. For each instruction that has a corresponding intrinsic function that can be called from C/C++, the syntax is provided. The load, store, and move intrinsics provided include intrinsics to perform:

  • Load from memory location

  • Store to memory location

  • Copy from memory location to memory location/register

  • Modify memory location

  • Add to memory location and load

  • Subtract from memory location and load

  • Sign extension

  • Zero extension

  • Swap bit(s)

  • Swap byte

  • Split register

  • Zero masking