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: 93.3 % 45 42
Test Date: 2026-08-04 10:52:23 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            4 : CcuRepShR::CcuRepShR(CcuInsGeneratorBase* insGenPtr, const Variable &varD, const Variable &varN, const Variable &varM)
      21            4 :     : subType(ShiftSubType::VAR_EQUALS_VAR_SHIFT_VAR), shiftType(ShiftType::LOGICAL_SHIFT), varN(varN), varM(varM),
      22            8 :       varD(varD), insGenPtr(insGenPtr)
      23              : {
      24            4 :     type       = CcuRepType::SHR;
      25            4 :     instrCount = insGenPtr->GetInstrCount(type);
      26            8 : }
      27              : 
      28            3 : CcuRepShR::CcuRepShR(CcuInsGeneratorBase* insGenPtr, const Variable &varD, const Variable &varM)
      29            3 :     : subType(ShiftSubType::VAR_SHIFT_ASSIGN_VAR), shiftType(ShiftType::LOGICAL_SHIFT), varM(varM), varD(varD), insGenPtr(insGenPtr)
      30              : {
      31            3 :     type       = CcuRepType::SHR;
      32            3 :     instrCount = insGenPtr->GetInstrCount(type);
      33            3 : }
      34              : 
      35            3 : CcuRepShR::CcuRepShR(CcuInsGeneratorBase* insGenPtr, const Address &addrD, const Variable &varN, const Variable &varM)
      36            3 :     : subType(ShiftSubType::ADDR_EQUALS_VAR_SHIFT_VAR), shiftType(ShiftType::LOGICAL_SHIFT), varN(varN), varM(varM),
      37            6 :       addrD(addrD), insGenPtr(insGenPtr)
      38              : {
      39            3 :     type       = CcuRepType::SHR;
      40            3 :     instrCount = insGenPtr->GetInstrCount(type);
      41            3 : }
      42              : 
      43            3 : CcuRepShR::CcuRepShR(CcuInsGeneratorBase* insGenPtr, const Address &addrD, const Variable &varM)
      44            3 :     : subType(ShiftSubType::ADDR_SHIFT_ASSIGN_VAR), shiftType(ShiftType::LOGICAL_SHIFT), varM(varM), addrD(addrD), insGenPtr(insGenPtr)
      45              : {
      46            3 :     type       = CcuRepType::SHR;
      47            3 :     instrCount = insGenPtr->GetInstrCount(type);
      48            3 : }
      49              : 
      50            4 : bool CcuRepShR::Translate(CcuKernel* ccuKernel, CcuInstr *&instr, uint16_t &curInstrId, const TransDep &dep)
      51              : {
      52            4 :     Hccl::CHECK_NULLPTR(instr, "[CcuRepShR::Translate] instr is nullptr!");
      53            4 :     this->instrId = curInstrId;
      54            4 :     translated    = true;
      55            4 :     instrCount = insGenPtr->GetInstrCount(type);
      56            4 :     insGenPtr->CcuRepShRTranslate(ccuKernel, instr, this, dep);
      57            4 :     CHK_PRT_THROW((curInstrId > UINT16_MAX - instrCount),
      58              :         HCCL_ERROR("[CcuRepShR::Translate]uint16 integer overflow occurs, curInstrId = [%hu], instrCount = [%hu]", curInstrId, instrCount),
      59              :         Hccl::InternalException, "integer overflow");
      60            4 :     curInstrId += instrCount;
      61            4 :     return translated;
      62              : }
      63              : 
      64            4 : std::string CcuRepShR::Describe()
      65              : {
      66            4 :     if (shiftType == ShiftType::LOGICAL_SHIFT) {
      67            4 :         switch (subType) {
      68            1 :             case ShiftSubType::VAR_EQUALS_VAR_SHIFT_VAR: {
      69            1 :                 return Hccl::StringFormat("Variable[%u] = Variable[%u] >> Variable[%u]", varD.Id(), varN.Id(), varM.Id());
      70              :             }
      71            1 :             case ShiftSubType::VAR_SHIFT_ASSIGN_VAR: {
      72            1 :                 return Hccl::StringFormat("Variable[%u] >>= Variable[%u]", varD.Id(), varM.Id());
      73              :             }
      74            1 :             case ShiftSubType::ADDR_EQUALS_VAR_SHIFT_VAR: {
      75            1 :                 return Hccl::StringFormat("Address[%u] = Variable[%u] >> Variable[%u]", addrD.Id(), varN.Id(), varM.Id());
      76              :             }
      77            1 :             case ShiftSubType::ADDR_SHIFT_ASSIGN_VAR: {
      78            1 :                 return Hccl::StringFormat("Address[%u] >>= Variable[%u]", addrD.Id(), varM.Id());
      79              :             }
      80            0 :             default: {
      81            0 :                 return Hccl::StringFormat("Invalid Shift");
      82              :             }
      83              :         }
      84              :     }
      85            0 :     return Hccl::StringFormat("Invalid Shift");
      86              : }
      87              : 
      88              : };  // namespace CcuRep
      89              : }; // namespace hcomm
        

Generated by: LCOV version 2.0-1