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.architecture kernel kernel.private math memory namespaces make
6 sequences words system layouts combinators math.order fry locals
7 compiler.constants vm byte-arrays
9 compiler.cfg.instructions
10 compiler.cfg.intrinsics
11 compiler.cfg.comparisons
12 compiler.cfg.stack-frame
13 compiler.codegen.fixup ;
14 FROM: layouts => cell ;
18 ! Add some methods to the assembler to be more useful to the backend
19 M: label JMP 0 JMP rc-relative label-fixup ;
20 M: label JUMPcc [ 0 ] dip JUMPcc rc-relative label-fixup ;
22 M: x86 two-operand? t ;
24 HOOK: stack-reg cpu ( -- reg )
26 HOOK: reserved-area-size cpu ( -- n )
28 : stack@ ( n -- op ) stack-reg swap [+] ;
30 : param@ ( n -- op ) reserved-area-size + stack@ ;
32 : spill@ ( n -- op ) spill-offset param@ ;
34 : gc-root@ ( n -- op ) gc-root-offset param@ ;
36 : decr-stack-reg ( n -- )
37 dup 0 = [ drop ] [ stack-reg swap SUB ] if ;
39 : incr-stack-reg ( n -- )
40 dup 0 = [ drop ] [ stack-reg swap ADD ] if ;
42 : align-stack ( n -- n' )
43 os macosx? cpu x86.64? or [ 16 align ] when ;
45 M: x86 stack-frame-size ( stack-frame -- i )
46 (stack-frame-size) 3 cells reserved-area-size + + align-stack ;
48 ! Must be a volatile register not used for parameter passing, for safe
49 ! use in calls in and out of C
50 HOOK: temp-reg cpu ( -- reg )
52 ! Fastcall calling convention
53 HOOK: param-reg-1 cpu ( -- reg )
54 HOOK: param-reg-2 cpu ( -- reg )
56 HOOK: pic-tail-reg cpu ( -- reg )
58 M: x86 %load-immediate dup 0 = [ drop dup XOR ] [ MOV ] if ;
60 M: x86 %load-reference swap 0 MOV rc-absolute-cell rel-immediate ;
62 HOOK: ds-reg cpu ( -- reg )
63 HOOK: rs-reg cpu ( -- reg )
65 : reg-stack ( n reg -- op ) swap cells neg [+] ;
67 GENERIC: loc>operand ( loc -- operand )
69 M: ds-loc loc>operand n>> ds-reg reg-stack ;
70 M: rs-loc loc>operand n>> rs-reg reg-stack ;
72 M: x86 %peek loc>operand MOV ;
73 M: x86 %replace loc>operand swap MOV ;
74 : (%inc) ( n reg -- ) swap cells dup 0 > [ ADD ] [ neg SUB ] if ; inline
75 M: x86 %inc-d ( n -- ) ds-reg (%inc) ;
76 M: x86 %inc-r ( n -- ) rs-reg (%inc) ;
78 M: x86 %call ( word -- ) 0 CALL rc-relative rel-word-pic ;
80 : xt-tail-pic-offset ( -- n )
81 #! See the comment in vm/cpu-x86.hpp
84 M: x86 %jump ( word -- )
85 pic-tail-reg 0 MOV xt-tail-pic-offset rc-absolute-cell rel-here
86 0 JMP rc-relative rel-word-pic-tail ;
88 M: x86 %jump-label ( label -- ) 0 JMP rc-relative label-fixup ;
90 M: x86 %return ( -- ) 0 RET ;
92 : code-alignment ( align -- n )
93 [ building get length dup ] dip align swap - ;
98 :: (%slot) ( obj slot tag temp -- op )
100 temp tag neg [+] ; inline
102 :: (%slot-imm) ( obj slot tag -- op )
103 obj slot cells tag - [+] ; inline
105 M: x86 %slot ( dst obj slot tag temp -- ) (%slot) MOV ;
106 M: x86 %slot-imm ( dst obj slot tag -- ) (%slot-imm) MOV ;
107 M: x86 %set-slot ( src obj slot tag temp -- ) (%slot) swap MOV ;
108 M: x86 %set-slot-imm ( src obj slot tag -- ) (%slot-imm) swap MOV ;
110 M: x86 %add 2over eq? [ nip ADD ] [ [+] LEA ] if ;
111 M: x86 %add-imm 2over eq? [ nip ADD ] [ [+] LEA ] if ;
112 M: x86 %sub nip SUB ;
113 M: x86 %sub-imm 2over eq? [ nip SUB ] [ neg [+] LEA ] if ;
114 M: x86 %mul nip swap IMUL2 ;
115 M: x86 %mul-imm IMUL3 ;
116 M: x86 %and nip AND ;
117 M: x86 %and-imm nip AND ;
119 M: x86 %or-imm nip OR ;
120 M: x86 %xor nip XOR ;
121 M: x86 %xor-imm nip XOR ;
122 M: x86 %shl-imm nip SHL ;
123 M: x86 %shr-imm nip SHR ;
124 M: x86 %sar-imm nip SAR ;
126 M: x86 %min nip [ CMP ] [ CMOVG ] 2bi ;
127 M: x86 %max nip [ CMP ] [ CMOVL ] 2bi ;
129 M: x86 %not drop NOT ;
132 GENERIC: copy-register* ( dst src rep -- )
134 M: int-rep copy-register* drop MOV ;
135 M: tagged-rep copy-register* drop MOV ;
136 M: float-rep copy-register* drop MOVSS ;
137 M: double-rep copy-register* drop MOVSD ;
138 M: float-4-rep copy-register* drop MOVUPS ;
139 M: double-2-rep copy-register* drop MOVUPD ;
140 M: vector-rep copy-register* drop MOVDQU ;
142 : copy-register ( dst src rep -- )
143 2over eq? [ 3drop ] [ copy-register* ] if ;
145 M: x86 %copy ( dst src rep -- ) copy-register ;
147 :: overflow-template ( label dst src1 src2 insn -- )
151 M: x86 %fixnum-add ( label dst src1 src2 -- )
152 [ ADD ] overflow-template ;
154 M: x86 %fixnum-sub ( label dst src1 src2 -- )
155 [ SUB ] overflow-template ;
157 M: x86 %fixnum-mul ( label dst src1 src2 -- )
158 [ swap IMUL2 ] overflow-template ;
160 : bignum@ ( reg n -- op )
161 cells bignum tag-number - [+] ; inline
163 M:: x86 %integer>bignum ( dst src temp -- )
164 #! on entry, inreg is a signed 32-bit quantity
165 #! exits with tagged ptr to bignum in outreg
166 #! 1 cell header, 1 cell length, 1 cell sign, + digits
167 #! length is the # of digits + sign
170 ! Load cached zero value
171 dst 0 >bignum %load-reference
173 ! Is it zero? Then just go to the end and return this zero
176 dst 4 cells bignum temp %allot
178 dst 1 bignum@ 2 tag-fixnum MOV
180 dst 3 bignum@ src MOV
183 temp cell-bits 1 - SAR
186 dst 2 bignum@ temp MOV
187 ! Make negative value positive
193 dst 3 bignum@ temp MOV
197 M:: x86 %bignum>integer ( dst src temp -- )
201 temp src 1 bignum@ MOV
202 ! if the length is 1, its just the sign and nothing else,
205 temp 1 tag-fixnum CMP
208 dst src 3 bignum@ MOV
210 temp src 2 bignum@ MOV
211 ! convert it into -1 or 1
220 M: x86 %add-float nip ADDSD ;
221 M: x86 %sub-float nip SUBSD ;
222 M: x86 %mul-float nip MULSD ;
223 M: x86 %div-float nip DIVSD ;
224 M: x86 %min-float nip MINSD ;
225 M: x86 %max-float nip MAXSD ;
226 M: x86 %sqrt SQRTSD ;
228 M: x86 %single>double-float CVTSS2SD ;
229 M: x86 %double>single-float CVTSD2SS ;
231 M: x86 %integer>float CVTSI2SD ;
232 M: x86 %float>integer CVTTSD2SI ;
234 M: x86 %unbox-float ( dst src -- )
235 float-offset [+] MOVSD ;
237 M:: x86 %box-float ( dst src temp -- )
238 dst 16 float temp %allot
239 dst float-offset [+] src MOVSD ;
241 M:: x86 %box-vector ( dst src rep temp -- )
242 dst rep rep-size 2 cells + byte-array temp %allot
243 16 tag-fixnum dst 1 byte-array tag-number %set-slot-imm
244 dst byte-array-offset [+]
245 src rep copy-register ;
247 M:: x86 %unbox-vector ( dst src rep -- )
248 dst src byte-array-offset [+]
251 M: x86 %broadcast-vector ( dst src rep -- )
253 { float-4-rep [ [ MOVSS ] [ drop dup 0 SHUFPS ] 2bi ] }
254 { double-2-rep [ [ MOVSD ] [ drop dup UNPCKLPD ] 2bi ] }
257 M:: x86 %gather-vector-4 ( dst src1 src2 src3 src4 rep -- )
270 M:: x86 %gather-vector-2 ( dst src1 src2 rep -- )
281 M: x86 %add-vector ( dst src1 src2 rep -- )
283 { float-4-rep [ ADDPS ] }
284 { double-2-rep [ ADDPD ] }
285 { char-16-rep [ PADDB ] }
286 { uchar-16-rep [ PADDB ] }
287 { short-8-rep [ PADDW ] }
288 { ushort-8-rep [ PADDW ] }
289 { int-4-rep [ PADDD ] }
290 { uint-4-rep [ PADDD ] }
293 M: x86 %sub-vector ( dst src1 src2 rep -- )
295 { float-4-rep [ SUBPS ] }
296 { double-2-rep [ SUBPD ] }
297 { char-16-rep [ PSUBB ] }
298 { uchar-16-rep [ PSUBB ] }
299 { short-8-rep [ PSUBW ] }
300 { ushort-8-rep [ PSUBW ] }
301 { int-4-rep [ PSUBD ] }
302 { uint-4-rep [ PSUBD ] }
305 M: x86 %mul-vector ( dst src1 src2 rep -- )
307 { float-4-rep [ MULPS ] }
308 { double-2-rep [ MULPD ] }
309 { int-4-rep [ PMULLW ] }
312 M: x86 %div-vector ( dst src1 src2 rep -- )
314 { float-4-rep [ DIVPS ] }
315 { double-2-rep [ DIVPD ] }
318 M: x86 %min-vector ( dst src1 src2 rep -- )
320 { float-4-rep [ MINPS ] }
321 { double-2-rep [ MINPD ] }
324 M: x86 %max-vector ( dst src1 src2 rep -- )
326 { float-4-rep [ MAXPS ] }
327 { double-2-rep [ MAXPD ] }
330 M: x86 %sqrt-vector ( dst src rep -- )
332 { float-4-rep [ SQRTPS ] }
333 { double-2-rep [ SQRTPD ] }
336 M: x86 %horizontal-add-vector ( dst src rep -- )
338 { float-4-rep [ [ MOVAPS ] [ HADDPS ] [ HADDPS ] 2tri ] }
339 { double-2-rep [ [ MOVAPD ] [ HADDPD ] 2bi ] }
342 M: x86 %unbox-alien ( dst src -- )
343 alien-offset [+] MOV ;
345 M:: x86 %unbox-any-c-ptr ( dst src temp -- )
347 { "is-byte-array" "end" "start" } [ define-label ] each
350 ! We come back here with displaced aliens
351 "start" resolve-label
353 temp \ f tag-number CMP
355 ! Is the object an alien?
356 temp header-offset [+] alien type-number tag-fixnum CMP
357 "is-byte-array" get JNE
358 ! If so, load the offset and add it to the address
359 dst temp alien-offset [+] ADD
360 ! Now recurse on the underlying alien
361 temp temp underlying-alien-offset [+] MOV
363 "is-byte-array" resolve-label
364 ! Add byte array address to address being computed
366 ! Add an offset to start of byte array's data
367 dst byte-array-offset ADD
371 : alien@ ( reg n -- op ) cells alien tag-number - [+] ;
373 :: %allot-alien ( dst displacement base temp -- )
374 dst 4 cells alien temp %allot
375 dst 1 alien@ base MOV ! alien
376 dst 2 alien@ \ f tag-number MOV ! expired
377 dst 3 alien@ displacement MOV ! displacement
380 M:: x86 %box-alien ( dst src temp -- )
383 dst \ f tag-number MOV
386 dst src \ f tag-number temp %allot-alien
390 M:: x86 %box-displaced-alien ( dst displacement base displacement' base' base-class -- )
394 ! If displacement is zero, return the base
398 ! Quickly use displacement' before its needed for real, as allot temporary
399 dst 4 cells alien displacement' %allot
400 ! If base is already a displaced alien, unpack it
402 displacement' displacement MOV
403 base \ f tag-number CMP
405 base header-offset [+] alien type-number tag-fixnum CMP
407 ! displacement += base.displacement
408 displacement' base 3 alien@ ADD
410 base' base 1 alien@ MOV
412 dst 1 alien@ base' MOV ! alien
413 dst 2 alien@ \ f tag-number MOV ! expired
414 dst 3 alien@ displacement' MOV ! displacement
418 ! The 'small-reg' mess is pretty crappy, but its only used on x86-32.
419 ! On x86-64, all registers have 8-bit versions. However, a similar
420 ! problem arises for shifts, where the shift count must be in CL, and
421 ! so one day I will fix this properly by adding precoloring to the
422 ! register allocator.
424 HOOK: has-small-reg? cpu ( reg size -- ? )
426 CONSTANT: have-byte-regs { EAX ECX EDX EBX }
428 M: x86.32 has-small-reg?
430 { 8 [ have-byte-regs memq? ] }
435 M: x86.64 has-small-reg? 2drop t ;
437 : small-reg-that-isn't ( exclude -- reg' )
438 [ have-byte-regs ] dip
439 [ native-version-of ] map
440 '[ _ memq? not ] find nip ;
442 : with-save/restore ( reg quot -- )
443 [ drop PUSH ] [ call ] [ drop POP ] 2tri ; inline
445 :: with-small-register ( dst exclude size quot: ( new-dst -- ) -- )
446 ! If the destination register overlaps a small register with
447 ! 'size' bits, we call the quot with that. Otherwise, we find a
448 ! small register that is not in exclude, and call quot, saving and
449 ! restoring the small register.
450 dst size has-small-reg? [ dst quot call ] [
451 exclude small-reg-that-isn't
452 [ quot call ] with-save/restore
455 : ?MOV ( dst src -- )
456 2dup = [ 2drop ] [ MOV ] if ; inline
458 M:: x86 %string-nth ( dst src index temp -- )
459 ! We request a small-reg of size 8 since those of size 16 are
462 dst { src index temp } 8 [| new-dst |
463 ! Load the least significant 7 bits into new-dst.
464 ! 8th bit indicates whether we have to load from
465 ! the aux vector or not.
466 temp src index [+] LEA
467 new-dst 8-bit-version-of temp string-offset [+] MOV
468 new-dst new-dst 8-bit-version-of MOVZX
469 ! Do we have to look at the aux vector?
472 ! Yes, this is a non-ASCII character. Load aux vector
473 temp src string-aux-offset [+] MOV
479 new-dst 16-bit-version-of new-dst byte-array-offset [+] MOV
480 new-dst new-dst 16-bit-version-of MOVZX
486 ] with-small-register ;
488 M:: x86 %set-string-nth-fast ( ch str index temp -- )
489 ch { index str temp } 8 [| new-ch |
491 temp str index [+] LEA
492 temp string-offset [+] new-ch 8-bit-version-of MOV
493 ] with-small-register ;
495 :: %alien-integer-getter ( dst src size quot -- )
496 dst { src } size [| new-dst |
497 new-dst dup size n-bit-version-of dup src [] MOV
500 ] with-small-register ; inline
502 : %alien-unsigned-getter ( dst src size -- )
503 [ MOVZX ] %alien-integer-getter ; inline
505 M: x86 %alien-unsigned-1 8 %alien-unsigned-getter ;
506 M: x86 %alien-unsigned-2 16 %alien-unsigned-getter ;
507 M: x86 %alien-unsigned-4 32 [ 2drop ] %alien-integer-getter ;
509 : %alien-signed-getter ( dst src size -- )
510 [ MOVSX ] %alien-integer-getter ; inline
512 M: x86 %alien-signed-1 8 %alien-signed-getter ;
513 M: x86 %alien-signed-2 16 %alien-signed-getter ;
514 M: x86 %alien-signed-4 32 %alien-signed-getter ;
516 M: x86 %alien-cell [] MOV ;
517 M: x86 %alien-float [] MOVSS ;
518 M: x86 %alien-double [] MOVSD ;
519 M: x86 %alien-vector [ [] ] dip copy-register ;
521 :: %alien-integer-setter ( ptr value size -- )
522 value { ptr } size [| new-value |
524 ptr [] new-value size n-bit-version-of MOV
525 ] with-small-register ; inline
527 M: x86 %set-alien-integer-1 8 %alien-integer-setter ;
528 M: x86 %set-alien-integer-2 16 %alien-integer-setter ;
529 M: x86 %set-alien-integer-4 32 %alien-integer-setter ;
530 M: x86 %set-alien-cell [ [] ] dip MOV ;
531 M: x86 %set-alien-float [ [] ] dip MOVSS ;
532 M: x86 %set-alien-double [ [] ] dip MOVSD ;
533 M: x86 %set-alien-vector [ [] ] 2dip copy-register ;
535 : shift-count? ( reg -- ? ) { ECX RCX } memq? ;
537 :: emit-shift ( dst src1 src2 quot -- )
546 ECX native-version-of [
548 drop dst CL quot call
553 M: x86 %shl [ SHL ] emit-shift ;
554 M: x86 %shr [ SHR ] emit-shift ;
555 M: x86 %sar [ SAR ] emit-shift ;
557 M: x86 %vm-field-ptr ( dst field -- )
558 [ drop 0 MOV rc-absolute-cell rt-vm rel-fixup ]
559 [ vm-field-offset ADD ] 2bi ;
561 : load-zone-ptr ( reg -- )
562 #! Load pointer to start of zone array
563 "nursery" %vm-field-ptr ;
565 : load-allot-ptr ( nursery-ptr allot-ptr -- )
566 [ drop load-zone-ptr ] [ swap cell [+] MOV ] 2bi ;
568 : inc-allot-ptr ( nursery-ptr n -- )
569 [ cell [+] ] dip 8 align ADD ;
571 : store-header ( temp class -- )
572 [ [] ] [ type-number tag-fixnum ] bi* MOV ;
574 : store-tagged ( dst tag -- )
577 M:: x86 %allot ( dst size class nursery-ptr -- )
578 nursery-ptr dst load-allot-ptr
579 dst class store-header
580 dst class store-tagged
581 nursery-ptr size inc-allot-ptr ;
584 M:: x86 %write-barrier ( src card# table -- )
585 #! Mark the card pointed to by vreg.
589 table "cards_offset" %vm-field-ptr
591 table card# [+] card-mark <byte> MOV
594 card# deck-bits card-bits - SHR
595 table "decks_offset" %vm-field-ptr
597 table card# [+] card-mark <byte> MOV ;
599 M:: x86 %check-nursery ( label temp1 temp2 -- )
601 temp2 temp1 cell [+] MOV
603 temp1 temp1 3 cells [+] MOV
607 M: x86 %save-gc-root ( gc-root register -- ) [ gc-root@ ] dip MOV ;
609 M: x86 %load-gc-root ( gc-root register -- ) swap gc-root@ MOV ;
611 M:: x86 %call-gc ( gc-root-count -- )
612 ! Pass pointer to start of GC roots as first parameter
613 param-reg-1 gc-root-base param@ LEA
614 ! Pass number of roots as second parameter
615 param-reg-2 gc-root-count MOV
617 "inline_gc" %vm-invoke-3rd-arg ;
619 M: x86 %alien-global ( dst symbol library -- )
620 [ 0 MOV ] 2dip rc-absolute-cell rel-dlsym ;
622 M: x86 %epilogue ( n -- ) cell - incr-stack-reg ;
624 :: %boolean ( dst temp word -- )
625 dst \ f tag-number MOV
626 temp 0 MOV \ t rc-absolute-cell rel-immediate
627 dst temp word execute ; inline
629 M:: x86 %compare ( dst src1 src2 cc temp -- )
632 { cc< [ dst temp \ CMOVL %boolean ] }
633 { cc<= [ dst temp \ CMOVLE %boolean ] }
634 { cc> [ dst temp \ CMOVG %boolean ] }
635 { cc>= [ dst temp \ CMOVGE %boolean ] }
636 { cc= [ dst temp \ CMOVE %boolean ] }
637 { cc/= [ dst temp \ CMOVNE %boolean ] }
640 M: x86 %compare-imm ( dst src1 src2 cc temp -- )
643 : %cmov-float= ( dst src -- )
645 "no-move" define-label
647 "no-move" get [ JNE ] [ JP ] bi
649 "no-move" resolve-label
652 : %cmov-float/= ( dst src -- )
654 "no-move" define-label
661 "no-move" resolve-label
664 :: (%compare-float) ( dst src1 src2 cc temp compare -- )
666 { cc< [ src2 src1 \ compare execute( a b -- ) dst temp \ CMOVA %boolean ] }
667 { cc<= [ src2 src1 \ compare execute( a b -- ) dst temp \ CMOVAE %boolean ] }
668 { cc> [ src1 src2 \ compare execute( a b -- ) dst temp \ CMOVA %boolean ] }
669 { cc>= [ src1 src2 \ compare execute( a b -- ) dst temp \ CMOVAE %boolean ] }
670 { cc= [ src1 src2 \ compare execute( a b -- ) dst temp \ %cmov-float= %boolean ] }
671 { cc<> [ src1 src2 \ compare execute( a b -- ) dst temp \ CMOVNE %boolean ] }
672 { cc<>= [ src1 src2 \ compare execute( a b -- ) dst temp \ CMOVNP %boolean ] }
673 { cc/< [ src2 src1 \ compare execute( a b -- ) dst temp \ CMOVBE %boolean ] }
674 { cc/<= [ src2 src1 \ compare execute( a b -- ) dst temp \ CMOVB %boolean ] }
675 { cc/> [ src1 src2 \ compare execute( a b -- ) dst temp \ CMOVBE %boolean ] }
676 { cc/>= [ src1 src2 \ compare execute( a b -- ) dst temp \ CMOVB %boolean ] }
677 { cc/= [ src1 src2 \ compare execute( a b -- ) dst temp \ %cmov-float/= %boolean ] }
678 { cc/<> [ src1 src2 \ compare execute( a b -- ) dst temp \ CMOVE %boolean ] }
679 { cc/<>= [ src1 src2 \ compare execute( a b -- ) dst temp \ CMOVP %boolean ] }
682 M: x86 %compare-float-ordered ( dst src1 src2 cc temp -- )
683 \ COMISD (%compare-float) ;
685 M: x86 %compare-float-unordered ( dst src1 src2 cc temp -- )
686 \ UCOMISD (%compare-float) ;
688 M:: x86 %compare-branch ( label src1 src2 cc -- )
692 { cc<= [ label JLE ] }
694 { cc>= [ label JGE ] }
696 { cc/= [ label JNE ] }
699 M: x86 %compare-imm-branch ( label src1 src2 cc -- )
702 : %jump-float= ( label -- )
704 "no-jump" define-label
707 "no-jump" resolve-label
710 : %jump-float/= ( label -- )
713 :: (%compare-float-branch) ( label src1 src2 cc compare -- )
715 { cc< [ src2 src1 \ compare execute( a b -- ) label JA ] }
716 { cc<= [ src2 src1 \ compare execute( a b -- ) label JAE ] }
717 { cc> [ src1 src2 \ compare execute( a b -- ) label JA ] }
718 { cc>= [ src1 src2 \ compare execute( a b -- ) label JAE ] }
719 { cc= [ src1 src2 \ compare execute( a b -- ) label %jump-float= ] }
720 { cc<> [ src1 src2 \ compare execute( a b -- ) label JNE ] }
721 { cc<>= [ src1 src2 \ compare execute( a b -- ) label JNP ] }
722 { cc/< [ src2 src1 \ compare execute( a b -- ) label JBE ] }
723 { cc/<= [ src2 src1 \ compare execute( a b -- ) label JB ] }
724 { cc/> [ src1 src2 \ compare execute( a b -- ) label JBE ] }
725 { cc/>= [ src1 src2 \ compare execute( a b -- ) label JB ] }
726 { cc/= [ src1 src2 \ compare execute( a b -- ) label %jump-float/= ] }
727 { cc/<> [ src1 src2 \ compare execute( a b -- ) label JE ] }
728 { cc/<>= [ src1 src2 \ compare execute( a b -- ) label JP ] }
731 M: x86 %compare-float-ordered-branch ( label src1 src2 cc -- )
732 \ COMISD (%compare-float-branch) ;
734 M: x86 %compare-float-unordered-branch ( label src1 src2 cc -- )
735 \ UCOMISD (%compare-float-branch) ;
737 M:: x86 %spill ( src rep n -- )
738 n spill@ src rep copy-register ;
740 M:: x86 %reload ( dst rep n -- )
741 dst n spill@ rep copy-register ;
743 M: x86 %loop-entry 16 code-alignment [ NOP ] times ;
745 M:: x86 %save-context ( temp1 temp2 callback-allowed? -- )
746 #! Save Factor stack pointers in case the C code calls a
747 #! callback which does a GC, which must reliably trace
749 temp1 0 MOV rc-absolute-cell rt-vm rel-fixup
750 temp1 temp1 "stack_chain" vm-field-offset [+] MOV
751 temp2 stack-reg cell neg [+] LEA
754 temp1 2 cells [+] ds-reg MOV
755 temp1 3 cells [+] rs-reg MOV
758 M: x86 value-struct? drop t ;
760 M: x86 small-enough? ( n -- ? )
761 HEX: -80000000 HEX: 7fffffff between? ;
763 : next-stack@ ( n -- operand )
764 #! nth parameter from the next stack frame. Used to box
765 #! input values to callbacks; the callback has its own
766 #! stack frame set up, and we want to read the frame
767 #! set up by the caller.
768 stack-frame get total-size>> + stack@ ;
771 enable-float-intrinsics