Line | Branch | Exec | Source |
---|---|---|---|
1 | // | ||
2 | // SPDX-FileCopyrightText: Copyright 2024 Arm Limited and/or its affiliates <open-source-office@arm.com> | ||
3 | // | ||
4 | // SPDX-License-Identifier: Apache-2.0 | ||
5 | // | ||
6 | |||
7 | #include "test/common/data_type.hpp" | ||
8 | |||
9 | #include <cstddef> | ||
10 | #include <cstdint> | ||
11 | |||
12 | #include "kai/kai_common.h" | ||
13 | |||
14 | namespace kai::test { | ||
15 | |||
16 | namespace { | ||
17 | |||
18 | 2595 | bool has_i(DataType dt) { | |
19 | 2595 | return (static_cast<uint16_t>(dt) & (1 << 15)) != 0; | |
20 | } | ||
21 | |||
22 | ✗ | bool has_s(DataType dt) { | |
23 | ✗ | return (static_cast<uint16_t>(dt) & (1 << 14)) != 0; | |
24 | } | ||
25 | |||
26 | ✗ | bool has_q(DataType dt) { | |
27 | ✗ | return (static_cast<uint16_t>(dt) & (1 << 13)) != 0; | |
28 | } | ||
29 | |||
30 | ✗ | bool has_a(DataType dt) { | |
31 | ✗ | return (static_cast<uint16_t>(dt) & (1 << 12)) != 0; | |
32 | } | ||
33 | |||
34 | 67361 | size_t bits(DataType dt) { | |
35 | 67361 | return static_cast<uint16_t>(dt) & 0xFF; | |
36 | } | ||
37 | |||
38 | } // namespace | ||
39 | |||
40 | 67361 | size_t data_type_size_in_bits(DataType dt) { | |
41 | 67361 | return bits(dt); | |
42 | } | ||
43 | |||
44 | 2595 | bool data_type_is_integral(DataType dt) { | |
45 | 2595 | return has_i(dt); | |
46 | } | ||
47 | |||
48 | ✗ | bool data_type_is_float(DataType dt) { | |
49 | − | KAI_ASSERT(data_type_is_signed(dt)); | |
50 | ✗ | return !data_type_is_integral(dt); | |
51 | } | ||
52 | |||
53 | ✗ | bool data_type_is_float_fp(DataType dt) { | |
54 | − | KAI_ASSERT(data_type_is_float(dt)); | |
55 | ✗ | return !has_q(dt); | |
56 | } | ||
57 | |||
58 | ✗ | bool data_type_is_float_bf(DataType dt) { | |
59 | − | KAI_ASSERT(data_type_is_float(dt)); | |
60 | ✗ | return has_q(dt); | |
61 | } | ||
62 | |||
63 | ✗ | bool data_type_is_signed(DataType dt) { | |
64 | ✗ | if (!has_s(dt)) { | |
65 | − | KAI_ASSERT(data_type_is_integral(dt)); | |
66 | ✗ | } | |
67 | |||
68 | ✗ | return has_s(dt); | |
69 | } | ||
70 | |||
71 | 2595 | bool data_type_is_quantized(DataType dt) { | |
72 |
1/2✓ Branch 0 taken 2595 times.
✗ Branch 1 not taken.
|
2595 | return data_type_is_integral(dt) && has_q(dt); |
73 | } | ||
74 | |||
75 | ✗ | bool data_type_is_quantized_asymm(DataType dt) { | |
76 | ✗ | return data_type_is_quantized(dt) && has_a(dt); | |
77 | } | ||
78 | |||
79 | } // namespace kai::test | ||
80 |