If variables are of fixed point type, compiler generated code will ideally utilize fixed point hardware instructions for it which is very efficient, but if variables are of float type, compiler needs to have software implementation which uses fixed point hardware instructions to simulate floating point and execute it?
Not quite. There's no fixed-point types in C so compilers can't generate instructions to use them. In CPUs with fixed-point types those will typically be separate built-in types beside the standard char
, short
, long
... in their C implementations and programmers need to explicitly declare the variables as fixed-point. For example
For floating-point types software emulation will be used if there's no FPU available. If the software FPU can utilizes the fixed-point instructions then of course they'll be used under the hood. Some CPUs have both fixed-point and floating-point and hardware acceleration will be used for all of them as long as you're using the correct type
In fact DSPs all have peculiar memory and register configurations for maximizing the data throughput. They very frequently have special registers like longer accumulators or saturated types. Those will also commonly be separate built-in types in their C implementations. For example check the documentations linked above you can see things like _Sat
for saturated types and _Accum
for the accumulator. In TI DSPs you can usually see __int40_t
for accumulators
You can find more information about compiler implementations for non-standard types including fixed-point in Programming DSPs using C: efficiency and portability trade-offs