Re: ternary vs double exclamation

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

 



On Tue, Dec 30, 2014 at 3:25 AM, Vinícius Tinti <viniciustinti@xxxxxxxxx> wrote:
> I was looking the kernel source code and there are a lot of places in
> which either "(expression) ? 1 : 0" or "(expression) ? 0 : 1" appear.
> As fair as I can tell both can be replaced by "!!expression" and
> "!expression".
>
> Moreover there it seems that using "!!" does not add a "nopl"
> instruction at the end of the call. Does anybody knows why?

It seems that the nop instruction is inserted for alignment, and if you
reverse the order of functions in your c source, nop will still be
inserted between them.

> 0000000000000000 <mod_if>:
>    0:   31 c0                   xor    %eax,%eax
>    2:   85 ff                   test   %edi,%edi
>    4:   0f 95 c0                setne  %al
>    7:   c3                      retq
>    8:   0f 1f 84 00 00 00 00    nopl   0x0(%rax,%rax,1)
>    f:   00
>
> 0000000000000010 <mod_x>:
>   10:   31 c0                   xor    %eax,%eax
>   12:   85 ff                   test   %edi,%edi
>   14:   0f 95 c0                setne  %al
>   17:   c3                      retq

-- 
Thanks.
-- Max

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@xxxxxxxxxxxxxxxxx
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies




[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux