The C29 has instructions that support the efficient implementation of many standard RTS functions when the -ffast-math compiler option is used. The compiler also supports builtins, or intrinsics, that correspond to these instructions. The F29-SDK provides examples in examples/rtlibs/fastmath/tmu that illustrate the use of these intrinsics. The examples supported are asinf(), acosf(), atan2f(), ceilf(), cosf(), divf(), expf(), floorf(), fmodf(), roundf(), sinf(), and truncf().
- Additionally, the compiler supports sqrtf() and 1/sqrtf() implementation with the ISQRTF instruction. The corresponding intrinsic is shown in the code block below.
float __builtin_c29_i32_isqrtf32_m(float x);
- The intrinsic for IEXP2F is shown in the code block below.
float __builtin_c29_i32_iexp2f32_m(float f0);
Note: Due to accuracy limitations with IEXP2F when the base or exponent are large, the compiler does not support expf(), exp2f(), 1/expf(), or 1/exp2f() implementation through IEXP2F. However, the F29x-SDK contains an example for this in examples/rtlibs/fastmath/tmu/ccs/expf_example, that demonstrates the use of the intrinsic over a range of inputs. The instruction (and intrinsic) are still accurate and useful over a range of base/exponent values.
- The compiler supports logarithm computation through the LOG2F instruction. Additionally, the intrinsic for LOG2F is shown in the code block below. It can be used to implement logf(), log2f(), and also powf().
float __builtin_c29_i32_log2f32_m(float f0);
- atanf() can be implemented with PUATANF, using the intrinsic float __builtin_c29_i32_puatanf32_m(float f0)
Example:
// x is per-unit in [-1,1]
// y is per-unit in [-0.125, 0.125] i.e. [-pi/4, pi/4] radians
y = __builtin_c29_i32_puatanf32_m(x);
- The compiler supports atan2f() computation through the PUATANF and QUADF instructions. Additionally, atan2f() can be implemented using the intrinsics float __builtin_c29_i32_puatanf32_m(float f0) and float __builtin_c29_quadf32(unsigned int * tdm_w_uip0, float * rw_fp1, float * rw_fp2)
Example:
test_output =puatan2f32(y_input,x_input);
static inline float32_t puatan2f32(float32_t y, float32_t x)
{
uint32_t flags;
return __builtin_c29_quadf32(&flags, &y, &x) + __builtin_c29_i32_puatanf32_m(y / x);
}