From 5518daf197447ea54a1f4ed6230c4b3205e58dcf Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Sat, 31 Jul 2021 23:23:23 -0700 Subject: [PATCH] ircd::gpt: Remove branch by assuming loop body always taken. --- ircd/gpt.cc | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/ircd/gpt.cc b/ircd/gpt.cc index e562517ce..4adaecaac 100644 --- a/ircd/gpt.cc +++ b/ircd/gpt.cc @@ -805,8 +805,30 @@ ircd::gpt::adamw(task &task, reinterpret_cast(m_[1]) + off, }; - for(uint i(0); i < num / 4; ++i) - off = adamw(p[0][i], p[1][i], p[2][i], grad, opts.alpha, opts.beta[0], opts.beta[1], ctrl.epic.step, off); + assert(num >= 4); + const uint n + { + uint(num) / 4 + }; + + // Assume loop body always taken w/o soundness; otherwise extra branch. + assert(n > 0); + uint i(0); do + { + off = adamw + ( + p[0][i], + p[1][i], + p[2][i], + grad, + opts.alpha, + opts.beta[0], + opts.beta[1], + ctrl.epic.step, + off + ); + } + while(++i < n); return off; }