Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1315980 > unrolled thread

Re: [PATCH] fs: dcache: Use bool return value instead of int

Started byChen Gang <chengang@emindsoft.com.cn>
First post2016-01-24 22:20 +0100
Last post2016-01-25 22:30 +0100
Articles 3 — 2 participants

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: [PATCH] fs: dcache: Use bool return value instead of int Chen Gang <chengang@emindsoft.com.cn> - 2016-01-24 22:20 +0100
    Re: [PATCH] fs: dcache: Use bool return value instead of int Al Viro <viro@ZenIV.linux.org.uk> - 2016-01-24 22:30 +0100
      Re: [PATCH] fs: dcache: Use bool return value instead of int Chen Gang <chengang@emindsoft.com.cn> - 2016-01-25 22:30 +0100

#1315980 — Re: [PATCH] fs: dcache: Use bool return value instead of int

FromChen Gang <chengang@emindsoft.com.cn>
Date2016-01-24 22:20 +0100
SubjectRe: [PATCH] fs: dcache: Use bool return value instead of int
Message-ID<qUAeK-2a9-9@gated-at.bofh.it>
Hello all:

Is this patch OK? shall I send the other patch based on this one? (the
other patch is v3 trivial patch for include/linux/dcache.h).

And sorry for replying late: the last week, I was not in Beijing, had to
be busy for analyzing a Linux kernel usb related issue for my company's
customer in Guangzhou (but at last, I guess, it is not kernel issue).


Thanks.

On 1/14/16 23:39, Chen Gang wrote:
> 
> On 1/14/16 06:54, Al Viro wrote:
>> On Thu, Jan 14, 2016 at 06:39:53AM +0800, Chen Gang wrote:
>>
>>>> As for the inlines... frankly, if gcc generates a different code from having
>>>> replaced int with bool in those, it's time to do something very nasty to
>>>> gcc developers.
>>>>
>>>
>>> Could you provide the related proof?
>>
>> static inline _Bool f(.....)
>> {
>> 	return <int expression>;
>> }
>>
>> ...
>> 	if (f(.....))
>>
> 
> For me, your case above isn't suitable for using bool. Please check this
> patch, there is no any cases like you said above.
> 
>  - For d_unhashed() which return hlist_bl_unhashed(), it seems like your
>    case, but in fact hlist_bl_unhashed() also need return bool (which I
>    shall send another patch for, next).
> 
>  - And all the other changes of this patch are all for real, pure bool
>    functions.
> 
> Thanks.
> 
>> should generate the code identical to
>> 	if ((_Bool)<int expression>)
>> which, in turn, should generate the code identical to
>> 	if (<int expression> != 0)
>> and
>> 	if (<int expression>)
>>
>> Neither explicit nor implicit conversion to _Bool (the former by the explicit
>> cast, the latter - by declaring f() to return _Bool) matters at all when the
>> damn thing is inlined in a condition context.  Conversion to _Bool is
>> equivalent to comparison with 0, and so is the use in condition of if() and
>> friends.
>>
>> For something not inlined you might get different code generated due to a
>> difference in calling sequences of _Bool(...) and int(...); for inlined
>> case having one of those variants produce a better code means that compiler
>> has managed to miss some trivial optimization in all other variants.
>>
>> And I'm yet to see any proof that gcc *does* fuck up in that fashion.  It
>> might - dumb bugs happen to everyone, but I would not assume that they'd
>> managed to do something that bogys without experimental evidence.
>>
> 
> For your cases, what you said sounds OK to me (although I am not quite
> sure what you said above whether precise or not).
> 
> Thanks.
> 

-- 
Chen Gang (陈刚)

Open, share, and attitude like air, water, and life which God blessed

[toc] | [next] | [standalone]


#1315982

FromAl Viro <viro@ZenIV.linux.org.uk>
Date2016-01-24 22:30 +0100
Message-ID<qUAop-2dS-3@gated-at.bofh.it>
In reply to#1315980
On Mon, Jan 25, 2016 at 05:19:43AM +0800, Chen Gang wrote:
> Hello all:
> 
> Is this patch OK? shall I send the other patch based on this one? (the
> other patch is v3 trivial patch for include/linux/dcache.h).
> 
> And sorry for replying late: the last week, I was not in Beijing, had to
> be busy for analyzing a Linux kernel usb related issue for my company's
> customer in Guangzhou (but at last, I guess, it is not kernel issue).

Again, do you have _any_ evidence of improved code generation with that
patch?  Because if you do, I would really like to see it, so I could file
bugs against gcc optimizer.

Your impression of what _Bool is and what semantics does it have appears
to be rather different from that described in C99, but that's a secondary
issue - first and foremost, on which .config and with which gcc version
do you see improvements from that change?

[toc] | [prev] | [next] | [standalone]


#1317311

FromChen Gang <chengang@emindsoft.com.cn>
Date2016-01-25 22:30 +0100
Message-ID<qUWRY-1zn-5@gated-at.bofh.it>
In reply to#1315982
On 1/25/16 05:27, Al Viro wrote:
> 
> Again, do you have _any_ evidence of improved code generation with that
> patch?  Because if you do, I would really like to see it, so I could file
> bugs against gcc optimizer.
> 
> Your impression of what _Bool is and what semantics does it have appears
> to be rather different from that described in C99, but that's a secondary
> issue - first and foremost, on which .config and with which gcc version
> do you see improvements from that change?
> 

For our case, the check_mount function have smaller size under x86_64
(movl for int, movb for bool, movl is longer than movb).

The related objdump is below, welcome any ideas, suggestions, and
discussions for it.

  origin (for int):

00000000 <check_mount>:
       0:       8b 12                   mov    (%edx),%edx
       2:       81 e2 00 00 01 00       and    $0x10000,%edx
       8:       74 16                   je     20 <check_mount+0x20>
       a:       c7 00 01 00 00 00       movl   $0x1,(%eax)
      10:       b8 01 00 00 00          mov    $0x1,%eax
      15:       c3                      ret
      16:       8d 76 00                lea    0x0(%esi),%esi
      19:       8d bc 27 00 00 00 00    lea    0x0(%edi,%eiz,1),%edi
      20:       31 c0                   xor    %eax,%eax
      22:       c3                      ret
      23:       8d b6 00 00 00 00       lea    0x0(%esi),%esi
      29:       8d bc 27 00 00 00 00    lea    0x0(%edi,%eiz,1),%edi

  new (for bool):

00000000 <check_mount>:
       0:       8b 12                   mov    (%edx),%edx
       2:       81 e2 00 00 01 00       and    $0x10000,%edx
       8:       74 0e                   je     18 <check_mount+0x18>
       a:       c6 00 01                movb   $0x1,(%eax)
       d:       b8 01 00 00 00          mov    $0x1,%eax
      12:       c3                      ret
      13:       90                      nop
      14:       8d 74 26 00             lea    0x0(%esi,%eiz,1),%esi
      18:       31 c0                   xor    %eax,%eax
      1a:       c3                      ret
      1b:       90                      nop
      1c:       8d 74 26 00             lea    0x0(%esi,%eiz,1),%esi

[root@localhost fs]# gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/local/libexec/gcc/x86_64-pc-linux-gnu/6.0.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../gcc-ana/configure
Thread model: posix
gcc version 6.0.0 20151121 (experimental) (GCC) 


-- 
Chen Gang (陈刚)

Open, share, and attitude like air, water, and life which God blessed

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web