lkml.org 
[lkml]   [2009]   [Dec]   [2]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [tip:core/locking] locking, x86: Slightly shorten __ticket_spin_trylock()


On Wed, 2 Dec 2009, Jan Beulich wrote:

> >>> Ingo Molnar <mingo@elte.hu> 02.12.09 15:21 >>>
> 792a99a9 <_raw_spin_lock>:
> ...
> >792a99f3: 89 d8 mov %ebx,%eax
> >792a99f5: ff 15 d0 6c f2 79 call *0x79f26cd0
> >792a99fb: 85 c0 test %eax,%eax
> ...
> >792a9a2e: 89 f8 mov %edi,%eax
> >792a9a30: ff 15 d0 6c f2 79 call *0x79f26cd0
> >792a9a36: 85 c0 test %eax,%eax
>
> Assuming that these are the calls to __raw_spin_trylock, it is clear that
> the generated code isn't what we want: It should be test %al, %al in
> both cases.

See my previous email. Using 'bool' was a mistake. It's _always_ a
mistake.

'bool' basically says that the compiler can assume magic things, and
compile the thing to be anything it wants that is convenient for it.
Put another way, 'bool' has a magic API. For all you know, the rule might
even be that a 'bool' return value is always returned in a flag register
(ok, on x86 that would be _very_ inconvenient, but it's _possible_).

So the calling convention could have been

call <bool-returning-function>
jne .. // jump if it returned non-zero

because the rule about bool is that it is just one bit of information,
but exactly _how_ that bit is done is totally up to the compiler ABI.

In this case, the rule gcc implements on x86 is probably just "we pass it
around as an 'int' that contains 0 or 1". So the code would work if you
had left in the 'movzbl'.

End result: don't use bool.

Linus


\
 
 \ /
  Last update: 2009-12-02 16:37    [W:0.447 / U:0.088 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site