aboutsummaryrefslogtreecommitdiff
path: root/pseudocode/library/generic_helpers.tosac
blob: 6dc2755bf0851615fbe2c7957b3ac65fe176683c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
//
// This confidential and proprietary software may be used only as
// authorised by a licensing agreement from ARM Limited
// (C) COPYRIGHT 2020-2024 ARM Limited
// ALL RIGHTS RESERVED
// The entire notice above must be reproduced on all authorised
// copies and copies may only be made to the extent permitted
// by a licensing agreement from ARM Limited.

bool_t is_floating_point<type>() {
    if (type == fp16_t || type == fp32_t || type == bf16_t || type == fp8e4m3_t || type == fp8e5m2_t)
        return true;
    return false;
}

int32_t idiv(int32_t input1, int32_t input2) {
    return input1 / input2; // Integer divide that truncates towards zero
}

// Integer division that checks input1 is a multiple of input2

int32_t idiv_check(int32_t input1, int32_t input2) {
    ERROR_IF(input1 % input2 != 0); // input1 must be a multiple of input2
    return input1 / input2;         // exact quotient without rounding
}

// perform an integer division with rounding towards minus infinity

int32_t idiv_floor(int32_t input1, int32_t input2) {
    int32_t rval = input1 / input2;
    if (rval * input2 > input1) {
        rval--;
    }
    return rval;
}

// return number of elements in input list
int32_t length(in_t input);

// return rank of an input tensor
int32_t rank(in_t input);

// return the sum of values of an input list
int32_t sum(in_t input[]);

// return True if floating-point input value is NaN
bool_t isNaN(float input);

// returns value of pi
float_t pi();

// return sine of angle given in radians
float_t sin(float_t angle);

// return cosine of angle given in radians
float_t cos(float_t angle);

// return true if value is a power of two, false otherwise
bool_t power_of_two(int32_t value);

// 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>();

// 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>();

// 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>();

// 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<in_out_t>();