What is the purpose of the “Prefer 32-bit” setting in Visual Studio and how does it actually work?

It is unclear to me how the compiler will automatically know to compile for 64-bit when it needs to. How does it know when it can confidently target 32-bit? I am mainly curious about how the compiler knows which architecture to target when compiling. Does it analyze the code and make a decision based on … Read more

What is a retpoline and how does it work?

In order to mitigate against kernel or cross-process memory disclosure (the Spectre attack), the Linux kernel1 will be compiled with a new option, -mindirect-branch=thunk-extern introduced to gcc to perform indirect calls through a so-called retpoline. This appears to be a newly invented term as a Google search turns up only very recent use (generally all … Read more

Deoptimizing a program for the pipeline in Intel Sandybridge-family CPUs

I’ve been racking my brain for a week trying to complete this assignment and I’m hoping someone here can lead me toward the right path. Let me start with the instructor’s instructions: Your assignment is the opposite of our first lab assignment, which was to optimize a prime number program. Your purpose in this assignment … Read more

Why is processing a sorted array faster than processing an unsorted array?

Here is a piece of C++ code that shows some very peculiar behavior. For some strange reason, sorting the data (before the timed region) miraculously makes the loop almost six times faster. #include <algorithm> #include <ctime> #include <iostream> int main() { // Generate data const unsigned arraySize = 32768; int data[arraySize]; for (unsigned c = … Read more