LCOV - code coverage report
Current view: top level - base_comm/resources/ccu/ccu_representation/reps/arithmetic - ccu_operator_v1.h (source / functions) Coverage Total Hit
Test: coverage.info Lines: 100.0 % 20 20
Test Date: 2026-08-18 17:47:01 Functions: 84.2 % 19 16

            Line data    Source code
       1              : /**
       2              :  * Copyright (c) 2026 Huawei Technologies Co., Ltd.
       3              :  * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
       4              :  * CANN Open Software License Agreement Version 2.0 (the "License").
       5              :  * Please refer to the License for details. You may not use this file except in compliance with the License.
       6              :  * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
       7              :  * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
       8              :  * See LICENSE in the root of the software repository for the full text of the License.
       9              :  */
      10              : 
      11              : #ifndef CCU_OPERATOR
      12              : #define CCU_OPERATOR
      13              : 
      14              : #include <stdexcept>
      15              : 
      16              : namespace hcomm {
      17              : namespace CcuRep {
      18              : 
      19              :     template <typename lhsT, typename rhsT>
      20              :     class CcuOperator {
      21              :     public:
      22          148 :         CcuOperator(lhsT lhs, rhsT rhs) : lhs(lhs), rhs(rhs) {}
      23              :         lhsT lhs;
      24              :         rhsT rhs;
      25              :     };
      26              : 
      27              :     enum class CcuArithmeticOperatorType { ADDITION, MULTIPLICATION, SUBTRACTION, INVALID };
      28              : 
      29              :     template <typename lhsT, typename rhsT>
      30              :     class CcuArithmeticOperator : public CcuOperator<lhsT, rhsT> {
      31              :     public:
      32          131 :         CcuArithmeticOperator(lhsT lhs, rhsT rhs, CcuArithmeticOperatorType type)
      33              :             : CcuOperator<lhsT, rhsT>(lhs, rhs),
      34          131 :               type(type)
      35              :         {
      36          131 :             Check();
      37          131 :         }
      38              :         void Check() const
      39              :         {
      40              :             // Hccl::THROW<Hccl::CcuApiException>("Invalid Arithmetic Operator");
      41              :             throw std::runtime_error("Invalid Arithmetic Operator");
      42              :         }
      43              : 
      44              :         CcuArithmeticOperatorType type{CcuArithmeticOperatorType::INVALID};
      45              :     };
      46              : 
      47              :     enum class CcuRelationalOperatorType {
      48              :         EQUAL,
      49              :         NOT_EQUAL,
      50              :         GREATER_THAN,
      51              :         GREATER_EQUAL,
      52              :         LESS_THAN,
      53              :         LESS_EQUAL,
      54              :         INVALID
      55              :     };
      56              : 
      57              :     template <typename lhsT, typename rhsT>
      58              :     class CcuRelationalOperator : public CcuOperator<lhsT, rhsT> {
      59              :     public:
      60            6 :         CcuRelationalOperator(lhsT lhs, rhsT rhs, CcuRelationalOperatorType type)
      61              :             : CcuOperator<lhsT, rhsT>(lhs, rhs),
      62            6 :               type(type)
      63              :         {
      64            6 :             Check();
      65            6 :         }
      66              :         void Check() const
      67              :         {
      68              :             // Hccl::THROW<Hccl::CcuApiException>("Invalid Relational Operator");
      69              :             throw std::runtime_error("Invalid Relational Operator");
      70              :         }
      71              : 
      72              :         CcuRelationalOperatorType type{CcuRelationalOperatorType::INVALID};
      73              :     };
      74              : 
      75              :     enum class CcuLogicOperatorType { AND, OR, XOR, NOT, INVALID };
      76              : 
      77              :     template <typename lhsT, typename rhsT = std::nullptr_t>
      78              :     class CcuLogicOperator : public CcuOperator<lhsT, rhsT> {
      79              :     public:
      80              :         template <typename U = rhsT, typename std::enable_if<!std::is_same<U, std::nullptr_t>::value, int>::type = 0>
      81            6 :         CcuLogicOperator(lhsT lhs, U rhs, CcuLogicOperatorType type) : CcuOperator<lhsT, U>(lhs, rhs),
      82            6 :                                                                        type(type)
      83              :         {
      84            6 :             Check();
      85            6 :         }
      86              : 
      87              :         template <typename U = rhsT, typename std::enable_if<std::is_same<U, std::nullptr_t>::value, int>::type = 0>
      88            1 :         CcuLogicOperator(lhsT lhs, CcuLogicOperatorType type) : CcuOperator<lhsT, U>(lhs, {}),
      89            1 :                                                                 type(type)
      90              :         {
      91            1 :             Check();
      92            1 :         }
      93              : 
      94              :         void Check() const { throw std::runtime_error("Invalid LogicOperator Operator"); }
      95              : 
      96              :         CcuLogicOperatorType type{CcuLogicOperatorType::INVALID};
      97              :     };
      98              : 
      99              :     enum class CcuShiftType { LEFT, RIGHT, INVALID };
     100              : 
     101              :     template <typename lhsT, typename rhsT>
     102              :     class CcuShiftOperator : public CcuOperator<lhsT, rhsT> {
     103              :     public:
     104            4 :         CcuShiftOperator(lhsT lhs, rhsT rhs, CcuShiftType type) : CcuOperator<lhsT, rhsT>(lhs, rhs), type(type)
     105              :         {
     106            4 :             Check();
     107            4 :         }
     108              :         void Check() const
     109              :         {
     110              :             // THROW<CcuApiException>("Invalid ShiftT Operator");
     111              :             throw std::runtime_error("Invalid ShiftT Operator");
     112              :         }
     113              : 
     114              :         CcuShiftType type{CcuShiftType::INVALID};
     115              :     };
     116              : 
     117              : }; // namespace CcuRep
     118              : }; // namespace hcomm
     119              : 
     120              : #endif // _CCU_OPERATOR
        

Generated by: LCOV version 2.0-1