机code对齐 [英] Machine code alignment

查看:159
本文介绍了机code对齐的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想了解机器code对齐的原则。我有一个汇编实现,它可以生成运行时间机器code。我使用的每一个分支目标的16字节对齐,但看起来是不是最佳的选择,因为我发现,如果我删除比对齐有时同一code工作得更快。我认为这是与高速缓存行的宽度,使一些命令是因为这样一个高速缓存行和CPU经验摊位切割。因此,如果调整​​的一些字节在一个地方插入,将移动指令还通过地方高速缓存的边界线......

I am trying to understand the principles of machine code alignment. I have an assembler implementation which can generate machine code in run-time. I use 16-bytes alignment on every branch destination, but looks like it is not the optimal choice, since I've noticed that if I remove alignment than sometimes same code works faster. I think that something to do with cache line width, so that some commands are cut by a cache line and CPU experiences stalls because of that. So if some bytes of alignment inserted at one place, it will move instructions somewhere further pass the cache border line...

我希望实现自动对准过程,该过程可以处理一个code作为一个整体,根据CPU的规格(高速缓存线的宽度,32/64位等)插入对准...

I was hoping to implement an automatic alignment procedure, which can process a code as a whole and insert alignment according to the specification of the CPU (cache line width, 32/64 bits and so on)...

能有人给有关这一过程的一些提示?作为一个例子,目标CPU可能是英特尔酷睿i7 CPU的64位平台。

Can someone give some hints about this procedure? As an example the target CPU could be Intel Core i7 CPU 64-bit platform.

感谢您。

推荐答案

段落(16字节)对齐通常是最好的。但是,它可以迫使一些局部JMP指令,不再是本地的(由于code尺寸膨胀)。也可能导致没有那么多code被缓存。我只对准code的主要部分,我不会对准每一个微小的子程序/ JMP部分。

Paragraph (16-byte) alignment is usually the best. However, it can force some "local" JMP instructions to no longer be local (due to code size bloat). May also result in not as much code being cached. I would only align major segments of code, I would not align every tiny subroutine/JMP section.

这篇关于机code对齐的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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