# Why no NAND nor NOR in Bitwise Operators?

**URL:** <https://discourse.julialang.org/t/why-no-nand-nor-nor-in-bitwise-operators/56540>\
**Category:** Internals & Design\
**Created:** [March 5, 2021, 9:58am UTC](https://discourse.julialang.org/t/why-no-nand-nor-nor-in-bitwise-operators/56540 "2021-03-05T09:58:24Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![citron](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/citron/32/22478_2.png) [@citron](https://discourse.julialang.org/u/citron)\
**Post date:** [March 5, 2021, 9:58am UTC](https://discourse.julialang.org/t/why-no-nand-nor-nor-in-bitwise-operators/56540/1 "2021-03-05T09:58:24Z")

</div>

Hello  
I would appreciate to see (vector) NAND (aka ⊼) and NOR (aka ⊽) bitwise operators implemented because these functions are commonly hardwired nowadays. We can see them in the [Arm A64 Instruction Set Architecture](https://developer.arm.com/documentation/ddi0596/2020-12/SVE-Instructions/NAND--NANDS--Bitwise-NAND-predicates-) and [Power ISA Instruction Set](https://ibm.box.com/s/hhjfw0x0lrbtyzmiaffnbxh2fuo0fog0) for instance. The X86 times are over.  
May I suggest to add these two functions to the specs ?

---

<div class="post-metadata">

**Author:** ![simeonschaub](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/simeonschaub/32/216566_2.png) [@simeonschaub](https://discourse.julialang.org/u/simeonschaub)\
**Post date:** [March 5, 2021, 10:51am UTC](https://discourse.julialang.org/t/why-no-nand-nor-nor-in-bitwise-operators/56540/2 "2021-03-05T10:51:10Z")

</div>

You don’t necessarily need intrinsics for nand and nor to take advantage of these instructions. I don’t own a computer with one of these architectures but what you can do is ask Julia for the LLVM IR of a `nand` function we just define ourselves:

```julia
julia> nand(x, y) = ~(x & y)
nand (generic function with 1 method)

julia> code_llvm(nand, NTuple{2, UInt})
; @ REPL[8]:1 within `nand'
define i64 @julia_nand_445(i64 zeroext %0, i64 zeroext %1) {
top:
; ┌ @ int.jl:311 within `&'
   %2 = and i64 %1, %0
; └
; ┌ @ int.jl:287 within `~'
   %3 = xor i64 %2, -1
; └
  ret i64 %3
}

```

If we tell llvm to compile this for PPC, we can see that it will just emit a single `nand` instruction (see [Compiler Explorer](https://alive2.llvm.org/ce/z/4AaWqx)):

```julia
julia_nand_445: # @julia_nand_445
        .quad .Lfunc_begin0
        .quad .TOC.@tocbase
        .quad 0
.Lfunc_begin0:
        nand 3, 4, 3
        blr
        .long 0
        .quad 0

```

That said, it probably wouldn’t be unreasonable to add a `nand` and `nor` function like this to base.

---

<div class="post-metadata">

**Author:** ![citron](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/citron/32/22478_2.png) [@citron](https://discourse.julialang.org/u/citron)\
**Post date:** [March 5, 2021, 1:44pm UTC](https://discourse.julialang.org/t/why-no-nand-nor-nor-in-bitwise-operators/56540/3 "2021-03-05T13:44:10Z")

</div>

very interesting ! Thanks !

---

<div class="post-metadata">

**Author:** ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)\
**Post date:** [March 6, 2021, 9:13pm UTC](https://discourse.julialang.org/t/why-no-nand-nor-nor-in-bitwise-operators/56540/4 "2021-03-06T21:13:52Z")

</div>

Seems like a reasonable issue to open. The standard infix operator versions could be defined by default as well.
