|
| 1 | +#define __SYCL_CONSTEXPR_HALF constexpr |
| 2 | +using StorageT = _Float16; |
| 3 | + |
| 4 | +class half { |
| 5 | +public: |
| 6 | + half() = default; |
| 7 | + constexpr half(const half &) = default; |
| 8 | + constexpr half(half &&) = default; |
| 9 | + |
| 10 | + __SYCL_CONSTEXPR_HALF half(const float &rhs) : Data(rhs) {} |
| 11 | + |
| 12 | + constexpr half &operator=(const half &rhs) = default; |
| 13 | + |
| 14 | + __SYCL_CONSTEXPR_HALF half &operator/=(const half &rhs) { |
| 15 | + Data /= rhs.Data; |
| 16 | + return *this; |
| 17 | + } |
| 18 | + |
| 19 | +#define OP(op, op_eq) \ |
| 20 | + __SYCL_CONSTEXPR_HALF friend half operator op(const half lhs, \ |
| 21 | + const half rhs) { \ |
| 22 | + half rtn = lhs; \ |
| 23 | + rtn op_eq rhs; \ |
| 24 | + return rtn; \ |
| 25 | + } \ |
| 26 | + __SYCL_CONSTEXPR_HALF friend double operator op(const half lhs, \ |
| 27 | + const double rhs) { \ |
| 28 | + double rtn = lhs; \ |
| 29 | + rtn op_eq rhs; \ |
| 30 | + return rtn; \ |
| 31 | + } \ |
| 32 | + __SYCL_CONSTEXPR_HALF friend double operator op(const double lhs, \ |
| 33 | + const half rhs) { \ |
| 34 | + double rtn = lhs; \ |
| 35 | + rtn op_eq rhs; \ |
| 36 | + return rtn; \ |
| 37 | + } \ |
| 38 | + __SYCL_CONSTEXPR_HALF friend float operator op(const half lhs, \ |
| 39 | + const float rhs) { \ |
| 40 | + float rtn = lhs; \ |
| 41 | + rtn op_eq rhs; \ |
| 42 | + return rtn; \ |
| 43 | + } \ |
| 44 | + __SYCL_CONSTEXPR_HALF friend float operator op(const float lhs, \ |
| 45 | + const half rhs) { \ |
| 46 | + float rtn = lhs; \ |
| 47 | + rtn op_eq rhs; \ |
| 48 | + return rtn; \ |
| 49 | + } \ |
| 50 | + __SYCL_CONSTEXPR_HALF friend half operator op(const half lhs, \ |
| 51 | + const int rhs) { \ |
| 52 | + half rtn = lhs; \ |
| 53 | + rtn op_eq rhs; \ |
| 54 | + return rtn; \ |
| 55 | + } \ |
| 56 | + __SYCL_CONSTEXPR_HALF friend half operator op(const int lhs, \ |
| 57 | + const half rhs) { \ |
| 58 | + half rtn = lhs; \ |
| 59 | + rtn op_eq rhs; \ |
| 60 | + return rtn; \ |
| 61 | + } \ |
| 62 | + __SYCL_CONSTEXPR_HALF friend half operator op(const half lhs, \ |
| 63 | + const long rhs) { \ |
| 64 | + half rtn = lhs; \ |
| 65 | + rtn op_eq rhs; \ |
| 66 | + return rtn; \ |
| 67 | + } \ |
| 68 | + __SYCL_CONSTEXPR_HALF friend half operator op(const long lhs, \ |
| 69 | + const half rhs) { \ |
| 70 | + half rtn = lhs; \ |
| 71 | + rtn op_eq rhs; \ |
| 72 | + return rtn; \ |
| 73 | + } \ |
| 74 | + __SYCL_CONSTEXPR_HALF friend half operator op(const half lhs, \ |
| 75 | + const long long rhs) { \ |
| 76 | + half rtn = lhs; \ |
| 77 | + rtn op_eq rhs; \ |
| 78 | + return rtn; \ |
| 79 | + } \ |
| 80 | + __SYCL_CONSTEXPR_HALF friend half operator op(const long long lhs, \ |
| 81 | + const half rhs) { \ |
| 82 | + half rtn = lhs; \ |
| 83 | + rtn op_eq rhs; \ |
| 84 | + return rtn; \ |
| 85 | + } \ |
| 86 | + __SYCL_CONSTEXPR_HALF friend half operator op(const half &lhs, \ |
| 87 | + const unsigned int &rhs) { \ |
| 88 | + half rtn = lhs; \ |
| 89 | + rtn op_eq rhs; \ |
| 90 | + return rtn; \ |
| 91 | + } \ |
| 92 | + __SYCL_CONSTEXPR_HALF friend half operator op(const unsigned int &lhs, \ |
| 93 | + const half &rhs) { \ |
| 94 | + half rtn = lhs; \ |
| 95 | + rtn op_eq rhs; \ |
| 96 | + return rtn; \ |
| 97 | + } \ |
| 98 | + __SYCL_CONSTEXPR_HALF friend half operator op(const half &lhs, \ |
| 99 | + const unsigned long &rhs) { \ |
| 100 | + half rtn = lhs; \ |
| 101 | + rtn op_eq rhs; \ |
| 102 | + return rtn; \ |
| 103 | + } \ |
| 104 | + __SYCL_CONSTEXPR_HALF friend half operator op(const unsigned long &lhs, \ |
| 105 | + const half &rhs) { \ |
| 106 | + half rtn = lhs; \ |
| 107 | + rtn op_eq rhs; \ |
| 108 | + return rtn; \ |
| 109 | + } \ |
| 110 | + __SYCL_CONSTEXPR_HALF friend half operator op( \ |
| 111 | + const half &lhs, const unsigned long long &rhs) { \ |
| 112 | + half rtn = lhs; \ |
| 113 | + rtn op_eq rhs; \ |
| 114 | + return rtn; \ |
| 115 | + } \ |
| 116 | + __SYCL_CONSTEXPR_HALF friend half operator op(const unsigned long long &lhs, \ |
| 117 | + const half &rhs) { \ |
| 118 | + half rtn = lhs; \ |
| 119 | + rtn op_eq rhs; \ |
| 120 | + return rtn; \ |
| 121 | + } |
| 122 | + OP(/, /=) |
| 123 | + |
| 124 | +#undef OP |
| 125 | + |
| 126 | + // Operator float |
| 127 | + __SYCL_CONSTEXPR_HALF operator float() const { |
| 128 | + return static_cast<float>(Data); |
| 129 | + } |
| 130 | + |
| 131 | +private: |
| 132 | + __SYCL_CONSTEXPR_HALF StorageT getFPRep() const { return Data; } |
| 133 | + |
| 134 | + StorageT Data; |
| 135 | +}; |
| 136 | + |
0 commit comments