Home > other >  C float type representation on fixed point hardware
C float type representation on fixed point hardware

Time:01-15

In case of CPUs that don't have floating-point arithmetic unit (like many of fixed-point DSPs), how does the C compiler handles float types and their operations?

I understand how to convert from floating-point to fixed-point, but the question is about representation of floating-point in fixed-point hardware.

Edit

To clarify question:

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?

CodePudding user response:

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

CodePudding user response:

how does the C compiler handles float types and their operations?

It implements floating point using with a software emulation of float point types and operations - tends to be slow and code intensive. @ 0___________ @Steve Summit

Example: software floating-point in the GCC low-level runtime library @Eric Postpischil

Even a Turing machine can handle float types and their operations, given enough time and space.

  • Related