You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用GNU汇编器编译ARMv8-A NEON指令报错,求排查方案

问题描述

尝试使用GNU汇编器编译AArch64架构的NEON指令,示例代码来自ARM社区的《NEON编程快速参考》,代码如下:

.text

    .align 4

    .global add_float_neon2

    .type add_float_neon2, %function

add_float_neon2:

.L_loop:

    ld1     {v0.4s}, [x1], #16

    ld1     {v1.4s}, [x2], #16

    fadd    v0.4s, v0.4s, v1.4s

    subs x3, x3, #4

    st1  {v0.4s}, [x0], #16

    bgt .L_loop

    ret

执行汇编命令arm-linux-gnueabi-as -march=armv8-a -mfpu=neon test.s时,出现以下错误:

test.s: Assembler messages:
test.s:13: Error: bad instruction `ld1 {v0.4s},[x1],#16'
test.s:15: Error: bad instruction `ld1 {v1.4s},[x2],#16'
test.s:17: Error: bad instruction `fadd v0.4s,v0.4s,v1.4s'
test.s:19: Error: ARM register expected -- `subs x3,x3,#4'
test.s:21: Error: bad instruction `st1 {v0.4s},[x0],#16'
test.s:25: Error: bad instruction `ret'

所有带<Vd>.<T>操作数格式的指令均无法编译,单独编译单条指令也会报错,请问问题出在哪里?

问题原因与解决方法
  • 工具链架构不匹配:你使用的arm-linux-gnueabi-as是针对32位ARM(AArch32)架构的汇编器,而你的代码是64位ARM(AArch64)架构的指令,工具链无法识别64位指令格式,因此报错。
  • 具体解决步骤:
    1. 替换为AArch64专用的汇编器aarch64-linux-gnu-as,这是适配64位ARM架构的GNU汇编器组件。
    2. 调整汇编命令为:aarch64-linux-gnu-as -march=armv8-a -mfpu=neon test.s -o test.o
    3. 若系统未安装该工具链,需先安装对应包,例如在Debian/Ubuntu系统中执行sudo apt install gcc-aarch64-linux-gnu,获取完整的AArch64交叉编译工具链。

内容的提问来源于stack exchange,提问作者susitsm

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.03 16:31:14