Opened 4 years ago

Last modified 6 months ago

#5444 new bug

Slow 64-bit primops on 32 bit system

Reported by: Khudyakov Owned by:
Priority: normal Milestone: 7.12.1
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 Revisions:

Description

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 (6)

comment:1 Changed 4 years ago by bos

  • Cc bos@… added

comment:2 Changed 4 years ago by igloo

  • Milestone set to 7.6.1

comment:3 Changed 4 years ago by dterei

  • Cc dterei added

comment:4 Changed 3 years ago by igloo

  • Milestone changed from 7.6.1 to 7.6.2

comment:5 Changed 12 months ago by thoughtpolice

  • Milestone changed from 7.6.2 to 7.10.1

Moving to 7.10.1.

comment:6 Changed 6 months ago by thoughtpolice

  • Milestone changed from 7.10.1 to 7.12.1

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.

Note: See TracTickets for help on using tickets.