Skip to content
This repository
Browse code

Fix small struct passing on ppc

  • Loading branch information...
commit 70b11b47eea93bf43627588d494d0b3b0d062481 1 parent 63ba1fa
Anthony Green authored
6 ChangeLog
... ... @@ -1,3 +1,9 @@
  1 +2013-02-08 Andreas Tobler <andreast@fgznet.ch>
  2 +
  3 + * src/powerpc/ffi.c (ffi_prep_cif_machdep): Fix small struct
  4 + support.
  5 + * src/powerpc/sysv.S: Ditto.
  6 +
1 7 2013-02-08 Anthony Green <green@moxielogic.com>
2 8
3 9 * testsuite/libffi.call/cls_longdouble.c: Remove xfail for
46 src/powerpc/ffi.c
@@ -48,6 +48,11 @@ enum {
48 48
49 49 FLAG_RETURNS_128BITS = 1 << (31-27), /* cr6 */
50 50
  51 + FLAG_SYSV_SMST_R4 = 1 << (31-26), /* use r4 for FFI_SYSV 8 byte
  52 + structs. */
  53 + FLAG_SYSV_SMST_R3 = 1 << (31-25), /* use r3 for FFI_SYSV 4 byte
  54 + structs. */
  55 +
51 56 FLAG_ARG_NEEDS_COPY = 1 << (31- 7),
52 57 #ifndef __NO_FPRS__
53 58 FLAG_FP_ARGUMENTS = 1 << (31- 6), /* cr1.eq; specified by ABI */
@@ -692,18 +697,35 @@ ffi_prep_cif_machdep (ffi_cif *cif)
692 697 break;
693 698
694 699 case FFI_TYPE_STRUCT:
695   - /*
696   - * The final SYSV ABI says that structures smaller or equal 8 bytes
697   - * are returned in r3/r4. The FFI_GCC_SYSV ABI instead returns them
698   - * in memory.
699   - *
700   - * NOTE: The assembly code can safely assume that it just needs to
701   - * store both r3 and r4 into a 8-byte word-aligned buffer, as
702   - * we allocate a temporary buffer in ffi_call() if this flag is
703   - * set.
704   - */
705   - if (cif->abi == FFI_SYSV && size <= 8)
706   - flags |= FLAG_RETURNS_SMST;
  700 + if (cif->abi == FFI_SYSV)
  701 + {
  702 + /* The final SYSV ABI says that structures smaller or equal 8 bytes
  703 + are returned in r3/r4. The FFI_GCC_SYSV ABI instead returns them
  704 + in memory. */
  705 +
  706 + /* Treat structs with size <= 8 bytes. */
  707 + if (size <= 8)
  708 + {
  709 + flags |= FLAG_RETURNS_SMST;
  710 + /* These structs are returned in r3. We pack the type and the
  711 + precalculated shift value (needed in the sysv.S) into flags.
  712 + The same applies for the structs returned in r3/r4. */
  713 + if (size <= 4)
  714 + {
  715 + flags |= FLAG_SYSV_SMST_R3;
  716 + flags |= 8 * (4 - size) << 8;
  717 + break;
  718 + }
  719 + /* These structs are returned in r3 and r4. See above. */
  720 + if (size <= 8)
  721 + {
  722 + flags |= FLAG_SYSV_SMST_R3 | FLAG_SYSV_SMST_R4;
  723 + flags |= 8 * (8 - size) << 8;
  724 + break;
  725 + }
  726 + }
  727 + }
  728 +
707 729 intarg_count++;
708 730 flags |= FLAG_RETVAL_REFERENCE;
709 731 /* Fall through. */
21 src/powerpc/sysv.S
@@ -142,14 +142,19 @@ L(float_return_value):
142 142 #endif
143 143
144 144 L(small_struct_return_value):
145   - /*
146   - * The C code always allocates a properly-aligned 8-byte bounce
147   - * buffer to make this assembly code very simple. Just write out
148   - * r3 and r4 to the buffer to allow the C code to handle the rest.
149   - */
150   - stw %r3, 0(%r30)
151   - stw %r4, 4(%r30)
152   - b L(done_return_value)
  145 + extrwi %r6,%r31,2,19 /* number of bytes padding = shift/8 */
  146 + mtcrf 0x02,%r31 /* copy flags to cr[24:27] (cr6) */
  147 + extrwi %r5,%r31,5,19 /* r5 <- number of bits of padding */
  148 + subfic %r6,%r6,4 /* r6 <- number of useful bytes in r3 */
  149 + bf- 25,L(done_return_value) /* struct in r3 ? if not, done. */
  150 +/* smst_one_register: */
  151 + slw %r3,%r3,%r5 /* Left-justify value in r3 */
  152 + mtxer %r6 /* move byte count to XER ... */
  153 + stswx %r3,0,%r30 /* ... and store that many bytes */
  154 + bf+ 26,L(done_return_value) /* struct in r3:r4 ? */
  155 + add %r6,%r6,%r30 /* adjust pointer */
  156 + stswi %r4,%r6,4 /* store last four bytes */
  157 + b L(done_return_value)
153 158
154 159 .LFE1:
155 160 END(ffi_call_SYSV)
1  src/sparc/ffi.c
@@ -529,6 +529,7 @@ ffi_prep_closure_loc (ffi_closure* closure,
529 529 /* SPARC v8 requires 5 instructions for flush to be visible */
530 530 asm volatile ("nop; nop; nop; nop; nop");
531 531 #endif
  532 +#else
532 533 ffi_flush_icache (closure, 16);
533 534 #endif
534 535

0 comments on commit 70b11b4

Please sign in to comment.
Something went wrong with that request. Please try again.