1 ! Copyright (C) 2005, 2009 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors assocs alien alien.c-types arrays strings
4 cpu.x86.assembler cpu.x86.assembler.private cpu.x86.assembler.operands
5 cpu.x86.features cpu.x86.features.private cpu.architecture kernel
6 kernel.private math memory namespaces make sequences words system
7 layouts combinators math.order math.vectors fry locals compiler.constants
8 byte-arrays io macros quotations compiler compiler.units init vm
10 compiler.cfg.instructions
11 compiler.cfg.intrinsics
12 compiler.cfg.comparisons
13 compiler.cfg.stack-frame
14 compiler.codegen.fixup ;
15 FROM: layouts => cell ;
19 ! Add some methods to the assembler to be more useful to the backend
20 M: label JMP 0 JMP rc-relative label-fixup ;
21 M: label JUMPcc [ 0 ] dip JUMPcc rc-relative label-fixup ;
23 M: x86 vector-regs float-regs ;
25 HOOK: stack-reg cpu ( -- reg )
27 HOOK: reserved-stack-space cpu ( -- n )
29 HOOK: extra-stack-space cpu ( stack-frame -- n )
31 : stack@ ( n -- op ) stack-reg swap [+] ;
33 : special@ ( n -- op )
34 stack-frame get extra-stack-space +
35 reserved-stack-space +
38 : spill@ ( n -- op ) spill-offset special@ ;
40 : gc-root@ ( n -- op ) gc-root-offset special@ ;
42 : decr-stack-reg ( n -- )
43 dup 0 = [ drop ] [ stack-reg swap SUB ] if ;
45 : incr-stack-reg ( n -- )
46 dup 0 = [ drop ] [ stack-reg swap ADD ] if ;
48 : align-stack ( n -- n' ) 16 align ;
50 M: x86 stack-frame-size ( stack-frame -- i )
51 [ (stack-frame-size) ]
52 [ extra-stack-space ] bi +
53 reserved-stack-space +
57 ! Must be a volatile register not used for parameter passing, for safe
58 ! use in calls in and out of C
59 HOOK: temp-reg cpu ( -- reg )
61 HOOK: pic-tail-reg cpu ( -- reg )
63 M: x86 %load-immediate dup 0 = [ drop dup XOR ] [ MOV ] if ;
65 M: x86 %load-reference swap 0 MOV rc-absolute-cell rel-immediate ;
67 HOOK: ds-reg cpu ( -- reg )
68 HOOK: rs-reg cpu ( -- reg )
70 : reg-stack ( n reg -- op ) swap cells neg [+] ;
72 GENERIC: loc>operand ( loc -- operand )
74 M: ds-loc loc>operand n>> ds-reg reg-stack ;
75 M: rs-loc loc>operand n>> rs-reg reg-stack ;
77 M: x86 %peek loc>operand MOV ;
78 M: x86 %replace loc>operand swap MOV ;
79 : (%inc) ( n reg -- ) swap cells dup 0 > [ ADD ] [ neg SUB ] if ; inline
80 M: x86 %inc-d ( n -- ) ds-reg (%inc) ;
81 M: x86 %inc-r ( n -- ) rs-reg (%inc) ;
83 M: x86 %call ( word -- ) 0 CALL rc-relative rel-word-pic ;
85 : xt-tail-pic-offset ( -- n )
86 #! See the comment in vm/cpu-x86.hpp
89 M: x86 %jump ( word -- )
90 pic-tail-reg 0 MOV xt-tail-pic-offset rc-absolute-cell rel-here
91 0 JMP rc-relative rel-word-pic-tail ;
93 M: x86 %jump-label ( label -- ) 0 JMP rc-relative label-fixup ;
95 M: x86 %return ( -- ) 0 RET ;
97 : code-alignment ( align -- n )
98 [ building get length dup ] dip align swap - ;
100 : align-code ( n -- )
103 :: (%slot-imm) ( obj slot tag -- op )
104 obj slot tag slot-offset [+] ; inline
106 M: x86 %slot ( dst obj slot -- ) [+] MOV ;
107 M: x86 %slot-imm ( dst obj slot tag -- ) (%slot-imm) MOV ;
108 M: x86 %set-slot ( src obj slot -- ) [+] swap MOV ;
109 M: x86 %set-slot-imm ( src obj slot tag -- ) (%slot-imm) swap MOV ;
111 :: two-operand ( dst src1 src2 rep -- dst src )
112 dst src2 eq? dst src1 eq? not and [ "Cannot handle this case" throw ] when
116 :: one-operand ( dst src rep -- dst )
120 M: x86 %add 2over eq? [ nip ADD ] [ [+] LEA ] if ;
121 M: x86 %add-imm 2over eq? [ nip ADD ] [ [+] LEA ] if ;
122 M: x86 %sub int-rep two-operand SUB ;
123 M: x86 %sub-imm 2over eq? [ nip SUB ] [ neg [+] LEA ] if ;
124 M: x86 %mul int-rep two-operand swap IMUL2 ;
125 M: x86 %mul-imm IMUL3 ;
126 M: x86 %and int-rep two-operand AND ;
127 M: x86 %and-imm int-rep two-operand AND ;
128 M: x86 %or int-rep two-operand OR ;
129 M: x86 %or-imm int-rep two-operand OR ;
130 M: x86 %xor int-rep two-operand XOR ;
131 M: x86 %xor-imm int-rep two-operand XOR ;
132 M: x86 %shl-imm int-rep two-operand SHL ;
133 M: x86 %shr-imm int-rep two-operand SHR ;
134 M: x86 %sar-imm int-rep two-operand SAR ;
136 M: x86 %min int-rep two-operand [ CMP ] [ CMOVG ] 2bi ;
137 M: x86 %max int-rep two-operand [ CMP ] [ CMOVL ] 2bi ;
139 M: x86 %not int-rep one-operand NOT ;
140 M: x86 %neg int-rep one-operand NEG ;
143 ! A bit of logic to avoid using MOVSS/MOVSD for reg-reg moves
144 ! since this induces partial register stalls
145 GENERIC: copy-register* ( dst src rep -- )
146 GENERIC: copy-memory* ( dst src rep -- )
148 M: int-rep copy-register* drop MOV ;
149 M: tagged-rep copy-register* drop MOV ;
150 M: float-rep copy-register* drop MOVAPS ;
151 M: double-rep copy-register* drop MOVAPS ;
152 M: float-4-rep copy-register* drop MOVAPS ;
153 M: double-2-rep copy-register* drop MOVAPS ;
154 M: vector-rep copy-register* drop MOVDQA ;
156 M: object copy-memory* copy-register* ;
157 M: float-rep copy-memory* drop MOVSS ;
158 M: double-rep copy-memory* drop MOVSD ;
160 M: x86 %copy ( dst src rep -- )
161 2over eq? [ 3drop ] [
162 [ [ dup spill-slot? [ n>> spill@ ] when ] bi@ ] dip
163 2over [ register? ] both? [ copy-register* ] [ copy-memory* ] if
166 M: x86 %fixnum-add ( label dst src1 src2 -- )
167 int-rep two-operand ADD JO ;
169 M: x86 %fixnum-sub ( label dst src1 src2 -- )
170 int-rep two-operand SUB JO ;
172 M: x86 %fixnum-mul ( label dst src1 src2 -- )
173 int-rep two-operand swap IMUL2 JO ;
175 M: x86 %unbox-alien ( dst src -- )
176 alien-offset [+] MOV ;
178 M:: x86 %unbox-any-c-ptr ( dst src -- )
183 src \ f type-number CMP
185 ! Compute tag in dst register
188 ! Is the object an alien?
189 dst alien type-number CMP
190 ! Add an offset to start of byte array's data
191 dst src byte-array-offset [+] LEA
193 ! If so, load the offset and add it to the address
194 dst src alien-offset [+] MOV
198 : alien@ ( reg n -- op ) cells alien type-number - [+] ;
200 M:: x86 %box-alien ( dst src temp -- )
203 dst \ f type-number MOV
206 dst 5 cells alien temp %allot
207 dst 1 alien@ \ f type-number MOV ! base
208 dst 2 alien@ \ f type-number MOV ! expired
209 dst 3 alien@ src MOV ! displacement
210 dst 4 alien@ src MOV ! address
214 M:: x86 %box-displaced-alien ( dst displacement base temp base-class -- )
219 "not-alien" define-label
221 ! If displacement is zero, return the base
223 displacement displacement TEST
226 ! Displacement is non-zero, we're going to be allocating a new
228 dst 5 cells alien temp %allot
231 dst 2 alien@ \ f type-number MOV
234 base \ f type-number CMP
237 ! Yes, it is f. Fill in new object
238 dst 1 alien@ base MOV
239 dst 3 alien@ displacement MOV
240 dst 4 alien@ displacement MOV
244 "not-f" resolve-label
248 temp tag-mask get AND
251 temp alien type-number CMP
254 ! Yes, it is an alien. Set new alien's base to base.base
255 temp base 1 alien@ MOV
256 dst 1 alien@ temp MOV
258 ! Compute displacement
259 temp base 3 alien@ MOV
260 temp displacement ADD
261 dst 3 alien@ temp MOV
264 temp base 4 alien@ MOV
265 temp displacement ADD
266 dst 4 alien@ temp MOV
271 ! Is base a byte array? It has to be, by now...
272 "not-alien" resolve-label
274 dst 1 alien@ base MOV
275 dst 3 alien@ displacement MOV
277 temp byte-array-offset ADD
278 temp displacement ADD
279 dst 4 alien@ temp MOV
284 ! The 'small-reg' mess is pretty crappy, but its only used on x86-32.
285 ! On x86-64, all registers have 8-bit versions. However, a similar
286 ! problem arises for shifts, where the shift count must be in CL, and
287 ! so one day I will fix this properly by adding precoloring to the
288 ! register allocator.
290 HOOK: has-small-reg? cpu ( reg size -- ? )
292 CONSTANT: have-byte-regs { EAX ECX EDX EBX }
294 M: x86.32 has-small-reg?
296 { 8 [ have-byte-regs member-eq? ] }
301 M: x86.64 has-small-reg? 2drop t ;
303 : small-reg-that-isn't ( exclude -- reg' )
304 [ have-byte-regs ] dip
305 [ native-version-of ] map
306 '[ _ member-eq? not ] find nip ;
308 : with-save/restore ( reg quot -- )
309 [ drop PUSH ] [ call ] [ drop POP ] 2tri ; inline
311 :: with-small-register ( dst exclude size quot: ( new-dst -- ) -- )
312 ! If the destination register overlaps a small register with
313 ! 'size' bits, we call the quot with that. Otherwise, we find a
314 ! small register that is not in exclude, and call quot, saving and
315 ! restoring the small register.
316 dst size has-small-reg? [ dst quot call ] [
317 exclude small-reg-that-isn't
318 [ quot call ] with-save/restore
321 M:: x86 %string-nth ( dst src index temp -- )
322 ! We request a small-reg of size 8 since those of size 16 are
325 dst { src index temp } 8 [| new-dst |
326 ! Load the least significant 7 bits into new-dst.
327 ! 8th bit indicates whether we have to load from
328 ! the aux vector or not.
329 temp src index [+] LEA
330 new-dst 8-bit-version-of temp string-offset [+] MOV
331 new-dst new-dst 8-bit-version-of MOVZX
332 ! Do we have to look at the aux vector?
335 ! Yes, this is a non-ASCII character. Load aux vector
336 temp src string-aux-offset [+] MOV
342 new-dst 16-bit-version-of new-dst byte-array-offset [+] MOV
343 new-dst new-dst 16-bit-version-of MOVZX
348 dst new-dst int-rep %copy
349 ] with-small-register ;
351 M:: x86 %set-string-nth-fast ( ch str index temp -- )
352 ch { index str temp } 8 [| new-ch |
353 new-ch ch int-rep %copy
354 temp str index [+] LEA
355 temp string-offset [+] new-ch 8-bit-version-of MOV
356 ] with-small-register ;
358 :: %alien-integer-getter ( dst src offset size quot -- )
359 dst { src } size [| new-dst |
360 new-dst dup size n-bit-version-of dup src offset [+] MOV
362 dst new-dst int-rep %copy
363 ] with-small-register ; inline
365 : %alien-unsigned-getter ( dst src offset size -- )
366 [ MOVZX ] %alien-integer-getter ; inline
368 : %alien-signed-getter ( dst src offset size -- )
369 [ MOVSX ] %alien-integer-getter ; inline
371 :: %alien-integer-setter ( ptr offset value size -- )
372 value { ptr } size [| new-value |
373 new-value value int-rep %copy
374 ptr offset [+] new-value size n-bit-version-of MOV
375 ] with-small-register ; inline
377 M: x86 %alien-unsigned-1 8 %alien-unsigned-getter ;
378 M: x86 %alien-unsigned-2 16 %alien-unsigned-getter ;
379 M: x86 %alien-unsigned-4 32 [ 2drop ] %alien-integer-getter ;
381 M: x86 %alien-signed-1 8 %alien-signed-getter ;
382 M: x86 %alien-signed-2 16 %alien-signed-getter ;
383 M: x86 %alien-signed-4 32 %alien-signed-getter ;
385 M: x86 %alien-cell [+] MOV ;
386 M: x86 %alien-float [+] MOVSS ;
387 M: x86 %alien-double [+] MOVSD ;
388 M: x86 %alien-vector [ [+] ] dip %copy ;
390 M: x86 %set-alien-integer-1 8 %alien-integer-setter ;
391 M: x86 %set-alien-integer-2 16 %alien-integer-setter ;
392 M: x86 %set-alien-integer-4 32 %alien-integer-setter ;
393 M: x86 %set-alien-cell [ [+] ] dip MOV ;
394 M: x86 %set-alien-float [ [+] ] dip MOVSS ;
395 M: x86 %set-alien-double [ [+] ] dip MOVSD ;
396 M: x86 %set-alien-vector [ [+] ] 2dip %copy ;
398 : shift-count? ( reg -- ? ) { ECX RCX } member-eq? ;
400 :: emit-shift ( dst src quot -- )
409 ECX native-version-of [
411 drop dst CL quot call
416 M: x86 %shl int-rep two-operand [ SHL ] emit-shift ;
417 M: x86 %shr int-rep two-operand [ SHR ] emit-shift ;
418 M: x86 %sar int-rep two-operand [ SAR ] emit-shift ;
420 : %mov-vm-ptr ( reg -- )
421 0 MOV 0 rc-absolute-cell rel-vm ;
423 M: x86 %vm-field-ptr ( dst field -- )
424 [ 0 MOV ] dip vm-field-offset rc-absolute-cell rel-vm ;
426 : load-allot-ptr ( nursery-ptr allot-ptr -- )
427 [ drop "nursery" %vm-field-ptr ] [ swap [] MOV ] 2bi ;
429 : inc-allot-ptr ( nursery-ptr n -- )
430 [ [] ] dip data-alignment get align ADD ;
432 : store-header ( temp class -- )
433 [ [] ] [ type-number tag-header ] bi* MOV ;
435 : store-tagged ( dst tag -- )
438 M:: x86 %allot ( dst size class nursery-ptr -- )
439 nursery-ptr dst load-allot-ptr
440 dst class store-header
441 dst class store-tagged
442 nursery-ptr size inc-allot-ptr ;
444 HOOK: %mark-card cpu ( card temp -- )
445 HOOK: %mark-deck cpu ( card temp -- )
447 :: (%write-barrier) ( src slot temp1 temp2 -- )
448 temp1 src slot [+] LEA
450 temp1 temp2 %mark-card
451 temp1 deck-bits card-bits - SHR
452 temp1 temp2 %mark-deck ;
454 M: x86 %write-barrier ( src slot temp1 temp2 -- ) (%write-barrier) ;
456 M: x86 %write-barrier-imm ( src slot temp1 temp2 -- ) (%write-barrier) ;
458 M:: x86 %check-nursery ( label size temp1 temp2 -- )
459 temp1 "nursery" %vm-field-ptr
460 ! Load 'here' into temp2
463 ! Load 'end' into temp1
464 temp1 temp1 2 cells [+] MOV
468 M: x86 %save-gc-root ( gc-root register -- ) [ gc-root@ ] dip MOV ;
470 M: x86 %load-gc-root ( gc-root register -- ) swap gc-root@ MOV ;
472 M: x86 %alien-global ( dst symbol library -- )
473 [ 0 MOV ] 2dip rc-absolute-cell rel-dlsym ;
475 M: x86 %epilogue ( n -- ) cell - incr-stack-reg ;
477 :: %boolean ( dst temp word -- )
478 dst \ f type-number MOV
479 temp 0 MOV \ t rc-absolute-cell rel-immediate
480 dst temp word execute ; inline
482 : (%compare) ( src1 src2 cc -- )
483 2over [ { cc= cc/= } member? ] [ register? ] [ 0 = ] tri* and and
487 M:: x86 %compare ( dst src1 src2 cc temp -- )
488 src1 src2 cc (%compare)
490 { cc< [ dst temp \ CMOVL %boolean ] }
491 { cc<= [ dst temp \ CMOVLE %boolean ] }
492 { cc> [ dst temp \ CMOVG %boolean ] }
493 { cc>= [ dst temp \ CMOVGE %boolean ] }
494 { cc= [ dst temp \ CMOVE %boolean ] }
495 { cc/= [ dst temp \ CMOVNE %boolean ] }
498 M: x86 %compare-imm ( dst src1 src2 cc temp -- )
501 M:: x86 %compare-branch ( label src1 src2 cc -- )
502 src1 src2 cc (%compare)
505 { cc<= [ label JLE ] }
507 { cc>= [ label JGE ] }
509 { cc/= [ label JNE ] }
512 M: x86 %compare-imm-branch ( label src1 src2 cc -- )
515 M: x86 %add-float double-rep two-operand ADDSD ;
516 M: x86 %sub-float double-rep two-operand SUBSD ;
517 M: x86 %mul-float double-rep two-operand MULSD ;
518 M: x86 %div-float double-rep two-operand DIVSD ;
519 M: x86 %min-float double-rep two-operand MINSD ;
520 M: x86 %max-float double-rep two-operand MAXSD ;
521 M: x86 %sqrt SQRTSD ;
523 : %clear-unless-in-place ( dst src -- )
524 over = [ drop ] [ dup XORPS ] if ;
526 M: x86 %single>double-float [ %clear-unless-in-place ] [ CVTSS2SD ] 2bi ;
527 M: x86 %double>single-float [ %clear-unless-in-place ] [ CVTSD2SS ] 2bi ;
529 M: x86 %integer>float [ drop dup XORPS ] [ CVTSI2SD ] 2bi ;
530 M: x86 %float>integer CVTTSD2SI ;
532 : %cmov-float= ( dst src -- )
534 "no-move" define-label
536 "no-move" get [ JNE ] [ JP ] bi
538 "no-move" resolve-label
541 : %cmov-float/= ( dst src -- )
543 "no-move" define-label
550 "no-move" resolve-label
553 :: (%compare-float) ( dst src1 src2 cc temp compare -- )
555 { cc< [ src2 src1 \ compare execute( a b -- ) dst temp \ CMOVA %boolean ] }
556 { cc<= [ src2 src1 \ compare execute( a b -- ) dst temp \ CMOVAE %boolean ] }
557 { cc> [ src1 src2 \ compare execute( a b -- ) dst temp \ CMOVA %boolean ] }
558 { cc>= [ src1 src2 \ compare execute( a b -- ) dst temp \ CMOVAE %boolean ] }
559 { cc= [ src1 src2 \ compare execute( a b -- ) dst temp \ %cmov-float= %boolean ] }
560 { cc<> [ src1 src2 \ compare execute( a b -- ) dst temp \ CMOVNE %boolean ] }
561 { cc<>= [ src1 src2 \ compare execute( a b -- ) dst temp \ CMOVNP %boolean ] }
562 { cc/< [ src2 src1 \ compare execute( a b -- ) dst temp \ CMOVBE %boolean ] }
563 { cc/<= [ src2 src1 \ compare execute( a b -- ) dst temp \ CMOVB %boolean ] }
564 { cc/> [ src1 src2 \ compare execute( a b -- ) dst temp \ CMOVBE %boolean ] }
565 { cc/>= [ src1 src2 \ compare execute( a b -- ) dst temp \ CMOVB %boolean ] }
566 { cc/= [ src1 src2 \ compare execute( a b -- ) dst temp \ %cmov-float/= %boolean ] }
567 { cc/<> [ src1 src2 \ compare execute( a b -- ) dst temp \ CMOVE %boolean ] }
568 { cc/<>= [ src1 src2 \ compare execute( a b -- ) dst temp \ CMOVP %boolean ] }
571 M: x86 %compare-float-ordered ( dst src1 src2 cc temp -- )
572 \ COMISD (%compare-float) ;
574 M: x86 %compare-float-unordered ( dst src1 src2 cc temp -- )
575 \ UCOMISD (%compare-float) ;
577 : %jump-float= ( label -- )
579 "no-jump" define-label
582 "no-jump" resolve-label
585 : %jump-float/= ( label -- )
588 :: (%compare-float-branch) ( label src1 src2 cc compare -- )
590 { cc< [ src2 src1 \ compare execute( a b -- ) label JA ] }
591 { cc<= [ src2 src1 \ compare execute( a b -- ) label JAE ] }
592 { cc> [ src1 src2 \ compare execute( a b -- ) label JA ] }
593 { cc>= [ src1 src2 \ compare execute( a b -- ) label JAE ] }
594 { cc= [ src1 src2 \ compare execute( a b -- ) label %jump-float= ] }
595 { cc<> [ src1 src2 \ compare execute( a b -- ) label JNE ] }
596 { cc<>= [ src1 src2 \ compare execute( a b -- ) label JNP ] }
597 { cc/< [ src2 src1 \ compare execute( a b -- ) label JBE ] }
598 { cc/<= [ src2 src1 \ compare execute( a b -- ) label JB ] }
599 { cc/> [ src1 src2 \ compare execute( a b -- ) label JBE ] }
600 { cc/>= [ src1 src2 \ compare execute( a b -- ) label JB ] }
601 { cc/= [ src1 src2 \ compare execute( a b -- ) label %jump-float/= ] }
602 { cc/<> [ src1 src2 \ compare execute( a b -- ) label JE ] }
603 { cc/<>= [ src1 src2 \ compare execute( a b -- ) label JP ] }
606 M: x86 %compare-float-ordered-branch ( label src1 src2 cc -- )
607 \ COMISD (%compare-float-branch) ;
609 M: x86 %compare-float-unordered-branch ( label src1 src2 cc -- )
610 \ UCOMISD (%compare-float-branch) ;
612 MACRO: available-reps ( alist -- )
613 ! Each SSE version adds new representations and supports
615 unzip { } [ append ] accumulate rest swap suffix
616 [ [ 1quotation ] map ] bi@ zip
617 reverse [ { } ] suffix
620 M: x86 %alien-vector-reps
622 { sse? { float-4-rep } }
623 { 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 } }
628 { double-2-rep [ dup XORPS ] }
629 { float-4-rep [ dup XORPS ] }
633 M: x86 %zero-vector-reps
635 { sse? { float-4-rep } }
636 { 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 } }
641 { double-2-rep [ dup [ XORPS ] [ CMPEQPS ] 2bi ] }
642 { float-4-rep [ dup [ XORPS ] [ CMPEQPS ] 2bi ] }
646 M: x86 %fill-vector-reps
648 { sse? { float-4-rep } }
649 { 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 } }
652 ! M:: x86 %broadcast-vector ( dst src rep -- )
655 ! dst src float-4-rep %copy
656 ! dst dst { 0 0 0 0 } SHUFPS
663 ! [ dst dst PUNPCKLQDQ ]
664 ! [ dst src { 0 1 0 1 } PSHUFD ]
668 ! dst src { 0 0 0 0 } PSHUFD
671 ! dst src { 0 0 0 0 } PSHUFLW
675 ! dst src char-16-rep %copy
677 ! dst dst { 0 0 0 0 } PSHUFLW
682 ! M: x86 %broadcast-vector-reps
684 ! ! Can't do this with sse1 since it will want to unbox
685 ! ! a double-precision float and convert to single precision
686 ! { sse2? { 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 } }
689 M:: x86 %gather-vector-4 ( dst src1 src2 src3 src4 rep -- )
692 dst src1 float-4-rep %copy
698 dst src1 int-4-rep %copy
705 M: x86 %gather-vector-4-reps
707 ! Can't do this with sse1 since it will want to unbox
708 ! double-precision floats and convert to single precision
709 { sse2? { float-4-rep int-4-rep uint-4-rep } }
712 M:: x86 %gather-vector-2 ( dst src1 src2 rep -- )
715 dst src1 double-2-rep %copy
719 dst src1 longlong-2-rep %copy
724 M: x86 %gather-vector-2-reps
726 { sse2? { double-2-rep longlong-2-rep ulonglong-2-rep } }
729 : sse1-float-4-shuffle ( dst shuffle -- )
731 { { 0 1 2 3 } [ drop ] }
732 { { 0 1 0 1 } [ dup MOVLHPS ] }
733 { { 2 3 2 3 } [ dup MOVHLPS ] }
734 { { 0 0 1 1 } [ dup UNPCKLPS ] }
735 { { 2 2 3 3 } [ dup UNPCKHPS ] }
739 : float-4-shuffle ( dst shuffle -- )
742 { { 0 0 2 2 } [ dup MOVSLDUP ] }
743 { { 1 1 3 3 } [ dup MOVSHDUP ] }
744 [ sse1-float-4-shuffle ]
746 ] [ sse1-float-4-shuffle ] if ;
748 : int-4-shuffle ( dst shuffle -- )
750 { { 0 1 2 3 } [ drop ] }
751 { { 0 0 1 1 } [ dup PUNPCKLDQ ] }
752 { { 2 2 3 3 } [ dup PUNPCKHDQ ] }
753 { { 0 1 0 1 } [ dup PUNPCKLQDQ ] }
754 { { 2 3 2 3 } [ dup PUNPCKHQDQ ] }
758 : longlong-2-shuffle ( dst shuffle -- )
759 first2 [ 2 * dup 1 + ] bi@ 4array int-4-shuffle ;
761 : >float-4-shuffle ( double-2-shuffle -- float-4-shuffle )
762 [ 2 * { 0 1 } n+v ] map concat ;
764 M:: x86 %shuffle-vector-imm ( dst src shuffle rep -- )
766 dst shuffle rep signed-rep {
767 { double-2-rep [ >float-4-shuffle float-4-shuffle ] }
768 { float-4-rep [ float-4-shuffle ] }
769 { int-4-rep [ int-4-shuffle ] }
770 { longlong-2-rep [ longlong-2-shuffle ] }
773 M: x86 %shuffle-vector-imm-reps
775 { sse? { float-4-rep } }
776 { sse2? { double-2-rep int-4-rep uint-4-rep longlong-2-rep ulonglong-2-rep } }
779 M: x86 %shuffle-vector ( dst src shuffle rep -- )
782 M: x86 %shuffle-vector-reps
784 { 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 } }
787 M: x86 %merge-vector-head
790 { double-2-rep [ MOVLHPS ] }
791 { float-4-rep [ UNPCKLPS ] }
792 { longlong-2-rep [ PUNPCKLQDQ ] }
793 { int-4-rep [ PUNPCKLDQ ] }
794 { short-8-rep [ PUNPCKLWD ] }
795 { char-16-rep [ PUNPCKLBW ] }
798 M: x86 %merge-vector-tail
801 { double-2-rep [ UNPCKHPD ] }
802 { float-4-rep [ UNPCKHPS ] }
803 { longlong-2-rep [ PUNPCKHQDQ ] }
804 { int-4-rep [ PUNPCKHDQ ] }
805 { short-8-rep [ PUNPCKHWD ] }
806 { char-16-rep [ PUNPCKHBW ] }
809 M: x86 %merge-vector-reps
811 { sse? { float-4-rep } }
812 { 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 } }
815 M: x86 %signed-pack-vector
818 { int-4-rep [ PACKSSDW ] }
819 { short-8-rep [ PACKSSWB ] }
822 M: x86 %signed-pack-vector-reps
824 { sse2? { short-8-rep int-4-rep } }
827 M: x86 %unsigned-pack-vector
830 { int-4-rep [ PACKUSDW ] }
831 { short-8-rep [ PACKUSWB ] }
834 M: x86 %unsigned-pack-vector-reps
836 { sse2? { short-8-rep } }
837 { sse4.1? { int-4-rep } }
840 M: x86 %tail>head-vector ( dst src rep -- )
842 { float-4-rep [ drop UNPCKHPD ] }
843 { double-2-rep [ drop UNPCKHPD ] }
844 [ drop [ %copy ] [ drop PUNPCKHQDQ ] 3bi ]
847 M: x86 %unpack-vector-head ( dst src rep -- )
849 { char-16-rep [ PMOVSXBW ] }
850 { uchar-16-rep [ PMOVZXBW ] }
851 { short-8-rep [ PMOVSXWD ] }
852 { ushort-8-rep [ PMOVZXWD ] }
853 { int-4-rep [ PMOVSXDQ ] }
854 { uint-4-rep [ PMOVZXDQ ] }
855 { float-4-rep [ CVTPS2PD ] }
858 M: x86 %unpack-vector-head-reps ( -- reps )
860 { sse2? { float-4-rep } }
861 { sse4.1? { char-16-rep uchar-16-rep short-8-rep ushort-8-rep int-4-rep uint-4-rep } }
864 M: x86 %integer>float-vector ( dst src rep -- )
866 { int-4-rep [ CVTDQ2PS ] }
869 M: x86 %integer>float-vector-reps
871 { sse2? { int-4-rep } }
874 M: x86 %float>integer-vector ( dst src rep -- )
876 { float-4-rep [ CVTTPS2DQ ] }
879 M: x86 %float>integer-vector-reps
881 { sse2? { float-4-rep } }
884 : (%compare-float-vector) ( dst src rep double single -- )
885 [ double-2-rep eq? ] 2dip if ; inline
886 : %compare-float-vector ( dst src rep cc -- )
888 { cc< [ [ CMPLTPD ] [ CMPLTPS ] (%compare-float-vector) ] }
889 { cc<= [ [ CMPLEPD ] [ CMPLEPS ] (%compare-float-vector) ] }
890 { cc= [ [ CMPEQPD ] [ CMPEQPS ] (%compare-float-vector) ] }
891 { cc<>= [ [ CMPORDPD ] [ CMPORDPS ] (%compare-float-vector) ] }
892 { cc/< [ [ CMPNLTPD ] [ CMPNLTPS ] (%compare-float-vector) ] }
893 { cc/<= [ [ CMPNLEPD ] [ CMPNLEPS ] (%compare-float-vector) ] }
894 { cc/= [ [ CMPNEQPD ] [ CMPNEQPS ] (%compare-float-vector) ] }
895 { cc/<>= [ [ CMPUNORDPD ] [ CMPUNORDPS ] (%compare-float-vector) ] }
898 :: (%compare-int-vector) ( dst src rep int64 int32 int16 int8 -- )
899 rep signed-rep :> rep'
901 { longlong-2-rep [ int64 call ] }
902 { int-4-rep [ int32 call ] }
903 { short-8-rep [ int16 call ] }
904 { char-16-rep [ int8 call ] }
906 : %compare-int-vector ( dst src rep cc -- )
908 { cc= [ [ PCMPEQQ ] [ PCMPEQD ] [ PCMPEQW ] [ PCMPEQB ] (%compare-int-vector) ] }
909 { cc> [ [ PCMPGTQ ] [ PCMPGTD ] [ PCMPGTW ] [ PCMPGTB ] (%compare-int-vector) ] }
912 M: x86 %compare-vector ( dst src1 src2 rep cc -- )
913 [ [ two-operand ] keep ] dip
914 over float-vector-rep?
915 [ %compare-float-vector ]
916 [ %compare-int-vector ] if ;
918 : %compare-vector-eq-reps ( -- reps )
920 { sse? { float-4-rep } }
921 { sse2? { double-2-rep char-16-rep uchar-16-rep short-8-rep ushort-8-rep int-4-rep uint-4-rep } }
922 { sse4.1? { longlong-2-rep ulonglong-2-rep } }
924 : %compare-vector-ord-reps ( -- reps )
926 { sse? { float-4-rep } }
927 { sse2? { double-2-rep char-16-rep short-8-rep int-4-rep } }
928 { sse4.2? { longlong-2-rep } }
931 M: x86 %compare-vector-reps
933 { [ dup { cc= cc/= cc/<>= cc<>= } member-eq? ] [ drop %compare-vector-eq-reps ] }
934 [ drop %compare-vector-ord-reps ]
937 : %compare-float-vector-ccs ( cc -- ccs not? )
939 { cc< [ { { cc< f } } f ] }
940 { cc<= [ { { cc<= f } } f ] }
941 { cc> [ { { cc< t } } f ] }
942 { cc>= [ { { cc<= t } } f ] }
943 { cc= [ { { cc= f } } f ] }
944 { cc<> [ { { cc< f } { cc< t } } f ] }
945 { cc<>= [ { { cc<>= f } } f ] }
946 { cc/< [ { { cc/< f } } f ] }
947 { cc/<= [ { { cc/<= f } } f ] }
948 { cc/> [ { { cc/< t } } f ] }
949 { cc/>= [ { { cc/<= t } } f ] }
950 { cc/= [ { { cc/= f } } f ] }
951 { cc/<> [ { { cc/= f } { cc/<>= f } } f ] }
952 { cc/<>= [ { { cc/<>= f } } f ] }
955 : %compare-int-vector-ccs ( cc -- ccs not? )
957 { cc< [ { { cc> t } } f ] }
958 { cc<= [ { { cc> f } } t ] }
959 { cc> [ { { cc> f } } f ] }
960 { cc>= [ { { cc> t } } t ] }
961 { cc= [ { { cc= f } } f ] }
962 { cc/= [ { { cc= f } } t ] }
967 M: x86 %compare-vector-ccs
968 swap float-vector-rep?
969 [ %compare-float-vector-ccs ]
970 [ %compare-int-vector-ccs ] if ;
972 :: %test-vector-mask ( dst temp mask vcc -- )
974 { vcc-any [ dst dst TEST dst temp \ CMOVNE %boolean ] }
975 { vcc-none [ dst dst TEST dst temp \ CMOVE %boolean ] }
976 { vcc-all [ dst mask CMP dst temp \ CMOVE %boolean ] }
977 { vcc-notall [ dst mask CMP dst temp \ CMOVNE %boolean ] }
980 : %move-vector-mask ( dst src rep -- mask )
982 { double-2-rep [ MOVMSKPS HEX: f ] }
983 { float-4-rep [ MOVMSKPS HEX: f ] }
984 [ drop PMOVMSKB HEX: ffff ]
987 M:: x86 %test-vector ( dst src temp rep vcc -- )
988 dst src rep %move-vector-mask :> mask
989 dst temp mask vcc %test-vector-mask ;
991 :: %test-vector-mask-branch ( label temp mask vcc -- )
993 { vcc-any [ temp temp TEST label JNE ] }
994 { vcc-none [ temp temp TEST label JE ] }
995 { vcc-all [ temp mask CMP label JE ] }
996 { vcc-notall [ temp mask CMP label JNE ] }
999 M:: x86 %test-vector-branch ( label src temp rep vcc -- )
1000 temp src rep %move-vector-mask :> mask
1001 label temp mask vcc %test-vector-mask-branch ;
1003 M: x86 %test-vector-reps
1005 { sse? { float-4-rep } }
1006 { 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 } }
1009 M: x86 %add-vector ( dst src1 src2 rep -- )
1010 [ two-operand ] keep
1012 { float-4-rep [ ADDPS ] }
1013 { double-2-rep [ ADDPD ] }
1014 { char-16-rep [ PADDB ] }
1015 { uchar-16-rep [ PADDB ] }
1016 { short-8-rep [ PADDW ] }
1017 { ushort-8-rep [ PADDW ] }
1018 { int-4-rep [ PADDD ] }
1019 { uint-4-rep [ PADDD ] }
1020 { longlong-2-rep [ PADDQ ] }
1021 { ulonglong-2-rep [ PADDQ ] }
1024 M: x86 %add-vector-reps
1026 { sse? { float-4-rep } }
1027 { 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 } }
1030 M: x86 %saturated-add-vector ( dst src1 src2 rep -- )
1031 [ two-operand ] keep
1033 { char-16-rep [ PADDSB ] }
1034 { uchar-16-rep [ PADDUSB ] }
1035 { short-8-rep [ PADDSW ] }
1036 { ushort-8-rep [ PADDUSW ] }
1039 M: x86 %saturated-add-vector-reps
1041 { sse2? { char-16-rep uchar-16-rep short-8-rep ushort-8-rep } }
1044 M: x86 %add-sub-vector ( dst src1 src2 rep -- )
1045 [ two-operand ] keep
1047 { float-4-rep [ ADDSUBPS ] }
1048 { double-2-rep [ ADDSUBPD ] }
1051 M: x86 %add-sub-vector-reps
1053 { sse3? { float-4-rep double-2-rep } }
1056 M: x86 %sub-vector ( dst src1 src2 rep -- )
1057 [ two-operand ] keep
1059 { float-4-rep [ SUBPS ] }
1060 { double-2-rep [ SUBPD ] }
1061 { char-16-rep [ PSUBB ] }
1062 { uchar-16-rep [ PSUBB ] }
1063 { short-8-rep [ PSUBW ] }
1064 { ushort-8-rep [ PSUBW ] }
1065 { int-4-rep [ PSUBD ] }
1066 { uint-4-rep [ PSUBD ] }
1067 { longlong-2-rep [ PSUBQ ] }
1068 { ulonglong-2-rep [ PSUBQ ] }
1071 M: x86 %sub-vector-reps
1073 { sse? { float-4-rep } }
1074 { 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 } }
1077 M: x86 %saturated-sub-vector ( dst src1 src2 rep -- )
1078 [ two-operand ] keep
1080 { char-16-rep [ PSUBSB ] }
1081 { uchar-16-rep [ PSUBUSB ] }
1082 { short-8-rep [ PSUBSW ] }
1083 { ushort-8-rep [ PSUBUSW ] }
1086 M: x86 %saturated-sub-vector-reps
1088 { sse2? { char-16-rep uchar-16-rep short-8-rep ushort-8-rep } }
1091 M: x86 %mul-vector ( dst src1 src2 rep -- )
1092 [ two-operand ] keep
1094 { float-4-rep [ MULPS ] }
1095 { double-2-rep [ MULPD ] }
1096 { short-8-rep [ PMULLW ] }
1097 { ushort-8-rep [ PMULLW ] }
1098 { int-4-rep [ PMULLD ] }
1099 { uint-4-rep [ PMULLD ] }
1102 M: x86 %mul-vector-reps
1104 { sse? { float-4-rep } }
1105 { sse2? { double-2-rep short-8-rep ushort-8-rep } }
1106 { sse4.1? { int-4-rep uint-4-rep } }
1109 M: x86 %div-vector ( dst src1 src2 rep -- )
1110 [ two-operand ] keep
1112 { float-4-rep [ DIVPS ] }
1113 { double-2-rep [ DIVPD ] }
1116 M: x86 %div-vector-reps
1118 { sse? { float-4-rep } }
1119 { sse2? { double-2-rep } }
1122 M: x86 %min-vector ( dst src1 src2 rep -- )
1123 [ two-operand ] keep
1125 { char-16-rep [ PMINSB ] }
1126 { uchar-16-rep [ PMINUB ] }
1127 { short-8-rep [ PMINSW ] }
1128 { ushort-8-rep [ PMINUW ] }
1129 { int-4-rep [ PMINSD ] }
1130 { uint-4-rep [ PMINUD ] }
1131 { float-4-rep [ MINPS ] }
1132 { double-2-rep [ MINPD ] }
1135 M: x86 %min-vector-reps
1137 { sse? { float-4-rep } }
1138 { sse2? { uchar-16-rep short-8-rep double-2-rep } }
1139 { sse4.1? { char-16-rep ushort-8-rep int-4-rep uint-4-rep } }
1142 M: x86 %max-vector ( dst src1 src2 rep -- )
1143 [ two-operand ] keep
1145 { char-16-rep [ PMAXSB ] }
1146 { uchar-16-rep [ PMAXUB ] }
1147 { short-8-rep [ PMAXSW ] }
1148 { ushort-8-rep [ PMAXUW ] }
1149 { int-4-rep [ PMAXSD ] }
1150 { uint-4-rep [ PMAXUD ] }
1151 { float-4-rep [ MAXPS ] }
1152 { double-2-rep [ MAXPD ] }
1155 M: x86 %max-vector-reps
1157 { sse? { float-4-rep } }
1158 { sse2? { uchar-16-rep short-8-rep double-2-rep } }
1159 { sse4.1? { char-16-rep ushort-8-rep int-4-rep uint-4-rep } }
1163 [ two-operand ] keep
1165 { float-4-rep [ HEX: ff DPPS ] }
1166 { double-2-rep [ HEX: ff DPPD ] }
1169 M: x86 %dot-vector-reps
1171 { sse4.1? { float-4-rep double-2-rep } }
1174 M: x86 %horizontal-add-vector ( dst src1 src2 rep -- )
1175 [ two-operand ] keep
1177 { float-4-rep [ HADDPS ] }
1178 { double-2-rep [ HADDPD ] }
1179 { int-4-rep [ PHADDD ] }
1180 { short-8-rep [ PHADDW ] }
1183 M: x86 %horizontal-add-vector-reps
1185 { sse3? { float-4-rep double-2-rep } }
1186 { ssse3? { int-4-rep uint-4-rep short-8-rep ushort-8-rep } }
1189 M: x86 %horizontal-shl-vector-imm ( dst src1 src2 rep -- )
1190 two-operand PSLLDQ ;
1192 M: x86 %horizontal-shl-vector-imm-reps
1194 { 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 } }
1197 M: x86 %horizontal-shr-vector-imm ( dst src1 src2 rep -- )
1198 two-operand PSRLDQ ;
1200 M: x86 %horizontal-shr-vector-imm-reps
1202 { 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 } }
1205 M: x86 %abs-vector ( dst src rep -- )
1207 { char-16-rep [ PABSB ] }
1208 { short-8-rep [ PABSW ] }
1209 { int-4-rep [ PABSD ] }
1212 M: x86 %abs-vector-reps
1214 { ssse3? { char-16-rep short-8-rep int-4-rep } }
1217 M: x86 %sqrt-vector ( dst src rep -- )
1219 { float-4-rep [ SQRTPS ] }
1220 { double-2-rep [ SQRTPD ] }
1223 M: x86 %sqrt-vector-reps
1225 { sse? { float-4-rep } }
1226 { sse2? { double-2-rep } }
1229 M: x86 %and-vector ( dst src1 src2 rep -- )
1230 [ two-operand ] keep
1232 { float-4-rep [ ANDPS ] }
1233 { double-2-rep [ ANDPS ] }
1237 M: x86 %and-vector-reps
1239 { sse? { float-4-rep } }
1240 { 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 } }
1243 M: x86 %andn-vector ( dst src1 src2 rep -- )
1244 [ two-operand ] keep
1246 { float-4-rep [ ANDNPS ] }
1247 { double-2-rep [ ANDNPS ] }
1251 M: x86 %andn-vector-reps
1253 { sse? { float-4-rep } }
1254 { 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 } }
1257 M: x86 %or-vector ( dst src1 src2 rep -- )
1258 [ two-operand ] keep
1260 { float-4-rep [ ORPS ] }
1261 { double-2-rep [ ORPS ] }
1265 M: x86 %or-vector-reps
1267 { sse? { float-4-rep } }
1268 { 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 } }
1271 M: x86 %xor-vector ( dst src1 src2 rep -- )
1272 [ two-operand ] keep
1274 { float-4-rep [ XORPS ] }
1275 { double-2-rep [ XORPS ] }
1279 M: x86 %xor-vector-reps
1281 { sse? { float-4-rep } }
1282 { 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 } }
1285 M: x86 %shl-vector ( dst src1 src2 rep -- )
1286 [ two-operand ] keep
1288 { short-8-rep [ PSLLW ] }
1289 { ushort-8-rep [ PSLLW ] }
1290 { int-4-rep [ PSLLD ] }
1291 { uint-4-rep [ PSLLD ] }
1292 { longlong-2-rep [ PSLLQ ] }
1293 { ulonglong-2-rep [ PSLLQ ] }
1296 M: x86 %shl-vector-reps
1298 { sse2? { short-8-rep ushort-8-rep int-4-rep uint-4-rep longlong-2-rep ulonglong-2-rep } }
1301 M: x86 %shr-vector ( dst src1 src2 rep -- )
1302 [ two-operand ] keep
1304 { short-8-rep [ PSRAW ] }
1305 { ushort-8-rep [ PSRLW ] }
1306 { int-4-rep [ PSRAD ] }
1307 { uint-4-rep [ PSRLD ] }
1308 { ulonglong-2-rep [ PSRLQ ] }
1311 M: x86 %shr-vector-reps
1313 { sse2? { short-8-rep ushort-8-rep int-4-rep uint-4-rep ulonglong-2-rep } }
1316 M: x86 %shl-vector-imm %shl-vector ;
1317 M: x86 %shl-vector-imm-reps %shl-vector-reps ;
1318 M: x86 %shr-vector-imm %shr-vector ;
1319 M: x86 %shr-vector-imm-reps %shr-vector-reps ;
1321 : scalar-sized-reg ( reg rep -- reg' )
1322 rep-size 8 * n-bit-version-of ;
1324 M: x86 %integer>scalar drop MOVD ;
1326 ! XXX the longlong versions won't work on x86.32
1327 M:: x86 %scalar>integer ( dst src rep -- )
1329 { longlong-scalar-rep [
1332 { ulonglong-scalar-rep [
1336 dst 32-bit-version-of src MOVD
1337 dst dst 32-bit-version-of
1338 2dup eq? [ 2drop ] [ MOVSX ] if
1341 dst 32-bit-version-of src MOVD
1343 { short-scalar-rep [
1344 dst 32-bit-version-of src MOVD
1345 dst dst 16-bit-version-of MOVSX
1347 { ushort-scalar-rep [
1348 dst 32-bit-version-of src MOVD
1349 dst dst 16-bit-version-of MOVZX
1352 dst 32-bit-version-of src MOVD
1353 dst { } 8 [| tmp-dst |
1354 tmp-dst dst int-rep %copy
1355 tmp-dst tmp-dst 8-bit-version-of MOVSX
1356 dst tmp-dst int-rep %copy
1357 ] with-small-register
1359 { uchar-scalar-rep [
1360 dst 32-bit-version-of src MOVD
1361 dst { } 8 [| tmp-dst |
1362 tmp-dst dst int-rep %copy
1363 tmp-dst tmp-dst 8-bit-version-of MOVZX
1364 dst tmp-dst int-rep %copy
1365 ] with-small-register
1369 M: x86 %vector>scalar %copy ;
1370 M: x86 %scalar>vector %copy ;
1372 M:: x86 %spill ( src rep dst -- ) dst src rep %copy ;
1373 M:: x86 %reload ( dst rep src -- ) dst src rep %copy ;
1375 M: x86 %loop-entry 16 code-alignment [ NOP ] times ;
1377 M:: x86 %save-context ( temp1 temp2 callback-allowed? -- )
1378 #! Save Factor stack pointers in case the C code calls a
1379 #! callback which does a GC, which must reliably trace
1381 temp1 "stack_chain" %vm-field-ptr
1383 temp2 stack-reg cell neg [+] LEA
1386 temp1 2 cells [+] ds-reg MOV
1387 temp1 3 cells [+] rs-reg MOV
1390 M: x86 value-struct? drop t ;
1392 M: x86 immediate-arithmetic? ( n -- ? )
1393 HEX: -80000000 HEX: 7fffffff between? ;
1395 M: x86 immediate-bitwise? ( n -- ? )
1396 HEX: -80000000 HEX: 7fffffff between? ;
1398 : next-stack@ ( n -- operand )
1399 #! nth parameter from the next stack frame. Used to box
1400 #! input values to callbacks; the callback has its own
1401 #! stack frame set up, and we want to read the frame
1402 #! set up by the caller.
1403 stack-frame get total-size>> + stack@ ;
1408 :: install-sse2-check ( -- )
1411 "This image was built to use SSE2 but your CPU does not support it." print
1412 "You will need to bootstrap Factor again." print
1416 ] "cpu.x86" add-startup-hook ;
1418 : enable-sse2 ( version -- )
1420 enable-float-intrinsics
1421 enable-float-functions
1422 enable-float-min/max
1428 [ { sse_version } compile ] with-optimizer
1429 "Checking for multimedia extensions: " write sse-version
1430 [ sse-string write " detected" print ] [ enable-sse2 ] bi ;