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 %load-immediate ( reg n -- ) swap LOAD ;
54 M: ppc %load-reference ( reg obj -- )
55 [ 0 swap LOAD32 ] [ rc-absolute-ppc-2/2 rel-immediate ] bi* ;
57 M: ppc %alien-global ( register symbol dll -- )
58 [ 0 swap LOAD32 ] 2dip rc-absolute-ppc-2/2 rel-dlsym ;
63 GENERIC: loc-reg ( loc -- reg )
65 M: ds-loc loc-reg drop ds-reg ;
66 M: rs-loc loc-reg drop rs-reg ;
68 : loc>operand ( loc -- reg n )
69 [ loc-reg ] [ n>> cells neg ] bi ; inline
71 M: ppc %peek loc>operand LWZ ;
72 M: ppc %replace loc>operand STW ;
74 :: (%inc) ( n reg -- ) reg reg n cells ADDI ; inline
76 M: ppc %inc-d ( n -- ) ds-reg (%inc) ;
77 M: ppc %inc-r ( n -- ) rs-reg (%inc) ;
79 HOOK: reserved-area-size os ( -- n )
81 ! The start of the stack frame contains the size of this frame
82 ! as well as the currently executing XT
83 : factor-area-size ( -- n ) 2 cells ; foldable
84 : next-save ( n -- i ) cell - ;
85 : xt-save ( n -- i ) 2 cells - ;
87 ! Next, we have the spill area as well as the FFI parameter area.
88 ! It is safe for them to overlap, since basic blocks with FFI calls
89 ! will never spill -- indeed, basic blocks with FFI calls do not
90 ! use vregs at all, and the FFI call is a stack analysis sync point.
91 ! In the future this will change and the stack frame logic will
92 ! need to be untangled somewhat.
94 : param@ ( n -- x ) reserved-area-size + ; inline
96 : param-save-size ( -- n ) 8 cells ; foldable
99 reserved-area-size param-save-size + + ; inline
101 : spill@ ( n -- offset )
102 spill-offset local@ ;
104 ! Some FP intrinsics need a temporary scratch area in the stack
105 ! frame, 8 bytes in size. This is in the param-save area so it
106 ! does not overlap with spill slots.
107 : scratch@ ( n -- offset )
111 : gc-root@ ( n -- offset )
112 gc-root-offset local@ ;
114 ! Finally we have the linkage area
115 HOOK: lr-save os ( -- n )
117 M: ppc stack-frame-size ( stack-frame -- i )
124 M: ppc %call ( word -- ) 0 BL rc-relative-ppc-3 rel-word-pic ;
126 M: ppc %jump ( word -- )
127 0 6 LOAD32 8 rc-absolute-ppc-2/2 rel-here
128 0 B rc-relative-ppc-3 rel-word-pic-tail ;
130 M: ppc %jump-label ( label -- ) B ;
131 M: ppc %return ( -- ) BLR ;
133 M:: ppc %dispatch ( src temp -- )
135 4 cells rc-absolute-ppc-2/2 rel-here
140 : (%slot-imm) ( obj slot tag -- reg offset )
141 [ cells ] dip - ; inline
143 M: ppc %slot ( dst obj slot -- ) swapd LWZX ;
144 M: ppc %slot-imm ( dst obj slot tag -- ) (%slot-imm) LWZ ;
145 M: ppc %set-slot ( src obj slot -- ) swapd STWX ;
146 M: ppc %set-slot-imm ( src obj slot tag -- ) (%slot-imm) STW ;
148 M:: ppc %string-nth ( dst src index temp -- )
152 dst temp string-offset LBZ
155 temp src string-aux-offset LWZ
158 temp temp byte-array-offset LHZ
164 M:: ppc %set-string-nth-fast ( ch obj index temp -- )
166 ch temp string-offset STB ;
169 M: ppc %add-imm ADDI ;
170 M: ppc %sub swap SUBF ;
171 M: ppc %sub-imm SUBI ;
173 M: ppc %mul-imm MULLI ;
175 M: ppc %and-imm ANDI ;
179 M: ppc %xor-imm XORI ;
181 M: ppc %shl-imm swapd SLWI ;
183 M: ppc %shr-imm swapd SRWI ;
185 M: ppc %sar-imm SRAWI ;
188 :: overflow-template ( label dst src1 src2 insn -- )
191 dst src2 src1 insn call
194 M: ppc %fixnum-add ( label dst src1 src2 -- )
195 [ ADDO. ] overflow-template ;
197 M: ppc %fixnum-sub ( label dst src1 src2 -- )
198 [ SUBFO. ] overflow-template ;
200 M: ppc %fixnum-mul ( label dst src1 src2 -- )
201 [ MULLWO. ] overflow-template ;
203 : bignum@ ( n -- offset ) cells bignum tag-number - ; inline
205 M:: ppc %integer>bignum ( dst src temp -- )
208 dst 0 >bignum %load-reference
209 ! Is it zero? Then just go to the end and return this zero
213 dst 4 cells bignum temp %allot
216 temp dst 1 bignum@ STW
219 temp temp cell-bits 1 - SRAWI
222 temp dst 2 bignum@ STW
223 ! Make negative value positive
229 temp dst 3 bignum@ STW
233 M:: ppc %bignum>integer ( dst src temp -- )
236 temp src 1 bignum@ LWZ
237 ! if the length is 1, its just the sign and nothing else,
240 0 temp 1 tag-fixnum CMPI
243 dst src 3 bignum@ LWZ
245 temp src 2 bignum@ LWZ
246 ! branchless arithmetic: we want to turn 0 into 1,
251 ! multiply value by sign
256 M: ppc %add-float FADD ;
257 M: ppc %sub-float FSUB ;
258 M: ppc %mul-float FMUL ;
259 M: ppc %div-float FDIV ;
261 M:: ppc %integer>float ( dst src -- )
262 HEX: 4330 scratch-reg LIS
263 scratch-reg 1 0 scratch@ STW
265 scratch-reg dup HEX: 8000 XORIS
266 scratch-reg 1 4 scratch@ STW
268 scratch-reg 4503601774854144.0 %load-reference
269 fp-scratch-reg scratch-reg float-offset LFD
270 dst dst fp-scratch-reg FSUB ;
272 M:: ppc %float>integer ( dst src -- )
273 fp-scratch-reg src FCTIWZ
274 fp-scratch-reg 1 0 scratch@ STFD
275 dst 1 4 scratch@ LWZ ;
277 M: ppc %copy ( dst src rep -- )
278 2over eq? [ 3drop ] [
281 { double-rep [ FMR ] }
285 M: ppc %unbox-float ( dst src -- ) float-offset LFD ;
287 M:: ppc %box-float ( dst src temp -- )
288 dst 16 float temp %allot
289 src dst float-offset STFD ;
291 : float-function-param ( i spill-slot -- )
292 [ float-regs param-regs nth 1 ] [ n>> spill@ ] bi* LFD ;
294 : float-function-return ( reg -- )
295 float-regs return-reg double-rep %copy ;
297 M:: ppc %unary-float-function ( dst src func -- )
298 0 src float-function-param
300 dst float-function-return ;
302 M:: ppc %binary-float-function ( dst src1 src2 func -- )
303 0 src1 float-function-param
304 1 src2 float-function-param
306 dst float-function-return ;
308 ! Internal format is always double-precision on PowerPC
309 M: ppc %single>double-float double-rep %copy ;
310 M: ppc %double>single-float double-rep %copy ;
312 ! VMX/AltiVec not supported yet
313 M: ppc %broadcast-vector-reps { } ;
314 M: ppc %gather-vector-2-reps { } ;
315 M: ppc %gather-vector-4-reps { } ;
316 M: ppc %add-vector-reps { } ;
317 M: ppc %saturated-add-vector-reps { } ;
318 M: ppc %add-sub-vector-reps { } ;
319 M: ppc %sub-vector-reps { } ;
320 M: ppc %saturated-sub-vector-reps { } ;
321 M: ppc %mul-vector-reps { } ;
322 M: ppc %saturated-mul-vector-reps { } ;
323 M: ppc %div-vector-reps { } ;
324 M: ppc %min-vector-reps { } ;
325 M: ppc %max-vector-reps { } ;
326 M: ppc %sqrt-vector-reps { } ;
327 M: ppc %horizontal-add-vector-reps { } ;
328 M: ppc %abs-vector-reps { } ;
329 M: ppc %and-vector-reps { } ;
330 M: ppc %or-vector-reps { } ;
331 M: ppc %xor-vector-reps { } ;
332 M: ppc %shl-vector-reps { } ;
333 M: ppc %shr-vector-reps { } ;
335 M: ppc %unbox-alien ( dst src -- )
338 M:: ppc %unbox-any-c-ptr ( dst src temp -- )
340 { "is-byte-array" "end" "start" } [ define-label ] each
341 ! Address is computed in dst
343 ! Load object into scratch-reg
345 ! We come back here with displaced aliens
346 "start" resolve-label
348 0 scratch-reg \ f tag-number CMPI
351 ! Is the object an alien?
352 0 scratch-reg header-offset LWZ
353 0 0 alien type-number tag-fixnum CMPI
354 "is-byte-array" get BNE
355 ! If so, load the offset
356 0 scratch-reg alien-offset LWZ
357 ! Add it to address being computed
359 ! Now recurse on the underlying alien
360 scratch-reg scratch-reg underlying-alien-offset LWZ
362 "is-byte-array" resolve-label
363 ! Add byte array address to address being computed
364 dst dst scratch-reg ADD
365 ! Add an offset to start of byte array's data area
366 dst dst byte-array-offset ADDI
370 : alien@ ( n -- n' ) cells object tag-number - ;
372 :: %allot-alien ( dst displacement base temp -- )
373 dst 4 cells alien temp %allot
374 temp \ f tag-number %load-immediate
375 ! Store underlying-alien slot
376 base dst 1 alien@ STW
378 temp dst 2 alien@ STW
380 displacement dst 3 alien@ STW ;
382 M:: ppc %box-alien ( dst src temp -- )
385 dst \ f tag-number %load-immediate
388 dst src temp temp %allot-alien
392 M:: ppc %box-displaced-alien ( dst displacement base displacement' base' base-class -- )
396 "simple-case" define-label
397 ! If displacement is zero, return the base
399 0 displacement 0 CMPI
401 ! Quickly use displacement' before its needed for real, as allot temporary
402 displacement' :> temp
403 dst 4 cells alien temp %allot
404 ! If base is already a displaced alien, unpack it
405 0 base \ f tag-number CMPI
406 "simple-case" get BEQ
407 temp base header-offset LWZ
408 0 temp alien type-number tag-fixnum CMPI
409 "simple-case" get BNE
410 ! displacement += base.displacement
411 temp base 3 alien@ LWZ
412 displacement' displacement temp ADD
414 base' base 1 alien@ LWZ
416 "simple-case" resolve-label
417 displacement' displacement MR
419 "alloc" resolve-label
420 ! Store underlying-alien slot
421 base' dst 1 alien@ STW
423 displacement' dst 3 alien@ STW
424 ! Store expired slot (its ok to clobber displacement')
425 temp \ f tag-number %load-immediate
426 temp dst 2 alien@ STW
430 M: ppc %alien-unsigned-1 0 LBZ ;
431 M: ppc %alien-unsigned-2 0 LHZ ;
433 M: ppc %alien-signed-1 dupd 0 LBZ dup EXTSB ;
434 M: ppc %alien-signed-2 0 LHA ;
436 M: ppc %alien-cell 0 LWZ ;
438 M: ppc %alien-float 0 LFS ;
439 M: ppc %alien-double 0 LFD ;
441 M: ppc %set-alien-integer-1 swap 0 STB ;
442 M: ppc %set-alien-integer-2 swap 0 STH ;
444 M: ppc %set-alien-cell swap 0 STW ;
446 M: ppc %set-alien-float swap 0 STFS ;
447 M: ppc %set-alien-double swap 0 STFD ;
449 : load-zone-ptr ( reg -- )
450 "nursery" %load-vm-field-addr ;
452 : load-allot-ptr ( nursery-ptr allot-ptr -- )
453 [ drop load-zone-ptr ] [ swap 4 LWZ ] 2bi ;
455 :: inc-allot-ptr ( nursery-ptr allot-ptr n -- )
456 scratch-reg allot-ptr n 8 align ADDI
457 scratch-reg nursery-ptr 4 STW ;
459 :: store-header ( dst class -- )
460 class type-number tag-fixnum scratch-reg LI
461 scratch-reg dst 0 STW ;
463 : store-tagged ( dst tag -- )
464 dupd tag-number ORI ;
466 M:: ppc %allot ( dst size class nursery-ptr -- )
467 nursery-ptr dst load-allot-ptr
468 nursery-ptr dst size inc-allot-ptr
469 dst class store-header
470 dst class store-tagged ;
472 : load-cards-offset ( dst -- )
473 [ "cards_offset" %load-vm-field-addr ] [ dup 0 LWZ ] bi ;
475 : load-decks-offset ( dst -- )
476 [ "decks_offset" %load-vm-field-addr ] [ dup 0 LWZ ] bi ;
478 M:: ppc %write-barrier ( src card# table -- )
479 card-mark scratch-reg LI
482 table load-cards-offset
483 src card# card-bits SRWI
484 table scratch-reg card# STBX
487 table load-decks-offset
488 src card# deck-bits SRWI
489 table scratch-reg card# STBX ;
491 M:: ppc %check-nursery ( label temp1 temp2 -- )
494 temp2 temp2 3 cells LWZ
495 ! add ALLOT_BUFFER_ZONE to here
496 temp1 temp1 1024 ADDI
501 M:: ppc %save-gc-root ( gc-root register -- )
502 register 1 gc-root gc-root@ STW ;
504 M:: ppc %load-gc-root ( gc-root register -- )
505 register 1 gc-root gc-root@ LWZ ;
507 M:: ppc %call-gc ( gc-root-count temp -- )
508 3 1 gc-root-base local@ ADDI
510 "inline_gc" f %alien-invoke ;
512 M: ppc %prologue ( n -- )
513 0 11 LOAD32 rc-absolute-ppc-2/2 rel-this
516 [ [ 1 1 ] dip neg ADDI ]
517 [ [ 11 1 ] dip xt-save STW ]
519 [ [ 11 1 ] dip next-save STW ]
520 [ [ 0 1 ] dip lr-save + STW ]
523 M: ppc %epilogue ( n -- )
524 #! At the end of each word that calls a subroutine, we store
525 #! the previous link register value in r0 by popping it off
526 #! the stack, set the link register to the contents of r0,
527 #! and jump to the link register.
528 [ [ 0 1 ] dip lr-save + LWZ ]
529 [ [ 1 1 ] dip ADDI ] bi
532 :: (%boolean) ( dst temp branch1 branch2 -- )
534 dst \ f tag-number %load-immediate
535 "end" get branch1 execute( label -- )
536 branch2 [ "end" get branch2 execute( label -- ) ] when
537 dst \ t %load-reference
538 "end" get resolve-label ; inline
540 :: %boolean ( dst cc temp -- )
541 cc negate-cc order-cc {
542 { cc< [ dst temp \ BLT f (%boolean) ] }
543 { cc<= [ dst temp \ BLE f (%boolean) ] }
544 { cc> [ dst temp \ BGT f (%boolean) ] }
545 { cc>= [ dst temp \ BGE f (%boolean) ] }
546 { cc= [ dst temp \ BEQ f (%boolean) ] }
547 { cc/= [ dst temp \ BNE f (%boolean) ] }
550 : (%compare) ( src1 src2 -- ) [ 0 ] dip CMP ; inline
551 : (%compare-imm) ( src1 src2 -- ) [ 0 ] 2dip CMPI ; inline
552 : (%compare-float-unordered) ( src1 src2 -- ) [ 0 ] dip FCMPU ; inline
553 : (%compare-float-ordered) ( src1 src2 -- ) [ 0 ] dip FCMPO ; inline
555 :: (%compare-float) ( src1 src2 cc compare -- branch1 branch2 )
557 { cc< [ src1 src2 \ compare execute( a b -- ) \ BLT f ] }
558 { cc<= [ src1 src2 \ compare execute( a b -- ) \ BLT \ BEQ ] }
559 { cc> [ src1 src2 \ compare execute( a b -- ) \ BGT f ] }
560 { cc>= [ src1 src2 \ compare execute( a b -- ) \ BGT \ BEQ ] }
561 { cc= [ src1 src2 \ compare execute( a b -- ) \ BEQ f ] }
562 { cc<> [ src1 src2 \ compare execute( a b -- ) \ BLT \ BGT ] }
563 { cc<>= [ src1 src2 \ compare execute( a b -- ) \ BNO f ] }
564 { cc/< [ src1 src2 \ compare execute( a b -- ) \ BGE f ] }
565 { cc/<= [ src1 src2 \ compare execute( a b -- ) \ BGT \ BO ] }
566 { cc/> [ src1 src2 \ compare execute( a b -- ) \ BLE f ] }
567 { cc/>= [ src1 src2 \ compare execute( a b -- ) \ BLT \ BO ] }
568 { cc/= [ src1 src2 \ compare execute( a b -- ) \ BNE f ] }
569 { cc/<> [ src1 src2 \ compare execute( a b -- ) \ BEQ \ BO ] }
570 { cc/<>= [ src1 src2 \ compare execute( a b -- ) \ BO f ] }
573 M: ppc %compare [ (%compare) ] 2dip %boolean ;
575 M: ppc %compare-imm [ (%compare-imm) ] 2dip %boolean ;
577 M:: ppc %compare-float-ordered ( dst src1 src2 cc temp -- )
578 src1 src2 cc negate-cc \ (%compare-float-ordered) (%compare-float) :> branch2 :> branch1
579 dst temp branch1 branch2 (%boolean) ;
581 M:: ppc %compare-float-unordered ( dst src1 src2 cc temp -- )
582 src1 src2 cc negate-cc \ (%compare-float-unordered) (%compare-float) :> branch2 :> branch1
583 dst temp branch1 branch2 (%boolean) ;
585 :: %branch ( label cc -- )
587 { cc< [ label BLT ] }
588 { cc<= [ label BLE ] }
589 { cc> [ label BGT ] }
590 { cc>= [ label BGE ] }
591 { cc= [ label BEQ ] }
592 { cc/= [ label BNE ] }
595 M:: ppc %compare-branch ( label src1 src2 cc -- )
599 M:: ppc %compare-imm-branch ( label src1 src2 cc -- )
600 src1 src2 (%compare-imm)
603 :: (%branch) ( label branch1 branch2 -- )
604 label branch1 execute( label -- )
605 branch2 [ label branch2 execute( label -- ) ] when ; inline
607 M:: ppc %compare-float-ordered-branch ( label src1 src2 cc -- )
608 src1 src2 cc \ (%compare-float-ordered) (%compare-float) :> branch2 :> branch1
609 label branch1 branch2 (%branch) ;
611 M:: ppc %compare-float-unordered-branch ( label src1 src2 cc -- )
612 src1 src2 cc \ (%compare-float-unordered) (%compare-float) :> branch2 :> branch1
613 label branch1 branch2 (%branch) ;
615 : load-from-frame ( dst n rep -- )
617 { int-rep [ [ 1 ] dip LWZ ] }
618 { float-rep [ [ 1 ] dip LFS ] }
619 { double-rep [ [ 1 ] dip LFD ] }
620 { stack-params [ [ 0 1 ] dip LWZ [ 0 1 ] dip param@ STW ] }
623 : next-param@ ( n -- x ) param@ stack-frame get total-size>> + ;
625 : store-to-frame ( src n rep -- )
627 { int-rep [ [ 1 ] dip STW ] }
628 { float-rep [ [ 1 ] dip STFS ] }
629 { double-rep [ [ 1 ] dip STFD ] }
630 { stack-params [ [ [ 0 1 ] dip next-param@ LWZ 0 1 ] dip STW ] }
633 M: ppc %spill ( src rep dst -- )
634 swap [ n>> spill@ ] dip store-to-frame ;
636 M: ppc %reload ( dst rep src -- )
637 swap [ n>> spill@ ] dip load-from-frame ;
641 M: int-regs return-reg drop 3 ;
642 M: int-regs param-regs drop { 3 4 5 6 7 8 9 10 } ;
643 M: float-regs return-reg drop 1 ;
645 M:: ppc %save-param-reg ( stack reg rep -- )
646 reg stack local@ rep store-to-frame ;
648 M:: ppc %load-param-reg ( stack reg rep -- )
649 reg stack local@ rep load-from-frame ;
651 M: ppc %prepare-unbox ( -- )
652 ! First parameter is top of stack
654 ds-reg dup cell SUBI ;
656 M: ppc %unbox ( n rep func -- )
657 ! Value must be in r3
660 ! Store the return value on the C stack
661 over [ [ reg-class-of return-reg ] keep %save-param-reg ] [ 2drop ] if ;
663 M: ppc %unbox-long-long ( n func -- )
664 ! Value must be in r3:r4
667 ! Store the return value on the C stack
669 [ [ 3 1 ] dip local@ STW ]
670 [ [ 4 1 ] dip cell + local@ STW ] bi
673 M: ppc %unbox-large-struct ( n c-type -- )
674 ! Value must be in r3
675 ! Compute destination address and load struct size
676 [ [ 4 1 ] dip local@ ADDI ] [ heap-size 5 LI ] bi*
678 "to_value_struct" f %alien-invoke ;
680 M: ppc %box ( n rep func -- )
681 ! If the source is a stack location, load it into freg #0.
682 ! If the source is f, then we assume the value is already in
684 [ over [ 0 over reg-class-of param-reg swap %load-param-reg ] [ 2drop ] if ] dip
687 M: ppc %box-long-long ( n func -- )
690 [ [ 3 1 ] dip local@ LWZ ]
691 [ [ 4 1 ] dip cell + local@ LWZ ] bi
693 ] dip f %alien-invoke ;
695 : struct-return@ ( n -- n )
696 [ stack-frame get params>> ] unless* local@ ;
698 M: ppc %prepare-box-struct ( -- )
699 #! Compute target address for value struct return
700 3 1 f struct-return@ ADDI
703 M: ppc %box-large-struct ( n c-type -- )
704 ! If n = f, then we're boxing a returned struct
705 ! Compute destination address and load struct size
706 [ [ 3 1 ] dip struct-return@ ADDI ] [ heap-size 4 LI ] bi*
708 "box_value_struct" f %alien-invoke ;
710 M:: ppc %save-context ( temp1 temp2 callback-allowed? -- )
711 #! Save Factor stack pointers in case the C code calls a
712 #! callback which does a GC, which must reliably trace
714 temp1 "stack_chain" %load-vm-field-addr
722 M: ppc %alien-invoke ( symbol dll -- )
723 [ 11 ] 2dip %alien-global 11 MTLR BLRL ;
725 M: ppc %alien-callback ( quot -- )
726 3 swap %load-reference "c_to_factor" f %alien-invoke ;
728 M: ppc %prepare-alien-indirect ( -- )
729 "unbox_alien" f %alien-invoke
732 M: ppc %alien-indirect ( -- )
735 M: ppc %callback-value ( ctype -- )
736 ! Save top of data stack
739 ! Restore data/call/retain stacks
740 "unnest_stacks" f %alien-invoke
741 ! Restore top of data stack
743 ! Unbox former top of data stack to return registers
746 M: ppc small-enough? ( n -- ? ) -32768 32767 between? ;
748 M: ppc return-struct-in-registers? ( c-type -- ? )
749 c-type return-in-registers?>> ;
751 M: ppc %box-small-struct ( c-type -- )
752 #! Box a <= 16-byte struct returned in r3:r4:r5:r6
754 "box_medium_struct" f %alien-invoke ;
756 : %unbox-struct-1 ( -- )
757 ! Alien must be in r3.
758 "alien_offset" f %alien-invoke
761 : %unbox-struct-2 ( -- )
762 ! Alien must be in r3.
763 "alien_offset" f %alien-invoke
767 : %unbox-struct-4 ( -- )
768 ! Alien must be in r3.
769 "alien_offset" f %alien-invoke
775 M: ppc %nest-stacks ( -- )
776 "nest_stacks" f %alien-invoke ;
778 M: ppc %unnest-stacks ( -- )
779 "unnest_stacks" 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