Pure 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 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 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 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 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 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 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 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 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 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 Article
More Pages to Explore .....