From 641df82cb32868d3369a12fcf9414696ee816af5 Mon Sep 17 00:00:00 2001 From: Erik Schnetter Date: Mon, 9 Sep 2024 16:36:01 -0400 Subject: [PATCH] Support chime_complex encoding of 4+4-bit integers --- Project.toml | 2 +- src/IndexSpaces.jl | 19 ++++++++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/Project.toml b/Project.toml index f6abf3c..c33dcd1 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "IndexSpaces" uuid = "3ceaaf38-e7b4-4193-a23a-303dd231a83a" authors = ["Erik Schnetter "] -version = "1.6.0" +version = "1.7.0" [deps] CUDA = "052768ef-5323-5732-b1bb-66c8b64840ba" diff --git a/src/IndexSpaces.jl b/src/IndexSpaces.jl index 555c25b..894d21d 100644 --- a/src/IndexSpaces.jl +++ b/src/IndexSpaces.jl @@ -1415,6 +1415,19 @@ 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, @@ -1422,6 +1435,7 @@ function widen!( var::Symbol, simd_register::Pair{SIMD,Register}; newtype::Union{Nothing,Type}=nothing, + swapped_withoffset::Bool=false, unshifted_withoffset::Bool=false, ) simd, register = simd_register @@ -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))