Write mask and swizzle syntax for C++

Started by
11 comments, last by snk_kid 17 years, 4 months ago
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" ?
--Michael Fawcett
Advertisement
Quote:Original post by snk_kid
Pointer to data members might be helpful to you, take a look here for some inspiration.


I actually followed that thread with some interest when it took place. In this case I am missing how it would solve the problem, especially since I've been convinced that the functionality doesn't actually need help, since the issue reported now seems like a non-issue (user error, taking address of function's return value).

The cool thing is that the macro and the "slick trick" you posted are compatible and could be used together. Maybe I'll do this some time...
--Michael Fawcett
Quote:Original post by mfawcett
In this case I am missing how it would solve the problem, especially since I've been convinced that the functionality doesn't actually need help, since the issue reported now seems like a non-issue (user error, taking address of function's return value).


I haven't read everything in this thread so i don't know what the problem is, just giving some ideas out.

This topic is closed to new replies.

Advertisement