2009-05-29 14:11:34 -04:00
|
|
|
! Copyright (C) 2008, 2009 Slava Pestov.
|
2008-10-28 05:38:37 -04:00
|
|
|
! See http://factorcode.org/license.txt for BSD license.
|
2009-06-08 22:15:52 -04:00
|
|
|
USING: accessors kernel sequences make compiler.cfg.instructions
|
2009-07-22 04:08:28 -04:00
|
|
|
compiler.cfg.rpo cpu.architecture ;
|
2008-10-28 05:38:37 -04:00
|
|
|
IN: compiler.cfg.two-operand
|
|
|
|
|
|
|
|
! On x86, instructions take the form x = x op y
|
|
|
|
! Our SSA IR is x = y op z
|
|
|
|
|
2009-06-08 22:15:52 -04:00
|
|
|
! We don't bother with ##add, ##add-imm, ##sub-imm or ##mul-imm
|
|
|
|
! since x86 has LEA and IMUL instructions which are effectively
|
|
|
|
! three-operand addition and multiplication, respectively.
|
2008-10-28 05:38:37 -04:00
|
|
|
|
2009-06-01 04:00:10 -04:00
|
|
|
: convert-two-operand/integer ( insn -- )
|
2009-05-29 14:11:34 -04:00
|
|
|
[ [ dst>> ] [ src1>> ] bi ##copy ]
|
|
|
|
[ dup dst>> >>src1 , ]
|
|
|
|
bi ; inline
|
2008-10-28 05:38:37 -04:00
|
|
|
|
2009-06-01 04:00:10 -04:00
|
|
|
: convert-two-operand/float ( insn -- )
|
2009-05-29 14:11:34 -04:00
|
|
|
[ [ dst>> ] [ src1>> ] bi ##copy-float ]
|
|
|
|
[ dup dst>> >>src1 , ]
|
|
|
|
bi ; inline
|
2008-10-28 05:38:37 -04:00
|
|
|
|
2009-05-29 14:11:34 -04:00
|
|
|
GENERIC: convert-two-operand* ( insn -- )
|
2008-10-28 05:38:37 -04:00
|
|
|
|
|
|
|
M: ##not convert-two-operand*
|
2009-05-29 14:11:34 -04:00
|
|
|
[ [ dst>> ] [ src>> ] bi ##copy ]
|
|
|
|
[ dup dst>> >>src , ]
|
|
|
|
bi ;
|
2008-10-28 05:38:37 -04:00
|
|
|
|
|
|
|
M: ##sub convert-two-operand* convert-two-operand/integer ;
|
|
|
|
M: ##mul convert-two-operand* convert-two-operand/integer ;
|
|
|
|
M: ##and convert-two-operand* convert-two-operand/integer ;
|
|
|
|
M: ##and-imm convert-two-operand* convert-two-operand/integer ;
|
|
|
|
M: ##or convert-two-operand* convert-two-operand/integer ;
|
|
|
|
M: ##or-imm convert-two-operand* convert-two-operand/integer ;
|
|
|
|
M: ##xor convert-two-operand* convert-two-operand/integer ;
|
|
|
|
M: ##xor-imm convert-two-operand* convert-two-operand/integer ;
|
2009-07-17 00:50:48 -04:00
|
|
|
M: ##shl convert-two-operand* convert-two-operand/integer ;
|
2008-10-28 05:38:37 -04:00
|
|
|
M: ##shl-imm convert-two-operand* convert-two-operand/integer ;
|
2009-07-17 00:50:48 -04:00
|
|
|
M: ##shr convert-two-operand* convert-two-operand/integer ;
|
2008-10-28 05:38:37 -04:00
|
|
|
M: ##shr-imm convert-two-operand* convert-two-operand/integer ;
|
2009-07-17 00:50:48 -04:00
|
|
|
M: ##sar convert-two-operand* convert-two-operand/integer ;
|
2008-10-28 05:38:37 -04:00
|
|
|
M: ##sar-imm convert-two-operand* convert-two-operand/integer ;
|
|
|
|
|
2009-07-16 19:29:40 -04:00
|
|
|
M: ##fixnum-overflow convert-two-operand* convert-two-operand/integer ;
|
|
|
|
|
2008-10-28 05:38:37 -04:00
|
|
|
M: ##add-float convert-two-operand* convert-two-operand/float ;
|
|
|
|
M: ##sub-float convert-two-operand* convert-two-operand/float ;
|
|
|
|
M: ##mul-float convert-two-operand* convert-two-operand/float ;
|
|
|
|
M: ##div-float convert-two-operand* convert-two-operand/float ;
|
|
|
|
|
2009-05-29 14:11:34 -04:00
|
|
|
M: insn convert-two-operand* , ;
|
2008-10-28 05:38:37 -04:00
|
|
|
|
2009-05-29 14:11:34 -04:00
|
|
|
: convert-two-operand ( cfg -- cfg' )
|
|
|
|
two-operand? [
|
2009-06-08 22:15:52 -04:00
|
|
|
[ [ [ convert-two-operand* ] each ] V{ } make ]
|
|
|
|
local-optimization
|
2009-05-29 14:11:34 -04:00
|
|
|
] when ;
|