Understanding Rust’s Trait Objects
Fat-pointers, Vtables, and dynamic dispatch in RustPhoto by Andrea Qoqonga on UnsplashThis article investigates how Rust handles dynamic dispatch using trait objects and vtables. We will also explore...
View ArticleCompare the Assembly Generated for Static vs Dynamic Dispatch in Rust
Understand the differences between static and dynamic dispatch in RustTraits in Rust are similar to interfaces in other languages. Traits permit the implementation of a standard interface for multiple...
View ArticleRust Under the Hood
A deep dive into Rust internals and generated assemblyOur first book, Rust Under the Hood is available at Amazon.This comprehensive guide delves into Rust’s core mechanics by examining the assembly...
View ArticleRust bool vector to a string slice vector
Understand the assembly code for a Vec<bool> to Vec<'static str> transformation.We have already looked at assembly code generated for a vector iteration. We will build on that knowledge to...
View ArticleMap Rust vector iteration to assembly
Learn how the compiler optimizes iteration for different vector lengthsVectors in Rust contain a pointer to a heap vector buffer ( buf) and a length ( len). The vector buffer is a pointer to a buffer...
View ArticleRust to assembly: Arrays, Tuples, Box, and Option handling
Map the Rust array, tuple, Box, and Option to assembly. See how the Rust compiler inlines functions.We have already seen how Rust handles enums under the hood. We also looked at the code generation for...
View ArticleRust enum-match code generation
Understand the generated assembly code for enum discriminated unionsMatching an enum and associated fieldsEnums in Rust are discriminated unions that can save one of the multiple variants. The enum...
View ArticleAssembly code generated from Rust for parameter passing
Understand the assembly code generated for passing a parameter by value, reference, Box, Rc, and ArcHere we will be exploring the performance implications of the passing the self parameter by value,...
View ArticleAuto-vectorize C and C++ code
Auto-vectorization of for loops results in significant performance improvementDevelopers can take advantage of built-in auto-vectorization support in GCC. Let’s explore vectorization with the GCC 11.2...
View Articlelikely — unlikely directives
likely — unlikely directivesAssisting the compiler in optimizing if conditionsA look at the Linux kernel code will show many if conditions enclosed in likely and unlikely macros. These macros invoke...
View ArticleC++ Lambda Under the Hood
Understand the closure generated from a lambda expressionLambda expressions in C++ let developers define anonymous functions that can be used to inject code. Lambda expressions are more than just...
View ArticleTail Call Optimization in C++
Eliminating the last function call and converting a recursive function into a loop based functionExamining the translation of simple examples of C++ code into assembly can be very instructive in...
View ArticlePure functions in C++
Declare a function to be side-effect freeC++ is not a functional programming language. Functions causing side-effects is the norm. If a compiler does not see the body of a function, it assumes that the...
View ArticleTranslate C code to assembly language
Learn about mapping C function calls, loops and conditional statements to assemblyMapping from C to generic assembly codeLearn the basics of mapping from C to a generic assembly language. The following...
View ArticleThe myth of O(1) random access
In this series of articles, Emil Ernerfeldt argues that with large data structures, there is no such thing as an O(1) random access. The impact of processor caches results in approximately O(√N)...
View ArticleWhy software developers should care about CPU caches
The memory subsystem on modern computer systems has not kept pace with the increasing processor speed. This has resulted in processor designers adding very fast cache memory to reduce the penalty of...
View ArticlePattern matching in C++14
Pattern matching in C++ is an alternative to using if statements to control the logic flow. Pattern matching lets you organize the code as matching patterns and the statements to be executed when the...
View ArticleBoost fiber in your code
OK, we are not giving you dietary advice. “Boost Fiber” is a library designed to provide very light weight thread (fiber) support in user mode. A single thread can support multiple fibers that are...
View ArticleMap C switch and if statements to assembly code
This article covers the code generation for if-else and switch statements.Code generation for a switch statement (case values are in a narrow range)The code generated for a switch statement varies a...
View Article