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