(Sorry if this sounds like a rant, but it's a real question and I'd appreciate real answers)
I understand that since C is so old, it might have not made sense to add it back then(MMX didn't even exist back then). But since then there was C99, and still there are no standard for SIMD variables(as far as I know).
By "SIMD variables", I mean something like:
vec2_int a = {2, 2};
vec2_int b = {3, 3};
a += b;
I also understand that this can be done with structs and (in theory) the compiler should optimize it to use SIMD when appropriate anyway.
But I recently saw a post from Qt Labs which includes an example with types like "__m128i"(which look clearly non-standard), inste开发者_如何学Goad of relying on optimizations. Considering Qt is advertising this as greatly improving Qt's speed, I'm guessing compiler optimizations are being insufficient, at least for some programmers.
If it was just C, I'd think C was being stupid. But, as far as I know, newer languages such as C++, Java and C# don't include these either. C# has Mono.SIMD but it's not a primitive type(and since C# has a "decimal" keyword, I don't think they were trying to save types).
So here's what I'm noticing: Languages with vector primitive types seem to be the exception and not the rule. Because vector primitive types look so obvious, I'm guessing there's got to be some decent reasons NOT to include these types.
Does anyone here know why these types are so frequently excluded? Some links to rationales against adding them?
Because not all processors support SIMD instructions. Languages like C and C++ (and even Java and C#) are designed to be used on different kinds of hardware, like microcontrollers, in addition to desktop computers.
Currently, vectorization of algorithms is not automatic (although that is being actively researched). Algorithms that are "vectorizable" must be explicitly written to take advantage of any SIMD capabilities of the execution environment.
精彩评论