This preview shows page 1. Sign up to view the full content.
Unformatted text preview: sh to use the result of some computation multiple times. For example, consider the expression x = (a*b)*(-(a*b)+c). For efﬁciency, we would like to compute a*b only once, but our stack instructions do not provide a way to keep a value on the stack once it has been used. With the set of instructions listed in Figure 3.29, we would therefore need to store the intermediate result a+b in some memory location, say t, and retrieve this value for each use. This gives the following code: 1 load c %st(0) 7 neg ¡
µ %st(0) %st(1) 2 load b %st(0) %st(2) %st(1) 8 addp ¡
´ µ· %st(0) 3 load a %st(0) 9 ¡
´ load t ¡ µ· %st(1) %st(0) 4 multp ¡ %st(1) %st(0) 10 multp ¡ ¡ ¡
´ ´ µ· µ %st(0) 5 storep t %st(0) 11 storep x %st(0) load t This approach has the disadvantage of generating additional memory trafﬁc, even though the register stack has sufﬁcient capacity to hold its intermediate results. The IA32 ﬂoating-point unit avoids this inefﬁciency 6 ¡ %st(1) 3.14. *FLOATING-POINT CODE
Instruction flds Ö fldl Ö fldt Ö fildl Ö fld %st( ) Source Format Single double ex...
View Full Document