1 ! Copyright (C) 2005, 2009 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors assocs sequences kernel combinators make math
4 math.order math.ranges system namespaces locals layouts words
5 alien alien.accessors alien.c-types alien.data literals cpu.architecture
6 cpu.ppc.assembler cpu.ppc.assembler.backend compiler.cfg.registers
7 compiler.cfg.instructions compiler.cfg.comparisons
8 compiler.codegen.fixup compiler.cfg.intrinsics
9 compiler.cfg.stack-frame compiler.cfg.build-stack-frame
10 compiler.units compiler.constants compiler.codegen vm ;
11 FROM: cpu.ppc.assembler => B ;
12 FROM: layouts => cell ;
16 ! PowerPC register assignments:
17 ! r2-r12: integer vregs
19 ! r30: integer scratch
23 ! Add some methods to the assembler that are useful to us
24 M: label (B) [ 0 ] 2dip (B) rc-relative-ppc-3 label-fixup ;
25 M: label BC [ 0 BC ] dip rc-relative-ppc-2 label-fixup ;
27 enable-float-intrinsics
30 \ ##integer>float t frame-required? set-word-prop
31 \ ##float>integer t frame-required? set-word-prop
34 : %load-vm-addr ( reg -- )
35 0 swap LOAD32 rc-absolute-ppc-2/2 rt-vm rel-fixup ;
37 : %load-vm-field-addr ( reg symbol -- )
38 [ drop %load-vm-addr ]
39 [ [ dup ] dip vm-field-offset ADDI ] 2bi ;
41 M: ppc %vm-field-ptr ( dst field -- ) %load-vm-field-addr ;
43 M: ppc machine-registers
45 { int-regs $[ 2 12 [a,b] 15 29 [a,b] append ] }
46 { float-regs $[ 0 29 [a,b] ] }
49 CONSTANT: scratch-reg 30
50 CONSTANT: fp-scratch-reg 30
52 M: ppc two-operand? f ;
54 M: ppc %load-immediate ( reg n -- ) swap LOAD ;
56 M: ppc %load-reference ( reg obj -- )
57 [ 0 swap LOAD32 ] [ rc-absolute-ppc-2/2 rel-immediate ] bi* ;
59 M: ppc %alien-global ( register symbol dll -- )
60 [ 0 swap LOAD32 ] 2dip rc-absolute-ppc-2/2 rel-dlsym ;
65 GENERIC: loc-reg ( loc -- reg )
67 M: ds-loc loc-reg drop ds-reg ;
68 M: rs-loc loc-reg drop rs-reg ;
70 : loc>operand ( loc -- reg n )
71 [ loc-reg ] [ n>> cells neg ] bi ; inline
73 M: ppc %peek loc>operand LWZ ;
74 M: ppc %replace loc>operand STW ;
76 :: (%inc) ( n reg -- ) reg reg n cells ADDI ; inline
78 M: ppc %inc-d ( n -- ) ds-reg (%inc) ;
79 M: ppc %inc-r ( n -- ) rs-reg (%inc) ;
81 HOOK: reserved-area-size os ( -- n )
83 ! The start of the stack frame contains the size of this frame
84 ! as well as the currently executing XT
85 : factor-area-size ( -- n ) 2 cells ; foldable
86 : next-save ( n -- i ) cell - ;
87 : xt-save ( n -- i ) 2 cells - ;
89 ! Next, we have the spill area as well as the FFI parameter area.
90 ! It is safe for them to overlap, since basic blocks with FFI calls
91 ! will never spill -- indeed, basic blocks with FFI calls do not
92 ! use vregs at all, and the FFI call is a stack analysis sync point.
93 ! In the future this will change and the stack frame logic will
94 ! need to be untangled somewhat.
96 : param@ ( n -- x ) reserved-area-size + ; inline
98 : param-save-size ( -- n ) 8 cells ; foldable
101 reserved-area-size param-save-size + + ; inline
103 : spill@ ( n -- offset )
104 spill-offset local@ ;
106 ! Some FP intrinsics need a temporary scratch area in the stack
107 ! frame, 8 bytes in size. This is in the param-save area so it
108 ! does not overlap with spill slots.
109 : scratch@ ( n -- offset )
113 : gc-root@ ( n -- offset )
114 gc-root-offset local@ ;
116 ! Finally we have the linkage area
117 HOOK: lr-save os ( -- n )
119 M: ppc stack-frame-size ( stack-frame -- i )
126 M: ppc %call ( word -- ) 0 BL rc-relative-ppc-3 rel-word-pic ;
128 M: ppc %jump ( word -- )
129 0 6 LOAD32 8 rc-absolute-ppc-2/2 rel-here
130 0 B rc-relative-ppc-3 rel-word-pic-tail ;
132 M: ppc %jump-label ( label -- ) B ;
133 M: ppc %return ( -- ) BLR ;
135 M:: ppc %dispatch ( src temp -- )
137 4 cells rc-absolute-ppc-2/2 rel-here
142 :: (%slot) ( obj slot tag temp -- reg offset )
144 temp tag neg ; inline
146 : (%slot-imm) ( obj slot tag -- reg offset )
147 [ cells ] dip - ; inline
149 M: ppc %slot ( dst obj slot tag temp -- ) (%slot) LWZ ;
150 M: ppc %slot-imm ( dst obj slot tag -- ) (%slot-imm) LWZ ;
151 M: ppc %set-slot ( src obj slot tag temp -- ) (%slot) STW ;
152 M: ppc %set-slot-imm ( src obj slot tag -- ) (%slot-imm) STW ;
154 M:: ppc %string-nth ( dst src index temp -- )
158 dst temp string-offset LBZ
161 temp src string-aux-offset LWZ
164 temp temp byte-array-offset LHZ
170 M:: ppc %set-string-nth-fast ( ch obj index temp -- )
172 ch temp string-offset STB ;
175 M: ppc %add-imm ADDI ;
176 M: ppc %sub swap SUBF ;
177 M: ppc %sub-imm SUBI ;
179 M: ppc %mul-imm MULLI ;
181 M: ppc %and-imm ANDI ;
185 M: ppc %xor-imm XORI ;
187 M: ppc %shl-imm swapd SLWI ;
189 M: ppc %shr-imm swapd SRWI ;
191 M: ppc %sar-imm SRAWI ;
194 :: overflow-template ( label dst src1 src2 insn -- )
197 dst src2 src1 insn call
200 M: ppc %fixnum-add ( label dst src1 src2 -- )
201 [ ADDO. ] overflow-template ;
203 M: ppc %fixnum-sub ( label dst src1 src2 -- )
204 [ SUBFO. ] overflow-template ;
206 M: ppc %fixnum-mul ( label dst src1 src2 -- )
207 [ MULLWO. ] overflow-template ;
209 : bignum@ ( n -- offset ) cells bignum tag-number - ; inline
211 M:: ppc %integer>bignum ( dst src temp -- )
214 dst 0 >bignum %load-reference
215 ! Is it zero? Then just go to the end and return this zero
219 dst 4 cells bignum temp %allot
222 temp dst 1 bignum@ STW
225 temp temp cell-bits 1 - SRAWI
228 temp dst 2 bignum@ STW
229 ! Make negative value positive
235 temp dst 3 bignum@ STW
239 M:: ppc %bignum>integer ( dst src temp -- )
242 temp src 1 bignum@ LWZ
243 ! if the length is 1, its just the sign and nothing else,
246 0 temp 1 tag-fixnum CMPI
249 dst src 3 bignum@ LWZ
251 temp src 2 bignum@ LWZ
252 ! branchless arithmetic: we want to turn 0 into 1,
257 ! multiply value by sign
262 M: ppc %add-float FADD ;
263 M: ppc %sub-float FSUB ;
264 M: ppc %mul-float FMUL ;
265 M: ppc %div-float FDIV ;
267 M:: ppc %integer>float ( dst src -- )
268 HEX: 4330 scratch-reg LIS
269 scratch-reg 1 0 scratch@ STW
271 scratch-reg dup HEX: 8000 XORIS
272 scratch-reg 1 4 scratch@ STW
274 scratch-reg 4503601774854144.0 %load-reference
275 fp-scratch-reg scratch-reg float-offset LFD
276 dst dst fp-scratch-reg FSUB ;
278 M:: ppc %float>integer ( dst src -- )
279 fp-scratch-reg src FCTIWZ
280 fp-scratch-reg 1 0 scratch@ STFD
281 dst 1 4 scratch@ LWZ ;
283 M: ppc %copy ( dst src rep -- )
284 2over eq? [ 3drop ] [
287 { double-rep [ FMR ] }
291 M: ppc %unbox-float ( dst src -- ) float-offset LFD ;
293 M:: ppc %box-float ( dst src temp -- )
294 dst 16 float temp %allot
295 src dst float-offset STFD ;
297 : float-function-param ( i spill-slot -- )
298 [ float-regs param-regs nth 1 ] [ n>> spill@ ] bi* LFD ;
300 : float-function-return ( reg -- )
301 float-regs return-reg double-rep %copy ;
303 M:: ppc %unary-float-function ( dst src func -- )
304 0 src float-function-param
306 dst float-function-return ;
308 M:: ppc %binary-float-function ( dst src1 src2 func -- )
309 0 src1 float-function-param
310 1 src2 float-function-param
312 dst float-function-return ;
314 ! Internal format is always double-precision on PowerPC
315 M: ppc %single>double-float double-rep %copy ;
316 M: ppc %double>single-float double-rep %copy ;
318 ! VMX/AltiVec not supported yet
319 M: ppc %broadcast-vector-reps { } ;
320 M: ppc %gather-vector-2-reps { } ;
321 M: ppc %gather-vector-4-reps { } ;
322 M: ppc %add-vector-reps { } ;
323 M: ppc %saturated-add-vector-reps { } ;
324 M: ppc %add-sub-vector-reps { } ;
325 M: ppc %sub-vector-reps { } ;
326 M: ppc %saturated-sub-vector-reps { } ;
327 M: ppc %mul-vector-reps { } ;
328 M: ppc %saturated-mul-vector-reps { } ;
329 M: ppc %div-vector-reps { } ;
330 M: ppc %min-vector-reps { } ;
331 M: ppc %max-vector-reps { } ;
332 M: ppc %sqrt-vector-reps { } ;
333 M: ppc %horizontal-add-vector-reps { } ;
334 M: ppc %abs-vector-reps { } ;
335 M: ppc %and-vector-reps { } ;
336 M: ppc %or-vector-reps { } ;
337 M: ppc %xor-vector-reps { } ;
338 M: ppc %shl-vector-reps { } ;
339 M: ppc %shr-vector-reps { } ;
341 M: ppc %unbox-alien ( dst src -- )
344 M:: ppc %unbox-any-c-ptr ( dst src temp -- )
346 { "is-byte-array" "end" "start" } [ define-label ] each
347 ! Address is computed in dst
349 ! Load object into scratch-reg
351 ! We come back here with displaced aliens
352 "start" resolve-label
354 0 scratch-reg \ f tag-number CMPI
357 ! Is the object an alien?
358 0 scratch-reg header-offset LWZ
359 0 0 alien type-number tag-fixnum CMPI
360 "is-byte-array" get BNE
361 ! If so, load the offset
362 0 scratch-reg alien-offset LWZ
363 ! Add it to address being computed
365 ! Now recurse on the underlying alien
366 scratch-reg scratch-reg underlying-alien-offset LWZ
368 "is-byte-array" resolve-label
369 ! Add byte array address to address being computed
370 dst dst scratch-reg ADD
371 ! Add an offset to start of byte array's data area
372 dst dst byte-array-offset ADDI
376 : alien@ ( n -- n' ) cells object tag-number - ;
378 :: %allot-alien ( dst displacement base temp -- )
379 dst 4 cells alien temp %allot
380 temp \ f tag-number %load-immediate
381 ! Store underlying-alien slot
382 base dst 1 alien@ STW
384 temp dst 2 alien@ STW
386 displacement dst 3 alien@ STW ;
388 M:: ppc %box-alien ( dst src temp -- )
391 dst \ f tag-number %load-immediate
394 dst src temp temp %allot-alien
398 M:: ppc %box-displaced-alien ( dst displacement base displacement' base' base-class -- )
402 "simple-case" define-label
403 ! If displacement is zero, return the base
405 0 displacement 0 CMPI
407 ! Quickly use displacement' before its needed for real, as allot temporary
408 displacement' :> temp
409 dst 4 cells alien temp %allot
410 ! If base is already a displaced alien, unpack it
411 0 base \ f tag-number CMPI
412 "simple-case" get BEQ
413 temp base header-offset LWZ
414 0 temp alien type-number tag-fixnum CMPI
415 "simple-case" get BNE
416 ! displacement += base.displacement
417 temp base 3 alien@ LWZ
418 displacement' displacement temp ADD
420 base' base 1 alien@ LWZ
422 "simple-case" resolve-label
423 displacement' displacement MR
425 "alloc" resolve-label
426 ! Store underlying-alien slot
427 base' dst 1 alien@ STW
429 displacement' dst 3 alien@ STW
430 ! Store expired slot (its ok to clobber displacement')
431 temp \ f tag-number %load-immediate
432 temp dst 2 alien@ STW
436 M: ppc %alien-unsigned-1 0 LBZ ;
437 M: ppc %alien-unsigned-2 0 LHZ ;
439 M: ppc %alien-signed-1 dupd 0 LBZ dup EXTSB ;
440 M: ppc %alien-signed-2 0 LHA ;
442 M: ppc %alien-cell 0 LWZ ;
444 M: ppc %alien-float 0 LFS ;
445 M: ppc %alien-double 0 LFD ;
447 M: ppc %set-alien-integer-1 swap 0 STB ;
448 M: ppc %set-alien-integer-2 swap 0 STH ;
450 M: ppc %set-alien-cell swap 0 STW ;
452 M: ppc %set-alien-float swap 0 STFS ;
453 M: ppc %set-alien-double swap 0 STFD ;
455 : load-zone-ptr ( reg -- )
456 "nursery" %load-vm-field-addr ;
458 : load-allot-ptr ( nursery-ptr allot-ptr -- )
459 [ drop load-zone-ptr ] [ swap 4 LWZ ] 2bi ;
461 :: inc-allot-ptr ( nursery-ptr allot-ptr n -- )
462 scratch-reg allot-ptr n 8 align ADDI
463 scratch-reg nursery-ptr 4 STW ;
465 :: store-header ( dst class -- )
466 class type-number tag-fixnum scratch-reg LI
467 scratch-reg dst 0 STW ;
469 : store-tagged ( dst tag -- )
470 dupd tag-number ORI ;
472 M:: ppc %allot ( dst size class nursery-ptr -- )
473 nursery-ptr dst load-allot-ptr
474 nursery-ptr dst size inc-allot-ptr
475 dst class store-header
476 dst class store-tagged ;
478 : load-cards-offset ( dst -- )
479 [ "cards_offset" %load-vm-field-addr ] [ dup 0 LWZ ] bi ;
481 : load-decks-offset ( dst -- )
482 [ "decks_offset" %load-vm-field-addr ] [ dup 0 LWZ ] bi ;
484 M:: ppc %write-barrier ( src card# table -- )
485 card-mark scratch-reg LI
488 table load-cards-offset
489 src card# card-bits SRWI
490 table scratch-reg card# STBX
493 table load-decks-offset
494 src card# deck-bits SRWI
495 table scratch-reg card# STBX ;
497 M:: ppc %check-nursery ( label temp1 temp2 -- )
500 temp2 temp2 3 cells LWZ
501 ! add ALLOT_BUFFER_ZONE to here
502 temp1 temp1 1024 ADDI
507 M:: ppc %save-gc-root ( gc-root register -- )
508 register 1 gc-root gc-root@ STW ;
510 M:: ppc %load-gc-root ( gc-root register -- )
511 register 1 gc-root gc-root@ LWZ ;
513 M:: ppc %call-gc ( gc-root-count -- )
514 3 1 gc-root-base local@ ADDI
516 "inline_gc" f %alien-invoke ;
518 M: ppc %prologue ( n -- )
519 0 11 LOAD32 rc-absolute-ppc-2/2 rel-this
522 [ [ 1 1 ] dip neg ADDI ]
523 [ [ 11 1 ] dip xt-save STW ]
525 [ [ 11 1 ] dip next-save STW ]
526 [ [ 0 1 ] dip lr-save + STW ]
529 M: ppc %epilogue ( n -- )
530 #! At the end of each word that calls a subroutine, we store
531 #! the previous link register value in r0 by popping it off
532 #! the stack, set the link register to the contents of r0,
533 #! and jump to the link register.
534 [ [ 0 1 ] dip lr-save + LWZ ]
535 [ [ 1 1 ] dip ADDI ] bi
538 :: (%boolean) ( dst temp branch1 branch2 -- )
540 dst \ f tag-number %load-immediate
541 "end" get branch1 execute( label -- )
542 branch2 [ "end" get branch2 execute( label -- ) ] when
543 dst \ t %load-reference
544 "end" get resolve-label ; inline
546 :: %boolean ( dst cc temp -- )
547 cc negate-cc order-cc {
548 { cc< [ dst temp \ BLT f (%boolean) ] }
549 { cc<= [ dst temp \ BLE f (%boolean) ] }
550 { cc> [ dst temp \ BGT f (%boolean) ] }
551 { cc>= [ dst temp \ BGE f (%boolean) ] }
552 { cc= [ dst temp \ BEQ f (%boolean) ] }
553 { cc/= [ dst temp \ BNE f (%boolean) ] }
556 : (%compare) ( src1 src2 -- ) [ 0 ] dip CMP ; inline
557 : (%compare-imm) ( src1 src2 -- ) [ 0 ] 2dip CMPI ; inline
558 : (%compare-float-unordered) ( src1 src2 -- ) [ 0 ] dip FCMPU ; inline
559 : (%compare-float-ordered) ( src1 src2 -- ) [ 0 ] dip FCMPO ; inline
561 :: (%compare-float) ( src1 src2 cc compare -- branch1 branch2 )
563 { cc< [ src1 src2 \ compare execute( a b -- ) \ BLT f ] }
564 { cc<= [ src1 src2 \ compare execute( a b -- ) \ BLT \ BEQ ] }
565 { cc> [ src1 src2 \ compare execute( a b -- ) \ BGT f ] }
566 { cc>= [ src1 src2 \ compare execute( a b -- ) \ BGT \ BEQ ] }
567 { cc= [ src1 src2 \ compare execute( a b -- ) \ BEQ f ] }
568 { cc<> [ src1 src2 \ compare execute( a b -- ) \ BLT \ BGT ] }
569 { cc<>= [ src1 src2 \ compare execute( a b -- ) \ BNO f ] }
570 { cc/< [ src1 src2 \ compare execute( a b -- ) \ BGE f ] }
571 { cc/<= [ src1 src2 \ compare execute( a b -- ) \ BGT \ BO ] }
572 { cc/> [ src1 src2 \ compare execute( a b -- ) \ BLE f ] }
573 { cc/>= [ src1 src2 \ compare execute( a b -- ) \ BLT \ BO ] }
574 { cc/= [ src1 src2 \ compare execute( a b -- ) \ BNE f ] }
575 { cc/<> [ src1 src2 \ compare execute( a b -- ) \ BEQ \ BO ] }
576 { cc/<>= [ src1 src2 \ compare execute( a b -- ) \ BO f ] }
579 M: ppc %compare [ (%compare) ] 2dip %boolean ;
581 M: ppc %compare-imm [ (%compare-imm) ] 2dip %boolean ;
583 M:: ppc %compare-float-ordered ( dst src1 src2 cc temp -- )
584 src1 src2 cc negate-cc \ (%compare-float-ordered) (%compare-float) :> branch2 :> branch1
585 dst temp branch1 branch2 (%boolean) ;
587 M:: ppc %compare-float-unordered ( dst src1 src2 cc temp -- )
588 src1 src2 cc negate-cc \ (%compare-float-unordered) (%compare-float) :> branch2 :> branch1
589 dst temp branch1 branch2 (%boolean) ;
591 :: %branch ( label cc -- )
593 { cc< [ label BLT ] }
594 { cc<= [ label BLE ] }
595 { cc> [ label BGT ] }
596 { cc>= [ label BGE ] }
597 { cc= [ label BEQ ] }
598 { cc/= [ label BNE ] }
601 M:: ppc %compare-branch ( label src1 src2 cc -- )
605 M:: ppc %compare-imm-branch ( label src1 src2 cc -- )
606 src1 src2 (%compare-imm)
609 :: (%branch) ( label branch1 branch2 -- )
610 label branch1 execute( label -- )
611 branch2 [ label branch2 execute( label -- ) ] when ; inline
613 M:: ppc %compare-float-ordered-branch ( label src1 src2 cc -- )
614 src1 src2 cc \ (%compare-float-ordered) (%compare-float) :> branch2 :> branch1
615 label branch1 branch2 (%branch) ;
617 M:: ppc %compare-float-unordered-branch ( label src1 src2 cc -- )
618 src1 src2 cc \ (%compare-float-unordered) (%compare-float) :> branch2 :> branch1
619 label branch1 branch2 (%branch) ;
621 : load-from-frame ( dst n rep -- )
623 { int-rep [ [ 1 ] dip LWZ ] }
624 { float-rep [ [ 1 ] dip LFS ] }
625 { double-rep [ [ 1 ] dip LFD ] }
626 { stack-params [ [ 0 1 ] dip LWZ [ 0 1 ] dip param@ STW ] }
629 : next-param@ ( n -- x ) param@ stack-frame get total-size>> + ;
631 : store-to-frame ( src n rep -- )
633 { int-rep [ [ 1 ] dip STW ] }
634 { float-rep [ [ 1 ] dip STFS ] }
635 { double-rep [ [ 1 ] dip STFD ] }
636 { stack-params [ [ [ 0 1 ] dip next-param@ LWZ 0 1 ] dip STW ] }
639 M: ppc %spill ( src rep n -- )
640 swap [ spill@ ] dip store-to-frame ;
642 M: ppc %reload ( dst rep n -- )
643 swap [ spill@ ] dip load-from-frame ;
647 M: int-regs return-reg drop 3 ;
648 M: int-regs param-regs drop { 3 4 5 6 7 8 9 10 } ;
649 M: float-regs return-reg drop 1 ;
651 M:: ppc %save-param-reg ( stack reg rep -- )
652 reg stack local@ rep store-to-frame ;
654 M:: ppc %load-param-reg ( stack reg rep -- )
655 reg stack local@ rep load-from-frame ;
657 M: ppc %prepare-unbox ( -- )
658 ! First parameter is top of stack
660 ds-reg dup cell SUBI ;
662 M: ppc %unbox ( n rep func -- )
663 ! Value must be in r3
666 ! Store the return value on the C stack
667 over [ [ reg-class-of return-reg ] keep %save-param-reg ] [ 2drop ] if ;
669 M: ppc %unbox-long-long ( n func -- )
670 ! Value must be in r3:r4
673 ! Store the return value on the C stack
675 [ [ 3 1 ] dip local@ STW ]
676 [ [ 4 1 ] dip cell + local@ STW ] bi
679 M: ppc %unbox-large-struct ( n c-type -- )
680 ! Value must be in r3
681 ! Compute destination address and load struct size
682 [ [ 4 1 ] dip local@ ADDI ] [ heap-size 5 LI ] bi*
684 "to_value_struct" f %alien-invoke ;
686 M: ppc %box ( n rep func -- )
687 ! If the source is a stack location, load it into freg #0.
688 ! If the source is f, then we assume the value is already in
690 [ over [ 0 over reg-class-of param-reg swap %load-param-reg ] [ 2drop ] if ] dip
693 M: ppc %box-long-long ( n func -- )
696 [ [ 3 1 ] dip local@ LWZ ]
697 [ [ 4 1 ] dip cell + local@ LWZ ] bi
699 ] dip f %alien-invoke ;
701 : struct-return@ ( n -- n )
702 [ stack-frame get params>> ] unless* local@ ;
704 M: ppc %prepare-box-struct ( -- )
705 #! Compute target address for value struct return
706 3 1 f struct-return@ ADDI
709 M: ppc %box-large-struct ( n c-type -- )
710 ! If n = f, then we're boxing a returned struct
711 ! Compute destination address and load struct size
712 [ [ 3 1 ] dip struct-return@ ADDI ] [ heap-size 4 LI ] bi*
714 "box_value_struct" f %alien-invoke ;
716 M:: ppc %save-context ( temp1 temp2 callback-allowed? -- )
717 #! Save Factor stack pointers in case the C code calls a
718 #! callback which does a GC, which must reliably trace
720 temp1 "stack_chain" %load-vm-field-addr
728 M: ppc %alien-invoke ( symbol dll -- )
729 [ 11 ] 2dip %alien-global 11 MTLR BLRL ;
731 M: ppc %alien-callback ( quot -- )
732 3 swap %load-reference "c_to_factor" f %alien-invoke ;
734 M: ppc %prepare-alien-indirect ( -- )
735 "unbox_alien" f %alien-invoke
738 M: ppc %alien-indirect ( -- )
741 M: ppc %callback-value ( ctype -- )
742 ! Save top of data stack
745 ! Restore data/call/retain stacks
746 "unnest_stacks" f %alien-invoke
747 ! Restore top of data stack
749 ! Unbox former top of data stack to return registers
752 M: ppc small-enough? ( n -- ? ) -32768 32767 between? ;
754 M: ppc return-struct-in-registers? ( c-type -- ? )
755 c-type return-in-registers?>> ;
757 M: ppc %box-small-struct ( c-type -- )
758 #! Box a <= 16-byte struct returned in r3:r4:r5:r6
760 "box_medium_struct" f %alien-invoke ;
762 : %unbox-struct-1 ( -- )
763 ! Alien must be in r3.
764 "alien_offset" f %alien-invoke
767 : %unbox-struct-2 ( -- )
768 ! Alien must be in r3.
769 "alien_offset" f %alien-invoke
773 : %unbox-struct-4 ( -- )
774 ! Alien must be in r3.
775 "alien_offset" f %alien-invoke
781 M: ppc %unbox-small-struct ( size -- )
782 #! Alien must be in EAX.
783 heap-size cell align cell /i {
784 { 1 [ %unbox-struct-1 ] }
785 { 2 [ %unbox-struct-2 ] }
786 { 4 [ %unbox-struct-4 ] }
789 enable-float-functions
794 { [ os macosx? ] [ "cpu.ppc.macosx" require ] }
795 { [ os linux? ] [ "cpu.ppc.linux" require ] }
798 "complex-double" c-type t >>return-in-registers? drop
802 [ alien-unsigned-4 c-bool> ] >>getter
803 [ [ >c-bool ] 2dip set-alien-unsigned-4 ] >>setter
806 "box_boolean" >>boxer
807 "to_boolean" >>unboxer
808 bool define-primitive-type
809 ] with-compilation-unit