C++ Function Multiversioning in Windows - Joe Bialek and Pranav Kant - CppCon 2022 https://github.com/CppCon/CppCon2022
Original Title: High-performance Load-time Implementation Selection
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 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 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. ---
Videos Filmed & Edited by Bash Films: http://www.BashFilms.com YouTube Channel Managed by Digital Medium Ltd https://events.digital-medium.co.uk
#cppcon #programming #function