File: uint16_sse4_tests.cpp

package info (click to toggle)
intel-compute-runtime 22.43.24595.41-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 57,740 kB
  • sloc: cpp: 631,142; lisp: 3,515; sh: 470; makefile: 76; python: 21
file content (131 lines) | stat: -rw-r--r-- 4,074 bytes parent folder | download | duplicates (3)
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/*
 * Copyright (C) 2018-2022 Intel Corporation
 *
 * SPDX-License-Identifier: MIT
 *
 */

#include "shared/source/helpers/aligned_memory.h"
#include "shared/source/helpers/uint16_sse4.h"

#include "gtest/gtest.h"

using namespace NEO;

TEST(Uint16Sse4, GivenMaskWhenCastingToBoolThenTrueIsReturned) {
    EXPECT_TRUE(static_cast<bool>(NEO::uint16x8_t::mask()));
}

TEST(Uint16Sse4, GivenZeroWhenCastingToBoolThenFalseIsReturned) {
    EXPECT_FALSE(static_cast<bool>(NEO::uint16x8_t::zero()));
}

TEST(Uint16Sse4, WhenConjoiningMaskAndZeroThenBooleanResultIsCorrect) {
    EXPECT_TRUE(NEO::uint16x8_t::mask() && NEO::uint16x8_t::mask());
    EXPECT_FALSE(NEO::uint16x8_t::mask() && NEO::uint16x8_t::zero());
    EXPECT_FALSE(NEO::uint16x8_t::zero() && NEO::uint16x8_t::mask());
    EXPECT_FALSE(NEO::uint16x8_t::zero() && NEO::uint16x8_t::zero());
}

TEST(Uint16Sse4, GivenOneWhenCreatingThenInstancesAreSame) {
    auto one = NEO::uint16x8_t::one();
    NEO::uint16x8_t alsoOne(one.value);
    EXPECT_EQ(0, memcmp(&alsoOne, &one, sizeof(NEO::uint16x8_t)));
}

TEST(Uint16Sse4, GivenValueWhenCreatingThenConstructorIsReplicated) {
    NEO::uint16x8_t allSevens(7u);
    for (int i = 0; i < NEO::uint16x8_t::numChannels; ++i) {
        EXPECT_EQ(7u, allSevens.get(i));
    }
}

ALIGNAS(32)
static const uint16_t laneValues[] = {
    0, 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};

TEST(Uint16Sse4, GivenArrayWhenCreatingThenConstructorIsReplicated) {
    NEO::uint16x8_t lanes(laneValues);
    for (int i = 0; i < NEO::uint16x8_t::numChannels; ++i) {
        EXPECT_EQ(static_cast<uint16_t>(i), lanes.get(i));
    }
}

TEST(Uint16Sse4, WhenLoadingThenValuesAreSetCorrectly) {
    NEO::uint16x8_t lanes;
    lanes.load(laneValues);
    for (int i = 0; i < NEO::uint16x8_t::numChannels; ++i) {
        EXPECT_EQ(static_cast<uint16_t>(i), lanes.get(i));
    }
}

TEST(Uint16Sse4, WhenLoadingUnalignedThenValuesAreSetCorrectly) {
    NEO::uint16x8_t lanes;
    lanes.loadUnaligned(laneValues + 1);
    for (int i = 0; i < NEO::uint16x8_t::numChannels; ++i) {
        EXPECT_EQ(static_cast<uint16_t>(i + 1), lanes.get(i));
    }
}

TEST(Uint16Sse4, WhenStoringThenValuesAreSetCorrectly) {
    uint16_t *alignedMemory = reinterpret_cast<uint16_t *>(alignedMalloc(1024, 32));

    NEO::uint16x8_t lanes(laneValues);
    lanes.store(alignedMemory);
    for (int i = 0; i < NEO::uint16x8_t::numChannels; ++i) {
        EXPECT_EQ(static_cast<uint16_t>(i), alignedMemory[i]);
    }

    alignedFree(alignedMemory);
}

TEST(Uint16Sse4, WhenStoringUnalignedThenValuesAreSetCorrectly) {
    uint16_t *alignedMemory = reinterpret_cast<uint16_t *>(alignedMalloc(1024, 32));

    NEO::uint16x8_t lanes(laneValues);
    lanes.storeUnaligned(alignedMemory + 1);
    for (int i = 0; i < NEO::uint16x8_t::numChannels; ++i) {
        EXPECT_EQ(static_cast<uint16_t>(i), (alignedMemory + 1)[i]);
    }

    alignedFree(alignedMemory);
}

TEST(Uint16Sse4, WhenDecrementingThenValuesAreSetCorrectly) {
    NEO::uint16x8_t result(laneValues);
    result -= NEO::uint16x8_t::one();

    for (int i = 0; i < NEO::uint16x8_t::numChannels; ++i) {
        EXPECT_EQ(static_cast<uint16_t>(i - 1), result.get(i));
    }
}

TEST(Uint16Sse4, WhenIncrementingThenValuesAreSetCorrectly) {
    NEO::uint16x8_t result(laneValues);
    result += NEO::uint16x8_t::one();

    for (int i = 0; i < NEO::uint16x8_t::numChannels; ++i) {
        EXPECT_EQ(static_cast<uint16_t>(i + 1), result.get(i));
    }
}

TEST(Uint16Sse4, WhenBlendingThenValuesAreSetCorrectly) {
    NEO::uint16x8_t a(NEO::uint16x8_t::one());
    NEO::uint16x8_t b(NEO::uint16x8_t::zero());
    NEO::uint16x8_t c;

    // c = mask ? a : b
    c = blend(a, b, NEO::uint16x8_t::mask());

    for (int i = 0; i < NEO::uint16x8_t::numChannels; ++i) {
        EXPECT_EQ(a.get(i), c.get(i));
    }

    // c = mask ? a : b
    c = blend(a, b, NEO::uint16x8_t::zero());

    for (int i = 0; i < NEO::uint16x8_t::numChannels; ++i) {
        EXPECT_EQ(b.get(i), c.get(i));
    }
}