From 3f7eaa5f7c7a34ed5b854e38acdaf5f7c689f6d2 Mon Sep 17 00:00:00 2001 From: Richard Holland Date: Fri, 3 Jun 2022 09:18:10 +0000 Subject: [PATCH] fix multiplier bug, multipliers lower than 1 are necessary --- src/ripple/app/hook/Guard.h | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/src/ripple/app/hook/Guard.h b/src/ripple/app/hook/Guard.h index 524baf133..d2e1bb84a 100644 --- a/src/ripple/app/hook/Guard.h +++ b/src/ripple/app/hook/Guard.h @@ -148,33 +148,47 @@ struct WasmBlkInf WasmBlkInf* parent; std::vector children; }; - + +#define PRINT_WCE(x)\ +{\ + if (DEBUG_GUARD)\ + printf("[%u]%.*swce=%ld | g=%u, pg=%u, m=%g\n",\ + x,\ + level, " ",\ + worst_case_execution,\ + blk->iteration_bound,\ + (blk->parent ? blk->parent->iteration_bound : -1),\ + multiplier);\ +} // compute worst case execution time inline -uint64_t compute_wce (const WasmBlkInf* blk) +uint64_t compute_wce (const WasmBlkInf* blk, int level = 0) { uint64_t worst_case_execution = blk->instruction_count; + double multiplier = 1.0; if (blk->children.size() > 0) - { for (auto const& child : blk->children) - worst_case_execution += compute_wce(&child); - } + worst_case_execution += compute_wce(&child, level + 1); if (blk->parent == 0 || blk->parent->iteration_bound == 0) // this condtion should never occur [defensively programmed] + { + PRINT_WCE(1); return worst_case_execution; + } // if the block has a parent then the quotient of its guard and its parent's guard // gives us the loop iterations and thus the multiplier for the instruction count - double multiplier = + multiplier = ((double)(blk->iteration_bound)) / ((double)(blk->parent->iteration_bound)); - if (multiplier < 1.0) - return worst_case_execution; - worst_case_execution *= multiplier; + if (worst_case_execution < 1.0) + worst_case_execution = 1.0; + + PRINT_WCE(3); return worst_case_execution; };