2010-01-10 07:20:32 -05:00
|
|
|
! Copyright (C) 2005, 2010 Slava Pestov.
|
2007-09-20 18:09:08 -04:00
|
|
|
! See http://factorcode.org/license.txt for BSD license.
|
2008-11-06 02:11:28 -05:00
|
|
|
USING: accessors assocs alien alien.c-types arrays strings
|
2009-07-29 22:44:08 -04:00
|
|
|
cpu.x86.assembler cpu.x86.assembler.private cpu.x86.assembler.operands
|
2009-09-23 21:23:25 -04:00
|
|
|
cpu.x86.features cpu.x86.features.private cpu.architecture kernel
|
|
|
|
kernel.private math memory namespaces make sequences words system
|
2009-11-01 17:09:44 -05:00
|
|
|
layouts combinators math.order math.vectors fry locals compiler.constants
|
2009-09-23 21:23:25 -04:00
|
|
|
byte-arrays io macros quotations compiler compiler.units init vm
|
2009-07-13 15:42:52 -04:00
|
|
|
compiler.cfg.registers
|
|
|
|
compiler.cfg.instructions
|
|
|
|
compiler.cfg.intrinsics
|
|
|
|
compiler.cfg.comparisons
|
|
|
|
compiler.cfg.stack-frame
|
|
|
|
compiler.codegen.fixup ;
|
2009-09-20 05:17:34 -04:00
|
|
|
FROM: layouts => cell ;
|
2009-09-15 17:08:42 -04:00
|
|
|
FROM: math => float ;
|
2008-11-05 05:15:48 -05:00
|
|
|
IN: cpu.x86
|
2007-09-20 18:09:08 -04:00
|
|
|
|
2009-05-06 17:14:53 -04:00
|
|
|
! Add some methods to the assembler to be more useful to the backend
|
|
|
|
M: label JMP 0 JMP rc-relative label-fixup ;
|
|
|
|
M: label JUMPcc [ 0 ] dip JUMPcc rc-relative label-fixup ;
|
|
|
|
|
2009-09-24 04:32:39 -04:00
|
|
|
M: x86 vector-regs float-regs ;
|
|
|
|
|
2009-06-02 19:23:47 -04:00
|
|
|
HOOK: stack-reg cpu ( -- reg )
|
|
|
|
|
2010-01-02 07:03:30 -05:00
|
|
|
HOOK: frame-reg cpu ( -- reg )
|
|
|
|
|
2009-10-20 06:02:42 -04:00
|
|
|
HOOK: reserved-stack-space cpu ( -- n )
|
|
|
|
|
|
|
|
HOOK: extra-stack-space cpu ( stack-frame -- n )
|
2009-06-02 19:23:47 -04:00
|
|
|
|
|
|
|
: stack@ ( n -- op ) stack-reg swap [+] ;
|
|
|
|
|
2009-10-20 06:02:42 -04:00
|
|
|
: special@ ( n -- op )
|
|
|
|
stack-frame get extra-stack-space +
|
|
|
|
reserved-stack-space +
|
|
|
|
stack@ ;
|
2009-06-02 19:23:47 -04:00
|
|
|
|
2009-10-20 06:02:42 -04:00
|
|
|
: spill@ ( n -- op ) spill-offset special@ ;
|
2009-06-02 19:23:47 -04:00
|
|
|
|
2009-10-20 06:02:42 -04:00
|
|
|
: gc-root@ ( n -- op ) gc-root-offset special@ ;
|
2009-06-02 19:23:47 -04:00
|
|
|
|
2010-04-01 20:36:09 -04:00
|
|
|
: param@ ( n -- op ) reserved-stack-space + stack@ ;
|
|
|
|
|
2009-06-02 19:23:47 -04:00
|
|
|
: decr-stack-reg ( n -- )
|
|
|
|
dup 0 = [ drop ] [ stack-reg swap SUB ] if ;
|
|
|
|
|
|
|
|
: incr-stack-reg ( n -- )
|
|
|
|
dup 0 = [ drop ] [ stack-reg swap ADD ] if ;
|
|
|
|
|
2009-11-04 00:51:44 -05:00
|
|
|
: align-stack ( n -- n' ) 16 align ;
|
2009-06-02 19:23:47 -04:00
|
|
|
|
|
|
|
M: x86 stack-frame-size ( stack-frame -- i )
|
2009-10-20 06:02:42 -04:00
|
|
|
[ (stack-frame-size) ]
|
|
|
|
[ extra-stack-space ] bi +
|
|
|
|
reserved-stack-space +
|
|
|
|
3 cells +
|
|
|
|
align-stack ;
|
2009-06-02 19:23:47 -04:00
|
|
|
|
2010-01-22 06:15:08 -05:00
|
|
|
! Must be a volatile register not used for parameter passing or
|
|
|
|
! integer return
|
2009-08-07 18:44:50 -04:00
|
|
|
HOOK: temp-reg cpu ( -- reg )
|
2008-10-19 02:10:45 -04:00
|
|
|
|
2009-05-06 20:22:22 -04:00
|
|
|
HOOK: pic-tail-reg cpu ( -- reg )
|
|
|
|
|
2009-07-27 23:27:54 -04:00
|
|
|
M: x86 %load-immediate dup 0 = [ drop dup XOR ] [ MOV ] if ;
|
2008-10-19 02:10:45 -04:00
|
|
|
|
2010-04-18 22:42:19 -04:00
|
|
|
M: x86 %load-reference swap 0 MOV rc-absolute-cell rel-literal ;
|
2008-10-21 04:21:29 -04:00
|
|
|
|
2008-10-20 06:55:57 -04:00
|
|
|
HOOK: ds-reg cpu ( -- reg )
|
|
|
|
HOOK: rs-reg cpu ( -- reg )
|
2008-10-05 22:30:29 -04:00
|
|
|
|
2007-09-20 18:09:08 -04:00
|
|
|
: reg-stack ( n reg -- op ) swap cells neg [+] ;
|
|
|
|
|
2008-10-07 17:42:11 -04:00
|
|
|
GENERIC: loc>operand ( loc -- operand )
|
|
|
|
|
|
|
|
M: ds-loc loc>operand n>> ds-reg reg-stack ;
|
|
|
|
M: rs-loc loc>operand n>> rs-reg reg-stack ;
|
2007-09-20 18:09:08 -04:00
|
|
|
|
2008-10-20 06:55:57 -04:00
|
|
|
M: x86 %peek loc>operand MOV ;
|
|
|
|
M: x86 %replace loc>operand swap MOV ;
|
|
|
|
: (%inc) ( n reg -- ) swap cells dup 0 > [ ADD ] [ neg SUB ] if ; inline
|
|
|
|
M: x86 %inc-d ( n -- ) ds-reg (%inc) ;
|
|
|
|
M: x86 %inc-r ( n -- ) rs-reg (%inc) ;
|
2007-09-20 18:09:08 -04:00
|
|
|
|
2009-05-06 17:14:53 -04:00
|
|
|
M: x86 %call ( word -- ) 0 CALL rc-relative rel-word-pic ;
|
2009-05-06 20:22:22 -04:00
|
|
|
|
2009-05-06 23:44:30 -04:00
|
|
|
: xt-tail-pic-offset ( -- n )
|
|
|
|
#! See the comment in vm/cpu-x86.hpp
|
2010-01-02 07:03:30 -05:00
|
|
|
4 1 + ; inline
|
2009-05-06 23:44:30 -04:00
|
|
|
|
2010-02-03 03:27:18 -05:00
|
|
|
HOOK: %prepare-jump cpu ( -- )
|
|
|
|
|
2009-05-06 20:22:22 -04:00
|
|
|
M: x86 %jump ( word -- )
|
2010-02-03 03:27:18 -05:00
|
|
|
%prepare-jump
|
2009-05-06 20:22:22 -04:00
|
|
|
0 JMP rc-relative rel-word-pic-tail ;
|
|
|
|
|
2009-05-06 17:14:53 -04:00
|
|
|
M: x86 %jump-label ( label -- ) 0 JMP rc-relative label-fixup ;
|
2009-05-06 20:22:22 -04:00
|
|
|
|
2008-10-20 06:55:57 -04:00
|
|
|
M: x86 %return ( -- ) 0 RET ;
|
2008-10-07 17:17:55 -04:00
|
|
|
|
2008-11-03 07:20:51 -05:00
|
|
|
: code-alignment ( align -- n )
|
2009-06-01 03:32:36 -04:00
|
|
|
[ building get length dup ] dip align swap - ;
|
2008-02-09 22:12:00 -05:00
|
|
|
|
|
|
|
: align-code ( n -- )
|
|
|
|
0 <repetition> % ;
|
|
|
|
|
2008-10-20 06:55:57 -04:00
|
|
|
:: (%slot-imm) ( obj slot tag -- op )
|
2009-10-15 03:40:23 -04:00
|
|
|
obj slot tag slot-offset [+] ; inline
|
2008-10-20 06:55:57 -04:00
|
|
|
|
2009-09-26 01:28:14 -04:00
|
|
|
M: x86 %slot ( dst obj slot -- ) [+] MOV ;
|
2008-10-20 06:55:57 -04:00
|
|
|
M: x86 %slot-imm ( dst obj slot tag -- ) (%slot-imm) MOV ;
|
2009-09-26 01:28:14 -04:00
|
|
|
M: x86 %set-slot ( src obj slot -- ) [+] swap MOV ;
|
2008-10-20 06:55:57 -04:00
|
|
|
M: x86 %set-slot-imm ( src obj slot tag -- ) (%slot-imm) swap MOV ;
|
|
|
|
|
2009-09-27 18:17:26 -04:00
|
|
|
:: two-operand ( dst src1 src2 rep -- dst src )
|
2009-09-28 09:48:39 -04:00
|
|
|
dst src2 eq? dst src1 eq? not and [ "Cannot handle this case" throw ] when
|
2009-09-27 18:17:26 -04:00
|
|
|
dst src1 rep %copy
|
|
|
|
dst src2 ; inline
|
|
|
|
|
|
|
|
:: one-operand ( dst src rep -- dst )
|
|
|
|
dst src rep %copy
|
|
|
|
dst ; inline
|
|
|
|
|
2009-07-27 23:27:54 -04:00
|
|
|
M: x86 %add 2over eq? [ nip ADD ] [ [+] LEA ] if ;
|
|
|
|
M: x86 %add-imm 2over eq? [ nip ADD ] [ [+] LEA ] if ;
|
2009-09-27 18:17:26 -04:00
|
|
|
M: x86 %sub int-rep two-operand SUB ;
|
2009-07-27 23:27:54 -04:00
|
|
|
M: x86 %sub-imm 2over eq? [ nip SUB ] [ neg [+] LEA ] if ;
|
2009-09-27 18:17:26 -04:00
|
|
|
M: x86 %mul int-rep two-operand swap IMUL2 ;
|
2009-06-08 22:15:52 -04:00
|
|
|
M: x86 %mul-imm IMUL3 ;
|
2009-09-27 18:17:26 -04:00
|
|
|
M: x86 %and int-rep two-operand AND ;
|
|
|
|
M: x86 %and-imm int-rep two-operand AND ;
|
|
|
|
M: x86 %or int-rep two-operand OR ;
|
|
|
|
M: x86 %or-imm int-rep two-operand OR ;
|
|
|
|
M: x86 %xor int-rep two-operand XOR ;
|
|
|
|
M: x86 %xor-imm int-rep two-operand XOR ;
|
|
|
|
M: x86 %shl-imm int-rep two-operand SHL ;
|
|
|
|
M: x86 %shr-imm int-rep two-operand SHR ;
|
|
|
|
M: x86 %sar-imm int-rep two-operand SAR ;
|
|
|
|
|
|
|
|
M: x86 %min int-rep two-operand [ CMP ] [ CMOVG ] 2bi ;
|
|
|
|
M: x86 %max int-rep two-operand [ CMP ] [ CMOVL ] 2bi ;
|
|
|
|
|
|
|
|
M: x86 %not int-rep one-operand NOT ;
|
2009-09-28 18:31:34 -04:00
|
|
|
M: x86 %neg int-rep one-operand NEG ;
|
2008-12-06 16:31:17 -05:00
|
|
|
M: x86 %log2 BSR ;
|
2008-10-20 06:55:57 -04:00
|
|
|
|
2009-11-04 00:51:44 -05:00
|
|
|
! A bit of logic to avoid using MOVSS/MOVSD for reg-reg moves
|
|
|
|
! since this induces partial register stalls
|
2009-09-03 03:33:07 -04:00
|
|
|
GENERIC: copy-register* ( dst src rep -- )
|
2009-11-04 00:51:44 -05:00
|
|
|
GENERIC: copy-memory* ( dst src rep -- )
|
2009-09-03 03:33:07 -04:00
|
|
|
|
|
|
|
M: int-rep copy-register* drop MOV ;
|
|
|
|
M: tagged-rep copy-register* drop MOV ;
|
2009-11-01 17:09:44 -05:00
|
|
|
M: float-rep copy-register* drop MOVAPS ;
|
|
|
|
M: double-rep copy-register* drop MOVAPS ;
|
|
|
|
M: float-4-rep copy-register* drop MOVAPS ;
|
|
|
|
M: double-2-rep copy-register* drop MOVAPS ;
|
|
|
|
M: vector-rep copy-register* drop MOVDQA ;
|
|
|
|
|
2009-11-04 00:51:44 -05:00
|
|
|
M: object copy-memory* copy-register* ;
|
|
|
|
M: float-rep copy-memory* drop MOVSS ;
|
|
|
|
M: double-rep copy-memory* drop MOVSD ;
|
2009-09-03 03:33:07 -04:00
|
|
|
|
2009-09-23 23:49:54 -04:00
|
|
|
M: x86 %copy ( dst src rep -- )
|
2009-09-27 20:28:20 -04:00
|
|
|
2over eq? [ 3drop ] [
|
|
|
|
[ [ dup spill-slot? [ n>> spill@ ] when ] bi@ ] dip
|
2009-11-04 00:51:44 -05:00
|
|
|
2over [ register? ] both? [ copy-register* ] [ copy-memory* ] if
|
2009-09-27 20:28:20 -04:00
|
|
|
] if ;
|
2009-09-03 03:33:07 -04:00
|
|
|
|
2009-07-16 19:29:40 -04:00
|
|
|
M: x86 %fixnum-add ( label dst src1 src2 -- )
|
2009-09-27 18:17:26 -04:00
|
|
|
int-rep two-operand ADD JO ;
|
2009-07-16 19:29:40 -04:00
|
|
|
|
|
|
|
M: x86 %fixnum-sub ( label dst src1 src2 -- )
|
2009-09-27 18:17:26 -04:00
|
|
|
int-rep two-operand SUB JO ;
|
2009-07-16 19:29:40 -04:00
|
|
|
|
|
|
|
M: x86 %fixnum-mul ( label dst src1 src2 -- )
|
2009-09-27 18:17:26 -04:00
|
|
|
int-rep two-operand swap IMUL2 JO ;
|
2008-11-30 08:26:49 -05:00
|
|
|
|
2009-09-28 06:39:53 -04:00
|
|
|
M: x86 %unbox-alien ( dst src -- )
|
|
|
|
alien-offset [+] MOV ;
|
2009-08-07 18:44:50 -04:00
|
|
|
|
2009-11-03 03:42:27 -05:00
|
|
|
M:: x86 %unbox-any-c-ptr ( dst src -- )
|
2009-09-28 06:39:53 -04:00
|
|
|
[
|
2009-11-02 04:25:39 -05:00
|
|
|
"end" define-label
|
2009-11-03 03:42:27 -05:00
|
|
|
dst dst XOR
|
2009-09-28 06:39:53 -04:00
|
|
|
! Is the object f?
|
2009-11-02 04:25:39 -05:00
|
|
|
src \ f type-number CMP
|
2009-09-28 06:39:53 -04:00
|
|
|
"end" get JE
|
2009-11-03 03:42:27 -05:00
|
|
|
! Compute tag in dst register
|
|
|
|
dst src MOV
|
|
|
|
dst tag-mask get AND
|
2009-09-28 06:39:53 -04:00
|
|
|
! Is the object an alien?
|
2009-11-03 03:42:27 -05:00
|
|
|
dst alien type-number CMP
|
2009-09-28 06:39:53 -04:00
|
|
|
! Add an offset to start of byte array's data
|
2009-11-02 04:25:39 -05:00
|
|
|
dst src byte-array-offset [+] LEA
|
|
|
|
"end" get JNE
|
2009-09-28 06:39:53 -04:00
|
|
|
! If so, load the offset and add it to the address
|
2009-11-02 04:25:39 -05:00
|
|
|
dst src alien-offset [+] MOV
|
2009-09-28 06:39:53 -04:00
|
|
|
"end" resolve-label
|
|
|
|
] with-scope ;
|
2008-10-20 06:55:57 -04:00
|
|
|
|
2009-11-02 04:25:39 -05:00
|
|
|
: alien@ ( reg n -- op ) cells alien type-number - [+] ;
|
2009-09-03 03:33:07 -04:00
|
|
|
|
2009-09-28 06:39:53 -04:00
|
|
|
M:: x86 %box-alien ( dst src temp -- )
|
|
|
|
[
|
|
|
|
"end" define-label
|
2009-11-02 04:25:39 -05:00
|
|
|
dst \ f type-number MOV
|
2009-11-03 03:42:27 -05:00
|
|
|
src src TEST
|
2009-09-28 06:39:53 -04:00
|
|
|
"end" get JE
|
2009-11-02 04:25:39 -05:00
|
|
|
dst 5 cells alien temp %allot
|
|
|
|
dst 1 alien@ \ f type-number MOV ! base
|
|
|
|
dst 2 alien@ \ f type-number MOV ! expired
|
2009-11-02 18:41:36 -05:00
|
|
|
dst 3 alien@ src MOV ! displacement
|
|
|
|
dst 4 alien@ src MOV ! address
|
2009-09-28 06:39:53 -04:00
|
|
|
"end" resolve-label
|
|
|
|
] with-scope ;
|
2009-09-20 03:08:32 -04:00
|
|
|
|
2009-11-03 03:42:27 -05:00
|
|
|
M:: x86 %box-displaced-alien ( dst displacement base temp base-class -- )
|
|
|
|
! This is ridiculous
|
2009-09-28 06:39:53 -04:00
|
|
|
[
|
|
|
|
"end" define-label
|
2009-11-03 03:42:27 -05:00
|
|
|
"not-f" define-label
|
|
|
|
"not-alien" define-label
|
|
|
|
|
2009-09-28 06:39:53 -04:00
|
|
|
! If displacement is zero, return the base
|
|
|
|
dst base MOV
|
2009-11-03 03:42:27 -05:00
|
|
|
displacement displacement TEST
|
2009-09-28 06:39:53 -04:00
|
|
|
"end" get JE
|
2009-11-03 03:42:27 -05:00
|
|
|
|
|
|
|
! Displacement is non-zero, we're going to be allocating a new
|
|
|
|
! object
|
|
|
|
dst 5 cells alien temp %allot
|
|
|
|
|
|
|
|
! Set expired to f
|
|
|
|
dst 2 alien@ \ f type-number MOV
|
|
|
|
|
|
|
|
! Is base f?
|
2009-11-02 04:25:39 -05:00
|
|
|
base \ f type-number CMP
|
2009-11-03 03:42:27 -05:00
|
|
|
"not-f" get JNE
|
|
|
|
|
|
|
|
! Yes, it is f. Fill in new object
|
|
|
|
dst 1 alien@ base MOV
|
|
|
|
dst 3 alien@ displacement MOV
|
|
|
|
dst 4 alien@ displacement MOV
|
|
|
|
|
|
|
|
"end" get JMP
|
|
|
|
|
|
|
|
"not-f" resolve-label
|
|
|
|
|
|
|
|
! Check base type
|
|
|
|
temp base MOV
|
|
|
|
temp tag-mask get AND
|
|
|
|
|
|
|
|
! Is base an alien?
|
|
|
|
temp alien type-number CMP
|
|
|
|
"not-alien" get JNE
|
|
|
|
|
|
|
|
! Yes, it is an alien. Set new alien's base to base.base
|
|
|
|
temp base 1 alien@ MOV
|
|
|
|
dst 1 alien@ temp MOV
|
|
|
|
|
|
|
|
! Compute displacement
|
|
|
|
temp base 3 alien@ MOV
|
|
|
|
temp displacement ADD
|
|
|
|
dst 3 alien@ temp MOV
|
|
|
|
|
|
|
|
! Compute address
|
|
|
|
temp base 4 alien@ MOV
|
|
|
|
temp displacement ADD
|
|
|
|
dst 4 alien@ temp MOV
|
|
|
|
|
|
|
|
! We are done
|
|
|
|
"end" get JMP
|
|
|
|
|
|
|
|
! Is base a byte array? It has to be, by now...
|
|
|
|
"not-alien" resolve-label
|
|
|
|
|
|
|
|
dst 1 alien@ base MOV
|
|
|
|
dst 3 alien@ displacement MOV
|
|
|
|
temp base MOV
|
|
|
|
temp byte-array-offset ADD
|
|
|
|
temp displacement ADD
|
|
|
|
dst 4 alien@ temp MOV
|
|
|
|
|
2009-09-28 06:39:53 -04:00
|
|
|
"end" resolve-label
|
|
|
|
] with-scope ;
|
2009-09-03 03:33:07 -04:00
|
|
|
|
2009-09-28 06:39:53 -04:00
|
|
|
! The 'small-reg' mess is pretty crappy, but its only used on x86-32.
|
|
|
|
! On x86-64, all registers have 8-bit versions. However, a similar
|
|
|
|
! problem arises for shifts, where the shift count must be in CL, and
|
|
|
|
! so one day I will fix this properly by adding precoloring to the
|
|
|
|
! register allocator.
|
2009-09-20 03:08:32 -04:00
|
|
|
|
2009-09-28 06:39:53 -04:00
|
|
|
HOOK: has-small-reg? cpu ( reg size -- ? )
|
2009-09-03 03:33:07 -04:00
|
|
|
|
2009-09-28 06:39:53 -04:00
|
|
|
CONSTANT: have-byte-regs { EAX ECX EDX EBX }
|
2009-09-20 03:08:32 -04:00
|
|
|
|
2009-09-28 06:39:53 -04:00
|
|
|
M: x86.32 has-small-reg?
|
2009-09-03 03:33:07 -04:00
|
|
|
{
|
2009-10-28 16:02:00 -04:00
|
|
|
{ 8 [ have-byte-regs member-eq? ] }
|
2009-09-28 06:39:53 -04:00
|
|
|
{ 16 [ drop t ] }
|
|
|
|
{ 32 [ drop t ] }
|
2009-09-27 18:17:26 -04:00
|
|
|
} case ;
|
2009-09-03 03:33:07 -04:00
|
|
|
|
2009-09-28 06:39:53 -04:00
|
|
|
M: x86.64 has-small-reg? 2drop t ;
|
2009-09-20 03:08:32 -04:00
|
|
|
|
2009-09-28 06:39:53 -04:00
|
|
|
: small-reg-that-isn't ( exclude -- reg' )
|
|
|
|
[ have-byte-regs ] dip
|
|
|
|
[ native-version-of ] map
|
2009-10-28 16:02:00 -04:00
|
|
|
'[ _ member-eq? not ] find nip ;
|
2009-09-21 00:16:02 -04:00
|
|
|
|
2009-09-28 06:39:53 -04:00
|
|
|
: with-save/restore ( reg quot -- )
|
|
|
|
[ drop PUSH ] [ call ] [ drop POP ] 2tri ; inline
|
2009-09-21 00:16:02 -04:00
|
|
|
|
2009-09-28 06:39:53 -04:00
|
|
|
:: with-small-register ( dst exclude size quot: ( new-dst -- ) -- )
|
|
|
|
! If the destination register overlaps a small register with
|
|
|
|
! 'size' bits, we call the quot with that. Otherwise, we find a
|
|
|
|
! small register that is not in exclude, and call quot, saving and
|
|
|
|
! restoring the small register.
|
|
|
|
dst size has-small-reg? [ dst quot call ] [
|
|
|
|
exclude small-reg-that-isn't
|
|
|
|
[ quot call ] with-save/restore
|
|
|
|
] if ; inline
|
2009-09-21 00:16:02 -04:00
|
|
|
|
2009-09-28 06:39:53 -04:00
|
|
|
M:: x86 %string-nth ( dst src index temp -- )
|
|
|
|
! We request a small-reg of size 8 since those of size 16 are
|
|
|
|
! a superset.
|
|
|
|
"end" define-label
|
|
|
|
dst { src index temp } 8 [| new-dst |
|
|
|
|
! Load the least significant 7 bits into new-dst.
|
|
|
|
! 8th bit indicates whether we have to load from
|
|
|
|
! the aux vector or not.
|
|
|
|
temp src index [+] LEA
|
|
|
|
new-dst 8-bit-version-of temp string-offset [+] MOV
|
|
|
|
new-dst new-dst 8-bit-version-of MOVZX
|
|
|
|
! Do we have to look at the aux vector?
|
|
|
|
new-dst HEX: 80 CMP
|
|
|
|
"end" get JL
|
|
|
|
! Yes, this is a non-ASCII character. Load aux vector
|
|
|
|
temp src string-aux-offset [+] MOV
|
|
|
|
new-dst temp XCHG
|
|
|
|
! Compute index
|
|
|
|
new-dst index ADD
|
|
|
|
new-dst index ADD
|
|
|
|
! Load high 16 bits
|
|
|
|
new-dst 16-bit-version-of new-dst byte-array-offset [+] MOV
|
|
|
|
new-dst new-dst 16-bit-version-of MOVZX
|
|
|
|
new-dst 7 SHL
|
|
|
|
! Compute code point
|
|
|
|
new-dst temp XOR
|
|
|
|
"end" resolve-label
|
|
|
|
dst new-dst int-rep %copy
|
|
|
|
] with-small-register ;
|
2009-09-21 00:16:02 -04:00
|
|
|
|
2009-09-28 06:39:53 -04:00
|
|
|
M:: x86 %set-string-nth-fast ( ch str index temp -- )
|
|
|
|
ch { index str temp } 8 [| new-ch |
|
|
|
|
new-ch ch int-rep %copy
|
|
|
|
temp str index [+] LEA
|
|
|
|
temp string-offset [+] new-ch 8-bit-version-of MOV
|
|
|
|
] with-small-register ;
|
2009-09-03 03:33:07 -04:00
|
|
|
|
2009-09-30 06:00:36 -04:00
|
|
|
:: %alien-integer-getter ( dst src offset size quot -- )
|
2009-09-28 06:39:53 -04:00
|
|
|
dst { src } size [| new-dst |
|
2009-09-30 06:00:36 -04:00
|
|
|
new-dst dup size n-bit-version-of dup src offset [+] MOV
|
2009-09-28 06:39:53 -04:00
|
|
|
quot call
|
|
|
|
dst new-dst int-rep %copy
|
|
|
|
] with-small-register ; inline
|
2009-09-20 03:08:32 -04:00
|
|
|
|
2009-09-30 06:00:36 -04:00
|
|
|
: %alien-unsigned-getter ( dst src offset size -- )
|
2009-09-28 06:39:53 -04:00
|
|
|
[ MOVZX ] %alien-integer-getter ; inline
|
2009-09-20 18:43:16 -04:00
|
|
|
|
2009-09-30 21:04:37 -04:00
|
|
|
: %alien-signed-getter ( dst src offset size -- )
|
|
|
|
[ MOVSX ] %alien-integer-getter ; inline
|
|
|
|
|
|
|
|
:: %alien-integer-setter ( ptr offset value size -- )
|
|
|
|
value { ptr } size [| new-value |
|
|
|
|
new-value value int-rep %copy
|
|
|
|
ptr offset [+] new-value size n-bit-version-of MOV
|
|
|
|
] with-small-register ; inline
|
|
|
|
|
2009-09-28 06:39:53 -04:00
|
|
|
M: x86 %alien-unsigned-1 8 %alien-unsigned-getter ;
|
|
|
|
M: x86 %alien-unsigned-2 16 %alien-unsigned-getter ;
|
|
|
|
M: x86 %alien-unsigned-4 32 [ 2drop ] %alien-integer-getter ;
|
2009-09-20 18:43:16 -04:00
|
|
|
|
2009-09-28 06:39:53 -04:00
|
|
|
M: x86 %alien-signed-1 8 %alien-signed-getter ;
|
|
|
|
M: x86 %alien-signed-2 16 %alien-signed-getter ;
|
|
|
|
M: x86 %alien-signed-4 32 %alien-signed-getter ;
|
2009-09-20 03:08:32 -04:00
|
|
|
|
2009-09-30 06:00:36 -04:00
|
|
|
M: x86 %alien-cell [+] MOV ;
|
|
|
|
M: x86 %alien-float [+] MOVSS ;
|
|
|
|
M: x86 %alien-double [+] MOVSD ;
|
|
|
|
M: x86 %alien-vector [ [+] ] dip %copy ;
|
2009-09-21 00:16:02 -04:00
|
|
|
|
2009-09-28 06:39:53 -04:00
|
|
|
M: x86 %set-alien-integer-1 8 %alien-integer-setter ;
|
|
|
|
M: x86 %set-alien-integer-2 16 %alien-integer-setter ;
|
|
|
|
M: x86 %set-alien-integer-4 32 %alien-integer-setter ;
|
2009-09-30 06:00:36 -04:00
|
|
|
M: x86 %set-alien-cell [ [+] ] dip MOV ;
|
|
|
|
M: x86 %set-alien-float [ [+] ] dip MOVSS ;
|
|
|
|
M: x86 %set-alien-double [ [+] ] dip MOVSD ;
|
|
|
|
M: x86 %set-alien-vector [ [+] ] 2dip %copy ;
|
2009-09-20 03:08:32 -04:00
|
|
|
|
2009-10-28 16:02:00 -04:00
|
|
|
: shift-count? ( reg -- ? ) { ECX RCX } member-eq? ;
|
2009-09-03 03:33:07 -04:00
|
|
|
|
2009-09-28 06:39:53 -04:00
|
|
|
:: emit-shift ( dst src quot -- )
|
|
|
|
src shift-count? [
|
|
|
|
dst CL quot call
|
|
|
|
] [
|
|
|
|
dst shift-count? [
|
|
|
|
dst src XCHG
|
|
|
|
src CL quot call
|
|
|
|
dst src XCHG
|
|
|
|
] [
|
|
|
|
ECX native-version-of [
|
|
|
|
CL src MOV
|
|
|
|
drop dst CL quot call
|
|
|
|
] with-save/restore
|
|
|
|
] if
|
|
|
|
] if ; inline
|
2009-09-20 03:08:32 -04:00
|
|
|
|
2009-09-28 06:39:53 -04:00
|
|
|
M: x86 %shl int-rep two-operand [ SHL ] emit-shift ;
|
|
|
|
M: x86 %shr int-rep two-operand [ SHR ] emit-shift ;
|
|
|
|
M: x86 %sar int-rep two-operand [ SAR ] emit-shift ;
|
2009-09-03 03:33:07 -04:00
|
|
|
|
2010-01-10 07:20:32 -05:00
|
|
|
HOOK: %mov-vm-ptr cpu ( reg -- )
|
2009-09-23 03:46:54 -04:00
|
|
|
|
2010-04-01 20:06:18 -04:00
|
|
|
HOOK: %vm-field-ptr cpu ( reg offset -- )
|
|
|
|
|
|
|
|
: load-zone-offset ( nursery-ptr -- )
|
|
|
|
"nursery" vm-field-offset %vm-field-ptr ;
|
|
|
|
|
2009-09-28 06:39:53 -04:00
|
|
|
: load-allot-ptr ( nursery-ptr allot-ptr -- )
|
2010-04-01 20:06:18 -04:00
|
|
|
[ drop load-zone-offset ] [ swap [] MOV ] 2bi ;
|
2009-09-23 03:46:54 -04:00
|
|
|
|
2009-09-28 06:39:53 -04:00
|
|
|
: inc-allot-ptr ( nursery-ptr n -- )
|
2009-10-20 13:45:00 -04:00
|
|
|
[ [] ] dip data-alignment get align ADD ;
|
2009-09-28 03:17:46 -04:00
|
|
|
|
2009-09-28 06:39:53 -04:00
|
|
|
: store-header ( temp class -- )
|
2009-11-10 22:06:36 -05:00
|
|
|
[ [] ] [ type-number tag-header ] bi* MOV ;
|
2009-09-28 03:17:46 -04:00
|
|
|
|
2009-09-28 06:39:53 -04:00
|
|
|
: store-tagged ( dst tag -- )
|
2009-11-02 04:25:39 -05:00
|
|
|
type-number OR ;
|
2009-09-28 03:17:46 -04:00
|
|
|
|
2009-09-28 06:39:53 -04:00
|
|
|
M:: x86 %allot ( dst size class nursery-ptr -- )
|
|
|
|
nursery-ptr dst load-allot-ptr
|
|
|
|
dst class store-header
|
|
|
|
dst class store-tagged
|
|
|
|
nursery-ptr size inc-allot-ptr ;
|
2009-09-28 03:17:46 -04:00
|
|
|
|
2009-10-15 23:07:03 -04:00
|
|
|
HOOK: %mark-card cpu ( card temp -- )
|
|
|
|
HOOK: %mark-deck cpu ( card temp -- )
|
|
|
|
|
2009-10-14 03:06:01 -04:00
|
|
|
:: (%write-barrier) ( src slot temp1 temp2 -- )
|
2009-10-15 03:40:23 -04:00
|
|
|
temp1 src slot [+] LEA
|
2009-10-14 03:06:01 -04:00
|
|
|
temp1 card-bits SHR
|
2009-10-15 23:07:03 -04:00
|
|
|
temp1 temp2 %mark-card
|
2009-10-14 03:06:01 -04:00
|
|
|
temp1 deck-bits card-bits - SHR
|
2009-10-15 23:07:03 -04:00
|
|
|
temp1 temp2 %mark-deck ;
|
2009-10-14 03:06:01 -04:00
|
|
|
|
|
|
|
M: x86 %write-barrier ( src slot temp1 temp2 -- ) (%write-barrier) ;
|
|
|
|
|
|
|
|
M: x86 %write-barrier-imm ( src slot temp1 temp2 -- ) (%write-barrier) ;
|
2009-09-20 03:08:32 -04:00
|
|
|
|
2009-10-05 06:27:49 -04:00
|
|
|
M:: x86 %check-nursery ( label size temp1 temp2 -- )
|
2010-04-01 20:06:18 -04:00
|
|
|
temp1 load-zone-offset
|
2009-10-14 03:06:01 -04:00
|
|
|
! Load 'here' into temp2
|
|
|
|
temp2 temp1 [] MOV
|
2009-10-05 06:27:49 -04:00
|
|
|
temp2 size ADD
|
2009-10-14 03:06:01 -04:00
|
|
|
! Load 'end' into temp1
|
|
|
|
temp1 temp1 2 cells [+] MOV
|
2009-09-28 06:39:53 -04:00
|
|
|
temp2 temp1 CMP
|
|
|
|
label JLE ;
|
2009-09-03 03:33:07 -04:00
|
|
|
|
2009-09-28 06:39:53 -04:00
|
|
|
M: x86 %save-gc-root ( gc-root register -- ) [ gc-root@ ] dip MOV ;
|
2009-09-20 03:08:32 -04:00
|
|
|
|
2009-09-28 06:39:53 -04:00
|
|
|
M: x86 %load-gc-root ( gc-root register -- ) swap gc-root@ MOV ;
|
2008-10-20 06:55:57 -04:00
|
|
|
|
2009-09-28 06:39:53 -04:00
|
|
|
M: x86 %alien-global ( dst symbol library -- )
|
|
|
|
[ 0 MOV ] 2dip rc-absolute-cell rel-dlsym ;
|
2009-09-23 03:46:54 -04:00
|
|
|
|
2009-12-21 21:42:49 -05:00
|
|
|
M: x86 %push-stack ( -- )
|
|
|
|
ds-reg cell ADD
|
|
|
|
ds-reg [] int-regs return-reg MOV ;
|
|
|
|
|
|
|
|
M: x86 %push-context-stack ( -- )
|
2010-04-01 20:06:18 -04:00
|
|
|
temp-reg %context
|
2010-02-03 03:27:18 -05:00
|
|
|
temp-reg "datastack" context-field-offset [+] bootstrap-cell ADD
|
|
|
|
temp-reg temp-reg "datastack" context-field-offset [+] MOV
|
2009-12-21 21:42:49 -05:00
|
|
|
temp-reg [] int-regs return-reg MOV ;
|
|
|
|
|
2009-09-28 06:39:53 -04:00
|
|
|
M: x86 %epilogue ( n -- ) cell - incr-stack-reg ;
|
2009-09-28 03:17:46 -04:00
|
|
|
|
2010-04-18 16:26:31 -04:00
|
|
|
:: (%boolean) ( dst temp insn -- )
|
2009-11-02 04:25:39 -05:00
|
|
|
dst \ f type-number MOV
|
2010-04-18 22:42:19 -04:00
|
|
|
temp 0 MOV \ t rc-absolute-cell rel-literal
|
2010-04-18 16:26:31 -04:00
|
|
|
dst temp insn execute ; inline
|
|
|
|
|
|
|
|
: %boolean ( dst cc temp -- )
|
|
|
|
swap order-cc {
|
|
|
|
{ cc< [ \ CMOVL (%boolean) ] }
|
|
|
|
{ cc<= [ \ CMOVLE (%boolean) ] }
|
|
|
|
{ cc> [ \ CMOVG (%boolean) ] }
|
|
|
|
{ cc>= [ \ CMOVGE (%boolean) ] }
|
|
|
|
{ cc= [ \ CMOVE (%boolean) ] }
|
|
|
|
{ cc/= [ \ CMOVNE (%boolean) ] }
|
|
|
|
} case ;
|
2009-10-10 14:13:53 -04:00
|
|
|
|
2009-09-28 06:39:53 -04:00
|
|
|
M:: x86 %compare ( dst src1 src2 cc temp -- )
|
2010-04-18 16:26:31 -04:00
|
|
|
src1 src2 CMP
|
|
|
|
dst cc temp %boolean ;
|
2009-09-23 03:46:54 -04:00
|
|
|
|
2010-04-18 16:26:31 -04:00
|
|
|
: use-test? ( src1 src2 cc -- ? )
|
|
|
|
[ register? ] [ 0 = ] [ { cc= cc/= } member? ] tri* and and ;
|
2009-09-23 03:46:54 -04:00
|
|
|
|
2010-04-18 16:26:31 -04:00
|
|
|
: (%compare-tagged) ( src1 src2 -- )
|
2010-04-18 22:42:19 -04:00
|
|
|
[ HEX: ffffffff CMP ] dip rc-absolute rel-literal ;
|
2010-04-18 16:26:31 -04:00
|
|
|
|
|
|
|
: (%compare-imm) ( src1 src2 cc -- )
|
|
|
|
{
|
|
|
|
{ [ 3dup use-test? ] [ 2drop dup TEST ] }
|
|
|
|
{ [ over integer? ] [ drop CMP ] }
|
|
|
|
{ [ over word? ] [ drop (%compare-tagged) ] }
|
2010-04-18 18:47:50 -04:00
|
|
|
{ [ over not ] [ 2drop \ f type-number CMP ] }
|
2010-04-18 16:26:31 -04:00
|
|
|
} cond ;
|
|
|
|
|
|
|
|
M:: x86 %compare-imm ( dst src1 src2 cc temp -- )
|
|
|
|
src1 src2 cc (%compare-imm)
|
|
|
|
dst cc temp %boolean ;
|
|
|
|
|
|
|
|
: %branch ( label cc -- )
|
|
|
|
order-cc {
|
|
|
|
{ cc< [ JL ] }
|
|
|
|
{ cc<= [ JLE ] }
|
|
|
|
{ cc> [ JG ] }
|
|
|
|
{ cc>= [ JGE ] }
|
|
|
|
{ cc= [ JE ] }
|
|
|
|
{ cc/= [ JNE ] }
|
2009-09-27 18:17:26 -04:00
|
|
|
} case ;
|
2009-09-23 03:46:54 -04:00
|
|
|
|
2010-04-18 16:26:31 -04:00
|
|
|
M:: x86 %compare-branch ( label src1 src2 cc -- )
|
|
|
|
src1 src2 CMP
|
|
|
|
label cc %branch ;
|
|
|
|
|
|
|
|
M:: x86 %compare-imm-branch ( label src1 src2 cc -- )
|
|
|
|
src1 src2 cc (%compare-imm)
|
|
|
|
label cc %branch ;
|
2009-09-20 03:08:32 -04:00
|
|
|
|
2009-09-28 06:39:53 -04:00
|
|
|
M: x86 %add-float double-rep two-operand ADDSD ;
|
|
|
|
M: x86 %sub-float double-rep two-operand SUBSD ;
|
|
|
|
M: x86 %mul-float double-rep two-operand MULSD ;
|
|
|
|
M: x86 %div-float double-rep two-operand DIVSD ;
|
|
|
|
M: x86 %min-float double-rep two-operand MINSD ;
|
|
|
|
M: x86 %max-float double-rep two-operand MAXSD ;
|
|
|
|
M: x86 %sqrt SQRTSD ;
|
2009-09-24 04:32:39 -04:00
|
|
|
|
2009-11-01 19:29:12 -05:00
|
|
|
: %clear-unless-in-place ( dst src -- )
|
|
|
|
over = [ drop ] [ dup XORPS ] if ;
|
2009-09-24 04:32:39 -04:00
|
|
|
|
2009-11-01 19:29:12 -05:00
|
|
|
M: x86 %single>double-float [ %clear-unless-in-place ] [ CVTSS2SD ] 2bi ;
|
|
|
|
M: x86 %double>single-float [ %clear-unless-in-place ] [ CVTSD2SS ] 2bi ;
|
|
|
|
|
2009-11-01 20:39:57 -05:00
|
|
|
M: x86 %integer>float [ drop dup XORPS ] [ CVTSI2SD ] 2bi ;
|
2009-09-28 06:39:53 -04:00
|
|
|
M: x86 %float>integer CVTTSD2SI ;
|
2009-09-24 04:32:39 -04:00
|
|
|
|
2009-09-28 06:39:53 -04:00
|
|
|
: %cmov-float= ( dst src -- )
|
|
|
|
[
|
|
|
|
"no-move" define-label
|
2009-09-24 04:32:39 -04:00
|
|
|
|
2009-09-28 06:39:53 -04:00
|
|
|
"no-move" get [ JNE ] [ JP ] bi
|
|
|
|
MOV
|
|
|
|
"no-move" resolve-label
|
|
|
|
] with-scope ;
|
2009-09-03 22:22:43 -04:00
|
|
|
|
2009-09-28 06:39:53 -04:00
|
|
|
: %cmov-float/= ( dst src -- )
|
2008-10-20 06:55:57 -04:00
|
|
|
[
|
2009-09-28 06:39:53 -04:00
|
|
|
"no-move" define-label
|
|
|
|
"move" define-label
|
|
|
|
|
|
|
|
"move" get JP
|
|
|
|
"no-move" get JE
|
|
|
|
"move" resolve-label
|
|
|
|
MOV
|
|
|
|
"no-move" resolve-label
|
2008-10-20 06:55:57 -04:00
|
|
|
] with-scope ;
|
|
|
|
|
2009-09-28 06:39:53 -04:00
|
|
|
:: (%compare-float) ( dst src1 src2 cc temp compare -- )
|
|
|
|
cc {
|
2010-04-18 16:26:31 -04:00
|
|
|
{ cc< [ src2 src1 \ compare execute( a b -- ) dst temp \ CMOVA (%boolean) ] }
|
|
|
|
{ cc<= [ src2 src1 \ compare execute( a b -- ) dst temp \ CMOVAE (%boolean) ] }
|
|
|
|
{ cc> [ src1 src2 \ compare execute( a b -- ) dst temp \ CMOVA (%boolean) ] }
|
|
|
|
{ cc>= [ src1 src2 \ compare execute( a b -- ) dst temp \ CMOVAE (%boolean) ] }
|
|
|
|
{ cc= [ src1 src2 \ compare execute( a b -- ) dst temp \ %cmov-float= (%boolean) ] }
|
|
|
|
{ cc<> [ src1 src2 \ compare execute( a b -- ) dst temp \ CMOVNE (%boolean) ] }
|
|
|
|
{ cc<>= [ src1 src2 \ compare execute( a b -- ) dst temp \ CMOVNP (%boolean) ] }
|
|
|
|
{ cc/< [ src2 src1 \ compare execute( a b -- ) dst temp \ CMOVBE (%boolean) ] }
|
|
|
|
{ cc/<= [ src2 src1 \ compare execute( a b -- ) dst temp \ CMOVB (%boolean) ] }
|
|
|
|
{ cc/> [ src1 src2 \ compare execute( a b -- ) dst temp \ CMOVBE (%boolean) ] }
|
|
|
|
{ cc/>= [ src1 src2 \ compare execute( a b -- ) dst temp \ CMOVB (%boolean) ] }
|
|
|
|
{ cc/= [ src1 src2 \ compare execute( a b -- ) dst temp \ %cmov-float/= (%boolean) ] }
|
|
|
|
{ cc/<> [ src1 src2 \ compare execute( a b -- ) dst temp \ CMOVE (%boolean) ] }
|
|
|
|
{ cc/<>= [ src1 src2 \ compare execute( a b -- ) dst temp \ CMOVP (%boolean) ] }
|
2009-09-28 06:39:53 -04:00
|
|
|
} case ; inline
|
2008-10-20 06:55:57 -04:00
|
|
|
|
2009-09-28 06:39:53 -04:00
|
|
|
M: x86 %compare-float-ordered ( dst src1 src2 cc temp -- )
|
|
|
|
\ COMISD (%compare-float) ;
|
2009-08-27 01:06:19 -04:00
|
|
|
|
2009-09-28 06:39:53 -04:00
|
|
|
M: x86 %compare-float-unordered ( dst src1 src2 cc temp -- )
|
|
|
|
\ UCOMISD (%compare-float) ;
|
2009-08-27 01:06:19 -04:00
|
|
|
|
2009-09-28 06:39:53 -04:00
|
|
|
: %jump-float= ( label -- )
|
2009-08-27 01:06:19 -04:00
|
|
|
[
|
2009-09-28 06:39:53 -04:00
|
|
|
"no-jump" define-label
|
|
|
|
"no-jump" get JP
|
|
|
|
JE
|
|
|
|
"no-jump" resolve-label
|
2008-10-20 06:55:57 -04:00
|
|
|
] with-scope ;
|
|
|
|
|
2009-09-28 06:39:53 -04:00
|
|
|
: %jump-float/= ( label -- )
|
|
|
|
[ JNE ] [ JP ] bi ;
|
2009-06-03 04:22:46 -04:00
|
|
|
|
2009-09-28 06:39:53 -04:00
|
|
|
:: (%compare-float-branch) ( label src1 src2 cc compare -- )
|
|
|
|
cc {
|
|
|
|
{ cc< [ src2 src1 \ compare execute( a b -- ) label JA ] }
|
|
|
|
{ cc<= [ src2 src1 \ compare execute( a b -- ) label JAE ] }
|
|
|
|
{ cc> [ src1 src2 \ compare execute( a b -- ) label JA ] }
|
|
|
|
{ cc>= [ src1 src2 \ compare execute( a b -- ) label JAE ] }
|
|
|
|
{ cc= [ src1 src2 \ compare execute( a b -- ) label %jump-float= ] }
|
|
|
|
{ cc<> [ src1 src2 \ compare execute( a b -- ) label JNE ] }
|
|
|
|
{ cc<>= [ src1 src2 \ compare execute( a b -- ) label JNP ] }
|
|
|
|
{ cc/< [ src2 src1 \ compare execute( a b -- ) label JBE ] }
|
|
|
|
{ cc/<= [ src2 src1 \ compare execute( a b -- ) label JB ] }
|
|
|
|
{ cc/> [ src1 src2 \ compare execute( a b -- ) label JBE ] }
|
|
|
|
{ cc/>= [ src1 src2 \ compare execute( a b -- ) label JB ] }
|
|
|
|
{ cc/= [ src1 src2 \ compare execute( a b -- ) label %jump-float/= ] }
|
|
|
|
{ cc/<> [ src1 src2 \ compare execute( a b -- ) label JE ] }
|
|
|
|
{ cc/<>= [ src1 src2 \ compare execute( a b -- ) label JP ] }
|
|
|
|
} case ;
|
2009-07-30 06:04:46 -04:00
|
|
|
|
2009-09-28 06:39:53 -04:00
|
|
|
M: x86 %compare-float-ordered-branch ( label src1 src2 cc -- )
|
|
|
|
\ COMISD (%compare-float-branch) ;
|
2009-07-30 06:04:46 -04:00
|
|
|
|
2009-09-28 06:39:53 -04:00
|
|
|
M: x86 %compare-float-unordered-branch ( label src1 src2 cc -- )
|
|
|
|
\ UCOMISD (%compare-float-branch) ;
|
2009-07-30 06:04:46 -04:00
|
|
|
|
2009-09-28 06:39:53 -04:00
|
|
|
MACRO: available-reps ( alist -- )
|
|
|
|
! Each SSE version adds new representations and supports
|
|
|
|
! all old ones
|
|
|
|
unzip { } [ append ] accumulate rest swap suffix
|
|
|
|
[ [ 1quotation ] map ] bi@ zip
|
|
|
|
reverse [ { } ] suffix
|
|
|
|
'[ _ cond ] ;
|
2008-10-20 06:55:57 -04:00
|
|
|
|
2009-10-10 13:53:10 -04:00
|
|
|
M: x86 %alien-vector-reps
|
|
|
|
{
|
|
|
|
{ sse? { float-4-rep } }
|
|
|
|
{ sse2? { double-2-rep char-16-rep uchar-16-rep short-8-rep ushort-8-rep int-4-rep uint-4-rep longlong-2-rep ulonglong-2-rep } }
|
|
|
|
} available-reps ;
|
|
|
|
|
2009-09-28 18:31:34 -04:00
|
|
|
M: x86 %zero-vector
|
|
|
|
{
|
2009-11-01 17:09:44 -05:00
|
|
|
{ double-2-rep [ dup XORPS ] }
|
2009-09-28 18:31:34 -04:00
|
|
|
{ float-4-rep [ dup XORPS ] }
|
|
|
|
[ drop dup PXOR ]
|
|
|
|
} case ;
|
|
|
|
|
|
|
|
M: x86 %zero-vector-reps
|
|
|
|
{
|
|
|
|
{ sse? { float-4-rep } }
|
|
|
|
{ sse2? { double-2-rep char-16-rep uchar-16-rep short-8-rep ushort-8-rep int-4-rep uint-4-rep longlong-2-rep ulonglong-2-rep } }
|
|
|
|
} available-reps ;
|
|
|
|
|
2009-10-02 21:04:28 -04:00
|
|
|
M: x86 %fill-vector
|
|
|
|
{
|
2009-11-01 17:09:44 -05:00
|
|
|
{ double-2-rep [ dup [ XORPS ] [ CMPEQPS ] 2bi ] }
|
2009-10-02 21:04:28 -04:00
|
|
|
{ float-4-rep [ dup [ XORPS ] [ CMPEQPS ] 2bi ] }
|
|
|
|
[ drop dup PCMPEQB ]
|
|
|
|
} case ;
|
|
|
|
|
|
|
|
M: x86 %fill-vector-reps
|
|
|
|
{
|
|
|
|
{ sse? { float-4-rep } }
|
|
|
|
{ sse2? { double-2-rep char-16-rep uchar-16-rep short-8-rep ushort-8-rep int-4-rep uint-4-rep longlong-2-rep ulonglong-2-rep } }
|
|
|
|
} available-reps ;
|
|
|
|
|
2009-09-28 06:39:53 -04:00
|
|
|
M:: x86 %gather-vector-4 ( dst src1 src2 src3 src4 rep -- )
|
2009-11-25 01:44:12 -05:00
|
|
|
rep signed-rep {
|
2009-09-28 12:24:08 -04:00
|
|
|
{ float-4-rep [
|
|
|
|
dst src1 float-4-rep %copy
|
|
|
|
dst src2 UNPCKLPS
|
|
|
|
src3 src4 UNPCKLPS
|
|
|
|
dst src3 MOVLHPS
|
|
|
|
] }
|
|
|
|
{ int-4-rep [
|
|
|
|
dst src1 int-4-rep %copy
|
|
|
|
dst src2 PUNPCKLDQ
|
|
|
|
src3 src4 PUNPCKLDQ
|
|
|
|
dst src3 PUNPCKLQDQ
|
|
|
|
] }
|
|
|
|
} case ;
|
2008-12-05 07:38:51 -05:00
|
|
|
|
2009-09-28 06:39:53 -04:00
|
|
|
M: x86 %gather-vector-4-reps
|
|
|
|
{
|
|
|
|
! Can't do this with sse1 since it will want to unbox
|
|
|
|
! double-precision floats and convert to single precision
|
2009-09-28 07:34:22 -04:00
|
|
|
{ sse2? { float-4-rep int-4-rep uint-4-rep } }
|
2009-09-28 06:39:53 -04:00
|
|
|
} available-reps ;
|
2008-10-20 06:55:57 -04:00
|
|
|
|
2009-09-28 06:39:53 -04:00
|
|
|
M:: x86 %gather-vector-2 ( dst src1 src2 rep -- )
|
2009-11-25 01:44:12 -05:00
|
|
|
rep signed-rep {
|
2009-09-28 12:24:08 -04:00
|
|
|
{ double-2-rep [
|
|
|
|
dst src1 double-2-rep %copy
|
2009-11-01 17:09:44 -05:00
|
|
|
dst src2 MOVLHPS
|
2009-09-28 12:24:08 -04:00
|
|
|
] }
|
|
|
|
{ longlong-2-rep [
|
|
|
|
dst src1 longlong-2-rep %copy
|
|
|
|
dst src2 PUNPCKLQDQ
|
|
|
|
] }
|
2009-09-28 06:39:53 -04:00
|
|
|
} case ;
|
2008-10-20 06:55:57 -04:00
|
|
|
|
2009-09-28 06:39:53 -04:00
|
|
|
M: x86 %gather-vector-2-reps
|
|
|
|
{
|
2009-09-28 12:24:08 -04:00
|
|
|
{ sse2? { double-2-rep longlong-2-rep ulonglong-2-rep } }
|
2009-09-28 06:39:53 -04:00
|
|
|
} available-reps ;
|
2008-10-20 06:55:57 -04:00
|
|
|
|
2009-10-10 13:00:47 -04:00
|
|
|
: sse1-float-4-shuffle ( dst shuffle -- )
|
2009-09-29 00:12:13 -04:00
|
|
|
{
|
|
|
|
{ { 0 1 2 3 } [ drop ] }
|
|
|
|
{ { 0 1 0 1 } [ dup MOVLHPS ] }
|
|
|
|
{ { 2 3 2 3 } [ dup MOVHLPS ] }
|
|
|
|
{ { 0 0 1 1 } [ dup UNPCKLPS ] }
|
|
|
|
{ { 2 2 3 3 } [ dup UNPCKHPS ] }
|
|
|
|
[ dupd SHUFPS ]
|
|
|
|
} case ;
|
|
|
|
|
2009-10-10 13:00:47 -04:00
|
|
|
: float-4-shuffle ( dst shuffle -- )
|
|
|
|
sse3? [
|
|
|
|
{
|
|
|
|
{ { 0 0 2 2 } [ dup MOVSLDUP ] }
|
|
|
|
{ { 1 1 3 3 } [ dup MOVSHDUP ] }
|
|
|
|
[ sse1-float-4-shuffle ]
|
|
|
|
} case
|
|
|
|
] [ sse1-float-4-shuffle ] if ;
|
|
|
|
|
2009-09-29 00:12:13 -04:00
|
|
|
: int-4-shuffle ( dst shuffle -- )
|
|
|
|
{
|
|
|
|
{ { 0 1 2 3 } [ drop ] }
|
|
|
|
{ { 0 0 1 1 } [ dup PUNPCKLDQ ] }
|
|
|
|
{ { 2 2 3 3 } [ dup PUNPCKHDQ ] }
|
|
|
|
{ { 0 1 0 1 } [ dup PUNPCKLQDQ ] }
|
|
|
|
{ { 2 3 2 3 } [ dup PUNPCKHQDQ ] }
|
|
|
|
[ dupd PSHUFD ]
|
|
|
|
} case ;
|
|
|
|
|
|
|
|
: longlong-2-shuffle ( dst shuffle -- )
|
|
|
|
first2 [ 2 * dup 1 + ] bi@ 4array int-4-shuffle ;
|
|
|
|
|
2009-11-01 17:09:44 -05:00
|
|
|
: >float-4-shuffle ( double-2-shuffle -- float-4-shuffle )
|
|
|
|
[ 2 * { 0 1 } n+v ] map concat ;
|
|
|
|
|
2009-10-09 21:46:52 -04:00
|
|
|
M:: x86 %shuffle-vector-imm ( dst src shuffle rep -- )
|
2009-09-29 00:12:13 -04:00
|
|
|
dst src rep %copy
|
2009-11-25 01:44:12 -05:00
|
|
|
dst shuffle rep signed-rep {
|
2009-11-01 17:09:44 -05:00
|
|
|
{ double-2-rep [ >float-4-shuffle float-4-shuffle ] }
|
2009-09-29 00:12:13 -04:00
|
|
|
{ float-4-rep [ float-4-shuffle ] }
|
|
|
|
{ int-4-rep [ int-4-shuffle ] }
|
|
|
|
{ longlong-2-rep [ longlong-2-shuffle ] }
|
|
|
|
} case ;
|
|
|
|
|
2009-10-09 21:46:52 -04:00
|
|
|
M: x86 %shuffle-vector-imm-reps
|
2009-09-29 00:12:13 -04:00
|
|
|
{
|
2009-09-29 05:46:38 -04:00
|
|
|
{ sse? { float-4-rep } }
|
|
|
|
{ sse2? { double-2-rep int-4-rep uint-4-rep longlong-2-rep ulonglong-2-rep } }
|
2009-09-29 00:12:13 -04:00
|
|
|
} available-reps ;
|
2009-09-28 18:31:34 -04:00
|
|
|
|
2009-10-09 21:46:52 -04:00
|
|
|
M: x86 %shuffle-vector ( dst src shuffle rep -- )
|
|
|
|
two-operand PSHUFB ;
|
|
|
|
|
|
|
|
M: x86 %shuffle-vector-reps
|
|
|
|
{
|
|
|
|
{ ssse3? { float-4-rep double-2-rep longlong-2-rep ulonglong-2-rep int-4-rep uint-4-rep short-8-rep ushort-8-rep char-16-rep uchar-16-rep } }
|
|
|
|
} available-reps ;
|
|
|
|
|
2009-10-03 22:48:53 -04:00
|
|
|
M: x86 %merge-vector-head
|
|
|
|
[ two-operand ] keep
|
2009-11-25 01:44:12 -05:00
|
|
|
signed-rep {
|
2009-11-01 17:09:44 -05:00
|
|
|
{ double-2-rep [ MOVLHPS ] }
|
2009-10-03 22:48:53 -04:00
|
|
|
{ float-4-rep [ UNPCKLPS ] }
|
|
|
|
{ longlong-2-rep [ PUNPCKLQDQ ] }
|
|
|
|
{ int-4-rep [ PUNPCKLDQ ] }
|
|
|
|
{ short-8-rep [ PUNPCKLWD ] }
|
|
|
|
{ char-16-rep [ PUNPCKLBW ] }
|
|
|
|
} case ;
|
|
|
|
|
|
|
|
M: x86 %merge-vector-tail
|
|
|
|
[ two-operand ] keep
|
2009-11-25 01:44:12 -05:00
|
|
|
signed-rep {
|
2009-10-03 22:48:53 -04:00
|
|
|
{ double-2-rep [ UNPCKHPD ] }
|
|
|
|
{ float-4-rep [ UNPCKHPS ] }
|
|
|
|
{ longlong-2-rep [ PUNPCKHQDQ ] }
|
|
|
|
{ int-4-rep [ PUNPCKHDQ ] }
|
|
|
|
{ short-8-rep [ PUNPCKHWD ] }
|
|
|
|
{ char-16-rep [ PUNPCKHBW ] }
|
|
|
|
} case ;
|
|
|
|
|
|
|
|
M: x86 %merge-vector-reps
|
|
|
|
{
|
|
|
|
{ sse? { float-4-rep } }
|
|
|
|
{ sse2? { double-2-rep char-16-rep uchar-16-rep short-8-rep ushort-8-rep int-4-rep uint-4-rep longlong-2-rep ulonglong-2-rep } }
|
|
|
|
} available-reps ;
|
|
|
|
|
2009-10-05 22:01:34 -04:00
|
|
|
M: x86 %signed-pack-vector
|
|
|
|
[ two-operand ] keep
|
|
|
|
{
|
|
|
|
{ int-4-rep [ PACKSSDW ] }
|
|
|
|
{ short-8-rep [ PACKSSWB ] }
|
|
|
|
} case ;
|
|
|
|
|
|
|
|
M: x86 %signed-pack-vector-reps
|
|
|
|
{
|
|
|
|
{ sse2? { short-8-rep int-4-rep } }
|
|
|
|
} available-reps ;
|
|
|
|
|
|
|
|
M: x86 %unsigned-pack-vector
|
|
|
|
[ two-operand ] keep
|
2009-11-25 01:44:12 -05:00
|
|
|
signed-rep {
|
2009-10-05 22:01:34 -04:00
|
|
|
{ int-4-rep [ PACKUSDW ] }
|
|
|
|
{ short-8-rep [ PACKUSWB ] }
|
|
|
|
} case ;
|
|
|
|
|
|
|
|
M: x86 %unsigned-pack-vector-reps
|
|
|
|
{
|
2009-10-07 13:00:31 -04:00
|
|
|
{ sse2? { short-8-rep } }
|
|
|
|
{ sse4.1? { int-4-rep } }
|
2009-10-05 22:01:34 -04:00
|
|
|
} available-reps ;
|
|
|
|
|
2009-10-07 15:09:46 -04:00
|
|
|
M: x86 %tail>head-vector ( dst src rep -- )
|
|
|
|
dup {
|
2009-11-01 17:09:44 -05:00
|
|
|
{ float-4-rep [ drop UNPCKHPD ] }
|
|
|
|
{ double-2-rep [ drop UNPCKHPD ] }
|
2009-10-07 15:09:46 -04:00
|
|
|
[ drop [ %copy ] [ drop PUNPCKHQDQ ] 3bi ]
|
2009-10-05 22:01:34 -04:00
|
|
|
} case ;
|
|
|
|
|
2009-10-07 15:09:46 -04:00
|
|
|
M: x86 %unpack-vector-head ( dst src rep -- )
|
|
|
|
{
|
|
|
|
{ char-16-rep [ PMOVSXBW ] }
|
|
|
|
{ uchar-16-rep [ PMOVZXBW ] }
|
|
|
|
{ short-8-rep [ PMOVSXWD ] }
|
|
|
|
{ ushort-8-rep [ PMOVZXWD ] }
|
|
|
|
{ int-4-rep [ PMOVSXDQ ] }
|
|
|
|
{ uint-4-rep [ PMOVZXDQ ] }
|
|
|
|
{ float-4-rep [ CVTPS2PD ] }
|
2009-10-05 22:01:34 -04:00
|
|
|
} case ;
|
|
|
|
|
2009-10-07 15:09:46 -04:00
|
|
|
M: x86 %unpack-vector-head-reps ( -- reps )
|
2009-10-05 22:01:34 -04:00
|
|
|
{
|
2009-10-07 15:09:46 -04:00
|
|
|
{ sse2? { float-4-rep } }
|
|
|
|
{ sse4.1? { char-16-rep uchar-16-rep short-8-rep ushort-8-rep int-4-rep uint-4-rep } }
|
2009-10-05 22:01:34 -04:00
|
|
|
} available-reps ;
|
|
|
|
|
|
|
|
M: x86 %integer>float-vector ( dst src rep -- )
|
|
|
|
{
|
|
|
|
{ int-4-rep [ CVTDQ2PS ] }
|
|
|
|
} case ;
|
|
|
|
|
|
|
|
M: x86 %integer>float-vector-reps
|
|
|
|
{
|
|
|
|
{ sse2? { int-4-rep } }
|
|
|
|
} available-reps ;
|
|
|
|
|
|
|
|
M: x86 %float>integer-vector ( dst src rep -- )
|
|
|
|
{
|
2009-10-06 14:57:54 -04:00
|
|
|
{ float-4-rep [ CVTTPS2DQ ] }
|
2009-10-05 22:01:34 -04:00
|
|
|
} case ;
|
|
|
|
|
|
|
|
M: x86 %float>integer-vector-reps
|
|
|
|
{
|
|
|
|
{ sse2? { float-4-rep } }
|
|
|
|
} available-reps ;
|
|
|
|
|
2009-10-03 00:19:56 -04:00
|
|
|
: (%compare-float-vector) ( dst src rep double single -- )
|
|
|
|
[ double-2-rep eq? ] 2dip if ; inline
|
2009-12-21 21:42:49 -05:00
|
|
|
|
2009-10-07 16:27:03 -04:00
|
|
|
: %compare-float-vector ( dst src rep cc -- )
|
|
|
|
{
|
2009-10-03 00:19:56 -04:00
|
|
|
{ cc< [ [ CMPLTPD ] [ CMPLTPS ] (%compare-float-vector) ] }
|
|
|
|
{ cc<= [ [ CMPLEPD ] [ CMPLEPS ] (%compare-float-vector) ] }
|
|
|
|
{ cc= [ [ CMPEQPD ] [ CMPEQPS ] (%compare-float-vector) ] }
|
|
|
|
{ cc<>= [ [ CMPORDPD ] [ CMPORDPS ] (%compare-float-vector) ] }
|
|
|
|
{ cc/< [ [ CMPNLTPD ] [ CMPNLTPS ] (%compare-float-vector) ] }
|
|
|
|
{ cc/<= [ [ CMPNLEPD ] [ CMPNLEPS ] (%compare-float-vector) ] }
|
|
|
|
{ cc/= [ [ CMPNEQPD ] [ CMPNEQPS ] (%compare-float-vector) ] }
|
|
|
|
{ cc/<>= [ [ CMPUNORDPD ] [ CMPUNORDPS ] (%compare-float-vector) ] }
|
2009-10-01 15:31:37 -04:00
|
|
|
} case ;
|
|
|
|
|
2009-10-03 00:19:56 -04:00
|
|
|
:: (%compare-int-vector) ( dst src rep int64 int32 int16 int8 -- )
|
2009-11-25 01:44:12 -05:00
|
|
|
rep signed-rep :> rep'
|
2009-10-03 00:19:56 -04:00
|
|
|
dst src rep' {
|
|
|
|
{ longlong-2-rep [ int64 call ] }
|
|
|
|
{ int-4-rep [ int32 call ] }
|
|
|
|
{ short-8-rep [ int16 call ] }
|
|
|
|
{ char-16-rep [ int8 call ] }
|
|
|
|
} case ; inline
|
2009-12-21 21:42:49 -05:00
|
|
|
|
2009-10-07 16:27:03 -04:00
|
|
|
: %compare-int-vector ( dst src rep cc -- )
|
|
|
|
{
|
2009-10-03 00:19:56 -04:00
|
|
|
{ cc= [ [ PCMPEQQ ] [ PCMPEQD ] [ PCMPEQW ] [ PCMPEQB ] (%compare-int-vector) ] }
|
|
|
|
{ cc> [ [ PCMPGTQ ] [ PCMPGTD ] [ PCMPGTW ] [ PCMPGTB ] (%compare-int-vector) ] }
|
2009-10-07 16:27:03 -04:00
|
|
|
} case ;
|
2009-10-03 00:19:56 -04:00
|
|
|
|
2009-10-07 16:27:03 -04:00
|
|
|
M: x86 %compare-vector ( dst src1 src2 rep cc -- )
|
|
|
|
[ [ two-operand ] keep ] dip
|
2009-10-03 00:19:56 -04:00
|
|
|
over float-vector-rep?
|
|
|
|
[ %compare-float-vector ]
|
|
|
|
[ %compare-int-vector ] if ;
|
2009-10-01 15:31:37 -04:00
|
|
|
|
2009-10-03 12:29:34 -04:00
|
|
|
: %compare-vector-eq-reps ( -- reps )
|
2009-10-01 15:31:37 -04:00
|
|
|
{
|
|
|
|
{ sse? { float-4-rep } }
|
|
|
|
{ sse2? { double-2-rep char-16-rep uchar-16-rep short-8-rep ushort-8-rep int-4-rep uint-4-rep } }
|
|
|
|
{ sse4.1? { longlong-2-rep ulonglong-2-rep } }
|
|
|
|
} available-reps ;
|
2009-12-21 21:42:49 -05:00
|
|
|
|
2009-10-03 12:29:34 -04:00
|
|
|
: %compare-vector-ord-reps ( -- reps )
|
|
|
|
{
|
|
|
|
{ sse? { float-4-rep } }
|
|
|
|
{ sse2? { double-2-rep char-16-rep short-8-rep int-4-rep } }
|
2009-10-22 00:00:02 -04:00
|
|
|
{ sse4.2? { longlong-2-rep } }
|
2009-10-03 12:29:34 -04:00
|
|
|
} available-reps ;
|
|
|
|
|
|
|
|
M: x86 %compare-vector-reps
|
|
|
|
{
|
2009-10-28 16:02:00 -04:00
|
|
|
{ [ dup { cc= cc/= cc/<>= cc<>= } member-eq? ] [ drop %compare-vector-eq-reps ] }
|
2009-10-03 12:29:34 -04:00
|
|
|
[ drop %compare-vector-ord-reps ]
|
|
|
|
} cond ;
|
2009-10-01 15:31:37 -04:00
|
|
|
|
2009-10-07 16:27:03 -04:00
|
|
|
: %compare-float-vector-ccs ( cc -- ccs not? )
|
|
|
|
{
|
|
|
|
{ cc< [ { { cc< f } } f ] }
|
|
|
|
{ cc<= [ { { cc<= f } } f ] }
|
|
|
|
{ cc> [ { { cc< t } } f ] }
|
|
|
|
{ cc>= [ { { cc<= t } } f ] }
|
|
|
|
{ cc= [ { { cc= f } } f ] }
|
|
|
|
{ cc<> [ { { cc< f } { cc< t } } f ] }
|
|
|
|
{ cc<>= [ { { cc<>= f } } f ] }
|
|
|
|
{ cc/< [ { { cc/< f } } f ] }
|
|
|
|
{ cc/<= [ { { cc/<= f } } f ] }
|
|
|
|
{ cc/> [ { { cc/< t } } f ] }
|
|
|
|
{ cc/>= [ { { cc/<= t } } f ] }
|
|
|
|
{ cc/= [ { { cc/= f } } f ] }
|
|
|
|
{ cc/<> [ { { cc/= f } { cc/<>= f } } f ] }
|
|
|
|
{ cc/<>= [ { { cc/<>= f } } f ] }
|
|
|
|
} case ;
|
|
|
|
|
|
|
|
: %compare-int-vector-ccs ( cc -- ccs not? )
|
|
|
|
order-cc {
|
|
|
|
{ cc< [ { { cc> t } } f ] }
|
|
|
|
{ cc<= [ { { cc> f } } t ] }
|
|
|
|
{ cc> [ { { cc> f } } f ] }
|
|
|
|
{ cc>= [ { { cc> t } } t ] }
|
|
|
|
{ cc= [ { { cc= f } } f ] }
|
|
|
|
{ cc/= [ { { cc= f } } t ] }
|
|
|
|
{ t [ { } t ] }
|
|
|
|
{ f [ { } f ] }
|
|
|
|
} case ;
|
|
|
|
|
|
|
|
M: x86 %compare-vector-ccs
|
|
|
|
swap float-vector-rep?
|
|
|
|
[ %compare-float-vector-ccs ]
|
|
|
|
[ %compare-int-vector-ccs ] if ;
|
|
|
|
|
2009-10-01 20:53:30 -04:00
|
|
|
:: %test-vector-mask ( dst temp mask vcc -- )
|
2009-10-01 16:35:38 -04:00
|
|
|
vcc {
|
2010-04-18 16:26:31 -04:00
|
|
|
{ vcc-any [ dst dst TEST dst temp \ CMOVNE (%boolean) ] }
|
|
|
|
{ vcc-none [ dst dst TEST dst temp \ CMOVE (%boolean) ] }
|
|
|
|
{ vcc-all [ dst mask CMP dst temp \ CMOVE (%boolean) ] }
|
|
|
|
{ vcc-notall [ dst mask CMP dst temp \ CMOVNE (%boolean) ] }
|
2009-10-01 16:35:38 -04:00
|
|
|
} case ;
|
|
|
|
|
2009-10-01 20:53:30 -04:00
|
|
|
: %move-vector-mask ( dst src rep -- mask )
|
|
|
|
{
|
2009-11-01 17:09:44 -05:00
|
|
|
{ double-2-rep [ MOVMSKPS HEX: f ] }
|
2009-10-01 16:35:38 -04:00
|
|
|
{ float-4-rep [ MOVMSKPS HEX: f ] }
|
|
|
|
[ drop PMOVMSKB HEX: ffff ]
|
2009-10-01 20:53:30 -04:00
|
|
|
} case ;
|
|
|
|
|
|
|
|
M:: x86 %test-vector ( dst src temp rep vcc -- )
|
|
|
|
dst src rep %move-vector-mask :> mask
|
|
|
|
dst temp mask vcc %test-vector-mask ;
|
|
|
|
|
|
|
|
:: %test-vector-mask-branch ( label temp mask vcc -- )
|
|
|
|
vcc {
|
|
|
|
{ vcc-any [ temp temp TEST label JNE ] }
|
|
|
|
{ vcc-none [ temp temp TEST label JE ] }
|
|
|
|
{ vcc-all [ temp mask CMP label JE ] }
|
|
|
|
{ vcc-notall [ temp mask CMP label JNE ] }
|
|
|
|
} case ;
|
|
|
|
|
|
|
|
M:: x86 %test-vector-branch ( label src temp rep vcc -- )
|
|
|
|
temp src rep %move-vector-mask :> mask
|
|
|
|
label temp mask vcc %test-vector-mask-branch ;
|
2009-10-01 16:35:38 -04:00
|
|
|
|
|
|
|
M: x86 %test-vector-reps
|
|
|
|
{
|
|
|
|
{ sse? { float-4-rep } }
|
|
|
|
{ sse2? { double-2-rep char-16-rep uchar-16-rep short-8-rep ushort-8-rep int-4-rep uint-4-rep longlong-2-rep ulonglong-2-rep } }
|
|
|
|
} available-reps ;
|
|
|
|
|
2009-09-28 06:39:53 -04:00
|
|
|
M: x86 %add-vector ( dst src1 src2 rep -- )
|
|
|
|
[ two-operand ] keep
|
|
|
|
{
|
|
|
|
{ float-4-rep [ ADDPS ] }
|
|
|
|
{ double-2-rep [ ADDPD ] }
|
|
|
|
{ char-16-rep [ PADDB ] }
|
|
|
|
{ uchar-16-rep [ PADDB ] }
|
|
|
|
{ short-8-rep [ PADDW ] }
|
|
|
|
{ ushort-8-rep [ PADDW ] }
|
|
|
|
{ int-4-rep [ PADDD ] }
|
|
|
|
{ uint-4-rep [ PADDD ] }
|
|
|
|
{ longlong-2-rep [ PADDQ ] }
|
|
|
|
{ ulonglong-2-rep [ PADDQ ] }
|
|
|
|
} case ;
|
2008-10-20 06:55:57 -04:00
|
|
|
|
2009-09-28 06:39:53 -04:00
|
|
|
M: x86 %add-vector-reps
|
|
|
|
{
|
|
|
|
{ sse? { float-4-rep } }
|
|
|
|
{ sse2? { double-2-rep char-16-rep uchar-16-rep short-8-rep ushort-8-rep int-4-rep uint-4-rep longlong-2-rep ulonglong-2-rep } }
|
|
|
|
} available-reps ;
|
2008-10-22 00:17:32 -04:00
|
|
|
|
2009-09-28 06:39:53 -04:00
|
|
|
M: x86 %saturated-add-vector ( dst src1 src2 rep -- )
|
|
|
|
[ two-operand ] keep
|
|
|
|
{
|
|
|
|
{ char-16-rep [ PADDSB ] }
|
|
|
|
{ uchar-16-rep [ PADDUSB ] }
|
|
|
|
{ short-8-rep [ PADDSW ] }
|
|
|
|
{ ushort-8-rep [ PADDUSW ] }
|
|
|
|
} case ;
|
2008-10-20 06:55:57 -04:00
|
|
|
|
2009-09-28 06:39:53 -04:00
|
|
|
M: x86 %saturated-add-vector-reps
|
|
|
|
{
|
|
|
|
{ sse2? { char-16-rep uchar-16-rep short-8-rep ushort-8-rep } }
|
|
|
|
} available-reps ;
|
2008-10-20 06:55:57 -04:00
|
|
|
|
2009-09-28 06:39:53 -04:00
|
|
|
M: x86 %add-sub-vector ( dst src1 src2 rep -- )
|
|
|
|
[ two-operand ] keep
|
|
|
|
{
|
|
|
|
{ float-4-rep [ ADDSUBPS ] }
|
|
|
|
{ double-2-rep [ ADDSUBPD ] }
|
|
|
|
} case ;
|
2008-10-20 06:55:57 -04:00
|
|
|
|
2009-09-28 06:39:53 -04:00
|
|
|
M: x86 %add-sub-vector-reps
|
|
|
|
{
|
|
|
|
{ sse3? { float-4-rep double-2-rep } }
|
|
|
|
} available-reps ;
|
2009-07-30 06:04:46 -04:00
|
|
|
|
2009-09-28 06:39:53 -04:00
|
|
|
M: x86 %sub-vector ( dst src1 src2 rep -- )
|
|
|
|
[ two-operand ] keep
|
|
|
|
{
|
|
|
|
{ float-4-rep [ SUBPS ] }
|
|
|
|
{ double-2-rep [ SUBPD ] }
|
|
|
|
{ char-16-rep [ PSUBB ] }
|
|
|
|
{ uchar-16-rep [ PSUBB ] }
|
|
|
|
{ short-8-rep [ PSUBW ] }
|
|
|
|
{ ushort-8-rep [ PSUBW ] }
|
|
|
|
{ int-4-rep [ PSUBD ] }
|
|
|
|
{ uint-4-rep [ PSUBD ] }
|
|
|
|
{ longlong-2-rep [ PSUBQ ] }
|
|
|
|
{ ulonglong-2-rep [ PSUBQ ] }
|
|
|
|
} case ;
|
2009-07-30 06:04:46 -04:00
|
|
|
|
2009-09-28 06:39:53 -04:00
|
|
|
M: x86 %sub-vector-reps
|
|
|
|
{
|
|
|
|
{ sse? { float-4-rep } }
|
|
|
|
{ sse2? { double-2-rep char-16-rep uchar-16-rep short-8-rep ushort-8-rep int-4-rep uint-4-rep longlong-2-rep ulonglong-2-rep } }
|
|
|
|
} available-reps ;
|
2009-07-30 06:04:46 -04:00
|
|
|
|
2009-09-28 06:39:53 -04:00
|
|
|
M: x86 %saturated-sub-vector ( dst src1 src2 rep -- )
|
|
|
|
[ two-operand ] keep
|
|
|
|
{
|
|
|
|
{ char-16-rep [ PSUBSB ] }
|
|
|
|
{ uchar-16-rep [ PSUBUSB ] }
|
|
|
|
{ short-8-rep [ PSUBSW ] }
|
|
|
|
{ ushort-8-rep [ PSUBUSW ] }
|
|
|
|
} case ;
|
2009-08-21 15:13:49 -04:00
|
|
|
|
2009-09-28 06:39:53 -04:00
|
|
|
M: x86 %saturated-sub-vector-reps
|
|
|
|
{
|
|
|
|
{ sse2? { char-16-rep uchar-16-rep short-8-rep ushort-8-rep } }
|
|
|
|
} available-reps ;
|
2008-10-20 06:55:57 -04:00
|
|
|
|
2009-09-28 06:39:53 -04:00
|
|
|
M: x86 %mul-vector ( dst src1 src2 rep -- )
|
|
|
|
[ two-operand ] keep
|
|
|
|
{
|
|
|
|
{ float-4-rep [ MULPS ] }
|
|
|
|
{ double-2-rep [ MULPD ] }
|
|
|
|
{ short-8-rep [ PMULLW ] }
|
|
|
|
{ ushort-8-rep [ PMULLW ] }
|
|
|
|
{ int-4-rep [ PMULLD ] }
|
|
|
|
{ uint-4-rep [ PMULLD ] }
|
|
|
|
} case ;
|
2008-10-20 06:55:57 -04:00
|
|
|
|
2009-09-28 06:39:53 -04:00
|
|
|
M: x86 %mul-vector-reps
|
|
|
|
{
|
|
|
|
{ sse? { float-4-rep } }
|
|
|
|
{ sse2? { double-2-rep short-8-rep ushort-8-rep } }
|
|
|
|
{ sse4.1? { int-4-rep uint-4-rep } }
|
|
|
|
} available-reps ;
|
2008-10-20 06:55:57 -04:00
|
|
|
|
2009-12-05 17:52:18 -05:00
|
|
|
M: x86 %mul-high-vector ( dst src1 src2 rep -- )
|
|
|
|
[ two-operand ] keep
|
|
|
|
{
|
|
|
|
{ short-8-rep [ PMULHW ] }
|
|
|
|
{ ushort-8-rep [ PMULHUW ] }
|
|
|
|
} case ;
|
|
|
|
|
|
|
|
M: x86 %mul-high-vector-reps
|
|
|
|
{
|
|
|
|
{ sse2? { short-8-rep ushort-8-rep } }
|
|
|
|
} available-reps ;
|
|
|
|
|
|
|
|
M: x86 %mul-horizontal-add-vector ( dst src1 src2 rep -- )
|
|
|
|
[ two-operand ] keep
|
|
|
|
{
|
|
|
|
{ char-16-rep [ PMADDUBSW ] }
|
|
|
|
{ uchar-16-rep [ PMADDUBSW ] }
|
|
|
|
{ short-8-rep [ PMADDWD ] }
|
|
|
|
} case ;
|
|
|
|
|
|
|
|
M: x86 %mul-horizontal-add-vector-reps
|
|
|
|
{
|
2009-12-05 20:17:16 -05:00
|
|
|
{ sse2? { short-8-rep } }
|
2009-12-05 17:52:18 -05:00
|
|
|
{ ssse3? { char-16-rep uchar-16-rep } }
|
|
|
|
} available-reps ;
|
|
|
|
|
2009-09-28 06:39:53 -04:00
|
|
|
M: x86 %div-vector ( dst src1 src2 rep -- )
|
|
|
|
[ two-operand ] keep
|
|
|
|
{
|
|
|
|
{ float-4-rep [ DIVPS ] }
|
|
|
|
{ double-2-rep [ DIVPD ] }
|
|
|
|
} case ;
|
2008-10-20 06:55:57 -04:00
|
|
|
|
2009-09-28 06:39:53 -04:00
|
|
|
M: x86 %div-vector-reps
|
|
|
|
{
|
|
|
|
{ sse? { float-4-rep } }
|
|
|
|
{ sse2? { double-2-rep } }
|
|
|
|
} available-reps ;
|
2007-09-20 18:09:08 -04:00
|
|
|
|
2009-09-28 06:39:53 -04:00
|
|
|
M: x86 %min-vector ( dst src1 src2 rep -- )
|
|
|
|
[ two-operand ] keep
|
|
|
|
{
|
|
|
|
{ char-16-rep [ PMINSB ] }
|
|
|
|
{ uchar-16-rep [ PMINUB ] }
|
|
|
|
{ short-8-rep [ PMINSW ] }
|
|
|
|
{ ushort-8-rep [ PMINUW ] }
|
|
|
|
{ int-4-rep [ PMINSD ] }
|
|
|
|
{ uint-4-rep [ PMINUD ] }
|
|
|
|
{ float-4-rep [ MINPS ] }
|
|
|
|
{ double-2-rep [ MINPD ] }
|
|
|
|
} case ;
|
|
|
|
|
|
|
|
M: x86 %min-vector-reps
|
|
|
|
{
|
|
|
|
{ sse? { float-4-rep } }
|
2009-10-20 23:30:57 -04:00
|
|
|
{ sse2? { uchar-16-rep short-8-rep double-2-rep } }
|
2009-09-28 06:39:53 -04:00
|
|
|
{ sse4.1? { char-16-rep ushort-8-rep int-4-rep uint-4-rep } }
|
|
|
|
} available-reps ;
|
2009-08-20 15:45:06 -04:00
|
|
|
|
2009-09-28 06:39:53 -04:00
|
|
|
M: x86 %max-vector ( dst src1 src2 rep -- )
|
|
|
|
[ two-operand ] keep
|
|
|
|
{
|
|
|
|
{ char-16-rep [ PMAXSB ] }
|
|
|
|
{ uchar-16-rep [ PMAXUB ] }
|
|
|
|
{ short-8-rep [ PMAXSW ] }
|
|
|
|
{ ushort-8-rep [ PMAXUW ] }
|
|
|
|
{ int-4-rep [ PMAXSD ] }
|
|
|
|
{ uint-4-rep [ PMAXUD ] }
|
|
|
|
{ float-4-rep [ MAXPS ] }
|
|
|
|
{ double-2-rep [ MAXPD ] }
|
|
|
|
} case ;
|
2008-10-20 06:55:57 -04:00
|
|
|
|
2009-09-28 06:39:53 -04:00
|
|
|
M: x86 %max-vector-reps
|
|
|
|
{
|
|
|
|
{ sse? { float-4-rep } }
|
2009-10-20 23:30:57 -04:00
|
|
|
{ sse2? { uchar-16-rep short-8-rep double-2-rep } }
|
2009-09-28 06:39:53 -04:00
|
|
|
{ sse4.1? { char-16-rep ushort-8-rep int-4-rep uint-4-rep } }
|
|
|
|
} available-reps ;
|
2008-10-20 06:55:57 -04:00
|
|
|
|
2009-12-05 17:52:18 -05:00
|
|
|
M: x86 %avg-vector ( dst src1 src2 rep -- )
|
|
|
|
[ two-operand ] keep
|
|
|
|
{
|
|
|
|
{ uchar-16-rep [ PAVGB ] }
|
|
|
|
{ ushort-8-rep [ PAVGW ] }
|
|
|
|
} case ;
|
|
|
|
|
|
|
|
M: x86 %avg-vector-reps
|
|
|
|
{
|
|
|
|
{ sse2? { uchar-16-rep ushort-8-rep } }
|
|
|
|
} available-reps ;
|
|
|
|
|
2009-09-28 18:31:34 -04:00
|
|
|
M: x86 %dot-vector
|
|
|
|
[ two-operand ] keep
|
|
|
|
{
|
2009-11-05 10:52:57 -05:00
|
|
|
{ float-4-rep [ HEX: ff DPPS ] }
|
|
|
|
{ double-2-rep [ HEX: ff DPPD ] }
|
2009-09-28 18:31:34 -04:00
|
|
|
} case ;
|
|
|
|
|
|
|
|
M: x86 %dot-vector-reps
|
|
|
|
{
|
2009-11-05 10:52:57 -05:00
|
|
|
{ sse4.1? { float-4-rep double-2-rep } }
|
2009-09-28 18:31:34 -04:00
|
|
|
} available-reps ;
|
|
|
|
|
2009-12-05 17:52:18 -05:00
|
|
|
M: x86 %sad-vector
|
|
|
|
[ two-operand ] keep
|
|
|
|
{
|
|
|
|
{ uchar-16-rep [ PSADBW ] }
|
|
|
|
} case ;
|
|
|
|
|
|
|
|
M: x86 %sad-vector-reps
|
|
|
|
{
|
2009-12-05 20:17:16 -05:00
|
|
|
{ sse2? { uchar-16-rep } }
|
2009-12-05 17:52:18 -05:00
|
|
|
} available-reps ;
|
|
|
|
|
2009-11-04 13:18:01 -05:00
|
|
|
M: x86 %horizontal-add-vector ( dst src1 src2 rep -- )
|
|
|
|
[ two-operand ] keep
|
2009-11-25 01:44:12 -05:00
|
|
|
signed-rep {
|
2009-11-04 13:18:01 -05:00
|
|
|
{ float-4-rep [ HADDPS ] }
|
|
|
|
{ double-2-rep [ HADDPD ] }
|
|
|
|
{ int-4-rep [ PHADDD ] }
|
|
|
|
{ short-8-rep [ PHADDW ] }
|
2009-09-28 06:39:53 -04:00
|
|
|
} case ;
|
2009-06-02 19:23:47 -04:00
|
|
|
|
2009-09-28 06:39:53 -04:00
|
|
|
M: x86 %horizontal-add-vector-reps
|
|
|
|
{
|
|
|
|
{ sse3? { float-4-rep double-2-rep } }
|
2009-11-04 13:18:01 -05:00
|
|
|
{ ssse3? { int-4-rep uint-4-rep short-8-rep ushort-8-rep } }
|
2009-09-28 06:39:53 -04:00
|
|
|
} available-reps ;
|
2009-06-02 19:23:47 -04:00
|
|
|
|
2009-10-30 01:41:19 -04:00
|
|
|
M: x86 %horizontal-shl-vector-imm ( dst src1 src2 rep -- )
|
2009-09-28 06:39:53 -04:00
|
|
|
two-operand PSLLDQ ;
|
2009-06-02 19:23:47 -04:00
|
|
|
|
2009-10-30 01:41:19 -04:00
|
|
|
M: x86 %horizontal-shl-vector-imm-reps
|
2009-09-28 06:39:53 -04:00
|
|
|
{
|
2009-11-03 22:38:29 -05:00
|
|
|
{ sse2? { char-16-rep uchar-16-rep short-8-rep ushort-8-rep int-4-rep uint-4-rep longlong-2-rep ulonglong-2-rep float-4-rep double-2-rep } }
|
2009-09-28 06:39:53 -04:00
|
|
|
} available-reps ;
|
2008-12-06 10:16:29 -05:00
|
|
|
|
2009-10-30 01:41:19 -04:00
|
|
|
M: x86 %horizontal-shr-vector-imm ( dst src1 src2 rep -- )
|
2009-09-28 06:39:53 -04:00
|
|
|
two-operand PSRLDQ ;
|
2007-09-20 18:09:08 -04:00
|
|
|
|
2009-10-30 01:41:19 -04:00
|
|
|
M: x86 %horizontal-shr-vector-imm-reps
|
2009-09-28 06:39:53 -04:00
|
|
|
{
|
2009-11-03 22:38:29 -05:00
|
|
|
{ sse2? { char-16-rep uchar-16-rep short-8-rep ushort-8-rep int-4-rep uint-4-rep longlong-2-rep ulonglong-2-rep float-4-rep double-2-rep } }
|
2009-09-28 06:39:53 -04:00
|
|
|
} available-reps ;
|
2008-10-21 04:21:29 -04:00
|
|
|
|
2009-09-28 06:39:53 -04:00
|
|
|
M: x86 %abs-vector ( dst src rep -- )
|
|
|
|
{
|
|
|
|
{ char-16-rep [ PABSB ] }
|
|
|
|
{ short-8-rep [ PABSW ] }
|
|
|
|
{ int-4-rep [ PABSD ] }
|
2008-10-21 04:21:29 -04:00
|
|
|
} case ;
|
|
|
|
|
2009-09-28 06:39:53 -04:00
|
|
|
M: x86 %abs-vector-reps
|
|
|
|
{
|
|
|
|
{ ssse3? { char-16-rep short-8-rep int-4-rep } }
|
|
|
|
} available-reps ;
|
2008-10-21 04:21:29 -04:00
|
|
|
|
2009-09-28 06:39:53 -04:00
|
|
|
M: x86 %sqrt-vector ( dst src rep -- )
|
|
|
|
{
|
|
|
|
{ float-4-rep [ SQRTPS ] }
|
|
|
|
{ double-2-rep [ SQRTPD ] }
|
|
|
|
} case ;
|
2009-09-03 21:32:05 -04:00
|
|
|
|
2009-09-28 06:39:53 -04:00
|
|
|
M: x86 %sqrt-vector-reps
|
|
|
|
{
|
|
|
|
{ sse? { float-4-rep } }
|
|
|
|
{ sse2? { double-2-rep } }
|
|
|
|
} available-reps ;
|
2009-09-03 21:32:05 -04:00
|
|
|
|
2009-09-28 06:39:53 -04:00
|
|
|
M: x86 %and-vector ( dst src1 src2 rep -- )
|
|
|
|
[ two-operand ] keep
|
|
|
|
{
|
|
|
|
{ float-4-rep [ ANDPS ] }
|
2009-11-01 17:09:44 -05:00
|
|
|
{ double-2-rep [ ANDPS ] }
|
2009-09-28 06:39:53 -04:00
|
|
|
[ drop PAND ]
|
|
|
|
} case ;
|
2009-09-03 21:32:05 -04:00
|
|
|
|
2009-09-28 06:39:53 -04:00
|
|
|
M: x86 %and-vector-reps
|
|
|
|
{
|
|
|
|
{ sse? { float-4-rep } }
|
|
|
|
{ sse2? { double-2-rep char-16-rep uchar-16-rep short-8-rep ushort-8-rep int-4-rep uint-4-rep longlong-2-rep ulonglong-2-rep } }
|
|
|
|
} available-reps ;
|
2009-09-03 21:32:05 -04:00
|
|
|
|
2009-09-28 06:39:53 -04:00
|
|
|
M: x86 %andn-vector ( dst src1 src2 rep -- )
|
|
|
|
[ two-operand ] keep
|
|
|
|
{
|
|
|
|
{ float-4-rep [ ANDNPS ] }
|
2009-11-01 17:09:44 -05:00
|
|
|
{ double-2-rep [ ANDNPS ] }
|
2009-09-28 06:39:53 -04:00
|
|
|
[ drop PANDN ]
|
|
|
|
} case ;
|
2009-09-08 18:04:26 -04:00
|
|
|
|
2009-09-28 06:39:53 -04:00
|
|
|
M: x86 %andn-vector-reps
|
|
|
|
{
|
|
|
|
{ sse? { float-4-rep } }
|
|
|
|
{ sse2? { double-2-rep char-16-rep uchar-16-rep short-8-rep ushort-8-rep int-4-rep uint-4-rep longlong-2-rep ulonglong-2-rep } }
|
|
|
|
} available-reps ;
|
2009-09-08 18:04:26 -04:00
|
|
|
|
2009-09-28 06:39:53 -04:00
|
|
|
M: x86 %or-vector ( dst src1 src2 rep -- )
|
|
|
|
[ two-operand ] keep
|
|
|
|
{
|
|
|
|
{ float-4-rep [ ORPS ] }
|
2009-11-01 17:09:44 -05:00
|
|
|
{ double-2-rep [ ORPS ] }
|
2009-09-28 06:39:53 -04:00
|
|
|
[ drop POR ]
|
|
|
|
} case ;
|
2008-10-21 04:21:29 -04:00
|
|
|
|
2009-09-28 06:39:53 -04:00
|
|
|
M: x86 %or-vector-reps
|
|
|
|
{
|
|
|
|
{ sse? { float-4-rep } }
|
|
|
|
{ sse2? { double-2-rep char-16-rep uchar-16-rep short-8-rep ushort-8-rep int-4-rep uint-4-rep longlong-2-rep ulonglong-2-rep } }
|
|
|
|
} available-reps ;
|
|
|
|
|
|
|
|
M: x86 %xor-vector ( dst src1 src2 rep -- )
|
|
|
|
[ two-operand ] keep
|
|
|
|
{
|
|
|
|
{ float-4-rep [ XORPS ] }
|
2009-11-01 17:09:44 -05:00
|
|
|
{ double-2-rep [ XORPS ] }
|
2009-09-28 06:39:53 -04:00
|
|
|
[ drop PXOR ]
|
2008-10-20 06:55:57 -04:00
|
|
|
} case ;
|
|
|
|
|
2009-09-28 06:39:53 -04:00
|
|
|
M: x86 %xor-vector-reps
|
|
|
|
{
|
|
|
|
{ sse? { float-4-rep } }
|
|
|
|
{ sse2? { double-2-rep char-16-rep uchar-16-rep short-8-rep ushort-8-rep int-4-rep uint-4-rep longlong-2-rep ulonglong-2-rep } }
|
|
|
|
} available-reps ;
|
2008-10-20 06:55:57 -04:00
|
|
|
|
2009-09-28 06:39:53 -04:00
|
|
|
M: x86 %shl-vector ( dst src1 src2 rep -- )
|
|
|
|
[ two-operand ] keep
|
|
|
|
{
|
|
|
|
{ short-8-rep [ PSLLW ] }
|
|
|
|
{ ushort-8-rep [ PSLLW ] }
|
|
|
|
{ int-4-rep [ PSLLD ] }
|
|
|
|
{ uint-4-rep [ PSLLD ] }
|
|
|
|
{ longlong-2-rep [ PSLLQ ] }
|
|
|
|
{ ulonglong-2-rep [ PSLLQ ] }
|
|
|
|
} case ;
|
2009-09-03 21:32:05 -04:00
|
|
|
|
2009-09-28 06:39:53 -04:00
|
|
|
M: x86 %shl-vector-reps
|
|
|
|
{
|
|
|
|
{ sse2? { short-8-rep ushort-8-rep int-4-rep uint-4-rep longlong-2-rep ulonglong-2-rep } }
|
|
|
|
} available-reps ;
|
2009-09-03 21:32:05 -04:00
|
|
|
|
2009-09-28 06:39:53 -04:00
|
|
|
M: x86 %shr-vector ( dst src1 src2 rep -- )
|
|
|
|
[ two-operand ] keep
|
|
|
|
{
|
|
|
|
{ short-8-rep [ PSRAW ] }
|
|
|
|
{ ushort-8-rep [ PSRLW ] }
|
|
|
|
{ int-4-rep [ PSRAD ] }
|
|
|
|
{ uint-4-rep [ PSRLD ] }
|
|
|
|
{ ulonglong-2-rep [ PSRLQ ] }
|
2008-10-20 06:55:57 -04:00
|
|
|
} case ;
|
2007-09-20 18:09:08 -04:00
|
|
|
|
2009-09-28 06:39:53 -04:00
|
|
|
M: x86 %shr-vector-reps
|
|
|
|
{
|
|
|
|
{ sse2? { short-8-rep ushort-8-rep int-4-rep uint-4-rep ulonglong-2-rep } }
|
|
|
|
} available-reps ;
|
2009-09-08 18:04:26 -04:00
|
|
|
|
2009-10-30 01:41:19 -04:00
|
|
|
M: x86 %shl-vector-imm %shl-vector ;
|
|
|
|
M: x86 %shl-vector-imm-reps %shl-vector-reps ;
|
|
|
|
M: x86 %shr-vector-imm %shr-vector ;
|
|
|
|
M: x86 %shr-vector-imm-reps %shr-vector-reps ;
|
|
|
|
|
2009-09-30 06:00:36 -04:00
|
|
|
: scalar-sized-reg ( reg rep -- reg' )
|
|
|
|
rep-size 8 * n-bit-version-of ;
|
|
|
|
|
2009-09-30 21:04:37 -04:00
|
|
|
M: x86 %integer>scalar drop MOVD ;
|
|
|
|
|
2009-12-05 18:38:43 -05:00
|
|
|
:: %scalar>integer-32 ( dst src rep -- )
|
2009-09-30 21:04:37 -04:00
|
|
|
rep {
|
|
|
|
{ int-scalar-rep [
|
|
|
|
dst 32-bit-version-of src MOVD
|
|
|
|
dst dst 32-bit-version-of
|
|
|
|
2dup eq? [ 2drop ] [ MOVSX ] if
|
|
|
|
] }
|
|
|
|
{ uint-scalar-rep [
|
|
|
|
dst 32-bit-version-of src MOVD
|
|
|
|
] }
|
2009-10-09 21:46:52 -04:00
|
|
|
{ short-scalar-rep [
|
|
|
|
dst 32-bit-version-of src MOVD
|
|
|
|
dst dst 16-bit-version-of MOVSX
|
|
|
|
] }
|
|
|
|
{ ushort-scalar-rep [
|
|
|
|
dst 32-bit-version-of src MOVD
|
|
|
|
dst dst 16-bit-version-of MOVZX
|
|
|
|
] }
|
|
|
|
{ char-scalar-rep [
|
|
|
|
dst 32-bit-version-of src MOVD
|
|
|
|
dst { } 8 [| tmp-dst |
|
|
|
|
tmp-dst dst int-rep %copy
|
|
|
|
tmp-dst tmp-dst 8-bit-version-of MOVSX
|
|
|
|
dst tmp-dst int-rep %copy
|
|
|
|
] with-small-register
|
|
|
|
] }
|
|
|
|
{ uchar-scalar-rep [
|
2009-10-10 11:39:23 -04:00
|
|
|
dst 32-bit-version-of src MOVD
|
2009-10-09 21:46:52 -04:00
|
|
|
dst { } 8 [| tmp-dst |
|
|
|
|
tmp-dst dst int-rep %copy
|
|
|
|
tmp-dst tmp-dst 8-bit-version-of MOVZX
|
|
|
|
dst tmp-dst int-rep %copy
|
|
|
|
] with-small-register
|
|
|
|
] }
|
2009-09-30 21:04:37 -04:00
|
|
|
} case ;
|
|
|
|
|
2009-12-05 18:38:43 -05:00
|
|
|
M: x86.32 %scalar>integer ( dst src rep -- ) %scalar>integer-32 ;
|
2009-12-21 21:42:49 -05:00
|
|
|
|
2009-12-05 18:38:43 -05:00
|
|
|
M: x86.64 %scalar>integer ( dst src rep -- )
|
|
|
|
{
|
|
|
|
{ longlong-scalar-rep [ MOVD ] }
|
|
|
|
{ ulonglong-scalar-rep [ MOVD ] }
|
|
|
|
[ %scalar>integer-32 ]
|
|
|
|
} case ;
|
|
|
|
|
2009-09-29 05:46:38 -04:00
|
|
|
M: x86 %vector>scalar %copy ;
|
|
|
|
M: x86 %scalar>vector %copy ;
|
2009-09-08 18:04:26 -04:00
|
|
|
|
2009-09-27 20:28:20 -04:00
|
|
|
M:: x86 %spill ( src rep dst -- ) dst src rep %copy ;
|
|
|
|
M:: x86 %reload ( dst rep src -- ) dst src rep %copy ;
|
2008-10-20 06:55:57 -04:00
|
|
|
|
2008-11-05 05:15:48 -05:00
|
|
|
M: x86 %loop-entry 16 code-alignment [ NOP ] times ;
|
2008-11-03 07:20:51 -05:00
|
|
|
|
2010-01-05 21:47:36 -05:00
|
|
|
M:: x86 %restore-context ( temp1 temp2 -- )
|
2010-01-02 07:03:30 -05:00
|
|
|
#! Load Factor stack pointers on entry from C to Factor.
|
2010-04-01 20:06:18 -04:00
|
|
|
temp1 %context
|
2010-01-05 21:47:36 -05:00
|
|
|
ds-reg temp1 "datastack" context-field-offset [+] MOV
|
|
|
|
rs-reg temp1 "retainstack" context-field-offset [+] MOV ;
|
2010-01-02 07:03:30 -05:00
|
|
|
|
2009-12-21 21:42:49 -05:00
|
|
|
M:: x86 %save-context ( temp1 temp2 -- )
|
2008-10-20 06:55:57 -04:00
|
|
|
#! Save Factor stack pointers in case the C code calls a
|
|
|
|
#! callback which does a GC, which must reliably trace
|
|
|
|
#! all roots.
|
2010-04-01 20:06:18 -04:00
|
|
|
temp1 %context
|
2009-09-08 22:50:55 -04:00
|
|
|
temp2 stack-reg cell neg [+] LEA
|
2010-01-05 21:47:36 -05:00
|
|
|
temp1 "callstack-top" context-field-offset [+] temp2 MOV
|
|
|
|
temp1 "datastack" context-field-offset [+] ds-reg MOV
|
|
|
|
temp1 "retainstack" context-field-offset [+] rs-reg MOV ;
|
2008-10-20 06:55:57 -04:00
|
|
|
|
2008-11-17 14:34:37 -05:00
|
|
|
M: x86 value-struct? drop t ;
|
2008-10-20 06:55:57 -04:00
|
|
|
|
2009-10-19 05:58:29 -04:00
|
|
|
M: x86 immediate-arithmetic? ( n -- ? )
|
|
|
|
HEX: -80000000 HEX: 7fffffff between? ;
|
|
|
|
|
|
|
|
M: x86 immediate-bitwise? ( n -- ? )
|
2008-10-20 06:55:57 -04:00
|
|
|
HEX: -80000000 HEX: 7fffffff between? ;
|
|
|
|
|
|
|
|
: next-stack@ ( n -- operand )
|
|
|
|
#! nth parameter from the next stack frame. Used to box
|
|
|
|
#! input values to callbacks; the callback has its own
|
|
|
|
#! stack frame set up, and we want to read the frame
|
|
|
|
#! set up by the caller.
|
2010-01-02 07:03:30 -05:00
|
|
|
frame-reg swap 2 cells + [+] ;
|
2009-08-28 06:21:16 -04:00
|
|
|
|
2009-09-21 00:18:07 -04:00
|
|
|
enable-min/max
|
|
|
|
enable-fixnum-log2
|
2009-09-03 04:28:38 -04:00
|
|
|
|
2009-09-21 00:16:02 -04:00
|
|
|
:: install-sse2-check ( -- )
|
2009-09-20 03:08:32 -04:00
|
|
|
[
|
2009-09-21 00:16:02 -04:00
|
|
|
sse-version 20 < [
|
|
|
|
"This image was built to use SSE2 but your CPU does not support it." print
|
2009-09-20 03:08:32 -04:00
|
|
|
"You will need to bootstrap Factor again." print
|
|
|
|
flush
|
|
|
|
1 exit
|
|
|
|
] when
|
2009-10-19 22:17:02 -04:00
|
|
|
] "cpu.x86" add-startup-hook ;
|
2009-09-20 03:08:32 -04:00
|
|
|
|
2009-09-21 00:16:02 -04:00
|
|
|
: enable-sse2 ( version -- )
|
|
|
|
20 >= [
|
|
|
|
enable-float-intrinsics
|
2009-09-27 19:06:30 -04:00
|
|
|
enable-float-functions
|
2009-09-28 03:27:55 -04:00
|
|
|
enable-float-min/max
|
|
|
|
enable-fsqrt
|
2009-09-21 00:16:02 -04:00
|
|
|
install-sse2-check
|
|
|
|
] when ;
|
|
|
|
|
2009-09-20 18:43:16 -04:00
|
|
|
: check-sse ( -- )
|
2010-01-07 00:30:01 -05:00
|
|
|
[ { (sse-version) } compile ] with-optimizer
|
2009-09-21 00:16:02 -04:00
|
|
|
"Checking for multimedia extensions: " write sse-version
|
|
|
|
[ sse-string write " detected" print ] [ enable-sse2 ] bi ;
|