3 ms·
> *techinically it's even true for CPU in some cases... Practically in all cases. It isn't as bad to branch as it is in a GPU. But branch prediction in CPUs is
by c4mpute 3y ago
> *techinically it's even true for CPU in some cases...
Practically in all cases. It isn't as bad to branch as it is in a GPU. But branch prediction in CPUs is an important factor for performance critical code, and getting it right (e.g. by switching the 'branch/no branch' conditions in assembler or using branch hints such as likely/unlikely in the linux kernel) can make a very noticable difference. I've seen a factor of 2 in some tight loops, and 10% should often be achievable.
And sometimes, by using bitmasks or multiplication by 1/0, one can design branchless code which can enable the use of e.g. more AVX instructions on CPUs, while also avoiding branch miss penalties.