用于嵌入式应用的浮点库

发布于 2024-08-20 00:46:39 字数 359 浏览 6 评论 0原文

我正在为 Cortex-M3 开发程序。它没有浮点协处理器。标准 C 库可以模拟浮点运算,但由于其大小,我不使用它。

有没有好的、免费的 C 库,可以模拟浮点运算,针对 ARM 处理器? 目前,当我使用浮点运算符时,我遇到这样的链接错误:

undefined reference to `__adddf3'
undefined reference to `__subdf3'
undefined reference to `__divdf3'
undefined reference to `__extendsfdf2'
undefined reference to `__muldf3'

所以这样的库可能应该实现它们。

I'm developing program for Cortex-M3. It doesn't have floating point coprocessor. Standard C library can emulate floating point operations, but I don't use it due to its size.

Is there any good and free c library, which can emulate floating point arithmetics, targeted on ARM processors?
Currently, when I use floating point operators I have such linkage errors:

undefined reference to `__adddf3'
undefined reference to `__subdf3'
undefined reference to `__divdf3'
undefined reference to `__extendsfdf2'
undefined reference to `__muldf3'

So probably such library should implement them.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

天荒地未老 2024-08-27 00:46:39

使用定点不是会更好(性能和尺寸方面)吗?对于简单的算术,直接实现或使用函数接口实现都很简单。如果您可以直接使用 C++,那么使用运算符重载可以使fixed 的使用几乎无缝(与 C 函数接口相比,没有运行时开销)。

如果您有更复杂的要求(三角函数、根等),这个博士提供了一个很好的定点库。多布的文章

Would you not be better off (performance and size wise) using fixed point? For simple arithmetic, this is trivial to implement either directly or with a function interface. If you could bare to use C++, using operator overloading could make the use of fixed almost seamless (at no runtime overhead compared to a C function interface).

If you have more complex requirements (trig, roots etc), a good fixed-point library is presented in this Dr. Dobb's Article.

韶华倾负 2024-08-27 00:46:39

如果您想使用内置运算符执行浮点算术,那么您需要提供编译器期望的库例程,因此您最终得到的内容可能与编译器附带的库一样大。

您可能拥有编译器浮动支持例程的源代码,因此如果您想查看它们以了解是否可以改进它们,这可能是您最好的机会。如果您认为无论出于何种原因这都不起作用,您应该与您的编译器供应商讨论编译器对浮动支持例程的要求以及替换供应商库的最佳方法。

如果您想规避编译器的要求,您可能需要避免使用内置运算符并使用显式函数调用执行算术运算。我没有使用第三方浮点库例程的经验,因此不幸的是我无法向您指出可能的好的替代方案。

If you want to perform your floating arithmetic using built in operators, then you'll need to provide the library routines that the compiler expects, so you'd end up with something that's likely to be as large as the library that came with the compiler.

You likely have the source code to the compiler's floating support routines, so if you want to look at them to see if you can improve them that's probably your best chance. If you don't think that'll work for whatever reason, you should talk to your compiler vendor about the requirements the compiler expects of the floating support routines and the best way to replace the vendor's library.

If you want to circumvent the compiler's requirements, you'll probably need to avoid using the built in operators and perform you arithmetic using explicit function calls. I have no experience with 3rd party floating point library routines, so unfortunately I can't point you to an possible good alternatives.

一个人的旅程 2024-08-27 00:46:39

这些应该在编译器的运行时支持库中定义。这些名称看起来像 libgcc 中的浮点函数( gcc),这是相当小的。您应该能够通过适当设置链接标志来引入这些函数。

Those should be defined in the runtime support library for your compiler. Those names look like the floating-point functions from libgcc (the support library for gcc), which is pretty small. You should be able to pull in those functions by setting your link flags appropriately.

扬花落满肩 2024-08-27 00:46:39

也许 newlib 在这里会有用?设置工具链可能很痛苦,但与 gcc 及其标准库相比,我已经成功地减少了嵌入式闪存的使用。

Perhaps newlib would be useful here? It can be a pain to set up the toolchain, but I've had success in reducing embedded flash usage versus gcc and its standard library.

久夏青 2024-08-27 00:46:39

任何有价值的静态链接器都会删除未使用的调用。对于嵌入式编译器来说尤其如此。

Any static linker worth its salt is going to remove unused calls. This is particularly true for embedded compilers.

淡写薰衣草的香 2024-08-27 00:46:39

gcc 具有所有这些功能,您可以使用 gcc build voodoo (multilib、thumb、thumb2 和 soft float)来自动显示它。我几年前就放弃了,只是从 gcc 源中获取文件,将它们修剪为干净的源,然后将它们构建到我的项目中。几年前,我们关注一两个商业编译器,然后关注 newlib 和 gcc,至少在当时它们都使用几乎相同的数学库。我想说的是来自 Sun 的。

gcc has all of those functions, there is gcc build voodoo (multilib, thumb, thumb2, and soft float) you can use to have that automatically have it show up. I have years ago given up and just go grab the files from the gcc sources trim them to a clean source and just build them into my projects. Years ago looking at a commercial compiler or two then looking at newlib and gcc, at least at the time they were all using pretty much the same math library. I want to say it was from Sun.

三月梨花 2024-08-27 00:46:39

假设您使用 gcc 尝试使用 -static-libgcc 标志进行编译并检查最终的二进制大小。我不知道链接器是否会优化未使用的调用,但我认为它会的。

Assuming your using gcc try compiling with the -static-libgcc flag and checking the final binary size. I don't know if the linker will optimize out the unused calls but I think it will.

信仰 2024-08-27 00:46:39

以下所有消息都代表一些算术运算
__adddf3' 的未定义引用
对 __subdf3' 的未定义引用
__divdf3' 的未定义引用
对 __extendsfdf2' 的未定义引用
对“__muldf3”的未定义引用

因此,如果您在两种不同的数据类型中进行一些艺术操作,则在链接时编译器将给出链接错误。例如:
浮动x;
浮动y;

y = x * 0.45;

因此,如果您在链接时编译此代码,它将给您以下消息
对“__muldf3”的未定义引用

要解决此问题,请显式指定“0.45”以浮动
y = x * 0.45F;

大多数情况下,当您使用 c++ 编译器编译 c 文件时,会出现这种类型的链接错误。

All the below message represent some arithmetic operation
undefined reference to __adddf3'
undefined reference to
__subdf3'
undefined reference to __divdf3'
undefined reference to
__extendsfdf2'
undefined reference to `__muldf3'

So while linking compiler will give linking error if you are doing some arthamatic operation in two different data type. For example:
Float x;
float y;

y = x * 0.45;

So if you compile this code while linking it will give you below message
undefined reference to `__muldf3'

To resolve this specify the "0.45" explicitly to float
y = x * 0.45F;

Most of the time this type of linking error comes when you are using c++ compiler to compile c file.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文