hashlink icon indicating copy to clipboard operation
hashlink copied to clipboard

Atomic operations.

Open Apprentice-Alchemist opened this issue 3 years ago • 7 comments

The JIT implementation is based on what GCC emits for it's intrinsics. The C implementation is copy pasted from what I did for hxcpp.

See https://github.com/HaxeFoundation/haxe/pull/10610

Apprentice-Alchemist avatar Mar 01 '22 12:03 Apprentice-Alchemist

I don't think this requires some specific opcodes, especially since the C version - which is supposed to be faster - is based on library function calls.

ncannasse avatar Mar 01 '22 16:03 ncannasse

Good point about library calls on MSVC, I should replace those with the intrinsics.

But for GCC/Clang it already uses instrinsics, which do not call library functions: Godbolt

Apprentice-Alchemist avatar Mar 01 '22 16:03 Apprentice-Alchemist

What's the status here? I'm willing to merge the hxcpp PR, but I'm unsure where we're at for HL.

Simn avatar Aug 02 '22 05:08 Simn

That's a lot of code. I'm curious what's the rationale for supporting all 8/16/32/64 bits int values ? I think 32 + ptr only would be good enough. Also, if the hl_atomic inlines are only meant to support HL/C, maybe they should be in hlc.h and not hl.h ?

ncannasse avatar Aug 03 '22 07:08 ncannasse

That's a lot of code. I'm curious what's the rationale for supporting all 8/16/32/64 bits int values ? I think 32 + ptr only would be good enough.

Hashlink has 8/16/32/64 bit int types, so I thought it made sense to already implement atomic operations for all of them even though there are no AtomicI8/16/64 types (yet).

Also, if the hl_atomic inlines are only meant to support HL/C, maybe they should be in hlc.h and not hl.h ?

Having them in hl.h could be useful if someone needs atomic operations when, for example, writing a hdll.

Apprentice-Alchemist avatar Aug 03 '22 18:08 Apprentice-Alchemist

I think we should keep things more simple with only int32 atomics and using primitives instead of opcodes.

ncannasse avatar Aug 31 '22 07:08 ncannasse

I've removed the 8/16/64 bit atomics, and switched everything to primitives. I have kept the pointer atomics, it'd be a shame if AtomicObject were only implemented for Java.

Apprentice-Alchemist avatar Aug 31 '22 13:08 Apprentice-Alchemist

@ncannasse Should this be merged? I'm happy to handle the hxcpp and Haxe side of this, but we need a decision for HL first.

Simn avatar Nov 07 '22 16:11 Simn

I could merge the PR but it still contains some JIT support leftovers.

ncannasse avatar Nov 15 '22 15:11 ncannasse

The leftovers from JIT support have been removed.

Apprentice-Alchemist avatar Nov 15 '22 19:11 Apprentice-Alchemist

Last change before merge : I think we should directly add atomics to threads.c ;)

ncannasse avatar Nov 20 '22 10:11 ncannasse

Thanks !

ncannasse avatar Nov 20 '22 11:11 ncannasse