qemu-devel
[Top][All Lists]
Advanced

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

Re: [Qemu-devel] [PATCH v2 3/3] bitops: use bool


From: Blue Swirl
Subject: Re: [Qemu-devel] [PATCH v2 3/3] bitops: use bool
Date: Tue, 10 Jul 2012 19:32:38 +0000

On Mon, Jul 9, 2012 at 7:43 AM, Markus Armbruster <address@hidden> wrote:
> address@hidden writes:
>
>> From: Blue Swirl <address@hidden>
>>
>> Use 'bool' type for return value of bit test functions.
>
> Matter of taste.  'bool' makes sense if you think of these functions as
> predicates (ugly ones, with side effects).  'int' makes sense if you
> think of them as returning the bit value (a bit is not a truth value in
> my book).

The documentation actually talks about returning the old value.

But I think the kernel version (with the same documentation) however
returns a truth value:
static inline int test_and_clear_bit(int nr, volatile unsigned long *addr)
{
        int oldbit;

        asm volatile(LOCK_PREFIX "btr %2,%1\n\t"
                     "sbb %0,%0"
                     : "=r" (oldbit), ADDR : "Ir" (nr) : "memory");

        return oldbit;
}

SBB oldbit, oldbit with oldbit = 0 initially and carry set will produce -1, no?

>
> In my opinion, this is just unnecessary churn, and unnecessary deviation
> from established kernel practice.

We use for example NetBSD queue macros with heavy modification. If we
have a need to modify code derived from Linux kernel, we should do it
as well. In this case the kernel practice seems to be inconsistent and
worth fixing.



reply via email to

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