🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.c
Article #2051

Re: optimising float3

#2051
From: Ross Finlayson
Date: Tue, 01 Dec 2026 11:09
803 lines
22437 bytes
On 11/30/2026 12:22 PM, Ross Finlayson wrote:
> On 11/30/2026 11:30 AM, bartc wrote:
>> On 30/11/2026 13:54, fir wrote:
>>> im a heavy user of float3
>>>
>>> and functions liek
>>>
>>>
>>> typedef struct {float x,y,z;} float3 ;
>>> typedef struct { float3 pos, right, down, dir;} Position ;
>>> typedef struct {float3 a,b,c;} tri ;
>>>
>>>
>>>
>>> inline float3 f3(float x,float y,float z) {    return (float3){x,y,z}; }
>>> inline float dot(float3 a, float3 b) {  return a.x * b.x + a.y * b.y +
>>> a.z * b.z; }
>>> inline float3 cross(float3 a, float3 b) {  return (float3) {a.y*b.z-
>>> a.z*b.y, a.z*b.x-a.x*b.z, a.x*b.y-a.y*b.x}; }
>>> inline float length(float3 v) {  return sqrtf( v.x*v.x + v.y*v.y +
>>> v.z*v.z ); }
>>>
>>> inline float distance(float3 p, float3 q) { float3 a = {q.x-p.x, q.y-
>>> p.y, q.z-p.z};    return length(a); }
>>>
>>> inline float length3(float x, float y, float z) {  return sqrtf( x*x +
>>> y*y + z*z ); }
>>>
>>> inline float3 mul(float3 m, float s) {    return
>>> f3(m.x*s,m.y*s,m.z*s); }
>>
>> You're passing a struct by value. C will do lots of copying here, which
>> is likely to take longer than the savings of using SIMD.
>>
>> Use pointers instead.
>>
>> Even then, you are doing one operation at a time, each one having the
>> function call overhead, even using pointers.
>>
>> For best efficiency, do lots of them in a loop within the same function.
>>
>> /Then/ look at possibly using SIMD. From C, lookup gcc SIMD intrinsics.
>>
>>
>
>
> One challenge of using SIMD, single-instruction-multiple-data, is that
> there's a proliferation of vector-units, that have grown over time,
> and various instruction-set-architectures, which of course are hidden
> by a language like C, with regards the compiler targeting them
> (targeting/targetting).
>
> So, the intrinsics introduce a bunch of types like what result the
> packed registers (vector-registers, v-registers) and about the lanes
> then of the tandem units as they are, yet that the various ISA's and
> various generations/editions of these, admit some commononality.
>
> So, the commonality of the vector-units is sort of like this: 16-Byte
> wide 16-many deep tandem v-register blocks, v-blocks, these as "virtual
> vector-blocks", vv-blocks, aliased onto the 128/256/512-bit wide
> registers, with insert and extract.
>
> What's meant by "tandem" is that these are essentially 16-Byte width
> vector units, teamed together, that accounts like "shift" and "rotate",
> besides the usual "vertical" account of the packed data-type registers,
> any "horizontal" account, and also about the predication of the lanes
> in later architectures, here about "AMD" and "ARM", or Intel/AMD with
> SSE(2, 4), AVX(2), AVX512, and ARM with NEON and SVE.
>
> So, besides after cpuid, or for example what "lscpu" on Linux gives,
> and later accounts like Intel's abandoning that, then about the
> Intel-issued intrinsics to gcc, can make for gas, the GNU assembler,
> accounts of macros, about various accounts of hiding the many & varied
> parallel/packed instructions, behind common macros that basically
> just consider these v-blocks as virtual v-blocks and blocks & banks,
> as data: loading onto the v-registers, then considering that a "type",
> for example to surface to C, and functions on that, as of as on those.
>
>
>
> Then, for example, these sorts macros are common to all
> instruction-set-architectures these commodity AMD & ARM vector-units,
> then for example there are only so many instructions that also act upon
> the quite wide registers just like regular registers, or
> "vector-wide-scalar-word".
>
> Each variation then just varies "COUNT_BLOCKS" and "COUNT_BANKS",
> and a common sort of treating a few of the 16-many v-registers
> in a v-block as "data", the rest "code", can have this sort of
> thing making then a model for "C", then though that this sort of
> account is mostly for using the vector-registers "byte-wise",
> which is an underserved sort of use-case when usually the
> vector-registers are doing embarrassingly parallel packed arithmetic.
>
> Figuring out how to surface that as "C" then is for making
> plain old functions then about the layouts, the layout of
> the data and layout of the code as what results data,
> then about to/from memory and to/from general-purpose
> or g-registers and these kinds of things.
>
> For most people it's "compile with -O3",
> and hope for the best.
>
>
>
>
>
>
> /* file:vwsw-avx512.S */
>
> /*  NB: "EVEX-encoded" */
>
> .include "vwsw-common.S"
>
> .set COUNT_BLOCKS, 4
> .set COUNT_BANKS, 2
> .set FW, W * COUNT_BLOCKS
> .set FD, D * COUNT_BANKS
>
>
> .section .rodata
> .balign FW
> .include "vwsw-constants.S"
>
>
> .set vr_1_A, %zmm0
> .set vr_2_A, %zmm1
> .set vr_3_A, %zmm2
> .set vr_4_A, %zmm3
> .set vr_5_A, %zmm4
> .set vr_6_A, %zmm5
> .set vr_7_A, %zmm6
> .set vr_8_A, %zmm7
> .set vr_9_A, %zmm8
> .set vr_10_A, %zmm9
> .set vr_11_A, %zmm10
>
> .set tmpA_A, %zmm11
> .set tmpB_A, %zmm12
> .set tmpC_A, %zmm13
> .set tmpD_A, %zmm14
> .set tmpE_A, %zmm15
>
> .set vr_1_B, %zmm16
> .set vr_2_B, %zmm17
> .set vr_3_B, %zmm18
> .set vr_4_B, %zmm19
> .set vr_5_B, %zmm20
> .set vr_6_B, %zmm21
> .set vr_7_B, %zmm22
> .set vr_8_B, %zmm23
> .set vr_9_B, %zmm24
> .set vr_10_B, %zmm25
> .set vr_11_B, %zmm26
>
> .set tmpA_B, %zmm27
> .set tmpB_B, %zmm28
> .set tmpC_B, %zmm29
> .set tmpD_B, %zmm30
> .set tmpE_B, %zmm31
>
>
> .set reserved_maskregister_UNUSED, %k0
> .set reserved_maskregister_A, %k1
>
> /*  zero-out all registers (non-temporaries) */
> .macro _zeroall
> vzeroall
> .endm
>
> /*  load FWB aligned */
> .macro _load dst, mem
> vmovdqa \mem, \dst
> .endm
>
> /*  store FWB aligned */
> .macro _stor mem, src
> vmovdqa \src, \mem
> .endm
>
> /*  copy from src to dst */
> .macro _copy dst, src
> vmovdqa \src, \dst
> .endm
>
> /*  extract a WB word from src at block/bank to dst */
> .macro _extract dst, src, imm_block=0, imm_bank=0
> vextract \imm_block, \src, \dst
> .endm
>
> /*  insert a WB word from src to dst at block/bank */
> .macro _insert dst, src, imm_block=0, imm_bank=0
> vinsert \imm_block, \src, \src, \dst
> .endm
>
>
> /*  bit-wise-logical AND full-register */
> .macro _and dst, src
> /*  TODO: vpternlog for ternary-logical for AVX-512F profile */
> pand \src, \dst
> .endm
>
> /*  bit-wise-logical OR full-register */
> .macro _ior dst, src
> por \src, \dst
> .endm
>
> /*  bit-wise-logical XOR full-register */
> .macro _xor dst, src
> pxor \src, \dst
> .endm
>
> /* byte-wise signed min, results min(dst, src) in dst */
> /* preserves: rhs */
> .macro _mins dst, rhs
> vpminsb \dst, \rhs, \dst
> .endm
>
> /* byte-wise signed max, results max(dst, src) in dst */
> /* preserves: rhs */
> .macro _maxs dst, rhs
> vpmaxsb \dst, \rhs, \dst
> .endm
>
> /* byte-wise un-signed min, results min(dst, src) in dst */
> /* preserves: rhs */
> .macro _minu dst, rhs
> vpminub \dst, \rhs, \dst
> .endm
>
> /* byte-wise un-signed max, results max(dst, src) in dst */
> /* preserves: rhs */
> .macro _maxu dst, rhs
> vpmaxub \dst, \rhs, \dst
> .endm
>
> /*  byte-wise compare dst to rhs result 0x00/0xFF in dst */
> /*  preserves: rhs */
> .macro _cmpeq dst, rhs
> vpcmpeqb \dst, \rhs, reserved_maskregister_A
> vpmovm2b reserved_maskregister_A, \dst
> .endm
>
> /*  byte-wise compare dst < rhs (unsigned) to result 0x00/0xFF in dst */
> /*  preserves: rhs */
> .macro _cmplt dst, rhs, tmp1, tmp2
> _copy \tmp1, \rhs
> _tuss \tmp1, \tmp2
> _tuss \tmp2, \dst
> vpcmpgtb \tmp2, \tmp1, reserved_maskregister_A
> vpmovm2b reserved_maskregister_A, \dst
> .endm
>
> /*  byte-wise compare dst > rhs (unsigned) to result 0x00/0xFF in dst */
> /*  preserves: rhs */
> .macro _cmpgt dst, rhs, tmp1, tmp2
> _copy \tmp1, \rhs
> _tuss \tmp1, \tmp2
> _tuss \tmp2, \dst
> vpcmpgtb \tmp2, \tmp1, reserved_maskregister_A
> vpmovm2b reserved_maskregister_A, \dst
> .endm
>
> /*  bit-wise-logical NOT */
> .macro _not dst, tmp1
> _ones \tmp1
> _xor \dst, \tmp1
> .endm
>
> /*  load constant 0x00 byte-wise into dst */
> .macro _zero dst
> _xor \dst, \dst
> .endm
>
> /*  load constant 0xFF byte-wise into dst */
> .macro _ones dst
> _zero \dst
> _cmpeq \dst, \dst
> .endm
>
> /*  load constant 0x80 byte-wise into dst */
> .macro _bithi dst
> _load \dst, constant_bithi(%rip)
> .endm
>
> /*  load constant 0x01 byte-wise into dst */
> .macro _bitlo dst
> _load \dst, constant_bitlo(%rip)
> .endm
>
> /*  load constant 0xF0 byte-wise into dst */
> .macro _nybhi dst
> _load \dst, constant_nybhi(%rip)
> .endm
>
> /*  load constant 0x0F byte-wise into dst */
> .macro _nyblo dst
> _load \dst, constant_nyblo(%rip)
> .endm
>
> /*  load constant 0x10 byte-wise into dst */
> .macro _nybhibitlo dst
> _load \dst, constant_nybhibitlo(%rip)
> .endm
>
> /*  load constant 0x08 byte-wise into dst */
> .macro _nyblobithi dst
> _load \dst, constant_nyblobithi(%rip)
> .endm
>
> /*  shift right byte-wise (effective division) */
> .macro _shr dst, imm_byte_offset, tmp1
> .set IMM, \imm_byte_offset
> vpsrldq $IMM, \dst, \dst
> .endm
>
> /*  shift left byte-wise (effective multiplication) */
> .macro _shl dst, imm_byte_offset, tmp1
> .set IMM, \imm_byte_offset
> vpslldq $IMM, \dst, \dst
> .endm
>
> /*  shift forward byte-wise */
> .macro _shf dst, imm_byte_offset, tmp1
> .set IMM, \imm_byte_offset
> _shl \dst, $IMM
> .endm
>
> /*  shift backward byte-wise */
> .macro _shb dst, imm_byte_offset, tmp1
> .set IMM, \imm_byte_offset
> _shr \dst, $IMM
> .endm
>
> /*  press each of FWB from src_g byte-wise saturated 0x00/0xFF into
> dst_v */
> .macro _press dst_v, src_g
> movq \src_g, \dst_v
> vpshufb reserved_maskregister_UNUSED, constant_pressctrl(%rip), \dst_v,
> \dst_v
> _and   \dst_v, constant_pressmask(%rip)
> _cmpeq \dst_v, constant_pressmask(%rip)
> .endm
>
> /*  pick each of FWB from src_v high-bit as FWb into dst_g */
> .macro _pick dst_g, src_v, tmp1, g_tmp
> vpmovb2m \src_v, reserved_maskregister_A
> kmovb reserved_maskregister_A, \dst_g
> .endm
>
> /* translate-signed-to-unsigned byte-wise in dst */
> .macro _tsus dst, tmp1
> _bithi \tmp1
> _xor \dst, \tmp1
> .endm
>
> /* translate-unsigned-to-signed byte-wise in dst */
> .macro _tuss dst, tmp1
> _bithi \tmp1
> paddb \tmp1, \dst
> .endm
>
> /*  true-if-false byte-wise translates 0x00 to 0xFF in dst */
> .macro _tiff dst, tmp1, tmp2
> _zero \tmp1
> _copy \tmp2, \dst
> _cmpeq \tmp2, \tmp1
> _ior \dst, \tmp2
> .endm
>
> /* table/shuffle, as pshufb or tbl */
> .macro _tshuf dst, constant_name
> vpshufb reserved_maskregister_UNUSED, \constant_name\()(%rip), \dst, \dst
> .endm
>
> /* saturating un-signed byte-wise addition, overflow clamped 255 */
> .macro _satuadd dst, src
> paddusb \src, \dst
> .endm
>
> /* saturating signed byte-wise addition, overflow clamped 127, underflow
> clamped -128 */
> .macro _satsadd dst, src
> paddsb \src, \dst
> .endm
>
> /*  saturate the high-bit set/clear to 0xFF/0x00 in dst */
> .macro _sathi dst, tmp1
> _bithi \tmp1
> _and \tmp1, \dst
> _cmpeq \dst, \tmp1
> .endm
>
> /*  saturate the low-bit set/clear to 0xFF/0x00 in dst */
> .macro _satlo dst, tmp1
> _bitlo \tmp1
> _and \tmp1, \dst
> _cmpeq \dst, \tmp1
> .endm
>
> /*  saturate any set-bit to 0xFF else 0x00 in dst */
> .macro _saton dst, tmp1
> _zero \tmp1
> _cmpeq \dst, \tmp1
> _not \dst, \tmp1
> .endm
>
> .macro _tease1 dst, imm_bit_offset, tmp1
> .set IMM, (8 - 1 - \imm_bit_offset)
> _load \tmp1, constant_tease1(%rip)
> vpsrlw reserved_maskregister_UNUSED, $IMM, \dst, \dst
> _and \dst, tmp1
> .endm
>
> .macro _tease2 dst, imm_bit_offset, tmp1
> .set IMM, (8 - 2 - \imm_bit_offset)
> _load \tmp1, constant_tease2(%rip)
> vpsrlw reserved_maskregister_UNUSED, $IMM, \dst, \dst
> _and \dst, tmp1
> .endm
>
> .macro _tease3 dst, imm_bit_offset, tmp1
> .set IMM, (8 - 3 - \imm_bit_offset)
> _load \tmp1, constant_tease3(%rip)
> vpsrlw reserved_maskregister_UNUSED, $IMM, \dst, \dst
> _and \dst, tmp1
> .endm
>
> .macro _tease4 dst, imm_bit_offset, tmp1
> .set IMM, (8 - 4 - \imm_bit_offset)
> _load \tmp1, constant_tease4(%rip)
> vpsrlw reserved_maskregister_UNUSED, $IMM, \dst, \dst
> _and \dst, tmp1
> .endm
>
>
>
>

So, then when looking into tow_str and fro_str, "toward-string" and 
"from-string", then it's not necessarily an unusual or unique idea to 
write to what one of these "v-blocks" makes as a model of computation 
itself, for example when there's for 
SIMD/single-instruction-multiple-data, the complementary concept 
SWAR/simd-within-a-register,
about emulating a v-block in g-registers, then figuring the actual 
processor has 1-20+ v-blocks sort of like as for giving the thread for 
some consecutive and repetitive functions, 1-20+ aligned, reasonably 
sized memory-buffers.

Then, this "Viswath:  vector-wide-scalar-word" approach,
is basically about that this as a model of a self-contained machine:
is a bunch of un-rolled small loops, in multiples for example of
16-bytes or 8-shorts or 4-ints/singles or 2-longs/doubles, usually
enough about the datatypes "byte, word (16b), double-word (32b),
quad-word (64b), double-quad-word (128b)", these being the
"data-types" in "Intel x86 assembler", or correspondingly ARM,
since ARM admits have this same sort of profile for these considered
instructions (which after looking around at all the specs of the ISAs,
these are pretty much all the operations available everywhere).



For example, here's for ARM NEON, notice it's the same macros
with the same signatures the same sources & destinations and
the same given needed-temporaries as AMD AVX512, or AVX2
or SSE4, basically, also ARM SVE, more-than-less.




/* file:vwsw-neon.S */

.include "vwsw-common.S"

.set COUNT_BLOCKS, 1
.set COUNT_BANKS, 2
.set FW, W * COUNT_BLOCKS
.set FD, D * COUNT_BANKS


.section .rodata
.balign FW
.include "vwsw-constants.S"


.set vr_1_B, v1
.set vr_2_B, v2
.set vr_3_B, v3
.set vr_4_B, v4
.set vr_5_B, v5
.set vr_6_B, v6
.set vr_7_B, v7
.set vr_8_B, v8
.set vr_9_B, v9
.set vr_10_B, v10
.set vr_11_B, v11

.set tmpA_B, v12
.set tmpB_B, v13
.set tmpC_B, v14
.set tmpD_B, v15
.set tmpE_B, v16

.set vr_1_B, v17
.set vr_2_B, v18
.set vr_3_B, v19
.set vr_4_B, v20
.set vr_5_B, v21
.set vr_6_B, v22
.set vr_7_B, v23
.set vr_8_B, v24
.set vr_9_B, v25
.set vr_10_B, v26
.set vr_11_B, v27

.set tmpA_B, v28
.set tmpB_B, v29
.set tmpC_B, v30
.set tmpD_B, v31
.set tmpE_B, v32

/*  zero-out all registers (non-temporaries) */
.macro _zeroall
_zero vr_1_B
_zero vr_2_B
_zero vr_3_B
_zero vr_4_B
_zero vr_5_B
_zero vr_6_B
_zero vr_7_B
_zero vr_8_B
_zero vr_9_B
_zero vr_10_B
_zero vr_11_B
_zero vr_1_B
_zero vr_2_B
_zero vr_3_B
_zero vr_4_B
_zero vr_5_B
_zero vr_6_B
_zero vr_7_B
_zero vr_8_B
_zero vr_9_B
_zero vr_10_B
_zero vr_11_B
.endm


/*  load 16B aligned */
.macro _load dst, mem
ldr \dst\().16b, \mem
.endm

/*  store 16B aligned */
.macro _stor mem, src
str \mem, \src\().16b
.endm

/*  copy from src to dst */
.macro _copy dst, src
mov \dst, \src
.endm

/*  extract a 16B word from src at block/bank to dst */
.macro _extract dst, src, imm_block=0, imm_bank=0
/*  no-op */
.endm

/*  insert a 16B word from src to dst at block/bank */
.macro _insert dst, src, imm_block=0, imm_bank=0
/*  no-op */
.endm

/*  bit-wise-logical AND full-register */
.macro _and dst, src
and \dst\().16b, \src\().16b, \dst\().16b
.endm

/*  bit-wise-logical OR full-register */
.macro _ior dst, src
orr \dst\().16b, \src\().16b, \dst\().16b
.endm

/*  bit-wise-logical XOR full-register */
.macro _xor dst, src
eor \dst\().16b, \src\().16b, \dst\().16b
.endm

/* byte-wise signed min, results min(dst, src) in dst */
/* preserves: rhs */
.macro _mins dst, rhs
smin \rhs\().16b, \dst\().16b
.endm

/* byte-wise signed max, results max(dst, src) in dst */
.macro _maxs dst, rhs
smax \rhs\().16b, \dst\().16b
.endm

/* byte-wise un-signed min, results min(dst, src) in dst */
/* preserves: rhs */
.macro _minu dst, rhs
umin \rhs\().16b, \dst\().16b
.endm

/* byte-wise un-signed max, results max(dst, src) in dst */
.macro _maxu dst, rhs
umax \rhs\().16b, \dst\().16b
.endm

/*  byte-wise compare dst to rhs result 0x00/0xFF in dst */
.macro _cmpeq dst, rhs
cmeq \dst\().16b, \dst\().16b, \rhs\().16b
.endm

/*  byte-wise compare dst < rhs (unsigned) to result 0x00/0xFF in dst */
/*  preserves: rhs */
.macro _cmplt dst, rhs, tmp1, tmp2
_copy \tmp1, \rhs
_tuss \tmp2, \tmp1
_tuss \tmp1, \dst
cmhi \dst\().16b, \tmp1\().16b, \tmp2\().16b
.endm

/*  byte-wise compare dst > rhs (unsigned) to result 0x00/0xFF in dst */
/*  preserves: rhs */
.macro _cmpgt dst, rhs, tmp1, tmp2
_copy \tmp1, \rhs
_tuss \tmp2, \tmp1
_tuss \tmp1, \dst
cmhi \dst\().16b, \tmp1\().16b, \tmp2\().16b
.endm

/*  bit-wise-logical NOT */
.macro _not dst, tmp1
not \dst\().16b, \dst\().16b
.endm

/*  load constant 0x00 byte-wise into dst */
.macro _zero dst
movi \dst\().16b, #0x00
.endm

/*  load constant 0xFF byte-wise into dst */
.macro _ones dst
movi \dst\().16b, #0xFF
.endm

/*  load constant 0x80 byte-wise into dst */
.macro _bithi dst
movi \dst\().16b, #0x80
.endm

/*  load constant 0x01 byte-wise into dst */
.macro _bitlo dst
movi \dst\().16b, #0x01
.endm

/*  load constant 0xF0 byte-wise into dst */
.macro _nybhi dst
movi \dst\().16b, #0xF0
.endm

/*  load constant 0x0F byte-wise into dst */
.macro _nyblo dst
movi \dst\().16b, #0x0F
.endm

/*  load constant 0x10 byte-wise into dst */
.macro _nybhibitlo dst
movi \dst\().16b, #0x10
.endm

/*  load constant 0x08 byte-wise into dst */
.macro _nyblobithi dst
movi \dst\().16b, #0x08
.endm

/*  shift right byte-wise (effective division) */
.macro _shr dst, imm_byte_offset, tmp1
_zero \tmp1
ext \dst\().16b, \tmp1\().16b, \dst\().16b, #(\imm_byte_offset)
.endm

/*  shift left byte-wise (effective multiplication) */
.macro _shl dst, imm_byte_offset, tmp1
_zero \tmp1
ext \dst\().16b, \dst\().16b, \tmp1\().16b, #(16 - \imm_byte_offset)
.endm

/*  shift forward byte-wise */
.macro _shf dst, imm_byte_offset, tmp1
_shr \imm_byte_offset, \dst, \tmp1
.endm

/*  shift backward byte-wise */
.macro _shb dst, imm_byte_offset, tmp1
_shl \imm_byte_offset, \dst, \tmp1
.endm

/*  press each of 16b from src_g byte-wise saturated 0x00/0xFF into dst_v */
.macro _press dst_v, src_g
mov \dst_v, \src_g
tbl \dst_v, constant_pressctrl(%rip), \dst_v
_and   constant_pressmask(%rip), \dst_v
_cmpeq constant_pressmask(%rip), \dst_v
.endm

/*  pick each of 16B from src_v high-bit as 16b into dst_g */
.macro _pick dst_g, src_v, tmp1, g_tmp
_load constant_pressmask(%rip), \tmp1
_and \tmp1, \src_v, \src_v
_load constant_octaquadhi, \tmp1
_and \tmp1, \src_v, \src_v
addv \src_v, \src_v
mov \g_tmp, \src_v
_load constant_pressmask(%rip), \tmp1
_and \tmp1, \src_v, \src_v
_load constant_octaquadlo, \tmp1
_and \tmp1, \src_v, \src_v
addv \src_v, \src_v
mov \dst_g, \src_v
add \dst_g, \dst_g, \g_tmp, LSL #8
.endm

/* translate-signed-to-unsigned byte-wise in dst */
.macro _tsus dst, tmp1
_bithi \tmp1
_xor \dst, \tmp1
.endm

/* translate-unsigned-to-signed byte-wise in dst */
.macro _tuss dst, tmp1
_bithi \tmp1
add \dst\().16b, \dst\().16b, \tmp1\().16b
.endm

/*  true-if-false byte-wise translates 0x00 to 0xFF in dst */
.macro _tiff dst, tmp1, tmp2
_zero \tmp1
_copy \tmp2, \dst
_cmpeq \tmp2, \tmp1
_ior \dst, \tmp2
.endm


/* saturating signed byte-wise addition, overflow clamped 127, underflow 
clamped -128 */
.macro _satsadd dst, src
sqadd \dst\().16b, \src\().16b
.endm

/* saturating un-signed byte-wise addition, overflow clamped 255, 
underflow clamped 0 */
.macro _satuadd dst, src
uqadd \dst\().16b, \src\().16b
.endm

/*  saturate the high-bit set/clear to 0xFF/0x00 in dst */
.macro _sathi dst, tmp1
_bithi \tmp1
_and \tmp1, \dst
_cmpeq \dst, \tmp1
.endm

/*  saturate the low-bit set/clear to 0xFF/0x00 in dst */
.macro _satlo dst, tmp1
_bitlo \tmp1
_and \tmp1, \dst
_cmpeq \dst, \tmp1
.endm

/*  saturate any set-bit to 0xFF else 0x00 in dst */
.macro _saton dst, tmp1
_zero \tmp1
_cmpeq \tmp1, \dst
_not \dst, \tmp1
.endm



.macro _tease1 dst imm_bit_offset, tmp1
ushr \dst\().16b, #(8 - 1 - imm_bit_offset)
.endm

.macro _tease2 dst imm_bit_offset, tmp1
ushr \dst\().16b, #(8 - 2 - imm_bit_offset)
.endm

.macro _tease3 dst imm_bit_offset, tmp1
ushr \dst\().16b, #(8 - 3 - imm_bit_offset)
.endm

.macro _tease4 dst imm_bit_offset, tmp1
ushr \dst\().16b, #(8 - 4 - imm_bit_offset)
.endm





Technical Details
Message-ID: <shucnbiQKpaGNpP2nZ2dnZfqn_adnZ2d@giganews.com>
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!weretis.net!feeder9.news.weretis.net!border-4.nntp.ord.giganews.com!nntp.giganews.com!Xl.tags.giganews.com!local-2.nntp.ord.giganews.com!news.giganews.com.POSTED!not-for-mail
References: <11ejv6f$fo9e$1@dont-email.me> <11ekiss$pbdj$1@dont-email.me> <CtKcnYQfdKaPRpD2nZ2dnZfqnPudnZ2d@giganews.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!weretis.net!feeder9.news.weretis.net!border-4.nntp.ord.giganews.com!nntp.giganews.com!Xl.tags.giganews.com!local-2.nntp.ord.giganews.com!news.giganews.com.POSTED!not-for-mail
NNTP-Posting-Date: Tue, 01 Dec 2026 11:10:19 +0000
Subject: Re: optimising float3
Newsgroups: comp.lang.c
References: <11ejv6f$fo9e$1@dont-email.me> <11ekiss$pbdj$1@dont-email.me>
 <CtKcnYQfdKaPRpD2nZ2dnZfqnPudnZ2d@giganews.com>
From: Ross Finlayson <ross.a.finlayson@gmail.com>
Date: Tue, 1 Dec 2026 03:09:45 -0800
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101
 Thunderbird/38.6.0
MIME-Version: 1.0
In-Reply-To: <CtKcnYQfdKaPRpD2nZ2dnZfqnPudnZ2d@giganews.com>
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
Message-ID: <shucnbiQKpaGNpP2nZ2dnZfqn_adnZ2d@giganews.com>
Lines: 803
X-Usenet-Provider: http://www.giganews.com
X-Trace: sv3-N6L6jDYCHFpHECP+8REdc6HBh8lJLH4LVdg80/abRr8cGT/jEdRsREHWaohstymFR0HEkGhk6Bpfq8c!kREqr5bTJT8shA7D45XDRa/BouvJsWGGs10Jb7SmGs5mpMNaAi7Y88QzWszT5rzyXUpQlpOyBiET
X-Complaints-To: abuse@giganews.com
X-DMCA-Notifications: http://www.giganews.com/info/dmca.html
X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers
X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly
X-Postfilter: 1.3.40