Skip to content

Commit

Permalink
Support chime_complex encoding of 4+4-bit integers
Browse files Browse the repository at this point in the history
  • Loading branch information
eschnett committed Sep 9, 2024
1 parent 1f4fa2c commit 641df82
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "IndexSpaces"
uuid = "3ceaaf38-e7b4-4193-a23a-303dd231a83a"
authors = ["Erik Schnetter <[email protected]>"]
version = "1.6.0"
version = "1.7.0"

[deps]
CUDA = "052768ef-5323-5732-b1bb-66c8b64840ba"
Expand Down
19 changes: 18 additions & 1 deletion src/IndexSpaces.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1415,13 +1415,27 @@ function int4x8_to_2int8x4_unshifted_withoffset(a::Int4x8)
return (Int8x4(a_lo), Int8x4(a_hi))::NTuple{2,Int8x4}
end

# Convert `Int4x8` to `NTuple{2,Int8x4}`, but swap the high and low nibbles and remove the offset encoding.
function int4x8_to_2int8x4_swapped_withoffset(a::Int4x8)
a1 = a.val # a + 8, implicit in the offset encoding
a2_lo = a1 & 0x0f0f0f0f # extract low part
a3_lo = a2_lo + 0x78787878 # a + 128
a4_lo = a3_lo 0x80808080 # a
a2_hi = (a1 >>> 0x04) & 0x0f0f0f0f # extract high part
a3_hi = a2_hi + 0x78787878 # a + 128
a4_hi = a3_hi 0x80808080 # a
a5_lo, a5_hi = a4_hi, a4_lo # Swap low and high parts
return (Int8x4(a5_lo), Int8x4(a5_hi))::NTuple{2,Int8x4}
end

export widen!
function widen!(
emitter::Emitter,
res::Symbol,
var::Symbol,
simd_register::Pair{SIMD,Register};
newtype::Union{Nothing,Type}=nothing,
swapped_withoffset::Bool=false,
unshifted_withoffset::Bool=false,
)
simd, register = simd_register
Expand Down Expand Up @@ -1471,7 +1485,10 @@ function widen!(
end
if indextag(var_value) == indextag(res_value) == IntValueTag
if var_value.length == 4 && res_value.length == 8
if unshifted_withoffset
@assert !(swapped_withoffset && unshifted_withoffset)
if swapped_withoffset
stmt = :(($(res_names...),) = IndexSpaces.int4x8_to_2int8x4_swapped_withoffset($var_name))
elseif unshifted_withoffset
stmt = :(($(res_names...),) = IndexSpaces.int4x8_to_2int8x4_unshifted_withoffset($var_name))
else
stmt = :(($(res_names...),) = convert(NTuple{2,Int8x4}, $var_name))
Expand Down

0 comments on commit 641df82

Please sign in to comment.