From a39700ea9595c432941707c39ed54662d30da3e0 Mon Sep 17 00:00:00 2001 From: Valentin Churavy Date: Thu, 19 Mar 2026 17:25:04 +0100 Subject: [PATCH 1/6] update to opaque ptr --- src/core.jl | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/src/core.jl b/src/core.jl index 733d19e..5488c08 100644 --- a/src/core.jl +++ b/src/core.jl @@ -67,10 +67,20 @@ const MAX_ATOMIC_SIZE = 8 const MAX_POINTERATOMIC_SIZE = 8 end +const OPAQUE_POINTERS = !(VERSION < v"1.12.0") + +if OPAQUE_POINTERS + ptr(typ) = typ*"*" + inttoptr(_, arg) = "bitcast ptr $arg to ptr" +else + ptr(typ) = "ptr" + inttoptr(typ, arg) = "inttoptr i$WORD_SIZE $arg to $(ptr(typ))" +end + # Based on: https://github.com/JuliaLang/julia/blob/v1.6.3/base/atomics.jl for typ in (inttypes..., floattypes...) lt = llvmtypes[typ] - rt = "$lt, $lt*" + rt = "$lt, $(ptr(lt))" for ord in orderings ord in (release, acq_rel) && continue @@ -84,7 +94,7 @@ for typ in (inttypes..., floattypes...) @eval function UnsafeAtomics.load(x::Ptr{$typ}, ::$(typeof(ord)), ::$(typeof(sync))) return llvmcall( $(""" - %ptr = inttoptr i$WORD_SIZE %0 to $lt* + %ptr = $(inttoptr(lt, "%0")) %rv = load atomic $rt %ptr $ord, align $(sizeof(typ)) ret $lt %rv """), @@ -110,8 +120,8 @@ for typ in (inttypes..., floattypes...) @eval function UnsafeAtomics.store!(x::Ptr{$typ}, v::$typ, ::$(typeof(ord)), ::$(typeof(sync))) return llvmcall( $(""" - %ptr = inttoptr i$WORD_SIZE %0 to $lt* - store atomic $lt %1, $lt* %ptr $ord, align $(sizeof(typ)) + %ptr = $(inttoptr(lt, "%0")) + store atomic $lt %1, $(ptr(lt)) %ptr $ord, align $(sizeof(typ)) ret void """), Cvoid, @@ -161,13 +171,13 @@ for typ in (inttypes..., floattypes...) old = llvmcall( $( """ - %ptr = inttoptr i$WORD_SIZE %0 to $lt* - %rs = cmpxchg $lt* %ptr, $lt %1, $lt %2 $success_ordering $failure_ordering + %ptr = $(inttoptr(lt, "%0")) + %rs = cmpxchg $(ptr(lt)) %ptr, $lt %1, $lt %2 $success_ordering $failure_ordering %rv = extractvalue { $lt, i1 } %rs, 0 %s1 = extractvalue { $lt, i1 } %rs, 1 %s8 = zext i1 %s1 to i8 - %sptr = inttoptr i$WORD_SIZE %3 to i8* - store i8 %s8, i8* %sptr + %sptr = $(inttoptr("i8", "%3")) + store i8 %s8, $(ptr("i8")) %sptr ret $lt %rv """ ), @@ -224,8 +234,8 @@ for typ in (inttypes..., floattypes...) ) old = llvmcall( $(""" - %ptr = inttoptr i$WORD_SIZE %0 to $lt* - %rv = atomicrmw $rmw $lt* %ptr, $lt %1 $ord + %ptr = $(inttoptr(lt, "%0")) + %rv = atomicrmw $rmw $(ptr(lt)) %ptr, $lt %1 $ord ret $lt %rv """), $typ, From ffe0d01ec686a75157431cd63054c97d91306e7f Mon Sep 17 00:00:00 2001 From: Valentin Churavy Date: Thu, 19 Mar 2026 17:35:20 +0100 Subject: [PATCH 2/6] update CI --- .github/workflows/ci.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1720176..dd02d98 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -15,7 +15,8 @@ jobs: julia-version: - 'lts' - '1.11' - - '1.12-nightly' + - '1.12' + - '1.13-nightly' - 'nightly' fail-fast: false name: Test Julia ${{ matrix.julia-version }} From 147ad3e51802e1fd535f4773cf811206894cc18e Mon Sep 17 00:00:00 2001 From: Valentin Churavy Date: Thu, 19 Mar 2026 17:42:27 +0100 Subject: [PATCH 3/6] update fence --- ext/UnsafeAtomicsLLVM/atomics.jl | 4 ++++ src/core.jl | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/ext/UnsafeAtomicsLLVM/atomics.jl b/ext/UnsafeAtomicsLLVM/atomics.jl index f2a54e7..2f33269 100644 --- a/ext/UnsafeAtomicsLLVM/atomics.jl +++ b/ext/UnsafeAtomicsLLVM/atomics.jl @@ -139,7 +139,11 @@ end # See: https://github.com/JuliaLang/julia/blob/v1.7.2/src/cgutils.cpp#L1570-L1572 return quote is_stronger_than_monotonic(_valueof(order)) || return ptr +@static if VERSION < v"1.14.0-DEV.1371" Core.Intrinsics.atomic_fence(_valueof(order)) +else + Core.Intrinsics.atomic_fence(_valueof(order), _valueof(sync)) +end return ptr end end diff --git a/src/core.jl b/src/core.jl index 5488c08..e9bb866 100644 --- a/src/core.jl +++ b/src/core.jl @@ -255,7 +255,11 @@ for sync in syncscopes if sync == none # Core.Intrinsics.atomic_fence was introduced in 1.10 @eval function UnsafeAtomics.fence(ord::Ordering, ::$(typeof(sync))) +@static if VERSION < v"1.14.0-DEV.1371" Core.Intrinsics.atomic_fence(base_ordering(ord)) +else + Core.Intrinsics.atomic_fence(base_ordering(ord), :system) +end return nothing end if Sys.ARCH == :x86_64 From 22ca3db51fc1504b57c9a84b2ea12e84c7d7d615 Mon Sep 17 00:00:00 2001 From: Valentin Churavy Date: Thu, 19 Mar 2026 17:46:00 +0100 Subject: [PATCH 4/6] fixup! update fence --- ext/UnsafeAtomicsLLVM/atomics.jl | 20 ++++++++++++-------- src/core.jl | 17 ++++++++++------- 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/ext/UnsafeAtomicsLLVM/atomics.jl b/ext/UnsafeAtomicsLLVM/atomics.jl index 2f33269..d582caa 100644 --- a/ext/UnsafeAtomicsLLVM/atomics.jl +++ b/ext/UnsafeAtomicsLLVM/atomics.jl @@ -137,14 +137,18 @@ end if sizeof(T) == 0 # Mimicking what `Core.Intrinsics.atomic_pointerset` generates. # See: https://github.com/JuliaLang/julia/blob/v1.7.2/src/cgutils.cpp#L1570-L1572 - return quote - is_stronger_than_monotonic(_valueof(order)) || return ptr -@static if VERSION < v"1.14.0-DEV.1371" - Core.Intrinsics.atomic_fence(_valueof(order)) -else - Core.Intrinsics.atomic_fence(_valueof(order), _valueof(sync)) -end - return ptr + if VERSION < v"1.14.0-DEV.1371" + return quote + is_stronger_than_monotonic(_valueof(order)) || return ptr + Core.Intrinsics.atomic_fence(_valueof(order)) + return ptr + end + else + return quote + is_stronger_than_monotonic(_valueof(order)) || return ptr + Core.Intrinsics.atomic_fence(_valueof(order), :system) + return ptr + end end end llvm_order = _valueof(llvm_from_julia_ordering(order())) diff --git a/src/core.jl b/src/core.jl index e9bb866..9da67d0 100644 --- a/src/core.jl +++ b/src/core.jl @@ -254,13 +254,16 @@ end for sync in syncscopes if sync == none # Core.Intrinsics.atomic_fence was introduced in 1.10 - @eval function UnsafeAtomics.fence(ord::Ordering, ::$(typeof(sync))) -@static if VERSION < v"1.14.0-DEV.1371" - Core.Intrinsics.atomic_fence(base_ordering(ord)) -else - Core.Intrinsics.atomic_fence(base_ordering(ord), :system) -end - return nothing + if VERSION < v"1.14.0-DEV.1371" + @eval function UnsafeAtomics.fence(ord::Ordering, ::$(typeof(sync))) + Core.Intrinsics.atomic_fence(base_ordering(ord)) + return nothing + end + else + @eval function UnsafeAtomics.fence(ord::Ordering, ::$(typeof(sync))) + Core.Intrinsics.atomic_fence(base_ordering(ord), :system) + return nothing + end end if Sys.ARCH == :x86_64 # FIXME: Disable this once on LLVM 19 From d08ac8ba8249c936674157a47d7a960059228388 Mon Sep 17 00:00:00 2001 From: Valentin Churavy Date: Thu, 19 Mar 2026 21:07:14 +0100 Subject: [PATCH 5/6] fixup! fixup! update fence --- src/core.jl | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/core.jl b/src/core.jl index 9da67d0..480fd89 100644 --- a/src/core.jl +++ b/src/core.jl @@ -67,14 +67,13 @@ const MAX_ATOMIC_SIZE = 8 const MAX_POINTERATOMIC_SIZE = 8 end -const OPAQUE_POINTERS = !(VERSION < v"1.12.0") -if OPAQUE_POINTERS +if VERSION < v"1.12.0" ptr(typ) = typ*"*" - inttoptr(_, arg) = "bitcast ptr $arg to ptr" + inttoptr(typ, arg) = "inttoptr i$WORD_SIZE $arg to $(ptr(typ))" else ptr(typ) = "ptr" - inttoptr(typ, arg) = "inttoptr i$WORD_SIZE $arg to $(ptr(typ))" + inttoptr(_, arg) = "bitcast ptr $arg to ptr" end # Based on: https://github.com/JuliaLang/julia/blob/v1.6.3/base/atomics.jl From 36297f91eb0216c75d30f5d9dbdce5cb41c6f259 Mon Sep 17 00:00:00 2001 From: Valentin Churavy Date: Thu, 19 Mar 2026 21:08:16 +0100 Subject: [PATCH 6/6] bump version --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index 8cc69d5..4909b4c 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "UnsafeAtomics" uuid = "013be700-e6cd-48c3-b4a1-df204f14c38f" authors = ["Takafumi Arakaki and contributors"] -version = "0.3.0" +version = "0.3.1" [weakdeps] LLVM = "929cbde3-209d-540e-8aea-75f648917ca0"