The doc: https://nim-lang.org/docs/manual.html#align_1 shows an example for sse. But when I try a bit it looks like only the header is aligned and not the data. Am I missing something obvious? Either in the docs or my code? If not, aligning only the header for simd has little use.
var avxSeq {.align:32.} = @[0.0'f32,0.1,0.2,0.3]
echo "header"
echo sizeof(avxSeq)
echo alignof(avxSeq)
echo cast[int](addr avxSeq)
echo cast[int](addr(avxSeq)) mod 32
echo "\n"
echo "data"
echo sizeof(avxSeq[0])
echo alignof(avxSeq[0])
echo cast[int](addr avxSeq[0])
echo cast[int](addr(avxSeq[0])) mod 32 #?? 0?
const
ALIGNSSE* = 16
ALIGNAVX* = 32
proc aSeq[T](size: int = 0, alignment: int = ALIGNAVX): (seq[T], int) =
## Creates a seq with aligned data section
## Return: (padded_seq, offset_to_aligned_data)
# The needed padding, worst case: alignment - 1 elements
let
padding = (alignment div sizeof(T)) - 1
totalSize = size + padding
var paddedSeq = newSeq[T](totalSize)
# Offset for alignment
let
baseAddr = cast[int](addr paddedSeq[0])
misalignment = baseAddr mod alignment
offsetBytes = if misalignment == 0: 0 else: alignment - misalignment
offsetElements = offsetBytes div sizeof(T)
return (paddedSeq, offsetElements)
and from there create an object etc.