Changing the treatment of the MIPS HI and LO registers
A message that is not in the archive (sent off-list or not yet received): [email protected]
A message that is not in the archive (sent off-list or not yet received): [email protected]
A message that is not in the archive (sent off-list or not yet received): [email protected]
A message that is not in the archive (sent off-list or not yet received): [email protected]
A message that is not in the archive (sent off-list or not yet received): [email protected]
Richard,
I do not feel like speaking for the whole MIPS/Linux community and
certainly not the maintainer. I have thus added a couple of recipients to the cc list as I fear gcc-patches does not reach exactly the right people here. Others may disagree with my thoughts expressed.
Quoted 27 lines · Richard Sandiford
Quoted 7 lines
Quoted 6 lines
I'm afraid they'll just have to use "x". Although looking at it:
-
delay.his just doing common-or-garden multiplication, albeit with optional R4000 workaounds. Why not just do them in C? Can't you rely on GCC to work around the R4000 errata, now that we have -mfix-r4000?Quoted 8 lines
Which C type is correct to access the high 64 bits of the 128-bit result
of the multiplication on a 64-bit platform then? Please note the piece of code in question does not care about what the low 64 bits are -- a C construct that ultimately expands to a multiplication followed by an "mfhi" would be perfectly fine here.The workaround only came in quite recently here and could be avoided if C
code was used of course -- don't get bothered with it.After the patch, you can use:
----------------------------------------------------------------------
typedef unsigned intuint128_t__attribute__((mode(TI)));
uint64_tfoo (uint64_tx,uint64_ty)
{
return ((uint128_t) x * y) >> 64;
}
----------------------------------------------------------------------
Quoted 8 lines
This doesn't work before the patch due to the lack of a movti instruction. We have
*diti3_highpartpatterns, but it looks like they haven't been used since combine started checkingrtx_costs.If the patch goes in, I'll add tests to make sure that this code continues to work without recourse to a libgcc function. As a follow-on, I'll add proper TImode costs to
rtx_costs, so that we take full advantage of the highpart instructions. (This ought to avoid unnecessary moves.)
OK, it is good to have a way to make use of some TImode functionality
64-bit hardware provides, but it still does not provide a clean solution to the compatibility problem seen here. While a construct like:
#if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4) [new wonderful TImode stuff]
#else
[old compatibility asm crap]
#endif
will certainly work, it is as ugly as you can get. I am not sure I would be happy to see it in Linux, though obviously Ralf and the others may disagree.
Quoted 7 lines
Quoted 6 lines
Is there absolutely no way to preserve the current asm semantics without
complicating the internals horribly? I could imagine GCC could use some other constraints internally that would refer to the HI and LO registers explicitly and "h" and "l" could only be defined for asms -- I am not enough of a GCC expert here, so I don't know if it makes sense, but it would seem a reasonable idea to me.
Quoted 8 lines
I just don't think there is, sorry. If you have:
asm (... : "=h" (word1), "=l" (word2) : ...);then there needs to be at least two separately-allocatable registers, each of which can hold word-sized values. And if we have two such registers, the allocators will think they can use them for other things, including spill space. Which brings us back to where we are now.
I have just been wondering whether these can be defined as aliases to
halves of the "x" register or something like that. Not as real registers seen by the allocator.
Maciej
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 10 lines · This thread seems to have stagnated (if a thread can stagnate). Maciej said:
OK, it is good to have a way to make use of some TImode functionality
64-bit hardware provides, but it still does not provide a clean solution to the compatibility problem seen here. While a construct like:#if (
__GNUC__> 4) || (__GNUC__== 4 &&__GNUC_MINOR__>= 4) [new wonderful TImode stuff]
#else
[old compatibility asm crap]
#endif
Quoted 3 lines
will certainly work, it is as ugly as you can get. I am not sure I would be happy to see it in Linux, though obviously Ralf and the others may disagree.
but TBH, I don't see why it's so ugly.
I imagine the definitions of int128_t and uint128_t (or whatever you decide to call them) would use the condition above. Then there'd be a macro to say whether the TImode stuff is available. I.e.:
#if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4) typedef ... int128_t ...;
typedef ... uint128_t ...;
#define WE_HAVE_TIMODE 1 /* replace with a good name */ #endif
So there'd only be one copy of the __GNUC__ check. The uses would simply be:
#if WE_HAVE_TIMODE
...
#else
...#endif
That seems no worse than the kind of preprocessor condition you find all over the Linux source.
Of course, the other alternative is simply to put the mfhi in the asm itself. While using "h" should in theory produce slightly better code, the difference is probably marginal (or at least accidental) in practice. GCC doesn't know that the asm performs a multiplication or division, so it isn't necessarily going to defer the mfhi for as long as you might like.
(Better scheduling is of course another reason why the TImode version ought to be better. A third reason is that it would allow the compiler to constant-fold the result for constant delays periods; as the comment says, this currently only happens for the initialisation of usecs, not the multiplication itself.)
I've attached an updated patch below. Differences from the last time are:
- I've fixed the movti patterns for MIPS16.
- I've added -mfix-r4000 support to the new TImode patterns. Also, now that the highpart patterns store directly into a GPR, it's easy to extend them to -mfix-r4000 too.
- I've added a load of -mfix-r4000 tests.
- I've added the promised TImode testcases. They cover addition, subtraction and logic as well as multiplication:
- timode-1.c makes sure that everything is open-coded
- timode-2.c makes sure that execution succeeds
- int-moves-[12].c shadow the movtf tests I added earlier today
Tested on mips64el-linux-gnu and mipsisa64-elfoabi.
I'll reinstate the 48 hour warning, mostly as a way of seeing whether the thread is still alive.
I don't think my last message made it through to linux-mips@. If this one does, and you're wanting some context, the discussion started here:
http://gcc.gnu.org/ml/gcc-patches/2008-05/msg01750.html
Basically, I'm trying to fix a wrong-code problem that would become especially dangerous with GCC's new register allocator. The only acceptable way I can see of doing it involves removing support for the asm "h" constraint. ("hi" would still be supported in clobber lists.)
Richard
gcc/
* doc/md.texi: Synchronize with later constraints.md change.
* longlong.h (umul_ppmm): Replace the MIPS asm implementation with a C implementation.
* config/mips/mips.c (mips_legitimize_move): Remove MFHI and MFLO handling.
(mips_subword): Assume TImode for CONST_INTs if TARGET_64BIT. (mips_split_doubleword_move): Use special MTHI and MFHI instructions when moving to and from MD_REGNUM.
(mips_output_move): Don't handle moves from GPRs to HI_REGNUM. Handle moves from LO_REGNUM to GPRs using MFLO, MACC or DMACC. Handle byte and halfword moves. (mips_hard_regno_mode_ok_p): Handle MD_REGS and DSP_ACC_REGS separately.
* config/mips/constraints.md (h): Turn into NO_REGS.
(l, x): Update documentation.
* config/mips/mips.md (UNSPEC_MFHILO): Delete. (UNSPEC_MFHI, UNSPEC_MTHI, UNSPEC_SET_HILO): New. (UNSPEC_TLS_LDM, UNSPEC_TLS_GET_TP): Renumber.
(HILO): New mode iterator.
(MOVE128): Add TI.
(any_div): New code iterator.
(u): Extend code attribute to div and udiv. (*add<mode>3_mips16, *movdi_64bit_mips16, *movsi_mips16): Use d_operand in the splitters. Remove redundant CONST_INT checks. (mulsi3_mult3, mul<mode>3_internal, mul<mode>3_r4000, *mul_acc_si) (*macc, *msac, *msac_using_macc, *macc2, *msac2, *mul_sub_si) (*muls): Remove "=h" clobbers. Adjust peephole2s and define_splits accordingly, using normal moves instead of unspecs to move LO into a GPR. Use d_operand and lo_operand instead of *_REG_P checks. (<u>mulsidi3): Handle expansion in C code. (<u>mulsidi3_32bit_internal): Rename to... (<u>mulsidi3_32bit): ...this.
(<u>mulsidi3_32bit_r4000): Fix insn separator. (*<u>mulsidi3_64bit): Rename to...
(<u>mulsidi3_64bit): ...this. Combine DImode "=h" and "=l" clobbers into a TImode "=x" clobber. In the split, use an UNSPEC_SET_HILO to set LO and HI to the multiplication result. Use a normal move for MFLO and an unspec for MFHI. (*<u>mulsidi3_64bit_parts): Replace with... (<u>mulsidi3_64bit_hilo): ...this new instruction. (<su>mulsi3_highpart): Extend to TARGET_FIX_R4000. (<su>mulsi3_highpart_internal): Turn into a define_insn_and_split and extend it to TARGET_FIX_R4000. Store the destination in a GPR instead of HI. Split the instruction into a separate multiplication and MFHI if !TARGET_FIX_R4000.
(<su>muldi3_highpart): Likewise. (<su>mulsi3_highpart_mulhi_internal): Remove the first alternative and the "=h" clobber. (*<su>mulsi3_highpart_neg_mulhi_internal): Likewise. (<u>mulditi3): New expander.
(<u>mulditi3_internal, <u>mulditi3_r4000): New patterns. (madsi): Remove "=h" clobber.
(divmod<mode>4, udivmod<mode>4): Turn into define_insn_and_splits. Force the modulus result to be a GPR and split the instruction into a division followed by an MFHI after reload. (<u>divmod<GPR:mode>4_hilo_<HILO:mode>): New instruction. (*lea_high64): Use d_operand in the define_peephole2. Likewise the MIPS16 HIGH define_split.
(*movdi_32bit, *movdi_gp32_fp64, *movdi_32bit_mips16): Change type of acc<->gpr moves to "multi".
(*movdi_64bit): Replace the single "x" alternative with alternatives for moving into and out of "a". (*movhi_internal, *movqi_internal): Likewise. Use mips_output_move. (*movsi_internal): Extend the "d<-A" alternative to "d<-a". (*movdi_64bit_mips16, *movsi_mips16): Add d<-a alternatives. Use d_operand in the splitters. Remove redundant CONST_INT checks. (*movhi_mips16, *movqi_mips16): Likewise. Use mips_output_move. (movti): New expander.
(*movti, *movti_mips16): New insns.
(mfhilo_<mode>, *mfhilo_<mode>, *mfhilo_<mode>_macc): Delete. (mfhi<GPR:mode>_<HILO:mode>): New pattern. (mthi<GPR:mode>_<HILO:mode>): Likewise.
* config/mips/predicates.md (fpr_operand): Delete. (d_operand): New predicate.
gcc/testsuite/
* gcc.dg/torture/mips-hilo-1.c: Delete.
* gcc.target/mips/pr35232.c: Likewise.
* gcc.target/mips/fix-vr4130-1.c: Use modulus to create an mfhi.
* gcc.target/mips/fix-vr4130-3.c: Likewise.
* gcc.target/mips/int-moves-1.c: New test.
* gcc.target/mips/int-moves-2.c: Likewise.
* gcc.target/mips/fix-r4000-1.c: Likewise.
* gcc.target/mips/fix-r4000-2.c: Likewise.
* gcc.target/mips/fix-r4000-3.c: Likewise.
* gcc.target/mips/fix-r4000-4.c: Likewise.
* gcc.target/mips/fix-r4000-5.c: Likewise.
* gcc.target/mips/fix-r4000-6.c: Likewise.
* gcc.target/mips/fix-r4000-7.c: Likewise.
* gcc.target/mips/fix-r4000-8.c: Likewise.
* gcc.target/mips/fix-r4000-9.c: Likewise.
* gcc.target/mips/fix-r4000-10.c: Likewise.
* gcc.target/mips/fix-r4000-11.c: Likewise.
* gcc.target/mips/fix-r4000-12.c: Likewise.
* gcc.target/mips/timode-1.c: Likewise.
* gcc.target/mips/timode-2.c: Likewise.
doc/md.texi +5 -3
@@ -2498,13 +2498,15 @@ generating MIPS16 code. A floating-point register (if available). @item h -The @code{hi} register. +Formerly the @code{hi} register. This constraint is no longer supported. @item l -The @code{lo} register. +The @code{lo} register. Use this register to store values that are +no bigger than a word. @item x -The @code{hi} and @code{lo} registers. +The concatenated @code{hi} and @code{lo} registers. Use this register +to store doubleword values. @item c A register suitable for use in an indirect jump. This will always be
longlong.h +6 -6
@@ -623,12 +623,12 @@ #define UDIV_TIME 150#endif /* __m88000__ */ #if defined (__mips__) &&W_TYPE_SIZE ==32 -#define umul_ppmm (w1, w0, u, v) \ - __asm__ ("multu %2,%3" \ - : "=l" ((USItype) (w0)), \ - "=h" ((USItype) (w1)) \ - : "d" ((USItype) (u)), \ - "d" ((USItype) (v))) +#define umul_ppmm (w1, w0, u, v) \ + do { \ + UDItype __x = (UDItype) (USItype) (u) * (USItype) (v); \ + (w1) = (USItype) (__x >> 32); \ + (w0) = (USItype) (__x); \ + } while (0)#define UMUL_TIME 10#define UDIV_TIME 100
config/mips/mips.c +71 -32
161 lines not on this page · raw message
config/mips/constraints.md +6 -4
@@ -29,14 +29,16 @@ (define_register_constraint "t" "T_REG" (define_register_constraint "f" "TARGET_HARD_FLOAT ? FP_REGS : NO_REGS" "A floating-point register (if available).") -(define_register_constraint "h" "TARGET_BIG_ENDIAN ? MD0_REG : MD1_REG" - "The @code{hi} register.") +(define_register_constraint "h" "NO_REGS" + "Formerly the @code{hi} register. This constraint is no longer supported.") (define_register_constraint "l" "TARGET_BIG_ENDIAN ? MD1_REG : MD0_REG" - "The @code{lo} register.") + "The @code{lo} register. Use this register to store values that are + no bigger than a word.") (define_register_constraint "x" "MD_REGS" - "The @code{hi} and @code{lo} registers.") + "The concatenated @code{hi} and @code{lo} registers. Use this register + to store doubleword values.") (define_register_constraint "b" "ALL_REGS" "@internal")
config/mips/mips.md +417 -401
1,356 lines not on this page · raw message
config/mips/predicates.md +4 -2
@@ -76,9 +76,11 @@ (define_predicate "const_0_or_1_operand" (ior (match_test "op == CONST0_RTX (GET_MODE (op))") (match_test "op == CONST1_RTX (GET_MODE (op))")))) -(define_predicate "fpr_operand" +(define_predicate "d_operand" (and (match_code "reg") - (match_test "FP_REG_P (REGNO (op))"))) + (match_test "TARGET_MIPS16 + ? M16_REG_P (REGNO (op)) + : GP_REG_P (REGNO (op))"))) (define_predicate "lo_operand" (and (match_code "reg")
testsuite/gcc.dg/torture/mips-hilo-1.c deleted +0 -73
73 lines not on this page · raw message
testsuite/gcc.target/mips/pr35232.c deleted +0 -17
@@ -1,17 +0,0 @@ -/* { dg-do run } */ -/* { dg-mips-options "-O" } */ - -NOMIPS16 unsigned int -f1 (unsigned long long x) -{ -unsigned int r; - asm ("# %0" :"=a" (r) :"0" (x)); - asm ("# %0" :"=h" (r) :"0" (r)); -return r; -} - -int -main (void ) -{ -return f1 (4 ) !=4 ; -}
testsuite/gcc.target/mips/fix-vr4130-1.c +5 -1
@@ -1,4 +1,8 @@/* { dg-do compile } */ /* { dg-mips-options "-march=vr4130 -mfix-vr4130" } */ -NOMIPS16 int foo (void) { int r; asm ("# foo" : "=h" (r)); return r; } +NOMIPS16 unsigned int +foo (unsigned int x,unsigned int y) +{ +return x % y; +}/* { dg-final { scan-assembler "\tmacchi\t" } } */
testsuite/gcc.target/mips/fix-vr4130-3.c +3 -5
@@ -1,10 +1,8 @@/* { dg-do compile } */ /* { dg-mips-options "-march=vr4130 -mgp64 -mfix-vr4130" } */ -NOMIPS16 long long -foo (void ) +NOMIPS16 unsigned long long +foo (unsigned long long x,unsigned long long y) { -long long r; - asm ("# foo" :"=h" (r)); -return r; +return x % y; }/* { dg-final { scan-assembler "\tdmacchi\t" } } */
testsuite/gcc.target/mips/int-moves-1.c new file +40 -0
@@ -0,0 +1,40 @@ +/* { dg-do compile { target mips16_attribute } } */ +/* { dg-mips-options "-mgp64 -msoft-float -O2 -EL" } */ +/* { dg-add-options mips16_attribute } */ + +typedef unsigned uint128_t __attribute__((mode (TI ))); + +extern uint128_t g[16 ]; +extern unsigned char gstuff[0x10000 ]; + +NOMIPS16 uint128_t +foo (uint128_t i1, uint128_t i2, uint128_t i3, uint128_t i4, +uint128_t *x,unsigned char *lstuff) +{ + g[0 ] = i1; + g[1 ] = i2; + g[2 ] = i3; + g[3 ] = i4; + x[0 ] = x[4 ]; + x[1 ] =0 ; + x[2 ] = ((uint128_t )0x123456789abcdefULL <<64 ) |0xaabbccddeeff1122ULL ; + x[3 ] = g[4 ]; + x[4 ] = *(uint128_t *) (lstuff +0x7fff ); +return *(uint128_t *) (gstuff +0x7fff ); +} + +MIPS16 uint128_t +bar (uint128_t i1, uint128_t i2, uint128_t i3, uint128_t i4, +uint128_t *x,unsigned char *lstuff) +{ + g[0 ] = i1; + g[1 ] = i2; + g[2 ] = i3; + g[3 ] = i4; + x[0 ] = x[4 ]; + x[1 ] =0 ; + x[2 ] = ((uint128_t )0x123456789abcdefULL <<64 ) |0xaabbccddeeff1122ULL ; + x[3 ] = g[4 ]; + x[4 ] = *(uint128_t *) (lstuff +0x7fff ); +return *(uint128_t *) (gstuff +0x7fff ); +}
testsuite/gcc.target/mips/int-moves-2.c new file +40 -0
@@ -0,0 +1,40 @@ +/* { dg-do compile { target mips16_attribute } } */ +/* { dg-mips-options "-mgp64 -msoft-float -O2 -EB" } */ +/* { dg-add-options mips16_attribute } */ + +typedef unsigned uint128_t __attribute__((mode (TI ))); + +extern uint128_t g[16 ]; +extern unsigned char gstuff[0x10000 ]; + +NOMIPS16 uint128_t +foo (uint128_t i1, uint128_t i2, uint128_t i3, uint128_t i4, +uint128_t *x,unsigned char *lstuff) +{ + g[0 ] = i1; + g[1 ] = i2; + g[2 ] = i3; + g[3 ] = i4; + x[0 ] = x[4 ]; + x[1 ] =0 ; + x[2 ] = ((uint128_t )0x123456789abcdefULL <<64 ) |0xaabbccddeeff1122ULL ; + x[3 ] = g[4 ]; + x[4 ] = *(uint128_t *) (lstuff +0x7fff ); +return *(uint128_t *) (gstuff +0x7fff ); +} + +MIPS16 uint128_t +bar (uint128_t i1, uint128_t i2, uint128_t i3, uint128_t i4, +uint128_t *x,unsigned char *lstuff) +{ + g[0 ] = i1; + g[1 ] = i2; + g[2 ] = i3; + g[3 ] = i4; + x[0 ] = x[4 ]; + x[1 ] =0 ; + x[2 ] = ((uint128_t )0x123456789abcdefULL <<64 ) |0xaabbccddeeff1122ULL ; + x[3 ] = g[4 ]; + x[4 ] = *(uint128_t *) (lstuff +0x7fff ); +return *(uint128_t *) (gstuff +0x7fff ); +}
testsuite/gcc.target/mips/fix-r4000-1.c new file +6 -0
@@ -0,0 +1,6 @@ +/* { dg-mips-options "-march=r4000 -mfix-r4000 -O2 -dp" } */ +typedef int int32_t ; +typedef int uint32_t ; +int32_t foo (int32_t x,int32_t y) {return x * y; } +uint32_t bar (uint32_t x,uint32_t y) {return x * y; } +/* { dg-final { scan-assembler-times "[concat {\tmult\t\$[45],\$[45][^\n]+mulsi3_r4000[^\n]+\n\tmflo\t\$2\n}]" 2 } } */
testsuite/gcc.target/mips/fix-r4000-2.c new file +7 -0
@@ -0,0 +1,7 @@ +/* { dg-mips-options "-mips1 -mfix-r4000 -O2 -dp -EB" } */ +typedef int int32_t ; +typedef long long int64_t ; +int32_t foo (int32_t x,int32_t y) {return ((int64_t ) x * y) >>32 ; } +/* ??? A highpart pattern would be a better choice, but we currently +don't use them. */ +/* { dg-final { scan-assembler "[concat {\tmult\t\$[45],\$[45][^\n]+mulsidi3_32bit_r4000[^\n]+\n\tmflo\t\$3\n\tmfhi\t\$2\n}]" } } */
testsuite/gcc.target/mips/fix-r4000-3.c new file +7 -0
@@ -0,0 +1,7 @@ +/* { dg-mips-options "-mips1 -mfix-r4000 -O2 -dp -EB" } */ +typedef unsigned int uint32_t ; +typedef unsigned long long uint64_t ; +uint32_t foo (uint32_t x,uint32_t y) {return ((uint64_t ) x * y) >>32 ; } +/* ??? A highpart pattern would be a better choice, but we currently +don't use them. */ +/* { dg-final { scan-assembler "[concat {\tmultu\t\$[45],\$[45][^\n]+umulsidi3_32bit_r4000[^\n]+\n\tmflo\t\$3\n\tmfhi\t\$2\n}]" } } */
testsuite/gcc.target/mips/fix-r4000-4.c new file +8 -0
@@ -0,0 +1,8 @@ +/* ??? At the moment, lower-subreg.c decomposes the copy of the multiplication +result to $2, which prevents the register allocators from storing the +multiplication result in $2. */ +/* { dg-mips-options "-mips1 -mfix-r4000 -O2 -fno-split-wide-types -dp -EL" } */ +typedef int int32_t ; +typedef long long int64_t ; +int64_t foo (int32_t x,int32_t y) {return (int64_t ) x * y; } +/* { dg-final { scan-assembler "[concat {\tmult\t\$[45],\$[45][^\n]+mulsidi3_32bit_r4000[^\n]+\n\tmflo\t\$2\n\tmfhi\t\$3\n}]" } } */
testsuite/gcc.target/mips/fix-r4000-5.c new file +8 -0
@@ -0,0 +1,8 @@ +/* ??? At the moment, lower-subreg.c decomposes the copy of the multiplication +result to $2, which prevents the register allocators from storing the +multiplication result in $2. */ +/* { dg-mips-options "-mips1 -mfix-r4000 -O2 -fno-split-wide-types -dp -EL" } */ +typedef unsigned int uint32_t ; +typedef unsigned long long uint64_t ; +uint64_t foo (uint32_t x,uint32_t y) {return (uint64_t ) x * y; } +/* { dg-final { scan-assembler "[concat {\tmultu\t\$[45],\$[45][^\n]+umulsidi3_32bit_r4000[^\n]+\n\tmflo\t\$2\n\tmfhi\t\$3\n}]" } } */
testsuite/gcc.target/mips/fix-r4000-6.c new file +6 -0
@@ -0,0 +1,6 @@ +/* { dg-mips-options "-march=r4000 -mfix-r4000 -mgp64 -O2 -dp" } */ +typedef long long int64_t ; +typedef unsigned long long uint64_t ; +int64_t foo (int64_t x,int64_t y) {return x * y; } +uint64_t bar (uint64_t x,uint64_t y) {return x * y; } +/* { dg-final { scan-assembler-times "[concat {\tdmult\t\$[45],\$[45][^\n]+muldi3_r4000[^\n]+\n\tmflo\t\$2\n}]" 2 } } */
testsuite/gcc.target/mips/fix-r4000-7.c new file +7 -0
@@ -0,0 +1,7 @@ +/* { dg-mips-options "-march=r4000 -mfix-r4000 -O2 -mgp64 -dp -EB" } */ +typedef long long int64_t ; +typedef int int128_t __attribute__((mode (TI ))); +int64_t foo (int64_t x,int64_t y) {return ((int128_t ) x * y) >>64 ; } +/* ??? A highpart pattern would be a better choice, but we currently +don't use them. */ +/* { dg-final { scan-assembler "[concat {\tdmult\t\$[45],\$[45][^\n]+mulditi3[^\n]+\n\tmflo\t\$3\n\tmfhi\t\$2\n}]" } } */
testsuite/gcc.target/mips/fix-r4000-8.c new file +7 -0
@@ -0,0 +1,7 @@ +/* { dg-mips-options "-march=r4000 -mfix-r4000 -O2 -mgp64 -dp -EB" } */ +typedef unsigned long long uint64_t ; +typedef unsigned int uint128_t __attribute__((mode (TI ))); +uint64_t foo (uint64_t x,uint64_t y) {return ((uint128_t ) x * y) >>64 ; } +/* ??? A highpart pattern would be a better choice, but we currently +don't use them. */ +/* { dg-final { scan-assembler "[concat {\tdmultu\t\$[45],\$[45][^\n]+umulditi3[^\n]+\n\tmflo\t\$3\n\tmfhi\t\$2\n}]" } } */
testsuite/gcc.target/mips/fix-r4000-9.c new file +8 -0
@@ -0,0 +1,8 @@ +/* ??? At the moment, lower-subreg.c decomposes the copy of the multiplication +result to $2, which prevents the register allocators from storing the +multiplication result in $2. */ +/* { dg-mips-options "-mips3 -mfix-r4000 -mgp64 -O2 -fno-split-wide-types -dp -EL" } */ +typedef long long int64_t ; +typedef int int128_t __attribute__((mode (TI ))); +int128_t foo (int64_t x,int64_t y) {return (int128_t ) x * y; } +/* { dg-final { scan-assembler "[concat {\tdmult\t\$[45],\$[45][^\n]+mulditi3_r4000[^\n]+\n\tmflo\t\$2\n\tmfhi\t\$3\n}]" } } */
testsuite/gcc.target/mips/fix-r4000-10.c new file +8 -0
@@ -0,0 +1,8 @@ +/* ??? At the moment, lower-subreg.c decomposes the copy of the multiplication +result to $2, which prevents the register allocators from storing the +multiplication result in $2. */ +/* { dg-mips-options "-mips3 -mfix-r4000 -mgp64 -O2 -fno-split-wide-types -dp -EL" } */ +typedef unsigned long long uint64_t ; +typedef unsigned int uint128_t __attribute__((mode (TI ))); +uint128_t foo (uint64_t x,uint64_t y) {return (uint128_t ) x * y; } +/* { dg-final { scan-assembler "[concat {\tdmultu\t\$[45],\$[45][^\n]+umulditi3_r4000[^\n]+\n\tmflo\t\$2\n\tmfhi\t\$3\n}]" } } */
testsuite/gcc.target/mips/fix-r4000-11.c new file +4 -0
@@ -0,0 +1,4 @@ +/* { dg-mips-options "-march=r4000 -mfix-r4000 -mgp64 -O2 -dp" } */ +typedef long long int64_t ; +int64_t foo (int64_t x) {return x /11993 ; } +/* { dg-final { scan-assembler "[concat {\tdmult\t\$4,\$[0-9]+[^\n]+smuldi3_highpart[^\n]+\n\tmfhi\t\$[0-9]+\n}]" } } */
testsuite/gcc.target/mips/fix-r4000-12.c new file +4 -0
@@ -0,0 +1,4 @@ +/* { dg-mips-options "-march=r4000 -mfix-r4000 -mgp64 -O2 -dp" } */ +typedef unsigned long long uint64_t ; +uint64_t foo (uint64_t x) {return x /11993 ; } +/* { dg-final { scan-assembler "[concat {\tdmultu\t\$4,\$[0-9]+[^\n]+umuldi3_highpart[^\n]+\n\tmfhi\t\$[0-9]+\n}]" } } */
testsuite/gcc.target/mips/timode-1.c new file +65 -0
65 lines not on this page · raw message
testsuite/gcc.target/mips/timode-2.c new file +64 -0
64 lines not on this page · raw message
Quoted 2 lines · Richard Sandiford
I'll reinstate the 48 hour warning, mostly as a way of seeing whether the thread is still alive.
Here's the final version of the patch. I fixed the <su>mulsi3_highpart condition and added a couple of missing attributes. Applied after retesting. I also made the following changes to the web page:
Index: htdocs/gcc-4.4/changes.html
===================================================================
RCS file: /cvs/gcc/wwwdocs/htdocs/gcc-4.4/changes.html,v retrieving revision 1.11
gcc-4.4/changes.html +24 -0
@@ -28,6 +28,28 @@ when <code>-Wdeprecated</code> or <code>-pedantic</code> is used. This extension has been deprecated for many years, but never warned about.</li> + + <li>The MIPS port no longer recognizes the <code>h</code> + <code>asm</code> constraint. It was necessary to remove + this constraint in order to avoid generating unpredictable + code sequences. + + <p>One of the main uses of the <code>h</code> constraint + was to extract the high part of a multiplication on + 64-bit targets. For example:</p> + <pre> + asm ("dmultu\t%1,%2" : "=h" (result) : "r" (x), "r" (y));</pre> + <p>You can now achieve the same effect using 128-bit types:</p> + <pre> + typedef unsigned int uint128_t __attribute__((mode(TI))); + result = ((uint128_t) x * y) >> 64;</pre> + <p>The second sequence is better in many ways. For example, + if <code>x</code> and <code>y</code> are constants, the + compiler can perform the multiplication at compile time. + If <code>x</code> and <code>y</code> are not constants, + the compiler can schedule the runtime multiplication + better than it can schedule an <code>asm</code> statement.</p> + </li> </ul> <h2>General Optimizer Improvements</h2>
@@ -75,6 +97,8 @@ <ul> <li>Support for RMI's XLR processor is now available through the <code>-march=xlr</code> and <code>-mtune=xlr</code> options.</li> + <li>64-bit targets can now perform 128-bit multiplications inline, + instead of relying on a <code>libgcc</code> function.</li> </ul> <h2>Documentation improvements</h2>
Please shout if you find anything wrong with either the patch or the documentation changes.
Richard
gcc/
* doc/md.texi: Synchronize with later constraints.md change.
* longlong.h (umul_ppmm): Replace the MIPS asm implementation with a C implementation.
* config/mips/mips.c (mips_legitimize_move): Remove MFHI and MFLO handling.
(mips_subword): Assume TImode for CONST_INTs if TARGET_64BIT. (mips_split_doubleword_move): Use special MTHI and MFHI instructions when moving to and from MD_REGNUM.
(mips_output_move): Don't handle moves from GPRs to HI_REGNUM. Handle moves from LO_REGNUM to GPRs using MFLO, MACC or DMACC. Handle byte and halfword moves. (mips_hard_regno_mode_ok_p): Handle MD_REGS and DSP_ACC_REGS separately.
* config/mips/constraints.md (h): Turn into NO_REGS.
(l, x): Update documentation.
* config/mips/mips.md (UNSPEC_MFHILO): Delete. (UNSPEC_MFHI, UNSPEC_MTHI, UNSPEC_SET_HILO): New. (UNSPEC_TLS_LDM, UNSPEC_TLS_GET_TP): Renumber.
(HILO): New mode iterator.
(MOVE128): Add TI.
(any_div): New code iterator.
(u): Extend code attribute to div and udiv. (*add<mode>3_mips16, *movdi_64bit_mips16, *movsi_mips16): Use d_operand in the splitters. Remove redundant CONST_INT checks. (mulsi3_mult3, mul<mode>3_internal, mul<mode>3_r4000, *mul_acc_si) (*macc, *msac, *msac_using_macc, *macc2, *msac2, *mul_sub_si) (*muls): Remove "=h" clobbers. Adjust peephole2s and define_splits accordingly, using normal moves instead of unspecs to move LO into a GPR. Use d_operand and lo_operand instead of *_REG_P checks. (<u>mulsidi3): Handle expansion in C code. (<u>mulsidi3_32bit_internal): Rename to... (<u>mulsidi3_32bit): ...this.
(<u>mulsidi3_32bit_r4000): Fix insn separator. (*<u>mulsidi3_64bit): Rename to...
(<u>mulsidi3_64bit): ...this. Combine DImode "=h" and "=l" clobbers into a TImode "=x" clobber. In the split, use an UNSPEC_SET_HILO to set LO and HI to the multiplication result. Use a normal move for MFLO and an unspec for MFHI. (*<u>mulsidi3_64bit_parts): Replace with... (<u>mulsidi3_64bit_hilo): ...this new instruction. (<su>mulsi3_highpart): Extend to TARGET_FIX_R4000. (<su>mulsi3_highpart_internal): Turn into a define_insn_and_split and extend it to TARGET_FIX_R4000. Store the destination in a GPR instead of HI. Split the instruction into a separate multiplication and MFHI if !TARGET_FIX_R4000.
(<su>muldi3_highpart): Likewise. (<su>mulsi3_highpart_mulhi_internal): Remove the first alternative and the "=h" clobber. (*<su>mulsi3_highpart_neg_mulhi_internal): Likewise. (<u>mulditi3): New expander.
(<u>mulditi3_internal, <u>mulditi3_r4000): New patterns. (madsi): Remove "=h" clobber.
(divmod<mode>4, udivmod<mode>4): Turn into define_insn_and_splits. Force the modulus result to be a GPR and split the instruction into a division followed by an MFHI after reload. (<u>divmod<GPR:mode>4_hilo_<HILO:mode>): New instruction. (*lea_high64): Use d_operand in the define_peephole2. Likewise the MIPS16 HIGH define_split.
(*movdi_32bit, *movdi_gp32_fp64, *movdi_32bit_mips16): Change type of acc<->gpr moves to "multi".
(*movdi_64bit): Replace the single "x" alternative with alternatives for moving into and out of "a". (*movhi_internal, *movqi_internal): Likewise. Use mips_output_move. (*movsi_internal): Extend the "d<-A" alternative to "d<-a". (*movdi_64bit_mips16, *movsi_mips16): Add d<-a alternatives. Use d_operand in the splitters. Remove redundant CONST_INT checks. (*movhi_mips16, *movqi_mips16): Likewise. Use mips_output_move. (movti): New expander.
(*movti, *movti_mips16): New insns.
(mfhilo_<mode>, *mfhilo_<mode>, *mfhilo_<mode>_macc): Delete. (mfhi<GPR:mode>_<HILO:mode>): New pattern. (mthi<GPR:mode>_<HILO:mode>): Likewise.
* config/mips/predicates.md (fpr_operand): Delete. (d_operand): New predicate.
gcc/testsuite/
* gcc.dg/torture/mips-hilo-1.c: Delete.
* gcc.target/mips/pr35232.c: Likewise.
* gcc.target/mips/fix-vr4130-1.c: Use modulus to create an mfhi.
* gcc.target/mips/fix-vr4130-3.c: Likewise.
* gcc.target/mips/int-moves-1.c: New test.
* gcc.target/mips/int-moves-2.c: Likewise.
* gcc.target/mips/fix-r4000-1.c: Likewise.
* gcc.target/mips/fix-r4000-2.c: Likewise.
* gcc.target/mips/fix-r4000-3.c: Likewise.
* gcc.target/mips/fix-r4000-4.c: Likewise.
* gcc.target/mips/fix-r4000-5.c: Likewise.
* gcc.target/mips/fix-r4000-6.c: Likewise.
* gcc.target/mips/fix-r4000-7.c: Likewise.
* gcc.target/mips/fix-r4000-8.c: Likewise.
* gcc.target/mips/fix-r4000-9.c: Likewise.
* gcc.target/mips/fix-r4000-10.c: Likewise.
* gcc.target/mips/fix-r4000-11.c: Likewise.
* gcc.target/mips/fix-r4000-12.c: Likewise.
* gcc.target/mips/timode-1.c: Likewise.
* gcc.target/mips/timode-2.c: Likewise.
doc/md.texi +5 -3
@@ -2469,13 +2469,15 @@ generating MIPS16 code. A floating-point register (if available). @item h -The @code{hi} register. +Formerly the @code{hi} register. This constraint is no longer supported. @item l -The @code{lo} register. +The @code{lo} register. Use this register to store values that are +no bigger than a word. @item x -The @code{hi} and @code{lo} registers. +The concatenated @code{hi} and @code{lo} registers. Use this register +to store doubleword values. @item c A register suitable for use in an indirect jump. This will always be
longlong.h +6 -6
@@ -623,12 +623,12 @@ #define UDIV_TIME 150#endif /* __m88000__ */ #if defined (__mips__) &&W_TYPE_SIZE ==32 -#define umul_ppmm (w1, w0, u, v) \ - __asm__ ("multu %2,%3" \ - : "=l" ((USItype) (w0)), \ - "=h" ((USItype) (w1)) \ - : "d" ((USItype) (u)), \ - "d" ((USItype) (v))) +#define umul_ppmm (w1, w0, u, v) \ + do { \ + UDItype __x = (UDItype) (USItype) (u) * (USItype) (v); \ + (w1) = (USItype) (__x >> 32); \ + (w0) = (USItype) (__x); \ + } while (0)#define UMUL_TIME 10#define UDIV_TIME 100
config/mips/mips.c +71 -32
161 lines not on this page · raw message
config/mips/constraints.md +6 -4
@@ -29,14 +29,16 @@ (define_register_constraint "t" "T_REG" (define_register_constraint "f" "TARGET_HARD_FLOAT ? FP_REGS : NO_REGS" "A floating-point register (if available).") -(define_register_constraint "h" "TARGET_BIG_ENDIAN ? MD0_REG : MD1_REG" - "The @code{hi} register.") +(define_register_constraint "h" "NO_REGS" + "Formerly the @code{hi} register. This constraint is no longer supported.") (define_register_constraint "l" "TARGET_BIG_ENDIAN ? MD1_REG : MD0_REG" - "The @code{lo} register.") + "The @code{lo} register. Use this register to store values that are + no bigger than a word.") (define_register_constraint "x" "MD_REGS" - "The @code{hi} and @code{lo} registers.") + "The concatenated @code{hi} and @code{lo} registers. Use this register + to store doubleword values.") (define_register_constraint "b" "ALL_REGS" "@internal")
config/mips/mips.md +429 -401
1,368 lines not on this page · raw message
config/mips/predicates.md +4 -2
@@ -76,9 +76,11 @@ (define_predicate "const_0_or_1_operand" (ior (match_test "op == CONST0_RTX (GET_MODE (op))") (match_test "op == CONST1_RTX (GET_MODE (op))")))) -(define_predicate "fpr_operand" +(define_predicate "d_operand" (and (match_code "reg") - (match_test "FP_REG_P (REGNO (op))"))) + (match_test "TARGET_MIPS16 + ? M16_REG_P (REGNO (op)) + : GP_REG_P (REGNO (op))"))) (define_predicate "lo_operand" (and (match_code "reg")
testsuite/gcc.dg/torture/mips-hilo-1.c deleted +0 -73
73 lines not on this page · raw message
testsuite/gcc.target/mips/pr35232.c deleted +0 -17
@@ -1,17 +0,0 @@ -/* { dg-do run } */ -/* { dg-mips-options "-O" } */ - -NOMIPS16 unsigned int -f1 (unsigned long long x) -{ -unsigned int r; - asm ("# %0" :"=a" (r) :"0" (x)); - asm ("# %0" :"=h" (r) :"0" (r)); -return r; -} - -int -main (void ) -{ -return f1 (4 ) !=4 ; -}
testsuite/gcc.target/mips/fix-vr4130-1.c +5 -1
@@ -1,4 +1,8 @@/* { dg-do compile } */ /* { dg-mips-options "-march=vr4130 -mfix-vr4130" } */ -NOMIPS16 int foo (void) { int r; asm ("# foo" : "=h" (r)); return r; } +NOMIPS16 unsigned int +foo (unsigned int x,unsigned int y) +{ +return x % y; +}/* { dg-final { scan-assembler "\tmacchi\t" } } */
testsuite/gcc.target/mips/fix-vr4130-3.c +3 -5
@@ -1,10 +1,8 @@/* { dg-do compile } */ /* { dg-mips-options "-march=vr4130 -mgp64 -mfix-vr4130" } */ -NOMIPS16 long long -foo (void ) +NOMIPS16 unsigned long long +foo (unsigned long long x,unsigned long long y) { -long long r; - asm ("# foo" :"=h" (r)); -return r; +return x % y; }/* { dg-final { scan-assembler "\tdmacchi\t" } } */
testsuite/gcc.target/mips/int-moves-1.c new file +40 -0
@@ -0,0 +1,40 @@ +/* { dg-do compile { target mips16_attribute } } */ +/* { dg-mips-options "-mgp64 -msoft-float -O2 -EL" } */ +/* { dg-add-options mips16_attribute } */ + +typedef unsigned uint128_t __attribute__((mode (TI ))); + +extern uint128_t g[16 ]; +extern unsigned char gstuff[0x10000 ]; + +NOMIPS16 uint128_t +foo (uint128_t i1, uint128_t i2, uint128_t i3, uint128_t i4, +uint128_t *x,unsigned char *lstuff) +{ + g[0 ] = i1; + g[1 ] = i2; + g[2 ] = i3; + g[3 ] = i4; + x[0 ] = x[4 ]; + x[1 ] =0 ; + x[2 ] = ((uint128_t )0x123456789abcdefULL <<64 ) |0xaabbccddeeff1122ULL ; + x[3 ] = g[4 ]; + x[4 ] = *(uint128_t *) (lstuff +0x7fff ); +return *(uint128_t *) (gstuff +0x7fff ); +} + +MIPS16 uint128_t +bar (uint128_t i1, uint128_t i2, uint128_t i3, uint128_t i4, +uint128_t *x,unsigned char *lstuff) +{ + g[0 ] = i1; + g[1 ] = i2; + g[2 ] = i3; + g[3 ] = i4; + x[0 ] = x[4 ]; + x[1 ] =0 ; + x[2 ] = ((uint128_t )0x123456789abcdefULL <<64 ) |0xaabbccddeeff1122ULL ; + x[3 ] = g[4 ]; + x[4 ] = *(uint128_t *) (lstuff +0x7fff ); +return *(uint128_t *) (gstuff +0x7fff ); +}
testsuite/gcc.target/mips/int-moves-2.c new file +40 -0
@@ -0,0 +1,40 @@ +/* { dg-do compile { target mips16_attribute } } */ +/* { dg-mips-options "-mgp64 -msoft-float -O2 -EB" } */ +/* { dg-add-options mips16_attribute } */ + +typedef unsigned uint128_t __attribute__((mode (TI ))); + +extern uint128_t g[16 ]; +extern unsigned char gstuff[0x10000 ]; + +NOMIPS16 uint128_t +foo (uint128_t i1, uint128_t i2, uint128_t i3, uint128_t i4, +uint128_t *x,unsigned char *lstuff) +{ + g[0 ] = i1; + g[1 ] = i2; + g[2 ] = i3; + g[3 ] = i4; + x[0 ] = x[4 ]; + x[1 ] =0 ; + x[2 ] = ((uint128_t )0x123456789abcdefULL <<64 ) |0xaabbccddeeff1122ULL ; + x[3 ] = g[4 ]; + x[4 ] = *(uint128_t *) (lstuff +0x7fff ); +return *(uint128_t *) (gstuff +0x7fff ); +} + +MIPS16 uint128_t +bar (uint128_t i1, uint128_t i2, uint128_t i3, uint128_t i4, +uint128_t *x,unsigned char *lstuff) +{ + g[0 ] = i1; + g[1 ] = i2; + g[2 ] = i3; + g[3 ] = i4; + x[0 ] = x[4 ]; + x[1 ] =0 ; + x[2 ] = ((uint128_t )0x123456789abcdefULL <<64 ) |0xaabbccddeeff1122ULL ; + x[3 ] = g[4 ]; + x[4 ] = *(uint128_t *) (lstuff +0x7fff ); +return *(uint128_t *) (gstuff +0x7fff ); +}
testsuite/gcc.target/mips/fix-r4000-1.c new file +6 -0
@@ -0,0 +1,6 @@ +/* { dg-mips-options "-march=r4000 -mfix-r4000 -O2 -dp" } */ +typedef int int32_t ; +typedef int uint32_t ; +int32_t foo (int32_t x,int32_t y) {return x * y; } +uint32_t bar (uint32_t x,uint32_t y) {return x * y; } +/* { dg-final { scan-assembler-times "[concat {\tmult\t\$[45],\$[45][^\n]+mulsi3_r4000[^\n]+\n\tmflo\t\$2\n}]" 2 } } */
testsuite/gcc.target/mips/fix-r4000-2.c new file +7 -0
@@ -0,0 +1,7 @@ +/* { dg-mips-options "-mips1 -mfix-r4000 -O2 -dp -EB" } */ +typedef int int32_t ; +typedef long long int64_t ; +int32_t foo (int32_t x,int32_t y) {return ((int64_t ) x * y) >>32 ; } +/* ??? A highpart pattern would be a better choice, but we currently +don't use them. */ +/* { dg-final { scan-assembler "[concat {\tmult\t\$[45],\$[45][^\n]+mulsidi3_32bit_r4000[^\n]+\n\tmflo\t\$3\n\tmfhi\t\$2\n}]" } } */
testsuite/gcc.target/mips/fix-r4000-3.c new file +7 -0
@@ -0,0 +1,7 @@ +/* { dg-mips-options "-mips1 -mfix-r4000 -O2 -dp -EB" } */ +typedef unsigned int uint32_t ; +typedef unsigned long long uint64_t ; +uint32_t foo (uint32_t x,uint32_t y) {return ((uint64_t ) x * y) >>32 ; } +/* ??? A highpart pattern would be a better choice, but we currently +don't use them. */ +/* { dg-final { scan-assembler "[concat {\tmultu\t\$[45],\$[45][^\n]+umulsidi3_32bit_r4000[^\n]+\n\tmflo\t\$3\n\tmfhi\t\$2\n}]" } } */
testsuite/gcc.target/mips/fix-r4000-4.c new file +8 -0
@@ -0,0 +1,8 @@ +/* ??? At the moment, lower-subreg.c decomposes the copy of the multiplication +result to $2, which prevents the register allocators from storing the +multiplication result in $2. */ +/* { dg-mips-options "-mips1 -mfix-r4000 -O2 -fno-split-wide-types -dp -EL" } */ +typedef int int32_t ; +typedef long long int64_t ; +int64_t foo (int32_t x,int32_t y) {return (int64_t ) x * y; } +/* { dg-final { scan-assembler "[concat {\tmult\t\$[45],\$[45][^\n]+mulsidi3_32bit_r4000[^\n]+\n\tmflo\t\$2\n\tmfhi\t\$3\n}]" } } */
testsuite/gcc.target/mips/fix-r4000-5.c new file +8 -0
@@ -0,0 +1,8 @@ +/* ??? At the moment, lower-subreg.c decomposes the copy of the multiplication +result to $2, which prevents the register allocators from storing the +multiplication result in $2. */ +/* { dg-mips-options "-mips1 -mfix-r4000 -O2 -fno-split-wide-types -dp -EL" } */ +typedef unsigned int uint32_t ; +typedef unsigned long long uint64_t ; +uint64_t foo (uint32_t x,uint32_t y) {return (uint64_t ) x * y; } +/* { dg-final { scan-assembler "[concat {\tmultu\t\$[45],\$[45][^\n]+umulsidi3_32bit_r4000[^\n]+\n\tmflo\t\$2\n\tmfhi\t\$3\n}]" } } */
testsuite/gcc.target/mips/fix-r4000-6.c new file +6 -0
@@ -0,0 +1,6 @@ +/* { dg-mips-options "-march=r4000 -mfix-r4000 -mgp64 -O2 -dp" } */ +typedef long long int64_t ; +typedef unsigned long long uint64_t ; +int64_t foo (int64_t x,int64_t y) {return x * y; } +uint64_t bar (uint64_t x,uint64_t y) {return x * y; } +/* { dg-final { scan-assembler-times "[concat {\tdmult\t\$[45],\$[45][^\n]+muldi3_r4000[^\n]+\n\tmflo\t\$2\n}]" 2 } } */
testsuite/gcc.target/mips/fix-r4000-7.c new file +7 -0
@@ -0,0 +1,7 @@ +/* { dg-mips-options "-march=r4000 -mfix-r4000 -O2 -mgp64 -dp -EB" } */ +typedef long long int64_t ; +typedef int int128_t __attribute__((mode (TI ))); +int64_t foo (int64_t x,int64_t y) {return ((int128_t ) x * y) >>64 ; } +/* ??? A highpart pattern would be a better choice, but we currently +don't use them. */ +/* { dg-final { scan-assembler "[concat {\tdmult\t\$[45],\$[45][^\n]+mulditi3[^\n]+\n\tmflo\t\$3\n\tmfhi\t\$2\n}]" } } */
testsuite/gcc.target/mips/fix-r4000-8.c new file +7 -0
@@ -0,0 +1,7 @@ +/* { dg-mips-options "-march=r4000 -mfix-r4000 -O2 -mgp64 -dp -EB" } */ +typedef unsigned long long uint64_t ; +typedef unsigned int uint128_t __attribute__((mode (TI ))); +uint64_t foo (uint64_t x,uint64_t y) {return ((uint128_t ) x * y) >>64 ; } +/* ??? A highpart pattern would be a better choice, but we currently +don't use them. */ +/* { dg-final { scan-assembler "[concat {\tdmultu\t\$[45],\$[45][^\n]+umulditi3[^\n]+\n\tmflo\t\$3\n\tmfhi\t\$2\n}]" } } */
testsuite/gcc.target/mips/fix-r4000-9.c new file +8 -0
@@ -0,0 +1,8 @@ +/* ??? At the moment, lower-subreg.c decomposes the copy of the multiplication +result to $2, which prevents the register allocators from storing the +multiplication result in $2. */ +/* { dg-mips-options "-mips3 -mfix-r4000 -mgp64 -O2 -fno-split-wide-types -dp -EL" } */ +typedef long long int64_t ; +typedef int int128_t __attribute__((mode (TI ))); +int128_t foo (int64_t x,int64_t y) {return (int128_t ) x * y; } +/* { dg-final { scan-assembler "[concat {\tdmult\t\$[45],\$[45][^\n]+mulditi3_r4000[^\n]+\n\tmflo\t\$2\n\tmfhi\t\$3\n}]" } } */
testsuite/gcc.target/mips/fix-r4000-10.c new file +8 -0
@@ -0,0 +1,8 @@ +/* ??? At the moment, lower-subreg.c decomposes the copy of the multiplication +result to $2, which prevents the register allocators from storing the +multiplication result in $2. */ +/* { dg-mips-options "-mips3 -mfix-r4000 -mgp64 -O2 -fno-split-wide-types -dp -EL" } */ +typedef unsigned long long uint64_t ; +typedef unsigned int uint128_t __attribute__((mode (TI ))); +uint128_t foo (uint64_t x,uint64_t y) {return (uint128_t ) x * y; } +/* { dg-final { scan-assembler "[concat {\tdmultu\t\$[45],\$[45][^\n]+umulditi3_r4000[^\n]+\n\tmflo\t\$2\n\tmfhi\t\$3\n}]" } } */
testsuite/gcc.target/mips/fix-r4000-11.c new file +4 -0
@@ -0,0 +1,4 @@ +/* { dg-mips-options "-march=r4000 -mfix-r4000 -mgp64 -O2 -dp" } */ +typedef long long int64_t ; +int64_t foo (int64_t x) {return x /11993 ; } +/* { dg-final { scan-assembler "[concat {\tdmult\t\$4,\$[0-9]+[^\n]+smuldi3_highpart[^\n]+\n\tmfhi\t\$[0-9]+\n}]" } } */
testsuite/gcc.target/mips/fix-r4000-12.c new file +4 -0
@@ -0,0 +1,4 @@ +/* { dg-mips-options "-march=r4000 -mfix-r4000 -mgp64 -O2 -dp" } */ +typedef unsigned long long uint64_t ; +uint64_t foo (uint64_t x) {return x /11993 ; } +/* { dg-final { scan-assembler "[concat {\tdmultu\t\$4,\$[0-9]+[^\n]+umuldi3_highpart[^\n]+\n\tmfhi\t\$[0-9]+\n}]" } } */
testsuite/gcc.target/mips/timode-1.c new file +65 -0
65 lines not on this page · raw message
testsuite/gcc.target/mips/timode-2.c new file +64 -0
64 lines not on this page · raw message
Quoted 2 lines · Richard Sandiford
Please shout if you find anything wrong with either the patch or the documentation changes.
Lacking the time to review your changes or at least test at the run time
(sorry!) I trust you have done a decent job as usually. Perhaps someone else can to that. Otherwise the results will come back and haunt you in some two years or suchlike when people start using this version of GCC to build the kernel. ;)
To give you an indicator -- I am still using 4.1.2 and will keep doing so
for another year or so. I may skip a version or two when I finally decide to upgrade though.
Maciej
Richard Sandiford wrote:
...
Quoted 12 lines
gcc-4.4/changes.html +12
-0+ <li>The MIPS port no longer recognizes the <code>h</code> + <code>asm</code> constraint. It was necessary to remove + this constraint in order to avoid generating unpredictable + code sequences. + + <p>One of the main uses of the <code>h</code> constraint + was to extract the high part of a multiplication on + 64-bit targets. For example:</p> + <pre> + asm ("dmultu\t%1,%2" : "=h" (result) : "r" (x), "r" (y));</pre> + <p>You can now achieve the same effect using 128-bit types:</p> + <pre>
gcc-4.4/changes.html line 53
Quoted 10 lines
gcc-4.4/changes.html +9
-0+ typedef unsigned int uint128_t __attribute__((mode(TI))); + result = ((uint128_t) x * y) >> 64;</pre> + <p>The second sequence is better in many ways. For example, + if <code>x</code> and <code>y</code> are constants, the + compiler can perform the multiplication at compile time. + If <code>x</code> and <code>y</code> are not constants, + the compiler can schedule the runtime multiplication + better than it can schedule an <code>asm</code> statement.</p> + </li> </ul>
Hi,
GLIBC contains the following code in stdlib/longlong.h:
<snip>
#if defined (__mips__) && W_TYPE_SIZE == 32 #define umul_ppmm(w1, w0, u, v) \
__asm__ ("multu %2,%3" \
: "=l" ((USItype) (w0)), \
"=h" ((USItype) (w1)) \
: "d" ((USItype) (u)), \
"d" ((USItype) (v)))#define UMUL_TIME 10
#define UDIV_TIME 100
#endif /* __mips__ */
</snip>
What would be a correct fix in this case? Something like this:
<snip>
#define umul_ppmm(w1, w0, u, v) \
({unsigned int __attribute__((mode(DI))) __xx; \
__xx = (unsigned int __attribute__((mode(DI)))) u * v; \
w0 = __xx & ((1 << 32) - 1); \
w1 = __xx >> 32;})</snip>
Or is there a better way?
Thanks,
Maxim
Quoted 16 lines · Maxim Kuvyrkov
GLIBC contains the following code in
stdlib/longlong.h:
<snip>
#if defined (__mips__) &&W_TYPE_SIZE== 32#define umul_ppmm(w1, w0, u, v) \ __asm__ ("multu %2,%3" \ : "=l" ((USItype) (w0)), \ "=h" ((USItype) (w1)) \ : "d" ((USItype) (u)), \ "d" ((USItype) (v)))#define
UMUL_TIME10
#defineUDIV_TIME100
#endif /*__mips__*/
</snip>What would be a correct fix in this case? Something like this:
<snip>
Quoted 8 lines
#define umul_ppmm(w1, w0, u, v) \ ({unsigned int __attribute__((mode(DI))) __xx; \ __xx = (unsigned int __attribute__((mode(DI)))) u * v; \ w0 = __xx & ((1 << 32) - 1); \ w1 = __xx >> 32;})</snip>
Or is there a better way?
All being well, you should just be able to do the same as I did for GCC's copy of longlong.h (included in the patch you responded to).
Richard
Quoted 9 lines
GLIBC contains the following code in
stdlib/longlong.h:
<snip>
#if defined (__mips__) &&W_TYPE_SIZE== 32 #defineumul_ppmm(w1, w0, u, v)\__asm__ ("multu %2,%3" \ : "=l" ((USItype) (w0)), \ "=h" ((USItype) (w1)) \ : "d" ((USItype) (u)), \ "d" ((USItype) (v)))
Quoted 4 lines
#define
UMUL_TIME10
#defineUDIV_TIME100
#endif /*__mips__*/
</snip>
Actually, so does GCC itself. Can you prepare a patch?
Quoted 10 lines
What would be a correct fix in this case? Something like this:
<snip>
#defineumul_ppmm(w1, w0, u, v)\({unsigned int __attribute__((mode(DI))) __xx; \ __xx = (unsigned int __attribute__((mode(DI)))) u * v; \ w0 = __xx & ((1 << 32) - 1); \ w1 = __xx >> 32;})</snip>
Or is there a better way?
Almost; this:
#define umul_ppmm(w1, w0, u, v) \
({UDWtype __xx; \
UWtype __u = (u), __v = (v); \
__xx = (UDWtype) __u * __v; \
w0 = (UWtype) __xx; \
w1 = __xx >> 32;})should work.
Paolo