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

为何GCC选用基础memset实现?如何获取AArch64优化版?

如何获取AArch64平台优化版的memset实现?

场景与代码

我在裸机程序中手动调用memset清零4K对齐的内存页(实际使用的是另一种8字节类型,示例中用uint64_t代替):

uint64_t something[512] __attribute__((aligned(4096)));
memset(something, 0x0, 4096);

编译命令

使用的编译命令如下:

%> /path/to/gcc-11.1.0/bin/aarch64-unknown-elf-gcc \
     -O3 \
     -std=gnu99 \
     -nostartfiles \
     --specs=nano.specs \
     -march=armv8.1-a \
     -Wl,--gc-sections \
     -Tlinker_script.lds \
     my_code.c \
     -o my_code.elf

当前问题:链接了逐字节的基础memset实现

反汇编后发现程序链接的是逐字节实现的memset,完全没有用到AArch64的优化指令(比如stp或向量指令):

000000004010399c <memset>:
      s = (char*)aligned_addr;
    }

#endif /* not PREFER_SIZE_OVER_SPEED */

  while (n--)
    4010399c:   d2800003    mov x3, #0x0                    // #0
    401039a0:   eb03005f    cmp x2, x3
    401039a4:   54000041    b.ne    401039ac <memset+0x10>  // b.any
    *s++ = (char) c;

  return m;
}
    401039a8:   d65f03c0    ret
    *s++ = (char) c;
    401039ac:   38236801    strb    w1, [x0, x3]
    401039b0:   91000463    add x3, x3, #0x1
    401039b4:   17fffffb    b   401039a0 <memset+0x4>

已尝试的操作

  • 移除编译命令中的--specs=nano.specs选项,问题依然存在
  • 使用aarch64-unknown-elf-ar x工具从多个库文件(包括/path/to/gcc-11.1.0/newlib-nano/aarch64-unknown-elf/lib/libc.a、libc_nano.a等)中提取libc_a.memset.o,但提取出的文件均为空,没能找到优化的memset实现

需求

我需要获取使用stp或向量指令的AArch64优化版memset实现,请问该如何解决?

内容的提问来源于stack exchange,提问作者Lance E.T. Compte

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.24 17:22:34