Admin message

Due to a large amount of spam we do not allow new users to create repositories, they are "external" users. If you are a new user and want to create a repository, for example for forking GHC, open a new issue on ghc/ghc using the "get-verified" issue template

RISC-V NCG: `truncate` does not truncate
## Summary On RISC-V NCG, `truncate` rounds to the nearest integer, instead of rounding toward zero. ## Steps to reproduce Run `arith005`. The lines K, M, R, T are wrong. ``` $ ghc -fforce-recomp -O testsuite/tests/numeric/should_run/arith005.hs $ testsuite/tests/numeric/should_run/arith005 A[0.0,-0.0,1.1,2.8,3.5,4.5,-1.0,-2.9999995,-3.5,-4.5,1000012.0,123.456,100.25,102.5,1.2e-3,-1.2e-7,17000.0,-1.7e-4,1.5e-7,3.1415927,1.18088e11,1.2111e14] B[0.0,-0.0,1.1,2.8,3.5,4.5,-1.0000000001,-2.9999995,-3.50000000001,-4.49999999999,1000012.0,123.456,100.25,102.5,1.2e-3,-1.2e-7,17000.0,-1.7e-4,1.5e-7,3.141592653589793,1.18088e11,1.2111e14] C[0,0,2,3,4,5,-1,-2,-3,-4,1000012,124,101,103,1,0,17000,0,1,4] D[0,0,2,3,4,5,-1,-2,-3,-4,1000012,124,101,103,1,0,17000,0,1,4,118087999488,121109999517696] E[0,0,2,3,4,5,-1,-2,-3,-4,1000012,124,101,103,1,0,17000,0,1,4] F[0,0,2,3,4,5,-1,-2,-3,-4,1000012,124,101,103,1,0,17000,0,1,4,118088000000,121110000000000] G[0,0,1,2,3,4,-1,-3,-4,-5,1000012,123,100,102,0,-1,17000,-1,0,3] H[0,0,1,2,3,4,-1,-3,-4,-5,1000012,123,100,102,0,-1,17000,-1,0,3,118087999488,121109999517696] I[0,0,1,2,3,4,-2,-3,-4,-5,1000012,123,100,102,0,-1,17000,-1,0,3] J[0,0,1,2,3,4,-2,-3,-4,-5,1000012,123,100,102,0,-1,17000,-1,0,3,118088000000,121110000000000] K[0,0,1,3,4,4,-1,-3,-4,-4,1000012,123,100,102,0,0,17000,0,0,3] L[0,0,1,2,3,4,-1,-2,-3,-4,1000012,123,100,102,0,0,17000,0,0,3,118087999488,121109999517696] M[0,0,1,3,4,4,-1,-3,-4,-4,1000012,123,100,102,0,0,17000,0,0,3] N[0,0,1,2,3,4,-1,-2,-3,-4,1000012,123,100,102,0,0,17000,0,0,3,118088000000,121110000000000] n[0,0,1,3,4,4,-1,-3,-4,-4,1000012,123,100,102,0,0,17000,0,0,3] O[0,0,1,3,4,4,-1,-3,-4,-4,1000012,123,100,102,0,0,17000,0,0,3,118087999488,121109999517696] P[0,0,1,3,4,4,-1,-3,-4,-4,1000012,123,100,102,0,0,17000,0,0,3] Q[0,0,1,3,4,4,-1,-3,-4,-4,1000012,123,100,102,0,0,17000,0,0,3,118088000000,121110000000000] R[(0,0.0),(0,0.0),(1,0.100000024),(3,-0.20000005),(4,-0.5),(4,0.5),(-1,0.0),(-3,4.7683716e-7),(-4,0.5),(-4,-0.5),(1000012,0.0),(123,0.45600128),(100,0.25),(102,0.5),(0,1.2e-3),(0,-1.2e-7),(17000,0.0),(0,-1.7e-4),(0,1.5e-7),(3,0.14159274)] S[(0,0.0),(0,0.0),(1,0.100000024),(2,0.79999995),(3,0.5),(4,0.5),(-1,0.0),(-2,-0.9999995),(-3,-0.5),(-4,-0.5),(1000012,0.0),(123,0.45600128),(100,0.25),(102,0.5),(0,1.2e-3),(0,-1.2e-7),(17000,0.0),(0,-1.7e-4),(0,1.5e-7),(3,0.14159274),(118087999488,0.0),(121109999517696,0.0)] T[(0,0.0),(0,0.0),(1,0.10000000000000009),(3,-0.20000000000000018),(4,-0.5),(4,0.5),(-1,-1.000000082740371e-10),(-3,5.00000000069889e-7),(-4,0.49999999999),(-4,-0.49999999999),(1000012,0.0),(123,0.45600000000000307),(100,0.25),(102,0.5),(0,1.2e-3),(0,-1.2e-7),(17000,0.0),(0,-1.7e-4),(0,1.5e-7),(3,0.14159265358979312)] U[(0,0.0),(0,0.0),(1,0.10000000000000009),(2,0.7999999999999998),(3,0.5),(4,0.5),(-1,-1.000000082740371e-10),(-2,-0.9999994999999999),(-3,-0.50000000001),(-4,-0.49999999999),(1000012,0.0),(123,0.45600000000000307),(100,0.25),(102,0.5),(0,1.2e-3),(0,-1.2e-7),(17000,0.0),(0,-1.7e-4),(0,1.5e-7),(3,0.14159265358979312),(118088000000,0.0),(121110000000000,0.0)] ``` Another, simpler reproducer: ```haskell import Data.Int main :: IO () main = do print $ map (truncate :: Float -> Int32) [0.0,0.25..2.0] print $ map (round :: Float -> Int32) [0.0,0.25..2.0] print $ map (truncate :: Double -> Int32) [0.0,0.25..2.0] print $ map (round :: Double -> Int32) [0.0,0.25..2.0] print $ map (truncate :: Float -> Int64) [0.0,0.25..2.0] print $ map (round :: Float -> Int64) [0.0,0.25..2.0] print $ map (truncate :: Double -> Int64) [0.0,0.25..2.0] print $ map (round :: Double -> Int64) [0.0,0.25..2.0] print $ map (truncate :: Float -> Integer) [0.0,0.25..2.0] print $ map (round :: Float -> Integer) [0.0,0.25..2.0] print $ map (truncate :: Double -> Integer) [0.0,0.25..2.0] print $ map (round :: Double -> Integer) [0.0,0.25..2.0] ``` ``` $ ghc -fforce-recomp -O truncate_test.hs $ ./truncate_test [0,0,0,1,1,1,2,2,2] [0,0,0,1,1,1,2,2,2] [0,0,0,1,1,1,2,2,2] [0,0,0,1,1,1,2,2,2] [0,0,0,1,1,1,2,2,2] [0,0,0,1,1,1,2,2,2] [0,0,0,1,1,1,2,2,2] [0,0,0,1,1,1,2,2,2] [0,0,0,0,1,1,1,1,2] [0,0,0,1,1,1,2,2,2] [0,0,0,0,1,1,1,1,2] [0,0,0,1,1,1,2,2,2] ``` ## Expected behavior The LLVM backend does it right, unless GHC's optimizer is buggy. ``` $ ghc -fforce-recomp -fllvm -O truncate_test.hs $ ./truncate_test [0,0,0,0,1,1,1,1,2] [0,0,0,1,1,1,2,2,2] [0,0,0,0,1,1,1,1,2] [0,0,0,1,1,1,2,2,2] [0,0,0,0,1,1,1,1,2] [0,0,0,1,1,1,2,2,2] [0,0,0,0,1,1,1,1,2] [0,0,0,1,1,1,2,2,2] [0,0,0,0,1,1,1,1,2] [0,0,0,1,1,1,2,2,2] [0,0,0,0,1,1,1,1,2] [0,0,0,1,1,1,2,2,2] ``` ## Environment * GHC version used: 10.1.20260525 (cccf45da) * Operating System: Bianbu 4.0 (an Ubuntu 26.04-based Linux distro) * System Architecture: 64-bit RISC-V
issue