* Re: [PATCH 2/9] drivers/acpi/asus_acpi.c: Correct use of ! and &
2008-02-29 5:55 ` Andrew Morton
@ 2008-02-29 6:10 ` Matthew Wilcox
2008-02-29 6:14 ` Matthew Wilcox
2008-02-29 6:19 ` Andrew Morton
2008-02-29 11:01 ` Julia Lawall
2008-02-29 18:06 ` Mark Pearson
2 siblings, 2 replies; 12+ messages in thread
From: Matthew Wilcox @ 2008-02-29 6:10 UTC (permalink / raw)
To: Andrew Morton
Cc: Mark Pearson, Karol Kozimor, Julia Lawall, corentincj, sziwan,
acpi4asus-user, linux-kernel, kernel-janitors, Len Brown
On Thu, Feb 28, 2008 at 09:55:03PM -0800, Andrew Morton wrote:
> if (invert) /* invert target value */
> - led_out = !led_out & 0x1;
> + led_out = !led_out;
>
> if (!write_acpi_int(hotk->handle, ledname, led_out, NULL))
But now you're writing 0xffffffff instead of 1. I think the suggestion
of led_out ^= 1 was the correct one.
--
Intel are signing my paycheques ... these opinions are still mine
"Bill, look, we understand that you're interested in selling us this
operating system, but compare it to ours. We can't possibly take such
a retrograde step."
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 2/9] drivers/acpi/asus_acpi.c: Correct use of ! and &
2008-02-29 6:10 ` Matthew Wilcox
@ 2008-02-29 6:14 ` Matthew Wilcox
2008-02-29 6:19 ` Andrew Morton
1 sibling, 0 replies; 12+ messages in thread
From: Matthew Wilcox @ 2008-02-29 6:14 UTC (permalink / raw)
To: Andrew Morton
Cc: Mark Pearson, Karol Kozimor, Julia Lawall, corentincj, sziwan,
acpi4asus-user, linux-kernel, kernel-janitors, Len Brown
On Thu, Feb 28, 2008 at 11:10:23PM -0700, Matthew Wilcox wrote:
> On Thu, Feb 28, 2008 at 09:55:03PM -0800, Andrew Morton wrote:
> > if (invert) /* invert target value */
> > - led_out = !led_out & 0x1;
> > + led_out = !led_out;
> >
> > if (!write_acpi_int(hotk->handle, ledname, led_out, NULL))
>
> But now you're writing 0xffffffff instead of 1. I think the suggestion
> of led_out ^= 1 was the correct one.
! is not ~
! is not ~
! is not ~
....
I'll go to sleep now.
--
Intel are signing my paycheques ... these opinions are still mine
"Bill, look, we understand that you're interested in selling us this
operating system, but compare it to ours. We can't possibly take such
a retrograde step."
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 2/9] drivers/acpi/asus_acpi.c: Correct use of ! and &
2008-02-29 6:10 ` Matthew Wilcox
2008-02-29 6:14 ` Matthew Wilcox
@ 2008-02-29 6:19 ` Andrew Morton
1 sibling, 0 replies; 12+ messages in thread
From: Andrew Morton @ 2008-02-29 6:19 UTC (permalink / raw)
To: Matthew Wilcox
Cc: Mark Pearson, Karol Kozimor, Julia Lawall, corentincj, sziwan,
acpi4asus-user, linux-kernel, kernel-janitors, Len Brown
On Thu, 28 Feb 2008 23:10:23 -0700 Matthew Wilcox <matthew@wil.cx> wrote:
> On Thu, Feb 28, 2008 at 09:55:03PM -0800, Andrew Morton wrote:
> > if (invert) /* invert target value */
> > - led_out = !led_out & 0x1;
> > + led_out = !led_out;
> >
> > if (!write_acpi_int(hotk->handle, ledname, led_out, NULL))
>
> But now you're writing 0xffffffff instead of 1. I think the suggestion
> of led_out ^= 1 was the correct one.
>
!0 is 1, not 0xffffffff.
IOW, ! != ~ ;)
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 2/9] drivers/acpi/asus_acpi.c: Correct use of ! and &
2008-02-29 5:55 ` Andrew Morton
2008-02-29 6:10 ` Matthew Wilcox
@ 2008-02-29 11:01 ` Julia Lawall
2008-02-29 11:08 ` Andrew Morton
2008-02-29 18:06 ` Mark Pearson
2 siblings, 1 reply; 12+ messages in thread
From: Julia Lawall @ 2008-02-29 11:01 UTC (permalink / raw)
To: Andrew Morton
Cc: Mark Pearson, Karol Kozimor, corentincj, sziwan, acpi4asus-user,
linux-kernel, kernel-janitors, Len Brown
On Thu, 28 Feb 2008, Andrew Morton wrote:
> On Wed, 27 Feb 2008 19:29:15 +0100 Mark Pearson <devnull.port@googlemail.com> wrote:
>
> > Karol Kozimor wrote:
> > > On 26-02-2008, at 21:42, Julia Lawall wrote:
> > >> if (invert) /* invert target value */
> > >> - led_out = !led_out & 0x1;
> > >> + led_out = !(led_out & 0x1);
> > >>
> > >> if (!write_acpi_int(hotk->handle, ledname, led_out, NULL))
> > >> printk(KERN_WARNING "Asus ACPI: LED (%s) write failed\n",
> > >
> > >
> > > IIRC we're just supposed to flip the last bit here, so the original code
> > > is correct.
> > > Best regards,
> > >
> >
> > Seems an odd way of doing:
> >
> > led_out ^= 0x01;
>
> It does.
>
> > It this due to some optimisation?
>
> Surely not ;)
>
> That code has been there for many years.
>
> I changed the patch to this:
>
> --- a/drivers/acpi/asus_acpi.c~drivers-acpi-asus_acpic-correct-use-of-and
> +++ a/drivers/acpi/asus_acpi.c
> @@ -610,7 +610,7 @@ write_led(const char __user * buffer, un
> (led_out) ? (hotk->status | ledmask) : (hotk->status & ~ledmask);
>
> if (invert) /* invert target value */
> - led_out = !led_out & 0x1;
> + led_out = !led_out;
I don't think this is the same:
!(0110 & 0x01) = !0 = 1
!0110 = 0
led_out ^= 0x01;
is also not the same:
0110 ^ 0x01 = 0111
Is it desired to keep the value and flip the last bit or just obtain the
opposite of the last bit?
julia
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 2/9] drivers/acpi/asus_acpi.c: Correct use of ! and &
2008-02-29 11:01 ` Julia Lawall
@ 2008-02-29 11:08 ` Andrew Morton
0 siblings, 0 replies; 12+ messages in thread
From: Andrew Morton @ 2008-02-29 11:08 UTC (permalink / raw)
To: Julia Lawall
Cc: Mark Pearson, Karol Kozimor, corentincj, sziwan, acpi4asus-user,
linux-kernel, kernel-janitors, Len Brown
On Fri, 29 Feb 2008 12:01:26 +0100 (CET) Julia Lawall <julia@diku.dk> wrote:
> On Thu, 28 Feb 2008, Andrew Morton wrote:
>
> > On Wed, 27 Feb 2008 19:29:15 +0100 Mark Pearson <devnull.port@googlemail.com> wrote:
> >
> > > Karol Kozimor wrote:
> > > > On 26-02-2008, at 21:42, Julia Lawall wrote:
> > > >> if (invert) /* invert target value */
> > > >> - led_out = !led_out & 0x1;
> > > >> + led_out = !(led_out & 0x1);
> > > >>
> > > >> if (!write_acpi_int(hotk->handle, ledname, led_out, NULL))
> > > >> printk(KERN_WARNING "Asus ACPI: LED (%s) write failed\n",
> > > >
> > > >
> > > > IIRC we're just supposed to flip the last bit here, so the original code
> > > > is correct.
> > > > Best regards,
> > > >
> > >
> > > Seems an odd way of doing:
> > >
> > > led_out ^= 0x01;
> >
> > It does.
> >
> > > It this due to some optimisation?
> >
> > Surely not ;)
> >
> > That code has been there for many years.
> >
> > I changed the patch to this:
> >
> > --- a/drivers/acpi/asus_acpi.c~drivers-acpi-asus_acpic-correct-use-of-and
> > +++ a/drivers/acpi/asus_acpi.c
> > @@ -610,7 +610,7 @@ write_led(const char __user * buffer, un
> > (led_out) ? (hotk->status | ledmask) : (hotk->status & ~ledmask);
> >
> > if (invert) /* invert target value */
> > - led_out = !led_out & 0x1;
> > + led_out = !led_out;
>
> I don't think this is the same:
>
> !(0110 & 0x01) = !0 = 1
> !0110 = 0
>
> led_out ^= 0x01;
>
> is also not the same:
>
> 0110 ^ 0x01 = 0111
>
> Is it desired to keep the value and flip the last bit or just obtain the
> opposite of the last bit?
>
led_out can only take the values 0 or 1 here.
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 2/9] drivers/acpi/asus_acpi.c: Correct use of ! and &
2008-02-29 5:55 ` Andrew Morton
2008-02-29 6:10 ` Matthew Wilcox
2008-02-29 11:01 ` Julia Lawall
@ 2008-02-29 18:06 ` Mark Pearson
2008-02-29 21:33 ` Andrew Morton
2 siblings, 1 reply; 12+ messages in thread
From: Mark Pearson @ 2008-02-29 18:06 UTC (permalink / raw)
To: Andrew Morton
Cc: Karol Kozimor, Julia Lawall, corentincj, sziwan, acpi4asus-user,
linux-kernel, kernel-janitors, Len Brown
Andrew Morton wrote:
>> Seems an odd way of doing:
>>
>> led_out ^= 0x01;
>
> It does.
>
>> It this due to some optimisation?
>
> Surely not ;)
>
;) Thought so - one doesn't like to be too presumptuous ;)
> That code has been there for many years.
>
> I changed the patch to this:
>
> --- a/drivers/acpi/asus_acpi.c~drivers-acpi-asus_acpic-correct-use-of-and
> +++ a/drivers/acpi/asus_acpi.c
> @@ -610,7 +610,7 @@ write_led(const char __user * buffer, un
> (led_out) ? (hotk->status | ledmask) : (hotk->status & ~ledmask);
>
> if (invert) /* invert target value */
> - led_out = !led_out & 0x1;
> + led_out = !led_out;
>
> if (!write_acpi_int(hotk->handle, ledname, led_out, NULL))
> printk(KERN_WARNING "Asus ACPI: LED (%s) write failed\n",
> _
>
>
Is the ! operator architecture/compiler dependent? or can one always say that
!NON_ZERO_VALUE == 0 and !0 == 1?
Cheers, Mark.
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 2/9] drivers/acpi/asus_acpi.c: Correct use of ! and &
2008-02-29 18:06 ` Mark Pearson
@ 2008-02-29 21:33 ` Andrew Morton
0 siblings, 0 replies; 12+ messages in thread
From: Andrew Morton @ 2008-02-29 21:33 UTC (permalink / raw)
To: Mark Pearson
Cc: sziwan, julia, corentincj, sziwan, acpi4asus-user, linux-kernel,
kernel-janitors, lenb
On Fri, 29 Feb 2008 19:06:48 +0100
Mark Pearson <devnull.port@googlemail.com> wrote:
> Andrew Morton wrote:
> >> Seems an odd way of doing:
> >>
> >> led_out ^= 0x01;
> >
> > It does.
> >
> >> It this due to some optimisation?
> >
> > Surely not ;)
> >
> ;) Thought so - one doesn't like to be too presumptuous ;)
>
> > That code has been there for many years.
> >
> > I changed the patch to this:
> >
> > --- a/drivers/acpi/asus_acpi.c~drivers-acpi-asus_acpic-correct-use-of-and
> > +++ a/drivers/acpi/asus_acpi.c
> > @@ -610,7 +610,7 @@ write_led(const char __user * buffer, un
> > (led_out) ? (hotk->status | ledmask) : (hotk->status & ~ledmask);
> >
> > if (invert) /* invert target value */
> > - led_out = !led_out & 0x1;
> > + led_out = !led_out;
> >
> > if (!write_acpi_int(hotk->handle, ledname, led_out, NULL))
> > printk(KERN_WARNING "Asus ACPI: LED (%s) write failed\n",
> > _
> >
> >
>
> Is the ! operator architecture/compiler dependent?
It shouldn't be.
> or can one always say that
> !NON_ZERO_VALUE == 0 and !0 == 1?
>
I always have ;) I expect it's in the C standard somewhere.
^ permalink raw reply [flat|nested] 12+ messages in thread