为什么SSE/AVX缺乏直接价值的负载?

发布于 2025-01-26 22:07:07 字数 449 浏览 2 评论 0原文

据我所知,SSE/AVX中没有任何指示可以立即加载。一个解决方法是将值加载到普通寄存器和movd,但是编译器似乎认为这比单个标量值即使从内存中加载也要成本高昂。

这使得每次使用通用常数进行操作,例如10x800000000x7ffffffff0x3f800000,这使得需要内存访问。 ,0x3f000000等。好吧,在机器代码中编码这些值的每个值将占用4个字节,但是32位绝对或RIP relalative地址和我相信立即负载比任何形式的内存负载便宜。

我一直以为movs xmm,imm32广播XMM,IMM32很高兴拥有,但是必须有一个理由不做此类说明。为什么设计这种方式?

As far as I know, there is no instruction in SSE/AVX for loading an immediate. One workaround is loading a value to a normal register and movd, but compilers seem to think this is more costly than loading from memory even for a single scalar value.

This makes memory access necessary every time doing an operation with common constants such as 1, 0x80000000, 0x7fffffff, 0x3f800000, 0x3f000000, etc. Well, having these values encoded in the machine code will occupy 4 bytes each, but so does a 32-bit absolute or rip-relative address, and I believe an immediate load is cheaper than any sort of memory load.

I always thought something like movss xmm, imm32 or broadcastss xmm, imm32 would be nice to have, but there must be a reason for not making such instructions. Why was it designed this way?

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文