emacs-bug-tracker
[Top][All Lists]
Advanced

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

[debbugs-tracker] bug#23713: closed ([PATCH 2/6] maint: replace bitwise


From: GNU bug Tracking System
Subject: [debbugs-tracker] bug#23713: closed ([PATCH 2/6] maint: replace bitwise with logical OR)
Date: Fri, 19 Aug 2016 05:56:02 +0000

Your message dated Thu, 18 Aug 2016 22:54:54 -0700
with message-id <address@hidden>
and subject line Re: bug#23713: [PATCH 2/6] maint: replace bitwise with logical 
OR
has caused the debbugs.gnu.org bug report #23713,
regarding [PATCH 2/6] maint: replace bitwise with logical OR
to be marked as done.

(If you believe you have received this mail in error, please contact
address@hidden)


-- 
23713: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=23713
GNU Bug Tracking System
Contact address@hidden with problems
--- Begin Message --- Subject: [PATCH 2/6] maint: replace bitwise with logical OR Date: Tue, 7 Jun 2016 01:37:39 -0500
* src/grep.c (main): replace bitwise ORs with logical ORs where it
makes sense (when dealing with boolean conditions as opposed to
bitmasks).
---
 src/grep.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/grep.c b/src/grep.c
index d812bae..9776507 100644
--- a/src/grep.c
+++ b/src/grep.c
@@ -2623,12 +2623,12 @@ main (int argc, char **argv)
      implementation, -q overrides -l and -L, which in turn override -c.  */
   if (exit_on_match)
     list_files = 0;
-  if (exit_on_match | list_files)
+  if (exit_on_match || list_files)
     {
       count_matches = false;
       done_on_match = true;
     }
-  out_quiet = count_matches | done_on_match;
+  out_quiet = count_matches || done_on_match;
 
   if (out_after < 0)
     out_after = default_context;
-- 
2.8.0.rc3




--- End Message ---
--- Begin Message --- Subject: Re: 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


--- End Message ---

reply via email to

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