loop anyway... you C++ people tend to overtax compiler with
optimizations. Is it really necessary to do (i == j) * factor
when (i == j) ? factor : 0 is easier for compiler to grok?

Of course I tried it. It's even slower. Doesn't help the compiler unroll the loop, and now there's a branch at each iteration.

This is another compiler bug. Note however, that if I want to use oldskool tricks to remove ?:, I would instead do -(i == j) & factor.

The compiler should be able to transform the ?: expression to the faster form (and to transform the latter into ?: on architectures where it's better) but it does this quite late in the compilation. It can happen that things are screwed up by the time we reach that part of the optimization pipeline, and the ?: idiom is not recognized anymore.

We are currently discussing including ?: in the compiler's intermediate representation, instead of representing it as an "if" statement; this might be a case where it helps.

Paolo

Reply via email to