lkml.org 
[lkml]   [2016]   [Sep]   [11]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: cmsg newgroup alt.sex.fetish.bool (was Re: [PATCH] arch: all: include: asm: bitops: Use bool instead of int for all bit test functions)


On 9/4/16 09:01, Al Viro wrote:
> On Sun, Sep 04, 2016 at 06:36:56AM +0800, Chen Gang wrote:
>
>> And for all: shall I provide the proof for another archs?
>>
>> For me, Boolean gives additional chance to compiler to improve the code.
>
> Whereas for compiler it gives nothing. Not in those cases.
>
>> If the compiler can not improve the code, it can treat it as int simply.
>> So theoretically, at least, Boolean should not be worse than int.
>
> Except for pointless code churn and pandering to irrational beliefs, that is...

For me, it is not quite suitable to get conclusion during discussing.

> Please, RTFISO9899 and learn the semantics of _Bool; it's not that complicated.
> Start with 6.2.5[2,6] and 6.3.1.2, then look through 6.8.4 and 6.8.5 to
> figure out the semantics of conditions in if/while/for. Note also 6.5.8,
> 6.5.9, 6.5.13 and 6.5.14 and observe that type of (x > 5 && y < 1) is *NOT*
> _Bool; it's int.
>

Yes, what you said above is true to me. But for (x > 5 && y < 1) will
return 1 for true and 0 for false, although its' type is still int. So
for compiler, it can simply treat it as Boolean type internally.

For my original saying, I assume 2 things (excuse me, I did not mention
originally):

- I assume what I said is for pure Boolean functions, in our case, all
functions intend to return 'Boolean' value (0 or 1) in most of archs,
although they use int type as return value.

- What I said is for compiler's optimization at middle language level
and at instruction level (internal processing), not for language
definition (interface for outside -- for C developers).

For me, one way is: in middle language level, bool can be treated as int
or long to be processed firstly, then in instruction level, the compiler
performs additional optimization and qualification for bool.

- So the compiler has additional chance for optimizing in instruction
level.

- Since for pure Boolean function, it is already sure that related int
value must be 0 or 1, and the compiler should be smart enough to know
that, so the output code need not additional qualifications.

- So, for me, theoretically, bool is equal or better than int for pure
bool functions, unless the compiler has performance bugs.

> If you can show any improvement or loss in code generation in this case
> (static inline int converted to static inline bool), I would really like to
> see the details. As in .config/file/function/gcc version/target architecture.
> Optimizer bugs happens, but they should be reported when found, and I would
> expect _Bool handling to be _less_ exercised than that of normal logical
> expressions, so loss is probably more likely. And yes, it also should be
> reported.
>

At least for x86_64 arch, as far as I know, I can find the case which
bool is better than int, but I can not find the case which worse than
int.

Thanks.
--
Chen Gang (陈刚)

Managing Natural Environments is the Duty of Human Beings.

\
 
 \ /
  Last update: 2016-09-17 09:59    [W:1.735 / U:0.108 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site