Re:1BRC merykitty’s magic SWAR: 8 lines of code explained in...
by haxen on Friday March 08, 2024 @02:47AM
(#39638827)
This post explains a piece of code that appeared on the recent One Billion Row Challenge, it parses a variable-layout string whose bytes are packed into a single 64-bit variable, and doesn't use any if statements to achieve it. The string represents a decimal number from the range [-99.9, 99.9].
The general class of techniques used is called SWAR -- SIMD Within A Register, because it uses the regular ALU instruction set to achieve the effect of SIMD (Single Instruction, Multiple Data).
The code in question was submitted by Quan Anh Mai (@merykitty on GitHub).
The general class of techniques used is called SWAR -- SIMD Within A Register, because it uses the regular ALU instruction set to achieve the effect of SIMD (Single Instruction, Multiple Data).
The code in question was submitted by Quan Anh Mai (@merykitty on GitHub).