返回信息流☆─────────────────────────────────────☆
jokerlee (Jackal The Dire) 于 (Tue Nov 17 19:06:07 2009) 提到:
只知道高级语言都有内存对齐,汇编也有对齐指令,x86 16位2字节对齐,32位4字节对齐,猜测是和寻址有关
但不知道具体原因,MS不同体系结构对内存对齐的要求不一样,x86可以不对齐,但是arm就必须对齐
求高人解答
☆─────────────────────────────────────☆
FadeToBlack (拜萝卜教 | gfw nmb) 于 (Tue Nov 17 21:35:57 2009) 提到:
Data misalignment in the 386
The case of misaligned data has a major effect on the 386 bus performance. If the data is aligned, for every memory read cycle the 80386 brings in 4 bytes of data using the D31~D0 data bus. Such data alignment is refered to as doubleword alignment. To make data doubleword aligned, the least significant digits of the hex address must be 0, 4, 8, or C.
Also, check the spins of 80386:
Data Bus Byte Enable
D7~D0 BE0
D15~D8 BE1
D23~D16 BE2
D31~D24 BE3
如果读入一个没有对齐的双字,那么一条指令需要实际两个CPU周期来执行,这也是为什么有些CPU不支持读入未对齐的数据。
☆─────────────────────────────────────☆
flyingkisser (齐天大猫) 于 (Tue Nov 17 22:06:27 2009) 提到:
到了64位更恶心,intel的cpu部分指令集只支持8字节对齐的内存,否则的话cpu直接
抛异常。
【 在 FadeToBlack (拜萝卜教 | gfw nmb) 的大作中提到: 】
: Data misalignment in the 386
: The case of misaligned data has a major effect on the 386 bus performance. If the data is aligned, for every memory read cycle the 80386 brings in 4 bytes of data using the D31~D0 data bus. Such data alignment is refered to as doubleword alignmen
: Also, check the spins of 80386:
: ...................
☆─────────────────────────────────────☆
dragon2000 (龙之梦工作室) 于 (Tue Nov 17 23:20:12 2009) 提到:
学了计算机组成原理还需要学以致用的。
【 在 jokerlee 的大作中提到: 】
: 只知道高级语言都有内存对齐,汇编也有对齐指令,x86 16位2字节对齐,32位4字节对齐,猜测是和寻址有关
: 但不知道具体原因,MS不同体系结构对内存对齐的要求不一样,x86可以不对齐,但是arm就必须对齐
: 求高人解答
☆─────────────────────────────────────☆
dudu66 (嘟嘟) 于 (Wed Nov 18 14:24:15 2009) 提到:
减少CPU的访存次数
保持存储空间的效率足够高
☆─────────────────────────────────────☆
yihang (Goodluckfly) 于 (Wed Nov 18 16:09:22 2009) 提到:
INTEL 80386 PROGRAMMER'S REFERENCE MANUAL 中对数据对齐的解释
Note that words need not be aligned at even-numbered addresses and doublewords need not be aligned at addresses evenly divisible by four. This allows maximum flexibility in data structures (e.g., records containing mixed byte, word, and doubleword items) and efficiency in memory utilization. When used in a configuration with a 32-bit bus, actual transfers of data between processor and memory take place in units of doublewords beginning at addresses evenly divisible by four; however, the processor converts requests for misaligned words or doublewords into the appropriate sequences of requests acceptable to the memory interface. Such misaligned data transfers reduce performance by requiring extra memory cycles. For maximum performance, data structures (including stacks) should be designed in such a way that, whenever possible, word operands are aligned at even addresses and doubleword operands are aligned at addresses evenly divisible by four.
☆─────────────────────────────────────☆
jmpesp (垃圾|人渣|缅甸果敢第一司令) 于 (Wed Nov 18 21:16:57 2009) 提到:
risc跟cisc规定不太一样。
一般情况下,cisc一般允许不对齐。但risc一般都要求 严格对齐,不然就抛出异常了。
对齐的根本原因 就是 效率。
☆─────────────────────────────────────☆
airb9 (by) 于 (Thu Nov 19 09:28:28 2009) 提到:
能否再详细解释下?谢谢了
本来好像明白,但是仔细一想又不太明白
地址不是2,4,8的整数倍,读出来就需要2条指令了?为什么?
知道地址,要读多少字节,一下出来不就行吗?
【 在 jmpesp 的大作中提到: 】
: risc跟cisc规定不太一样。
: 一般情况下,cisc一般允许不对齐。但risc一般都要求 严格对齐,不然就抛出异常了。
: 对齐的根本原因 就是 效率。
☆─────────────────────────────────────☆
jmpesp (垃圾|人渣|缅甸果敢第一司令) 于 (Thu Nov 19 11:48:02 2009) 提到:
【 在 airb9 的大作中提到: 】
: 能否再详细解释下?谢谢了
: 本来好像明白,但是仔细一想又不太明白
: 地址不是2,4,8的整数倍,读出来就需要2条指令了?为什么?
: ...................
假设 地址线 36位, 一般情况下 最低3位 置0,数据线64位。
那么,不对齐就需要 两次访问内存了
☆─────────────────────────────────────☆
dragon2000 (龙之梦工作室) 于 (Thu Nov 19 21:56:04 2009) 提到:
你的“一下出来”是机器指令级的,底下还有微指令级,指令周期不一样。
【 在 airb9 的大作中提到: 】
: 能否再详细解释下?谢谢了
: 本来好像明白,但是仔细一想又不太明白
: 地址不是2,4,8的整数倍,读出来就需要2条指令了?为什么?
: ...................
这是一条镜像帖。来源:北邮人论坛 / soft-design / #36725同步于 2009/11/30
SoftDesign机器人发帖
[合集] 【求教】内存对齐的实际意义
FadeToBlack
2009/11/30镜像同步0 回复
订阅后,新回复会通过你的通知中心匿名送达。
0 条回复
暂无回复 · 你可以订阅本帖等待新回复。