Permalink
Browse files

cpu.x86.assembler: drop useless ST0 operand from some x87 instructions

  • Loading branch information...
1 parent f6430de commit d05bb6e5d7ce6ba3b9b3377c555cb6c26ce34867 Slava Pestov committed May 18, 2010
View
6 basis/cpu/x86/assembler/assembler-tests.factor
@@ -218,9 +218,9 @@ cell 4 = [
[ { HEX: DC HEX: C5 } ] [ [ ST5 ST0 FADD ] { } make ] unit-test
[ { HEX: D8 HEX: 00 } ] [ [ ST0 EAX [] FADD ] { } make ] unit-test
-[ { HEX: D9 HEX: C2 } ] [ [ ST0 ST2 FLD ] { } make ] unit-test
-[ { HEX: DD HEX: D2 } ] [ [ ST2 ST0 FST ] { } make ] unit-test
-[ { HEX: DD HEX: DA } ] [ [ ST2 ST0 FSTP ] { } make ] unit-test
+[ { HEX: D9 HEX: C2 } ] [ [ ST2 FLD ] { } make ] unit-test
+[ { HEX: DD HEX: D2 } ] [ [ ST2 FST ] { } make ] unit-test
+[ { HEX: DD HEX: DA } ] [ [ ST2 FSTP ] { } make ] unit-test
[ { 15 183 195 } ] [ [ EAX BX MOVZX ] { } make ] unit-test
View
34 basis/cpu/x86/assembler/assembler.factor
@@ -455,8 +455,8 @@ ERROR: bad-x87-operands ;
3 shift bitor
operand reg-code bitor , ;
-:: x87-st0-op ( dst src opcode reg -- )
- dst ST0 = src register? and
+:: x87-st0-op ( src opcode reg -- )
+ src register?
[ src opcode reg (x87-op) ]
[ bad-x87-operands ] if ;
@@ -481,17 +481,17 @@ PRIVATE>
: FADD ( dst src -- ) HEX: D8 0 x87-m-st0/n-op ;
: FCHS ( -- ) { HEX: D9 HEX: E0 } % ;
-: FCMOVB ( dst src -- ) HEX: DA 0 x87-st0-op ;
-: FCMOVE ( dst src -- ) HEX: DA 1 x87-st0-op ;
-: FCMOVBE ( dst src -- ) HEX: DA 2 x87-st0-op ;
-: FCMOVU ( dst src -- ) HEX: DA 3 x87-st0-op ;
-: FCMOVNB ( dst src -- ) HEX: DB 0 x87-st0-op ;
-: FCMOVNE ( dst src -- ) HEX: DB 1 x87-st0-op ;
-: FCMOVNBE ( dst src -- ) HEX: DB 2 x87-st0-op ;
-: FCMOVNU ( dst src -- ) HEX: DB 3 x87-st0-op ;
-
-: FCOMI ( a b -- ) HEX: DB 6 x87-st0-op ;
-: FUCOMI ( a b -- ) HEX: DB 5 x87-st0-op ;
+: FCMOVB ( src -- ) HEX: DA 0 x87-st0-op ;
+: FCMOVE ( src -- ) HEX: DA 1 x87-st0-op ;
+: FCMOVBE ( src -- ) HEX: DA 2 x87-st0-op ;
+: FCMOVU ( src -- ) HEX: DA 3 x87-st0-op ;
+: FCMOVNB ( src -- ) HEX: DB 0 x87-st0-op ;
+: FCMOVNE ( src -- ) HEX: DB 1 x87-st0-op ;
+: FCMOVNBE ( src -- ) HEX: DB 2 x87-st0-op ;
+: FCMOVNU ( src -- ) HEX: DB 3 x87-st0-op ;
+
+: FCOMI ( src -- ) HEX: DB 6 x87-st0-op ;
+: FUCOMI ( src -- ) HEX: DB 5 x87-st0-op ;
: FCOS ( -- ) { HEX: D9 HEX: FF } % ;
: FDECSTP ( -- ) { HEX: D9 HEX: F6 } % ;
: FINCSTP ( -- ) { HEX: D9 HEX: F7 } % ;
@@ -505,7 +505,7 @@ PRIVATE>
: FISTTPD ( dst -- ) { BIN: 001 f HEX: DB } 1-operand ;
: FISTTPQ ( dst -- ) { BIN: 001 f HEX: DF } 1-operand ;
-: FLD ( dst src -- ) HEX: D9 0 x87-st0-op ;
+: FLD ( src -- ) HEX: D9 0 x87-st0-op ;
: FLD1 ( -- ) { HEX: D9 HEX: E8 } % ;
: FLDL2T ( -- ) { HEX: D9 HEX: E9 } % ;
: FLDL2E ( -- ) { HEX: D9 HEX: EA } % ;
@@ -528,11 +528,11 @@ PRIVATE>
: FSUB ( dst src -- ) HEX: D8 HEX: 4 x87-m-st0/n-op ;
: FSUBR ( dst src -- ) HEX: D8 HEX: 5 x87-m-st0/n-op ;
-: FST ( dst src -- ) swap HEX: DD 2 x87-st0-op ;
-: FSTP ( dst src -- ) swap HEX: DD 3 x87-st0-op ;
+: FST ( src -- ) HEX: DD 2 x87-st0-op ;
+: FSTP ( src -- ) HEX: DD 3 x87-st0-op ;
: FXAM ( -- ) { HEX: D9 HEX: E5 } % ;
-: FXCH ( dst src -- ) HEX: D9 1 x87-st0-op ;
+: FXCH ( src -- ) HEX: D9 1 x87-st0-op ;
: FXTRACT ( -- ) { HEX: D9 HEX: F4 } % ;
: FYL2X ( -- ) { HEX: D9 HEX: F1 } % ;
View
33 basis/cpu/x86/x87/x87.factor
@@ -8,25 +8,22 @@ IN: cpu.x86.x87
! x87 unit is only used if SSE2 is not available.
-: FLD* ( src -- ) [ ST0 ] dip FLD ;
-: FSTP* ( dst -- ) ST0 FSTP ;
-
: copy-register-x87 ( dst src -- )
- 2dup eq? [ 2drop ] [ FLD* shuffle-down FSTP* ] if ;
+ 2dup eq? [ 2drop ] [ FLD shuffle-down FSTP ] if ;
M: float-rep copy-register* drop copy-register-x87 ;
M: double-rep copy-register* drop copy-register-x87 ;
: load-x87 ( dst src rep -- )
{
- { float-rep [ FLDS shuffle-down FSTP* ] }
- { double-rep [ FLDL shuffle-down FSTP* ] }
+ { float-rep [ FLDS shuffle-down FSTP ] }
+ { double-rep [ FLDL shuffle-down FSTP ] }
} case ;
: store-x87 ( dst src rep -- )
{
- { float-rep [ FLD* FSTPS ] }
- { double-rep [ FLD* FSTPL ] }
+ { float-rep [ FLD FSTPS ] }
+ { double-rep [ FLD FSTPL ] }
} case ;
: copy-memory-x87 ( dst src rep -- )
@@ -41,24 +38,24 @@ M: double-rep copy-memory* copy-memory-x87 ;
M: x86 %load-float
0 [] FLDS
<float> rc-absolute rel-binary-literal
- shuffle-down FSTP* ;
+ shuffle-down FSTP ;
M: x86 %load-double
0 [] FLDL
<double> rc-absolute rel-binary-literal
- shuffle-down FSTP* ;
+ shuffle-down FSTP ;
:: binary-op ( dst src1 src2 quot -- )
- src1 FLD*
+ src1 FLD
ST0 src2 shuffle-down quot call
- dst shuffle-down FSTP* ; inline
+ dst shuffle-down FSTP ; inline
M: x86 %add-float [ FADD ] binary-op ;
M: x86 %sub-float [ FSUB ] binary-op ;
M: x86 %mul-float [ FMUL ] binary-op ;
M: x86 %div-float [ FDIV ] binary-op ;
-M: x86 %sqrt FLD* FSQRT shuffle-down FSTP* ;
+M: x86 %sqrt FLD FSQRT shuffle-down FSTP ;
M: x86 %single>double-float copy-register-x87 ;
M: x86 %double>single-float copy-register-x87 ;
@@ -68,10 +65,10 @@ M: x86 integer-float-needs-stack-frame? t ;
M:: x86 %integer>float ( dst src -- )
4 stack@ src MOV
4 stack@ FILDD
- dst shuffle-down FSTP* ;
+ dst shuffle-down FSTP ;
M:: x86 %float>integer ( dst src -- )
- src FLD*
+ src FLD
8 stack@ EAX MOV
0 stack@ FNSTCW
AX 0 stack@ MOV
@@ -84,9 +81,9 @@ M:: x86 %float>integer ( dst src -- )
dst 4 stack@ MOV ;
:: compare-op ( src1 src2 quot -- )
- src1 FLD*
- ST0 src2 shuffle-down quot call
- ST0 FSTP* ; inline
+ src1 FLD
+ src2 shuffle-down quot call
+ ST0 FSTP ; inline
M: x86 %compare-float-ordered ( dst src1 src2 cc temp -- )
[ [ FCOMI ] compare-op ] (%compare-float) ;

0 comments on commit d05bb6e

Please sign in to comment.