小辉程序员之路, since 1996 http://www.xiaohui.com
乐走天涯: 工作并快乐着,职业并休闲着
 » 首页 > MMX 优化: How to optimize for the Pentium family of microprocessors

6. Alignmen


http://www.XiaoHui.com 日期: 2000-04-01 13:00

6. Alignment

All data in RAM should be aligned to addresses divisible by 2, 4, 8, or 16 according to this scheme:
alignment
operand size PPlain and PMMX PPro, PII and PIII
1 (byte) 11
2 (word) 22
4 (dword) 44
6 (fword) 48
8 (qword) 88
10 (tbyte) 816
16 (oword) n.a.16

On PPlain and PMMX, misaligned data will take at least 3 clock cycles extra to access if a 4 byte boundary is crossed. The penalty is higher when a cache line boundary is crossed.

On PPro, PII and PIII, misaligned data will cost you 6-12 clocks extra when a cache line boundary is crossed. Misaligned operands smaller than 16 bytes that do not cross a 32 byte boundary give no penalty.

Aligning data by 8 or 16 on a dword size stack may be a problem. A common method is to set up an aligned frame pointer. A function with aligned local data may look like this:

_FuncWithAlign PROC NEAR PUSH EBP ; prolog code MOV EBP, ESP AND EBP, -8 ; align frame pointer by 8 FLD DWORD PTR [ESP+8] ; function parameter SUB ESP, LocalSpace + 4 ; allocate local space FSTP QWORD PTR [EBP-LocalSpace] ; store something in aligned space ... ADD ESP, LocalSpace + 4 ; epilog code. restore ESP POP EBP ; (AGI stall on PPlain/PMMX) RET _FuncWithAlign ENDP

While aligning data is always important, aligning code is not necessary on the PPlain and PMMX. Principles for aligning code on PPro, PII and PIII are explained in chapter 15.

Tags: MMX 优化



 文章评论

目前没有任何评论.

↓ 快抢占第1楼,发表你的评论和意见 ↓
 
发表你的评论
如果你想针对此文发表评论, 请填写下列表单:
姓名: * 必填
E-mail: 可选 (不会被公开)
反垃圾广告: 为了防止广告机器人自动发贴, 请计算下列表达式的值:
10 + 12 = * 必填
评论内容:
* 必填
你可以使用下列标签修饰文字:
[b] 文字 [/b]: 加粗文字
[quote] 文字 [/quote]: 引用文字

 

小辉程序员之路 建站于 1997 ◇ 做一名最好的开发者是我不变的理想……
Copyright(C) 1997-2009 XiaoHui.com   All rights reserved
声明:站内所有原创文字,未经许可,均可转载、复制。
转载时必须以链接形式注明作者和原始出处