bug-coreutils
[Top][All Lists]
Advanced

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

Re: [PATCH] df: new option: --total (-c) to produce grand total (in the


From: James Youngman
Subject: Re: [PATCH] df: new option: --total (-c) to produce grand total (in the same way as du)
Date: Tue, 2 Sep 2008 13:13:38 +0100

On Tue, Sep 2, 2008 at 12:06 PM, Jim Meyering <address@hidden> wrote:
> Andreas Schwab <address@hidden> wrote:
>> Jim Meyering <address@hidden> writes:
>>> Kamil Dudka <address@hidden> wrote:
>>>> +#define LOG_EQ(a,b) (((a)&&(b))||(!(a)&&!(b)))
>>>
>>> This can be written more simply as !((a) ^ (b))
>>
>> Only if the operands are already boolean, and then you can just use a == b.
>
> Oh.  Right.  To be general, it'd have to be like this,
> but this is probably too obtuse unless you're comfortable
> with the "!!" pseudo operator idiom:
>
> #define LOG_EQ(a, b) !((!!(a)) ^ (!!(b)))

Why is it necessary anyway?   The result of ! is already guaranteed to
be either 1 or 0.   Hence as Andreas said,

#define LOG_EQ(a,b) (!(a) == !(b))


In fact as far as I can tell these produce equivalent code on my system anyway:


   8:logeq.c       **** int
   9:logeq.c       **** log_eq_1 (int b, int a)
  10:logeq.c       **** {
  16                            .loc 1 10 0
  17                    .LVL0:
  18                            .loc 1 10 0
  19 0000 85F6                  testl   %esi, %esi
  20 0002 0F95C0                setne   %al
  21 0005 85FF                  testl   %edi, %edi
  22 0007 0F94C2                sete    %dl
  23 000a 31D0                  xorl    %edx, %eax
  24 000c 0FB6C0                movzbl  %al, %eax
  11:logeq.c       ****   return !a == !b;
  12:logeq.c       **** }
  25                            .loc 1 12 0
  26 000f C3                    ret
  27                    .LFE20:
  28                            .size   log_eq_1, .-log_eq_1
  29                            .p2align 4,,15
  30                    .globl log_eq_2
  31                            .type   log_eq_2, @function
  32                    log_eq_2:
  33                    .LFB21:
  13:logeq.c       ****
  14:logeq.c       **** int
  15:logeq.c       **** log_eq_2 (int a, int b)
  16:logeq.c       **** {
  34                            .loc 1 16 0
  35                    .LVL1:
  36                            .loc 1 16 0
  37 0010 85FF                  testl   %edi, %edi
^LGAS LISTING /tmp/cczOkpUt.s                   page 2


  38 0012 0F94C0                sete    %al
  39 0015 85F6                  testl   %esi, %esi
  40 0017 0F95C2                setne   %dl
  41 001a 31D0                  xorl    %edx, %eax
  42 001c 0FB6C0                movzbl  %al, %eax
  17:logeq.c       ****   return !((!!a) ^ (!!b));
  18:logeq.c       **** }




James.




reply via email to

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