On 12/01/2026 03:09 AM, Ross Finlayson wrote:
> 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 */ >>
> 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 */ >
Of course when I say "that's all there is to it", it's particularly about what's "byte-wise" on the SIMD vector-units, that the usual wider account was first single-floats and double-floats then int32's then uint32's then half-floats (16-bits) and the like, about word/dword/qword, then that the accounts of arithmetic which makes one of: arithmetic, bit-wise logical, or comparison, is granular in those sizes, for adding two vectors. (This is the "vertical" not getting yet into the "horizontal".) Then probably there's either "array-of-structs" or "struct-of-arrays" approach, that basically independent terms like the axes of 3-D then make for: struct { float x; float y; float z; float unused; } or for like struct { short r; short g; short b; short a; } so that then that equals 8-bytes and two of those load on a 16-byte alias ("virtual vector-register") via insert/extract on a 16, 32, 64, ... byte wide "full vector-register", or full-vector wide as long as it aligns and fits, then for v3d state[N]; v3d change[N]; then makes for void add_single_v3d(v3d* state_1, v3d* change_1) { state_1.x += change_1.x; state_1.y += change_1.y; state_1.z += change_1.z; state_1.unused += change_1.unused; } void add_vector_v3d(v3d* state_v, v3d* change_v, size_t count) { for (int i = 0; i < count; i++) { add_single_v3d( &(*state_v++), &(*change_v++) ); } } and compile with "-O3" and hope for the best.