mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-06 15:48:51 +00:00
Add static SIMD support to XXH3 in core:hash/xxhash.
This uses compile-time features to decide how large of a SIMD vector to use. It currently has checks for amd64/i386 to size its vectors for SSE2/AVX2/AVX512 as necessary. The generalized SIMD functions could also be useful for multiversioning of the hash procs, to allow for run-time dispatch based on available CPU features.
This commit is contained in:
@@ -101,3 +101,35 @@ XXH64_read64 :: #force_inline proc(buf: []u8, alignment := Alignment.Unaligned)
|
||||
return u64(b)
|
||||
}
|
||||
}
|
||||
|
||||
XXH64_read64_simd :: #force_inline proc(buf: []$E, $W: uint, alignment := Alignment.Unaligned) -> (res: #simd[W]u64) {
|
||||
if alignment == .Aligned {
|
||||
res = (^#simd[W]u64)(raw_data(buf))^
|
||||
} else {
|
||||
res = intrinsics.unaligned_load((^#simd[W]u64)(raw_data(buf)))
|
||||
}
|
||||
|
||||
when ODIN_ENDIAN == .Big {
|
||||
bytes := transmute(#simd[W*8]u8)res
|
||||
bytes = intrinsics.simd_lanes_reverse(bytes)
|
||||
res = transmute(#simd[W]u64)bytes
|
||||
res = intrinsics.simd_lanes_reverse(res)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
XXH64_write64_simd :: #force_inline proc(buf: []$E, value: $V/#simd[$W]u64, alignment := Alignment.Unaligned) {
|
||||
value := value
|
||||
when ODIN_ENDIAN == .Big {
|
||||
bytes := transmute(#simd[W*8]u8)value
|
||||
bytes = intrinsics.simd_lanes_reverse(bytes)
|
||||
value = transmute(#simd[W]u64)bytes
|
||||
value = intrinsics.simd_lanes_reverse(value)
|
||||
}
|
||||
|
||||
if alignment == .Aligned {
|
||||
(^V)(raw_data(buf))^ = value
|
||||
} else {
|
||||
intrinsics.unaligned_store((^V)(raw_data(buf)), value)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user