1 ! Copyright (C) 2005, 2010 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors assocs sequences kernel combinators
4 classes.algebra byte-arrays make math math.order math.ranges
5 system namespaces locals layouts words alien alien.accessors
6 alien.c-types alien.complex alien.data literals cpu.architecture
7 cpu.ppc.assembler cpu.ppc.assembler.backend
8 compiler.cfg.registers compiler.cfg.instructions
9 compiler.cfg.comparisons compiler.codegen.fixup
10 compiler.cfg.intrinsics compiler.cfg.stack-frame
11 compiler.cfg.build-stack-frame compiler.units compiler.constants
13 QUALIFIED-WITH: alien.c-types c
14 FROM: cpu.ppc.assembler => B ;
15 FROM: layouts => cell ;
19 ! PowerPC register assignments:
20 ! r2-r12: integer vregs
24 ! r16-r29: integer vregs
25 ! r30: integer scratch
29 ! Add some methods to the assembler that are useful to us
30 M: label (B) [ 0 ] 2dip (B) rc-relative-ppc-3 label-fixup ;
31 M: label BC [ 0 BC ] dip rc-relative-ppc-2 label-fixup ;
33 enable-float-intrinsics
36 \ ##integer>float t "frame-required?" set-word-prop
37 \ ##float>integer t "frame-required?" set-word-prop
40 M: ppc machine-registers
42 { int-regs $[ 2 12 [a,b] 16 29 [a,b] append ] }
43 { float-regs $[ 0 29 [a,b] ] }
46 CONSTANT: scratch-reg 30
47 CONSTANT: fp-scratch-reg 30
49 M: ppc complex-addressing? f ;
51 M: ppc fused-unboxing? f ;
53 M: ppc %load-immediate ( reg n -- ) swap LOAD ;
55 M: ppc %load-reference ( reg obj -- )
56 [ [ 0 swap LOAD32 ] [ rc-absolute-ppc-2/2 rel-literal ] bi* ]
57 [ \ f type-number swap LI ]
60 M: ppc %alien-global ( register symbol dll -- )
61 [ 0 swap LOAD32 ] 2dip rc-absolute-ppc-2/2 rel-dlsym ;
67 : %load-vm-addr ( reg -- ) vm-reg MR ;
69 M: ppc %vm-field ( dst field -- ) [ vm-reg ] dip LWZ ;
71 M: ppc %set-vm-field ( src field -- ) [ vm-reg ] dip STW ;
73 GENERIC: loc-reg ( loc -- reg )
75 M: ds-loc loc-reg drop ds-reg ;
76 M: rs-loc loc-reg drop rs-reg ;
78 : loc>operand ( loc -- reg n )
79 [ loc-reg ] [ n>> cells neg ] bi ; inline
81 M: ppc %peek loc>operand LWZ ;
82 M: ppc %replace loc>operand STW ;
84 :: (%inc) ( n reg -- ) reg reg n cells ADDI ; inline
86 M: ppc %inc-d ( n -- ) ds-reg (%inc) ;
87 M: ppc %inc-r ( n -- ) rs-reg (%inc) ;
89 HOOK: reserved-area-size os ( -- n )
91 ! The start of the stack frame contains the size of this frame
92 ! as well as the currently executing code block
93 : factor-area-size ( -- n ) 2 cells ; foldable
94 : next-save ( n -- i ) cell - ; foldable
95 : xt-save ( n -- i ) 2 cells - ; foldable
97 ! Next, we have the spill area as well as the FFI parameter area.
98 ! It is safe for them to overlap, since basic blocks with FFI calls
99 ! will never spill -- indeed, basic blocks with FFI calls do not
100 ! use vregs at all, and the FFI call is a stack analysis sync point.
101 ! In the future this will change and the stack frame logic will
102 ! need to be untangled somewhat.
104 : param@ ( n -- x ) reserved-area-size + ; inline
106 : param-save-size ( -- n ) 8 cells ; foldable
109 reserved-area-size param-save-size + + ; inline
111 : spill@ ( n -- offset )
112 spill-offset local@ ;
114 ! Some FP intrinsics need a temporary scratch area in the stack
115 ! frame, 8 bytes in size. This is in the param-save area so it
116 ! does not overlap with spill slots.
117 : scratch@ ( n -- offset )
120 ! Finally we have the linkage area
121 HOOK: lr-save os ( -- n )
123 M: ppc stack-frame-size ( stack-frame -- i )
130 M: ppc %call ( word -- ) 0 BL rc-relative-ppc-3 rel-word-pic ;
132 M: ppc %jump ( word -- )
133 0 6 LOAD32 4 rc-absolute-ppc-2/2 rel-here
134 0 B rc-relative-ppc-3 rel-word-pic-tail ;
136 M: ppc %jump-label ( label -- ) B ;
137 M: ppc %return ( -- ) BLR ;
139 M:: ppc %dispatch ( src temp -- )
141 3 cells rc-absolute-ppc-2/2 rel-here
146 : (%slot) ( dst obj slot scale tag -- obj dst slot )
147 [ 0 assert= ] bi@ swapd ;
149 M: ppc %slot ( dst obj slot scale tag -- ) (%slot) LWZX ;
150 M: ppc %slot-imm ( dst obj slot tag -- ) slot-offset LWZ ;
151 M: ppc %set-slot ( src obj slot scale tag -- ) (%slot) STWX ;
152 M: ppc %set-slot-imm ( src obj slot tag -- ) slot-offset STW ;
155 M: ppc %add-imm ADDI ;
156 M: ppc %sub swap SUBF ;
157 M: ppc %sub-imm SUBI ;
159 M: ppc %mul-imm MULLI ;
161 M: ppc %and-imm ANDI ;
165 M: ppc %xor-imm XORI ;
167 M: ppc %shl-imm swapd SLWI ;
169 M: ppc %shr-imm swapd SRWI ;
171 M: ppc %sar-imm SRAWI ;
175 :: overflow-template ( label dst src1 src2 cc insn -- )
178 dst src2 src1 insn call
180 { cc-o [ label BO ] }
181 { cc/o [ label BNO ] }
184 M: ppc %fixnum-add ( label dst src1 src2 cc -- )
185 [ ADDO. ] overflow-template ;
187 M: ppc %fixnum-sub ( label dst src1 src2 cc -- )
188 [ SUBFO. ] overflow-template ;
190 M: ppc %fixnum-mul ( label dst src1 src2 cc -- )
191 [ MULLWO. ] overflow-template ;
193 M: ppc %add-float FADD ;
194 M: ppc %sub-float FSUB ;
195 M: ppc %mul-float FMUL ;
196 M: ppc %div-float FDIV ;
198 M:: ppc %integer>float ( dst src -- )
199 HEX: 4330 scratch-reg LIS
200 scratch-reg 1 0 scratch@ STW
202 scratch-reg dup HEX: 8000 XORIS
203 scratch-reg 1 4 scratch@ STW
205 scratch-reg 4503601774854144.0 %load-reference
206 fp-scratch-reg scratch-reg float-offset LFD
207 dst dst fp-scratch-reg FSUB ;
209 M:: ppc %float>integer ( dst src -- )
210 fp-scratch-reg src FCTIWZ
211 fp-scratch-reg 1 0 scratch@ STFD
212 dst 1 4 scratch@ LWZ ;
214 M: ppc %copy ( dst src rep -- )
215 2over eq? [ 3drop ] [
217 { tagged-rep [ MR ] }
219 { double-rep [ FMR ] }
223 GENERIC: float-function-param* ( dst src -- )
225 M: spill-slot float-function-param* [ 1 ] dip n>> spill@ LFD ;
226 M: integer float-function-param* FMR ;
228 : float-function-param ( i src -- )
229 [ float-regs cdecl param-regs nth ] dip float-function-param* ;
231 : float-function-return ( reg -- )
232 float-regs return-reg double-rep %copy ;
234 M:: ppc %unary-float-function ( dst src func -- )
235 0 src float-function-param
237 dst float-function-return ;
239 M:: ppc %binary-float-function ( dst src1 src2 func -- )
240 0 src1 float-function-param
241 1 src2 float-function-param
243 dst float-function-return ;
245 ! Internal format is always double-precision on PowerPC
246 M: ppc %single>double-float double-rep %copy ;
247 M: ppc %double>single-float FRSP ;
249 M: ppc %unbox-alien ( dst src -- )
252 M:: ppc %unbox-any-c-ptr ( dst src -- )
257 0 src \ f type-number CMPI
259 ! Compute tag in dst register
260 dst src tag-mask get ANDI
261 ! Is the object an alien?
262 0 dst alien type-number CMPI
263 ! Add an offset to start of byte array's data
264 dst src byte-array-offset ADDI
266 ! If so, load the offset and add it to the address
267 dst src alien-offset LWZ
271 : alien@ ( n -- n' ) cells alien type-number - ;
273 M:: ppc %box-alien ( dst src temp -- )
276 dst \ f type-number %load-immediate
279 dst 5 cells alien temp %allot
280 temp \ f type-number %load-immediate
281 temp dst 1 alien@ STW
282 temp dst 2 alien@ STW
288 :: %box-displaced-alien/f ( dst displacement base -- )
289 base dst 1 alien@ STW
290 displacement dst 3 alien@ STW
291 displacement dst 4 alien@ STW ;
293 :: %box-displaced-alien/alien ( dst displacement base temp -- )
294 ! Set new alien's base to base.base
295 temp base 1 alien@ LWZ
296 temp dst 1 alien@ STW
298 ! Compute displacement
299 temp base 3 alien@ LWZ
300 temp temp displacement ADD
301 temp dst 3 alien@ STW
304 temp base 4 alien@ LWZ
305 temp temp displacement ADD
306 temp dst 4 alien@ STW ;
308 :: %box-displaced-alien/byte-array ( dst displacement base temp -- )
309 base dst 1 alien@ STW
310 displacement dst 3 alien@ STW
311 temp base byte-array-offset ADDI
312 temp temp displacement ADD
313 temp dst 4 alien@ STW ;
315 :: %box-displaced-alien/dynamic ( dst displacement base temp -- )
317 "not-alien" define-label
320 0 base \ f type-number CMPI
323 ! Yes, it is f. Fill in new object
324 dst displacement base %box-displaced-alien/f
328 "not-f" resolve-label
331 temp base tag-mask get ANDI
334 0 temp alien type-number CMPI
337 dst displacement base temp %box-displaced-alien/alien
342 ! Is base a byte array? It has to be, by now...
343 "not-alien" resolve-label
345 dst displacement base temp %box-displaced-alien/byte-array ;
347 M:: ppc %box-displaced-alien ( dst displacement base temp base-class -- )
352 ! If displacement is zero, return the base
354 0 displacement 0 CMPI
357 ! Displacement is non-zero, we're going to be allocating a new
359 dst 5 cells alien temp %allot
362 temp \ f type-number %load-immediate
363 temp dst 2 alien@ STW
365 dst displacement base temp
367 { [ base-class \ f class<= ] [ drop %box-displaced-alien/f ] }
368 { [ base-class \ alien class<= ] [ %box-displaced-alien/alien ] }
369 { [ base-class \ byte-array class<= ] [ %box-displaced-alien/byte-array ] }
370 [ %box-displaced-alien/dynamic ]
376 M: ppc %load-memory-imm ( dst base offset rep c-type -- )
379 { c:char [ [ dup ] 2dip LBZ dup EXTSB ] }
387 { float-rep [ LFS ] }
388 { double-rep [ LFD ] }
392 : (%memory) ( val base displacement scale offset rep c-type -- base val displacement rep c-type )
393 [ [ 0 assert= ] bi@ swapd ] 2dip ; inline
395 M: ppc %load-memory ( dst base displacement scale offset rep c-type -- )
398 { c:char [ [ LBZX ] [ drop dup EXTSB ] 2bi ] }
401 { c:ushort [ LHZX ] }
406 { float-rep [ LFSX ] }
407 { double-rep [ LFDX ] }
411 M: ppc %store-memory-imm ( src base offset rep c-type -- )
422 { float-rep [ STFS ] }
423 { double-rep [ STFD ] }
427 M: ppc %store-memory ( src base displacement scale offset rep c-type -- )
433 { c:ushort [ STHX ] }
438 { float-rep [ STFSX ] }
439 { double-rep [ STFDX ] }
443 : load-zone-ptr ( reg -- )
444 vm-reg "nursery" vm-field-offset ADDI ;
446 : load-allot-ptr ( nursery-ptr allot-ptr -- )
447 [ drop load-zone-ptr ] [ swap 0 LWZ ] 2bi ;
449 :: inc-allot-ptr ( nursery-ptr allot-ptr n -- )
450 scratch-reg allot-ptr n data-alignment get align ADDI
451 scratch-reg nursery-ptr 0 STW ;
453 :: store-header ( dst class -- )
454 class type-number tag-header scratch-reg LI
455 scratch-reg dst 0 STW ;
457 : store-tagged ( dst tag -- )
458 dupd type-number ORI ;
460 M:: ppc %allot ( dst size class nursery-ptr -- )
461 nursery-ptr dst load-allot-ptr
462 nursery-ptr dst size inc-allot-ptr
463 dst class store-header
464 dst class store-tagged ;
466 : load-cards-offset ( dst -- )
467 0 swap LOAD32 rc-absolute-ppc-2/2 rel-cards-offset ;
469 : load-decks-offset ( dst -- )
470 0 swap LOAD32 rc-absolute-ppc-2/2 rel-decks-offset ;
472 :: (%write-barrier) ( temp1 temp2 -- )
473 card-mark scratch-reg LI
476 temp1 temp1 card-bits SRWI
477 temp2 load-cards-offset
478 temp1 scratch-reg temp2 STBX
481 temp1 temp1 deck-bits card-bits - SRWI
482 temp2 load-decks-offset
483 temp1 scratch-reg temp2 STBX ;
485 M:: ppc %write-barrier ( src slot scale tag temp1 temp2 -- )
486 scale 0 assert= tag 0 assert=
488 temp1 temp2 (%write-barrier) ;
490 M:: ppc %write-barrier-imm ( src slot tag temp1 temp2 -- )
491 temp1 src slot tag slot-offset ADDI
492 temp1 temp2 (%write-barrier) ;
494 M:: ppc %check-nursery-branch ( label size cc temp1 temp2 -- )
495 temp1 vm-reg "nursery" vm-field-offset LWZ
496 temp2 vm-reg "nursery" vm-field-offset 2 cells + LWZ
497 temp1 temp1 size ADDI
501 { cc<= [ label BLE ] }
502 { cc/<= [ label BGT ] }
505 : gc-root-offsets ( seq -- seq' )
506 [ n>> spill@ ] map f like ;
508 M: ppc %call-gc ( gc-roots -- )
509 3 swap gc-root-offsets %load-reference
511 "inline_gc" f %alien-invoke ;
513 M: ppc %prologue ( n -- )
514 0 11 LOAD32 rc-absolute-ppc-2/2 rel-this
517 [ [ 1 1 ] dip neg ADDI ]
518 [ [ 11 1 ] dip xt-save STW ]
520 [ [ 11 1 ] dip next-save STW ]
521 [ [ 0 1 ] dip lr-save + STW ]
524 M: ppc %epilogue ( n -- )
525 #! At the end of each word that calls a subroutine, we store
526 #! the previous link register value in r0 by popping it off
527 #! the stack, set the link register to the contents of r0,
528 #! and jump to the link register.
529 [ [ 0 1 ] dip lr-save + LWZ ]
530 [ [ 1 1 ] dip ADDI ] bi
533 :: (%boolean) ( dst temp branch1 branch2 -- )
535 dst \ f type-number %load-immediate
536 "end" get branch1 execute( label -- )
537 branch2 [ "end" get branch2 execute( label -- ) ] when
538 dst \ t %load-reference
539 "end" get resolve-label ; inline
541 :: %boolean ( dst cc temp -- )
542 cc negate-cc order-cc {
543 { cc< [ dst temp \ BLT f (%boolean) ] }
544 { cc<= [ dst temp \ BLE f (%boolean) ] }
545 { cc> [ dst temp \ BGT f (%boolean) ] }
546 { cc>= [ dst temp \ BGE f (%boolean) ] }
547 { cc= [ dst temp \ BEQ f (%boolean) ] }
548 { cc/= [ dst temp \ BNE f (%boolean) ] }
551 : (%compare) ( src1 src2 -- ) [ 0 ] dip CMP ; inline
553 : (%compare-integer-imm) ( src1 src2 -- )
554 [ 0 ] 2dip CMPI ; inline
556 : (%compare-imm) ( src1 src2 -- )
557 [ tag-fixnum ] [ \ f type-number ] if* (%compare-integer-imm) ; inline
559 : (%compare-float-unordered) ( src1 src2 -- )
560 [ 0 ] dip FCMPU ; inline
562 : (%compare-float-ordered) ( src1 src2 -- )
563 [ 0 ] dip FCMPO ; inline
565 :: (%compare-float) ( src1 src2 cc compare -- branch1 branch2 )
567 { cc< [ src1 src2 \ compare execute( a b -- ) \ BLT f ] }
568 { cc<= [ src1 src2 \ compare execute( a b -- ) \ BLT \ BEQ ] }
569 { cc> [ src1 src2 \ compare execute( a b -- ) \ BGT f ] }
570 { cc>= [ src1 src2 \ compare execute( a b -- ) \ BGT \ BEQ ] }
571 { cc= [ src1 src2 \ compare execute( a b -- ) \ BEQ f ] }
572 { cc<> [ src1 src2 \ compare execute( a b -- ) \ BLT \ BGT ] }
573 { cc<>= [ src1 src2 \ compare execute( a b -- ) \ BNO f ] }
574 { cc/< [ src1 src2 \ compare execute( a b -- ) \ BGE f ] }
575 { cc/<= [ src1 src2 \ compare execute( a b -- ) \ BGT \ BO ] }
576 { cc/> [ src1 src2 \ compare execute( a b -- ) \ BLE f ] }
577 { cc/>= [ src1 src2 \ compare execute( a b -- ) \ BLT \ BO ] }
578 { cc/= [ src1 src2 \ compare execute( a b -- ) \ BNE f ] }
579 { cc/<> [ src1 src2 \ compare execute( a b -- ) \ BEQ \ BO ] }
580 { cc/<>= [ src1 src2 \ compare execute( a b -- ) \ BO f ] }
583 M: ppc %compare [ (%compare) ] 2dip %boolean ;
585 M: ppc %compare-imm [ (%compare-imm) ] 2dip %boolean ;
587 M: ppc %compare-integer-imm [ (%compare-integer-imm) ] 2dip %boolean ;
589 M:: ppc %compare-float-ordered ( dst src1 src2 cc temp -- )
590 src1 src2 cc negate-cc \ (%compare-float-ordered) (%compare-float) :> ( branch1 branch2 )
591 dst temp branch1 branch2 (%boolean) ;
593 M:: ppc %compare-float-unordered ( dst src1 src2 cc temp -- )
594 src1 src2 cc negate-cc \ (%compare-float-unordered) (%compare-float) :> ( branch1 branch2 )
595 dst temp branch1 branch2 (%boolean) ;
597 :: %branch ( label cc -- )
599 { cc< [ label BLT ] }
600 { cc<= [ label BLE ] }
601 { cc> [ label BGT ] }
602 { cc>= [ label BGE ] }
603 { cc= [ label BEQ ] }
604 { cc/= [ label BNE ] }
607 M:: ppc %compare-branch ( label src1 src2 cc -- )
611 M:: ppc %compare-imm-branch ( label src1 src2 cc -- )
612 src1 src2 (%compare-imm)
615 M:: ppc %compare-integer-imm-branch ( label src1 src2 cc -- )
616 src1 src2 (%compare-integer-imm)
619 :: (%branch) ( label branch1 branch2 -- )
620 label branch1 execute( label -- )
621 branch2 [ label branch2 execute( label -- ) ] when ; inline
623 M:: ppc %compare-float-ordered-branch ( label src1 src2 cc -- )
624 src1 src2 cc \ (%compare-float-ordered) (%compare-float) :> ( branch1 branch2 )
625 label branch1 branch2 (%branch) ;
627 M:: ppc %compare-float-unordered-branch ( label src1 src2 cc -- )
628 src1 src2 cc \ (%compare-float-unordered) (%compare-float) :> ( branch1 branch2 )
629 label branch1 branch2 (%branch) ;
631 : load-from-frame ( dst n rep -- )
633 { int-rep [ [ 1 ] dip LWZ ] }
634 { tagged-rep [ [ 1 ] dip LWZ ] }
635 { float-rep [ [ 1 ] dip LFS ] }
636 { double-rep [ [ 1 ] dip LFD ] }
637 { stack-params [ [ 0 1 ] dip LWZ [ 0 1 ] dip param@ STW ] }
640 : next-param@ ( n -- reg x )
643 : store-to-frame ( src n rep -- )
645 { int-rep [ [ 1 ] dip STW ] }
646 { tagged-rep [ [ 1 ] dip STW ] }
647 { float-rep [ [ 1 ] dip STFS ] }
648 { double-rep [ [ 1 ] dip STFD ] }
649 { stack-params [ [ [ 0 ] dip next-param@ LWZ 0 1 ] dip STW ] }
652 M: ppc %spill ( src rep dst -- )
653 swap [ n>> spill@ ] dip store-to-frame ;
655 M: ppc %reload ( dst rep src -- )
656 swap [ n>> spill@ ] dip load-from-frame ;
660 M: int-regs return-reg drop 3 ;
662 M: int-regs param-regs 2drop { 3 4 5 6 7 8 9 10 } ;
664 M: float-regs return-reg drop 1 ;
666 M:: ppc %save-param-reg ( stack reg rep -- )
667 reg stack local@ rep store-to-frame ;
669 M:: ppc %load-param-reg ( stack reg rep -- )
670 reg stack local@ rep load-from-frame ;
672 M: ppc %pop-stack ( n -- )
673 [ 3 ] dip <ds-loc> loc>operand LWZ ;
675 M: ppc %push-stack ( -- )
677 int-regs return-reg ds-reg 0 STW ;
679 M: ppc %push-context-stack ( -- )
681 12 11 "datastack" context-field-offset LWZ
683 12 11 "datastack" context-field-offset STW
684 int-regs return-reg 12 0 STW ;
686 M: ppc %pop-context-stack ( -- )
688 12 11 "datastack" context-field-offset LWZ
689 int-regs return-reg 12 0 LWZ
691 12 11 "datastack" context-field-offset STW ;
693 M: ppc %unbox ( n rep func -- )
694 ! Value must be in r3
698 ! Store the return value on the C stack
699 over [ [ reg-class-of return-reg ] keep %save-param-reg ] [ 2drop ] if ;
701 M: ppc %unbox-long-long ( n func -- )
705 ! Store the return value on the C stack
707 [ [ 3 1 ] dip local@ STW ]
708 [ [ 4 1 ] dip cell + local@ STW ] bi
711 M: ppc %unbox-large-struct ( n c-type -- )
712 ! Value must be in r3
713 ! Compute destination address and load struct size
714 [ [ 4 1 ] dip local@ ADDI ] [ heap-size 5 LI ] bi*
717 "to_value_struct" f %alien-invoke ;
719 M:: ppc %box ( n rep func -- )
720 ! If the source is a stack location, load it into freg #0.
721 ! If the source is f, then we assume the value is already in
723 n [ 0 rep reg-class-of cdecl param-reg rep %load-param-reg ] when*
724 rep double-rep? 5 4 ? %load-vm-addr
725 func f %alien-invoke ;
727 M: ppc %box-long-long ( n func -- )
730 [ [ 3 1 ] dip local@ LWZ ]
731 [ [ 4 1 ] dip cell + local@ LWZ ] bi
734 ] dip f %alien-invoke ;
736 : struct-return@ ( n -- n )
737 [ stack-frame get params>> ] unless* local@ ;
739 M: ppc %prepare-box-struct ( -- )
740 #! Compute target address for value struct return
741 3 1 f struct-return@ ADDI
744 M: ppc %box-large-struct ( n c-type -- )
745 ! If n = f, then we're boxing a returned struct
746 ! Compute destination address and load struct size
747 [ [ 3 1 ] dip struct-return@ ADDI ] [ heap-size 4 LI ] bi*
750 "from_value_struct" f %alien-invoke ;
752 M:: ppc %restore-context ( temp1 temp2 -- )
754 ds-reg temp1 "datastack" context-field-offset LWZ
755 rs-reg temp1 "retainstack" context-field-offset LWZ ;
757 M:: ppc %save-context ( temp1 temp2 -- )
759 1 temp1 "callstack-top" context-field-offset STW
760 ds-reg temp1 "datastack" context-field-offset STW
761 rs-reg temp1 "retainstack" context-field-offset STW ;
763 M: ppc %alien-invoke ( symbol dll -- )
764 [ 11 ] 2dip %alien-global 11 MTLR BLRL ;
766 M: ppc %prepare-alien-indirect ( -- )
770 "pinned_alien_offset" f %alien-invoke
773 M: ppc %alien-indirect ( -- )
776 M: ppc immediate-arithmetic? ( n -- ? ) -32768 32767 between? ;
778 M: ppc immediate-bitwise? ( n -- ? ) 0 65535 between? ;
780 M: ppc immediate-store? drop f ;
782 M: ppc struct-return-pointer-type void* ;
784 M: ppc return-struct-in-registers? ( c-type -- ? )
785 c-type return-in-registers?>> ;
787 M: ppc %box-small-struct ( c-type -- )
788 #! Box a <= 16-byte struct returned in r3:r4:r5:r6
791 "from_medium_struct" f %alien-invoke ;
793 : %unbox-struct-1 ( -- )
794 ! Alien must be in r3.
796 "alien_offset" f %alien-invoke
799 : %unbox-struct-2 ( -- )
800 ! Alien must be in r3.
802 "alien_offset" f %alien-invoke
806 : %unbox-struct-4 ( -- )
807 ! Alien must be in r3.
809 "alien_offset" f %alien-invoke
815 M: ppc %begin-callback ( -- )
817 "begin_callback" f %alien-invoke ;
819 M: ppc %alien-callback ( quot -- )
821 3 swap %load-reference
822 4 3 quot-entry-point-offset LWZ
827 M: ppc %end-callback ( -- )
829 "end_callback" f %alien-invoke ;
831 M: ppc %end-callback-value ( ctype -- )
832 ! Save top of data stack
835 ! Restore top of data stack
837 ! Unbox former top of data stack to return registers
840 M: ppc %unbox-small-struct ( size -- )
841 heap-size cell align cell /i {
842 { 1 [ %unbox-struct-1 ] }
843 { 2 [ %unbox-struct-2 ] }
844 { 4 [ %unbox-struct-4 ] }
847 enable-float-functions
852 { [ os macosx? ] [ "cpu.ppc.macosx" require ] }
853 { [ os linux? ] [ "cpu.ppc.linux" require ] }
856 complex-double c-type t >>return-in-registers? drop