Example 2-14, Example 2-15, Example 2-13 – Intel ARCHITECTURE IA-32 User Manual

Page 108

Advertising
background image

IA-32 Intel® Architecture Optimization

2-36

Example 2-14 illustrates a stalled store-forwarding situation that may
appear in compiler generated code. Sometimes a compiler generates
code similar to that shown in Example 2-14 to handle spilled byte to the
stack and convert the byte to an integer value.

Example 2-15 offers two alternatives to avoid the non-forwarding
situation shown in Example 2-14.

Example 2-13 A Non-forwarding Example of Large Load After Small Store

mov [EBP], ‘a’

mov [EBP + 1], ‘b’

mov [EBP + 2], ‘c’

mov [EBP + 3], ‘d’

mov EAX, [EBP]

; blocked

; The first 4 small store can be consolidated into

; a single DWORD store to prevent this non-forwarding

; situation

Example 2-14 A Non-forwarding Situation in Compiler Generated Code

mov DWORD PTR [esp+10h], 00000000h

mov BYTE PTR [esp+10h], bl

mov eax, DWORD PTR [esp+10h] ; Stall

and eax, 0xff

; converting back to byte value

Example 2-15 Two Examples to Avoid the Non-forwarding Situation in

Example 2-14

;A. Use movz instruction to avoid large load after small

; store, when spills are ignored

movz eax, bl

; Replaces the last three instructions

; in Example 2-12

;B. Use movz instruction and handle spills to the stack

mov DWORD PTR [esp+10h], 00000000h

mov BYTE PTR [esp+10h], bl

movz eax, BYTE PTR [esp+10h] ; not blocked

Advertising