From 807b9d528476b1dc19f51f34a6e1e980bf403eec Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 29 Oct 2025 16:26:27 +0000 Subject: [PATCH] Fix dx4 calculation in scalar remainder code and add null checks - Fix dx4 computation in scalar remainder loops (should be dx2*dx2) - Add missing null pointer check in benchmark_sinf for consistency Co-authored-by: wvbbreu <185333235+wvbbreu@users.noreply.github.com> --- benchmarks/benchmark_utils.hpp | 3 +++ src/lookup_xsimd.cpp | 6 +++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/benchmarks/benchmark_utils.hpp b/benchmarks/benchmark_utils.hpp index bf0c2cd..bd39b25 100644 --- a/benchmarks/benchmark_utils.hpp +++ b/benchmarks/benchmark_utils.hpp @@ -26,6 +26,9 @@ static void benchmark_sinf(benchmark::State &state) { reinterpret_cast(backend.allocate_memory(N * sizeof(float))); float *s = reinterpret_cast(backend.allocate_memory(N * sizeof(float))); + if (!x || !s) { + throw std::runtime_error("Buffer allocation failed"); + } auto end = std::chrono::high_resolution_clock::now(); state.counters["init_ms"] = std::chrono::duration_cast(end - start) diff --git a/src/lookup_xsimd.cpp b/src/lookup_xsimd.cpp index ab9ba65..18cf42d 100644 --- a/src/lookup_xsimd.cpp +++ b/src/lookup_xsimd.cpp @@ -78,7 +78,7 @@ template struct cosf_dispatcher { const float dx = a[i] - idx * lookup_table_.PI_FRAC; const float dx2 = dx * dx; const float dx3 = dx2 * dx; - const float dx4 = dx3 * dx; + const float dx4 = dx2 * dx2; const float cosdx = 1.0f - lookup_table_.TERM2 * dx2 + lookup_table_.TERM4 * dx4; const float sindx = dx - lookup_table_.TERM3 * dx3; @@ -138,7 +138,7 @@ template struct sinf_dispatcher { const float dx = a[i] - idx * lookup_table_.PI_FRAC; const float dx2 = dx * dx; const float dx3 = dx2 * dx; - const float dx4 = dx3 * dx; + const float dx4 = dx2 * dx2; const float cosdx = 1.0f - lookup_table_.TERM2 * dx2 + lookup_table_.TERM4 * dx4; const float sindx = dx - lookup_table_.TERM3 * dx3; @@ -202,7 +202,7 @@ template struct sin_cosf_dispatcher { const float dx = a[i] - idx * lookup_table_.PI_FRAC; const float dx2 = dx * dx; const float dx3 = dx2 * dx; - const float dx4 = dx3 * dx; + const float dx4 = dx2 * dx2; const float cosdx = 1.0f - lookup_table_.TERM2 * dx2 + lookup_table_.TERM4 * dx4; const float sindx = dx - lookup_table_.TERM3 * dx3;