Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC

Commits:

3 changed files:

Changes:

  • compiler/GHC/CmmToC.hs
    ... ... @@ -426,7 +426,7 @@ pprMachOpApp :: Platform -> MachOp -> [CmmExpr] -> SDoc
    426 426
     
    
    427 427
     pprMachOpApp platform op args
    
    428 428
       | isMulMayOfloOp op
    
    429
    -  = text "mulIntMayOflo" <> parens (commafy (map (pprExpr platform) args))
    
    429
    +  = text "hs_mulIntMayOflo" <> parens (commafy (map (pprExpr platform) args))
    
    430 430
       where isMulMayOfloOp (MO_S_MulMayOflo _) = True
    
    431 431
             isMulMayOfloOp _ = False
    
    432 432
     
    

  • rts/include/Stg.h
    ... ... @@ -519,79 +519,3 @@ INLINE_HEADER StgInt64 PK_Int64(W_ p_src[])
    519 519
     }
    
    520 520
     
    
    521 521
     #endif /* SIZEOF_HSWORD == 4 */
    522
    -
    
    523
    -/* -----------------------------------------------------------------------------
    
    524
    -   Integer multiply with overflow
    
    525
    -   -------------------------------------------------------------------------- */
    
    526
    -
    
    527
    -/* Multiply with overflow checking.
    
    528
    - *
    
    529
    - * This is tricky - the usual sign rules for add/subtract don't apply.
    
    530
    - *
    
    531
    - * On 32-bit machines we use gcc's 'long long' types, finding
    
    532
    - * overflow with some careful bit-twiddling.
    
    533
    - *
    
    534
    - * On 64-bit machines where gcc's 'long long' type is also 64-bits,
    
    535
    - * we use a crude approximation, testing whether either operand is
    
    536
    - * larger than 32-bits; if neither is, then we go ahead with the
    
    537
    - * multiplication.
    
    538
    - *
    
    539
    - * Return non-zero if there is any possibility that the signed multiply
    
    540
    - * of a and b might overflow.  Return zero only if you are absolutely sure
    
    541
    - * that it won't overflow.  If in doubt, return non-zero.
    
    542
    - */
    
    543
    -
    
    544
    -#if SIZEOF_VOID_P == 4
    
    545
    -
    
    546
    -#if defined(WORDS_BIGENDIAN)
    
    547
    -#define RTS_CARRY_IDX__ 0
    
    548
    -#define RTS_REM_IDX__  1
    
    549
    -#else
    
    550
    -#define RTS_CARRY_IDX__ 1
    
    551
    -#define RTS_REM_IDX__ 0
    
    552
    -#endif
    
    553
    -
    
    554
    -typedef union {
    
    555
    -    StgInt64 l;
    
    556
    -    StgInt32 i[2];
    
    557
    -} long_long_u ;
    
    558
    -
    
    559
    -#define mulIntMayOflo(a,b)       \
    
    560
    -({                                              \
    
    561
    -  StgInt32 r, c;           \
    
    562
    -  long_long_u z;           \
    
    563
    -  z.l = (StgInt64)a * (StgInt64)b;     \
    
    564
    -  r = z.i[RTS_REM_IDX__];        \
    
    565
    -  c = z.i[RTS_CARRY_IDX__];         \
    
    566
    -  if (c == 0 || c == -1) {       \
    
    567
    -    c = ((StgWord)((a^b) ^ r))         \
    
    568
    -      >> (BITS_IN (I_) - 1);        \
    
    569
    -  }                  \
    
    570
    -  c;                                            \
    
    571
    -})
    
    572
    -
    
    573
    -/* Careful: the carry calculation above is extremely delicate.  Make sure
    
    574
    - * you test it thoroughly after changing it.
    
    575
    - */
    
    576
    -
    
    577
    -#else
    
    578
    -
    
    579
    -/* Approximate version when we don't have long arithmetic (on 64-bit archs) */
    
    580
    -
    
    581
    -/* If we have n-bit words then we have n-1 bits after accounting for the
    
    582
    - * sign bit, so we can fit the result of multiplying 2 (n-1)/2-bit numbers */
    
    583
    -#define HALF_POS_INT  (((I_)1) << ((BITS_IN (I_) - 1) / 2))
    
    584
    -#define HALF_NEG_INT  (-HALF_POS_INT)
    
    585
    -
    
    586
    -#define mulIntMayOflo(a,b)       \
    
    587
    -({                                              \
    
    588
    -  I_ c;              \
    
    589
    -  if ((I_)a <= HALF_NEG_INT || a >= HALF_POS_INT    \
    
    590
    -      || (I_)b <= HALF_NEG_INT || b >= HALF_POS_INT) {\
    
    591
    -    c = 1;              \
    
    592
    -  } else {              \
    
    593
    -    c = 0;              \
    
    594
    -  }                  \
    
    595
    -  c;                                            \
    
    596
    -})
    
    597
    -#endif

  • rts/prim/mulIntMayOflo.c
    1 1
     #include "Rts.h"
    
    2 2
     
    
    3
    -W_ hs_mulIntMayOflo(W_ a, W_ b) { return mulIntMayOflo(a, b); }
    3
    +W_ hs_mulIntMayOflo(W_ a, W_ b) {
    
    4
    +  I_ r;
    
    5
    +  return (W_)__builtin_mul_overflow((I_)a, (I_)b, &r);
    
    6
    +}