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
10 compiler.cfg.registers
11 compiler.cfg.instructions
12 compiler.cfg.intrinsics
13 compiler.cfg.comparisons
14 compiler.cfg.stack-frame
15 compiler.codegen.gc-maps
16 compiler.codegen.labels
17 compiler.codegen.relocation ;
18 QUALIFIED-WITH: alien.c-types c
19 FROM: layouts => cell ;
23 ! Add some methods to the assembler to be more useful to the backend
24 M: label JMP 0 JMP rc-relative label-fixup ;
25 M: label JUMPcc [ 0 ] dip JUMPcc rc-relative label-fixup ;
27 M: x86 vector-regs float-regs ;
29 HOOK: stack-reg cpu ( -- reg )
31 HOOK: reserved-stack-space cpu ( -- n )
33 : stack@ ( n -- op ) stack-reg swap [+] ;
35 : special-offset ( m -- n )
36 reserved-stack-space + ;
38 : spill@ ( n -- op ) spill-offset special-offset stack@ ;
40 : decr-stack-reg ( n -- )
41 dup 0 = [ drop ] [ stack-reg swap SUB ] if ;
43 : incr-stack-reg ( n -- )
44 dup 0 = [ drop ] [ stack-reg swap ADD ] if ;
46 : align-stack ( n -- n' ) 16 align ;
48 M: x86 stack-frame-size ( stack-frame -- i )
50 reserved-stack-space +
54 HOOK: pic-tail-reg cpu ( -- reg )
56 M: x86 complex-addressing? t ;
58 M: x86 fused-unboxing? t ;
60 M: x86 test-instruction? t ;
62 M: x86 immediate-store? immediate-comparand? ;
64 M: x86 %load-immediate dup 0 = [ drop dup XOR ] [ MOV ] if ;
66 M: x86 %load-reference
67 [ swap 0 MOV rc-absolute-cell rel-literal ]
68 [ \ f type-number MOV ]
71 HOOK: ds-reg cpu ( -- reg )
72 HOOK: rs-reg cpu ( -- reg )
74 : reg-stack ( n reg -- op ) swap cells neg [+] ;
76 GENERIC: loc>operand ( loc -- operand )
78 M: ds-loc loc>operand n>> ds-reg reg-stack ;
79 M: rs-loc loc>operand n>> rs-reg reg-stack ;
81 M: x86 %peek loc>operand MOV ;
83 M: x86 %replace loc>operand swap MOV ;
88 { [ dup not ] [ drop \ f type-number MOV ] }
89 { [ dup fixnum? ] [ tag-fixnum MOV ] }
90 [ [ HEX: ffffffff MOV ] dip rc-absolute rel-literal ]
93 : (%inc) ( n reg -- ) swap cells dup 0 > [ ADD ] [ neg SUB ] if ; inline
94 M: x86 %inc-d ( n -- ) ds-reg (%inc) ;
95 M: x86 %inc-r ( n -- ) rs-reg (%inc) ;
97 M: x86 %call ( word -- ) 0 CALL rc-relative rel-word-pic ;
99 : xt-tail-pic-offset ( -- n )
100 #! See the comment in vm/cpu-x86.hpp
103 HOOK: %prepare-jump cpu ( -- )
105 M: x86 %jump ( word -- )
107 0 JMP rc-relative rel-word-pic-tail ;
109 M: x86 %jump-label ( label -- ) 0 JMP rc-relative label-fixup ;
111 M: x86 %return ( -- ) 0 RET ;
113 : (%slot) ( obj slot scale tag -- op ) neg <indirect> ; inline
114 : (%slot-imm) ( obj slot tag -- op ) slot-offset [+] ; inline
116 M: x86 %slot ( dst obj slot scale tag -- ) (%slot) MOV ;
117 M: x86 %slot-imm ( dst obj slot tag -- ) (%slot-imm) MOV ;
118 M: x86 %set-slot ( src obj slot scale tag -- ) (%slot) swap MOV ;
119 M: x86 %set-slot-imm ( src obj slot tag -- ) (%slot-imm) swap MOV ;
121 :: two-operand ( dst src1 src2 rep -- dst src )
122 dst src2 eq? dst src1 eq? not and [ "Cannot handle this case" throw ] when
126 :: one-operand ( dst src rep -- dst )
130 M: x86 %add 2over eq? [ nip ADD ] [ [+] LEA ] if ;
131 M: x86 %add-imm 2over eq? [ nip ADD ] [ [+] LEA ] if ;
132 M: x86 %sub int-rep two-operand SUB ;
133 M: x86 %sub-imm 2over eq? [ nip SUB ] [ neg [+] LEA ] if ;
134 M: x86 %mul int-rep two-operand IMUL2 ;
135 M: x86 %mul-imm IMUL3 ;
136 M: x86 %and int-rep two-operand AND ;
137 M: x86 %and-imm int-rep two-operand AND ;
138 M: x86 %or int-rep two-operand OR ;
139 M: x86 %or-imm int-rep two-operand OR ;
140 M: x86 %xor int-rep two-operand XOR ;
141 M: x86 %xor-imm int-rep two-operand XOR ;
142 M: x86 %shl-imm int-rep two-operand SHL ;
143 M: x86 %shr-imm int-rep two-operand SHR ;
144 M: x86 %sar-imm int-rep two-operand SAR ;
146 M: x86 %min int-rep two-operand [ CMP ] [ CMOVG ] 2bi ;
147 M: x86 %max int-rep two-operand [ CMP ] [ CMOVL ] 2bi ;
149 M: x86 %not int-rep one-operand NOT ;
150 M: x86 %neg int-rep one-operand NEG ;
152 M: x86 %bit-count POPCNT ;
154 ! A bit of logic to avoid using MOVSS/MOVSD for reg-reg moves
155 ! since this induces partial register stalls
156 GENERIC: copy-register* ( dst src rep -- )
157 GENERIC: copy-memory* ( dst src rep -- )
159 M: int-rep copy-register* drop MOV ;
160 M: tagged-rep copy-register* drop MOV ;
162 M: object copy-memory* copy-register* ;
164 : ?spill-slot ( obj -- obj ) dup spill-slot? [ n>> spill@ ] when ;
166 M: x86 %copy ( dst src rep -- )
167 2over eq? [ 3drop ] [
168 [ [ ?spill-slot ] bi@ ] dip
169 2over [ register? ] both? [ copy-register* ] [ copy-memory* ] if
172 : fixnum-overflow ( label dst src1 src2 cc quot -- )
173 swap [ [ int-rep two-operand ] dip call ] dip
179 M: x86 %fixnum-add ( label dst src1 src2 cc -- )
180 [ ADD ] fixnum-overflow ;
182 M: x86 %fixnum-sub ( label dst src1 src2 cc -- )
183 [ SUB ] fixnum-overflow ;
185 M: x86 %fixnum-mul ( label dst src1 src2 cc -- )
186 [ IMUL2 ] fixnum-overflow ;
188 M: x86 %unbox-alien ( dst src -- )
189 alien-offset [+] MOV ;
191 M:: x86 %unbox-any-c-ptr ( dst src -- )
196 src \ f type-number CMP
198 ! Compute tag in dst register
201 ! Is the object an alien?
202 dst alien type-number CMP
203 ! Add an offset to start of byte array's data
204 dst src byte-array-offset [+] LEA
206 ! If so, load the offset and add it to the address
207 dst src alien-offset [+] MOV
211 : alien@ ( reg n -- op ) cells alien type-number - [+] ;
213 M:: x86 %box-alien ( dst src temp -- )
216 dst \ f type-number MOV
219 dst 5 cells alien temp %allot
220 dst 1 alien@ \ f type-number MOV ! base
221 dst 2 alien@ \ f type-number MOV ! expired
222 dst 3 alien@ src MOV ! displacement
223 dst 4 alien@ src MOV ! address
227 :: %box-displaced-alien/f ( dst displacement -- )
228 dst 1 alien@ \ f type-number MOV
229 dst 3 alien@ displacement MOV
230 dst 4 alien@ displacement MOV ;
232 :: %box-displaced-alien/alien ( dst displacement base temp -- )
233 ! Set new alien's base to base.base
234 temp base 1 alien@ MOV
235 dst 1 alien@ temp MOV
237 ! Compute displacement
238 temp base 3 alien@ MOV
239 temp displacement ADD
240 dst 3 alien@ temp MOV
243 temp base 4 alien@ MOV
244 temp displacement ADD
245 dst 4 alien@ temp MOV ;
247 :: %box-displaced-alien/byte-array ( dst displacement base temp -- )
248 dst 1 alien@ base MOV
249 dst 3 alien@ displacement MOV
250 temp base displacement byte-array-offset [++] LEA
251 dst 4 alien@ temp MOV ;
253 :: %box-displaced-alien/dynamic ( dst displacement base temp -- )
255 "not-alien" define-label
259 temp tag-mask get AND
262 temp \ f type-number CMP
265 ! Yes, it is f. Fill in new object
266 dst displacement %box-displaced-alien/f
270 "not-f" resolve-label
273 temp alien type-number CMP
276 dst displacement base temp %box-displaced-alien/alien
281 ! Is base a byte array? It has to be, by now...
282 "not-alien" resolve-label
284 dst displacement base temp %box-displaced-alien/byte-array ;
286 M:: x86 %box-displaced-alien ( dst displacement base temp base-class -- )
290 ! If displacement is zero, return the base
292 displacement displacement TEST
295 ! Displacement is non-zero, we're going to be allocating a new
297 dst 5 cells alien temp %allot
300 dst 2 alien@ \ f type-number MOV
302 dst displacement base temp
304 { [ base-class \ f class<= ] [ 2drop %box-displaced-alien/f ] }
305 { [ base-class \ alien class<= ] [ %box-displaced-alien/alien ] }
306 { [ base-class \ byte-array class<= ] [ %box-displaced-alien/byte-array ] }
307 [ %box-displaced-alien/dynamic ]
313 ! The 'small-reg' mess is pretty crappy, but its only used on x86-32.
314 ! On x86-64, all registers have 8-bit versions. However, a similar
315 ! problem arises for shifts, where the shift count must be in CL, and
316 ! so one day I will fix this properly by adding precoloring to the
317 ! register allocator.
319 HOOK: has-small-reg? cpu ( reg size -- ? )
321 CONSTANT: have-byte-regs { EAX ECX EDX EBX }
323 M: x86.32 has-small-reg?
325 { 8 [ have-byte-regs member-eq? ] }
330 M: x86.64 has-small-reg? 2drop t ;
332 : small-reg-that-isn't ( exclude -- reg' )
333 [ have-byte-regs ] dip
334 [ native-version-of ] map
335 '[ _ member-eq? not ] find nip ;
337 : with-save/restore ( reg quot -- )
338 [ drop PUSH ] [ call ] [ drop POP ] 2tri ; inline
340 :: with-small-register ( dst exclude size quot: ( new-dst -- ) -- )
341 ! If the destination register overlaps a small register with
342 ! 'size' bits, we call the quot with that. Otherwise, we find a
343 ! small register that is not in exclude, and call quot, saving and
344 ! restoring the small register.
345 dst size has-small-reg? [ dst quot call ] [
346 exclude small-reg-that-isn't
347 [ quot call ] with-save/restore
350 :: (%convert-integer) ( dst src bits quot -- )
351 dst { src } bits [| new-dst |
352 new-dst src int-rep %copy
353 new-dst dup bits n-bit-version-of quot call
354 dst new-dst int-rep %copy
355 ] with-small-register ; inline
357 : %zero-extend ( dst src bits -- )
358 [ MOVZX ] (%convert-integer) ; inline
360 : %sign-extend ( dst src bits -- )
361 [ MOVSX ] (%convert-integer) ; inline
363 M: x86 %convert-integer ( dst src c-type -- )
365 { c:char [ 8 %sign-extend ] }
366 { c:uchar [ 8 %zero-extend ] }
367 { c:short [ 16 %sign-extend ] }
368 { c:ushort [ 16 %zero-extend ] }
369 { c:int [ 32 %sign-extend ] }
370 { c:uint [ 32 [ 2drop ] (%convert-integer) ] }
373 :: %alien-integer-getter ( dst exclude address bits quot -- )
374 dst exclude bits [| new-dst |
375 new-dst dup bits n-bit-version-of dup address MOV
377 dst new-dst int-rep %copy
378 ] with-small-register ; inline
380 : %alien-unsigned-getter ( dst exclude address bits -- )
381 [ MOVZX ] %alien-integer-getter ; inline
383 : %alien-signed-getter ( dst exclude address bits -- )
384 [ MOVSX ] %alien-integer-getter ; inline
386 :: %alien-integer-setter ( value exclude address bits -- )
387 value exclude bits [| new-value |
388 new-value value int-rep %copy
389 address new-value bits n-bit-version-of MOV
390 ] with-small-register ; inline
392 : (%memory) ( base displacement scale offset rep c-type -- exclude address rep c-type )
393 [ [ [ 2array ] 2keep ] 2dip <indirect> ] 2dip ;
395 : (%memory-imm) ( base offset rep c-type -- exclude address rep c-type )
396 [ [ drop 1array ] [ [+] ] 2bi ] 2dip ;
398 : (%load-memory) ( dst exclude address rep c-type -- )
401 { c:char [ 8 %alien-signed-getter ] }
402 { c:uchar [ 8 %alien-unsigned-getter ] }
403 { c:short [ 16 %alien-signed-getter ] }
404 { c:ushort [ 16 %alien-unsigned-getter ] }
405 { c:int [ 32 %alien-signed-getter ] }
406 { c:uint [ 32 [ 2drop ] %alien-integer-getter ] }
408 ] [ [ drop ] 2dip %copy ] ?if ;
410 M: x86 %load-memory ( dst base displacement scale offset rep c-type -- )
411 (%memory) (%load-memory) ;
413 M: x86 %load-memory-imm ( dst base offset rep c-type -- )
414 (%memory-imm) (%load-memory) ;
416 : (%store-memory) ( src exclude address rep c-type -- )
419 { c:char [ 8 %alien-integer-setter ] }
420 { c:uchar [ 8 %alien-integer-setter ] }
421 { c:short [ 16 %alien-integer-setter ] }
422 { c:ushort [ 16 %alien-integer-setter ] }
423 { c:int [ 32 %alien-integer-setter ] }
424 { c:uint [ 32 %alien-integer-setter ] }
426 ] [ [ nip swap ] dip %copy ] ?if ;
428 M: x86 %store-memory ( src base displacement scale offset rep c-type -- )
429 (%memory) (%store-memory) ;
431 M: x86 %store-memory-imm ( src base offset rep c-type -- )
432 (%memory-imm) (%store-memory) ;
434 : shift-count? ( reg -- ? ) { ECX RCX } member-eq? ;
436 :: emit-shift ( dst src quot -- )
445 ECX native-version-of [
447 drop dst CL quot call
452 M: x86 %shl int-rep two-operand [ SHL ] emit-shift ;
453 M: x86 %shr int-rep two-operand [ SHR ] emit-shift ;
454 M: x86 %sar int-rep two-operand [ SAR ] emit-shift ;
456 HOOK: %mov-vm-ptr cpu ( reg -- )
458 HOOK: %vm-field-ptr cpu ( reg offset -- )
460 : load-zone-offset ( nursery-ptr -- )
461 "nursery" vm-field-offset %vm-field-ptr ;
463 : load-allot-ptr ( nursery-ptr allot-ptr -- )
464 [ drop load-zone-offset ] [ swap [] MOV ] 2bi ;
466 : inc-allot-ptr ( nursery-ptr n -- )
467 [ [] ] dip data-alignment get align ADD ;
469 : store-header ( temp class -- )
470 [ [] ] [ type-number tag-header ] bi* MOV ;
472 : store-tagged ( dst tag -- )
475 M:: x86 %allot ( dst size class nursery-ptr -- )
476 nursery-ptr dst load-allot-ptr
477 dst class store-header
478 dst class store-tagged
479 nursery-ptr size inc-allot-ptr ;
481 HOOK: %mark-card cpu ( card temp -- )
482 HOOK: %mark-deck cpu ( card temp -- )
484 :: (%write-barrier) ( temp1 temp2 -- )
486 temp1 temp2 %mark-card
487 temp1 deck-bits card-bits - SHR
488 temp1 temp2 %mark-deck ;
490 M:: x86 %write-barrier ( src slot scale tag temp1 temp2 -- )
491 temp1 src slot scale tag (%slot) LEA
492 temp1 temp2 (%write-barrier) ;
494 M:: x86 %write-barrier-imm ( src slot tag temp1 temp2 -- )
495 temp1 src slot tag (%slot-imm) LEA
496 temp1 temp2 (%write-barrier) ;
498 M:: x86 %check-nursery-branch ( label size cc temp1 temp2 -- )
499 temp1 load-zone-offset
502 temp2 temp1 2 cells [+] CMP
504 { cc<= [ label JLE ] }
505 { cc/<= [ label JG ] }
508 M: x86 gc-root-offset
509 n>> spill-offset special-offset cell + cell /i ;
511 M: x86 %call-gc ( gc-map -- )
515 M: x86 %alien-global ( dst symbol library -- )
516 [ 0 MOV ] 2dip rc-absolute-cell rel-dlsym ;
518 M: x86 %epilogue ( n -- ) cell - incr-stack-reg ;
520 :: (%boolean) ( dst temp insn -- )
521 dst \ f type-number MOV
522 temp 0 MOV \ t rc-absolute-cell rel-literal
523 dst temp insn execute ; inline
525 : %boolean ( dst cc temp -- )
527 { cc< [ \ CMOVL (%boolean) ] }
528 { cc<= [ \ CMOVLE (%boolean) ] }
529 { cc> [ \ CMOVG (%boolean) ] }
530 { cc>= [ \ CMOVGE (%boolean) ] }
531 { cc= [ \ CMOVE (%boolean) ] }
532 { cc/= [ \ CMOVNE (%boolean) ] }
535 M:: x86 %compare ( dst src1 src2 cc temp -- )
537 dst cc temp %boolean ;
539 M:: x86 %test ( dst src1 src2 cc temp -- )
541 dst cc temp %boolean ;
543 : (%compare-tagged) ( src1 src2 -- )
544 [ HEX: ffffffff CMP ] dip rc-absolute rel-literal ;
546 M:: x86 %compare-integer-imm ( dst src1 src2 cc temp -- )
548 dst cc temp %boolean ;
550 M:: x86 %test-imm ( dst src1 src2 cc temp -- )
552 dst cc temp %boolean ;
554 : (%compare-imm) ( src1 src2 -- )
556 { [ dup fixnum? ] [ tag-fixnum CMP ] }
557 { [ dup not ] [ drop \ f type-number CMP ] }
558 [ (%compare-tagged) ]
561 M:: x86 %compare-imm ( dst src1 src2 cc temp -- )
562 src1 src2 (%compare-imm)
563 dst cc temp %boolean ;
565 : %branch ( label cc -- )
575 M:: x86 %compare-branch ( label src1 src2 cc -- )
579 M:: x86 %compare-integer-imm-branch ( label src1 src2 cc -- )
583 M:: x86 %test-branch ( label src1 src2 cc -- )
587 M:: x86 %test-imm-branch ( label src1 src2 cc -- )
591 M:: x86 %compare-imm-branch ( label src1 src2 cc -- )
592 src1 src2 (%compare-imm)
595 M:: x86 %dispatch ( src temp -- )
596 ! Load jump table base.
597 temp HEX: ffffffff MOV
598 building get length :> start
599 0 rc-absolute-cell rel-here
600 ! Add jump table base
601 temp src HEX: 7f [++] JMP
602 building get length :> end
603 ! Fix up the displacement above
605 [ end start - + building get dup pop* push ]
609 M:: x86 %spill ( src rep dst -- )
612 M:: x86 %reload ( dst rep src -- )
615 M:: x86 %local-allot ( dst size align offset -- )
616 dst offset local-allot-offset special-offset stack@ LEA ;
618 : next-stack@ ( n -- operand )
619 #! nth parameter from the next stack frame. Used to box
620 #! input values to callbacks; the callback has its own
621 #! stack frame set up, and we want to read the frame
622 #! set up by the caller.
623 [ frame-reg ] dip 2 cells + reserved-stack-space + [+] ;
625 : return-reg ( rep -- reg )
626 reg-class-of return-regs at first ;
628 HOOK: %load-stack-param cpu ( vreg rep n -- )
630 HOOK: %store-stack-param cpu ( vreg rep n -- )
632 HOOK: %load-reg-param cpu ( vreg rep reg -- )
634 HOOK: %store-reg-param cpu ( vreg rep reg -- )
636 HOOK: %discard-reg-param cpu ( rep reg -- )
638 : %load-return ( dst rep -- )
639 dup return-reg %load-reg-param ;
641 : %store-return ( dst rep -- )
642 dup return-reg %store-reg-param ;
644 HOOK: %prepare-var-args cpu ( -- )
646 HOOK: %cleanup cpu ( n -- )
648 :: emit-alien-insn ( reg-inputs stack-inputs reg-outputs dead-outputs cleanup stack-size quot -- )
649 stack-inputs [ first3 %store-stack-param ] each
650 reg-inputs [ first3 %store-reg-param ] each
654 reg-outputs [ first3 %load-reg-param ] each
655 dead-outputs [ first2 %discard-reg-param ] each ; inline
657 M: x86 %alien-invoke ( reg-inputs stack-inputs reg-outputs dead-outputs cleanup stack-size symbols dll gc-map -- )
658 '[ _ _ _ %c-invoke ] emit-alien-insn ;
660 M:: x86 %alien-indirect ( src reg-inputs stack-inputs reg-outputs dead-outputs cleanup stack-size gc-map -- )
661 reg-inputs stack-inputs reg-outputs dead-outputs cleanup stack-size [
666 M: x86 %alien-assembly ( reg-inputs stack-inputs reg-outputs dead-outputs cleanup stack-size quot gc-map -- )
667 '[ _ _ gc-map set call( -- ) ] emit-alien-insn ;
669 HOOK: %begin-callback cpu ( -- )
671 M: x86 %callback-inputs ( reg-outputs stack-outputs -- )
672 [ [ first3 %load-reg-param ] each ]
673 [ [ first3 %load-stack-param ] each ] bi*
676 HOOK: %end-callback cpu ( -- )
678 M: x86 %callback-outputs ( reg-inputs -- )
680 [ first3 %store-reg-param ] each ;
682 M: x86 %loop-entry 16 alignment [ NOP ] times ;
684 M:: x86 %save-context ( temp1 temp2 -- )
685 #! Save Factor stack pointers in case the C code calls a
686 #! callback which does a GC, which must reliably trace
689 temp2 stack-reg cell neg [+] LEA
690 temp1 "callstack-top" context-field-offset [+] temp2 MOV
691 temp1 "datastack" context-field-offset [+] ds-reg MOV
692 temp1 "retainstack" context-field-offset [+] rs-reg MOV ;
694 M: x86 value-struct? drop t ;
696 M: x86 long-long-odd-register? f ;
698 M: x86 float-right-align-on-stack? f ;
700 M: x86 immediate-arithmetic? ( n -- ? )
701 HEX: -80000000 HEX: 7fffffff between? ;
703 M: x86 immediate-bitwise? ( n -- ? )
704 HEX: -80000000 HEX: 7fffffff between? ;
706 : %cmov-float= ( dst src -- )
708 "no-move" define-label
710 "no-move" get [ JNE ] [ JP ] bi
712 "no-move" resolve-label
715 : %cmov-float/= ( dst src -- )
717 "no-move" define-label
724 "no-move" resolve-label
727 :: (%compare-float) ( dst src1 src2 cc temp compare -- )
729 { cc< [ src2 src1 compare call( a b -- ) dst temp \ CMOVA (%boolean) ] }
730 { cc<= [ src2 src1 compare call( a b -- ) dst temp \ CMOVAE (%boolean) ] }
731 { cc> [ src1 src2 compare call( a b -- ) dst temp \ CMOVA (%boolean) ] }
732 { cc>= [ src1 src2 compare call( a b -- ) dst temp \ CMOVAE (%boolean) ] }
733 { cc= [ src1 src2 compare call( a b -- ) dst temp \ %cmov-float= (%boolean) ] }
734 { cc<> [ src1 src2 compare call( a b -- ) dst temp \ CMOVNE (%boolean) ] }
735 { cc<>= [ src1 src2 compare call( a b -- ) dst temp \ CMOVNP (%boolean) ] }
736 { cc/< [ src2 src1 compare call( a b -- ) dst temp \ CMOVBE (%boolean) ] }
737 { cc/<= [ src2 src1 compare call( a b -- ) dst temp \ CMOVB (%boolean) ] }
738 { cc/> [ src1 src2 compare call( a b -- ) dst temp \ CMOVBE (%boolean) ] }
739 { cc/>= [ src1 src2 compare call( a b -- ) dst temp \ CMOVB (%boolean) ] }
740 { cc/= [ src1 src2 compare call( a b -- ) dst temp \ %cmov-float/= (%boolean) ] }
741 { cc/<> [ src1 src2 compare call( a b -- ) dst temp \ CMOVE (%boolean) ] }
742 { cc/<>= [ src1 src2 compare call( a b -- ) dst temp \ CMOVP (%boolean) ] }
745 : %jump-float= ( label -- )
747 "no-jump" define-label
750 "no-jump" resolve-label
753 : %jump-float/= ( label -- )
756 :: (%compare-float-branch) ( label src1 src2 cc compare -- )
758 { cc< [ src2 src1 compare call( a b -- ) label JA ] }
759 { cc<= [ src2 src1 compare call( a b -- ) label JAE ] }
760 { cc> [ src1 src2 compare call( a b -- ) label JA ] }
761 { cc>= [ src1 src2 compare call( a b -- ) label JAE ] }
762 { cc= [ src1 src2 compare call( a b -- ) label %jump-float= ] }
763 { cc<> [ src1 src2 compare call( a b -- ) label JNE ] }
764 { cc<>= [ src1 src2 compare call( a b -- ) label JNP ] }
765 { cc/< [ src2 src1 compare call( a b -- ) label JBE ] }
766 { cc/<= [ src2 src1 compare call( a b -- ) label JB ] }
767 { cc/> [ src1 src2 compare call( a b -- ) label JBE ] }
768 { cc/>= [ src1 src2 compare call( a b -- ) label JB ] }
769 { cc/= [ src1 src2 compare call( a b -- ) label %jump-float/= ] }
770 { cc/<> [ src1 src2 compare call( a b -- ) label JE ] }
771 { cc/<>= [ src1 src2 compare call( a b -- ) label JP ] }
778 "Checking for multimedia extensions... " write flush
779 [ { (sse-version) } compile ] with-optimizer
781 [ sse-string " detected" append print ]
782 [ 20 < "cpu.x86.x87" "cpu.x86.sse" ? require ] bi ;