Skip to content

Commit

Permalink
Add propagate_inbounds_meta to atomic genericmemory ops (#55902)
Browse files Browse the repository at this point in the history
`memoryref(mem, i)` will otherwise emit a boundscheck.

```
; │ @ /home/vchuravy/WorkstealingQueues/src/CLL.jl:53 within `setindex_atomic!` @ genericmemory.jl:329
; │┌ @ boot.jl:545 within `memoryref`
    %ptls_field = getelementptr inbounds i8, ptr %tls_pgcstack, i64 16
    %ptls_load = load ptr, ptr %ptls_field, align 8
    %"box::GenericMemoryRef" = call noalias nonnull align 8 dereferenceable(32) ptr @ijl_gc_small_alloc(ptr %ptls_load, i32 552, i32 32, i64 23456076646928) #9
    %"box::GenericMemoryRef.tag_addr" = getelementptr inbounds i64, ptr %"box::GenericMemoryRef", i64 -1
    store atomic i64 23456076646928, ptr %"box::GenericMemoryRef.tag_addr" unordered, align 8
    store ptr %memoryref_data, ptr %"box::GenericMemoryRef", align 8
    %.repack8 = getelementptr inbounds { ptr, ptr }, ptr %"box::GenericMemoryRef", i64 0, i32 1
    store ptr %memoryref_mem, ptr %.repack8, align 8
    call void @ijl_bounds_error_int(ptr nonnull %"box::GenericMemoryRef", i64 %7)
    unreachable
```

For the Julia code:

```julia
function Base.setindex_atomic!(buf::WSBuffer{T}, order::Symbol, val::T, idx::Int64) where T
    @inbounds Base.setindex_atomic!(buf.buffer, order, val,((idx - 1) & buf.mask) + 1)
end
```

from
https://github.com/gbaraldi/WorkstealingQueues.jl/blob/0ebc57237cf0c90feedf99e4338577d04b67805b/src/CLL.jl#L41
  • Loading branch information
vchuravy authored Oct 1, 2024
1 parent 75393f6 commit 03f8523
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions base/genericmemory.jl
Original file line number Diff line number Diff line change
Expand Up @@ -320,11 +320,13 @@ end

# get, set(once), modify, swap and replace at index, atomically
function getindex_atomic(mem::GenericMemory, order::Symbol, i::Int)
@_propagate_inbounds_meta
memref = memoryref(mem, i)
return memoryrefget(memref, order, @_boundscheck)
end

function setindex_atomic!(mem::GenericMemory, order::Symbol, val, i::Int)
@_propagate_inbounds_meta
T = eltype(mem)
memref = memoryref(mem, i)
return memoryrefset!(
Expand All @@ -342,6 +344,7 @@ function setindexonce_atomic!(
val,
i::Int,
)
@_propagate_inbounds_meta
T = eltype(mem)
memref = memoryref(mem, i)
return Core.memoryrefsetonce!(
Expand All @@ -354,11 +357,13 @@ function setindexonce_atomic!(
end

function modifyindex_atomic!(mem::GenericMemory, order::Symbol, op, val, i::Int)
@_propagate_inbounds_meta
memref = memoryref(mem, i)
return Core.memoryrefmodify!(memref, op, val, order, @_boundscheck)
end

function swapindex_atomic!(mem::GenericMemory, order::Symbol, val, i::Int)
@_propagate_inbounds_meta
T = eltype(mem)
memref = memoryref(mem, i)
return Core.memoryrefswap!(
Expand All @@ -377,6 +382,7 @@ function replaceindex_atomic!(
desired,
i::Int,
)
@_propagate_inbounds_meta
T = eltype(mem)
memref = memoryref(mem, i)
return Core.memoryrefreplace!(
Expand Down

0 comments on commit 03f8523

Please sign in to comment.