1 ! Copyright (C) 2005, 2010 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 classes.algebra compiler
9 compiler.units init vm vocabs.loader
10 compiler.cfg.registers
11 compiler.cfg.instructions
12 compiler.cfg.intrinsics
13 compiler.cfg.comparisons
14 compiler.cfg.stack-frame
15 compiler.codegen.fixup ;
16 QUALIFIED-WITH: alien.c-types c
17 FROM: layouts => cell ;
21 ! Add some methods to the assembler to be more useful to the backend
22 M: label JMP 0 JMP rc-relative label-fixup ;
23 M: label JUMPcc [ 0 ] dip JUMPcc rc-relative label-fixup ;
25 M: x86 vector-regs float-regs ;
27 HOOK: stack-reg cpu ( -- reg )
29 HOOK: reserved-stack-space cpu ( -- n )
31 : stack@ ( n -- op ) stack-reg swap [+] ;
33 : special-offset ( m -- n )
34 reserved-stack-space + ;
36 : spill@ ( n -- op ) spill-offset special-offset stack@ ;
38 : decr-stack-reg ( n -- )
39 dup 0 = [ drop ] [ stack-reg swap SUB ] if ;
41 : incr-stack-reg ( n -- )
42 dup 0 = [ drop ] [ stack-reg swap ADD ] if ;
44 : align-stack ( n -- n' ) 16 align ;
46 M: x86 stack-frame-size ( stack-frame -- i )
48 reserved-stack-space +
52 HOOK: pic-tail-reg cpu ( -- reg )
54 M: x86 complex-addressing? t ;
56 M: x86 fused-unboxing? t ;
58 M: x86 test-instruction? t ;
60 M: x86 immediate-store? immediate-comparand? ;
62 M: x86 %load-immediate dup 0 = [ drop dup XOR ] [ MOV ] if ;
64 M: x86 %load-reference
65 [ swap 0 MOV rc-absolute-cell rel-literal ]
66 [ \ f type-number MOV ]
69 HOOK: ds-reg cpu ( -- reg )
70 HOOK: rs-reg cpu ( -- reg )
72 : reg-stack ( n reg -- op ) swap cells neg [+] ;
74 GENERIC: loc>operand ( loc -- operand )
76 M: ds-loc loc>operand n>> ds-reg reg-stack ;
77 M: rs-loc loc>operand n>> rs-reg reg-stack ;
79 M: x86 %peek loc>operand MOV ;
81 M: x86 %replace loc>operand swap MOV ;
86 { [ dup not ] [ drop \ f type-number MOV ] }
87 { [ dup fixnum? ] [ tag-fixnum MOV ] }
88 [ [ HEX: ffffffff MOV ] dip rc-absolute rel-literal ]
91 : (%inc) ( n reg -- ) swap cells dup 0 > [ ADD ] [ neg SUB ] if ; inline
92 M: x86 %inc-d ( n -- ) ds-reg (%inc) ;
93 M: x86 %inc-r ( n -- ) rs-reg (%inc) ;
95 M: x86 %call ( word -- ) 0 CALL rc-relative rel-word-pic ;
97 : xt-tail-pic-offset ( -- n )
98 #! See the comment in vm/cpu-x86.hpp
101 HOOK: %prepare-jump cpu ( -- )
103 M: x86 %jump ( word -- )
105 0 JMP rc-relative rel-word-pic-tail ;
107 M: x86 %jump-label ( label -- ) 0 JMP rc-relative label-fixup ;
109 M: x86 %return ( -- ) 0 RET ;
111 : (%slot) ( obj slot scale tag -- op ) neg <indirect> ; inline
112 : (%slot-imm) ( obj slot tag -- op ) slot-offset [+] ; inline
114 M: x86 %slot ( dst obj slot scale tag -- ) (%slot) MOV ;
115 M: x86 %slot-imm ( dst obj slot tag -- ) (%slot-imm) MOV ;
116 M: x86 %set-slot ( src obj slot scale tag -- ) (%slot) swap MOV ;
117 M: x86 %set-slot-imm ( src obj slot tag -- ) (%slot-imm) swap MOV ;
119 :: two-operand ( dst src1 src2 rep -- dst src )
120 dst src2 eq? dst src1 eq? not and [ "Cannot handle this case" throw ] when
124 :: one-operand ( dst src rep -- dst )
128 M: x86 %add 2over eq? [ nip ADD ] [ [+] LEA ] if ;
129 M: x86 %add-imm 2over eq? [ nip ADD ] [ [+] LEA ] if ;
130 M: x86 %sub int-rep two-operand SUB ;
131 M: x86 %sub-imm 2over eq? [ nip SUB ] [ neg [+] LEA ] if ;
132 M: x86 %mul int-rep two-operand IMUL2 ;
133 M: x86 %mul-imm IMUL3 ;
134 M: x86 %and int-rep two-operand AND ;
135 M: x86 %and-imm int-rep two-operand AND ;
136 M: x86 %or int-rep two-operand OR ;
137 M: x86 %or-imm int-rep two-operand OR ;
138 M: x86 %xor int-rep two-operand XOR ;
139 M: x86 %xor-imm int-rep two-operand XOR ;
140 M: x86 %shl-imm int-rep two-operand SHL ;
141 M: x86 %shr-imm int-rep two-operand SHR ;
142 M: x86 %sar-imm int-rep two-operand SAR ;
144 M: x86 %min int-rep two-operand [ CMP ] [ CMOVG ] 2bi ;
145 M: x86 %max int-rep two-operand [ CMP ] [ CMOVL ] 2bi ;
147 M: x86 %not int-rep one-operand NOT ;
148 M: x86 %neg int-rep one-operand NEG ;
150 M: x86 %bit-count POPCNT ;
152 ! A bit of logic to avoid using MOVSS/MOVSD for reg-reg moves
153 ! since this induces partial register stalls
154 GENERIC: copy-register* ( dst src rep -- )
155 GENERIC: copy-memory* ( dst src rep -- )
157 M: int-rep copy-register* drop MOV ;
158 M: tagged-rep copy-register* drop MOV ;
160 M: object copy-memory* copy-register* ;
162 : ?spill-slot ( obj -- obj ) dup spill-slot? [ n>> spill@ ] when ;
164 M: x86 %copy ( dst src rep -- )
165 2over eq? [ 3drop ] [
166 [ [ ?spill-slot ] bi@ ] dip
167 2over [ register? ] both? [ copy-register* ] [ copy-memory* ] if
170 : fixnum-overflow ( label dst src1 src2 cc quot -- )
171 swap [ [ int-rep two-operand ] dip call ] dip
177 M: x86 %fixnum-add ( label dst src1 src2 cc -- )
178 [ ADD ] fixnum-overflow ;
180 M: x86 %fixnum-sub ( label dst src1 src2 cc -- )
181 [ SUB ] fixnum-overflow ;
183 M: x86 %fixnum-mul ( label dst src1 src2 cc -- )
184 [ IMUL2 ] fixnum-overflow ;
186 M: x86 %unbox-alien ( dst src -- )
187 alien-offset [+] MOV ;
189 M:: x86 %unbox-any-c-ptr ( dst src -- )
194 src \ f type-number CMP
196 ! Compute tag in dst register
199 ! Is the object an alien?
200 dst alien type-number CMP
201 ! Add an offset to start of byte array's data
202 dst src byte-array-offset [+] LEA
204 ! If so, load the offset and add it to the address
205 dst src alien-offset [+] MOV
209 : alien@ ( reg n -- op ) cells alien type-number - [+] ;
211 M:: x86 %box-alien ( dst src temp -- )
214 dst \ f type-number MOV
217 dst 5 cells alien temp %allot
218 dst 1 alien@ \ f type-number MOV ! base
219 dst 2 alien@ \ f type-number MOV ! expired
220 dst 3 alien@ src MOV ! displacement
221 dst 4 alien@ src MOV ! address
225 :: %box-displaced-alien/f ( dst displacement -- )
226 dst 1 alien@ \ f type-number MOV
227 dst 3 alien@ displacement MOV
228 dst 4 alien@ displacement MOV ;
230 :: %box-displaced-alien/alien ( dst displacement base temp -- )
231 ! Set new alien's base to base.base
232 temp base 1 alien@ MOV
233 dst 1 alien@ temp MOV
235 ! Compute displacement
236 temp base 3 alien@ MOV
237 temp displacement ADD
238 dst 3 alien@ temp MOV
241 temp base 4 alien@ MOV
242 temp displacement ADD
243 dst 4 alien@ temp MOV ;
245 :: %box-displaced-alien/byte-array ( dst displacement base temp -- )
246 dst 1 alien@ base MOV
247 dst 3 alien@ displacement MOV
248 temp base displacement byte-array-offset [++] LEA
249 dst 4 alien@ temp MOV ;
251 :: %box-displaced-alien/dynamic ( dst displacement base temp -- )
253 "not-alien" define-label
257 temp tag-mask get AND
260 temp \ f type-number CMP
263 ! Yes, it is f. Fill in new object
264 dst displacement %box-displaced-alien/f
268 "not-f" resolve-label
271 temp alien type-number CMP
274 dst displacement base temp %box-displaced-alien/alien
279 ! Is base a byte array? It has to be, by now...
280 "not-alien" resolve-label
282 dst displacement base temp %box-displaced-alien/byte-array ;
284 M:: x86 %box-displaced-alien ( dst displacement base temp base-class -- )
288 ! If displacement is zero, return the base
290 displacement displacement TEST
293 ! Displacement is non-zero, we're going to be allocating a new
295 dst 5 cells alien temp %allot
298 dst 2 alien@ \ f type-number MOV
300 dst displacement base temp
302 { [ base-class \ f class<= ] [ 2drop %box-displaced-alien/f ] }
303 { [ base-class \ alien class<= ] [ %box-displaced-alien/alien ] }
304 { [ base-class \ byte-array class<= ] [ %box-displaced-alien/byte-array ] }
305 [ %box-displaced-alien/dynamic ]
311 ! The 'small-reg' mess is pretty crappy, but its only used on x86-32.
312 ! On x86-64, all registers have 8-bit versions. However, a similar
313 ! problem arises for shifts, where the shift count must be in CL, and
314 ! so one day I will fix this properly by adding precoloring to the
315 ! register allocator.
317 HOOK: has-small-reg? cpu ( reg size -- ? )
319 CONSTANT: have-byte-regs { EAX ECX EDX EBX }
321 M: x86.32 has-small-reg?
323 { 8 [ have-byte-regs member-eq? ] }
328 M: x86.64 has-small-reg? 2drop t ;
330 : small-reg-that-isn't ( exclude -- reg' )
331 [ have-byte-regs ] dip
332 [ native-version-of ] map
333 '[ _ member-eq? not ] find nip ;
335 : with-save/restore ( reg quot -- )
336 [ drop PUSH ] [ call ] [ drop POP ] 2tri ; inline
338 :: with-small-register ( dst exclude size quot: ( new-dst -- ) -- )
339 ! If the destination register overlaps a small register with
340 ! 'size' bits, we call the quot with that. Otherwise, we find a
341 ! small register that is not in exclude, and call quot, saving and
342 ! restoring the small register.
343 dst size has-small-reg? [ dst quot call ] [
344 exclude small-reg-that-isn't
345 [ quot call ] with-save/restore
348 :: (%convert-integer) ( dst src bits quot -- )
349 dst { src } bits [| new-dst |
350 new-dst src int-rep %copy
351 new-dst dup bits n-bit-version-of quot call
352 dst new-dst int-rep %copy
353 ] with-small-register ; inline
355 : %zero-extend ( dst src bits -- )
356 [ MOVZX ] (%convert-integer) ; inline
358 : %sign-extend ( dst src bits -- )
359 [ MOVSX ] (%convert-integer) ; inline
361 M: x86 %convert-integer ( dst src c-type -- )
363 { c:char [ 8 %sign-extend ] }
364 { c:uchar [ 8 %zero-extend ] }
365 { c:short [ 16 %sign-extend ] }
366 { c:ushort [ 16 %zero-extend ] }
367 { c:int [ 32 %sign-extend ] }
368 { c:uint [ 32 [ 2drop ] (%convert-integer) ] }
371 :: %alien-integer-getter ( dst exclude address bits quot -- )
372 dst exclude bits [| new-dst |
373 new-dst dup bits n-bit-version-of dup address MOV
375 dst new-dst int-rep %copy
376 ] with-small-register ; inline
378 : %alien-unsigned-getter ( dst exclude address bits -- )
379 [ MOVZX ] %alien-integer-getter ; inline
381 : %alien-signed-getter ( dst exclude address bits -- )
382 [ MOVSX ] %alien-integer-getter ; inline
384 :: %alien-integer-setter ( value exclude address bits -- )
385 value exclude bits [| new-value |
386 new-value value int-rep %copy
387 address new-value bits n-bit-version-of MOV
388 ] with-small-register ; inline
390 : (%memory) ( base displacement scale offset rep c-type -- exclude address rep c-type )
391 [ [ [ 2array ] 2keep ] 2dip <indirect> ] 2dip ;
393 : (%memory-imm) ( base offset rep c-type -- exclude address rep c-type )
394 [ [ drop 1array ] [ [+] ] 2bi ] 2dip ;
396 : (%load-memory) ( dst exclude address rep c-type -- )
399 { c:char [ 8 %alien-signed-getter ] }
400 { c:uchar [ 8 %alien-unsigned-getter ] }
401 { c:short [ 16 %alien-signed-getter ] }
402 { c:ushort [ 16 %alien-unsigned-getter ] }
403 { c:int [ 32 %alien-signed-getter ] }
404 { c:uint [ 32 [ 2drop ] %alien-integer-getter ] }
406 ] [ [ drop ] 2dip %copy ] ?if ;
408 M: x86 %load-memory ( dst base displacement scale offset rep c-type -- )
409 (%memory) (%load-memory) ;
411 M: x86 %load-memory-imm ( dst base offset rep c-type -- )
412 (%memory-imm) (%load-memory) ;
414 : (%store-memory) ( src exclude address rep c-type -- )
417 { c:char [ 8 %alien-integer-setter ] }
418 { c:uchar [ 8 %alien-integer-setter ] }
419 { c:short [ 16 %alien-integer-setter ] }
420 { c:ushort [ 16 %alien-integer-setter ] }
421 { c:int [ 32 %alien-integer-setter ] }
422 { c:uint [ 32 %alien-integer-setter ] }
424 ] [ [ nip swap ] dip %copy ] ?if ;
426 M: x86 %store-memory ( src base displacement scale offset rep c-type -- )
427 (%memory) (%store-memory) ;
429 M: x86 %store-memory-imm ( src base offset rep c-type -- )
430 (%memory-imm) (%store-memory) ;
432 : shift-count? ( reg -- ? ) { ECX RCX } member-eq? ;
434 :: emit-shift ( dst src quot -- )
443 ECX native-version-of [
445 drop dst CL quot call
450 M: x86 %shl int-rep two-operand [ SHL ] emit-shift ;
451 M: x86 %shr int-rep two-operand [ SHR ] emit-shift ;
452 M: x86 %sar int-rep two-operand [ SAR ] emit-shift ;
454 HOOK: %mov-vm-ptr cpu ( reg -- )
456 HOOK: %vm-field-ptr cpu ( reg offset -- )
458 : load-zone-offset ( nursery-ptr -- )
459 "nursery" vm-field-offset %vm-field-ptr ;
461 : load-allot-ptr ( nursery-ptr allot-ptr -- )
462 [ drop load-zone-offset ] [ swap [] MOV ] 2bi ;
464 : inc-allot-ptr ( nursery-ptr n -- )
465 [ [] ] dip data-alignment get align ADD ;
467 : store-header ( temp class -- )
468 [ [] ] [ type-number tag-header ] bi* MOV ;
470 : store-tagged ( dst tag -- )
473 M:: x86 %allot ( dst size class nursery-ptr -- )
474 nursery-ptr dst load-allot-ptr
475 dst class store-header
476 dst class store-tagged
477 nursery-ptr size inc-allot-ptr ;
479 HOOK: %mark-card cpu ( card temp -- )
480 HOOK: %mark-deck cpu ( card temp -- )
482 :: (%write-barrier) ( temp1 temp2 -- )
484 temp1 temp2 %mark-card
485 temp1 deck-bits card-bits - SHR
486 temp1 temp2 %mark-deck ;
488 M:: x86 %write-barrier ( src slot scale tag temp1 temp2 -- )
489 temp1 src slot scale tag (%slot) LEA
490 temp1 temp2 (%write-barrier) ;
492 M:: x86 %write-barrier-imm ( src slot tag temp1 temp2 -- )
493 temp1 src slot tag (%slot-imm) LEA
494 temp1 temp2 (%write-barrier) ;
496 M:: x86 %check-nursery-branch ( label size cc temp1 temp2 -- )
497 temp1 load-zone-offset
500 temp2 temp1 2 cells [+] CMP
502 { cc<= [ label JLE ] }
503 { cc/<= [ label JG ] }
506 M: x86 gc-root-offset
507 n>> spill-offset special-offset cell + cell /i ;
509 M: x86 %call-gc ( gc-map -- )
513 M: x86 %alien-global ( dst symbol library -- )
514 [ 0 MOV ] 2dip rc-absolute-cell rel-dlsym ;
516 M: x86 %epilogue ( n -- ) cell - incr-stack-reg ;
518 :: (%boolean) ( dst temp insn -- )
519 dst \ f type-number MOV
520 temp 0 MOV \ t rc-absolute-cell rel-literal
521 dst temp insn execute ; inline
523 : %boolean ( dst cc temp -- )
525 { cc< [ \ CMOVL (%boolean) ] }
526 { cc<= [ \ CMOVLE (%boolean) ] }
527 { cc> [ \ CMOVG (%boolean) ] }
528 { cc>= [ \ CMOVGE (%boolean) ] }
529 { cc= [ \ CMOVE (%boolean) ] }
530 { cc/= [ \ CMOVNE (%boolean) ] }
533 M:: x86 %compare ( dst src1 src2 cc temp -- )
535 dst cc temp %boolean ;
537 M:: x86 %test ( dst src1 src2 cc temp -- )
539 dst cc temp %boolean ;
541 : (%compare-tagged) ( src1 src2 -- )
542 [ HEX: ffffffff CMP ] dip rc-absolute rel-literal ;
544 M:: x86 %compare-integer-imm ( dst src1 src2 cc temp -- )
546 dst cc temp %boolean ;
548 M:: x86 %test-imm ( dst src1 src2 cc temp -- )
550 dst cc temp %boolean ;
552 : (%compare-imm) ( src1 src2 -- )
554 { [ dup fixnum? ] [ tag-fixnum CMP ] }
555 { [ dup not ] [ drop \ f type-number CMP ] }
556 [ (%compare-tagged) ]
559 M:: x86 %compare-imm ( dst src1 src2 cc temp -- )
560 src1 src2 (%compare-imm)
561 dst cc temp %boolean ;
563 : %branch ( label cc -- )
573 M:: x86 %compare-branch ( label src1 src2 cc -- )
577 M:: x86 %compare-integer-imm-branch ( label src1 src2 cc -- )
581 M:: x86 %test-branch ( label src1 src2 cc -- )
585 M:: x86 %test-imm-branch ( label src1 src2 cc -- )
589 M:: x86 %compare-imm-branch ( label src1 src2 cc -- )
590 src1 src2 (%compare-imm)
593 M:: x86 %dispatch ( src temp -- )
594 ! Load jump table base.
595 temp HEX: ffffffff MOV
596 building get length :> start
597 0 rc-absolute-cell rel-here
598 ! Add jump table base
599 temp src HEX: 7f [++] JMP
600 building get length :> end
601 ! Fix up the displacement above
603 [ end start - + building get dup pop* push ]
607 M:: x86 %spill ( src rep dst -- )
610 M:: x86 %reload ( dst rep src -- )
613 M:: x86 %local-allot ( dst size align offset -- )
614 dst offset local-allot-offset special-offset stack@ LEA ;
616 : next-stack@ ( n -- operand )
617 #! nth parameter from the next stack frame. Used to box
618 #! input values to callbacks; the callback has its own
619 #! stack frame set up, and we want to read the frame
620 #! set up by the caller.
621 [ frame-reg ] dip 2 cells + reserved-stack-space + [+] ;
623 : return-reg ( rep -- reg )
624 reg-class-of return-regs at first ;
626 HOOK: %load-stack-param cpu ( vreg rep n -- )
628 HOOK: %store-stack-param cpu ( vreg rep n -- )
630 HOOK: %load-reg-param cpu ( vreg rep reg -- )
632 HOOK: %store-reg-param cpu ( vreg rep reg -- )
634 HOOK: %discard-reg-param cpu ( rep reg -- )
636 : %load-return ( dst rep -- )
637 dup return-reg %load-reg-param ;
639 : %store-return ( dst rep -- )
640 dup return-reg %store-reg-param ;
642 HOOK: %prepare-var-args cpu ( -- )
644 HOOK: %cleanup cpu ( n -- )
646 :: emit-alien-insn ( reg-inputs stack-inputs reg-outputs dead-outputs cleanup stack-size quot -- )
647 stack-inputs [ first3 %store-stack-param ] each
648 reg-inputs [ first3 %store-reg-param ] each
652 reg-outputs [ first3 %load-reg-param ] each
653 dead-outputs [ first2 %discard-reg-param ] each ; inline
655 M: x86 %alien-invoke ( reg-inputs stack-inputs reg-outputs dead-outputs cleanup stack-size symbols dll gc-map -- )
656 '[ _ _ _ %c-invoke ] emit-alien-insn ;
658 M:: x86 %alien-indirect ( src reg-inputs stack-inputs reg-outputs dead-outputs cleanup stack-size gc-map -- )
659 reg-inputs stack-inputs reg-outputs dead-outputs cleanup stack-size [
664 M: x86 %alien-assembly ( reg-inputs stack-inputs reg-outputs dead-outputs cleanup stack-size quot gc-map -- )
665 '[ _ _ gc-map set call( -- ) ] emit-alien-insn ;
667 HOOK: %begin-callback cpu ( -- )
669 M: x86 %callback-inputs ( reg-outputs stack-outputs -- )
670 [ [ first3 %load-reg-param ] each ]
671 [ [ first3 %load-stack-param ] each ] bi*
674 HOOK: %end-callback cpu ( -- )
676 M: x86 %callback-outputs ( reg-inputs -- )
678 [ first3 %store-reg-param ] each ;
680 M: x86 %loop-entry 16 alignment [ NOP ] times ;
682 M:: x86 %save-context ( temp1 temp2 -- )
683 #! Save Factor stack pointers in case the C code calls a
684 #! callback which does a GC, which must reliably trace
687 temp2 stack-reg cell neg [+] LEA
688 temp1 "callstack-top" context-field-offset [+] temp2 MOV
689 temp1 "datastack" context-field-offset [+] ds-reg MOV
690 temp1 "retainstack" context-field-offset [+] rs-reg MOV ;
692 M: x86 value-struct? drop t ;
694 M: x86 immediate-arithmetic? ( n -- ? )
695 HEX: -80000000 HEX: 7fffffff between? ;
697 M: x86 immediate-bitwise? ( n -- ? )
698 HEX: -80000000 HEX: 7fffffff between? ;
700 : %cmov-float= ( dst src -- )
702 "no-move" define-label
704 "no-move" get [ JNE ] [ JP ] bi
706 "no-move" resolve-label
709 : %cmov-float/= ( dst src -- )
711 "no-move" define-label
718 "no-move" resolve-label
721 :: (%compare-float) ( dst src1 src2 cc temp compare -- )
723 { cc< [ src2 src1 compare call( a b -- ) dst temp \ CMOVA (%boolean) ] }
724 { cc<= [ src2 src1 compare call( a b -- ) dst temp \ CMOVAE (%boolean) ] }
725 { cc> [ src1 src2 compare call( a b -- ) dst temp \ CMOVA (%boolean) ] }
726 { cc>= [ src1 src2 compare call( a b -- ) dst temp \ CMOVAE (%boolean) ] }
727 { cc= [ src1 src2 compare call( a b -- ) dst temp \ %cmov-float= (%boolean) ] }
728 { cc<> [ src1 src2 compare call( a b -- ) dst temp \ CMOVNE (%boolean) ] }
729 { cc<>= [ src1 src2 compare call( a b -- ) dst temp \ CMOVNP (%boolean) ] }
730 { cc/< [ src2 src1 compare call( a b -- ) dst temp \ CMOVBE (%boolean) ] }
731 { cc/<= [ src2 src1 compare call( a b -- ) dst temp \ CMOVB (%boolean) ] }
732 { cc/> [ src1 src2 compare call( a b -- ) dst temp \ CMOVBE (%boolean) ] }
733 { cc/>= [ src1 src2 compare call( a b -- ) dst temp \ CMOVB (%boolean) ] }
734 { cc/= [ src1 src2 compare call( a b -- ) dst temp \ %cmov-float/= (%boolean) ] }
735 { cc/<> [ src1 src2 compare call( a b -- ) dst temp \ CMOVE (%boolean) ] }
736 { cc/<>= [ src1 src2 compare call( a b -- ) dst temp \ CMOVP (%boolean) ] }
739 : %jump-float= ( label -- )
741 "no-jump" define-label
744 "no-jump" resolve-label
747 : %jump-float/= ( label -- )
750 :: (%compare-float-branch) ( label src1 src2 cc compare -- )
752 { cc< [ src2 src1 compare call( a b -- ) label JA ] }
753 { cc<= [ src2 src1 compare call( a b -- ) label JAE ] }
754 { cc> [ src1 src2 compare call( a b -- ) label JA ] }
755 { cc>= [ src1 src2 compare call( a b -- ) label JAE ] }
756 { cc= [ src1 src2 compare call( a b -- ) label %jump-float= ] }
757 { cc<> [ src1 src2 compare call( a b -- ) label JNE ] }
758 { cc<>= [ src1 src2 compare call( a b -- ) label JNP ] }
759 { cc/< [ src2 src1 compare call( a b -- ) label JBE ] }
760 { cc/<= [ src2 src1 compare call( a b -- ) label JB ] }
761 { cc/> [ src1 src2 compare call( a b -- ) label JBE ] }
762 { cc/>= [ src1 src2 compare call( a b -- ) label JB ] }
763 { cc/= [ src1 src2 compare call( a b -- ) label %jump-float/= ] }
764 { cc/<> [ src1 src2 compare call( a b -- ) label JE ] }
765 { cc/<>= [ src1 src2 compare call( a b -- ) label JP ] }
772 "Checking for multimedia extensions... " write flush
773 [ { (sse-version) } compile ] with-optimizer
775 [ sse-string " detected" append print ]
776 [ 20 < "cpu.x86.x87" "cpu.x86.sse" ? require ] bi ;