git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH] fsm-listen-daarwin: combine bit operations
@ 2023-01-17 21:25 Rose via GitGitGadget
  2023-01-17 21:54 ` [PATCH v2] fsm-listen-darwin: " Rose via GitGitGadget
  0 siblings, 1 reply; 5+ messages in thread
From: Rose via GitGitGadget @ 2023-01-17 21:25 UTC (permalink / raw)
  To: git; +Cc: Rose, Seija Kijin

From: Seija Kijin <doremylover123@gmail.com>

Signed-off-by: Seija Kijin <doremylover123@gmail.com>
---
    fsm-listen-daarwin: combine bit operations
    
    Signed-off-by: Seija Kijin doremylover123@gmail.com

Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-1437%2FAtariDreams%2Fdarwin-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-1437/AtariDreams/darwin-v1
Pull-Request: https://github.com/git/git/pull/1437

 compat/fsmonitor/fsm-listen-darwin.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/compat/fsmonitor/fsm-listen-darwin.c b/compat/fsmonitor/fsm-listen-darwin.c
index 97a55a6f0a4..fccdd21d858 100644
--- a/compat/fsmonitor/fsm-listen-darwin.c
+++ b/compat/fsmonitor/fsm-listen-darwin.c
@@ -129,9 +129,9 @@ static int ef_is_root_renamed(const FSEventStreamEventFlags ef)
 
 static int ef_is_dropped(const FSEventStreamEventFlags ef)
 {
-	return (ef & kFSEventStreamEventFlagMustScanSubDirs ||
-		ef & kFSEventStreamEventFlagKernelDropped ||
-		ef & kFSEventStreamEventFlagUserDropped);
+	return (ef & (kFSEventStreamEventFlagMustScanSubDirs |
+		      kFSEventStreamEventFlagKernelDropped |
+		      kFSEventStreamEventFlagUserDropped));
 }
 
 /*

base-commit: a7caae2729742fc80147bca1c02ae848cb55921a
-- 
gitgitgadget

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v2] fsm-listen-darwin: combine bit operations
  2023-01-17 21:25 [PATCH] fsm-listen-daarwin: combine bit operations Rose via GitGitGadget
@ 2023-01-17 21:54 ` Rose via GitGitGadget
  2023-01-20 15:48   ` Jeff Hostetler
  0 siblings, 1 reply; 5+ messages in thread
From: Rose via GitGitGadget @ 2023-01-17 21:54 UTC (permalink / raw)
  To: git; +Cc: Rose, Seija Kijin

From: Seija Kijin <doremylover123@gmail.com>

Signed-off-by: Seija Kijin <doremylover123@gmail.com>
---
    fsm-listen-darwin: combine bit operations
    
    Signed-off-by: Seija Kijin doremylover123@gmail.com

Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-1437%2FAtariDreams%2Fdarwin-v2
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-1437/AtariDreams/darwin-v2
Pull-Request: https://github.com/git/git/pull/1437

Range-diff vs v1:

 1:  a98654c7507 ! 1:  9943d52654f fsm-listen-daarwin: combine bit operations
     @@ Metadata
      Author: Seija Kijin <doremylover123@gmail.com>
      
       ## Commit message ##
     -    fsm-listen-daarwin: combine bit operations
     +    fsm-listen-darwin: combine bit operations
      
          Signed-off-by: Seija Kijin <doremylover123@gmail.com>
      


 compat/fsmonitor/fsm-listen-darwin.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/compat/fsmonitor/fsm-listen-darwin.c b/compat/fsmonitor/fsm-listen-darwin.c
index 97a55a6f0a4..fccdd21d858 100644
--- a/compat/fsmonitor/fsm-listen-darwin.c
+++ b/compat/fsmonitor/fsm-listen-darwin.c
@@ -129,9 +129,9 @@ static int ef_is_root_renamed(const FSEventStreamEventFlags ef)
 
 static int ef_is_dropped(const FSEventStreamEventFlags ef)
 {
-	return (ef & kFSEventStreamEventFlagMustScanSubDirs ||
-		ef & kFSEventStreamEventFlagKernelDropped ||
-		ef & kFSEventStreamEventFlagUserDropped);
+	return (ef & (kFSEventStreamEventFlagMustScanSubDirs |
+		      kFSEventStreamEventFlagKernelDropped |
+		      kFSEventStreamEventFlagUserDropped));
 }
 
 /*

base-commit: a7caae2729742fc80147bca1c02ae848cb55921a
-- 
gitgitgadget

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] fsm-listen-darwin: combine bit operations
  2023-01-17 21:54 ` [PATCH v2] fsm-listen-darwin: " Rose via GitGitGadget
@ 2023-01-20 15:48   ` Jeff Hostetler
  2023-01-20 17:52     ` Junio C Hamano
  0 siblings, 1 reply; 5+ messages in thread
From: Jeff Hostetler @ 2023-01-20 15:48 UTC (permalink / raw)
  To: Rose via GitGitGadget, git; +Cc: Rose, Seija Kijin



On 1/17/23 4:54 PM, Rose via GitGitGadget wrote:
> From: Seija Kijin <doremylover123@gmail.com>
> 
> Signed-off-by: Seija Kijin <doremylover123@gmail.com>
> ---
>      fsm-listen-darwin: combine bit operations
>      
>      Signed-off-by: Seija Kijin doremylover123@gmail.com
> 
> Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-1437%2FAtariDreams%2Fdarwin-v2
> Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-1437/AtariDreams/darwin-v2
> Pull-Request: https://github.com/git/git/pull/1437
> 
> Range-diff vs v1:
> 
>   1:  a98654c7507 ! 1:  9943d52654f fsm-listen-daarwin: combine bit operations
>       @@ Metadata
>        Author: Seija Kijin <doremylover123@gmail.com>
>        
>         ## Commit message ##
>       -    fsm-listen-daarwin: combine bit operations
>       +    fsm-listen-darwin: combine bit operations
>        
>            Signed-off-by: Seija Kijin <doremylover123@gmail.com>
>        
> 
> 
>   compat/fsmonitor/fsm-listen-darwin.c | 6 +++---
>   1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/compat/fsmonitor/fsm-listen-darwin.c b/compat/fsmonitor/fsm-listen-darwin.c
> index 97a55a6f0a4..fccdd21d858 100644
> --- a/compat/fsmonitor/fsm-listen-darwin.c
> +++ b/compat/fsmonitor/fsm-listen-darwin.c
> @@ -129,9 +129,9 @@ static int ef_is_root_renamed(const FSEventStreamEventFlags ef)
>   
>   static int ef_is_dropped(const FSEventStreamEventFlags ef)
>   {
> -	return (ef & kFSEventStreamEventFlagMustScanSubDirs ||
> -		ef & kFSEventStreamEventFlagKernelDropped ||
> -		ef & kFSEventStreamEventFlagUserDropped);
> +	return (ef & (kFSEventStreamEventFlagMustScanSubDirs |
> +		      kFSEventStreamEventFlagKernelDropped |
> +		      kFSEventStreamEventFlagUserDropped));
>   }

Technically, the returned value is slightly different, but
the only caller is just checking for non-zero, so it doesn't
matter.

So this is fine.

Thanks,
Jeff


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] fsm-listen-darwin: combine bit operations
  2023-01-20 15:48   ` Jeff Hostetler
@ 2023-01-20 17:52     ` Junio C Hamano
  2023-01-20 19:48       ` Jeff Hostetler
  0 siblings, 1 reply; 5+ messages in thread
From: Junio C Hamano @ 2023-01-20 17:52 UTC (permalink / raw)
  To: Jeff Hostetler; +Cc: Rose via GitGitGadget, git, Seija Kijin

Jeff Hostetler <git@jeffhostetler.com> writes:

>>     static int ef_is_dropped(const FSEventStreamEventFlags ef)
>>   {
>> -	return (ef & kFSEventStreamEventFlagMustScanSubDirs ||
>> -		ef & kFSEventStreamEventFlagKernelDropped ||
>> -		ef & kFSEventStreamEventFlagUserDropped);
>> +	return (ef & (kFSEventStreamEventFlagMustScanSubDirs |
>> +		      kFSEventStreamEventFlagKernelDropped |
>> +		      kFSEventStreamEventFlagUserDropped));
>>   }
>
> Technically, the returned value is slightly different, but
> the only caller is just checking for non-zero, so it doesn't
> matter.
>
> So this is fine.

But is it worth the code churn and reviewer bandwidth?  Don't we
have better things to spend our time on?

I would not be surprised if a smart enough compiler used the same
transformartion as this patch does manually as an optimization.

Then it matters more which one of the two is more readable by our
developers.  And the original matches how we humans would think, I
would imagine.  ef might have MustScanSubdirs bit, KernelDropped
bit, or UserDropped bit and in these cases we want to say that ef is
dropped.  Arguably, the original is more readble, and it would be a
good change to adopt if there is an upside, like the updated code
resulting in markedly more efficient binary.

So, this might be technically fine, but I am not enthused to see
these kind of code churning patches with dubious upside.  An
optimization patch should be able to demonstrate its benefit with a
solid benchmark, or at least a clear difference in generated code.

In fact.

Compiler explorer godbolt.org tells me that gcc 12 with -O2 compiles
the following two functions into identical assembly.  The !! prefix
used in the second example is different from the postimage of what
Seija posted, but this being a file-scope static function, I would
expect the compiler to notice that the actual value would not matter
to the callers, only the truth value, does.


* Input *
int one(unsigned int num) {
    return ((num & 01) ||
            (num & 02) || (num & 04));
}

int two(unsigned int num) {
    return !!((num) & (01|02|04));
}

* Assembly *
one(unsigned int):
        xor     eax, eax
        and     edi, 7
        setne   al
        ret
two(unsigned int):
        xor     eax, eax
        and     edi, 7
        setne   al
        ret

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] fsm-listen-darwin: combine bit operations
  2023-01-20 17:52     ` Junio C Hamano
@ 2023-01-20 19:48       ` Jeff Hostetler
  0 siblings, 0 replies; 5+ messages in thread
From: Jeff Hostetler @ 2023-01-20 19:48 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Rose via GitGitGadget, git, Seija Kijin



On 1/20/23 12:52 PM, Junio C Hamano wrote:
> Jeff Hostetler <git@jeffhostetler.com> writes:
> 
>>>      static int ef_is_dropped(const FSEventStreamEventFlags ef)
>>>    {
>>> -	return (ef & kFSEventStreamEventFlagMustScanSubDirs ||
>>> -		ef & kFSEventStreamEventFlagKernelDropped ||
>>> -		ef & kFSEventStreamEventFlagUserDropped);
>>> +	return (ef & (kFSEventStreamEventFlagMustScanSubDirs |
>>> +		      kFSEventStreamEventFlagKernelDropped |
>>> +		      kFSEventStreamEventFlagUserDropped));
>>>    }
>>
>> Technically, the returned value is slightly different, but
>> the only caller is just checking for non-zero, so it doesn't
>> matter.
>>
>> So this is fine.
> 
> But is it worth the code churn and reviewer bandwidth?  Don't we
> have better things to spend our time on?
> 
> I would not be surprised if a smart enough compiler used the same
> transformartion as this patch does manually as an optimization.
> 
> Then it matters more which one of the two is more readable by our
> developers.  And the original matches how we humans would think, I
> would imagine.  ef might have MustScanSubdirs bit, KernelDropped
> bit, or UserDropped bit and in these cases we want to say that ef is
> dropped.  Arguably, the original is more readble, and it would be a
> good change to adopt if there is an upside, like the updated code
> resulting in markedly more efficient binary.
> 
> So, this might be technically fine, but I am not enthused to see
> these kind of code churning patches with dubious upside.  An
> optimization patch should be able to demonstrate its benefit with a
> solid benchmark, or at least a clear difference in generated code.
> 
> In fact.
> 
> Compiler explorer godbolt.org tells me that gcc 12 with -O2 compiles
> the following two functions into identical assembly.  The !! prefix
> used in the second example is different from the postimage of what
> Seija posted, but this being a file-scope static function, I would
> expect the compiler to notice that the actual value would not matter
> to the callers, only the truth value, does.
> 
> 
> * Input *
> int one(unsigned int num) {
>      return ((num & 01) ||
>              (num & 02) || (num & 04));
> }
> 
> int two(unsigned int num) {
>      return !!((num) & (01|02|04));
> }
> 
> * Assembly *
> one(unsigned int):
>          xor     eax, eax
>          and     edi, 7
>          setne   al
>          ret
> two(unsigned int):
>          xor     eax, eax
>          and     edi, 7
>          setne   al
>          ret

agreed.  i didn't think the change was really worth the bother
and churn.  personally, i prefer the conceptual clarity of the
code the way I wrote it.

and i was wondering if the compiler would generate the same
result, but didn't take the time (read: was too lazy) to actually
verify that.

all i was intending to say was that it wasn't a wrong change.

jeff

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-01-20 19:49 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-17 21:25 [PATCH] fsm-listen-daarwin: combine bit operations Rose via GitGitGadget
2023-01-17 21:54 ` [PATCH v2] fsm-listen-darwin: " Rose via GitGitGadget
2023-01-20 15:48   ` Jeff Hostetler
2023-01-20 17:52     ` Junio C Hamano
2023-01-20 19:48       ` Jeff Hostetler

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).