如何在编译器中启用内在函数? [英] How to enable intrinsics in compiler?

查看:36
本文介绍了如何在编译器中启用内在函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谁能解释一下:如何在c代码中启用内部函数?

Who can explain: how to enable intrinsics in c code?

我想使用 armv5TE中的特殊dsp指令

考虑 qadd 指令,当我使用汇编方法时它可以很好地工作,如下所示:

Consider qadd instruction, it nicely works when i use assembler approach, like this:

inline int function_qadd(int a, int b) {
    __asm__ (
            "qadd %0, %1, %2" : "=r" (a) : "r" (a), "r" (b));
    return a;
}

但是当我尝试使用 __qadd内在而不是像这样的asm:

But when i tried to use __qadd intrinsic instead of asm like this:

int add_result = __qadd(5,10);
LOGI("qadd='%d'", add_result);

我有错误:

错误:对__qadd"的未定义引用

error: undefined reference to '__qadd'

我做错了什么,如何在 c 代码中启用内部函数?

更新:

我有 ndk android-ndk-r8c(windows 版本),它 默认使用 GCC 4.6:

I have ndk android-ndk-r8c (windows version), it have GCC 4.6 as default:

GCC 4.6 编译器仍然是默认的,

The GCC 4.6 compiler is still the default,

除了我在 android.mk 中明确指定

Besides i explicitly specify in android.mk

NDK_TOOLCHAIN_VERSION=4.6

我的编译器标志是:

LOCAL_CFLAGS += -std=c99 -ffast-math -march=armv5te -mfpu=vfp -mfloat-abi=softfp 

除了我通过 -S 编译器标志检查 gcc 生成的 asm 代码之外,它还生成了 qadd 指令:

Besides i check the asm code generated by gcc throught -S compiler flag, it generate qadd instruction:

qadd r3, r3, r2

推荐答案

内部函数 __qadd 不适用于 GCC 编译器.您提供的文档链接适用于(非免费)armcc 编译器.

The intrinsic function __qadd is not available for the GCC compiler. The link to the documentation you've provided is for the (non-free) armcc compiler.

如果您使用 GCC,则使用汇编器方法是使用 qadd 指令的唯一实用方法.

Using the assembler approach is the only practical way to use the qadd instruction if you're using GCC.

这篇关于如何在编译器中启用内在函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆