From 82f19e2ad25bcbdde8e7f8b6bd6a6064a207fe36 Mon Sep 17 00:00:00 2001 From: Eric Kunze Date: Mon, 25 Oct 2021 16:13:22 -0700 Subject: Readability fixes for pseudocode Avoid use of acc for variables when they are not convolution accumulators. Use argument types appropriately. Add missing pseudocode for some MI operators Change-Id: I9113f9228dbcafb85206bcc39310e9599cb12c08 --- chapters/pseudocode.adoc | 74 ++++++++++++++++++++++++++++++------------------ 1 file changed, 47 insertions(+), 27 deletions(-) (limited to 'chapters/pseudocode.adoc') diff --git a/chapters/pseudocode.adoc b/chapters/pseudocode.adoc index 16e7e67..d5f05db 100644 --- a/chapters/pseudocode.adoc +++ b/chapters/pseudocode.adoc @@ -54,43 +54,61 @@ void ERROR_IF(condition) { This section contains general pseudocode utility functions used throughout the specification. -The following functions provide basic arithmetic while defining requirements such that values stay in the valid range. +The following functions provide arithmetic while defining requirements such that values stay in the valid range. [source,c++] ---- -acc_t apply_add(acc_t a, acc_t b) { - if (acc_t == float_t) return a + b; +in_t apply_add(in_t a, in_t b) { + if ( == float_t) return a + b; int64_t c = (int64_t)a + (int64_t)b; - REQUIRE(c >= minimum && c <= maximum); - return (acc_t)c; + REQUIRE(c >= minimum && c <= maximum); + return (in_t)c; } -acc_t apply_sub(acc_t a, acc_t b) { - if (acc_t == float_t) return a - b; - int64_t c = (int64_t)a - (int64_t)b; - REQUIRE(c >= minimum && c <= maximum); - return (acc_t)c; +in_t apply_ceil(in_t input) { + return input value rounded up to nearest integer } ----- -The following functions are used in the pseudocode to take maximum, -minimum, clip values to a range, or count leading zeros. -[[count_leading_zeros]] -[source,c++] ----- - apply_max( a, b) { +in_t apply_clip(in_t value, in_t min_val, in_t max_val) { + REQUIRE(min_val <= max_val); + value = apply_max(value, min_val); + value = apply_min(value, max_val); + return value; +} + +in_t apply_exp(in_t input) { + return e to the power input +} + +in_t apply_floor(in_t input) { + return input value rounded down to nearest integer +} + +in_t apply_log(in_t input) { + return the natural logarithm of input +} + +in_t apply_max(in_t a, in_t b) { if (a >= b) return a; else return b; } - apply_min( a, b) { +in_t apply_min(in_t a, in_t b) { if (a < b) return a; else return b; } - apply_clip( value, min_val, max_val) { - REQUIRE(min_val <= max_val); - value = apply_max(value, min_val); - value = apply_min(value, max_val); - return value; +in_t apply_pow(in_t a, in_t b) { + return a ** b; // a raised to the power b +} + +in_t apply_sqrt(in_t input) { + return the square root of input +} + +in_t apply_sub(in_t a, in_t b) { + if (in_t == float_t) return a - b; + int64_t c = (int64_t)a - (int64_t)b; + REQUIRE(c >= minimum && c <= maximum); + return (in_t)c; } int32_t count_leading_zeros(int32_t a) { @@ -146,15 +164,17 @@ Generic helper functions used to keep the pseudocode concise. [source,c++] ---- + +int idiv(int input1, int input2) { + return input1 / input2; // Integer divide that truncates towards zero +} + int length(in_t input) return number of elements in input list -int floor(in_t input) - return input value rounded down to nearest integer - int rank(in_t input) return rank of an input tensor int sum(in_t input[]) return the sum of values of an input list ----- \ No newline at end of file +---- -- cgit v1.2.1