Software Optimization Guide for AMD64 Processors

25112 Rev. 3.06 September 2005

10.5Floating-Point Subexpression Elimination

Optimization

Reduce the number of superfluous FXCH instructions by putting the shared source operand at the top of the stack to eliminate subexpressions.

Application

This optimization applies to:

32-bit software

64-bit software

Rationale

There are cases that do not require an FXCH instruction after every instruction to allow access to two new stack entries. In the cases where two instructions share a source operand, an FXCH is not required between the two instructions. When there is an opportunity for subexpression elimination, reduce the number of superfluous FXCH instructions by putting the shared source operand at the top of the stack—for example:

Examples

Listing 29. Avoid

;=====================

;func((x*y),(x+z))

;=====================

fld

x

; x

 

fld

y

; y x

 

fld

x

; x y

x

fld

z

; z x

y x

faddp

st(1), st

; x+z

y x

fxch

st(2)

; x y

x+z

fmulp

st(1), st

; x*y

x+z

Listing 30. Preferred

fld

z

; z

 

fld

y

; y z

 

fld

x

; x y

z

fmul st(1), st

; x x*y z

faddp st(2), st

; x*y

x+z

246

x87 Floating-Point Optimizations

Chapter 10

Page 262
Image 262
AMD 250 manual Floating-Point Subexpression Elimination, 246