LCOV - code coverage report
Current view: top level - base_comm/resources/ccu/ccu_representation/reps/arithmetic - ccu_rep_mul.cc (source / functions) Coverage Total Hit
Test: coverage.info Lines: 98.1 % 103 101
Test Date: 2026-08-04 10:52:23 Functions: 100.0 % 23 23

            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              : #include "ccu_rep_v1.h"
      12              : #include "ccu_ins_generator_v1.h"
      13              : #include "string_util.h"
      14              : #include "exception_util.h"
      15              : #include "ccu_api_exception.h"
      16              : #include "ccu_kernel.h"
      17              : 
      18              : namespace hcomm {
      19              : namespace CcuRep {
      20           37 : void CcuRepMul::SetCommonInfo()
      21              : {
      22           37 :     type       = CcuRepType::MUL;
      23           37 :     instrCount = insGenPtr->GetInstrCount(type);
      24           37 : }
      25              : 
      26            7 : CcuRepMul::CcuRepMul(CcuInsGeneratorBase* insGenPtr, const Variable &varC, const Variable &varA, const Variable &varB)
      27            7 :     : insGenPtr(insGenPtr), subType(MulSubType::VAR_MUL_VAR_TO_VAR), varA(varA), varB(varB), varC(varC)
      28              : {
      29            7 :     SetCommonInfo();
      30            7 : }
      31              : 
      32            5 : CcuRepMul::CcuRepMul(CcuInsGeneratorBase* insGenPtr, const Variable &varC, const Variable &varA, uint16_t immedB)
      33            5 :     : insGenPtr(insGenPtr), subType(MulSubType::VAR_MUL_IMMED_TO_VAR), varA(varA), varC(varC), immedB(immedB)
      34              : {
      35            5 :     SetCommonInfo();
      36            5 : }
      37              : 
      38            3 : CcuRepMul::CcuRepMul(CcuInsGeneratorBase* insGenPtr, const Variable &varA, const Variable &varB)
      39            3 :     : insGenPtr(insGenPtr), subType(MulSubType::SELF_MUL_VAR_VARIABLE), varA(varA), varB(varB)
      40              : {
      41            3 :     SetCommonInfo();
      42            3 : }
      43              : 
      44            3 : CcuRepMul::CcuRepMul(CcuInsGeneratorBase* insGenPtr, const Variable &varA, uint16_t immedB)
      45            3 :     : insGenPtr(insGenPtr), subType(MulSubType::SELF_MUL_IMMED_VARIABLE), varA(varA), immedB(immedB)
      46              : {
      47            3 :     SetCommonInfo();
      48            3 : }
      49              : 
      50            3 : CcuRepMul::CcuRepMul(CcuInsGeneratorBase* insGenPtr, const Address &addrC, const Variable &varA, const Variable &varB)
      51            3 :     : insGenPtr(insGenPtr), subType(MulSubType::VAR_MUL_VAR_TO_ADDR), varA(varA), varB(varB), addrC(addrC)
      52              : {
      53            3 :     SetCommonInfo();
      54            3 : }
      55              : 
      56            3 : CcuRepMul::CcuRepMul(CcuInsGeneratorBase* insGenPtr, const Address &addrC, const Variable &varA, const Address &addrB)
      57            3 :     : insGenPtr(insGenPtr), subType(MulSubType::VAR_MUL_ADDR_TO_ADDR), varA(varA), addrB(addrB), addrC(addrC)
      58              : {
      59            3 :     SetCommonInfo();
      60            3 : }
      61              : 
      62            3 : CcuRepMul::CcuRepMul(CcuInsGeneratorBase* insGenPtr, const Address &addrA, const Variable &varB)
      63            3 :     : insGenPtr(insGenPtr), subType(MulSubType::SELF_MUL_VAR_ADDRESS), varB(varB), addrA(addrA)
      64              : {
      65            3 :     SetCommonInfo();
      66            3 : }
      67              : 
      68            3 : CcuRepMul::CcuRepMul(CcuInsGeneratorBase* insGenPtr, const Address &addrC, const Address &addrA, const uint16_t immedB)
      69            3 :     : insGenPtr(insGenPtr), subType(MulSubType::ADDR_MUL_IMMED_TO_ADDR), addrA(addrA), addrC(addrC), immedB(immedB)
      70              : {
      71            3 :     SetCommonInfo();
      72            3 : }
      73              : 
      74            2 : CcuRepMul::CcuRepMul(CcuInsGeneratorBase* insGenPtr, const Address &addrC, const Variable &varA, const uint16_t immedB)
      75            2 :     : insGenPtr(insGenPtr), subType(MulSubType::VAR_MUL_IMMED_TO_ADDR), varA(varA), addrC(addrC), immedB(immedB)
      76              : {
      77            2 :     SetCommonInfo();
      78            2 : }
      79              : 
      80            2 : CcuRepMul::CcuRepMul(CcuInsGeneratorBase* insGenPtr, const Address &addrA, const uint16_t immedB)
      81            2 :     : insGenPtr(insGenPtr), subType(MulSubType::SELF_MUL_IMMED_ADDRESS), addrA(addrA), immedB(immedB)
      82              : {
      83            2 :     SetCommonInfo();
      84            2 : }
      85              : 
      86            3 : CcuRepMul::CcuRepMul(CcuInsGeneratorBase* insGenPtr, const Variable &varC, const Address &addrA, const uint16_t immedB)
      87            3 :     : insGenPtr(insGenPtr), subType(MulSubType::ADDR_MUL_IMMED_TO_VAR), varC(varC), addrA(addrA), immedB(immedB)
      88              : {
      89            3 :     SetCommonInfo();
      90            3 : }
      91              : 
      92            8 : void CcuRepMul::ValidateInsGenPtrForMul()
      93              : {
      94            8 :     CcuInsGeneratorV1* tmpPtrV1 = dynamic_cast<CcuInsGeneratorV1 *>(insGenPtr);
      95            8 :     CHK_PRT_THROW((tmpPtrV1 && !supportCcuV1),
      96              :         HCCL_ERROR("[CcuRepMul][%s]Cannot translate CcuRepMul for A5 when supportCcuV1 is false", __func__),
      97              :         Hccl::CcuApiException, "tmpPtrV1 does not match supportCcuV1");
      98            8 : }
      99              : 
     100            8 : bool CcuRepMul::Translate(CcuKernel* ccuKernel, CcuInstr *&instr, uint16_t &instrId, const TransDep &dep)
     101              : {
     102            8 :     ValidateInsGenPtrForMul();
     103            8 :     Hccl::CHECK_NULLPTR(instr, "[CcuRepMul::Translate] instr is nullptr!");
     104            8 :     this->instrId = instrId;
     105            8 :     translated    = true;
     106              : 
     107            8 :     insGenPtr->CcuRepMulTranslate(ccuKernel, instr, this);
     108              :     
     109            8 :     CHK_PRT_THROW((instrId > UINT16_MAX - instrCount),
     110              :                         HCCL_ERROR("[CcuRepMul::Translate]uint16 integer overflow occurs, instrId = [%hu], instrCount = [%hu]", instrId, instrCount),
     111              :                           Hccl::InternalException, "integer overflow");
     112            8 :     instrId += instrCount;
     113              : 
     114            8 :     return translated;
     115              : }
     116              : 
     117           15 : std::string CcuRepMul::Describe()
     118              : {
     119           15 :     switch (subType) {
     120            3 :         case MulSubType::VAR_MUL_VAR_TO_VAR: {
     121            3 :             return Hccl::StringFormat("Variable[%u] = Variable[%u] * Variable[%u]", varC.Id(), varA.Id(), varB.Id());
     122              :         }
     123            3 :         case MulSubType::VAR_MUL_IMMED_TO_VAR: {
     124            3 :             return Hccl::StringFormat("Variable[%u] = Variable[%u] * Immed[%u]", varC.Id(), varA.Id(), immedB);
     125              :         }
     126            1 :         case MulSubType::SELF_MUL_VAR_VARIABLE: {
     127            1 :             return Hccl::StringFormat("Variable[%u] *= Variable[%u]", varA.Id(), varB.Id());
     128              :         }
     129            1 :         case MulSubType::SELF_MUL_IMMED_VARIABLE: {
     130            1 :             return Hccl::StringFormat("Variable[%u] *= Immed[%u]", varA.Id(), immedB);
     131              :         }
     132            1 :         case MulSubType::VAR_MUL_VAR_TO_ADDR: {
     133            1 :             return Hccl::StringFormat("Address[%u] = Variable[%u] * Variable[%u]", addrC.Id(), varA.Id(), varB.Id());
     134              :         }
     135            1 :         case MulSubType::VAR_MUL_ADDR_TO_ADDR: {
     136            1 :             return Hccl::StringFormat("Address[%u] = Variable[%u] * Address[%u]", addrC.Id(), varA.Id(), addrB.Id());
     137              :         }
     138            1 :         case MulSubType::VAR_MUL_IMMED_TO_ADDR: {
     139            1 :             return Hccl::StringFormat("address[%u] = Variable[%u] * Immed[%u]", addrC.Id(), varA.Id(), immedB);
     140              :         }
     141            1 :         case MulSubType::ADDR_MUL_IMMED_TO_ADDR: {
     142            1 :             return Hccl::StringFormat("address[%u] = address[%u] * Immed[%u]", addrC.Id(), addrA.Id(), immedB);
     143              :         }
     144            1 :         case MulSubType::SELF_MUL_VAR_ADDRESS: {
     145            1 :             return Hccl::StringFormat("address[%u] *= Variable[%u]", addrA.Id(), varB.Id());
     146              :         }
     147            1 :         case MulSubType::SELF_MUL_IMMED_ADDRESS: {
     148            1 :             return Hccl::StringFormat("address[%u] *= Immed[%u]", addrA.Id(), immedB);
     149              :         }
     150            1 :         case MulSubType::ADDR_MUL_IMMED_TO_VAR: {
     151            1 :             return Hccl::StringFormat("Variable[%u] = address[%u] * Immed[%u]", varC.Id(), addrA.Id(), immedB);
     152              :         }
     153            0 :         default: {
     154            0 :             return Hccl::StringFormat("Invalid Mul");
     155              :         }
     156              :     }
     157              : }
     158              : 
     159            3 : Address CcuRepMul::GetAddrA()
     160              : {
     161            3 :     return addrA;
     162              : }
     163              : 
     164            1 : Address CcuRepMul::GetAddrB()
     165              : {
     166            1 :     return addrB;
     167              : }
     168              : 
     169            3 : Address CcuRepMul::GetAddrC()
     170              : {
     171            3 :     return addrC;
     172              : }
     173              : 
     174            8 : Variable CcuRepMul::GetVarA()
     175              : {
     176            8 :     return varA;
     177              : }
     178              : 
     179            6 : Variable CcuRepMul::GetVarB()
     180              : {
     181            6 :     return varB;
     182              : }
     183              : 
     184            7 : Variable CcuRepMul::GetVarC()
     185              : {
     186            7 :     return varC;
     187              : }
     188              : 
     189            4 : uint16_t CcuRepMul::GetImmedB()
     190              : {
     191            4 :     return immedB;
     192              : }
     193              : 
     194           19 : MulSubType CcuRepMul::GetSubType()
     195              : {
     196           19 :     return subType;
     197              : }
     198              : }; // namespace CcuRep
     199              : }; // namespace hcomm
        

Generated by: LCOV version 2.0-1