haskell / primitive

This package provides various primitive memory-related operations.
Other
114 stars 58 forks source link

Missing atomic operators for `Data.Primitive.ByteArray` #122

Open TerrorJack opened 6 years ago

TerrorJack commented 6 years ago

There are several atomic primops for MutableByteArray# like casIntArray#, fetchAddIntArray#, yet they don't have shims in Data.Primitive.ByteArray yet. Mind if I open a PR for this?

treeowl commented 6 years ago

Please do!

On Mon, Apr 2, 2018, 9:15 AM Shao Cheng notifications@github.com wrote:

There are several atomic primops for MutableByteArray# like casIntArray#, fetchAddIntArray#, yet they don't have shims in Data.Primitive.ByteArray yet. Mind if I open a PR for this?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/haskell/primitive/issues/122, or mute the thread https://github.com/notifications/unsubscribe-auth/ABzi_SCcjse67Hc5Ksasi09s9QwpxQYwks5tkcHmgaJpZM4TDMWa .

cartazio commented 6 years ago

@TerrorJack .... plase make sure they have a consistent size on both 32bit and 64bit platforms....

Theres also gonna be some gotchas (i imagine) with alignment plus how this interacts with cache line synchronization etc. so lets make sure we understand the semantics and performance characteristics before we merge it in.

andrewthad commented 6 years ago

make sure they have a consistent size on both 32bit and 64bit platforms

Isn't the only way to implement this to make them have inconsistent sizes on 32 bit vs 64 bit platforms? I think this has to use machine-sized words.

cartazio commented 6 years ago

I’ll have to double check what’s available on the various target platforms. I guess I’m just uncomfortable with a byte varying per platform operation on bytearrays. Illl need to think about this

On Tue, Apr 3, 2018 at 3:07 PM Andrew Martin notifications@github.com wrote:

make sure they have a consistent size on both 32bit and 64bit platforms

Isn't the only way to implement this to make them have inconsistent sizes on 32 bit vs 64 bit platforms? I think this has to use machine-sized words.

— You are receiving this because you commented.

Reply to this email directly, view it on GitHub https://github.com/haskell/primitive/issues/122#issuecomment-378362396, or mute the thread https://github.com/notifications/unsubscribe-auth/AAAQwoeTibieji1aug7OV_vK0Q_z1a87ks5tk8hsgaJpZM4TDMWa .

andrewthad commented 6 years ago

It's worth considering that we are already in this situation. This bit of code

writeByteArray myArray 1 (1 :: Int)

behaves differently on a 32-bit platform and a 64-bit platform.

andrewthad commented 6 years ago

I have two PRs exploring different approaches to implementing these primops:

Both of these only add primops to PrimArray, but these could easily be added to the ByteArray module as well.

andrewthad commented 4 years ago

I have written a library that implements this: primitive-atomic. I will consider merging this into primitive, although I'm not certain that it meets a terribly dire need.