LCOV - code coverage report
Current view: top level - base_comm/resources/ccu/ccu_representation/interface - ccu_datatype.cc (source / functions) Coverage Total Hit
Test: coverage.info Lines: 56.8 % 243 138
Test Date: 2026-08-18 17:47:01 Functions: 68.8 % 77 53

            Line data    Source code
       1              : /**
       2              :  * Copyright (c) 2025 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              : #include "ccu_datatype_v1.h"
      12              : #include "ccu_rep_v1.h"
      13              : #include "ccu_kernel_resource.h"
      14              : #include "ccu_interface_assist_v1.h"
      15              : 
      16              : #include "exception_util.h"
      17              : #include "ccu_api_exception.h"
      18              : 
      19              : namespace hcomm {
      20              : namespace CcuRep {
      21              : 
      22         4953 :     uint16_t CcuPhyRes::Id() const { return id; }
      23           77 :     uint16_t CcuPhyRes::DieId() const { return dieId; }
      24        42987 :     void CcuPhyRes::Reset(uint16_t id) { this->id = id; }
      25         1515 :     void CcuPhyRes::SetDieId(uint16_t dieId) { this->dieId = dieId; }
      26              : 
      27       129827 :     CcuVirRes::CcuVirRes(CcuRepContext* context) : context(context) { phyRes = std::make_shared<CcuPhyRes>(); }
      28              : 
      29        41475 :     void CcuVirRes::Reset(uint16_t id) { phyRes->Reset(id); }
      30              : 
      31         1511 :     void CcuVirRes::Reset(uint16_t id, uint16_t dieId)
      32              :     {
      33         1511 :         phyRes->Reset(id);
      34         1511 :         phyRes->SetDieId(dieId);
      35         1511 :     }
      36              : 
      37            3 :     void CcuVirRes::SetDieId(uint16_t dieId) { phyRes->SetDieId(dieId); }
      38              : 
      39         4880 :     uint16_t CcuVirRes::Id() const { return phyRes->Id(); }
      40              : 
      41            4 :     uint16_t CcuVirRes::DieId() const { return phyRes->DieId(); }
      42              : 
      43        29463 :     Variable::Variable(CcuRepContext* context) : CcuVirRes(context) {}
      44              : 
      45        63882 :     Variable::Variable(const Variable& other) : CcuVirRes(other.context) { phyRes = other.phyRes; }
      46              : 
      47          288 :     void Variable::operator=(Variable&& other)
      48              :     {
      49          288 :         phyRes = other.phyRes;
      50          288 :         context = other.context;
      51          288 :     }
      52              : 
      53          159 :     void Variable::operator=(const Variable& other)
      54              :     {
      55          159 :         AppendToContext(context, std::make_shared<CcuRepAssign>(context->GetInsGenerator(), *this, other));
      56          159 :     }
      57              : 
      58          284 :     void Variable::operator=(uint64_t immediate)
      59              :     {
      60          284 :         AppendToContext(context, std::make_shared<CcuRepAssign>(context->GetInsGenerator(), *this, immediate));
      61          284 :     }
      62              : 
      63              :     template <typename Dst, typename Lhs, typename Rhs>
      64          123 :     void ArithmeticAppendToContext(CcuRepContext* context, Dst& dst, CcuArithmeticOperator<Lhs, Rhs> op)
      65              :     {
      66          123 :         switch (op.type) {
      67          113 :             case CcuArithmeticOperatorType::ADDITION:
      68          113 :                 AppendToContext(context, std::make_shared<CcuRepAdd>(context->GetInsGenerator(), dst, op.lhs, op.rhs));
      69          113 :                 break;
      70            5 :             case CcuArithmeticOperatorType::MULTIPLICATION:
      71            5 :                 AppendToContext(context, std::make_shared<CcuRepMul>(context->GetInsGenerator(), dst, op.lhs, op.rhs));
      72            5 :                 break;
      73            5 :             case CcuArithmeticOperatorType::SUBTRACTION:
      74            5 :                 AppendToContext(context, std::make_shared<CcuRepSub>(context->GetInsGenerator(), dst, op.lhs, op.rhs));
      75            5 :                 break;
      76            0 :             default:
      77            0 :                 Hccl::THROW<Hccl::NotSupportException>("Not supported Arithmetic operator[%d].", op.type);
      78              :         }
      79          123 :     }
      80              : 
      81          116 :     void Variable::VarVarAppendToContext(CcuArithmeticOperator<Variable, Variable> op)
      82              :     {
      83          116 :         ArithmeticAppendToContext(context, *this, op);
      84          116 :     }
      85              : 
      86          116 :     void Variable::operator=(CcuArithmeticOperator<Variable, Variable> op) { VarVarAppendToContext(op); }
      87              : 
      88            5 :     void Variable::VarImmedAppendToContext(CcuArithmeticOperator<Variable, uint16_t> op)
      89              :     {
      90            5 :         ArithmeticAppendToContext(context, *this, op);
      91            5 :     }
      92              : 
      93            5 :     void Variable::operator=(CcuArithmeticOperator<Variable, uint16_t> op) { VarImmedAppendToContext(op); }
      94              : 
      95            0 :     void Variable::AddrImmedAppendToContext(CcuArithmeticOperator<Address, uint16_t> op)
      96              :     {
      97            0 :         ArithmeticAppendToContext(context, *this, op);
      98            0 :     }
      99              : 
     100            0 :     void Variable::operator=(CcuArithmeticOperator<Address, uint16_t> op) { AddrImmedAppendToContext(op); }
     101              : 
     102            0 :     void Variable::AddrAddrAppendToContext(CcuArithmeticOperator<Address, Address> op)
     103              :     {
     104            0 :         switch (op.type) {
     105            0 :             case CcuArithmeticOperatorType::ADDITION: {
     106            0 :                 AppendToContext(
     107            0 :                     context, std::make_shared<CcuRepAdd>(context->GetInsGenerator(), *this, op.lhs, op.rhs));
     108            0 :                 break;
     109              :             }
     110            0 :             default: {
     111            0 :                 Hccl::THROW<Hccl::NotSupportException>(
     112              :                     "Not supported Arithmetic operate in variable = addr (op) addr.");
     113              :             }
     114              :         }
     115            0 :     }
     116              : 
     117            0 :     void Variable::operator=(CcuArithmeticOperator<Address, Address> op) { AddrAddrAppendToContext(op); }
     118              : 
     119            1 :     void Variable::operator+=(const Variable& other)
     120              :     {
     121            1 :         AppendToContext(context, std::make_shared<CcuRepAdd>(context->GetInsGenerator(), *this, other));
     122            1 :     }
     123              : 
     124            1 :     void Variable::operator+=(const uint16_t immediate)
     125              :     {
     126            1 :         AppendToContext(context, std::make_shared<CcuRepAdd>(context->GetInsGenerator(), *this, immediate));
     127            1 :     }
     128              : 
     129            1 :     void Variable::operator*=(const Variable& other)
     130              :     {
     131            1 :         AppendToContext(context, std::make_shared<CcuRepMul>(context->GetInsGenerator(), *this, other));
     132            1 :     }
     133              : 
     134            1 :     void Variable::operator*=(uint16_t immediate)
     135              :     {
     136            1 :         AppendToContext(context, std::make_shared<CcuRepMul>(context->GetInsGenerator(), *this, immediate));
     137            1 :     }
     138              : 
     139            1 :     void Variable::operator-=(const Variable& other)
     140              :     {
     141            1 :         AppendToContext(context, std::make_shared<CcuRepSub>(context->GetInsGenerator(), *this, other));
     142            1 :     }
     143              : 
     144            1 :     void Variable::operator-=(uint16_t immediate)
     145              :     {
     146            1 :         AppendToContext(context, std::make_shared<CcuRepSub>(context->GetInsGenerator(), *this, immediate));
     147            1 :     }
     148              : 
     149            0 :     void Variable::operator&=(const Variable& other)
     150              :     {
     151            0 :         AppendToContext(context, std::make_shared<CcuRepAnd>(context->GetInsGenerator(), *this, other));
     152            0 :     }
     153              : 
     154            0 :     void Variable::operator|=(const Variable& other)
     155              :     {
     156            0 :         AppendToContext(context, std::make_shared<CcuRepOr>(context->GetInsGenerator(), *this, other));
     157            0 :     }
     158              : 
     159            0 :     void Variable::operator^=(const Variable& other)
     160              :     {
     161            0 :         AppendToContext(context, std::make_shared<CcuRepXor>(context->GetInsGenerator(), *this, other));
     162            0 :     }
     163              : 
     164            6 :     void Variable::VarVarLogicAppendToContext(CcuLogicOperator<Variable, Variable> op)
     165              :     {
     166            6 :         switch (op.type) {
     167            2 :             case CcuLogicOperatorType::AND: {
     168            2 :                 AppendToContext(
     169            4 :                     context, std::make_shared<CcuRepAnd>(context->GetInsGenerator(), *this, op.lhs, op.rhs));
     170            2 :                 break;
     171              :             }
     172            2 :             case CcuLogicOperatorType::OR: {
     173            2 :                 AppendToContext(context, std::make_shared<CcuRepOr>(context->GetInsGenerator(), *this, op.lhs, op.rhs));
     174            2 :                 break;
     175              :             }
     176            2 :             case CcuLogicOperatorType::XOR: {
     177            2 :                 AppendToContext(
     178            4 :                     context, std::make_shared<CcuRepXor>(context->GetInsGenerator(), *this, op.lhs, op.rhs));
     179            2 :                 break;
     180              :             }
     181            0 :             default: {
     182            0 :                 Hccl::THROW<Hccl::NotSupportException>("Not supported Logic operate between var and var");
     183              :             }
     184              :         }
     185            6 :     }
     186              : 
     187            1 :     void Variable::AddrLogicAppendToContext(CcuLogicOperator<Variable> op)
     188              :     {
     189            1 :         switch (op.type) {
     190            1 :             case CcuLogicOperatorType::NOT: {
     191            1 :                 AppendToContext(context, std::make_shared<CcuRepNot>(context->GetInsGenerator(), *this, op.lhs));
     192            1 :                 break;
     193              :             }
     194            0 :             default: {
     195            0 :                 Hccl::THROW<Hccl::NotSupportException>("Not supported Logic operate between addr and immedB.");
     196              :             }
     197              :         }
     198            1 :     }
     199              : 
     200            6 :     void Variable::operator=(CcuLogicOperator<Variable, Variable> op) { VarVarLogicAppendToContext(op); }
     201              : 
     202            1 :     void Variable::operator=(CcuLogicOperator<Variable> op) { AddrLogicAppendToContext(op); }
     203              : 
     204            4 :     void Variable::operator=(CcuShiftOperator<Variable, Variable> op)
     205              :     {
     206            4 :         switch (op.type) {
     207            2 :             case CcuShiftType::RIGHT: {
     208            2 :                 AppendToContext(
     209            4 :                     context, std::make_shared<CcuRepShR>(context->GetInsGenerator(), *this, op.lhs, op.rhs));
     210            2 :                 break;
     211              :             }
     212            2 :             case CcuShiftType::LEFT: {
     213            2 :                 AppendToContext(
     214            4 :                     context, std::make_shared<CcuRepShL>(context->GetInsGenerator(), *this, op.lhs, op.rhs));
     215            2 :                 break;
     216              :             }
     217            0 :             default: {
     218            0 :                 Hccl::THROW<Hccl::NotSupportException>("Not supported shift bit operate between var and immed.");
     219              :             }
     220              :         }
     221            4 :     }
     222              : 
     223            0 :     void Variable::operator<<=(const Variable& other) const
     224              :     {
     225            0 :         AppendToContext(context, std::make_shared<CcuRepShL>(context->GetInsGenerator(), *this, other));
     226            0 :     }
     227              : 
     228            0 :     void Variable::operator>>=(const Variable& other) const
     229              :     {
     230            0 :         AppendToContext(context, std::make_shared<CcuRepShR>(context->GetInsGenerator(), *this, other));
     231            0 :     }
     232              : 
     233        10801 :     Address::Address(CcuRepContext* context) : CcuVirRes(context) {}
     234              : 
     235        19086 :     Address::Address(const Address& other) : CcuVirRes(other.context) { phyRes = other.phyRes; }
     236              : 
     237           91 :     Address::Address(Variable&& other) : CcuVirRes(other.GetCurContext()) { phyRes = other.GetCurPhyRes(); }
     238              : 
     239            0 :     void Address::operator=(Address&& other)
     240              :     {
     241            0 :         phyRes = other.phyRes;
     242            0 :         context = other.context;
     243            0 :     }
     244              : 
     245           39 :     void Address::operator=(const Address& other)
     246              :     {
     247           39 :         AppendToContext(context, std::make_shared<CcuRepAssign>(context->GetInsGenerator(), *this, other));
     248           39 :     }
     249              : 
     250           15 :     void Address::operator=(const Variable& other)
     251              :     {
     252           15 :         AppendToContext(context, std::make_shared<CcuRepAssign>(context->GetInsGenerator(), *this, other));
     253           15 :     }
     254              : 
     255           14 :     void Address::operator=(uint64_t immediate)
     256              :     {
     257           14 :         AppendToContext(context, std::make_shared<CcuRepAssign>(context->GetInsGenerator(), *this, immediate));
     258           14 :     }
     259              : 
     260            1 :     void Address::VarAddrAppendToContext(CcuArithmeticOperator<Variable, Address> op)
     261              :     {
     262            1 :         switch (op.type) {
     263            1 :             case CcuArithmeticOperatorType::ADDITION: {
     264            1 :                 AppendToContext(
     265            2 :                     context, std::make_shared<CcuRepAdd>(context->GetInsGenerator(), *this, op.rhs, op.lhs));
     266            1 :                 break;
     267              :             }
     268            0 :             case CcuArithmeticOperatorType::MULTIPLICATION: {
     269            0 :                 AppendToContext(
     270            0 :                     context, std::make_shared<CcuRepMul>(context->GetInsGenerator(), *this, op.lhs, op.rhs));
     271            0 :                 break;
     272              :             }
     273            0 :             case CcuArithmeticOperatorType::SUBTRACTION: {
     274            0 :                 AppendToContext(
     275            0 :                     context, std::make_shared<CcuRepSub>(context->GetInsGenerator(), *this, op.rhs, op.lhs));
     276            0 :                 break;
     277              :             }
     278            0 :             default: {
     279            0 :                 Hccl::THROW<Hccl::NotSupportException>("Not supported Arithmetic operate between var and addr.");
     280              :             }
     281              :         }
     282            1 :     }
     283            1 :     void Address::operator=(CcuArithmeticOperator<Variable, Address> op) { VarAddrAppendToContext(op); }
     284              : 
     285            3 :     void Address::AddrAddrAppendToContext(CcuArithmeticOperator<Address, Address> op)
     286              :     {
     287            3 :         switch (op.type) {
     288            3 :             case CcuArithmeticOperatorType::ADDITION: {
     289            3 :                 AppendToContext(
     290            6 :                     context, std::make_shared<CcuRepAdd>(context->GetInsGenerator(), *this, op.lhs, op.rhs));
     291            3 :                 break;
     292              :             }
     293            0 :             default: {
     294            0 :                 Hccl::THROW<Hccl::NotSupportException>("Not supported Arithmetic operate in addr = addr (op) addr .");
     295              :             }
     296              :         }
     297            3 :     }
     298              : 
     299            3 :     void Address::operator=(CcuArithmeticOperator<Address, Address> op) { AddrAddrAppendToContext(op); }
     300              : 
     301            0 :     void Address::VarImmedAppendToContext(CcuArithmeticOperator<Variable, uint16_t> op)
     302              :     {
     303            0 :         ArithmeticAppendToContext(context, *this, op);
     304            0 :     }
     305            0 :     void Address::operator=(CcuArithmeticOperator<Variable, uint16_t> op) { VarImmedAppendToContext(op); }
     306              : 
     307            2 :     void Address::AddrImmedAppendToContext(CcuArithmeticOperator<Address, uint16_t> op)
     308              :     {
     309            2 :         ArithmeticAppendToContext(context, *this, op);
     310            2 :     }
     311            2 :     void Address::operator=(CcuArithmeticOperator<Address, uint16_t> op) { AddrImmedAppendToContext(op); }
     312              : 
     313            0 :     void Address::VarVarAppendToContext(CcuArithmeticOperator<Variable, Variable> op)
     314              :     {
     315            0 :         switch (op.type) {
     316            0 :             case CcuArithmeticOperatorType::ADDITION: {
     317            0 :                 AppendToContext(
     318            0 :                     context, std::make_shared<CcuRepAdd>(context->GetInsGenerator(), *this, op.lhs, op.rhs));
     319            0 :                 break;
     320              :             }
     321            0 :             case CcuArithmeticOperatorType::MULTIPLICATION: {
     322            0 :                 AppendToContext(
     323            0 :                     context, std::make_shared<CcuRepMul>(context->GetInsGenerator(), *this, op.lhs, op.rhs));
     324            0 :                 break;
     325              :             }
     326            0 :             default: {
     327            0 :                 Hccl::THROW<Hccl::NotSupportException>("Not supported Arithmetic operate between var and var.");
     328              :             }
     329              :         }
     330            0 :     }
     331              : 
     332            0 :     void Address::operator=(CcuArithmeticOperator<Variable, Variable> op) { VarVarAppendToContext(op); }
     333              : 
     334           42 :     void Address::operator+=(const Variable& other)
     335              :     {
     336           42 :         AppendToContext(context, std::make_shared<CcuRepAdd>(context->GetInsGenerator(), *this, other));
     337           42 :     }
     338              : 
     339            0 :     void Address::operator+=(const uint16_t immediate)
     340              :     {
     341            0 :         AppendToContext(context, std::make_shared<CcuRepAdd>(context->GetInsGenerator(), *this, immediate));
     342            0 :     }
     343              : 
     344            0 :     void Address::operator*=(const Variable& other)
     345              :     {
     346            0 :         AppendToContext(context, std::make_shared<CcuRepMul>(context->GetInsGenerator(), *this, other));
     347            0 :     }
     348              : 
     349            0 :     void Address::operator*=(const uint16_t immediate)
     350              :     {
     351            0 :         AppendToContext(context, std::make_shared<CcuRepMul>(context->GetInsGenerator(), *this, immediate));
     352            0 :     }
     353              : 
     354            0 :     void Address::operator-=(const Variable& other)
     355              :     {
     356            0 :         AppendToContext(context, std::make_shared<CcuRepSub>(context->GetInsGenerator(), *this, other));
     357            0 :     }
     358              : 
     359            0 :     void Address::operator-=(const uint16_t immediate)
     360              :     {
     361            0 :         AppendToContext(context, std::make_shared<CcuRepSub>(context->GetInsGenerator(), *this, immediate));
     362            0 :     }
     363              : 
     364            0 :     void Address::operator=(CcuShiftOperator<Variable, Variable> op)
     365              :     {
     366            0 :         switch (op.type) {
     367            0 :             case CcuShiftType::LEFT: {
     368            0 :                 AppendToContext(
     369            0 :                     context, std::make_shared<CcuRepShL>(context->GetInsGenerator(), *this, op.lhs, op.rhs));
     370            0 :                 break;
     371              :             }
     372            0 :             case CcuShiftType::RIGHT: {
     373            0 :                 AppendToContext(
     374            0 :                     context, std::make_shared<CcuRepShR>(context->GetInsGenerator(), *this, op.lhs, op.rhs));
     375            0 :                 break;
     376              :             }
     377            0 :             default: {
     378            0 :                 Hccl::THROW<Hccl::NotSupportException>("Not supported shift bit operate between var and var.");
     379              :             }
     380              :         }
     381            0 :     }
     382              : 
     383            0 :     void Address::operator<<=(const Variable& other) const
     384              :     {
     385            0 :         AppendToContext(context, std::make_shared<CcuRepShL>(context->GetInsGenerator(), *this, other));
     386            0 :     }
     387              : 
     388            0 :     void Address::operator>>=(const Variable& other) const
     389              :     {
     390            0 :         AppendToContext(context, std::make_shared<CcuRepShR>(context->GetInsGenerator(), *this, other));
     391            0 :     }
     392              : 
     393           10 :     LocalNotify::LocalNotify(CcuRepContext* context) : CcuVirRes(context) {}
     394              : 
     395            1 :     CcuBuffer::CcuBuffer(CcuRepContext* context) : CcuVirRes(context) {}
     396              : 
     397          377 :     CcuBuf::CcuBuf(CcuRepContext* context) : CcuVirRes(context) {}
     398            1 :     uint16_t CcuBuffer::Id() const { return phyRes->Id() + CCUBUFFER_DIE_ID_BIT * phyRes->DieId(); }
     399              : 
     400           71 :     uint16_t CcuBuf::Id() const { return phyRes->Id() + CCUBUFFER_DIE_ID_BIT * phyRes->DieId(); }
     401              : 
     402          113 :     Executor::Executor(CcuRepContext* context) : CcuVirRes(context) {}
     403              : 
     404         6001 :     CompletedEvent::CompletedEvent(CcuRepContext* context) : CcuVirRes(context) {}
     405              : 
     406              : }; // namespace CcuRep
     407              : }; // namespace hcomm
        

Generated by: LCOV version 2.0-1