在 AMD64 上使用 -m32 -mtune=native 进行编译
在 AMD64 机器上使用 -m32 和 -mtune=native 进行编译将使用 32 位指针,从而使用稍小的数据结构,从而获得更密集的缓存包装,这是正确的评估吗?我的应用程序(仍处于设计阶段)不需要超过 1 GB 的内存,因此 32 位地址空间应该没问题。我希望利用位缩小的数据结构来获取缓存中的更多数据,并有可能使用更多寄存器进行整数数学运算。我试图实现的是两全其美,通过 -mtune=native 获得更多寄存器,但通过 -m32 获得更小的指针。额外寄存器的可用性是否会在很大程度上自动处理,或者我是否必须明确处理 sse.我宁愿不。
Is it a correct assessment that compiling with -m32 and -mtune=native on a AMD64 machine will use 32 bits for pointers and hence slightly smaller data structures, and consequently a denser cache packing. My application (it is still in its design stage) will not need more than a GB of memory so a 32 bit address space should be fine. I am hoping to utilize the bit-shrunk data structures for more data in cache, and also the potential to use more registers for integer math. What I am trying to achieve is the best of both worlds, more registers by virtue of -mtune=native, but smaller pointers by -m32. Will the availability of extra registers be taken care of largely automatically or do I have to deal explicitly with sse. I would rather not.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
至少如果我明白你想要什么,我认为编译器不会为你做这项工作。它将生成 32 位或 64 位代码。对于 64 位代码,指针将是 64 位 - 如果您想要 32 位指针,则必须生成 32 位代码(具有相应的限制,例如它将使用哪些寄存器) 。
为了得到你想要的,我很确定你必须自己拆分指针:存储一个(可能是 64 位)基地址,并在数据结构中存储偏移量而不是完整地址。不过,在尝试取消引用之前,您需要自己将基数和偏移量添加在一起。
At least if I understand what you want, I don't think the compiler is going to do the job for you. It'd going to produce either 32-bit or 64-bit code. With 64-bit code, the pointers will be 64 bits -- if you want 32-bit pointers, you're going to have to generate 32-bit code (with its commensurate limitations, such as on what registers it'll use).
To get what you want, I'm pretty sure you'll have to split the pointer up yourself: store a (probably 64-bit) base address, and inside your data structure, store offsets rather than complete addresses. You'll need to add the base and offset together yourself before you attempt to de-reference though.
是的,-m32 应该使用 32 位指针。您可以通过打印 sizeof(int *) 来确认这一点。
然而,64 位应用程序在指令集中有更多可访问的寄存器(而且它们更大) - 因此您可能会得到相反的效果。这取决于应用程序,哪种效果(更大的指针与更多的寄存器)具有更大的影响,通常我建议尝试两者并比较性能。
Yes, -m32 should use 32-bit pointers. You could confirm that by printing sizeof(int *).
However 64bit applications have more registers accessible in the instruction set (in addition to them being larger) - so you might get the opposite effect. It depends on the application which effect (larger pointers vs more registers) has a bigger impact, generally I would suggest trying both and comparing the performance.