SIMD with Zig
To find the index of the first instance of a character within a body of [ASCII] text, you might write something like: Or use the std.mem.indexOfScalar function from the standard library, which is essentially the same implementation. This implementation loops through the input and checks each character, one by one, to see if it's equal to our target. With SIMD, we can leverage CPU instructions to check multiple characters of our input in parallel. Let's do that in Zig. To keep this simple for now, let's pretend that our input is always exactly 8 characters long (we'll look at dynamic input lengths after, but 8 characters means we can illustrate the full content of our vectors). As an example, say we have "Hello Jo" and we want the first index of "o" (which is 4). Our first step is to create a vector (think of it as an array) of 8 elements, each containing the value "o": Our @as cast is a very Zig-specicific thing. 'o' on its own is a comptime_int. If we try to use that, we'll get an err
SIMD with Zig May 02, 2023 To find the index of the first instance of a character within a body of [ASCII] text, you might write something like: fn indexOf ( haystack : [ ] const u8 , needle : u8 ) ? usize { for ( haystack , 0 .. ) | c , i | { if ( c == needle ) return i ; } return null ; } Or use the std.mem.indexOfScalar function from the standard library, which is essentially the same implementation. This implementation loops through the input and checks each character, one by one, to see if it's equal to our target. With SIMD, we can leverage CPU instructions to check multiple characters o
Explore this link on the map →related reading
- Designing a SIMD Algorithm from Scratch · mcyoungmcyoung.xyz
- Let's see Paul Allen's SIMD CSV parser | chunkofcoal.comchunkofcoal.com
- LLVM is Smarter Than Meblog.sulami.xyz
- Faiss: A library for efficient similarity search - Engineering at Metaengineering.fb.com
- Devlog ⚡ Zig Programming Languageziglang.org
- Zenbleedlock.cmpxchg8b.com
- CS 6120: Loop-Level Automatic Vectorizationcs.cornell.edu
- Fast regex search: indexing text for agent tools · Cursorcursor.com
- Static search trees: 40x faster than binary search · CuriousCodingcuriouscoding.nl
- Announcing ScaNN: Efficient Vector Similarity Searchai.googleblog.com
- Algorithms for Modern Hardware - Algorithmicaen.algorithmica.org
- Zig: Already More Knowable Than C - Andrew Kelleyandrewkelley.me