Opened 5 years ago

Last modified 13 months ago

#5444 new bug

Slow 64-bit primops on 32 bit system

Reported by: Khudyakov Owned by:
Priority: normal Milestone:
Component: Compiler Version: 7.2.1
Keywords: Cc: bos@…, dterei
Operating System: Unknown/Multiple Architecture: x86
Type of failure: Runtime performance bug Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:


GHC primops for 64-bit arithmetic are implemented as FFI calls. It leads to serious performance penalty for 32 bit code which heavily uses 64-bit arithmetics.

I found this while investigating poor performance of mwc-random on 32-bit systems. 32-bit build runs 3-4 times slower than 64-bit build on the same hardware. It's difficult to estimate how faster would run optimal implementation since it doesn't exist. But it's probably at least 2x slowdown.

Here is simple program to demonstrate issue

sqr64 :: Int32 -> Int64
sqr64 x = y * y where y = fromIntegral x

Here is optimized core

$wsqr64 :: Int# -> Int64
$wsqr64 =
  \ (ww_sGO :: Int#) ->
    case {__pkg_ccall ghc-prim hs_intToInt64 Int#
                                    -> State# RealWorld -> (# State# RealWorld, Int64# #)}_aFY
           ww_sGO realWorld#
    of _ { (# _, ds2_aG2 #) ->
    case {__pkg_ccall ghc-prim hs_timesInt64 Int64#
                                    -> Int64# -> State# RealWorld -> (# State# RealWorld, Int64# #)}_aGc
           ds2_aG2 ds2_aG2 realWorld#
    of _ { (# _, ds4_aGi #) ->
    I64# ds4_aGi

sqr64 :: Int32 -> Int64
sqr64 = \ (w_sGM :: Int32) ->
    case w_sGM of _ { I32# ww_sGO -> $wsqr64 ww_sGO }

Change History (8)

comment:1 Changed 5 years ago by bos

Cc: bos@… added

comment:2 Changed 5 years ago by igloo

Milestone: 7.6.1

comment:3 Changed 5 years ago by dterei

Cc: dterei added

comment:4 Changed 4 years ago by igloo


comment:5 Changed 3 years ago by thoughtpolice


Moving to 7.10.1.

comment:6 Changed 2 years ago by thoughtpolice


Moving to 7.12.1 milestone; if you feel this is an error and should be addressed sooner, please move it back to the 7.10.1 milestone.

comment:7 Changed 18 months ago by thoughtpolice


Milestone renamed

comment:8 Changed 13 months ago by thomie

Milestone: 8.0.1
Note: See TracTickets for help on using tickets.