HIGH PERFORMANCE COMPUTING

## Preface FROM THE FUTURE! (2013) HQ9+ may wind up being my legacy. Created as an elaborate (and admittedly obscure) joke over 12 years ago, it’s somehow developed an enduring popularity that took me completely by surprise.
GUY STEELE
VIRTUAL REALITY AND MIXED REALITY

# Preface FROM THE FUTURE! (2013) Where HQ9+ was a gag, 4DL began as a thought experiment. I was working at Charlie’s Espresso in Tempe at the time, and my shifts often had dead time that I used designing processor architectures and programming languages. I later learned, to my horror, that three- and four-dimensional instruction spaces are not actually uncommon (think: page-switching). I’ve preserved the 4DL definition below verbatim, in case people are curious. It contains an error, which I discovered early on but left in to see if anyone actually tried implementing the language. This became a habit.
CHRIS PRESSEY
PROGRAMMING LANGUAGES AND COMPILERS

(Series Overview) In this part of the series, we’ll take a grungy optimized C program and translate it, fairly literally, into a grungy optimized unsafe Rust program. It’ll get the same results, with the same performance, as the original.
PROGRAMMING LANGUAGES AND COMPILERS

(Series Overview) In the first part of this tutorial we took an optimized C program and translated it to an equivalent Rust program, complete with all the unsafe weirdness of the original: uninitialized variables, pointer casting and arithmetic, etc. In this section, we’ll begin using Rust’s features to make the program incrementally more robust, while keeping performance unchanged. Specifically, we’ll begin by introducing references.
PROGRAMMING LANGUAGES AND COMPILERS
Why Learn Rust the Dangerous Way?
(Series Overview) I think Rust is a great tool for C programmers to have in their arsenals. But Rust tutorials tend to start with higher-level concepts, focusing on what can be done with safe code and treating
unsafe code as the exception. This can be alienating to us hardcore low-level programmers. It’s like offering a course on blacksmithing but then spending all your time talking about how to clean chain mail — useful, maybe, but…didn’t you skip some important steps? In this series, I’m trying something different. Let’s take a grungy, optimized, pointer-type-punning, SSE-using, heap-eschewing, warning-disabling C program and look at how we could create the same program in Rust. And I do mean the same program, without bounds checks or seatbelts, in all its unsafe glory. Then, let’s evolve it, by applying the features that Rust adds to C. We’ll study the advantages and disadvantages at each step, thinking about how it affects both the code and our experience of working on the code. And as a ground rule: we won’t let any step lose performance. In the end, we’ll wind up with a 95%-safe Rust program, immune to crashes and segfaults and buffer overflows, that’s slightly faster than the original C program implementing the exact same algorithm. # What this isn’t This isn’t a complete course on Rust — it’s meant to complement other resources for learning the language. Read the Rust book to learn what Rust’s features are; read this to put them in context with the low-level programming you already understand. Experienced programmers can probably get a taste of Rust from this series even if you don’t speak the language. If what I have to say piques your interest, it’s time to go read the book. # Interested? Head to section one: You can’t write C in just any ol’ language.