SIMD Hints
From Manta
[edit]
Hints for writting SIMD code in Manta
SSE or more generically SIMD code segments in Manta are placed in #ifdef blocks. These blocks are used if the cmake variable MANTA_REAL is set to float and the cmake variable MANTA_SSE is enabled.
[edit]
Generic SIMD Code Template
Most SIMD code in manta performs operations on ray packet elements. This code usually follows the form:
#ifdef MANTA_SSE
int b = (rays.rayBegin + 3) & (~3);
int e = rays.rayEnd & (~3);
// Check to see if there are less than 4 elements.
if (b == e) {
// Iterate over all of the rays.
for(int i=rays.rayBegin;i<rays.rayEnd;i++) {
// NON-SIMD CODE.
}
} else {
int i = rays.rayBegin;
// Do the non aligned in front
for(;i<b;++i) {
// NON-SIMD CODE
}
// Do the aligned in the middle
for(;i<e;i+=4) {
// SIMD CODE
}
// Do the non aligned in end
for(;i<rayEnd;++i) {
// NON-SIMD CODE
}
}
#else
// NON-SIMD CODE
#endif
