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