Overview
ReXGlue provides multiple optimization levels and code generation options to tune performance of recompiled Xbox 360 executables. This guide covers compiler optimization flags, code generation options, and performance tuning strategies.Compiler Optimization Levels
Build Type Optimization
ReXGlue uses Clang’s optimization levels via CMake build types:| Build Type | Optimization | Debug Info | Use Case |
|---|---|---|---|
Debug | -O0 | Full (-g) | Development, debugging |
Release | -O3 | None | Production, maximum performance |
RelWithDebInfo | -O2 | Full (-g) | Profiling, performance debugging |
MinSizeRel | -Os | None | Size-constrained deployments |
/home/daytona/workspace/source/CMakeLists.txt:72-75
Setting Build Type
Clang Compiler Requirement
ReXGlue requires Clang 18+ for optimal code generation:/home/daytona/workspace/source/CMakeLists.txt:40-46
Code Generation Options
RecompilerConfig Optimization Flags
Configure code generation in your TOML config or programmatically:/home/daytona/workspace/source/include/rex/codegen/config.h:82-91
Register Allocation Strategies
1. Non-Argument Registers as Locals
2. Non-Volatile Registers as Locals
3. Condition Register Optimization
Special Register Optimization
Skip Link Register (LR)
blr or save/restore LR.
Trade-off: Saves overhead but breaks functions that return via LR.
Skip Machine State Register (MSR)
CTR/XER as Local Variables
Platform-Specific Optimizations
Linux: Large Code Model
On Linux, ReXGlue uses the large code model for executables over 35MB:/home/daytona/workspace/source/CMakeLists.txt:64
Reason: Supports very large recompiled executables that exceed the default code model’s 2GB addressing limit.
Floating-Point Model
ReXGlue uses strict floating-point semantics to match PowerPC behavior:/home/daytona/workspace/source/CMakeLists.txt:71
Trade-off: Ensures correctness but disables aggressive FP optimizations like reassociation and fused multiply-add.
No Strict Aliasing
/home/daytona/workspace/source/CMakeLists.txt:70
Reason: Recompiled code frequently casts pointers (e.g., byte access to words), which violates C++ strict aliasing rules.
Performance Tuning
Analysis Thresholds
Tune analysis heuristics for your binary:/home/daytona/workspace/source/include/rex/codegen/config.h:93-95
Max Jump Extension
Controls how far the recompiler extends a function to include jump table targets:Data Region Threshold
Number of consecutive invalid instructions before marking a region as data:Exception Handler Overhead
Exception handlers add significant overhead:Link-Time Optimization (LTO)
Enable LTO for whole-program optimization:- Cross-module inlining
- Better dead code elimination
- Optimized calling conventions
- Longer build times
- Higher memory usage during linking
Profiling and Benchmarking
CPU Profiling
Linux: perf
Windows: Visual Studio Profiler
- Build with
RelWithDebInfo - Open in Visual Studio
- Debug → Performance Profiler
- Select CPU Usage
- Start profiling
Hotspot Analysis
Identify performance bottlenecks:Micro-Benchmarking
Benchmark specific recompiled functions:Common Performance Issues
Issue: Slow Memory Access
Symptom: Recompiled code is 5-10x slower than expected Cause: Every memory access goes through indirection Solution: Ensure guest memory is mapped at a fixed address (default:0x100000000)
Issue: Excessive Context Switching
Symptom: High overhead inPPCContext loads/stores
Cause: Registers stored in context instead of local variables
Solution: Enable register-as-local optimizations:
Issue: Debug Assertions in Hot Paths
Symptom: Debug build is 100x slower than Release Cause:assert_* macros execute expensive checks
Solution: Use RelWithDebInfo for profiling, or disable specific assertions:
Issue: Large Function Compilation Time
Symptom: Clang takes minutes to compile a single function Cause: Function is too large (>100KB) for effective optimization Solution: Split into chunks using theparent field:
Optimization Checklist
For maximum performance:- Use
Releasebuild type (-O3) - Enable Clang 18+ with LTO
- Set
generateExceptionHandlers = falsein production - Enable register-as-local optimizations for hot functions
- Set
skipMsr = truefor most functions - Use
-mcmodel=largeon Linux for large executables - Profile with
perfor Visual Studio Profiler - Benchmark before and after optimizations
- Consider splitting functions >1MB into chunks
Related Topics
- Debugging - Debug builds and sanitizers
- Platform Support - Platform-specific optimizations
- Exception Handlers - Performance impact of SEH