<commit_before>---
title: De / Interleave bits
published: true
tags: c++ bits morton-code raytracing
---
> Interleaving the binary coordinate values yields binary z-values. Connecting the z-values in their numerical order produces the recursively [Z-shaped curve]({% post_url 2017-12-29-Space-filling-curve %}). - [Morton Codes](http://asgerhoedt.dk/?p=276)

## [Morton Codes](http://asgerhoedt.dk/?p=276)
Provides an ordering along a space-filling curve while preserving data locality. - Constructing Acceleration Datastructures (raytracing).

- [Morton-code](https://www.highperformancegraphics.org/wp-content/uploads/2017/Papers-Session3/HPG207_ExtendedMortonCodes.pdf)

## Interleaving bits
- [Bit Twiddling Hacks](http://graphics.stanford.edu/~seander/bithacks.html) / [HN](https://news.ycombinator.com/item?id=25300310)
- [Software way](http://graphics.stanford.edu/~seander/bithacks.html#InterleaveBMN)
- [BMI2 instruction (x86)](https://stackoverflow.com/a/32235584/51386)

# De-interleaving bits
- [How fast can you bit-interleave 32-bit integers?](https://lemire.me/blog/2018/01/09/how-fast-can-you-bit-interleave-32-bit-integers-simd-edition/)<commit_msg>Update 2017-12-30-bit-interleave.md<commit_after>---
title: De / Interleave bits
published: true
tags: c++ bits morton-code raytracing
---
> Interleaving the binary coordinate values yields binary z-values. Connecting the z-values in their numerical order produces the recursively [Z-shaped curve]({% post_url 2017-12-29-Space-filling-curve %}). - [Morton Codes](http://asgerhoedt.dk/?p=276)

## [Morton Codes](http://asgerhoedt.dk/?p=276)
Provides an ordering along a space-filling curve while preserving data locality. - Constructing Acceleration Datastructures (raytracing).

- [How to use Morton Order(z order curve) in range search?](https://stackoverflow.com/questions/30170783/how-to-use-morton-orderz-order-curve-in-range-search)
- [Morton-code](https://www.highperformancegraphics.org/wp-content/uploads/2017/Papers-Session3/HPG207_ExtendedMortonCodes.pdf)


## Interleaving bits
- [Bit Twiddling Hacks](http://graphics.stanford.edu/~seander/bithacks.html) / [HN](https://news.ycombinator.com/item?id=25300310)
- [Software way](http://graphics.stanford.edu/~seander/bithacks.html#InterleaveBMN)
- [BMI2 instruction (x86)](https://stackoverflow.com/a/32235584/51386)

# De-interleaving bits
- [Decoding Morton Codes](https://fgiesen.wordpress.com/2009/12/13/decoding-morton-codes/)
- [How fast can you bit-interleave 32-bit integers?](https://lemire.me/blog/2018/01/09/how-fast-can-you-bit-interleave-32-bit-integers-simd-edition/)


{'fraction_non_alphanumeric': 0.1503644035289605, 'fraction_numerical': 0.05370157268891446, 'mean_word_length': 5.0510440835266825, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 10, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '346820', 'n_tokens_mistral': 1017, 'n_tokens_neox': 871, 'n_words': 161}