Optimized CPU version of TVAL3 algorithm