From 5339d9e7b47e3e7a889c926990ce2de56ef48ed9 Mon Sep 17 00:00:00 2001 From: Hugo Saint-Vignes Date: Thu, 15 Oct 2020 16:25:11 +0200 Subject: [PATCH] [apps/shared] Add static assert for cache steps Change-Id: I77498775b4caf3d97522219d2a7c979601b985e8 --- apps/shared/continuous_function_cache.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/apps/shared/continuous_function_cache.cpp b/apps/shared/continuous_function_cache.cpp index 62064532d..9b3657960 100644 --- a/apps/shared/continuous_function_cache.cpp +++ b/apps/shared/continuous_function_cache.cpp @@ -64,6 +64,8 @@ void ContinuousFunctionCache::ComputeNonCartesianSteps(float * tStep, float * tC const int numberOfCacheablePoints = k_sizeOfCache / 2; const int numberOfWholeSteps = static_cast(Graph::GraphView::k_graphStepDenominator); static_assert(numberOfCacheablePoints % numberOfWholeSteps == 0, "numberOfCacheablePoints should be a multiple of numberOfWholeSteps for optimal caching"); + const int multiple = numberOfCacheablePoints / numberOfWholeSteps; + static_assert(multiple && !(multiple & (multiple - 1)), "multiple should be a power of 2 for optimal caching"); /* Define cacheStep such that every whole graph steps are equally divided * For instance, with : * graphStepDenominator = 10.1 @@ -72,7 +74,7 @@ void ContinuousFunctionCache::ComputeNonCartesianSteps(float * tStep, float * tC * step1 step2 step10 step11 * There are 11 steps, the first 10 are whole and have an equal size (tStep). * There are 16 cache points in the first 10 steps, 160 total cache points. */ - *tCacheStep = *tStep * numberOfWholeSteps / numberOfCacheablePoints; + *tCacheStep = *tStep / multiple; } // private