LCOV - code coverage report
Current view: top level - base_comm/resources/ccu/ccu_representation/reps/shift - ccu_rep_shr.cc (source / functions) Coverage Total Hit
Test: coverage.info Lines: 95.2 % 63 60
Test Date: 2026-08-18 17:47:01 Functions: 100.0 % 6 6

            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 "string_util.h"
      12              : #include "exception_util.h"
      13              : #include "ccu_api_exception.h"
      14              : #include "ccu_rep_v1.h"
      15              : #include "ccu_ins_generator_v1.h"
      16              : #include "ccu_kernel.h"
      17              : namespace hcomm {
      18              : namespace CcuRep {
      19              : 
      20            6 :     CcuRepShR::CcuRepShR(
      21            6 :         CcuInsGeneratorBase* insGenPtr, const Variable& varD, const Variable& varN, const Variable& varM)
      22            6 :         : subType(ShiftSubType::VAR_EQUALS_VAR_SHIFT_VAR),
      23            6 :           shiftType(ShiftType::LOGICAL_SHIFT),
      24            6 :           varN(varN),
      25            6 :           varM(varM),
      26            6 :           varD(varD),
      27           12 :           insGenPtr(insGenPtr)
      28              :     {
      29            6 :         type = CcuRepType::SHR;
      30            6 :         instrCount = insGenPtr->GetInstrCount(type);
      31           10 :     }
      32              : 
      33            3 :     CcuRepShR::CcuRepShR(CcuInsGeneratorBase* insGenPtr, const Variable& varD, const Variable& varM)
      34            3 :         : subType(ShiftSubType::VAR_SHIFT_ASSIGN_VAR),
      35            3 :           shiftType(ShiftType::LOGICAL_SHIFT),
      36            3 :           varM(varM),
      37            3 :           varD(varD),
      38            6 :           insGenPtr(insGenPtr)
      39              :     {
      40            3 :         type = CcuRepType::SHR;
      41            3 :         instrCount = insGenPtr->GetInstrCount(type);
      42            3 :     }
      43              : 
      44            3 :     CcuRepShR::CcuRepShR(
      45            3 :         CcuInsGeneratorBase* insGenPtr, const Address& addrD, const Variable& varN, const Variable& varM)
      46            3 :         : subType(ShiftSubType::ADDR_EQUALS_VAR_SHIFT_VAR),
      47            3 :           shiftType(ShiftType::LOGICAL_SHIFT),
      48            3 :           varN(varN),
      49            3 :           varM(varM),
      50            3 :           addrD(addrD),
      51            6 :           insGenPtr(insGenPtr)
      52              :     {
      53            3 :         type = CcuRepType::SHR;
      54            3 :         instrCount = insGenPtr->GetInstrCount(type);
      55            3 :     }
      56              : 
      57            3 :     CcuRepShR::CcuRepShR(CcuInsGeneratorBase* insGenPtr, const Address& addrD, const Variable& varM)
      58            3 :         : subType(ShiftSubType::ADDR_SHIFT_ASSIGN_VAR),
      59            3 :           shiftType(ShiftType::LOGICAL_SHIFT),
      60            3 :           varM(varM),
      61            3 :           addrD(addrD),
      62            6 :           insGenPtr(insGenPtr)
      63              :     {
      64            3 :         type = CcuRepType::SHR;
      65            3 :         instrCount = insGenPtr->GetInstrCount(type);
      66            3 :     }
      67              : 
      68            6 :     bool CcuRepShR::Translate(CcuKernel* ccuKernel, CcuInstr*& instr, uint16_t& curInstrId, const TransDep& dep)
      69              :     {
      70            6 :         Hccl::CHECK_NULLPTR(instr, "[CcuRepShR::Translate] instr is nullptr!");
      71            6 :         this->instrId = curInstrId;
      72            6 :         translated = true;
      73            6 :         instrCount = insGenPtr->GetInstrCount(type);
      74            6 :         CHK_PRT_THROW(
      75              :             insGenPtr->CcuRepShRTranslate(ccuKernel, instr, this, dep) != HcclResult::HCCL_SUCCESS,
      76              :             HCCL_ERROR("[CcuRepShR][Translate] failed to translate for instrId[%u]", instrId), Hccl::CcuApiException,
      77              :             "CcuRepShR translate failed");
      78            6 :         CHK_PRT_THROW(
      79              :             (curInstrId > UINT16_MAX - instrCount),
      80              :             HCCL_ERROR(
      81              :                 "[CcuRepShR::Translate]uint16 integer overflow occurs, curInstrId = [%hu], instrCount = [%hu]",
      82              :                 curInstrId, instrCount),
      83              :             Hccl::InternalException, "integer overflow");
      84            6 :         curInstrId += instrCount;
      85            6 :         return translated;
      86              :     }
      87              : 
      88            6 :     std::string CcuRepShR::Describe()
      89              :     {
      90            6 :         if (shiftType == ShiftType::LOGICAL_SHIFT) {
      91            6 :             switch (subType) {
      92            3 :                 case ShiftSubType::VAR_EQUALS_VAR_SHIFT_VAR: {
      93              :                     return Hccl::StringFormat(
      94            3 :                         "Variable[%u] = Variable[%u] >> Variable[%u]", varD.Id(), varN.Id(), varM.Id());
      95              :                 }
      96            1 :                 case ShiftSubType::VAR_SHIFT_ASSIGN_VAR: {
      97            1 :                     return Hccl::StringFormat("Variable[%u] >>= Variable[%u]", varD.Id(), varM.Id());
      98              :                 }
      99            1 :                 case ShiftSubType::ADDR_EQUALS_VAR_SHIFT_VAR: {
     100              :                     return Hccl::StringFormat(
     101            1 :                         "Address[%u] = Variable[%u] >> Variable[%u]", addrD.Id(), varN.Id(), varM.Id());
     102              :                 }
     103            1 :                 case ShiftSubType::ADDR_SHIFT_ASSIGN_VAR: {
     104            1 :                     return Hccl::StringFormat("Address[%u] >>= Variable[%u]", addrD.Id(), varM.Id());
     105              :                 }
     106            0 :                 default: {
     107            0 :                     return Hccl::StringFormat("Invalid Shift");
     108              :                 }
     109              :             }
     110              :         }
     111            0 :         return Hccl::StringFormat("Invalid Shift");
     112              :     }
     113              : 
     114              : }; // namespace CcuRep
     115              : }; // namespace hcomm
        

Generated by: LCOV version 2.0-1