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 : CcuRepShL::CcuRepShL(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::SHL;
25 4 : instrCount = insGenPtr->GetInstrCount(type);
26 8 : }
27 :
28 3 : CcuRepShL::CcuRepShL(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::SHL;
32 3 : instrCount = insGenPtr->GetInstrCount(type);
33 3 : }
34 :
35 3 : CcuRepShL::CcuRepShL(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::SHL;
40 3 : instrCount = insGenPtr->GetInstrCount(type);
41 3 : }
42 :
43 3 : CcuRepShL::CcuRepShL(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::SHL;
47 3 : instrCount = insGenPtr->GetInstrCount(type);
48 3 : }
49 :
50 4 : bool CcuRepShL::Translate(CcuKernel* ccuKernel, CcuInstr *&instr, uint16_t &curInstrId, const TransDep &dep)
51 : {
52 4 : Hccl::CHECK_NULLPTR(instr, "[CcuRepShL::Translate] instr is nullptr!");
53 4 : this->instrId = curInstrId;
54 4 : translated = true;
55 4 : instrCount = insGenPtr->GetInstrCount(type);
56 4 : insGenPtr->CcuRepShLTranslate(ccuKernel, instr, this, dep);
57 4 : 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 4 : curInstrId += instrCount;
61 4 : return translated;
62 : }
63 :
64 4 : std::string CcuRepShL::Describe()
65 : {
66 4 : switch (subType) {
67 1 : case ShiftSubType::VAR_EQUALS_VAR_SHIFT_VAR: {
68 1 : return Hccl::StringFormat("Variable[%u] = Variable[%u] << Variable[%u]", varD.Id(), varN.Id(), varM.Id());
69 : }
70 1 : case ShiftSubType::VAR_SHIFT_ASSIGN_VAR: {
71 1 : return Hccl::StringFormat("Variable[%u] <<= Variable[%u]", varD.Id(), varM.Id());
72 : }
73 1 : case ShiftSubType::ADDR_EQUALS_VAR_SHIFT_VAR: {
74 1 : return Hccl::StringFormat("Address[%u] = Variable[%u] << Variable[%u]", addrD.Id(), varN.Id(), varM.Id());
75 : }
76 1 : case ShiftSubType::ADDR_SHIFT_ASSIGN_VAR: {
77 1 : 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
|