Skip to content

Use unsafeShift in BitUtil for base >= 4.8 #216

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed

Use unsafeShift in BitUtil for base >= 4.8 #216

wants to merge 2 commits into from

Conversation

Rufflewind
Copy link
Member

Use unsafeShiftL/R in BitUtil for base >= 4.8 instead of explicitly using GHC primitives, and also avoid the warning about Trustworthy.

@treeowl
Copy link
Contributor

treeowl commented May 4, 2016

The comments accompanying those indicate the purpose is to ensure inlining.
The Bits Int instance does not INLINE those methods, so they won't be
inlined in unfoldings, I don't think.
On May 4, 2016 4:35 AM, "Phil Ruffwind" [email protected] wrote:

Use unsafeShiftL/R in BitUtil for base >= 4.8 instead of explicitly using

GHC primitives, and also avoid the warning about Trustworthy.

You can view, comment on, or merge this pull request online at:

#216
Commit Summary

  • Use unsafeShift in BitUtil for base >= 4.8
  • Avoid Trustworthy warning in BitUtil

File Changes

Patch Links:


You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub
#216

@treeowl
Copy link
Contributor

treeowl commented May 4, 2016

Of course, it's possible that's not necessary, but it would be good to be
sure.
On May 4, 2016 4:38 AM, "David Feuer" [email protected] wrote:

The comments accompanying those indicate the purpose is to ensure
inlining. The Bits Int instance does not INLINE those methods, so they
won't be inlined in unfoldings, I don't think.
On May 4, 2016 4:35 AM, "Phil Ruffwind" [email protected] wrote:

Use unsafeShiftL/R in BitUtil for base >= 4.8 instead of explicitly

using GHC primitives, and also avoid the warning about Trustworthy.

You can view, comment on, or merge this pull request online at:

#216
Commit Summary

  • Use unsafeShift in BitUtil for base >= 4.8
  • Avoid Trustworthy warning in BitUtil

File Changes

Patch Links:


You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub
#216

@Rufflewind
Copy link
Member Author

You're right. It doesn't seem to inline those … I don't understand why shift has INLINE but unsafeShift don't :/

https://hackage.haskell.org/package/base-4.8.2.0/docs/src/GHC.Word.html

shiftRL2 :: Word -> Int -> Word

shiftRL2 =
  \ (ds_d1VQ :: Word) (ds1_d1VR :: Int) ->
    case ds_d1VQ of _ [Occ=Dead] { W# x_a1MJ ->
    case ds1_d1VR of _ [Occ=Dead] { I# i_a1MK ->
    GHC.Types.W# (uncheckedShiftRL# x_a1MJ i_a1MK)
    }
    }

shiftRL :: Word -> Int -> Word

shiftRL = Data.Bits.$fBitsWord_$cunsafeShiftR

@treeowl
Copy link
Contributor

treeowl commented May 6, 2016

The comment in Data.Bits is not terribly informative. I would think these should all be marked INLINE or INLINE CONLIKE. I suggest you open a ticket upstream to consider this and link from here. I'll leave this ticket open pending a decision upstream.

@Rufflewind
Copy link
Member Author

I suggest you open a ticket upstream to consider this and link from here.

https://ghc.haskell.org/trac/ghc/ticket/12022

@m-renaud
Copy link
Contributor

There doesn't appear to be any updates on the upstream ticktet and the Bits instance for Int in base-4.10.0.0 still doesn't have unsafeShiftL and unsafeShiftR marked INLINE. I'll follow up on the trac ticket when I get a chance.

@m-renaud
Copy link
Contributor

m-renaud commented Dec 26, 2017

See updated comments in https://ghc.haskell.org/trac/ghc/ticket/12022. It sounds like the advice is still to let the compiler determine when to INLINE. mpickering also points out that the shiftLL function has different semantics depending on if __GLASGOW_HASKELL__ is set or not.

I don't know enough about optimization or GHC semantics at this point to comment on what we should do here.

@sjakobi
Copy link
Member

sjakobi commented Jul 29, 2019

I think this can be closed. Today we have

shiftRL = unsafeShiftR
shiftLL = unsafeShiftL

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants