From e5d22a77300643f0a3013ad40ccd2b5b76788b42 Mon Sep 17 00:00:00 2001 From: Eric Kunze Date: Tue, 15 Dec 2020 15:41:05 -0800 Subject: Disambiguate scale_t in RESIZE command scale_t is already defined globally for the rescaling. Move pseudocode for count_leading_zeros to introduction, and use it in the implementation of CLZ. Change-Id: I2453bce93b6dd25e870b8a010fc62af4c001cbf9 --- chapters/introduction.adoc | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'chapters/introduction.adoc') diff --git a/chapters/introduction.adoc b/chapters/introduction.adoc index 3133f36..da1c1b1 100644 --- a/chapters/introduction.adoc +++ b/chapters/introduction.adoc @@ -330,8 +330,9 @@ acc_t apply_sub(acc_t a, acc_t b) { } .... -The following functions are used in the pseudocode to take maximum, minimum or clip values to a range. - +The following functions are used in the pseudocode to take maximum, +minimum, clip values to a range, or count leading zeros. +[[count_leading_zeros]] .... apply_max( a, b) { if (a >= b) return a; else return b; @@ -347,6 +348,20 @@ The following functions are used in the pseudocode to take maximum, minimum or c value = apply_min(value, max_val); return value; } + +int32_t count_leading_zeros(int32_t a) { + int32_t acc = 32; + if (a != 0) { + uint32_t mask; + mask = 1 << (32 - 1); // width of int32_t - 1 + acc = 0; + while ((mask & a) == 0) { + mask = mask >> 1; + acc = acc + 1; + } + } + return acc; +} .... ==== Quantized Convolutions -- cgit v1.2.1