Assembly Code Optimization Without Branch Prediction Penalties

Resolve Bottlenecks,
Find Innovative Solutions
Generate Solutions

Solution Overview

Problem

The inefficiency and increased cost due to failed branch predictions in processor pipelines, which lead to pipeline emptying and reduced execution efficiency, are addressed by optimizing code to eliminate the need for branch prediction processes.

Innovation Solution

A system that generates assembly code from user code, embedding branch codes and jump instructions to modify execution flow dynamically, allowing branch execution without prediction, thus optimizing the user code's execution flow.

Engineering Contradictions & Design Principles

VSEngineering Contradiction Analysis

1Productivity

If branch prediction mechanism is used to predict execution of condition branches, then program execution efficiency is improved through efficient pipeline utilization, but when prediction fails, pipelines are emptied causing increased prediction cost and reduced efficiency

Engineering Contradiction:
Improveprogram execution efficiencyVSAvoidpipeline emptying time
Core Design Contradiction:
ProductivityVSLoss of time

Solution Approach 1:

The patent applies preliminary action by pre-calculating and storing target addresses for all branch conditions in a branch target buffer before execution. When a branch is encountered, the system checks the buffer to determine the target address in advance, eliminating the need for dynamic branch prediction and avoiding pipeline emptying when predictions fail.

Inventive Principle:
Principle #10Preliminary action

Solution Approach 2:

The patent implements dynamics by making the branch target address determination adaptive based on runtime conditions. The system dynamically selects between using pre-stored target addresses from the buffer or calculating targets on-the-fly, allowing the execution flow to adapt efficiently to different branch scenarios without pipeline disruption.

Inventive Principle:
Principle #15Dynamics

2Productivity

If traditional branch prediction is used, then pipeline utilization is improved, but prediction failures lead to pipeline reconstruction and increased overhead

Engineering Contradiction:
Improveinstruction throughputVSAvoidprediction cost
Core Design Contradiction:
ProductivityVSDevice complexity

Solution Approach 1:

The system performs preliminary action by pre-computing and caching branch target addresses in the branch target buffer during compilation or initial execution. This eliminates the need for complex runtime branch prediction logic, reducing prediction cost while maintaining high instruction throughput through efficient direct address lookup.

Inventive Principle:
Principle #10Preliminary action

Solution Approach 2:

The patent introduces an intermediary branch target buffer that mediates between the branch instruction and the target address. This buffer acts as a lookup table that provides target addresses directly without requiring complex prediction algorithms, thereby reducing device complexity while maintaining productivity.

Inventive Principle:
Principle #24Intermediary (Mediator)

3Measurement precision

If assembly code with embedded branch codes is generated, then execution flow can be modified accurately without branch prediction, but code generation complexity increases

Engineering Contradiction:
Improvebranch condition determination accuracyVSAvoidcode generation complexity
Core Design Contradiction:
Measurement precisionVSDevice complexity

Solution Approach 1:

The code generation process applies preliminary action by pre-generating assembly code with embedded branch codes and target addresses during compilation. This eliminates the need for complex runtime branch prediction logic, achieving precise branch condition determination while managing code generation complexity through automated compiler processing.

Inventive Principle:
Principle #10Preliminary action

Solution Approach 2:

The patent extracts the branch target address determination logic from the runtime execution path and places it in the compilation phase. By taking out the complex prediction logic and replacing it with simple embedded branch codes in the assembly output, the system achieves high precision while keeping the actual execution code generation relatively simple.

Inventive Principle:
Principle #2Taking out (Extraction)

Data Source

PatentEP4281859B1Systems and methods for code optimization
Publication Date: 2025.08.27 ZHEJIANG DAHUA TECH CO LTD
  • EP4281859B1 patent drawingFigure 1
  • EP4281859B1 patent drawingFigure 2
  • EP4281859B1 patent drawingFigure 3

AI summary

Systems and methods for code optimization. The methods may include generating, based on a first macro of a user code, an assembly code corresponding to the user code (610). The first macro may include one or more parameters relating to one or more branch codes, and the assembly code may include one or more assembly branch codes corresponding to the one or more branch codes and one or more jump codes corresponding to the one or more assembly branch codes. The methods may further include obtaining, based on a second macro of the user code, target information for identifying an execution condition of the one or more branch codes (620), and determining, based on the assembly code and the target information, a compiled user code (630). When being executed, the compiled user code may call, based on the target information, a procedure to determine a value of the execution condition. The procedure may be configured to modify an execution flow of the compiled user code.