File: reference_bitwise_operators.pass.cpp

package info (click to toggle)
llvm-toolchain-21 1%3A21.1.7-1
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 2,245,064 kB
  • sloc: cpp: 7,619,731; ansic: 1,434,018; asm: 1,058,748; python: 252,740; f90: 94,671; objc: 70,685; lisp: 42,813; pascal: 18,401; sh: 8,601; ml: 5,111; perl: 4,720; makefile: 3,676; awk: 3,523; javascript: 2,409; xml: 892; fortran: 770
file content (117 lines) | stat: -rw-r--r-- 4,035 bytes parent folder | download | duplicates (5)
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
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

// UNSUPPORTED: c++03, c++11, c++14

// <experimental/simd>
//
// [simd.reference]
// template<class U> reference|=(U&& x) && noexcept;
// template<class U> reference&=(U&& x) && noexcept;
// template<class U> reference^=(U&& x) && noexcept;
// template<class U> reference<<=(U&& x) && noexcept;
// template<class U> reference>>=(U&& x) && noexcept;

#include <experimental/simd>
#include <functional>

#include "../test_utils.h"

namespace ex = std::experimental::parallelism_v2;

struct AndAssign {
  template <typename T, typename U>
  void operator()(T&& lhs, const U& rhs) const noexcept {
    std::forward<T>(lhs) &= rhs;
  }
};

struct OrAssign {
  template <typename T, typename U>
  void operator()(T&& lhs, const U& rhs) const noexcept {
    std::forward<T>(lhs) |= rhs;
  }
};

struct XorAssign {
  template <typename T, typename U>
  void operator()(T&& lhs, const U& rhs) const noexcept {
    std::forward<T>(lhs) ^= rhs;
  }
};

struct LeftShiftAssign {
  template <typename T, typename U>
  void operator()(T&& lhs, const U& rhs) const noexcept {
    std::forward<T>(lhs) <<= rhs;
  }
};

struct RightShiftAssign {
  template <typename T, typename U>
  void operator()(T&& lhs, const U& rhs) const noexcept {
    std::forward<T>(lhs) >>= rhs;
  }
};

struct LeftShift {
  template <typename T, typename U>
  T operator()(const T& lhs, const U& rhs) const noexcept {
    return lhs << rhs;
  }
};

struct RightShift {
  template <typename T, typename U>
  T operator()(const T& lhs, const U& rhs) const noexcept {
    return lhs >> rhs;
  }
};

template <typename T, typename SimdAbi, typename Op, typename OpAssign>
struct SimdReferenceOperatorHelper {
  template <class U>
  void operator()() const {
    ex::simd<T, SimdAbi> origin_simd(static_cast<T>(3));
    static_assert(noexcept(OpAssign{}(origin_simd[0], static_cast<U>(2))));
    OpAssign{}(origin_simd[0], static_cast<U>(2));
    assert((T)origin_simd[0] == (T)Op{}(static_cast<T>(3), static_cast<T>(std::forward<U>(2))));
  }
};

template <typename T, typename SimdAbi, typename Op, typename OpAssign>
struct MaskReferenceOperatorHelper {
  template <class U>
  void operator()() const {
    ex::simd_mask<T, SimdAbi> origin_mask(true);
    static_assert(noexcept(OpAssign{}(origin_mask[0], static_cast<U>(false))));
    OpAssign{}(origin_mask[0], static_cast<U>(false));
    assert((bool)origin_mask[0] == (bool)Op{}(true, static_cast<bool>(std::forward<U>(false))));
  }
};

template <class T, std::size_t>
struct CheckReferenceBitwiseOperators {
  template <class SimdAbi>
  void operator()() {
    types::for_each(simd_test_integer_types(), SimdReferenceOperatorHelper<T, SimdAbi, std::bit_and<>, AndAssign>());
    types::for_each(simd_test_integer_types(), SimdReferenceOperatorHelper<T, SimdAbi, std::bit_or<>, OrAssign>());
    types::for_each(simd_test_integer_types(), SimdReferenceOperatorHelper<T, SimdAbi, std::bit_xor<>, XorAssign>());
    types::for_each(simd_test_integer_types(), SimdReferenceOperatorHelper<T, SimdAbi, LeftShift, LeftShiftAssign>());
    types::for_each(simd_test_integer_types(), SimdReferenceOperatorHelper<T, SimdAbi, RightShift, RightShiftAssign>());

    types::for_each(simd_test_integer_types(), MaskReferenceOperatorHelper<T, SimdAbi, std::bit_and<>, AndAssign>());
    types::for_each(simd_test_integer_types(), MaskReferenceOperatorHelper<T, SimdAbi, std::bit_or<>, OrAssign>());
    types::for_each(simd_test_integer_types(), MaskReferenceOperatorHelper<T, SimdAbi, std::bit_xor<>, XorAssign>());
  }
};

int main(int, char**) {
  types::for_each(types::integer_types(), TestAllSimdAbiFunctor<CheckReferenceBitwiseOperators>());
  return 0;
}