Quote:Original post by Christer Ericson
That's certainly possible, of course, but perhaps unlikely as I've implemented SIMD libraries on e.g. PS2 and PS3 and seen happen exactly what I mentioned. It is well-known that e.g. gcc is notoriously bad in this respect, and will spill to memory as soon as you take a reference of a vector object (whether you inline or not). On e.g. the PS3 (and the XBOX 360), needlessly spilling registers to memory will kill CPU performance and the type of code-shenanigans you posted are a complete no-no for that reason. These problems are well-known in the console developer circuits and are frequently discussed in the (closed access) developer fora.
Perhaps you should try implementing a SIMD-based vector library for yourself and see. You might be surprised!
Sigh, I have for the PS2, not PS3. I still think you are overstating w.r.t. the code I have posted. I think you are misreading the code, which I admit is very convoluted due to everything being generated by the preprocessor, or misunderstanding how it would be used. There are no "code-shenanigans" taking place. The macro simply generates all possible permutations of xyzw of length 2, 3, and 4. The actual function body that implements the swizzle is a demonstration (the vector classes aren't even close to complete on purpose. The whole point was the macro).
Like I said, you could have every swizzle function end up looking like this
// This could be any code you want. The interesting part is the macro will// give you every possible 2, 3, and 4 component permutation as a sequencefloat4 wzyx() const { return float4(w, z, y, x); }float4 wzxy() const { return float4(w, z, x, y); }...// Instead of what it is currently...vec4<float &> wzyx() const { return vec4<float &>(w, z, y, x); }vec4<float &> wzxy() const { return vec4<float &>(w, z, x, y); }
if you didn't care about write masks and wanted to remove all references. Then where would the problem be? Everything is a value-based contiguous memory vector at that point, and you get swizzle functionality. Surely you can't still claim that this is an "utter no-no", or "have serious performance issues", or be (my favorite) "outright harmful" ?