From 8caa1729c120711baccd6b6f51259bf15539e939 Mon Sep 17 00:00:00 2001 From: Thomas Faingnaert Date: Tue, 14 Nov 2023 23:37:00 +0100 Subject: [PATCH] Fix alignment check for non 16-byte alignments --- src/layout.jl | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/layout.jl b/src/layout.jl index b591f363..807b3a9a 100644 --- a/src/layout.jl +++ b/src/layout.jl @@ -24,13 +24,13 @@ struct Vec{N, T} end error() end -@inline function checkalignment(ptr) - checkalignment(Bool, ptr) || throw_alignmenterror(ptr) +@inline function checkalignment(ptr, alignment) + checkalignment(Bool, ptr, alignment) || throw_alignmenterror(ptr) nothing end -@inline function checkalignment(::Type{Bool}, ptr) - Int(ptr) % 16 == 0 +@inline function checkalignment(::Type{Bool}, ptr, alignment) + Int(ptr) % alignment == 0 end @inline @generated function vloada(::Type{Vec{N, T}}, ptr::Core.LLVMPtr{T, AS}) where {N, T, AS} @@ -38,7 +38,7 @@ end return quote vec_ptr = Base.bitcast(Core.LLVMPtr{NTuple{N, VecElement{T}}, AS}, ptr) - @boundscheck checkalignment(vec_ptr) + @boundscheck checkalignment(vec_ptr, $alignment) return unsafe_load(vec_ptr, 1, Val($alignment)) end end @@ -55,7 +55,7 @@ end append!(ex.args, (quote y = @ntuple $N j -> VecElement{T}(x[j+$offset].value) vec_ptr = Base.bitcast(Core.LLVMPtr{NTuple{N, VecElement{T}}, AS}, ptr) - @boundscheck checkalignment(vec_ptr) + @boundscheck checkalignment(vec_ptr, $alignment) unsafe_store!(vec_ptr, y, $offset รท N + 1, Val($alignment)) end).args) end