Sven Tennie pushed to branch wip/supersven/fix-foundation-test-shift-amounts at Glasgow Haskell Compiler / GHC

Commits:

2 changed files:

Changes:

  • compiler/GHC/Builtin/primops.txt.pp
    ... ... @@ -148,6 +148,7 @@ defaults
    148 148
        vector           = []
    
    149 149
        deprecated_msg   = {}      -- A non-empty message indicates deprecation
    
    150 150
        div_like         = False   -- Second argument expected to be non zero - used for tests
    
    151
    +   shift_like       = False   -- Second argument expected to be atmost first argument's word size -1 - used for tests
    
    151 152
        defined_bits     = Nothing -- The number of bits the operation is defined for (if not all bits)
    
    152 153
     
    
    153 154
     -- Note [When do out-of-line primops go in primops.txt.pp]
    
    ... ... @@ -312,8 +313,16 @@ primop Int8QuotRemOp "quotRemInt8#" GenPrimOp Int8# -> Int8# -> (# Int8#, Int8#
    312 313
         div_like = True
    
    313 314
     
    
    314 315
     primop Int8SllOp "uncheckedShiftLInt8#"  GenPrimOp Int8# -> Int# -> Int8#
    
    316
    +  with
    
    317
    +    shift_like = True
    
    318
    +
    
    315 319
     primop Int8SraOp "uncheckedShiftRAInt8#" GenPrimOp Int8# -> Int# -> Int8#
    
    320
    +  with
    
    321
    +    shift_like = True
    
    322
    +
    
    316 323
     primop Int8SrlOp "uncheckedShiftRLInt8#" GenPrimOp Int8# -> Int# -> Int8#
    
    324
    +  with
    
    325
    +    shift_like = True
    
    317 326
     
    
    318 327
     primop Int8ToWord8Op "int8ToWord8#" GenPrimOp Int8# -> Word8#
    
    319 328
        with code_size = 0
    
    ... ... @@ -372,7 +381,12 @@ primop Word8XorOp "xorWord8#" GenPrimOp Word8# -> Word8# -> Word8#
    372 381
     primop Word8NotOp "notWord8#" GenPrimOp Word8# -> Word8#
    
    373 382
     
    
    374 383
     primop Word8SllOp "uncheckedShiftLWord8#"  GenPrimOp Word8# -> Int# -> Word8#
    
    384
    +  with
    
    385
    +    shift_like = True
    
    386
    +
    
    375 387
     primop Word8SrlOp "uncheckedShiftRLWord8#" GenPrimOp Word8# -> Int# -> Word8#
    
    388
    +  with
    
    389
    +    shift_like = True
    
    376 390
     
    
    377 391
     primop Word8ToInt8Op "word8ToInt8#" GenPrimOp Word8# -> Int8#
    
    378 392
        with code_size = 0
    
    ... ... @@ -422,8 +436,16 @@ primop Int16QuotRemOp "quotRemInt16#" GenPrimOp Int16# -> Int16# -> (# Int16#, I
    422 436
         div_like = True
    
    423 437
     
    
    424 438
     primop Int16SllOp "uncheckedShiftLInt16#"  GenPrimOp Int16# -> Int# -> Int16#
    
    439
    +  with
    
    440
    +    shift_like = True
    
    441
    +
    
    425 442
     primop Int16SraOp "uncheckedShiftRAInt16#" GenPrimOp Int16# -> Int# -> Int16#
    
    443
    +  with
    
    444
    +    shift_like = True
    
    445
    +
    
    426 446
     primop Int16SrlOp "uncheckedShiftRLInt16#" GenPrimOp Int16# -> Int# -> Int16#
    
    447
    +  with
    
    448
    +    shift_like = True
    
    427 449
     
    
    428 450
     primop Int16ToWord16Op "int16ToWord16#" GenPrimOp Int16# -> Word16#
    
    429 451
        with code_size = 0
    
    ... ... @@ -482,7 +504,12 @@ primop Word16XorOp "xorWord16#" GenPrimOp Word16# -> Word16# -> Word16#
    482 504
     primop Word16NotOp "notWord16#" GenPrimOp Word16# -> Word16#
    
    483 505
     
    
    484 506
     primop Word16SllOp "uncheckedShiftLWord16#"  GenPrimOp Word16# -> Int# -> Word16#
    
    507
    +  with
    
    508
    +    shift_like = True
    
    509
    +
    
    485 510
     primop Word16SrlOp "uncheckedShiftRLWord16#" GenPrimOp Word16# -> Int# -> Word16#
    
    511
    +  with
    
    512
    +    shift_like = True
    
    486 513
     
    
    487 514
     primop Word16ToInt16Op "word16ToInt16#" GenPrimOp Word16# -> Int16#
    
    488 515
        with code_size = 0
    
    ... ... @@ -532,8 +559,16 @@ primop Int32QuotRemOp "quotRemInt32#" GenPrimOp Int32# -> Int32# -> (# Int32#, I
    532 559
         div_like = True
    
    533 560
     
    
    534 561
     primop Int32SllOp "uncheckedShiftLInt32#"  GenPrimOp Int32# -> Int# -> Int32#
    
    562
    +  with
    
    563
    +    shift_like = True
    
    564
    +
    
    535 565
     primop Int32SraOp "uncheckedShiftRAInt32#" GenPrimOp Int32# -> Int# -> Int32#
    
    566
    +  with
    
    567
    +    shift_like = True
    
    568
    +
    
    536 569
     primop Int32SrlOp "uncheckedShiftRLInt32#" GenPrimOp Int32# -> Int# -> Int32#
    
    570
    +  with
    
    571
    +    shift_like = True
    
    537 572
     
    
    538 573
     primop Int32ToWord32Op "int32ToWord32#" GenPrimOp Int32# -> Word32#
    
    539 574
        with code_size = 0
    
    ... ... @@ -592,7 +627,12 @@ primop Word32XorOp "xorWord32#" GenPrimOp Word32# -> Word32# -> Word32#
    592 627
     primop Word32NotOp "notWord32#" GenPrimOp Word32# -> Word32#
    
    593 628
     
    
    594 629
     primop Word32SllOp "uncheckedShiftLWord32#"  GenPrimOp Word32# -> Int# -> Word32#
    
    630
    +  with
    
    631
    +    shift_like = True
    
    632
    +
    
    595 633
     primop Word32SrlOp "uncheckedShiftRLWord32#" GenPrimOp Word32# -> Int# -> Word32#
    
    634
    +  with
    
    635
    +    shift_like = True
    
    596 636
     
    
    597 637
     primop Word32ToInt32Op "word32ToInt32#" GenPrimOp Word32# -> Int32#
    
    598 638
        with code_size = 0
    
    ... ... @@ -637,8 +677,16 @@ primop Int64RemOp "remInt64#" GenPrimOp Int64# -> Int64# -> Int64#
    637 677
         div_like = True
    
    638 678
     
    
    639 679
     primop Int64SllOp "uncheckedIShiftL64#"  GenPrimOp Int64# -> Int# -> Int64#
    
    680
    +  with
    
    681
    +    shift_like = True
    
    682
    +
    
    640 683
     primop Int64SraOp "uncheckedIShiftRA64#" GenPrimOp Int64# -> Int# -> Int64#
    
    684
    +  with
    
    685
    +    shift_like = True
    
    686
    +
    
    641 687
     primop Int64SrlOp "uncheckedIShiftRL64#" GenPrimOp Int64# -> Int# -> Int64#
    
    688
    +  with
    
    689
    +    shift_like = True
    
    642 690
     
    
    643 691
     primop Int64ToWord64Op "int64ToWord64#" GenPrimOp Int64# -> Word64#
    
    644 692
        with code_size = 0
    
    ... ... @@ -692,7 +740,12 @@ primop Word64XorOp "xor64#" GenPrimOp Word64# -> Word64# -> Word64#
    692 740
     primop Word64NotOp "not64#" GenPrimOp Word64# -> Word64#
    
    693 741
     
    
    694 742
     primop Word64SllOp "uncheckedShiftL64#"  GenPrimOp Word64# -> Int# -> Word64#
    
    743
    +  with
    
    744
    +    shift_like = True
    
    745
    +
    
    695 746
     primop Word64SrlOp "uncheckedShiftRL64#" GenPrimOp Word64# -> Int# -> Word64#
    
    747
    +  with
    
    748
    +    shift_like = True
    
    696 749
     
    
    697 750
     primop Word64ToInt64Op "word64ToInt64#" GenPrimOp Word64# -> Int64#
    
    698 751
        with code_size = 0
    
    ... ... @@ -865,12 +918,20 @@ primop WordToDoubleOp "word2Double#" GenPrimOp Word# -> Double#
    865 918
     primop   IntSllOp   "uncheckedIShiftL#" GenPrimOp  Int# -> Int# -> Int#
    
    866 919
              {Shift left.  Result undefined if shift amount is not
    
    867 920
               in the range 0 to word size - 1 inclusive.}
    
    921
    +  with
    
    922
    +    shift_like = True
    
    923
    +
    
    868 924
     primop   IntSraOp   "uncheckedIShiftRA#" GenPrimOp Int# -> Int# -> Int#
    
    869 925
              {Shift right arithmetic.  Result undefined if shift amount is not
    
    870 926
               in the range 0 to word size - 1 inclusive.}
    
    927
    +  with
    
    928
    +    shift_like = True
    
    929
    +
    
    871 930
     primop   IntSrlOp   "uncheckedIShiftRL#" GenPrimOp Int# -> Int# -> Int#
    
    872 931
              {Shift right logical.  Result undefined if shift amount is not
    
    873 932
               in the range 0 to word size - 1 inclusive.}
    
    933
    +  with
    
    934
    +    shift_like = True
    
    874 935
     
    
    875 936
     ------------------------------------------------------------------------
    
    876 937
     section "Word#"
    
    ... ... @@ -946,9 +1007,14 @@ primop WordNotOp "not#" GenPrimOp Word# -> Word#
    946 1007
     primop   WordSllOp   "uncheckedShiftL#"   GenPrimOp   Word# -> Int# -> Word#
    
    947 1008
              {Shift left logical.   Result undefined if shift amount is not
    
    948 1009
               in the range 0 to word size - 1 inclusive.}
    
    1010
    +  with
    
    1011
    +    shift_like = True
    
    1012
    +
    
    949 1013
     primop   WordSrlOp   "uncheckedShiftRL#"   GenPrimOp   Word# -> Int# -> Word#
    
    950 1014
              {Shift right logical.   Result undefined if shift  amount is not
    
    951 1015
               in the range 0 to word size - 1 inclusive.}
    
    1016
    +  with
    
    1017
    +    shift_like = True
    
    952 1018
     
    
    953 1019
     primop   WordToIntOp   "word2Int#"   GenPrimOp   Word# -> Int#
    
    954 1020
        with code_size = 0
    

  • utils/genprimopcode/Syntax.hs
    ... ... @@ -54,23 +54,23 @@ is_primtype (PrimTypeSpec {}) = True
    54 54
     is_primtype _ = False
    
    55 55
     
    
    56 56
     is_divLikeOp :: Entry -> Bool
    
    57
    -is_divLikeOp entry = case entry of
    
    58
    -   PrimOpSpec{} -> has_div_like
    
    59
    -   PseudoOpSpec{} -> has_div_like
    
    60
    -   PrimVecOpSpec{} -> has_div_like
    
    61
    -   PrimTypeSpec{} -> False
    
    62
    -   PrimVecTypeSpec{} -> False
    
    63
    -   Section{} -> False
    
    64
    -   where
    
    65
    -      has_div_like = case lookup_attrib "div_like" (opts entry) of
    
    66
    -         Just (OptionTrue{}) -> True
    
    67
    -         _ -> False
    
    57
    +is_divLikeOp = is_likeOp "div_like"
    
    68 58
     
    
    69 59
     is_shiftLikeOp :: Entry -> Bool
    
    70
    -is_shiftLikeOp (PrimOpSpec {name = n}) = "Shift" `Data.List.isInfixOf` n
    
    71
    -is_shiftLikeOp (PseudoOpSpec {name = n}) = "Shift" `Data.List.isInfixOf` n
    
    72
    -is_shiftLikeOp (PrimVecOpSpec {name = n}) = "Shift" `Data.List.isInfixOf` n
    
    73
    -is_shiftLikeOp _ = False
    
    60
    +is_shiftLikeOp = is_likeOp "shift_like"
    
    61
    +
    
    62
    +is_likeOp :: String -> Entry -> Bool
    
    63
    +is_likeOp attrName entry = case entry of
    
    64
    +  PrimOpSpec {} -> has_attr
    
    65
    +  PseudoOpSpec {} -> has_attr
    
    66
    +  PrimVecOpSpec {} -> has_attr
    
    67
    +  PrimTypeSpec {} -> False
    
    68
    +  PrimVecTypeSpec {} -> False
    
    69
    +  Section {} -> False
    
    70
    +  where
    
    71
    +    has_attr = case lookup_attrib attrName (opts entry) of
    
    72
    +      Just (OptionTrue {}) -> True
    
    73
    +      _ -> False
    
    74 74
     
    
    75 75
     -- a binding of property to value
    
    76 76
     data Option