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
470 "inline_gc" f %alien-invoke ;
472 M: ppc %prologue ( n -- )
473 0 11 LOAD32 rc-absolute-ppc-2/2 rel-this
476 [ [ 1 1 ] dip neg ADDI ]
477 [ [ 11 1 ] dip xt-save STW ]
479 [ [ 11 1 ] dip next-save STW ]
480 [ [ 0 1 ] dip lr-save + STW ]
483 M: ppc %epilogue ( n -- )
484 #! At the end of each word that calls a subroutine, we store
485 #! the previous link register value in r0 by popping it off
486 #! the stack, set the link register to the contents of r0,
487 #! and jump to the link register.
488 [ [ 0 1 ] dip lr-save + LWZ ]
489 [ [ 1 1 ] dip ADDI ] bi
492 :: (%boolean) ( dst temp branch1 branch2 -- )
494 dst \ f tag-number %load-immediate
495 "end" get branch1 execute( label -- )
496 branch2 [ "end" get branch2 execute( label -- ) ] when
497 dst \ t %load-reference
498 "end" get resolve-label ; inline
500 :: %boolean ( dst cc temp -- )
501 cc negate-cc order-cc {
502 { cc< [ dst temp \ BLT f (%boolean) ] }
503 { cc<= [ dst temp \ BLE f (%boolean) ] }
504 { cc> [ dst temp \ BGT f (%boolean) ] }
505 { cc>= [ dst temp \ BGE f (%boolean) ] }
506 { cc= [ dst temp \ BEQ f (%boolean) ] }
507 { cc/= [ dst temp \ BNE f (%boolean) ] }
510 : (%compare) ( src1 src2 -- ) [ 0 ] dip CMP ; inline
511 : (%compare-imm) ( src1 src2 -- ) [ 0 ] 2dip CMPI ; inline
512 : (%compare-float-unordered) ( src1 src2 -- ) [ 0 ] dip FCMPU ; inline
513 : (%compare-float-ordered) ( src1 src2 -- ) [ 0 ] dip FCMPO ; inline
515 :: (%compare-float) ( src1 src2 cc compare -- branch1 branch2 )
517 { cc< [ src1 src2 \ compare execute( a b -- ) \ BLT f ] }
518 { cc<= [ src1 src2 \ compare execute( a b -- ) \ BLT \ BEQ ] }
519 { cc> [ src1 src2 \ compare execute( a b -- ) \ BGT f ] }
520 { cc>= [ src1 src2 \ compare execute( a b -- ) \ BGT \ BEQ ] }
521 { cc= [ src1 src2 \ compare execute( a b -- ) \ BEQ f ] }
522 { cc<> [ src1 src2 \ compare execute( a b -- ) \ BLT \ BGT ] }
523 { cc<>= [ src1 src2 \ compare execute( a b -- ) \ BNO f ] }
524 { cc/< [ src1 src2 \ compare execute( a b -- ) \ BGE f ] }
525 { cc/<= [ src1 src2 \ compare execute( a b -- ) \ BGT \ BO ] }
526 { cc/> [ src1 src2 \ compare execute( a b -- ) \ BLE f ] }
527 { cc/>= [ src1 src2 \ compare execute( a b -- ) \ BLT \ BO ] }
528 { cc/= [ src1 src2 \ compare execute( a b -- ) \ BNE f ] }
529 { cc/<> [ src1 src2 \ compare execute( a b -- ) \ BEQ \ BO ] }
530 { cc/<>= [ src1 src2 \ compare execute( a b -- ) \ BO f ] }
533 M: ppc %compare [ (%compare) ] 2dip %boolean ;
535 M: ppc %compare-imm [ (%compare-imm) ] 2dip %boolean ;
537 M:: ppc %compare-float-ordered ( dst src1 src2 cc temp -- )
538 src1 src2 cc negate-cc \ (%compare-float-ordered) (%compare-float) :> branch2 :> branch1
539 dst temp branch1 branch2 (%boolean) ;
541 M:: ppc %compare-float-unordered ( dst src1 src2 cc temp -- )
542 src1 src2 cc negate-cc \ (%compare-float-unordered) (%compare-float) :> branch2 :> branch1
543 dst temp branch1 branch2 (%boolean) ;
545 :: %branch ( label cc -- )
547 { cc< [ label BLT ] }
548 { cc<= [ label BLE ] }
549 { cc> [ label BGT ] }
550 { cc>= [ label BGE ] }
551 { cc= [ label BEQ ] }
552 { cc/= [ label BNE ] }
555 M:: ppc %compare-branch ( label src1 src2 cc -- )
559 M:: ppc %compare-imm-branch ( label src1 src2 cc -- )
560 src1 src2 (%compare-imm)
563 :: (%branch) ( label branch1 branch2 -- )
564 label branch1 execute( label -- )
565 branch2 [ label branch2 execute( label -- ) ] when ; inline
567 M:: ppc %compare-float-ordered-branch ( label src1 src2 cc -- )
568 src1 src2 cc \ (%compare-float-ordered) (%compare-float) :> branch2 :> branch1
569 label branch1 branch2 (%branch) ;
571 M:: ppc %compare-float-unordered-branch ( label src1 src2 cc -- )
572 src1 src2 cc \ (%compare-float-unordered) (%compare-float) :> branch2 :> branch1
573 label branch1 branch2 (%branch) ;
575 : load-from-frame ( dst n rep -- )
577 { int-rep [ [ 1 ] dip LWZ ] }
578 { float-rep [ [ 1 ] dip LFS ] }
579 { double-rep [ [ 1 ] dip LFD ] }
580 { stack-params [ [ 0 1 ] dip LWZ [ 0 1 ] dip param@ STW ] }
583 : next-param@ ( n -- x ) param@ stack-frame get total-size>> + ;
585 : store-to-frame ( src n rep -- )
587 { int-rep [ [ 1 ] dip STW ] }
588 { float-rep [ [ 1 ] dip STFS ] }
589 { double-rep [ [ 1 ] dip STFD ] }
590 { stack-params [ [ [ 0 1 ] dip next-param@ LWZ 0 1 ] dip STW ] }
593 M: ppc %spill ( src rep dst -- )
594 swap [ n>> spill@ ] dip store-to-frame ;
596 M: ppc %reload ( dst rep src -- )
597 swap [ n>> spill@ ] dip load-from-frame ;
601 M: int-regs return-reg drop 3 ;
602 M: int-regs param-regs drop { 3 4 5 6 7 8 9 10 } ;
603 M: float-regs return-reg drop 1 ;
605 M:: ppc %save-param-reg ( stack reg rep -- )
606 reg stack local@ rep store-to-frame ;
608 M:: ppc %load-param-reg ( stack reg rep -- )
609 reg stack local@ rep load-from-frame ;
611 M: ppc %prepare-unbox ( -- )
612 ! First parameter is top of stack
614 ds-reg dup cell SUBI ;
616 M: ppc %unbox ( n rep func -- )
617 ! Value must be in r3
621 ! Store the return value on the C stack
622 over [ [ reg-class-of return-reg ] keep %save-param-reg ] [ 2drop ] if ;
624 M: ppc %unbox-long-long ( n func -- )
625 ! Value must be in r3:r4
629 ! Store the return value on the C stack
631 [ [ 3 1 ] dip local@ STW ]
632 [ [ 4 1 ] dip cell + local@ STW ] bi
635 M: ppc %unbox-large-struct ( n c-type -- )
636 ! Value must be in r3
637 ! Compute destination address and load struct size
638 [ [ 4 1 ] dip local@ ADDI ] [ heap-size 5 LI ] bi*
641 "to_value_struct" f %alien-invoke ;
643 M:: ppc %box ( n rep func -- )
644 ! If the source is a stack location, load it into freg #0.
645 ! If the source is f, then we assume the value is already in
647 n [ 0 rep reg-class-of param-reg rep %load-param-reg ] when*
648 rep double-rep? 5 4 ? %load-vm-addr
649 func f %alien-invoke ;
651 M: ppc %box-long-long ( n func -- )
654 [ [ 3 1 ] dip local@ LWZ ]
655 [ [ 4 1 ] dip cell + local@ LWZ ] bi
658 ] dip f %alien-invoke ;
660 : struct-return@ ( n -- n )
661 [ stack-frame get params>> ] unless* local@ ;
663 M: ppc %prepare-box-struct ( -- )
664 #! Compute target address for value struct return
665 3 1 f struct-return@ ADDI
668 M: ppc %box-large-struct ( n c-type -- )
669 ! If n = f, then we're boxing a returned struct
670 ! Compute destination address and load struct size
671 [ [ 3 1 ] dip struct-return@ ADDI ] [ heap-size 4 LI ] bi*
674 "box_value_struct" f %alien-invoke ;
676 M:: ppc %save-context ( temp1 temp2 callback-allowed? -- )
677 #! Save Factor stack pointers in case the C code calls a
678 #! callback which does a GC, which must reliably trace
680 temp1 "stack_chain" %load-vm-field-addr
688 M: ppc %alien-invoke ( symbol dll -- )
689 [ 11 ] 2dip %alien-global 11 MTLR BLRL ;
691 M: ppc %alien-callback ( quot -- )
692 3 swap %load-reference
694 "c_to_factor" f %alien-invoke ;
696 M: ppc %prepare-alien-indirect ( -- )
698 "unbox_alien" f %alien-invoke
701 M: ppc %alien-indirect ( -- )
704 M: ppc %callback-value ( ctype -- )
705 ! Save top of data stack
709 ! Restore data/call/retain stacks
710 "unnest_stacks" f %alien-invoke
711 ! Restore top of data stack
713 ! Unbox former top of data stack to return registers
716 M: ppc small-enough? ( n -- ? ) -32768 32767 between? ;
718 M: ppc return-struct-in-registers? ( c-type -- ? )
719 c-type return-in-registers?>> ;
721 M: ppc %box-small-struct ( c-type -- )
722 #! Box a <= 16-byte struct returned in r3:r4:r5:r6
725 "box_medium_struct" f %alien-invoke ;
727 : %unbox-struct-1 ( -- )
728 ! Alien must be in r3.
730 "alien_offset" f %alien-invoke
733 : %unbox-struct-2 ( -- )
734 ! Alien must be in r3.
736 "alien_offset" f %alien-invoke
740 : %unbox-struct-4 ( -- )
741 ! Alien must be in r3.
743 "alien_offset" f %alien-invoke
749 M: ppc %nest-stacks ( -- )
751 "nest_stacks" f %alien-invoke ;
753 M: ppc %unnest-stacks ( -- )
755 "unnest_stacks" f %alien-invoke ;
757 M: ppc %unbox-small-struct ( size -- )
758 #! Alien must be in EAX.
759 heap-size cell align cell /i {
760 { 1 [ %unbox-struct-1 ] }
761 { 2 [ %unbox-struct-2 ] }
762 { 4 [ %unbox-struct-4 ] }
765 enable-float-functions
770 { [ os macosx? ] [ "cpu.ppc.macosx" require ] }
771 { [ os linux? ] [ "cpu.ppc.linux" require ] }
774 "complex-double" c-type t >>return-in-registers? drop
778 [ alien-unsigned-4 c-bool> ] >>getter
779 [ [ >c-bool ] 2dip set-alien-unsigned-4 ] >>setter
782 "box_boolean" >>boxer
783 "to_boolean" >>unboxer
784 bool define-primitive-type
785 ] with-compilation-unit