forked from google/XNNPACK
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathu32-simd-scalar.cc
68 lines (58 loc) · 1.9 KB
/
u32-simd-scalar.cc
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
// Auto-generated file. Do not edit!
// Template: test/u32-simd.cc.in
// Generator: tools/xngen
//
// Copyright 2024 Google LLC
//
// This source code is licensed under the BSD-style license found in the
// LICENSE file in the root directory of this source tree.
#include <algorithm>
#include <cmath>
#include <cstddef>
#include <cstdint>
#include <limits>
#include <random>
#include <vector>
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include "xnnpack/isa-checks.h"
#include "xnnpack/simd/u32-scalar.h"
#include "replicable_random_device.h"
namespace xnnpack {
class U32SimdSCALARTest : public ::testing::Test {
protected:
void SetUp() override {
inputs_.resize(3 * xnn_simd_size_u32);
output_.resize(xnn_simd_size_u32);
std::uniform_int_distribution<uint32_t> u32dist(0, 20000);
std::generate(inputs_.begin(), inputs_.end(),
[&]() { return u32dist(rng_); });
}
xnnpack::ReplicableRandomDevice rng_;
std::vector<uint32_t> inputs_;
std::vector<uint32_t> output_;
};
TEST_F(U32SimdSCALARTest, Mul) {
const xnn_simd_u32_t a = xnn_loadu_u32(inputs_.data());
const xnn_simd_u32_t b = xnn_loadu_u32(inputs_.data() + xnn_simd_size_u32);
const xnn_simd_u32_t res = xnn_mul_u32(a, b);
xnn_storeu_u32(output_.data(), res);
for (size_t k = 0; k < xnn_simd_size_u32; k++) {
ASSERT_EQ(output_[k], inputs_[k] * inputs_[k + xnn_simd_size_u32]);
}
}
TEST_F(U32SimdSCALARTest, StoreTail) {
const xnn_simd_u32_t a = xnn_loadu_u32(inputs_.data());
for (size_t num_elements = 1; num_elements < xnn_simd_size_u32;
num_elements++) {
std::fill(output_.begin(), output_.end(), 0.0f);
xnn_store_tail_u32(output_.data(), a, num_elements);
for (size_t k = 0; k < num_elements; k++) {
ASSERT_EQ(output_[k], inputs_[k]);
}
for (size_t k = num_elements; k < xnn_simd_size_u32; k++) {
ASSERT_EQ(output_[k], 0.0f);
}
}
}
} // namespace xnnpack