/* * Copyright (c) Meta Platforms, Inc. and affiliates. * All rights reserved. * * This source code is licensed under the BSD-style license found in the * LICENSE file in the root directory of this source tree. */ #pragma once #include #include #include namespace torch { namespace executor { namespace native { namespace internal { #define DEFINE_BINARY_OPERATOR_TEMPLATE(name, op) \ template \ T name(const T val_a, const T val_b) { \ return val_a op val_b; \ } DEFINE_BINARY_OPERATOR_TEMPLATE(bitwise_and, &) DEFINE_BINARY_OPERATOR_TEMPLATE(bitwise_or, |) DEFINE_BINARY_OPERATOR_TEMPLATE(bitwise_xor, ^) template using bitwise_fn = T (*)(const T, const T); template constexpr bitwise_fn get_bitwise_fn() { std::string_view op = op_name; if (op == "bitwise_and.Tensor_out" || op == "bitwise_and.Scalar_out") { return bitwise_and; } if (op == "bitwise_or.Tensor_out" || op == "bitwise_or.Scalar_out") { return bitwise_or; } if (op == "bitwise_xor.Tensor_out" || op == "bitwise_xor.Scalar_out") { return bitwise_xor; } return nullptr; }; template struct BitwiseFnForOp { static constexpr auto get_value() { return get_bitwise_fn(); } static_assert(get_value() != nullptr, "unknown op_name!"); }; template