LLVM is Smarter Than Me - sulami's blog
I was reading Algorithms for Modern Hardware recently, specifically the chapter on SIMD, and was impressed by auto-vectorization. The basic idea is that modern CPUs have so-called SIMD1 instructions that allow applying an operation to several values at once, which is much faster than performing the equivalent scalar instructions one at a time. Modern compilers can detect certain programming patterns where an operation is performed repeatedly on scalar values and group the operations to make use of the faster instructions.2 The book uses primarily C++ for its examples, but I was curious if the same pattern would work in Rust as well, without having to manually annotate anything. So I opened up the compiler explorer and typed in my first test, which looked like this: To make sure I the compiler would feel safe to use SIMD instructions, I used -C opt-level=3 -C target-cpu=skylake, telling it that the target CPU supports them. But instead of SIMD instructions I got this assembly: Turns out
LLVM is Smarter Than Me Weak Opinions, Strongly Held Feed • Now • Uses • About LLVM is Smarter Than Me Published on 2024-04-19 Tags: rust , compilers I was reading Algorithms for Modern Hardware recently, specifically the chapter on SIMD , and was impressed by auto-vectorization. The basic idea is that modern CPUs have so-called SIMD 1 Single Instruction Multiple Data instructions that allow applying an operation to several values at once, which is much faster than performing the equivalent scalar instructions one at a time. Modern compilers can detect certain programming patterns where an ope
Explore this link on the map →saved by
related reading
- Algorithms for Modern Hardware - Algorithmicaen.algorithmica.org
- A Gentle Introduction to LLVM IR · mcyoungmcyoung.xyz
- CS 6120: Loop-Level Automatic Vectorizationcs.cornell.edu
- A Gentle Introduction to LLVM IR · mcyoungmcyoung.xyz
- A friendly introduction to machine learning compilers and optimizershuyenchip.com
- Designing a SIMD Algorithm from Scratch · mcyoungmcyoung.xyz
- Rust Optimization.md · GitHubgist.github.com
- Reddit - Please wait for verificationreddit.com
- Compilers - What Every Programmer Should Know About Compiler Optimizations | Microsoft Learnlearn.microsoft.com
- A half-hour to learn Rustfasterthanli.me
- ⭐️ Fast LLM Inference From Scratchandrewkchan.dev
- Many can write faster asm than the compiler, yet don't. Why? — LessWronglesswrong.com