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: 47.3 % 281 133
Test Date: 2026-07-28 12:11:00 Functions: 57.1 % 77 44

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

Generated by: LCOV version 2.0-1