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 : (%memory) ( val base displacement scale offset rep c-type -- base val displacement rep c-type )
377 [ [ 0 assert= ] bi@ swapd ] 2dip ; inline
379 M: ppc %load-memory-imm ( dst base offset rep c-type -- )
382 { c:char [ [ dup ] 2dip LBZ dup EXTSB ] }
392 { float-rep [ LFS ] }
393 { double-rep [ LFD ] }
397 M: ppc %load-memory ( dst base displacement scale offset rep c-type -- )
400 { c:char [ [ LBZX ] [ drop dup EXTSB ] 2bi ] }
403 { c:ushort [ LHZX ] }
410 { float-rep [ LFSX ] }
411 { double-rep [ LFDX ] }
415 M: ppc %store-memory-imm ( src base offset rep c-type -- )
428 { float-rep [ STFS ] }
429 { double-rep [ STFD ] }
433 M: ppc %store-memory ( src base displacement scale offset rep c-type -- )
439 { c:ushort [ STHX ] }
446 { float-rep [ STFSX ] }
447 { double-rep [ STFDX ] }
451 : load-zone-ptr ( reg -- )
452 vm-reg "nursery" vm-field-offset ADDI ;
454 : load-allot-ptr ( nursery-ptr allot-ptr -- )
455 [ drop load-zone-ptr ] [ swap 0 LWZ ] 2bi ;
457 :: inc-allot-ptr ( nursery-ptr allot-ptr n -- )
458 scratch-reg allot-ptr n data-alignment get align ADDI
459 scratch-reg nursery-ptr 0 STW ;
461 :: store-header ( dst class -- )
462 class type-number tag-header scratch-reg LI
463 scratch-reg dst 0 STW ;
465 : store-tagged ( dst tag -- )
466 dupd type-number ORI ;
468 M:: ppc %allot ( dst size class nursery-ptr -- )
469 nursery-ptr dst load-allot-ptr
470 nursery-ptr dst size inc-allot-ptr
471 dst class store-header
472 dst class store-tagged ;
474 : load-cards-offset ( dst -- )
475 0 swap LOAD32 rc-absolute-ppc-2/2 rel-cards-offset ;
477 : load-decks-offset ( dst -- )
478 0 swap LOAD32 rc-absolute-ppc-2/2 rel-decks-offset ;
480 :: (%write-barrier) ( temp1 temp2 -- )
481 card-mark scratch-reg LI
484 temp1 temp1 card-bits SRWI
485 temp2 load-cards-offset
486 temp1 scratch-reg temp2 STBX
489 temp1 temp1 deck-bits card-bits - SRWI
490 temp2 load-decks-offset
491 temp1 scratch-reg temp2 STBX ;
493 M:: ppc %write-barrier ( src slot scale tag temp1 temp2 -- )
494 scale 0 assert= tag 0 assert=
496 temp1 temp2 (%write-barrier) ;
498 M:: ppc %write-barrier-imm ( src slot tag temp1 temp2 -- )
499 temp1 src slot tag slot-offset ADDI
500 temp1 temp2 (%write-barrier) ;
502 M:: ppc %check-nursery-branch ( label size cc temp1 temp2 -- )
503 temp1 vm-reg "nursery" vm-field-offset LWZ
504 temp2 vm-reg "nursery" vm-field-offset 2 cells + LWZ
505 temp1 temp1 size ADDI
509 { cc<= [ label BLE ] }
510 { cc/<= [ label BGT ] }
513 : gc-root-offsets ( seq -- seq' )
514 [ n>> spill@ ] map f like ;
516 M: ppc %call-gc ( gc-roots -- )
517 3 swap gc-root-offsets %load-reference
519 "inline_gc" f %alien-invoke ;
521 M: ppc %prologue ( n -- )
522 0 11 LOAD32 rc-absolute-ppc-2/2 rel-this
525 [ [ 1 1 ] dip neg ADDI ]
526 [ [ 11 1 ] dip xt-save STW ]
528 [ [ 11 1 ] dip next-save STW ]
529 [ [ 0 1 ] dip lr-save + STW ]
532 M: ppc %epilogue ( n -- )
533 #! At the end of each word that calls a subroutine, we store
534 #! the previous link register value in r0 by popping it off
535 #! the stack, set the link register to the contents of r0,
536 #! and jump to the link register.
537 [ [ 0 1 ] dip lr-save + LWZ ]
538 [ [ 1 1 ] dip ADDI ] bi
541 :: (%boolean) ( dst temp branch1 branch2 -- )
543 dst \ f type-number %load-immediate
544 "end" get branch1 execute( label -- )
545 branch2 [ "end" get branch2 execute( label -- ) ] when
546 dst \ t %load-reference
547 "end" get resolve-label ; inline
549 :: %boolean ( dst cc temp -- )
550 cc negate-cc order-cc {
551 { cc< [ dst temp \ BLT f (%boolean) ] }
552 { cc<= [ dst temp \ BLE f (%boolean) ] }
553 { cc> [ dst temp \ BGT f (%boolean) ] }
554 { cc>= [ dst temp \ BGE f (%boolean) ] }
555 { cc= [ dst temp \ BEQ f (%boolean) ] }
556 { cc/= [ dst temp \ BNE f (%boolean) ] }
559 : (%compare) ( src1 src2 -- ) [ 0 ] dip CMP ; inline
561 : (%compare-integer-imm) ( src1 src2 -- )
562 [ 0 ] 2dip CMPI ; inline
564 : (%compare-imm) ( src1 src2 -- )
565 [ tag-fixnum ] [ \ f type-number ] if* (%compare-integer-imm) ; inline
567 : (%compare-float-unordered) ( src1 src2 -- )
568 [ 0 ] dip FCMPU ; inline
570 : (%compare-float-ordered) ( src1 src2 -- )
571 [ 0 ] dip FCMPO ; inline
573 :: (%compare-float) ( src1 src2 cc compare -- branch1 branch2 )
575 { cc< [ src1 src2 \ compare execute( a b -- ) \ BLT f ] }
576 { cc<= [ src1 src2 \ compare execute( a b -- ) \ BLT \ BEQ ] }
577 { cc> [ src1 src2 \ compare execute( a b -- ) \ BGT f ] }
578 { cc>= [ src1 src2 \ compare execute( a b -- ) \ BGT \ BEQ ] }
579 { cc= [ src1 src2 \ compare execute( a b -- ) \ BEQ f ] }
580 { cc<> [ src1 src2 \ compare execute( a b -- ) \ BLT \ BGT ] }
581 { cc<>= [ src1 src2 \ compare execute( a b -- ) \ BNO f ] }
582 { cc/< [ src1 src2 \ compare execute( a b -- ) \ BGE f ] }
583 { cc/<= [ src1 src2 \ compare execute( a b -- ) \ BGT \ BO ] }
584 { cc/> [ src1 src2 \ compare execute( a b -- ) \ BLE f ] }
585 { cc/>= [ src1 src2 \ compare execute( a b -- ) \ BLT \ BO ] }
586 { cc/= [ src1 src2 \ compare execute( a b -- ) \ BNE f ] }
587 { cc/<> [ src1 src2 \ compare execute( a b -- ) \ BEQ \ BO ] }
588 { cc/<>= [ src1 src2 \ compare execute( a b -- ) \ BO f ] }
591 M: ppc %compare [ (%compare) ] 2dip %boolean ;
593 M: ppc %compare-imm [ (%compare-imm) ] 2dip %boolean ;
595 M: ppc %compare-integer-imm [ (%compare-integer-imm) ] 2dip %boolean ;
597 M:: ppc %compare-float-ordered ( dst src1 src2 cc temp -- )
598 src1 src2 cc negate-cc \ (%compare-float-ordered) (%compare-float) :> ( branch1 branch2 )
599 dst temp branch1 branch2 (%boolean) ;
601 M:: ppc %compare-float-unordered ( dst src1 src2 cc temp -- )
602 src1 src2 cc negate-cc \ (%compare-float-unordered) (%compare-float) :> ( branch1 branch2 )
603 dst temp branch1 branch2 (%boolean) ;
605 :: %branch ( label cc -- )
607 { cc< [ label BLT ] }
608 { cc<= [ label BLE ] }
609 { cc> [ label BGT ] }
610 { cc>= [ label BGE ] }
611 { cc= [ label BEQ ] }
612 { cc/= [ label BNE ] }
615 M:: ppc %compare-branch ( label src1 src2 cc -- )
619 M:: ppc %compare-imm-branch ( label src1 src2 cc -- )
620 src1 src2 (%compare-imm)
623 M:: ppc %compare-integer-imm-branch ( label src1 src2 cc -- )
624 src1 src2 (%compare-integer-imm)
627 :: (%branch) ( label branch1 branch2 -- )
628 label branch1 execute( label -- )
629 branch2 [ label branch2 execute( label -- ) ] when ; inline
631 M:: ppc %compare-float-ordered-branch ( label src1 src2 cc -- )
632 src1 src2 cc \ (%compare-float-ordered) (%compare-float) :> ( branch1 branch2 )
633 label branch1 branch2 (%branch) ;
635 M:: ppc %compare-float-unordered-branch ( label src1 src2 cc -- )
636 src1 src2 cc \ (%compare-float-unordered) (%compare-float) :> ( branch1 branch2 )
637 label branch1 branch2 (%branch) ;
639 : load-from-frame ( dst n rep -- )
641 { int-rep [ [ 1 ] dip LWZ ] }
642 { tagged-rep [ [ 1 ] dip LWZ ] }
643 { float-rep [ [ 1 ] dip LFS ] }
644 { double-rep [ [ 1 ] dip LFD ] }
645 { stack-params [ [ 0 1 ] dip LWZ [ 0 1 ] dip param@ STW ] }
648 : next-param@ ( n -- reg x )
651 : store-to-frame ( src n rep -- )
653 { int-rep [ [ 1 ] dip STW ] }
654 { tagged-rep [ [ 1 ] dip STW ] }
655 { float-rep [ [ 1 ] dip STFS ] }
656 { double-rep [ [ 1 ] dip STFD ] }
657 { stack-params [ [ [ 0 ] dip next-param@ LWZ 0 1 ] dip STW ] }
660 M: ppc %spill ( src rep dst -- )
661 swap [ n>> spill@ ] dip store-to-frame ;
663 M: ppc %reload ( dst rep src -- )
664 swap [ n>> spill@ ] dip load-from-frame ;
668 M: int-regs return-reg drop 3 ;
670 M: int-regs param-regs 2drop { 3 4 5 6 7 8 9 10 } ;
672 M: float-regs return-reg drop 1 ;
674 M:: ppc %save-param-reg ( stack reg rep -- )
675 reg stack local@ rep store-to-frame ;
677 M:: ppc %load-param-reg ( stack reg rep -- )
678 reg stack local@ rep load-from-frame ;
680 M: ppc %pop-stack ( n -- )
681 [ 3 ] dip <ds-loc> loc>operand LWZ ;
683 M: ppc %push-stack ( -- )
685 int-regs return-reg ds-reg 0 STW ;
687 M: ppc %push-context-stack ( -- )
689 12 11 "datastack" context-field-offset LWZ
691 12 11 "datastack" context-field-offset STW
692 int-regs return-reg 12 0 STW ;
694 M: ppc %pop-context-stack ( -- )
696 12 11 "datastack" context-field-offset LWZ
697 int-regs return-reg 12 0 LWZ
699 12 11 "datastack" context-field-offset STW ;
701 M: ppc %unbox ( n rep func -- )
702 ! Value must be in r3
706 ! Store the return value on the C stack
707 over [ [ reg-class-of return-reg ] keep %save-param-reg ] [ 2drop ] if ;
709 M: ppc %unbox-long-long ( n func -- )
713 ! Store the return value on the C stack
715 [ [ 3 1 ] dip local@ STW ]
716 [ [ 4 1 ] dip cell + local@ STW ] bi
719 M: ppc %unbox-large-struct ( n c-type -- )
720 ! Value must be in r3
721 ! Compute destination address and load struct size
722 [ [ 4 1 ] dip local@ ADDI ] [ heap-size 5 LI ] bi*
725 "to_value_struct" f %alien-invoke ;
727 M:: ppc %box ( n rep func -- )
728 ! If the source is a stack location, load it into freg #0.
729 ! If the source is f, then we assume the value is already in
731 n [ 0 rep reg-class-of cdecl param-reg rep %load-param-reg ] when*
732 rep double-rep? 5 4 ? %load-vm-addr
733 func f %alien-invoke ;
735 M: ppc %box-long-long ( n func -- )
738 [ [ 3 1 ] dip local@ LWZ ]
739 [ [ 4 1 ] dip cell + local@ LWZ ] bi
742 ] dip f %alien-invoke ;
744 : struct-return@ ( n -- n )
745 [ stack-frame get params>> ] unless* local@ ;
747 M: ppc %prepare-box-struct ( -- )
748 #! Compute target address for value struct return
749 3 1 f struct-return@ ADDI
752 M: ppc %box-large-struct ( n c-type -- )
753 ! If n = f, then we're boxing a returned struct
754 ! Compute destination address and load struct size
755 [ [ 3 1 ] dip struct-return@ ADDI ] [ heap-size 4 LI ] bi*
758 "from_value_struct" f %alien-invoke ;
760 M:: ppc %restore-context ( temp1 temp2 -- )
762 ds-reg temp1 "datastack" context-field-offset LWZ
763 rs-reg temp1 "retainstack" context-field-offset LWZ ;
765 M:: ppc %save-context ( temp1 temp2 -- )
767 1 temp1 "callstack-top" context-field-offset STW
768 ds-reg temp1 "datastack" context-field-offset STW
769 rs-reg temp1 "retainstack" context-field-offset STW ;
771 M: ppc %alien-invoke ( symbol dll -- )
772 [ 11 ] 2dip %alien-global 11 MTLR BLRL ;
774 M: ppc %prepare-alien-indirect ( -- )
778 "pinned_alien_offset" f %alien-invoke
781 M: ppc %alien-indirect ( -- )
784 M: ppc immediate-arithmetic? ( n -- ? ) -32768 32767 between? ;
786 M: ppc immediate-bitwise? ( n -- ? ) 0 65535 between? ;
788 M: ppc immediate-store? drop f ;
790 M: ppc struct-return-pointer-type void* ;
792 M: ppc return-struct-in-registers? ( c-type -- ? )
793 c-type return-in-registers?>> ;
795 M: ppc %box-small-struct ( c-type -- )
796 #! Box a <= 16-byte struct returned in r3:r4:r5:r6
799 "from_medium_struct" f %alien-invoke ;
801 : %unbox-struct-1 ( -- )
802 ! Alien must be in r3.
804 "alien_offset" f %alien-invoke
807 : %unbox-struct-2 ( -- )
808 ! Alien must be in r3.
810 "alien_offset" f %alien-invoke
814 : %unbox-struct-4 ( -- )
815 ! Alien must be in r3.
817 "alien_offset" f %alien-invoke
823 M: ppc %begin-callback ( -- )
825 "begin_callback" f %alien-invoke ;
827 M: ppc %alien-callback ( quot -- )
829 3 swap %load-reference
830 4 3 quot-entry-point-offset LWZ
835 M: ppc %end-callback ( -- )
837 "end_callback" f %alien-invoke ;
839 M: ppc %end-callback-value ( ctype -- )
840 ! Save top of data stack
843 ! Restore top of data stack
845 ! Unbox former top of data stack to return registers
848 M: ppc %unbox-small-struct ( size -- )
849 heap-size cell align cell /i {
850 { 1 [ %unbox-struct-1 ] }
851 { 2 [ %unbox-struct-2 ] }
852 { 4 [ %unbox-struct-4 ] }
855 enable-float-functions
860 { [ os macosx? ] [ "cpu.ppc.macosx" require ] }
861 { [ os linux? ] [ "cpu.ppc.linux" require ] }
864 complex-double c-type t >>return-in-registers? drop