Recap:对齐问题 对s字节的对象访问地址为A,如果 A mod s=0称为边界对齐。 边界对齐的原因是存储器本身读写的要求,存储器本身读写通常就是边界对 齐的,对于不是边界对齐的对象的访问可能要导致存储器的两次访问,然后 再拼接出所需要的数。(或发生异常) Address mod8 0 2 4 5 6 Byte Aligned Aligned Aligned Aligned Aligned aligned Aligned aligned 2 Bytes Aligned Aligned Aligned Aligned 2 Bytes Misaligned Misaligned Misaligned Misalign 4 Bytes Aligned Aligned 4 Bytes Misaligned Misaligned 4 Bytes Misaligned Misaligned 4 Bytes Misaligned Misalign 8 Bytes Aligned 8 Bytes Misaligned ∠U2I∠
Recap: 对齐问题 • 对s字节的对象访问地址为A,如果A mod s =0 称为边界对齐。 • 边界对齐的原因是存储器本身读写的要求,存储器本身读写通常就是边界对 齐的,对于不是边界对齐的对象的访问可能要导致存储器的两次访问,然后 再拼接出所需要的数。(或发生异常) 2021/2/5 12
Recap:寻址方式 寻址方式:如何说明要访问的对象地址 有效地址:由寻址方式说明的某一存储单元的实际存储器地址。有效地址vs.物理地址 Mode Example Meaning When used Register Add R1 R2 R1←R1+R2 Values in registers Immediate Add R1. 100 R1∈R1+100 For constants Register Indirect Add R1, (R2) ∈R1+Mem(R2) R2 contains address Displacement Id R1, (R2+16) R1 6 R1+ Mem(R2+16) Address local variables Absolute AdR1,(1000)R1←R1+Mem(1000) Address static data Indexed Add R1, (R2+R3) R1 R1+ Mem(R2+R3) R2=base. R3=index Scaled Index Add R1, (R2+s"R3) R1 6 R1+ Mem(R2+ s"R3) s= scale factor 2, 4, or 8 Post-increment Add R1, (R2)+ R1∈R1+Mem(R2) Stepping through array R2R2+s s= element size R2 R2-s Pre-decrement Add R1,(R2) Stepping through array R1∈R1+Mem(R2) s= element size 20212/5 13
Recap: 寻址方式 • 寻址方式:如何说明要访问的对象地址 • 有效地址:由寻址方式说明的某一存储单元的实际存储器地址。有效地址 vs. 物理地址 2021/2/5 13
各种寻址方式的使用情况?(忽略寄存器直接寻址) mory indirect spice Scaled 16% Tex Tex 17% Tex 32% 40% Frequency of the addressing mode 三个SPEc89程序在VAX结构上的测试结果: 立即寻址,偏移寻址使用较多 202125
各种寻址方式的使用情况? (忽略寄存器直接寻址) 2021/2/5 14 三个SPEC89程序在VAX结构上的测试结果: 立即寻址,偏移寻址使用较多
偏移寻址 主要问题:偏移的范围(偏移量的大小) 40% 35%i lnteger average 30% 25% Percentage of 20% displacement Floating-point average 15% 10% 5% 0% 0123456789101112131415 Number of bits of displacement Alpha Architecture with full optimization for Spec CPU2000, showing the average of integer programs (ciNT2000 and the average of floating-point programs (CFP2000) 2021/2/5
偏移寻址 • 主要问题:偏移的范围(偏移量的大小) 2021/2/5 15 Alpha Architecture with full optimization for Spec CPU2000, showing the average of integer programs(CINT2000) and the average of floating-point programs (CFP2000)
立即数寻址 22% 23% d Floating-point average 19% 口 Integer average ALU operations 25% 16% All instructions 21% 0%5%10%15%20%25%30% Alpha Architecture with full optimization for Spec CPU2000, showing the average of integer programs(CINT2000 and the average of floating-point programs(CFP2000) 2021/25 16
立即数寻址 2021/2/5 16 Alpha Architecture with full optimization for Spec CPU2000, showing the average of integer programs(CINT2000) and the average of floating-point programs (CFP2000)