Skip to content

Roland sipos/zero out optimization#44

Draft
roland-sipos wants to merge 3 commits into
developfrom
roland-sipos/zero-out-optimization
Draft

Roland sipos/zero out optimization#44
roland-sipos wants to merge 3 commits into
developfrom
roland-sipos/zero-out-optimization

Conversation

@roland-sipos

@roland-sipos roland-sipos commented Jun 30, 2026

Copy link
Copy Markdown
Member

Description

Addresses issue #43

Changes Made

  1. AVX Threshold Processor
    File: AVXThresholdProcessor.cpp
    Optimization: Replaced _mm256_blendv_epi8(_mm256_setzero_si256(), signal, mask) with _mm256_and_si256(signal, mask).
    Latency/Throughput Improvement: Reduced a variable-blend instruction down to a single bitwise AND instruction, increasing throughput and port availability (releasing Port 5 constraints).

  2. AVX Frugal Pedestal Subtract Processor
    File: AVXFrugalPedestalSubtractProcessor.cpp
    Optimizations: Replaced the two 3-instruction blocks generating to_add = (is_gt ? 1 : 0) + (is_lt ? -1 : 0) (which materialized zero, 1, -1 and ran blendv) with _mm256_sub_epi16(is_lt, is_gt). Since comparison masks contain elements that are either 0 or 0xFFFF (which is signed -1), is_lt - is_gt mathematically computes the exact desired addition/subtraction.
    Replaced _mm256_blendv_epi8(m_accum, _mm256_setzero_si256(), need_reset) with _mm256_andnot_si256(need_reset, m_accum).
    Latency/Throughput Improvement: Avoided 4 slow blendv instructions, 2 zero-vector initializations, and 4 constant-vector initializations. The operations now use single-cycle arithmetic subtraction and bitwise ANDNOT.

  3. AVX Pipeline
    File: AVXPipeline.cpp
    Optimizations: Replaced _mm256_blendv_epi8(_mm256_setzero_si256(), m_ones_register, active) with _mm256_and_si256(m_ones_register, active).
    Replaced 5 blendv calls masking fields in generate_tps with fast _mm256_and_si256.
    Replaced 5 blendv calls resetting fields in generate_tps with fast _mm256_andnot_si256.
    Latency/Throughput Improvement: Eliminated 11 slow variable-blend (blendv) intrinsics in the critical path of trigger primitive generation.

Standalone Benchmark and Verification App
A self-contained validation and performance benchmark app is located in /test/app/test_benchmark_tpg.cxx

You can build this benchmark application on any Linux system with GCC and AVX2 support without needing the DUNE-DAQ environment:

Compile

g++ -O3 -mavx2 test/apps/test_benchmark_tpg.cxx -o tpglibs_benchmark

Run

./tpglibs_benchmark

Type of change

  • Documentation (non-breaking change that adds or improves the documentation)
  • New feature or enhancement (non-breaking change which adds functionality)
  • Optimization (non-breaking change that improves code/performance)
  • Bug fix (non-breaking change which fixes an issue)
  • Breaking change (whatever its nature)

Testing checklist

  • Unit tests pass (e.g. dbt-build --unittest)
  • Minimal system quicktest passes (pytest -s minimal_system_quick_test.py)
  • Full set of integration tests pass (dunedaq_integtest_bundle.sh)
  • Python tests pass if applicable (e.g. python -m pytest)
  • Pre-commit hooks run successfully if applicable (e.g. pre-commit run --all-files)

Comments here on the testing

Further checks

  • Code is commented where needed, particularly in hard-to-understand areas
  • Code style is correct (dbt-build --lint, and/or see https://dune-daq-sw.readthedocs.io/en/latest/packages/styleguide/)
  • If applicable, new tests have been added or an issue has been opened to tackle that in the future.
    (Indicate issue here: # (issue))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Optimization]: AVX2 Intrinsics: Blend vs. Andnot

3 participants