Semi-static Conditions in Low-latency C++ for High Frequency Trading: Better than Branch Prediction Hints

08/27/2023
by   Paul Alexander Bilokon, et al.
0

Conditional branches pose a challenge for code optimisation, particularly in low latency settings. For better performance, processors leverage dedicated hardware to predict the outcome of a branch and execute the following instructions speculatively, a powerful optimisation. Modern branch predictors employ sophisticated algorithms and heuristics that utilise historical data and patterns to make predictions, and often, are extremely effective at doing so. Consequently, programmers may inadvertently underestimate the cost of misprediction when benchmarking code with synthetic data that is either too short or too predictable. While eliminating branches may not always be feasible, C++20 introduced the [[likely]] and [[unlikely]] attributes that enable the compiler to perform spot optimisations on assembly code associated with likely execution paths. Can we do better than this? This work presents the development of a novel language construct, referred to as a semi-static condition, which enables programmers to dynamically modify the direction of a branch at run-time by modifying the assembly code within the underlying executable. Subsequently, we explore scenarios where the use of semi-static conditions outperforms traditional conditional branching, highlighting their potential applications in real-time machine learning and high-frequency trading. Throughout the development process, key considerations of performance, portability, syntax, and security were taken into account.

READ FULL TEXT

page 1

page 2

page 3

page 4

research
09/08/2023

C++ Design Patterns for Low-latency Applications Including High-frequency Trading

This work aims to bridge the existing knowledge gap in the optimisation ...
research
04/25/2023

Dynamic Ineffectuality-based Clustered Architectures

The direction of conditional branches is predicted correctly in modern p...
research
06/13/2019

Branch Prediction Is Not a Solved Problem: Measurements, Opportunities, and Future Directions

Modern branch predictors predict the vast majority of conditional branch...
research
06/29/2020

SeMPE: Secure Multi Path Execution Architecture for Removing Conditional Branch Side Channels

One of the most prevalent source of side channel vulnerabilities is the ...
research
05/29/2020

Dynamic Merge Point Prediction

Despite decades of research, conditional branch mispredictions still pos...
research
07/16/2018

oo7: Low-overhead Defense against Spectre Attacks

The Spectre vulnerability in modern processors has been reported earlier...
research
07/16/2018

oo7: Low-overhead Defense against Spectre Attacks via Binary Analysis

The Spectre vulnerability in modern processors has been reported earlier...

Please sign up or login with your details

Forgot password? Click here to reset