Re: Logical XOR



On Sep 21, 11:30 am, Martin Wells <war...@xxxxxxxxxx> wrote:
!!a != !!b

About three seconds after I sent that post I realised I cuda written:

!a != !b

fred.l.kleinschmidt@xxxxxxxxxx writes:
If a and b are always boolean values (0 or 1), just use
a^b

If they are not you can join those two techniques to form !a ^ !b which
is probably faster then !a != !b because no branching is used (at least
on some architectures).

But, I assume that if at least one of the values (say a) is boolean the
following will be even faster: ((unsigned)(((signed)a)-1)) & b. Not
sure if it's not implementation specific though. (If neither is boolean
replace a with !a). Disadvantage is that if b is not boolean this will
not produce a boolean value.

--
Best regards, _ _
.o. | Liege of Serenly Enlightened Majesty of o' \,=./ `o
..o | Computer Science, Michal "mina86" Nazarewicz (o o)
ooo +--<mina86*tlen.pl>---<jid:mina86*chrome.pl>--ooO--(_)--Ooo--
.



Relevant Pages

  • OT: Lost in all the letters
    ... Now you are getting into boolean and just plain smart searching ... techniques and that's beyond our scope of the class discussion ...
    (rec.games.pinball)
  • Re: Logical XOR
    ... Disadvantage is that if b is not boolean this will ... can't get nonboolean ^ to work because it's linear. ... than int you have to specify appropriately wide typenames. ... modern architectures) by doing somewhat more computation: ...
    (comp.lang.c)