You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
```
complement (m-1) `xor` m == -m `xor` m
```
Latter produces slightly better assembly.
```asm
movq %rdi, %rax
negq %rax
xorq %rdi, %rax
```
Indeed if we give
```cpp
uint64_t f(uint64_t m_aQU2) {
return ((m_aQU2 - 1) ^ 18446744073709551615UL) ^ m_aQU2;
}
```
to clang and compile with optimisation, that's the ASM it spits out.
Translating it back to Haskell gives the solution from this branch.
Without same optimisation, even in Haskell it saves an instruction.
```hs
maskW :: Word -> Word
maskW m = complement (m-1) `xor` m
{-
movq %rax,%rbx
xorq $-1,%rbx
decq %rax
xorq %rbx,%rax
-}
```
```hs
maskMine :: Word -> Word
maskMine m = (-m) `xor` m
{-
movq %rax,%rbx
negq %rbx
xorq %rax,%rbx
-}
```
0 commit comments