From 38bed04d32f51d06d0d564d26359e831c75d566f Mon Sep 17 00:00:00 2001 From: Andrew Gozillon Date: Fri, 1 Feb 2019 18:49:46 -0800 Subject: [PATCH] [SYCL][NFC] id.hpp & range.hpp operator tidyup This should be a NFC, refactoring the hardcoded operators in the range and id classes into macros to generate them so that the classes are a little more concise to read. Signed-off-by: Andrew Gozillon --- sycl/include/CL/sycl/id.hpp | 547 +++++---------------------------- sycl/include/CL/sycl/range.hpp | 542 ++++---------------------------- 2 files changed, 136 insertions(+), 953 deletions(-) diff --git a/sycl/include/CL/sycl/id.hpp b/sycl/include/CL/sycl/id.hpp index 326e0021f7898..d1e8ea125a721 100644 --- a/sycl/include/CL/sycl/id.hpp +++ b/sycl/include/CL/sycl/id.hpp @@ -75,486 +75,77 @@ template struct id : public detail::array { } // OP is: +, -, *, /, %, <<, >>, &, |, ^, &&, ||, <, >, <=, >= - id operator+(const id &rhs) const { - id result; - for (int i = 0; i < dimensions; ++i) { - result.common_array[i] = this->common_array[i] + rhs.common_array[i]; - } - return result; - } - id operator-(const id &rhs) const { - id result; - for (int i = 0; i < dimensions; ++i) { - result.common_array[i] = this->common_array[i] - rhs.common_array[i]; - } - return result; - } - id operator*(const id &rhs) const { - id result; - for (int i = 0; i < dimensions; ++i) { - result.common_array[i] = this->common_array[i] * rhs.common_array[i]; - } - return result; - } - id operator/(const id &rhs) const { - id result; - for (int i = 0; i < dimensions; ++i) { - result.common_array[i] = this->common_array[i] / rhs.common_array[i]; - } - return result; - } - id operator%(const id &rhs) const { - id result; - for (int i = 0; i < dimensions; ++i) { - result.common_array[i] = this->common_array[i] % rhs.common_array[i]; - } - return result; - } - id operator<<(const id &rhs) const { - id result; - for (int i = 0; i < dimensions; ++i) { - result.common_array[i] = this->common_array[i] << rhs.common_array[i]; - } - return result; - } - id operator>>(const id &rhs) const { - id result; - for (int i = 0; i < dimensions; ++i) { - result.common_array[i] = this->common_array[i] >> rhs.common_array[i]; - } - return result; - } - id operator&(const id &rhs) const { - id result; - for (int i = 0; i < dimensions; ++i) { - result.common_array[i] = this->common_array[i] & rhs.common_array[i]; - } - return result; - } - id operator|(const id &rhs) const { - id result; - for (int i = 0; i < dimensions; ++i) { - result.common_array[i] = this->common_array[i] | rhs.common_array[i]; - } - return result; - } - id operator^(const id &rhs) const { - id result; - for (int i = 0; i < dimensions; ++i) { - result.common_array[i] = this->common_array[i] ^ rhs.common_array[i]; - } - return result; - } - id operator&&(const id &rhs) const { - id result; - for (int i = 0; i < dimensions; ++i) { - result.common_array[i] = this->common_array[i] && rhs.common_array[i]; - } - return result; - } - id operator||(const id &rhs) const { - id result; - for (int i = 0; i < dimensions; ++i) { - result.common_array[i] = this->common_array[i] || rhs.common_array[i]; - } - return result; - } - id operator<(const id &rhs) const { - id result; - for (int i = 0; i < dimensions; ++i) { - result.common_array[i] = this->common_array[i] < rhs.common_array[i]; - } - return result; - } - id operator>(const id &rhs) const { - id result; - for (int i = 0; i < dimensions; ++i) { - result.common_array[i] = this->common_array[i] > rhs.common_array[i]; - } - return result; - } - id operator<=(const id &rhs) const { - id result; - for (int i = 0; i < dimensions; ++i) { - result.common_array[i] = this->common_array[i] <= rhs.common_array[i]; - } - return result; - } - id operator>=(const id &rhs) const { - id result; - for (int i = 0; i < dimensions; ++i) { - result.common_array[i] = this->common_array[i] >= rhs.common_array[i]; - } - return result; - } - - // OP is: +, -, *, /, %, <<, >>, &, |, ^, &&, ||, <, >, <=, >= - id operator+(const size_t &rhs) const { - id result; - for (int i = 0; i < dimensions; ++i) { - result.common_array[i] = this->common_array[i] + rhs; - } - return result; - } - id operator-(const size_t &rhs) const { - id result; - for (int i = 0; i < dimensions; ++i) { - result.common_array[i] = this->common_array[i] - rhs; - } - return result; - } - id operator*(const size_t &rhs) const { - id result; - for (int i = 0; i < dimensions; ++i) { - result.common_array[i] = this->common_array[i] * rhs; - } - return result; - } - id operator/(const size_t &rhs) const { - id result; - for (int i = 0; i < dimensions; ++i) { - result.common_array[i] = this->common_array[i] / rhs; - } - return result; - } - id operator%(const size_t &rhs) const { - id result; - for (int i = 0; i < dimensions; ++i) { - result.common_array[i] = this->common_array[i] % rhs; - } - return result; - } - id operator<<(const size_t &rhs) const { - id result; - for (int i = 0; i < dimensions; ++i) { - result.common_array[i] = this->common_array[i] << rhs; - } - return result; - } - id operator>>(const size_t &rhs) const { - id result; - for (int i = 0; i < dimensions; ++i) { - result.common_array[i] = this->common_array[i] >> rhs; - } - return result; - } - id operator&(const size_t &rhs) const { - id result; - for (int i = 0; i < dimensions; ++i) { - result.common_array[i] = this->common_array[i] & rhs; - } - return result; - } - id operator|(const size_t &rhs) const { - id result; - for (int i = 0; i < dimensions; ++i) { - result.common_array[i] = this->common_array[i] | rhs; - } - return result; - } - id operator^(const size_t &rhs) const { - id result; - for (int i = 0; i < dimensions; ++i) { - result.common_array[i] = this->common_array[i] ^ rhs; - } - return result; - } - id operator&&(const size_t &rhs) const { - id result; - for (int i = 0; i < dimensions; ++i) { - result.common_array[i] = this->common_array[i] && rhs; - } - return result; - } - id operator||(const size_t &rhs) const { - id result; - for (int i = 0; i < dimensions; ++i) { - result.common_array[i] = this->common_array[i] || rhs; - } - return result; - } - id operator<(const size_t &rhs) const { - id result; - for (int i = 0; i < dimensions; ++i) { - result.common_array[i] = this->common_array[i] < rhs; - } - return result; - } - id operator>(const size_t &rhs) const { - id result; - for (int i = 0; i < dimensions; ++i) { - result.common_array[i] = this->common_array[i] > rhs; - } - return result; - } - id operator<=(const size_t &rhs) const { - id result; - for (int i = 0; i < dimensions; ++i) { - result.common_array[i] = this->common_array[i] <= rhs; - } - return result; - } - id operator>=(const size_t &rhs) const { - id result; - for (int i = 0; i < dimensions; ++i) { - result.common_array[i] = this->common_array[i] >= rhs; - } - return result; - } - - // OP is: +=, -=, *=, /=, %=, <<=, >>=, &=, |=, ^= - id &operator+=(const id &rhs) { - for (int i = 0; i < dimensions; ++i) { - this->common_array[i] += rhs[i]; - } - return *this; - } - id &operator-=(const id &rhs) { - for (int i = 0; i < dimensions; ++i) { - this->common_array[i] -= rhs.common_array[i]; - } - return *this; - } - id &operator*=(const id &rhs) { - for (int i = 0; i < dimensions; ++i) { - this->common_array[i] *= rhs.common_array[i]; - } - return *this; - } - id &operator/=(const id &rhs) { - for (int i = 0; i < dimensions; ++i) { - this->common_array[i] /= rhs.common_array[i]; - } - return *this; - } - id &operator%=(const id &rhs) { - for (int i = 0; i < dimensions; ++i) { - this->common_array[i] %= rhs.common_array[i]; - } - return *this; - } - id &operator<<=(const id &rhs) { - for (int i = 0; i < dimensions; ++i) { - this->common_array[i] <<= rhs.common_array[i]; - } - return *this; - } - id &operator>>=(const id &rhs) { - for (int i = 0; i < dimensions; ++i) { - this->common_array[i] >>= rhs.common_array[i]; - } - return *this; - } - id &operator&=(const id &rhs) { - for (int i = 0; i < dimensions; ++i) { - this->common_array[i] &= rhs.common_array[i]; - } - return *this; - } - id &operator|=(const id &rhs) { - for (int i = 0; i < dimensions; ++i) { - this->common_array[i] |= rhs.common_array[i]; - } - return *this; - } - id &operator^=(const id &rhs) { - for (int i = 0; i < dimensions; ++i) { - this->common_array[i] ^= rhs.common_array[i]; - } - return *this; - } + #define __SYCL_GEN_OPT(op) \ + id operator op(const id &rhs) const { \ + id result; \ + for (int i = 0; i < dimensions; ++i) { \ + result.common_array[i] = this->common_array[i] op rhs.common_array[i]; \ + } \ + return result; \ + } \ + id operator op(const size_t &rhs) const { \ + id result; \ + for (int i = 0; i < dimensions; ++i) { \ + result.common_array[i] = this->common_array[i] op rhs; \ + } \ + return result; \ + } \ + friend id operator op(const size_t &lhs, \ + const id &rhs) { \ + id result; \ + for (int i = 0; i < dimensions; ++i) { \ + result.common_array[i] = lhs op rhs.common_array[i]; \ + } \ + return result; \ + } \ + + + __SYCL_GEN_OPT(+) + __SYCL_GEN_OPT(-) + __SYCL_GEN_OPT(*) + __SYCL_GEN_OPT(/) + __SYCL_GEN_OPT(%) + __SYCL_GEN_OPT(<<) + __SYCL_GEN_OPT(>>) + __SYCL_GEN_OPT(&) + __SYCL_GEN_OPT(|) + __SYCL_GEN_OPT(^) + __SYCL_GEN_OPT(&&) + __SYCL_GEN_OPT(||) + __SYCL_GEN_OPT(<) + __SYCL_GEN_OPT(>) + __SYCL_GEN_OPT(<=) + __SYCL_GEN_OPT(>=) + + #undef __SYCL_GEN_OPT // OP is: +=, -=, *=, /=, %=, <<=, >>=, &=, |=, ^= - id &operator+=(const size_t &rhs) { - for (int i = 0; i < dimensions; ++i) { - this->common_array[i] += rhs; - } - return *this; - } - id &operator-=(const size_t &rhs) { - for (int i = 0; i < dimensions; ++i) { - this->common_array[i] -= rhs; - } - return *this; - } - id &operator*=(const size_t &rhs) { - for (int i = 0; i < dimensions; ++i) { - this->common_array[i] *= rhs; - } - return *this; - } - id &operator/=(const size_t &rhs) { - for (int i = 0; i < dimensions; ++i) { - this->common_array[i] /= rhs; - } - return *this; - } - id &operator%=(const size_t &rhs) { - for (int i = 0; i < dimensions; ++i) { - this->common_array[i] %= rhs; - } - return *this; - } - id &operator<<=(const size_t &rhs) { - for (int i = 0; i < dimensions; ++i) { - this->common_array[i] <<= rhs; - } - return *this; - } - id &operator>>=(const size_t &rhs) { - for (int i = 0; i < dimensions; ++i) { - this->common_array[i] >>= rhs; - } - return *this; - } - id &operator&=(const size_t &rhs) { - for (int i = 0; i < dimensions; ++i) { - this->common_array[i] &= rhs; - } - return *this; - } - id &operator|=(const size_t &rhs) { - for (int i = 0; i < dimensions; ++i) { - this->common_array[i] |= rhs; - } - return *this; - } - id &operator^=(const size_t &rhs) { - for (int i = 0; i < dimensions; ++i) { - this->common_array[i] ^= rhs; - } - return *this; - } - - // OP is: +, -, *, /, %, <<, >>, &, |, ^, <, >, <=, >=, &&, || - friend id operator+(const size_t &lhs, - const id &rhs) { - id result; - for (int i = 0; i < dimensions; ++i) { - result.common_array[i] = lhs + rhs.common_array[i]; - } - return result; - } - friend id operator-(const size_t &lhs, - const id &rhs) { - id result; - for (int i = 0; i < dimensions; ++i) { - result.common_array[i] = lhs - rhs.common_array[i]; - } - return result; - } - friend id operator*(const size_t &lhs, - const id &rhs) { - id result; - for (int i = 0; i < dimensions; ++i) { - result.common_array[i] = lhs * rhs.common_array[i]; - } - return result; - } - friend id operator/(const size_t &lhs, - const id &rhs) { - id result; - for (int i = 0; i < dimensions; ++i) { - result.common_array[i] = lhs / rhs.common_array[i]; - } - return result; - } - friend id operator%(const size_t &lhs, - const id &rhs) { - id result; - for (int i = 0; i < dimensions; ++i) { - result.common_array[i] = lhs % rhs.common_array[i]; - } - return result; - } - friend id operator<<(const size_t &lhs, - const id &rhs) { - id result; - for (int i = 0; i < dimensions; ++i) { - result.common_array[i] = lhs << rhs.common_array[i]; - } - return result; - } - friend id operator>>(const size_t &lhs, - const id &rhs) { - id result; - for (int i = 0; i < dimensions; ++i) { - result.common_array[i] = lhs >> rhs.common_array[i]; - } - return result; - } - friend id operator&(const size_t &lhs, - const id &rhs) { - id result; - for (int i = 0; i < dimensions; ++i) { - result.common_array[i] = lhs & rhs.common_array[i]; - } - return result; - } - friend id operator|(const size_t &lhs, - const id &rhs) { - id result; - for (int i = 0; i < dimensions; ++i) { - result.common_array[i] = lhs | rhs.common_array[i]; - } - return result; - } - friend id operator^(const size_t &lhs, - const id &rhs) { - id result; - for (int i = 0; i < dimensions; ++i) { - result.common_array[i] = lhs ^ rhs.common_array[i]; - } - return result; - } - friend id operator<(const size_t &lhs, - const id &rhs) { - id result; - for (int i = 0; i < dimensions; ++i) { - result.common_array[i] = lhs < rhs.common_array[i]; - } - return result; - } - friend id operator>(const size_t &lhs, - const id &rhs) { - id result; - for (int i = 0; i < dimensions; ++i) { - result.common_array[i] = lhs > rhs.common_array[i]; - } - return result; - } - friend id operator<=(const size_t &lhs, - const id &rhs) { - id result; - for (int i = 0; i < dimensions; ++i) { - result.common_array[i] = lhs <= rhs.common_array[i]; - } - return result; - } - friend id operator>=(const size_t &lhs, - const id &rhs) { - id result; - for (int i = 0; i < dimensions; ++i) { - result.common_array[i] = lhs >= rhs.common_array[i]; - } - return result; - } - friend id operator&&(const size_t &lhs, - const id &rhs) { - id result; - for (int i = 0; i < dimensions; ++i) { - result.common_array[i] = lhs && rhs.common_array[i]; - } - return result; - } - friend id operator||(const size_t &lhs, - const id &rhs) { - id result; - for (int i = 0; i < dimensions; ++i) { - result.common_array[i] = lhs || rhs.common_array[i]; - } - return result; - } + #define __SYCL_GEN_OPT(op) \ + id &operator op(const id &rhs) { \ + for (int i = 0; i < dimensions; ++i) { \ + this->common_array[i] op rhs.common_array[i]; \ + } \ + return *this; \ + } \ + id &operator op(const size_t &rhs) { \ + for (int i = 0; i < dimensions; ++i) { \ + this->common_array[i] op rhs; \ + } \ + return *this; \ + } \ + + __SYCL_GEN_OPT(+=) + __SYCL_GEN_OPT(-=) + __SYCL_GEN_OPT(*=) + __SYCL_GEN_OPT(/=) + __SYCL_GEN_OPT(%=) + __SYCL_GEN_OPT(<<=) + __SYCL_GEN_OPT(>>=) + __SYCL_GEN_OPT(&=) + __SYCL_GEN_OPT(|=) + __SYCL_GEN_OPT(^=) + + #undef __SYCL_GEN_OPT }; namespace detail { diff --git a/sycl/include/CL/sycl/range.hpp b/sycl/include/CL/sycl/range.hpp index 6d7f4919f66e6..80e601196ff08 100644 --- a/sycl/include/CL/sycl/range.hpp +++ b/sycl/include/CL/sycl/range.hpp @@ -59,486 +59,78 @@ class range : public detail::array { range() = default; // OP is: +, -, *, /, %, <<, >>, &, |, ^, &&, ||, <, >, <=, >= - range operator+(const range &rhs) const { - range result; - for (int i = 0; i < dimensions; ++i) { - result.common_array[i] = this->common_array[i] + rhs.common_array[i]; - } - return result; - } - range operator-(const range &rhs) const { - range result; - for (int i = 0; i < dimensions; ++i) { - result.common_array[i] = this->common_array[i] - rhs.common_array[i]; - } - return result; - } - range operator*(const range &rhs) const { - range result; - for (int i = 0; i < dimensions; ++i) { - result.common_array[i] = this->common_array[i] * rhs.common_array[i]; - } - return result; - } - range operator/(const range &rhs) const { - range result; - for (int i = 0; i < dimensions; ++i) { - result.common_array[i] = this->common_array[i] / rhs.common_array[i]; - } - return result; - } - range operator%(const range &rhs) const { - range result; - for (int i = 0; i < dimensions; ++i) { - result.common_array[i] = this->common_array[i] % rhs.common_array[i]; - } - return result; - } - range operator<<(const range &rhs) const { - range result; - for (int i = 0; i < dimensions; ++i) { - result.common_array[i] = this->common_array[i] << rhs.common_array[i]; - } - return result; - } - range operator>>(const range &rhs) const { - range result; - for (int i = 0; i < dimensions; ++i) { - result.common_array[i] = this->common_array[i] >> rhs.common_array[i]; - } - return result; - } - range operator&(const range &rhs) const { - range result; - for (int i = 0; i < dimensions; ++i) { - result.common_array[i] = this->common_array[i] & rhs.common_array[i]; - } - return result; - } - range operator|(const range &rhs) const { - range result; - for (int i = 0; i < dimensions; ++i) { - result.common_array[i] = this->common_array[i] | rhs.common_array[i]; - } - return result; - } - range operator^(const range &rhs) const { - range result; - for (int i = 0; i < dimensions; ++i) { - result.common_array[i] = this->common_array[i] ^ rhs.common_array[i]; - } - return result; - } - range operator&&(const range &rhs) const { - range result; - for (int i = 0; i < dimensions; ++i) { - result.common_array[i] = this->common_array[i] && rhs.common_array[i]; - } - return result; - } - range operator||(const range &rhs) const { - range result; - for (int i = 0; i < dimensions; ++i) { - result.common_array[i] = this->common_array[i] || rhs.common_array[i]; - } - return result; - } - range operator<(const range &rhs) const { - range result; - for (int i = 0; i < dimensions; ++i) { - result.common_array[i] = this->common_array[i] < rhs.common_array[i]; - } - return result; - } - range operator>(const range &rhs) const { - range result; - for (int i = 0; i < dimensions; ++i) { - result.common_array[i] = this->common_array[i] > rhs.common_array[i]; - } - return result; - } - range operator<=(const range &rhs) const { - range result; - for (int i = 0; i < dimensions; ++i) { - result.common_array[i] = this->common_array[i] <= rhs.common_array[i]; - } - return result; - } - range operator>=(const range &rhs) const { - range result; - for (int i = 0; i < dimensions; ++i) { - result.common_array[i] = this->common_array[i] >= rhs.common_array[i]; - } - return result; - } + #define __SYCL_GEN_OPT(op) \ + range operator op(const range &rhs) const { \ + range result; \ + for (int i = 0; i < dimensions; ++i) { \ + result.common_array[i] = this->common_array[i] op rhs.common_array[i]; \ + } \ + return result; \ + } \ + range operator op(const size_t &rhs) const { \ + range result; \ + for (int i = 0; i < dimensions; ++i) { \ + result.common_array[i] = this->common_array[i] op rhs; \ + } \ + return result; \ + } \ + friend range operator op(const size_t &lhs, \ + const range &rhs) { \ + range result; \ + for (int i = 0; i < dimensions; ++i) { \ + result.common_array[i] = lhs op rhs.common_array[i]; \ + } \ + return result; \ + } \ - // OP is: +, -, *, /, %, <<, >>, &, |, ^, &&, ||, <, >, <=, >= - range operator+(const size_t &rhs) const { - range result; - for (int i = 0; i < dimensions; ++i) { - result.common_array[i] = this->common_array[i] + rhs; - } - return result; - } - range operator-(const size_t &rhs) const { - range result; - for (int i = 0; i < dimensions; ++i) { - result.common_array[i] = this->common_array[i] - rhs; - } - return result; - } - range operator*(const size_t &rhs) const { - range result; - for (int i = 0; i < dimensions; ++i) { - result.common_array[i] = this->common_array[i] * rhs; - } - return result; - } - range operator/(const size_t &rhs) const { - range result; - for (int i = 0; i < dimensions; ++i) { - result.common_array[i] = this->common_array[i] / rhs; - } - return result; - } - range operator%(const size_t &rhs) const { - range result; - for (int i = 0; i < dimensions; ++i) { - result.common_array[i] = this->common_array[i] % rhs; - } - return result; - } - range operator<<(const size_t &rhs) const { - range result; - for (int i = 0; i < dimensions; ++i) { - result.common_array[i] = this->common_array[i] << rhs; - } - return result; - } - range operator>>(const size_t &rhs) const { - range result; - for (int i = 0; i < dimensions; ++i) { - result.common_array[i] = this->common_array[i] >> rhs; - } - return result; - } - range operator&(const size_t &rhs) const { - range result; - for (int i = 0; i < dimensions; ++i) { - result.common_array[i] = this->common_array[i] & rhs; - } - return result; - } - range operator|(const size_t &rhs) const { - range result; - for (int i = 0; i < dimensions; ++i) { - result.common_array[i] = this->common_array[i] | rhs; - } - return result; - } - range operator^(const size_t &rhs) const { - range result; - for (int i = 0; i < dimensions; ++i) { - result.common_array[i] = this->common_array[i] ^ rhs; - } - return result; - } - range operator&&(const size_t &rhs) const { - range result; - for (int i = 0; i < dimensions; ++i) { - result.common_array[i] = this->common_array[i] && rhs; - } - return result; - } - range operator||(const size_t &rhs) const { - range result; - for (int i = 0; i < dimensions; ++i) { - result.common_array[i] = this->common_array[i] || rhs; - } - return result; - } - range operator<(const size_t &rhs) const { - range result; - for (int i = 0; i < dimensions; ++i) { - result.common_array[i] = this->common_array[i] < rhs; - } - return result; - } - range operator>(const size_t &rhs) const { - range result; - for (int i = 0; i < dimensions; ++i) { - result.common_array[i] = this->common_array[i] > rhs; - } - return result; - } - range operator<=(const size_t &rhs) const { - range result; - for (int i = 0; i < dimensions; ++i) { - result.common_array[i] = this->common_array[i] <= rhs; - } - return result; - } - range operator>=(const size_t &rhs) const { - range result; - for (int i = 0; i < dimensions; ++i) { - result.common_array[i] = this->common_array[i] >= rhs; - } - return result; - } + __SYCL_GEN_OPT(+) + __SYCL_GEN_OPT(-) + __SYCL_GEN_OPT(*) + __SYCL_GEN_OPT(/) + __SYCL_GEN_OPT(%) + __SYCL_GEN_OPT(<<) + __SYCL_GEN_OPT(>>) + __SYCL_GEN_OPT(&) + __SYCL_GEN_OPT(|) + __SYCL_GEN_OPT(^) + __SYCL_GEN_OPT(&&) + __SYCL_GEN_OPT(||) + __SYCL_GEN_OPT(<) + __SYCL_GEN_OPT(>) + __SYCL_GEN_OPT(<=) + __SYCL_GEN_OPT(>=) - // OP is: +=, -=, *=, /=, %=, <<=, >>=, &=, |=, ^= - range &operator+=(const range &rhs) { - for (int i = 0; i < dimensions; ++i) { - this->common_array[i] += rhs[i]; - } - return *this; - } - range &operator-=(const range &rhs) { - for (int i = 0; i < dimensions; ++i) { - this->common_array[i] -= rhs.common_array[i]; - } - return *this; - } - range &operator*=(const range &rhs) { - for (int i = 0; i < dimensions; ++i) { - this->common_array[i] *= rhs.common_array[i]; - } - return *this; - } - range &operator/=(const range &rhs) { - for (int i = 0; i < dimensions; ++i) { - this->common_array[i] /= rhs.common_array[i]; - } - return *this; - } - range &operator%=(const range &rhs) { - for (int i = 0; i < dimensions; ++i) { - this->common_array[i] %= rhs.common_array[i]; - } - return *this; - } - range &operator<<=(const range &rhs) { - for (int i = 0; i < dimensions; ++i) { - this->common_array[i] <<= rhs.common_array[i]; - } - return *this; - } - range &operator>>=(const range &rhs) { - for (int i = 0; i < dimensions; ++i) { - this->common_array[i] >>= rhs.common_array[i]; - } - return *this; - } - range &operator&=(const range &rhs) { - for (int i = 0; i < dimensions; ++i) { - this->common_array[i] &= rhs.common_array[i]; - } - return *this; - } - range &operator|=(const range &rhs) { - for (int i = 0; i < dimensions; ++i) { - this->common_array[i] |= rhs.common_array[i]; - } - return *this; - } - range &operator^=(const range &rhs) { - for (int i = 0; i < dimensions; ++i) { - this->common_array[i] ^= rhs.common_array[i]; - } - return *this; - } + #undef __SYCL_GEN_OPT // OP is: +=, -=, *=, /=, %=, <<=, >>=, &=, |=, ^= - range &operator+=(const size_t &rhs) { - for (int i = 0; i < dimensions; ++i) { - this->common_array[i] += rhs; - } - return *this; - } - range &operator-=(const size_t &rhs) { - for (int i = 0; i < dimensions; ++i) { - this->common_array[i] -= rhs; - } - return *this; - } - range &operator*=(const size_t &rhs) { - for (int i = 0; i < dimensions; ++i) { - this->common_array[i] *= rhs; - } - return *this; - } - range &operator/=(const size_t &rhs) { - for (int i = 0; i < dimensions; ++i) { - this->common_array[i] /= rhs; - } - return *this; - } - range &operator%=(const size_t &rhs) { - for (int i = 0; i < dimensions; ++i) { - this->common_array[i] %= rhs; - } - return *this; - } - range &operator<<=(const size_t &rhs) { - for (int i = 0; i < dimensions; ++i) { - this->common_array[i] <<= rhs; - } - return *this; - } - range &operator>>=(const size_t &rhs) { - for (int i = 0; i < dimensions; ++i) { - this->common_array[i] >>= rhs; - } - return *this; - } - range &operator&=(const size_t &rhs) { - for (int i = 0; i < dimensions; ++i) { - this->common_array[i] &= rhs; - } - return *this; - } - range &operator|=(const size_t &rhs) { - for (int i = 0; i < dimensions; ++i) { - this->common_array[i] |= rhs; - } - return *this; - } - range &operator^=(const size_t &rhs) { - for (int i = 0; i < dimensions; ++i) { - this->common_array[i] ^= rhs; - } - return *this; - } + #define __SYCL_GEN_OPT(op) \ + range &operator op(const range &rhs) { \ + for (int i = 0; i < dimensions; ++i) { \ + this->common_array[i] op rhs[i]; \ + } \ + return *this; \ + } \ + range &operator op(const size_t &rhs) { \ + for (int i = 0; i < dimensions; ++i) { \ + this->common_array[i] op rhs; \ + } \ + return *this; \ + } \ + + + __SYCL_GEN_OPT(+=) + __SYCL_GEN_OPT(-=) + __SYCL_GEN_OPT(*=) + __SYCL_GEN_OPT(/=) + __SYCL_GEN_OPT(%=) + __SYCL_GEN_OPT(<<=) + __SYCL_GEN_OPT(>>=) + __SYCL_GEN_OPT(&=) + __SYCL_GEN_OPT(|=) + __SYCL_GEN_OPT(^=) + + #undef __SYCL_GEN_OPT - // OP is: +, -, *, /, %, <<, >>, &, |, ^, <, >, <=, >=, &&, || - friend range operator+(const size_t &lhs, - const range &rhs) { - range result; - for (int i = 0; i < dimensions; ++i) { - result.common_array[i] = lhs + rhs.common_array[i]; - } - return result; - } - friend range operator-(const size_t &lhs, - const range &rhs) { - range result; - for (int i = 0; i < dimensions; ++i) { - result.common_array[i] = lhs - rhs.common_array[i]; - } - return result; - } - friend range operator*(const size_t &lhs, - const range &rhs) { - range result; - for (int i = 0; i < dimensions; ++i) { - result.common_array[i] = lhs * rhs.common_array[i]; - } - return result; - } - friend range operator/(const size_t &lhs, - const range &rhs) { - range result; - for (int i = 0; i < dimensions; ++i) { - result.common_array[i] = lhs / rhs.common_array[i]; - } - return result; - } - friend range operator%(const size_t &lhs, - const range &rhs) { - range result; - for (int i = 0; i < dimensions; ++i) { - result.common_array[i] = lhs % rhs.common_array[i]; - } - return result; - } - friend range operator<<(const size_t &lhs, - const range &rhs) { - range result; - for (int i = 0; i < dimensions; ++i) { - result.common_array[i] = lhs << rhs.common_array[i]; - } - return result; - } - friend range operator>>(const size_t &lhs, - const range &rhs) { - range result; - for (int i = 0; i < dimensions; ++i) { - result.common_array[i] = lhs >> rhs.common_array[i]; - } - return result; - } - friend range operator&(const size_t &lhs, - const range &rhs) { - range result; - for (int i = 0; i < dimensions; ++i) { - result.common_array[i] = lhs & rhs.common_array[i]; - } - return result; - } - friend range operator|(const size_t &lhs, - const range &rhs) { - range result; - for (int i = 0; i < dimensions; ++i) { - result.common_array[i] = lhs | rhs.common_array[i]; - } - return result; - } - friend range operator^(const size_t &lhs, - const range &rhs) { - range result; - for (int i = 0; i < dimensions; ++i) { - result.common_array[i] = lhs ^ rhs.common_array[i]; - } - return result; - } - friend range operator<(const size_t &lhs, - const range &rhs) { - range result; - for (int i = 0; i < dimensions; ++i) { - result.common_array[i] = lhs < rhs.common_array[i]; - } - return result; - } - friend range operator>(const size_t &lhs, - const range &rhs) { - range result; - for (int i = 0; i < dimensions; ++i) { - result.common_array[i] = lhs > rhs.common_array[i]; - } - return result; - } - friend range operator<=(const size_t &lhs, - const range &rhs) { - range result; - for (int i = 0; i < dimensions; ++i) { - result.common_array[i] = lhs <= rhs.common_array[i]; - } - return result; - } - friend range operator>=(const size_t &lhs, - const range &rhs) { - range result; - for (int i = 0; i < dimensions; ++i) { - result.common_array[i] = lhs >= rhs.common_array[i]; - } - return result; - } - friend range operator&&(const size_t &lhs, - const range &rhs) { - range result; - for (int i = 0; i < dimensions; ++i) { - result.common_array[i] = lhs && rhs.common_array[i]; - } - return result; - } - friend range operator||(const size_t &lhs, - const range &rhs) { - range result; - for (int i = 0; i < dimensions; ++i) { - result.common_array[i] = lhs || rhs.common_array[i]; - } - return result; - } }; } // namespace sycl } // namespace cl