From 667e62897a809ab3af832e7778139d3869532277 Mon Sep 17 00:00:00 2001 From: Kevin Petit Date: Thu, 8 Feb 2024 11:03:26 +0000 Subject: pseudocode: use function declaration syntax for library functions that are not defined Also: - Add missing semicolon - Fix prototype for is_floating_point to use template syntax Change-Id: I9ec1c687a3854b73ddac78f4db0db8e10f4e10e6 Signed-off-by: Kevin Petit --- pseudocode/library/arithmetic_helpers.tosac | 27 ++++++----- pseudocode/library/generic_helpers.tosac | 52 +++++++++++----------- .../library/numeric_conversion_helpers.tosac | 40 ++++++++--------- 3 files changed, 59 insertions(+), 60 deletions(-) diff --git a/pseudocode/library/arithmetic_helpers.tosac b/pseudocode/library/arithmetic_helpers.tosac index 1b8de0f..a50ab43 100644 --- a/pseudocode/library/arithmetic_helpers.tosac +++ b/pseudocode/library/arithmetic_helpers.tosac @@ -32,9 +32,8 @@ in_t apply_intdiv_s(in_t a, in_t b) { return static_cast(c); } -in_t apply_ceil(in_t input) { - return input value rounded up to nearest integer -} +// return input value rounded up to nearest integer +in_t apply_ceil(in_t input); in_t apply_clip_s(in_t value, in_t min_val, in_t max_val) { if (is_floating_point()) { @@ -55,22 +54,23 @@ in_t apply_clip_u(in_t value, in_t min_val, in_t max_val) { return value; } -in_t apply_exp(in_t input) { - return e to the power input -} +// return e to the power input +in_t apply_exp(in_t input); -in_t apply_floor(in_t input) { - return input value rounded down to nearest integer -} +// return input value rounded down to nearest integer +in_t apply_floor(in_t input); + +// return the natural logarithm of input +in_t apply_log_positive_input(in_t input); in_t apply_log(in_t input) { if (input == 0) { - return -INFINITY + return -INFINITY; } else if (input < 0) { return NaN; } - return the natural logarithm of input + return apply_log_positive_input(input); } in_t apply_logical_rshift(in_t a, in_t b) { @@ -118,9 +118,8 @@ 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 -} +// return the square root of input +in_t apply_sqrt(in_t input); in_t apply_sub_s(in_t a, in_t b) { if (is_floating_point()) return a - b; diff --git a/pseudocode/library/generic_helpers.tosac b/pseudocode/library/generic_helpers.tosac index a2fdbe0..eabc9b2 100644 --- a/pseudocode/library/generic_helpers.tosac +++ b/pseudocode/library/generic_helpers.tosac @@ -7,13 +7,13 @@ // copies and copies may only be made to the extent permitted // by a licensing agreement from ARM Limited. -bool_t is_floating_point(type) { +bool_t is_floating_point() { if (type == fp16_t || type == fp32_t || type == bf16_t || type == fp8e4m3_t || type == fp8e5m2_t) return true; return false; } -bool_t is_saturating_float_type(type) { +bool_t is_saturating_float_type() { // Saturate for the fp8 formats, all other floats do not saturate if (type == fp8e4m3_t || type == fp8e5m2_t) { return true; @@ -43,38 +43,38 @@ int32_t idiv_floor(int32_t input1, int32_t input2) { return rval; } -int32_t length(in_t input) - return number of elements in input list +// return number of elements in input list +int32_t length(in_t input); -int32_t rank(in_t input) - return rank of an input tensor +// return rank of an input tensor +int32_t rank(in_t input); -int32_t sum(in_t input[]) - return the sum of values of an input list +// return the sum of values of an input list +int32_t sum(in_t input[]); -bool isNaN(float input) - return True if floating-point input value is NaN +// return True if floating-point input value is NaN +bool_t isNaN(float input); -float_t pi() - returns value of pi +// returns value of pi +float_t pi(); -float_t sin(angle) - return sine of angle given in radians +// return sine of angle given in radians +float_t sin(float_t angle); -float_t cos(angle) - return cosine of angle given in radians +// return cosine of angle given in radians +float_t cos(float_t angle); -bool power_of_two(int32_t value) - return true if value is a power of two, false otherwise +// return true if value is a power of two, false otherwise +bool_t power_of_two(int32_t value); -in_out_t maximum_s - return the maximum value when interpreting type T as a signed value as returned by the make_signed helper. +// return the maximum value when interpreting type in_out_t as a signed value as returned by the make_signed helper. +in_out_t maximum_s(); -in_out_t minimum_s - return the minimum value when interpreting type T as a signed value as returned by the make_signed helper. +// return the minimum value when interpreting type in_out_t as a signed value as returned by the make_signed helper. +in_out_t minimum_s(); -in_out_t maximum_u - return the maximum value when interpreting type T as an unsigned value as returned by the make_unsigned helper. +// return the maximum value when interpreting type in_out_t as an unsigned value as returned by the make_unsigned helper. +in_out_t maximum_u(); -in_out_t minimum_u - return the minimum value when interpreting type T as an unsigned value as returned by the make_unsigned helper. +// return the minimum value when interpreting type in_out_t as an unsigned value as returned by the make_unsigned helper. +in_out_t minimum_u(); diff --git a/pseudocode/library/numeric_conversion_helpers.tosac b/pseudocode/library/numeric_conversion_helpers.tosac index 576351f..0073a66 100644 --- a/pseudocode/library/numeric_conversion_helpers.tosac +++ b/pseudocode/library/numeric_conversion_helpers.tosac @@ -7,28 +7,28 @@ // copies and copies may only be made to the extent permitted // by a licensing agreement from ARM Limited. -int round_to_nearest_int(float_t f) - Converts the floating-point value to f, with rounding to the nearest integer value. - For the required precision see the section: Main inference precision requirements. +// Converts the floating-point value to f, with rounding to the nearest integer value. +// For the required precision see the section: Main inference precision requirements. +int round_to_nearest_int(float_t f); -float_t round_to_nearest_float_nonsaturating(in_t f) - Converts the input value into floating-point, rounding to the nearest representable value. - Values that are not NaN outside of the representable range of the destination type must be set to infinity of the correct sign. - For the required precision see the section: Main inference precision requirements. +// Converts the input value into floating-point, rounding to the nearest representable value. +// Values that are not NaN outside of the representable range of the destination type must be set to infinity of the correct sign. +// For the required precision see the section: Main inference precision requirements. +float_t round_to_nearest_float_nonsaturating(in_t f); -float_t round_to_nearest_float_saturating(in_t f) - Converts the input value into floating-point, rounding to the nearest representable normal value. - Values that are not NaN outside of the representable range must return the maximum representable normal value of the correct sign. - For the required precision see the section: Main inference precision requirements. +// Converts the input value into floating-point, rounding to the nearest representable normal value. +// Values that are not NaN outside of the representable range must return the maximum representable normal value of the correct sign. +// For the required precision see the section: Main inference precision requirements. +float_t round_to_nearest_float_saturating(in_t f); -out_t sign_extend(in_t input) - Floating point values are unchanged. - For two's complement integer values where out_t has more bits than in_t, replicate the top bit of input for all bits between the top bit of input and the top bit of output. +// Floating point values are unchanged. +// For two's complement integer values where out_t has more bits than in_t, replicate the top bit of input for all bits between the top bit of input and the top bit of output. +out_t sign_extend(in_t input); -out_t zero_extend(in_t input) - Floating point values are unchanged. - For two's complement integer values where out_t has more bits than in_t, insert zero values for all bits between the top bit of input and the top bit of output. +// Floating point values are unchanged. +// For two's complement integer values where out_t has more bits than in_t, insert zero values for all bits between the top bit of input and the top bit of output. +out_t zero_extend(in_t input); -out_t truncate(in_t input) - output is the sizeof(out_t) least significant bits in input. - Nop for floating-point types +// output is the sizeof(out_t) least significant bits in input. +// Nop for floating-point types +out_t truncate(in_t input); -- cgit v1.2.1