more random singeli additions

This commit is contained in:
dzaima 2022-03-13 15:40:59 +02:00
parent ccd2b70747
commit d771f07b30
2 changed files with 20 additions and 0 deletions

View File

@ -33,10 +33,14 @@ def load {a:T, n & w256i{eltype{T} }} = emit{eltype{T}, '_mm256_loadu_si256',
def loada{a:T, n & w256i{eltype{T} }} = emit{eltype{T}, '_mm256_load_si256', a+n}
def load {a:T, n & w256f{eltype{T},64}} = emit{eltype{T}, '_mm256_loadu_pd', cast_p{f64, a+n}}
def loada{a:T, n & w256f{eltype{T},64}} = emit{eltype{T}, '_mm256_load_pd', cast_p{f64, a+n}}
def load {a:T, n & w256f{eltype{T},32}} = emit{eltype{T}, '_mm256_loadu_ps', cast_p{f32, a+n}}
def loada{a:T, n & w256f{eltype{T},32}} = emit{eltype{T}, '_mm256_load_ps', cast_p{f32, a+n}}
def store {a:T, n, v & w256i{eltype{T} }} = emit{void, '_mm256_storeu_si256', a+n, v}
def storea{a:T, n, v & w256i{eltype{T} }} = emit{void, '_mm256_store_si256', a+n, v}
def store {a:T, n, v & w256f{eltype{T},64}} = emit{void, '_mm256_storeu_pd', cast_p{f64, a+n}, v}
def storea{a:T, n, v & w256f{eltype{T},64}} = emit{void, '_mm256_store_pd', cast_p{f64, a+n}, v}
def store {a:T, n, v & w256f{eltype{T},32}} = emit{void, '_mm256_storeu_ps', cast_p{f32, a+n}, v}
def storea{a:T, n, v & w256f{eltype{T},32}} = emit{void, '_mm256_store_ps', cast_p{f32, a+n}, v}
# broadcast
def broadcast{T, v & w256i{T, 8}} = emit{T, '_mm256_set1_epi8', ext{eltype{T},v}}
@ -92,10 +96,19 @@ def abs{a:[4]f64} = emit{[4]f64, '_mm256_and_pd', a, v2d{broadcast{[4]u64, (ca
def floor{a:[4]f64} = emit{[4]f64, '_mm256_floor_pd', a}
def ceil{a:[4]f64} = emit{[4]f64, '_mm256_ceil_pd', a}
# conversion
def cvt_f2i{x:[8]f32} = emit{[8]i32, '_mm256_cvtps_epi32', x}
def cvt_i2f{x:[8]i32} = emit{[8]f32, '_mm256_cvtepi32_ps', x}
# structural operations
def extract{x:T, i & w256i{T,32} & knum{i}} = emit{eltype{T}, '_mm256_extract_epi32', x, i}
def extract{x:T, i & w256i{T,64} & knum{i}} = emit{eltype{T}, '_mm256_extract_epi64', x, i}
def extract{x:T, i & w256f{T,64} & knum{i}} = emit{f64, '_mm256_cvtsd_f64', emit{T, '_mm256_permute4x64_pd', x, i}}
def extract{x:T, i & w256f{T,32} & knum{i}} = {
t:= emit{[4]f32, '_mm256_extractf128_ps', x, i>>2}
emit{f32, '_mm_cvtss_f32', emit{[4]f32, '_mm_shuffle_ps', t, t, i}}
}
def insert{x:T, i, v & w256i{T, 8} & knum{i}} = emit{T, '_mm256_insert_epi8', x, v, i}
def insert{x:T, i, v & w256i{T,16} & knum{i}} = emit{T, '_mm256_insert_epi16', x, v, i}
@ -105,6 +118,7 @@ def insert{x:T, i, v & w256i{T,64} & knum{i}} = emit{T, '_mm256_insert_epi64', x
# mixed-width operations
def half{x:T, i & w256{T} & knum{i}} = cast_v{[vcount{T}/2](eltype{T}), emit{[8]i16, '_mm256_extracti128_si256', v2i{x}, i}}
def pair{a:T,b:T & width{T}==128} = cast_v{T, emit{[8]i32, '_mm256_setr_m128i', a, b}}
def pair{x} = pair{tupsel{0,x},tupsel{1,x}}
# mask stuff
def getmask{x:T & w256{T, 32}} = emit{u8, '_mm256_movemask_ps', v2f{x}}

View File

@ -14,8 +14,14 @@ def isunsigned{T} = isint{T} & ~issigned{T}
def assert{x:u1} = emit{void, 'si_assert', x}
def cast_p{T, x} = emit{*T, '(void*)', x}
def anyNum{x} = knum{x}
def anyNum{x & match{'constant',kind{x}}} = 1
def anyNum{x:T} = match{'primitive',typekind{T}}
def anyInt{x} = knum{x}
def anyInt{x & match{'register',kind{x}} | match{'constant',kind{x}}} = isint{x}
def __add{a:T,b & match{'pointer',typekind{T}} & anyInt{b}} = emit{T, 'op +', a, b}
def __sub{a:T,b & match{'pointer',typekind{T}} & anyInt{b}} = emit{T, 'op +', a, b}