Compilers can surprise
18, Apr, 2019Today I was testing one exotic compiler (vbcc) on exotic platform (Amiga). I had function
static inline f32v4 f32v4_add(f32v4 a, f32v4 b) {
return (f32v4) {a.x+b.x, a.y+b.y, a.z+b.z, a.w+b.w};
}
and a macro
#define F32V4_ADD(a, b) (f32v4) { (a).x+(b).x, (a).y+(b).y, (a).z+(b).z, (a).w+(b).w }
I was iterating (two fors) in tight loop adding two consecutive values, something like:
arr[i] = f32v4_add(a[i-1], a[i-2])
The macro version on average was 3.7 times faster! But, why? Looking into assembler I have found that function was properly inlined. However, there was some magic around loop handling, address registers and addressing modes of fmove operations. Optimizer got lost by this inline function.
p.s. The gcc was slower than both.
- Posted by michal in
- Add a comment