Use /2 and 2* instead of >>1 and <<1 which are tricky with signed types

Today's compilers generate shift instructions to perform division and
multiplications by powers of 2 [1]. `(x >> 1)` looks straightforward enough, but
if x is signed the code will fail when x < 0. The compiler knows better: use
`x / 2`.

That's why we have code like this:

    (long)((long_u)Rows >> 1))

instead of the cleaner version that generates the same or better machine code:

    Rows / 2

[1] http://goo.gl/J4WpG7
This commit is contained in:
Felipe Oliveira Carvalho
2014-04-19 13:12:04 -03:00
committed by Thiago de Arruda
parent 9a5b3eee5f
commit db23cb05d1
6 changed files with 11 additions and 13 deletions

View File

@@ -7162,7 +7162,7 @@ find_internal_func (
* Find the function name in the table. Binary search.
*/
while (first <= last) {
x = first + ((unsigned)(last - first) >> 1);
x = first + (last - first) / 2;
cmp = STRCMP(name, functions[x].f_name);
if (cmp < 0)
last = x - 1;