1 /* This file is part of the sirit project.
2  * Copyright (c) 2019 sirit
3  * This software may be used and distributed according to the terms of the
4  * 3-Clause BSD License
5  */
6 
7 #include <memory>
8 #include "common_types.h"
9 #include "op.h"
10 #include "sirit/sirit.h"
11 
12 namespace Sirit {
13 
OpShiftRightLogical(Id result_type,Id base,Id shift)14 Id Module::OpShiftRightLogical(Id result_type, Id base, Id shift) {
15     auto op{std::make_unique<Op>(spv::Op::OpShiftRightLogical, bound++, result_type)};
16     op->Add(base);
17     op->Add(shift);
18     return AddCode(std::move(op));
19 }
20 
OpShiftRightArithmetic(Id result_type,Id base,Id shift)21 Id Module::OpShiftRightArithmetic(Id result_type, Id base, Id shift) {
22     auto op{std::make_unique<Op>(spv::Op::OpShiftRightArithmetic, bound++, result_type)};
23     op->Add(base);
24     op->Add(shift);
25     return AddCode(std::move(op));
26 }
27 
OpShiftLeftLogical(Id result_type,Id base,Id shift)28 Id Module::OpShiftLeftLogical(Id result_type, Id base, Id shift) {
29     auto op{std::make_unique<Op>(spv::Op::OpShiftLeftLogical, bound++, result_type)};
30     op->Add(base);
31     op->Add(shift);
32     return AddCode(std::move(op));
33 }
34 
OpBitwiseOr(Id result_type,Id operand_1,Id operand_2)35 Id Module::OpBitwiseOr(Id result_type, Id operand_1, Id operand_2) {
36     auto op{std::make_unique<Op>(spv::Op::OpBitwiseOr, bound++, result_type)};
37     op->Add(operand_1);
38     op->Add(operand_2);
39     return AddCode(std::move(op));
40 }
41 
OpBitwiseXor(Id result_type,Id operand_1,Id operand_2)42 Id Module::OpBitwiseXor(Id result_type, Id operand_1, Id operand_2) {
43     auto op{std::make_unique<Op>(spv::Op::OpBitwiseXor, bound++, result_type)};
44     op->Add(operand_1);
45     op->Add(operand_2);
46     return AddCode(std::move(op));
47 }
48 
OpBitwiseAnd(Id result_type,Id operand_1,Id operand_2)49 Id Module::OpBitwiseAnd(Id result_type, Id operand_1, Id operand_2) {
50     auto op{std::make_unique<Op>(spv::Op::OpBitwiseAnd, bound++, result_type)};
51     op->Add(operand_1);
52     op->Add(operand_2);
53     return AddCode(std::move(op));
54 }
55 
OpNot(Id result_type,Id operand)56 Id Module::OpNot(Id result_type, Id operand) {
57     auto op{std::make_unique<Op>(spv::Op::OpNot, bound++, result_type)};
58     op->Add(operand);
59     return AddCode(std::move(op));
60 }
61 
OpBitFieldInsert(Id result_type,Id base,Id insert,Id offset,Id count)62 Id Module::OpBitFieldInsert(Id result_type, Id base, Id insert, Id offset, Id count) {
63     auto op{std::make_unique<Op>(spv::Op::OpBitFieldInsert, bound++, result_type)};
64     op->Add(base);
65     op->Add(insert);
66     op->Add(offset);
67     op->Add(count);
68     return AddCode(std::move(op));
69 }
70 
OpBitFieldSExtract(Id result_type,Id base,Id offset,Id count)71 Id Module::OpBitFieldSExtract(Id result_type, Id base, Id offset, Id count) {
72     auto op{std::make_unique<Op>(spv::Op::OpBitFieldSExtract, bound++, result_type)};
73     op->Add(base);
74     op->Add(offset);
75     op->Add(count);
76     return AddCode(std::move(op));
77 }
78 
OpBitFieldUExtract(Id result_type,Id base,Id offset,Id count)79 Id Module::OpBitFieldUExtract(Id result_type, Id base, Id offset, Id count) {
80     auto op{std::make_unique<Op>(spv::Op::OpBitFieldUExtract, bound++, result_type)};
81     op->Add(base);
82     op->Add(offset);
83     op->Add(count);
84     return AddCode(std::move(op));
85 }
86 
OpBitReverse(Id result_type,Id base)87 Id Module::OpBitReverse(Id result_type, Id base) {
88     auto op{std::make_unique<Op>(spv::Op::OpBitReverse, bound++, result_type)};
89     op->Add(base);
90     return AddCode(std::move(op));
91 }
92 
OpBitCount(Id result_type,Id base)93 Id Module::OpBitCount(Id result_type, Id base) {
94     auto op{std::make_unique<Op>(spv::Op::OpBitCount, bound++, result_type)};
95     op->Add(base);
96     return AddCode(std::move(op));
97 }
98 
99 } // namespace Sirit
100