jart / morton

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Morton

This repository implements bit interleaving in C/C++.

 morton(0b1100,0b0011)
          │││└──┐││││
          ││└─┐ │││││
          │└┐ │ │││││
          │┌─────┘│││
          │││ │ │ │││
          │││┌────┘││
          │││││ │  ││
          │││││┌───┘│
          │││││││┌──┘
        0b10100101

By default a SWAR implementation is used which takes 2 nanoseconds. If -mbmi2 is available, then morton() and unmorton() take less than one nanosecond. If no compiler optimizations are used then these funcs take 10 nanoseconds. The cost is constant since this implementation is fully branchless.

See Also

About

License:ISC License


Languages

Language:C 97.2%Language:Makefile 2.8%