Design of a low-level C++ template SIMD library [pdf]
ti.uni-bielefeld.de
ti.uni-bielefeld.de
Since it's not too easy to spot, the paper refers to http://www.ti.uni-bielefeld.de/html/people/moeller/tsimd_war... and that page has a "Software Download" section with a custom license that has significant arbitrary restrictions:
* "agrees not to transfer [...] to other individuals"
* "agrees not to use the software [...] where property of humans [is] endangered"
* etc.
I.e. this "contribution" would only be relevant if was usable under a really free license, e.g. one of: https://www.gnu.org/licenses/license-list.html#SoftwareLicen...
> (3) The software and the databases will only be used for the licensee's own scientific study, scientific research, or academic teaching. Use for commercial or business purposes is not permitted. [...]
is quite limiting.
What's more is that as this HN post conveys, there are plenty of libraries like this, many being developed under much less bizarre licenses.
The thing that I find particularly bizarre is that I have a lot of understanding for people who craft custom licenses to make money to support a project (or do dual-license stuff). But this just seems self-defeating. I honestly just stopped reading at LICENSE.
There's also a ton of frisky legal bullshit:
"(11) Should any provision of this license agreement be or become invalid, this shall not affect the validity of the remaining provisions. Any invalid provision shall be replaced by a valid provision which corresponds to the meaning and purpose of the invalid provision."
Ah yes, the old "if my clause is legal garbage, magically replace it by what I meant and enforce that".
> I.e. this "contribution" would only be relevant if was usable under a really free license, e.g. one of: https://www.gnu.org/licenses/license-list.html#SoftwareLicen....
The ironic thing about your comments is that half the open source projects out there would reject the code anyhow if it was GPLed. I'm not sure why we should expect the author of such a paper to pick the magic combination of licenses (because you'd have to have multiple licenses, and that's a pain in the butt) to make everyone happy, when making everyone happy is not the purpose, writing an academic paper is.
Sometimes the value you're going to get from code comes simply from reading it or using it as a reference, and that is okay.
Here's the gist of it:
typedef float vec4f __attribute__((vector_size(4 * sizeof(float))));
vec4f a = { 1.0, 2.0, 3.0, 4.0 }, b = { 5.0, 6.0, 7.0, 8.0 };
vec4f c = (2.0 * a) + (a + b * b); // with -ffast-math, this will emit a fused multiply-and-add (FMA)
Note: if you look inside the intrinsics headers (xmmintrin.h, arm_neon.h, etc) supplied by GCC, you'll find that it uses these internally. E.g. _mm_add_ps(a, b) is defined as a+b.I work with basic 3d math and physics, so I don't need that much and just having 4-wide vectors is good enough for me.
I've also found out that you can use vector widths that are not available in the target machine. E.g. 4 x double vectors work fine even without 256 bit registers, the compiler will split the vector and use two 128 bit registers and emit two instructions. This might also work for using 16 x float vectors for 4x4 matrices.
Some C++ overloading magic would be useful for naming things (e.g. no need for dot4f vs dot4d).
I've been trying to get some time to write an article about the ins and outs of using vector extensions, but haven't got there yet. Some effort would also be required to put together a decent library of basic arithmetic (dot, cross, quaternion product, matrix product & inverse, etc) as well as basic libm functions (sin, cos, log, exp). I haven't had the time to put together a comprehensive (and well tested) collection of these nor have I found any open source library that would do.
[0] https://gcc.gnu.org/onlinedocs/gcc/Vector-Extensions.html [1] https://godbolt.org/g/N9VvXZ
"libsimdpp is a portable header-only zero-overhead C++ low level SIMD library." Not yet sure how it compares to the linked library.
For anything more complex, you need to write SIMD code explicitly. Getting good performance requires writing code where the full width of the registers is used. If the compiler falls back to using scalar arithmetic, it tends to pollute the surrounding code with register spilling when registers are required for scalar arithmetic (ie. only the 1st component of the xmm0 register is used).
Writing SIMD code is quite a bit of effort if you need to get it working well.
Autovectorised SIMD code would probably need something like an "AUTOVEC" annotation at every single line to be effective which defeats the purpose of autovectorisation in the first place.
If you only need SIMD for stream processing, autovectorisation is OK.
Only there’re multiple autovectorizers in C. The default one is indeed very fragile. But the one in OpenMP 4 is better: http://www.hpctoday.com/hpc-labs/explicit-vector-programming...
But even that OMP 4 is very limited.
One reason is many SSE operations don’t map to C: approximate math (rcpps, rsqrtps), composite operations (FMA, AES), and saturated math (there’re dozens instruction for manipulating 8 and 16 bit numbers with saturation, i.e. on over/underflow the numbers don’t wrap around by stripping highest byte[s] but stay at the min/max 8/16 bit value).
Another reason is some SSE instructions operate horizontally (phminposuw, pmaddubsw, psadbw, dpps), or are advanced swizzle instructions (shufps, pshufb, pshuflw, pshufhw, pslldq), both are very hard to autogenerate from these #pragma omp simd loops.
which extends C with data parallel constructs. Notably it can generate generic wide code as long as the implementation of different intrinsic dis provided.
Custom licenses are a headache and I always wonder whether the academics who promulgate them wonder why no-one uses their software.
https://bitbucket.org/eschnett/vecmathlib/src
Also includes implementation of functions like sin cos
https://eigen.tuxfamily.org/dox/TopicInsideEigenExample.html
IceLake is expected to do AVX512.