rentzsch.com: tales from the red shed

PowerPC double Alignment

Notes
Tim Seufert wrote me to point out a fact that slipped under my radar, unmentioned in my Straighten Up and Fly Right: Aligning Your Data for Speed and Correctness paper.

While PowerPCs have hardware support for 4-byte aligned 8-byte doubles, you still pay a performance penalty if you use that support. The penalty is nothing like horrendous penalty for unaligned 8-byte access (2,372% overhead!), but it's still measurable. Indeed, I measured it myself without realizing it:

This is a marked-up version of my paper's "Multiple Byte Access Comparison #2" chart. Note how 8-byte (64-bit) access times are the slightly faster than the 4-byte (32-bit) access times when they're evenly divisible by 8 (annotated by the green rectangles). Then note how the 8-byte access times are slower than the 4-byte access times when not divisible by 8 (the red circles).

Tim also notes that the Mac OS X ABI does not enforce 8-byte aligned doubles, so by default your structs may suffer from unnecessary memory access overhead. Fortunately, you can pass a -malign-natural option to gcc to have it add sufficient padding.

Friday, November 07, 2003
12:02 PM