C/C++ optimization: negate doubles fast -
I have to reject a large number of doubles quickly if I generate bit_generator 0 The sign should be changed. If generates bit_generator 1, nothing happens, the loop is run multiple times and bit_generator is very fast, faster than the case 1 on my platform case 2 Is from It seems that my CPU does not like branching. Is there a fast and portable way to do this? What do you think about 3?
generates 0 and 1 int bit_generator; // large vector (C ++) vector & lt; Double & gt; V; 1 for size 1 (size_t i = 0; i Edit: Added 4th and C-tag, because the vector can be a plain array. Since I can control how doubles are made, I redesigned the code as shown in 4. This avoids the extra multiplication and equality in the branches. I think it's pretty fast on all platforms.
Unless you want to convert the vector into a loop, lift V.size () for expression, i.e. const unsigned SZ = v.size (); For (size_t i = 0; i
If the compiler is in bit_generator (), then this compiler can be very difficult to prove that v.size () can not be changed, which loop unrolling Or vectoring impossible.
UPDATE: I have done some tests and my machine seems fastest on method 2. However, it seems to be fast to use a pattern that I call "group action" :-) In fact, you can group multiple values in one value and switch to it:
const size_t SZ = v.size (); (Size_t i = 0; i
wrap the loop
Comments
Post a Comment