Skip to content

Latest commit

 

History

History
77 lines (70 loc) · 5.36 KB

SOFTWARE_OPTIMIZATION.md

File metadata and controls

77 lines (70 loc) · 5.36 KB

Software Optimization

Tips and tools for optimizing audio software.

  • Agner Fog's Instruction Tables - A useful table that lists the latency and throughput performance of various x86 instructions.
  • Algorithms for Modern Hardware by Sergey Slotin - Free online book on high performance computing.
    • The Profiling chapter is a good guide on how to do effective profiling and benchmarking.
  • Audio Software Optimization Tips - My own list of audio software optimization tips.
  • Auto-Vectorization in LLVM - Tips and tricks on how to structure your code to most effectively take advantage of auto-vectorization.
  • Compiler Explorer - Very useful tool that lets you analyze the assembly output of many different languages including Rust, C, and C++.
    • Note, you will generally want to enable compiler optimizations when using this tool to get the assembly output for release mode. To do this, enter the following text into the "Compiler options..." field for your given language/compiler:
      • C/C++ (gcc or clang): -O3
      • C/C++ (msvc): /O2
      • Rust: -C opt-level=3
    • Sometimes the compiler optimizes so much that it removes the function you want to analyze entirely (i.e. dead code elimination). To fix this, use the following function attributes for your given language/compiler:
      • C/C++ (gcc): __attribute__((optimize("O0")))
        • Place this on a function that calls the function you want to analyze, not the function itself. For example:
        • int __attribute__((optimize("O0"))) main() {
            foo_my_function_to_analyze();
            return 0;
          }
      • C/C++ (clang): __attribute__ ((optnone))
        • Place this on a function that calls the function you want to analyze, not the function itself. For example:
        • int __attribute__ ((optnone)) main() {
            foo_my_function_to_analyze();
            return 0;
          }
      • C/C++ (msvc): #pragma optimize( "", off ) / #pragma optimize( "", on )
        • Place these around a function that calls the function you want to analyze, not the function itself. For example:
        • #pragma optimize( "", off )
          int main() {
            foo_my_function_to_analyze();
            return 0;
          }
          #pragma optimize( "", on )
      • Rust: #[no_mangle] or #[inline(never)]
        • #[no_mangle]
          pub fn foo_my_function_to_analyze() {
            // ...
          }
  • Fast-DSP-Approximations - My own list of public-domain fast approximations of various expensive calculations.
  • How-to Optimize Rust Programs on Linux - How-to guide on profiling Rust code on Linux.
  • Intel Intrinsics Guide - x86 processor intrinsics
  • Minimizing Rust Binary Size - Tips on how to reduce the size of Rust binaries. This is a very minor optimization, but it can sometimes be useful for shipping release versions of plugins.
    • Note, don't set opt-level to "s" or "z" because that will likely make performance much worse (except for maybe when running on an embedded system with little memory).
  • multiversion - Easy function multiversioning in Rust.
  • Performance Ninja Class - A free and open source online course on how to find and fix low-level performance issues.
  • projet μ - denormal - Important article on how to avoid denormals in your code.
    • no_denormals - A Rust crate for temporarily turning off denormals in your DSP code.
  • Real-time audio programming 101 - Tips on writing real-time code.
  • Software Optimization Resources - A popular resource on optimizing for x86 based architectures.
  • The Rust Performance Book - Tips on optimizing code in Rust.

Profiling Tools

  • llvm-mca - Powerful machine code analyzer. You can also use this inside Compiler Explorer by selecting it under "Add tool".
  • uProf - Powerful profiler for AMD processors.
  • Valgrind - A collection of static analysis and profiling tools.
  • VTune - Powerful profiler for Intel processors.

Portable SIMD Libraries