KleidiAI Coverage Report


Directory: ./
File: test/common/round.cpp
Date: 2025-10-20 13:18:31
Coverage Exec Excl Total
Lines: 85.7% 12 4 18
Functions: 85.7% 6 0 7
Branches: -% 0 8 8

Line Branch Exec Source
1 //
2 // SPDX-FileCopyrightText: Copyright 2024-2025 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/round.hpp"
8
9 #include <cstddef>
10 #include <cstdint>
11
12 #include "kai/kai_common.h"
13
14 extern "C" {
15
16 /// Rounds the specified value to nearest with tie to even.
17 ///
18 /// @param[in] value The value to be rounded.
19 ///
20 /// @return The rounded value.
21 int32_t kai_test_round_to_nearest_even_i32_f32(float value);
22
23 /// Rounds the specified value to nearest with tie to even.
24 ///
25 /// @param[in] value The value to be rounded.
26 ///
27 /// @return The rounded value.
28 int64_t kai_test_round_to_nearest_even_i64_f32(float value);
29 }
30
31 namespace kai::test {
32
33 92897202 int32_t round_to_nearest_even_i32(float value) {
34 92897202 return kai_test_round_to_nearest_even_i32_f32(value);
35 }
36
37 247440 size_t round_to_nearest_even_usize(float value) {
38 static_assert(sizeof(size_t) == sizeof(uint64_t));
39 KAI_ASSUME(value >= 0);
40 247440 return static_cast<size_t>(kai_test_round_to_nearest_even_i64_f32(value));
41 }
42
43 template <>
44 36898147 int32_t round_to_nearest_even(float value) {
45 36898147 return round_to_nearest_even_i32(value);
46 }
47
48 template <>
49 size_t round_to_nearest_even(float value) {
50 return round_to_nearest_even_usize(value);
51 }
52
53 304115 size_t round_up_multiple(size_t a, size_t b) {
54 KAI_ASSUME(b != 0);
55 304115 return ((a + b - 1) / b) * b;
56 }
57
58 241298 size_t round_up_division(size_t a, size_t b) {
59 KAI_ASSUME(b != 0);
60 241298 return (a + b - 1) / b;
61 }
62
63 247440 size_t round_down_multiple(size_t a, size_t b) {
64 KAI_ASSUME(b != 0);
65 247440 return (a / b) * b;
66 }
67
68 } // namespace kai::test
69