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 ;
189 :: overflow-template ( label dst src1 src2 insn -- )
192 dst src2 src1 insn call
195 M: ppc %fixnum-add ( label dst src1 src2 -- )
196 [ ADDO. ] overflow-template ;
198 M: ppc %fixnum-sub ( label dst src1 src2 -- )
199 [ SUBFO. ] overflow-template ;
201 M: ppc %fixnum-mul ( label dst src1 src2 -- )
202 [ MULLWO. ] overflow-template ;
204 M: ppc %add-float FADD ;
205 M: ppc %sub-float FSUB ;
206 M: ppc %mul-float FMUL ;
207 M: ppc %div-float FDIV ;
209 M:: ppc %integer>float ( dst src -- )
210 HEX: 4330 scratch-reg LIS
211 scratch-reg 1 0 scratch@ STW
213 scratch-reg dup HEX: 8000 XORIS
214 scratch-reg 1 4 scratch@ STW
216 scratch-reg 4503601774854144.0 %load-reference
217 fp-scratch-reg scratch-reg float-offset LFD
218 dst dst fp-scratch-reg FSUB ;
220 M:: ppc %float>integer ( dst src -- )
221 fp-scratch-reg src FCTIWZ
222 fp-scratch-reg 1 0 scratch@ STFD
223 dst 1 4 scratch@ LWZ ;
225 M: ppc %copy ( dst src rep -- )
226 2over eq? [ 3drop ] [
229 { double-rep [ FMR ] }
233 M: ppc %unbox-float ( dst src -- ) float-offset LFD ;
235 M:: ppc %box-float ( dst src temp -- )
236 dst 16 float temp %allot
237 src dst float-offset STFD ;
239 GENERIC: float-function-param* ( dst src -- )
241 M: spill-slot float-function-param* [ 1 ] dip n>> spill@ LFD ;
242 M: integer float-function-param* FMR ;
244 : float-function-param ( i src -- )
245 [ float-regs param-regs nth ] dip float-function-param* ;
247 : float-function-return ( reg -- )
248 float-regs return-reg double-rep %copy ;
250 M:: ppc %unary-float-function ( dst src func -- )
251 0 src float-function-param
253 dst float-function-return ;
255 M:: ppc %binary-float-function ( dst src1 src2 func -- )
256 0 src1 float-function-param
257 1 src2 float-function-param
259 dst float-function-return ;
261 ! Internal format is always double-precision on PowerPC
262 M: ppc %single>double-float double-rep %copy ;
263 M: ppc %double>single-float double-rep %copy ;
265 ! VMX/AltiVec not supported yet
266 M: ppc %zero-vector-reps { } ;
267 M: ppc %gather-vector-2-reps { } ;
268 M: ppc %gather-vector-4-reps { } ;
269 M: ppc %shuffle-vector-reps { } ;
270 M: ppc %add-vector-reps { } ;
271 M: ppc %saturated-add-vector-reps { } ;
272 M: ppc %add-sub-vector-reps { } ;
273 M: ppc %sub-vector-reps { } ;
274 M: ppc %saturated-sub-vector-reps { } ;
275 M: ppc %mul-vector-reps { } ;
276 M: ppc %saturated-mul-vector-reps { } ;
277 M: ppc %div-vector-reps { } ;
278 M: ppc %min-vector-reps { } ;
279 M: ppc %max-vector-reps { } ;
280 M: ppc %dot-vector-reps { } ;
281 M: ppc %sqrt-vector-reps { } ;
282 M: ppc %horizontal-add-vector-reps { } ;
283 M: ppc %horizontal-sub-vector-reps { } ;
284 M: ppc %abs-vector-reps { } ;
285 M: ppc %and-vector-reps { } ;
286 M: ppc %andn-vector-reps { } ;
287 M: ppc %or-vector-reps { } ;
288 M: ppc %xor-vector-reps { } ;
289 M: ppc %shl-vector-reps { } ;
290 M: ppc %shr-vector-reps { } ;
291 M: ppc %horizontal-shl-vector-reps { } ;
292 M: ppc %horizontal-shr-vector-reps { } ;
294 M: ppc %unbox-alien ( dst src -- )
297 M:: ppc %unbox-any-c-ptr ( dst src temp -- )
299 { "is-byte-array" "end" "start" } [ define-label ] each
300 ! Address is computed in dst
302 ! Load object into scratch-reg
304 ! We come back here with displaced aliens
305 "start" resolve-label
307 0 scratch-reg \ f tag-number CMPI
310 ! Is the object an alien?
311 0 scratch-reg header-offset LWZ
312 0 0 alien type-number tag-fixnum CMPI
313 "is-byte-array" get BNE
314 ! If so, load the offset
315 0 scratch-reg alien-offset LWZ
316 ! Add it to address being computed
318 ! Now recurse on the underlying alien
319 scratch-reg scratch-reg underlying-alien-offset LWZ
321 "is-byte-array" resolve-label
322 ! Add byte array address to address being computed
323 dst dst scratch-reg ADD
324 ! Add an offset to start of byte array's data area
325 dst dst byte-array-offset ADDI
329 : alien@ ( n -- n' ) cells object tag-number - ;
331 :: %allot-alien ( dst displacement base temp -- )
332 dst 4 cells alien temp %allot
333 temp \ f tag-number %load-immediate
334 ! Store underlying-alien slot
335 base dst 1 alien@ STW
337 temp dst 2 alien@ STW
339 displacement dst 3 alien@ STW ;
341 M:: ppc %box-alien ( dst src temp -- )
344 dst \ f tag-number %load-immediate
347 dst src temp temp %allot-alien
351 M:: ppc %box-displaced-alien ( dst displacement base displacement' base' base-class -- )
355 "simple-case" define-label
356 ! If displacement is zero, return the base
358 0 displacement 0 CMPI
360 ! Quickly use displacement' before its needed for real, as allot temporary
361 displacement' :> temp
362 dst 4 cells alien temp %allot
363 ! If base is already a displaced alien, unpack it
364 0 base \ f tag-number CMPI
365 "simple-case" get BEQ
366 temp base header-offset LWZ
367 0 temp alien type-number tag-fixnum CMPI
368 "simple-case" get BNE
369 ! displacement += base.displacement
370 temp base 3 alien@ LWZ
371 displacement' displacement temp ADD
373 base' base 1 alien@ LWZ
375 "simple-case" resolve-label
376 displacement' displacement MR
378 "alloc" resolve-label
379 ! Store underlying-alien slot
380 base' dst 1 alien@ STW
382 displacement' dst 3 alien@ STW
383 ! Store expired slot (its ok to clobber displacement')
384 temp \ f tag-number %load-immediate
385 temp dst 2 alien@ STW
389 M: ppc %alien-unsigned-1 LBZ ;
390 M: ppc %alien-unsigned-2 LHZ ;
392 M: ppc %alien-signed-1 [ dup ] 2dip LBZ dup EXTSB ;
393 M: ppc %alien-signed-2 LHA ;
395 M: ppc %alien-cell LWZ ;
397 M: ppc %alien-float LFS ;
398 M: ppc %alien-double LFD ;
400 M: ppc %set-alien-integer-1 swapd STB ;
401 M: ppc %set-alien-integer-2 swapd STH ;
403 M: ppc %set-alien-cell swapd STW ;
405 M: ppc %set-alien-float swapd STFS ;
406 M: ppc %set-alien-double swapd STFD ;
408 : load-zone-ptr ( reg -- )
409 "nursery" %load-vm-field-addr ;
411 : load-allot-ptr ( nursery-ptr allot-ptr -- )
412 [ drop load-zone-ptr ] [ swap 4 LWZ ] 2bi ;
414 :: inc-allot-ptr ( nursery-ptr allot-ptr n -- )
415 scratch-reg allot-ptr n 8 align ADDI
416 scratch-reg nursery-ptr 4 STW ;
418 :: store-header ( dst class -- )
419 class type-number tag-fixnum scratch-reg LI
420 scratch-reg dst 0 STW ;
422 : store-tagged ( dst tag -- )
423 dupd tag-number ORI ;
425 M:: ppc %allot ( dst size class nursery-ptr -- )
426 nursery-ptr dst load-allot-ptr
427 nursery-ptr dst size inc-allot-ptr
428 dst class store-header
429 dst class store-tagged ;
431 : load-cards-offset ( dst -- )
432 [ "cards_offset" %load-vm-field-addr ] [ dup 0 LWZ ] bi ;
434 : load-decks-offset ( dst -- )
435 [ "decks_offset" %load-vm-field-addr ] [ dup 0 LWZ ] bi ;
437 M:: ppc %write-barrier ( src card# table -- )
438 card-mark scratch-reg LI
441 table load-cards-offset
442 src card# card-bits SRWI
443 table scratch-reg card# STBX
446 table load-decks-offset
447 src card# deck-bits SRWI
448 table scratch-reg card# STBX ;
450 M:: ppc %check-nursery ( label temp1 temp2 -- )
453 temp2 temp2 3 cells LWZ
454 ! add ALLOT_BUFFER_ZONE to here
455 temp1 temp1 1024 ADDI
460 M:: ppc %save-gc-root ( gc-root register -- )
461 register 1 gc-root gc-root@ STW ;
463 M:: ppc %load-gc-root ( gc-root register -- )
464 register 1 gc-root gc-root@ LWZ ;
466 M:: ppc %call-gc ( gc-root-count temp -- )
467 3 1 gc-root-base local@ ADDI
469 "inline_gc" f %alien-invoke ;
471 M: ppc %prologue ( n -- )
472 0 11 LOAD32 rc-absolute-ppc-2/2 rel-this
475 [ [ 1 1 ] dip neg ADDI ]
476 [ [ 11 1 ] dip xt-save STW ]
478 [ [ 11 1 ] dip next-save STW ]
479 [ [ 0 1 ] dip lr-save + STW ]
482 M: ppc %epilogue ( n -- )
483 #! At the end of each word that calls a subroutine, we store
484 #! the previous link register value in r0 by popping it off
485 #! the stack, set the link register to the contents of r0,
486 #! and jump to the link register.
487 [ [ 0 1 ] dip lr-save + LWZ ]
488 [ [ 1 1 ] dip ADDI ] bi
491 :: (%boolean) ( dst temp branch1 branch2 -- )
493 dst \ f tag-number %load-immediate
494 "end" get branch1 execute( label -- )
495 branch2 [ "end" get branch2 execute( label -- ) ] when
496 dst \ t %load-reference
497 "end" get resolve-label ; inline
499 :: %boolean ( dst cc temp -- )
500 cc negate-cc order-cc {
501 { cc< [ dst temp \ BLT f (%boolean) ] }
502 { cc<= [ dst temp \ BLE f (%boolean) ] }
503 { cc> [ dst temp \ BGT f (%boolean) ] }
504 { cc>= [ dst temp \ BGE f (%boolean) ] }
505 { cc= [ dst temp \ BEQ f (%boolean) ] }
506 { cc/= [ dst temp \ BNE f (%boolean) ] }
509 : (%compare) ( src1 src2 -- ) [ 0 ] dip CMP ; inline
510 : (%compare-imm) ( src1 src2 -- ) [ 0 ] 2dip CMPI ; inline
511 : (%compare-float-unordered) ( src1 src2 -- ) [ 0 ] dip FCMPU ; inline
512 : (%compare-float-ordered) ( src1 src2 -- ) [ 0 ] dip FCMPO ; inline
514 :: (%compare-float) ( src1 src2 cc compare -- branch1 branch2 )
516 { cc< [ src1 src2 \ compare execute( a b -- ) \ BLT f ] }
517 { cc<= [ src1 src2 \ compare execute( a b -- ) \ BLT \ BEQ ] }
518 { cc> [ src1 src2 \ compare execute( a b -- ) \ BGT f ] }
519 { cc>= [ src1 src2 \ compare execute( a b -- ) \ BGT \ BEQ ] }
520 { cc= [ src1 src2 \ compare execute( a b -- ) \ BEQ f ] }
521 { cc<> [ src1 src2 \ compare execute( a b -- ) \ BLT \ BGT ] }
522 { cc<>= [ src1 src2 \ compare execute( a b -- ) \ BNO f ] }
523 { cc/< [ src1 src2 \ compare execute( a b -- ) \ BGE f ] }
524 { cc/<= [ src1 src2 \ compare execute( a b -- ) \ BGT \ BO ] }
525 { cc/> [ src1 src2 \ compare execute( a b -- ) \ BLE f ] }
526 { cc/>= [ src1 src2 \ compare execute( a b -- ) \ BLT \ BO ] }
527 { cc/= [ src1 src2 \ compare execute( a b -- ) \ BNE f ] }
528 { cc/<> [ src1 src2 \ compare execute( a b -- ) \ BEQ \ BO ] }
529 { cc/<>= [ src1 src2 \ compare execute( a b -- ) \ BO f ] }
532 M: ppc %compare [ (%compare) ] 2dip %boolean ;
534 M: ppc %compare-imm [ (%compare-imm) ] 2dip %boolean ;
536 M:: ppc %compare-float-ordered ( dst src1 src2 cc temp -- )
537 src1 src2 cc negate-cc \ (%compare-float-ordered) (%compare-float) :> branch2 :> branch1
538 dst temp branch1 branch2 (%boolean) ;
540 M:: ppc %compare-float-unordered ( dst src1 src2 cc temp -- )
541 src1 src2 cc negate-cc \ (%compare-float-unordered) (%compare-float) :> branch2 :> branch1
542 dst temp branch1 branch2 (%boolean) ;
544 :: %branch ( label cc -- )
546 { cc< [ label BLT ] }
547 { cc<= [ label BLE ] }
548 { cc> [ label BGT ] }
549 { cc>= [ label BGE ] }
550 { cc= [ label BEQ ] }
551 { cc/= [ label BNE ] }
554 M:: ppc %compare-branch ( label src1 src2 cc -- )
558 M:: ppc %compare-imm-branch ( label src1 src2 cc -- )
559 src1 src2 (%compare-imm)
562 :: (%branch) ( label branch1 branch2 -- )
563 label branch1 execute( label -- )
564 branch2 [ label branch2 execute( label -- ) ] when ; inline
566 M:: ppc %compare-float-ordered-branch ( label src1 src2 cc -- )
567 src1 src2 cc \ (%compare-float-ordered) (%compare-float) :> branch2 :> branch1
568 label branch1 branch2 (%branch) ;
570 M:: ppc %compare-float-unordered-branch ( label src1 src2 cc -- )
571 src1 src2 cc \ (%compare-float-unordered) (%compare-float) :> branch2 :> branch1
572 label branch1 branch2 (%branch) ;
574 : load-from-frame ( dst n rep -- )
576 { int-rep [ [ 1 ] dip LWZ ] }
577 { float-rep [ [ 1 ] dip LFS ] }
578 { double-rep [ [ 1 ] dip LFD ] }
579 { stack-params [ [ 0 1 ] dip LWZ [ 0 1 ] dip param@ STW ] }
582 : next-param@ ( n -- x ) param@ stack-frame get total-size>> + ;
584 : store-to-frame ( src n rep -- )
586 { int-rep [ [ 1 ] dip STW ] }
587 { float-rep [ [ 1 ] dip STFS ] }
588 { double-rep [ [ 1 ] dip STFD ] }
589 { stack-params [ [ [ 0 1 ] dip next-param@ LWZ 0 1 ] dip STW ] }
592 M: ppc %spill ( src rep dst -- )
593 swap [ n>> spill@ ] dip store-to-frame ;
595 M: ppc %reload ( dst rep src -- )
596 swap [ n>> spill@ ] dip load-from-frame ;
600 M: int-regs return-reg drop 3 ;
601 M: int-regs param-regs drop { 3 4 5 6 7 8 9 10 } ;
602 M: float-regs return-reg drop 1 ;
604 M:: ppc %save-param-reg ( stack reg rep -- )
605 reg stack local@ rep store-to-frame ;
607 M:: ppc %load-param-reg ( stack reg rep -- )
608 reg stack local@ rep load-from-frame ;
610 M: ppc %prepare-unbox ( -- )
611 ! First parameter is top of stack
613 ds-reg dup cell SUBI ;
615 M: ppc %unbox ( n rep func -- )
616 ! Value must be in r3
619 ! Store the return value on the C stack
620 over [ [ reg-class-of return-reg ] keep %save-param-reg ] [ 2drop ] if ;
622 M: ppc %unbox-long-long ( n func -- )
623 ! Value must be in r3:r4
626 ! Store the return value on the C stack
628 [ [ 3 1 ] dip local@ STW ]
629 [ [ 4 1 ] dip cell + local@ STW ] bi
632 M: ppc %unbox-large-struct ( n c-type -- )
633 ! Value must be in r3
634 ! Compute destination address and load struct size
635 [ [ 4 1 ] dip local@ ADDI ] [ heap-size 5 LI ] bi*
637 "to_value_struct" f %alien-invoke ;
639 M: ppc %box ( n rep func -- )
640 ! If the source is a stack location, load it into freg #0.
641 ! If the source is f, then we assume the value is already in
643 [ over [ 0 over reg-class-of param-reg swap %load-param-reg ] [ 2drop ] if ] dip
646 M: ppc %box-long-long ( n func -- )
649 [ [ 3 1 ] dip local@ LWZ ]
650 [ [ 4 1 ] dip cell + local@ LWZ ] bi
652 ] dip f %alien-invoke ;
654 : struct-return@ ( n -- n )
655 [ stack-frame get params>> ] unless* local@ ;
657 M: ppc %prepare-box-struct ( -- )
658 #! Compute target address for value struct return
659 3 1 f struct-return@ ADDI
662 M: ppc %box-large-struct ( n c-type -- )
663 ! If n = f, then we're boxing a returned struct
664 ! Compute destination address and load struct size
665 [ [ 3 1 ] dip struct-return@ ADDI ] [ heap-size 4 LI ] bi*
667 "box_value_struct" f %alien-invoke ;
669 M:: ppc %save-context ( temp1 temp2 callback-allowed? -- )
670 #! Save Factor stack pointers in case the C code calls a
671 #! callback which does a GC, which must reliably trace
673 temp1 "stack_chain" %load-vm-field-addr
681 M: ppc %alien-invoke ( symbol dll -- )
682 [ 11 ] 2dip %alien-global 11 MTLR BLRL ;
684 M: ppc %alien-callback ( quot -- )
685 3 swap %load-reference "c_to_factor" f %alien-invoke ;
687 M: ppc %prepare-alien-indirect ( -- )
688 "unbox_alien" f %alien-invoke
691 M: ppc %alien-indirect ( -- )
694 M: ppc %callback-value ( ctype -- )
695 ! Save top of data stack
698 ! Restore data/call/retain stacks
699 "unnest_stacks" f %alien-invoke
700 ! Restore top of data stack
702 ! Unbox former top of data stack to return registers
705 M: ppc small-enough? ( n -- ? ) -32768 32767 between? ;
707 M: ppc return-struct-in-registers? ( c-type -- ? )
708 c-type return-in-registers?>> ;
710 M: ppc %box-small-struct ( c-type -- )
711 #! Box a <= 16-byte struct returned in r3:r4:r5:r6
713 "box_medium_struct" f %alien-invoke ;
715 : %unbox-struct-1 ( -- )
716 ! Alien must be in r3.
717 "alien_offset" f %alien-invoke
720 : %unbox-struct-2 ( -- )
721 ! Alien must be in r3.
722 "alien_offset" f %alien-invoke
726 : %unbox-struct-4 ( -- )
727 ! Alien must be in r3.
728 "alien_offset" f %alien-invoke
734 M: ppc %nest-stacks ( -- )
735 "nest_stacks" f %alien-invoke ;
737 M: ppc %unnest-stacks ( -- )
738 "unnest_stacks" f %alien-invoke ;
740 M: ppc %unbox-small-struct ( size -- )
741 #! Alien must be in EAX.
742 heap-size cell align cell /i {
743 { 1 [ %unbox-struct-1 ] }
744 { 2 [ %unbox-struct-2 ] }
745 { 4 [ %unbox-struct-4 ] }
748 enable-float-functions
753 { [ os macosx? ] [ "cpu.ppc.macosx" require ] }
754 { [ os linux? ] [ "cpu.ppc.linux" require ] }
757 "complex-double" c-type t >>return-in-registers? drop
761 [ alien-unsigned-4 c-bool> ] >>getter
762 [ [ >c-bool ] 2dip set-alien-unsigned-4 ] >>setter
765 "box_boolean" >>boxer
766 "to_boolean" >>unboxer
767 bool define-primitive-type
768 ] with-compilation-unit