1 /*
2 * Copyright (C) 2020 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #include <audio_utils/intrinsic_utils.h>
18
19 #include <gtest/gtest.h>
20
21 template <typename D>
22 class IntrisicUtilsTest : public ::testing::Test { };
23
24 // Basic intrinsic tests which are run on the simple scalar types (no NEON SIMD vector registers).
25 using FloatTypes = ::testing::Types<float, double>;
26 TYPED_TEST_CASE(IntrisicUtilsTest, FloatTypes);
27
TYPED_TEST(IntrisicUtilsTest,vdupn)28 TYPED_TEST(IntrisicUtilsTest, vdupn) {
29 constexpr TypeParam value = 1.f;
30 ASSERT_EQ(value, android::audio_utils::intrinsics::vdupn<TypeParam>(value));
31 }
32
TYPED_TEST(IntrisicUtilsTest,vld1)33 TYPED_TEST(IntrisicUtilsTest, vld1) {
34 constexpr TypeParam value = 2.f;
35 ASSERT_EQ(value, android::audio_utils::intrinsics::vld1<TypeParam>(&value));
36 }
37
TYPED_TEST(IntrisicUtilsTest,vmla)38 TYPED_TEST(IntrisicUtilsTest, vmla) {
39 constexpr TypeParam a = 2.125f;
40 constexpr TypeParam b = 2.25f;
41 constexpr TypeParam c = 2.5f;
42 constexpr TypeParam result = c + a * b;
43 ASSERT_EQ(result, android::audio_utils::intrinsics::vmla(c, a, b));
44 }
45
TYPED_TEST(IntrisicUtilsTest,vmul)46 TYPED_TEST(IntrisicUtilsTest, vmul) {
47 constexpr TypeParam a = 2.25f;
48 constexpr TypeParam b = 2.5f;
49 constexpr TypeParam result = a * b;
50 ASSERT_EQ(result, android::audio_utils::intrinsics::vmul(a, b));
51 }
52
TYPED_TEST(IntrisicUtilsTest,vneg)53 TYPED_TEST(IntrisicUtilsTest, vneg) {
54 constexpr TypeParam value = 3.125f;
55 ASSERT_EQ(-value, android::audio_utils::intrinsics::vneg(value));
56 }
57
TYPED_TEST(IntrisicUtilsTest,vst1)58 TYPED_TEST(IntrisicUtilsTest, vst1) {
59 constexpr TypeParam value = 2.f;
60 TypeParam destination = 1.f;
61 android::audio_utils::intrinsics::vst1(
62 &destination, android::audio_utils::intrinsics::vdupn<TypeParam>(value));
63 ASSERT_EQ(value, destination);
64 }
65