使用android NDK获取硬件浮点

发布于 2024-09-04 11:17:12 字数 663 浏览 6 评论 0原文

我已经开始使用 android NDK。我刚刚学到的一件事是创建一个 application.mk 文件来指定armv7 abi。

我正在使用以下参数构建 san-angeles 示例。

APP_MODULES      := sanangeles
APP_PROJECT_PATH := $(call my-dir)/../
APP_OPTIM        := release
APP_ABI          := armeabi-v7a

然而,这似乎以与之前完全相同的速度运行(即很糟糕)。我只是 GL 受限而不是 CPU 受限还是这里出了问题?

我注意到,当我编译时,我得到了以下命令行选项:

-march=armv7-a -mfloat-abi=softfp -mfpu=vfp -mthumb 

让我担心的是“softfp”。其中提到了 v7 abi、VFP fpu 的东西,我猜“thumb”指的是“thumb-2”指令(尽管我不知道这些指令到底是什么)。然而,“softfp”确实让我担心。不应该是“hardfp”吗?

有人对这些问题有任何想法吗?我想我可能已经准备好开始为我的 HTC Desire 实现一些 GL ES 2.0 代码,但我想确保我能从中获得尽可能最佳的速度:)

提前干杯!

I've begun playing with the android NDK. One of the things I've just learnt is about creating an application.mk file to specify the armv7 abi.

I'm building the san-angeles example with the following parameters.

APP_MODULES      := sanangeles
APP_PROJECT_PATH := $(call my-dir)/../
APP_OPTIM        := release
APP_ABI          := armeabi-v7a

However this seems to run at exactly the same speed as it did before (ie badly). Am I just GL limited and not CPU limited or is something wrong here?

I have noticed when I compile that I get the following command line options emitted:

-march=armv7-a -mfloat-abi=softfp -mfpu=vfp -mthumb 

The thing that worries me there is the "softfp". There IS mention of the v7 abi, the VFP fpu stuff and I'm guessing the "thumb" refers to the "thumb-2" instructions (Though I don't know what exactly these are). However that "softfp" does concern me. Shouldn't it be "hardfp"?

Anyone got any ideas on these questions? I think I'm probably about ready to start implementing some GL ES 2.0 code for my HTC Desire but I'd like to make sure I'm getting the best possible speed out of it :)

Cheers in advance!

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

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

发布评论

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

评论(1

弱骨蛰伏 2024-09-11 11:17:12

您提供给 NDK 的选项只会影响代码的编译方式。它不会更改 GL 库或平台的其他任何内容,这些库始终以适当的方式生成。如果您只是将几何体扔到 GL 硬件上,您不会看到任何差异。

如果您想查看您的选项是否有效,请下载(或创建)一个简单的基准测试,该基准测试使用双精度浮点值执行一系列操作,并计算前后执行所需的时间。

-mfloat-abi=softp 参数确定浮点值如何在函数之间传递。 softfp 意味着它们总是在整数寄存器或堆栈中传递。如果 Android 未指定 softfp,则该库的 ARMv7-A 版本将期望浮点数显示在硬件寄存器中,并且为 ARMv5TE 构建的任何代码都会中断。

“softfp”给某些函数增加了一点开销,但是将值移入和移出 fp 寄存器的指令在 ARM 上很便宜,并且提供的 ABI 兼容性使其值得。

“-mthumb”可以生成 Thumb/Thumb2 代码。 Thumb 代码往往比同等的 ARM 慢一点,但小一点;有时更小意味着你更适合CPU i-cache并且实际上运行得更快。大小始终是这些设备上需要考虑的问题,因此默认情况下启用 Thumb。

如有疑问,“arm-eabi-objdump -dwhatever.o”将向您显示代码的反汇编。

更新: NDK r9b 添加了对 - 的支持mhard-浮动。这允许您为armeabi-v7a 目标构建具有硬浮动API 约定的NDK 库。

The options you supply to the NDK will only affect the way your code is compiled. It won't change the GL libs or anything else that's part of the platform, which are always generated in an appropriate fashion. If you're just throwing geometry at the GL hardware, you're not going to see a difference.

If you want to see if your options are having an effect, download (or create) a simple benchmark that does a bunch of operations with double-precision floating point values, and time how long it takes to execute before and after.

The -mfloat-abi=softp argument determines how floating-point values are passed between functions. softfp means they're always passed in integer registers or on the stack. If Android didn't specify softfp, the ARMv7-A version of the library would expect floats to show up in hardware registers, and any code built for ARMv5TE would break.

"softfp" adds a little overhead to some functions, but the instructions for moving values in and out of fp registers are cheap on ARM, and the ABI compatibility provided makes it worthwhile.

The "-mthumb" enables generation of Thumb/Thumb2 code. Thumb code tends to be a bit slower but a bit smaller than equivalent ARM; sometimes smaller means you'll fit better in the CPU i-cache and will actually run faster. Size is always a concern on these devices, so Thumb is enabled by default.

When in doubt, "arm-eabi-objdump -d whatever.o" will show you a disassembly of your code.

Update: NDK r9b added support for -mhard-float. This allows you to build NDK libraries with hard-float API conventions for armeabi-v7a targets.

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