简体   繁体   English

C 定点硬件上的浮点型表示

[英]C float type representation on fixed point hardware

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?如果 CPU 没有浮点运算单元(如许多定点 DSP),C 编译器如何处理float类型及其操作?

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?如果变量是fixed point类型,编译器生成的代码会理想地使用定点硬件指令,这是非常有效的,但如果变量是float类型,编译器需要有软件实现,使用定点硬件指令来模拟浮动-指向并执行它?

how does the C compiler handles float types and their operations? C 编译器如何处理浮点类型及其操作?

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 @ 0__________ @史蒂夫·萨米特

Example: software floating-point in the GCC low-level runtime library @Eric Postpischil示例: GCC 低级运行库@Eric Postpischil 中的软件浮点

Even a Turing machine can handle float types and their operations, given enough time and space.如果有足够的时间和空间,即使是图灵机也可以处理浮点类型及其操作。

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. C 中没有定点类型,因此编译器无法生成使用它们的指令。 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.在具有定点类型的 CPU 中,在其 C 实现中,除了标准的charshortlong ... 之外,这些通常是单独的内置类型,程序员需要将变量显式声明为定点。 For example例如

For floating-point types software emulation will be used if there's no FPU available.对于浮点类型,如果没有可用的 FPU,将使用软件仿真。 If the software FPU can utilizes the fixed-point instructions then of course they'll be used under the hood.如果软件 FPU 可以利用定点指令,那么它们当然会在幕后使用。 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有些 CPU 同时具有定点和浮点,只要您使用正确的类型,硬件加速就会用于所有这些


In fact DSPs all have peculiar memory and register configurations for maximizing the data throughput.事实上,DSP 都有特殊的memory 和寄存器配置,以最大化数据吞吐量。 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.在其 C 实现中,这些通常也将是单独的内置类型。 For example check the documentations linked above you can see things like _Sat for saturated types and _Accum for the accumulator.例如,查看上面链接的文档,您可以看到饱和类型的_Accum和累加器的_Sat之类的东西。 In TI DSPs you can usually see __int40_t for accumulators在 TI DSP 中,您通常可以看到用于累加器__int40_t

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您可以在使用 C 编程 DSP 中找到有关非标准类型(包括定点)的编译器实现的更多信息:效率和可移植性权衡

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM