Andreas Klebinger pushed to branch wip/andreask/arm-ffi at Glasgow Haskell Compiler / GHC
Commits:
-
d033b028
by Andreas Klebinger at 2026-07-03T12:36:27+02:00
-
035094c1
by Andreas Klebinger at 2026-07-03T12:37:39+02:00
-
294c6098
by Andreas Klebinger at 2026-07-03T12:40:02+02:00
-
3faf1eb0
by Andreas Klebinger at 2026-07-03T12:40:52+02:00
5 changed files:
- compiler/GHC/Cmm/Expr.hs
- + testsuite/tests/codeGen/should_run/T27430.hs
- + testsuite/tests/codeGen/should_run/T27430.stdout
- + testsuite/tests/codeGen/should_run/T27430_c.c
- testsuite/tests/codeGen/should_run/all.T
Changes:
| ... | ... | @@ -443,6 +443,11 @@ pprExpr platform e |
| 443 | 443 | CmmLit lit -> pprLit platform lit
|
| 444 | 444 | _other -> pprExpr1 platform e
|
| 445 | 445 | |
| 446 | +-- `exp` usually, but (expr[width]) with -dppr-debug
|
|
| 447 | +withDebugWidth :: Width -> SDoc -> SDoc
|
|
| 448 | +withDebugWidth w exp =
|
|
| 449 | + ifPprDebug (parens (exp <> brackets (ppr w))) exp
|
|
| 450 | + |
|
| 446 | 451 | -- Here's the precedence table from GHC.Cmm.Parser:
|
| 447 | 452 | -- %nonassoc '>=' '>' '<=' '<' '!=' '=='
|
| 448 | 453 | -- %left '|'
|
| ... | ... | @@ -465,15 +470,17 @@ pprExpr1 platform e = pprExpr7 platform e |
| 465 | 470 | |
| 466 | 471 | infixMachOp1, infixMachOp7, infixMachOp8 :: MachOp -> Maybe SDoc
|
| 467 | 472 | |
| 468 | -infixMachOp1 (MO_Eq _) = Just (text "==")
|
|
| 469 | -infixMachOp1 (MO_Ne _) = Just (text "!=")
|
|
| 470 | -infixMachOp1 (MO_Shl _) = Just (text "<<")
|
|
| 471 | -infixMachOp1 (MO_U_Shr _) = Just (text ">>")
|
|
| 472 | -infixMachOp1 (MO_U_Ge _) = Just (text ">=")
|
|
| 473 | -infixMachOp1 (MO_U_Le _) = Just (text "<=")
|
|
| 474 | -infixMachOp1 (MO_U_Gt _) = Just (char '>')
|
|
| 475 | -infixMachOp1 (MO_U_Lt _) = Just (char '<')
|
|
| 476 | -infixMachOp1 _ = Nothing
|
|
| 473 | +infixMachOp1 mop = case mop of
|
|
| 474 | + (MO_Eq w) -> Just $ withDebugWidth w (text "==")
|
|
| 475 | + (MO_Ne w) -> Just $ withDebugWidth w (text "!=")
|
|
| 476 | + (MO_Shl w) -> Just $ withDebugWidth w (text "<<")
|
|
| 477 | + (MO_U_Shr w) -> Just $ withDebugWidth w (text ">>")
|
|
| 478 | + (MO_U_Ge w) -> Just $ withDebugWidth w (text ">=")
|
|
| 479 | + (MO_U_Le w) -> Just $ withDebugWidth w (text "<=")
|
|
| 480 | + (MO_U_Gt w) -> Just $ withDebugWidth w (char '>')
|
|
| 481 | + (MO_U_Lt w) -> Just $ withDebugWidth w (char '<')
|
|
| 482 | + _ -> Nothing
|
|
| 483 | + where
|
|
| 477 | 484 | |
| 478 | 485 | -- %left '-' '+'
|
| 479 | 486 | pprExpr7 platform (CmmMachOp (MO_Add rep1) [x, CmmLit (CmmInt i rep2)]) | i < 0
|
| ... | ... | @@ -483,8 +490,8 @@ pprExpr7 platform (CmmMachOp op [x,y]) |
| 483 | 490 | = pprExpr7 platform x <+> doc <+> pprExpr8 platform y
|
| 484 | 491 | pprExpr7 platform e = pprExpr8 platform e
|
| 485 | 492 | |
| 486 | -infixMachOp7 (MO_Add _) = Just (char '+')
|
|
| 487 | -infixMachOp7 (MO_Sub _) = Just (char '-')
|
|
| 493 | +infixMachOp7 (MO_Add w) = Just $ withDebugWidth w (char '+')
|
|
| 494 | +infixMachOp7 (MO_Sub w) = Just $ withDebugWidth w (char '-')
|
|
| 488 | 495 | infixMachOp7 _ = Nothing
|
| 489 | 496 | |
| 490 | 497 | -- %left '/' '*' '%'
|
| ... | ... | @@ -493,9 +500,9 @@ pprExpr8 platform (CmmMachOp op [x,y]) |
| 493 | 500 | = pprExpr8 platform x <+> doc <+> pprExpr9 platform y
|
| 494 | 501 | pprExpr8 platform e = pprExpr9 platform e
|
| 495 | 502 | |
| 496 | -infixMachOp8 (MO_U_Quot _) = Just (char '/')
|
|
| 497 | -infixMachOp8 (MO_Mul _) = Just (char '*')
|
|
| 498 | -infixMachOp8 (MO_U_Rem _) = Just (char '%')
|
|
| 503 | +infixMachOp8 (MO_U_Quot w) = Just $ withDebugWidth w (char '/')
|
|
| 504 | +infixMachOp8 (MO_Mul w) = Just $ withDebugWidth w (char '*')
|
|
| 505 | +infixMachOp8 (MO_U_Rem w) = Just $ withDebugWidth w (char '%')
|
|
| 499 | 506 | infixMachOp8 _ = Nothing
|
| 500 | 507 | |
| 501 | 508 | pprExpr9 :: Platform -> CmmExpr -> SDoc
|
| 1 | +{-# LANGUAGE MagicHash #-}
|
|
| 2 | +{-# OPTIONS_GHC -dno-typeable-binds -ddump-to-file -dsuppress-ticks -dsuppress-timestamps -ddump-stg-from-core -ddump-stg-final -ddump-cmm -ddump-cmm-raw -ddump-asm #-}
|
|
| 3 | + |
|
| 4 | +import GHC.Exts
|
|
| 5 | +import Data.Bits
|
|
| 6 | +import GHC.Word
|
|
| 7 | + |
|
| 8 | +foreign import ccall unsafe "u64_to_u8" u64_to_u8 :: Word64 -> Word8
|
|
| 9 | +foreign import ccall unsafe "u64_to_u16" u64_to_u16 :: Word64 -> Word16
|
|
| 10 | +foreign import ccall unsafe "u64_to_u32" u64_to_u32 :: Word64 -> Word32
|
|
| 11 | + |
|
| 12 | +x :: Word64
|
|
| 13 | +x = 5
|
|
| 14 | + |
|
| 15 | +-- Those should give just x when truncated.
|
|
| 16 | +y8,y16,y32 :: Word64
|
|
| 17 | +y8 = setBit x 8
|
|
| 18 | +y16 = setBit x 16
|
|
| 19 | +y32 = setBit x 32
|
|
| 20 | + |
|
| 21 | +eq8 :: Word8 -> Word8 -> Int
|
|
| 22 | +eq8 (W8# a) (W8# b) = I# (eqWord8# a b)
|
|
| 23 | + |
|
| 24 | +eq16 :: Word16 -> Word16 -> Int
|
|
| 25 | +eq16 (W16# a) (W16# b) = I# (eqWord16# a b)
|
|
| 26 | + |
|
| 27 | +eq32 :: Word32 -> Word32 -> Int
|
|
| 28 | +eq32 (W32# a) (W32# b) = I# (eqWord32# a b)
|
|
| 29 | + |
|
| 30 | +{-# NOINLINE outline_eq8 #-}
|
|
| 31 | +outline_eq8 = eq8
|
|
| 32 | +{-# NOINLINE outline_eq16 #-}
|
|
| 33 | +outline_eq16 = eq16
|
|
| 34 | +{-# NOINLINE outline_eq32 #-}
|
|
| 35 | +outline_eq32 = eq32
|
|
| 36 | + |
|
| 37 | +main :: IO ()
|
|
| 38 | +main = do
|
|
| 39 | + print (eq8 (u64_to_u8 x) (u64_to_u8 y8))
|
|
| 40 | + print (eq16 (u64_to_u16 x) (u64_to_u16 y16))
|
|
| 41 | + print (eq32 (u64_to_u32 x) (u64_to_u32 y32))
|
|
| 42 | + |
|
| 43 | + print (outline_eq8 (u64_to_u8 x) (u64_to_u8 y8))
|
|
| 44 | + print (outline_eq16 (u64_to_u16 x) (u64_to_u16 y16))
|
|
| 45 | + print (outline_eq32 (u64_to_u32 x) (u64_to_u32 y32)) |
| 1 | +1
|
|
| 2 | +1
|
|
| 3 | +1
|
|
| 4 | +1
|
|
| 5 | +1
|
|
| 6 | +1 |
| 1 | +#include <stdint.h>
|
|
| 2 | + |
|
| 3 | +uint8_t u64_to_u8(uint64_t v) { return (uint8_t)v; }
|
|
| 4 | +uint8_t u64_to_u16(uint64_t v) { return (uint16_t)v; }
|
|
| 5 | +uint8_t u64_to_u32(uint64_t v) { return (uint32_t)v; } |
| ... | ... | @@ -295,3 +295,5 @@ test('aarch64-sxtw-run', |
| 295 | 295 | when(unregisterised(), skip)],
|
| 296 | 296 | multi_compile_and_run,
|
| 297 | 297 | ['aarch64-sxtw-run', [('aarch64-sxtw-cmm.cmm', '')], '-O'])
|
| 298 | + |
|
| 299 | +test('T27430', [req_c], compile_and_run, ['T27430_c.c']) |