bug-grep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#23713: [PATCH 2/6] maint: replace bitwise with logical OR


From: Paul Eggert
Subject: bug#23713: [PATCH 2/6] maint: replace bitwise with logical OR
Date: Thu, 18 Aug 2016 22:54:54 -0700
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0

Thanks. I see this patch was also installed in June so will close the bug 
report.

I have a bone to pick with it, though. For bool expressions without side effects, bitwise ops are logically equivalent to short-circuit ops. On modern platforms where operands are trivial, short-circuit ops are often a tad bigger and can have more branch-prediction overhead, which is a tiny bit worse for performance. In the examples you the short-circuit ops all generate bigger machine code on my platform (GCC 6.1 x86-64). So I'm mildly inclined to revert the change and have pushed the attached. To some extent this is a style issue; yes, there is a long tradition in C of using short-circuit ops for bool, but I don't mind too much diverging slightly from the common style in order to make the point.

For clarity this patch also uses c_isdigit (which uses a switch) instead of && though GCC seems to generate the same code either way.

Attachment: 0001-grep-prefer-bitwise-to-short-circuit-when-shorter.patch
Description: Text Data


reply via email to

[Prev in Thread] Current Thread [Next in Thread]