Jlm
arithmetic.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2014 2015 2024 Helge Bahmann <hcb@chaoticmind.net>
3  * Copyright 2011 2012 2013 2014 Nico Reißmann <nico.reissmann@gmail.com>
4  * See COPYING for terms of redistribution.
5  */
6 
10 
11 namespace jlm::rvsdg
12 {
13 
14 // This provides the explicit template instantiations underlying
15 // all bitstring operation classes: This ensures that there is a
16 // single definition for all virtual functions, vmts etc in the
17 // rvsdg library (instead of the compiler template-instantiating
18 // them multiple times in each translation unit, and then relying
19 // on linker to do de-duplication).
20 
21 struct reduce_neg
22 {
25  {
26  return arg.neg();
27  }
28 };
29 
30 const char BitNegateLabel[] = "BitNegate";
32 
33 struct reduce_not
34 {
37  {
38  return arg.lnot();
39  }
40 };
41 
42 const char BitNotLabel[] = "BitNot";
44 
45 struct reduce_add
46 {
48  operator()(const BitValueRepresentation & arg1, const BitValueRepresentation & arg2) const
49  {
50  return arg1.add(arg2);
51  }
52 };
53 
54 const char BitAddLabel[] = "BitAdd";
55 template class MakeBitBinaryOperation<
56  reduce_add,
59 
60 struct reduce_and
61 {
63  operator()(const BitValueRepresentation & arg1, const BitValueRepresentation & arg2) const
64  {
65  return arg1.land(arg2);
66  }
67 };
68 
69 const char BitAndLabel[] = "BitAnd";
70 template class MakeBitBinaryOperation<
71  reduce_and,
74 
76 {
78  operator()(const BitValueRepresentation & arg1, const BitValueRepresentation & arg2) const
79  {
80  return arg1.ashr(arg2.to_uint());
81  }
82 };
83 
84 const char BitAShrLabel[] = "BitAShr";
86 
87 struct reduce_mul
88 {
90  operator()(const BitValueRepresentation & arg1, const BitValueRepresentation & arg2) const
91  {
92  return arg1.mul(arg2);
93  }
94 };
95 
96 const char BitMulLabel[] = "BitMul";
97 template class MakeBitBinaryOperation<
98  reduce_mul,
101 
102 struct reduce_or
103 {
105  operator()(const BitValueRepresentation & arg1, const BitValueRepresentation & arg2) const
106  {
107  return arg1.lor(arg2);
108  }
109 };
110 
111 const char BitOrLabel[] = "BitOr";
112 template class MakeBitBinaryOperation<
113  reduce_or,
114  BitOrLabel,
116 
118 {
120  operator()(const BitValueRepresentation & arg1, const BitValueRepresentation & arg2) const
121  {
122  return arg1.sdiv(arg2);
123  }
124 };
125 
126 const char BitSDivLabel[] = "BitSDiv";
128 
130 {
132  operator()(const BitValueRepresentation & arg1, const BitValueRepresentation & arg2) const
133  {
134  return arg1.shl(arg2.to_uint());
135  }
136 };
137 
138 const char BitShlLabel[] = "BitShl";
140 
142 {
144  operator()(const BitValueRepresentation & arg1, const BitValueRepresentation & arg2) const
145  {
146  return arg1.shr(arg2.to_uint());
147  }
148 };
149 
150 const char BitShrLabel[] = "BitShr";
152 
154 {
156  operator()(const BitValueRepresentation & arg1, const BitValueRepresentation & arg2) const
157  {
158  return arg1.smod(arg2);
159  }
160 };
161 
162 const char BitSModLabel[] = "BitSMod";
164 
166 {
168  operator()(const BitValueRepresentation & arg1, const BitValueRepresentation & arg2) const
169  {
170  return arg1.smulh(arg2);
171  }
172 };
173 
174 const char BitSMulHLabel[] = "BitSMulH";
175 template class MakeBitBinaryOperation<
176  reduce_smulh,
179 
181 {
183  operator()(const BitValueRepresentation & arg1, const BitValueRepresentation & arg2) const
184  {
185  return arg1.sub(arg2);
186  }
187 };
188 
189 const char BitSubLabel[] = "BitSub";
191 
193 {
195  operator()(const BitValueRepresentation & arg1, const BitValueRepresentation & arg2) const
196  {
197  return arg1.udiv(arg2);
198  }
199 };
200 
201 const char BitUDivLabel[] = "BitUDiv";
203 
205 {
207  operator()(const BitValueRepresentation & arg1, const BitValueRepresentation & arg2) const
208  {
209  return arg1.umod(arg2);
210  }
211 };
212 
213 const char BitUModLabel[] = "BitUMod";
215 
217 {
219  operator()(const BitValueRepresentation & arg1, const BitValueRepresentation & arg2) const
220  {
221  return arg1.umulh(arg2);
222  }
223 };
224 
225 const char BitUMulHLabel[] = "BitUMulH";
226 template class MakeBitBinaryOperation<
227  reduce_umulh,
230 
232 {
234  operator()(const BitValueRepresentation & arg1, const BitValueRepresentation & arg2) const
235  {
236  return arg1.lxor(arg2);
237  }
238 };
239 
240 const char BitXorLabel[] = "BitXor";
241 template class MakeBitBinaryOperation<
242  reduce_xor,
243  BitXorLabel,
245 
246 }
BitValueRepresentation shl(size_t shift) const
void udiv(const BitValueRepresentation &divisor, BitValueRepresentation &quotient, BitValueRepresentation &remainder) const
BitValueRepresentation smod(const BitValueRepresentation &other) const
void mul(const BitValueRepresentation &factor1, const BitValueRepresentation &factor2, BitValueRepresentation &product) const
BitValueRepresentation sdiv(const BitValueRepresentation &other) const
BitValueRepresentation neg() const
BitValueRepresentation umulh(const BitValueRepresentation &other) const
char lor(char a, char b) const noexcept
char lxor(char a, char b) const noexcept
BitValueRepresentation sub(const BitValueRepresentation &other) const
BitValueRepresentation ashr(size_t shift) const
BitValueRepresentation shr(size_t shift) const
BitValueRepresentation umod(const BitValueRepresentation &other) const
BitValueRepresentation smulh(const BitValueRepresentation &other) const
char land(char a, char b) const noexcept
char add(char a, char b, char c) const noexcept
const char BitOrLabel[]
Definition: arithmetic.cpp:111
const char BitNegateLabel[]
Definition: arithmetic.cpp:30
const char BitSMulHLabel[]
Definition: arithmetic.cpp:174
const char BitAndLabel[]
Definition: arithmetic.cpp:69
const char BitShrLabel[]
Definition: arithmetic.cpp:150
const char BitAShrLabel[]
Definition: arithmetic.cpp:84
const char BitSDivLabel[]
Definition: arithmetic.cpp:126
const char BitUDivLabel[]
Definition: arithmetic.cpp:201
const char BitShlLabel[]
Definition: arithmetic.cpp:138
const char BitUModLabel[]
Definition: arithmetic.cpp:213
const char BitNotLabel[]
Definition: arithmetic.cpp:42
const char BitMulLabel[]
Definition: arithmetic.cpp:96
const char BitXorLabel[]
Definition: arithmetic.cpp:240
const char BitUMulHLabel[]
Definition: arithmetic.cpp:225
const char BitSubLabel[]
Definition: arithmetic.cpp:189
const char BitAddLabel[]
Definition: arithmetic.cpp:54
const char BitSModLabel[]
Definition: arithmetic.cpp:162
BitValueRepresentation operator()(const BitValueRepresentation &arg1, const BitValueRepresentation &arg2) const
Definition: arithmetic.cpp:48
BitValueRepresentation operator()(const BitValueRepresentation &arg1, const BitValueRepresentation &arg2) const
Definition: arithmetic.cpp:63
BitValueRepresentation operator()(const BitValueRepresentation &arg1, const BitValueRepresentation &arg2) const
Definition: arithmetic.cpp:78
BitValueRepresentation operator()(const BitValueRepresentation &arg1, const BitValueRepresentation &arg2) const
Definition: arithmetic.cpp:90
BitValueRepresentation operator()(const BitValueRepresentation &arg) const
Definition: arithmetic.cpp:24
BitValueRepresentation operator()(const BitValueRepresentation &arg) const
Definition: arithmetic.cpp:36
BitValueRepresentation operator()(const BitValueRepresentation &arg1, const BitValueRepresentation &arg2) const
Definition: arithmetic.cpp:105
BitValueRepresentation operator()(const BitValueRepresentation &arg1, const BitValueRepresentation &arg2) const
Definition: arithmetic.cpp:120
BitValueRepresentation operator()(const BitValueRepresentation &arg1, const BitValueRepresentation &arg2) const
Definition: arithmetic.cpp:132
BitValueRepresentation operator()(const BitValueRepresentation &arg1, const BitValueRepresentation &arg2) const
Definition: arithmetic.cpp:144
BitValueRepresentation operator()(const BitValueRepresentation &arg1, const BitValueRepresentation &arg2) const
Definition: arithmetic.cpp:156
BitValueRepresentation operator()(const BitValueRepresentation &arg1, const BitValueRepresentation &arg2) const
Definition: arithmetic.cpp:168
BitValueRepresentation operator()(const BitValueRepresentation &arg1, const BitValueRepresentation &arg2) const
Definition: arithmetic.cpp:183
BitValueRepresentation operator()(const BitValueRepresentation &arg1, const BitValueRepresentation &arg2) const
Definition: arithmetic.cpp:195
BitValueRepresentation operator()(const BitValueRepresentation &arg1, const BitValueRepresentation &arg2) const
Definition: arithmetic.cpp:207
BitValueRepresentation operator()(const BitValueRepresentation &arg1, const BitValueRepresentation &arg2) const
Definition: arithmetic.cpp:219
BitValueRepresentation operator()(const BitValueRepresentation &arg1, const BitValueRepresentation &arg2) const
Definition: arithmetic.cpp:234