Please rotate your tablet to be horizontal.

You can dismiss this notice but please note that this experience has not been designed for mobile devices and so will be less than optimal

Back To Schedule

High-performance Load-time Implementation Selection

09:00 - 10:00 Tuesday 13th September 2022 MDT Summit 8 & 9 / Online C
Intermediate
Advanced
Expert
Idioms & Techniques

Programmers often write software that is going to run on a wide variety of machine types. Writing code that is maximally efficient for all target machines can be a challenge. Often, a programmer may want to provide multiple implementations of a particular function, with each implementation optimized for a particular class of machines (e.g., an SSE implementation and an AVX implementation of a function). However, when there are multiple implementations provided, there is often a runtime cost to select the best implementation for the particular target.

Our feature combines compiler and OS facilities to enable no-overhead selection of the optimal implementation of a function. It is a function multi-versioning feature where a programmer can write multiple implementations of the function and specify to the compiler which implementation should be used on which target architectures. The compiler will use this information to generate metadata that it will include in the binary. When the binary is loaded, the OS will use this metadata to fix up references to the function, so that all references refer to the encoded optimal implementation for the current machine.

This feature enables extremely fine-grained function specialization without any overhead from indirect calls, jump tables, test-and-branch checks, etc. The specializations can be based on CPU architecture, model, features supported, or nearly any other characteristic of the current system.

This talk will walk through how this feature works, and how it is similar to existing features (e.g., gcc function multiversioning using ifuncs), and what implementation details compilers and OSes must consider when implementing this feature. We will discuss our implementation of this feature in Visual C++ and Windows 11, and demo the feature in action.

Joe Bialek

Microsoft

Joe Bialek is a security engineer in the Microsoft Security Response Center's Vulnerability & Mitigations team. Joe spends his time eliminating vulnerability classes, creating exploit mitigations, and finding security bugs.

Pranav Kant

Compiler EngineerMicrosoft

Pranav is a Software Engineer working for Microsoft on Visual C++ Compiler Backend team where he focuses on code generation, linking, and post-link binary level tooling.