julia
47ea71e5 - base: use `unsafe_memoryrefload/store!` for dense ReinterpretArray indexing

Commit
30 days ago
base: use `unsafe_memoryrefload/store!` for dense ReinterpretArray indexing the bottom of this stack is the important one to review; this one provides the original motivation for the intrinsic though ```julia julia> @btime ary.+=Int32(1) setup = (ary = rand(Int32, 10^5)); 7.854 μs (0 allocations: 0 bytes) julia> @btime ary.+=Int32(1) setup = (ary = reinterpret(Int32, rand(UInt8, 10^5*4))); 34.666 μs (0 allocations: 0 bytes) # master 7.875 μs (0 allocations: 0 bytes) # PR ``` and ```julia julia> _from_zigzag(n) = (n >> one(n)) ⊻ -(n & one(n)) _from_zigzag (generic function with 1 method) julia> function g(res) @simd for i in eachindex(res) res[i] = _from_zigzag(res[i]) end end g (generic function with 1 method) julia> ARY = reinterpret(Int16, rand(UInt8, 10^5)); julia> using BenchmarkTools julia> @btime g(x) setup=begin x = copy(ARY) end 2.199 μs (0 allocations: 0 bytes) julia> @btime g(x) setup=begin x = deepcopy(ARY) end 26.459 μs (0 allocations: 0 bytes) # master 2.199 μs (0 allocations: 0 bytes) # PR ``` 🤖: Use owner-aware byte loads and stores for dense reinterpret storage. Fetch the current parent reference at each scalar access so resizing remains visible. Convert before checking bounds so a conversion that shrinks the parent is observed. Buffer alias information allows hoisting when that reference is unchanged. Other storage retains the general indexing implementation. Keep the existing logical bounds checks and skip the redundant owner-span check, which otherwise blocks zigzag loop vectorization. The unchecked accesses lose `:noub` and gain conditional consistency and argument-memory effects. `getindex` was not foldable with the raw-pointer implementation either. Fixes #51658 Fixes #48801 Assisted-by: Codex (GPT 6.1 Sol) Assisted-by: Claude Code (Claude Opus 5.5)
Author
Committer
Parents
Loading