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 "ccu_rep_v1.h"
12 : #include "string_util.h"
13 : #include "exception_util.h"
14 : #include "ccu_api_exception.h"
15 : #include "ccu_ins_generater_v1.h"
16 : #include "ccu_kernel.h"
17 : namespace hcomm {
18 : namespace CcuRep {
19 :
20 0 : CcuRepXor::CcuRepXor(CcuInsGeneraterBase* insGenPtr, const Variable &varC, const Variable &varA, const Variable &varB)
21 0 : : subType(XorSubType::VAR_XOR_VAR_TO_VAR), varA(varA), varB(varB), varC(varC), insGenPtr(insGenPtr)
22 : {
23 0 : type = CcuRepType::XOR;
24 0 : instrCount = insGenPtr->GetInstrCount(type);
25 0 : }
26 :
27 0 : CcuRepXor::CcuRepXor(CcuInsGeneraterBase* insGenPtr, const Variable &varC, const Variable &varB)
28 0 : : subType(XorSubType::SELF_XOR_VAR_VARIABLE), varB(varB), varC(varC), insGenPtr(insGenPtr)
29 : {
30 0 : type = CcuRepType::XOR;
31 0 : instrCount = insGenPtr->GetInstrCount(type);
32 0 : }
33 :
34 0 : bool CcuRepXor::Translate(CcuKernel* ccuKernel, CcuInstr *&instr, uint16_t &curInstrId, const TransDep &dep)
35 : {
36 0 : Hccl::CHECK_NULLPTR(instr, "[CcuRepXor::Translate] instr is nullptr!");
37 0 : this->instrId = curInstrId;
38 0 : translated = true;
39 0 : instrCount = insGenPtr->GetInstrCount(type);
40 0 : insGenPtr->CcuRepXorTranslate(ccuKernel, instr, this, dep);
41 0 : CHK_PRT_THROW((curInstrId > UINT16_MAX - instrCount),
42 : HCCL_ERROR("[CcuRepXor::Translate]uint16 integer overflow occurs, curInstrId = [%hu], instrCount = [%hu]", curInstrId, instrCount),
43 : Hccl::InternalException, "integer overflow");
44 0 : curInstrId += instrCount;
45 0 : return translated;
46 : }
47 :
48 0 : std::string CcuRepXor::Describe()
49 : {
50 0 : switch (subType) {
51 0 : case XorSubType::VAR_XOR_VAR_TO_VAR: {
52 0 : return Hccl::StringFormat("Variable[%u] = Variable[%u] ^ Variable[%u]", varC.Id(), varA.Id(), varB.Id());
53 : }
54 0 : case XorSubType::SELF_XOR_VAR_VARIABLE: {
55 0 : return Hccl::StringFormat("Variable[%u] ^= Variable[%u]", varC.Id(), varB.Id());
56 : }
57 0 : default: {
58 0 : return Hccl::StringFormat("Invalid Xor");
59 : }
60 : }
61 : }
62 :
63 : }; // namespace CcuRep
64 : }; // namespace hcomm
|