GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/util/floatingpoint_literal_symfpu_traits.cpp Lines: 113 122 92.6 %
Date: 2021-09-29 Branches: 67 268 25.0 %

Line Exec Source
1
/******************************************************************************
2
 * Top contributors (to current version):
3
 *   Martin Brain, Aina Niemetz
4
 *
5
 * This file is part of the cvc5 project.
6
 *
7
 * Copyright (c) 2009-2021 by the authors listed in the file AUTHORS
8
 * in the top-level source directory and their institutional affiliations.
9
 * All rights reserved.  See the file COPYING in the top-level source
10
 * directory for licensing information.
11
 * ****************************************************************************
12
 *
13
 * SymFPU glue code for floating-point values.
14
 */
15
16
#include "util/floatingpoint_literal_symfpu_traits.h"
17
18
#include "base/check.h"
19
20
namespace cvc5 {
21
namespace symfpuLiteral {
22
23
template <bool isSigned>
24
270736
wrappedBitVector<isSigned> wrappedBitVector<isSigned>::one(
25
    const Cvc5BitWidth& w)
26
{
27
270736
  return wrappedBitVector<isSigned>(w, 1);
28
}
29
30
template <bool isSigned>
31
147369
wrappedBitVector<isSigned> wrappedBitVector<isSigned>::zero(
32
    const Cvc5BitWidth& w)
33
{
34
147369
  return wrappedBitVector<isSigned>(w, 0);
35
}
36
37
template <bool isSigned>
38
18082
wrappedBitVector<isSigned> wrappedBitVector<isSigned>::allOnes(
39
    const Cvc5BitWidth& w)
40
{
41
18082
  return ~wrappedBitVector<isSigned>::zero(w);
42
}
43
44
template <bool isSigned>
45
10442
Cvc5Prop wrappedBitVector<isSigned>::isAllOnes() const
46
{
47
10442
  return (*this == wrappedBitVector<isSigned>::allOnes(getWidth()));
48
}
49
template <bool isSigned>
50
47826
Cvc5Prop wrappedBitVector<isSigned>::isAllZeros() const
51
{
52
47826
  return (*this == wrappedBitVector<isSigned>::zero(getWidth()));
53
}
54
55
template <bool isSigned>
56
30
wrappedBitVector<isSigned> wrappedBitVector<isSigned>::maxValue(
57
    const Cvc5BitWidth& w)
58
{
59
  if (isSigned)
60
  {
61
60
    BitVector base(w - 1, 0U);
62
30
    return wrappedBitVector<true>((~base).zeroExtend(1));
63
  }
64
  else
65
  {
66
    return wrappedBitVector<false>::allOnes(w);
67
  }
68
}
69
70
template <bool isSigned>
71
15
wrappedBitVector<isSigned> wrappedBitVector<isSigned>::minValue(
72
    const Cvc5BitWidth& w)
73
{
74
  if (isSigned)
75
  {
76
30
    BitVector base(w, 1U);
77
30
    BitVector shiftAmount(w, w - 1);
78
30
    BitVector result(base.leftShift(shiftAmount));
79
15
    return wrappedBitVector<true>(result);
80
  }
81
  else
82
  {
83
    return wrappedBitVector<false>::zero(w);
84
  }
85
}
86
87
/*** Operators ***/
88
template <bool isSigned>
89
204966
wrappedBitVector<isSigned> wrappedBitVector<isSigned>::operator<<(
90
    const wrappedBitVector<isSigned>& op) const
91
{
92
204966
  return BitVector::leftShift(op);
93
}
94
95
template <>
96
wrappedBitVector<true> wrappedBitVector<true>::operator>>(
97
    const wrappedBitVector<true>& op) const
98
{
99
  return BitVector::arithRightShift(op);
100
}
101
102
template <>
103
4424
wrappedBitVector<false> wrappedBitVector<false>::operator>>(
104
    const wrappedBitVector<false>& op) const
105
{
106
4424
  return BitVector::logicalRightShift(op);
107
}
108
109
template <bool isSigned>
110
4389
wrappedBitVector<isSigned> wrappedBitVector<isSigned>::operator|(
111
    const wrappedBitVector<isSigned>& op) const
112
{
113
4389
  return BitVector::operator|(op);
114
}
115
116
template <bool isSigned>
117
43304
wrappedBitVector<isSigned> wrappedBitVector<isSigned>::operator&(
118
    const wrappedBitVector<isSigned>& op) const
119
{
120
43304
  return BitVector::operator&(op);
121
}
122
123
template <bool isSigned>
124
10826
wrappedBitVector<isSigned> wrappedBitVector<isSigned>::operator+(
125
    const wrappedBitVector<isSigned>& op) const
126
{
127
10826
  return BitVector::operator+(op);
128
}
129
130
template <bool isSigned>
131
254213
wrappedBitVector<isSigned> wrappedBitVector<isSigned>::operator-(
132
    const wrappedBitVector<isSigned>& op) const
133
{
134
254213
  return BitVector::operator-(op);
135
}
136
137
template <bool isSigned>
138
502
wrappedBitVector<isSigned> wrappedBitVector<isSigned>::operator*(
139
    const wrappedBitVector<isSigned>& op) const
140
{
141
502
  return BitVector::operator*(op);
142
}
143
144
template <>
145
196
wrappedBitVector<false> wrappedBitVector<false>::operator/(
146
    const wrappedBitVector<false>& op) const
147
{
148
196
  return BitVector::unsignedDivTotal(op);
149
}
150
151
template <>
152
196
wrappedBitVector<false> wrappedBitVector<false>::operator%(
153
    const wrappedBitVector<false>& op) const
154
{
155
196
  return BitVector::unsignedRemTotal(op);
156
}
157
158
template <bool isSigned>
159
106032
wrappedBitVector<isSigned> wrappedBitVector<isSigned>::operator-(void) const
160
{
161
106032
  return BitVector::operator-();
162
}
163
164
template <bool isSigned>
165
21692
wrappedBitVector<isSigned> wrappedBitVector<isSigned>::operator~(void) const
166
{
167
21692
  return BitVector::operator~();
168
}
169
170
template <bool isSigned>
171
35
wrappedBitVector<isSigned> wrappedBitVector<isSigned>::increment() const
172
{
173
35
  return *this + wrappedBitVector<isSigned>::one(getWidth());
174
}
175
176
template <bool isSigned>
177
21051
wrappedBitVector<isSigned> wrappedBitVector<isSigned>::decrement() const
178
{
179
21051
  return *this - wrappedBitVector<isSigned>::one(getWidth());
180
}
181
182
template <bool isSigned>
183
1609
wrappedBitVector<isSigned> wrappedBitVector<isSigned>::signExtendRightShift(
184
    const wrappedBitVector<isSigned>& op) const
185
{
186
1609
  return BitVector::arithRightShift(BitVector(getWidth(), op));
187
}
188
189
/*** Modular opertaions ***/
190
// No overflow checking so these are the same as other operations
191
template <bool isSigned>
192
24799
wrappedBitVector<isSigned> wrappedBitVector<isSigned>::modularLeftShift(
193
    const wrappedBitVector<isSigned>& op) const
194
{
195
24799
  return *this << op;
196
}
197
198
template <bool isSigned>
199
581
wrappedBitVector<isSigned> wrappedBitVector<isSigned>::modularRightShift(
200
    const wrappedBitVector<isSigned>& op) const
201
{
202
581
  return *this >> op;
203
}
204
205
template <bool isSigned>
206
wrappedBitVector<isSigned> wrappedBitVector<isSigned>::modularIncrement() const
207
{
208
  return increment();
209
}
210
211
template <bool isSigned>
212
19020
wrappedBitVector<isSigned> wrappedBitVector<isSigned>::modularDecrement() const
213
{
214
19020
  return decrement();
215
}
216
217
template <bool isSigned>
218
5192
wrappedBitVector<isSigned> wrappedBitVector<isSigned>::modularAdd(
219
    const wrappedBitVector<isSigned>& op) const
220
{
221
5192
  return *this + op;
222
}
223
224
template <bool isSigned>
225
5050
wrappedBitVector<isSigned> wrappedBitVector<isSigned>::modularNegate() const
226
{
227
5050
  return -(*this);
228
}
229
230
/*** Comparisons ***/
231
232
template <bool isSigned>
233
100835
Cvc5Prop wrappedBitVector<isSigned>::operator==(
234
    const wrappedBitVector<isSigned>& op) const
235
{
236
100835
  return BitVector::operator==(op);
237
}
238
239
template <>
240
149261
Cvc5Prop wrappedBitVector<true>::operator<=(
241
    const wrappedBitVector<true>& op) const
242
{
243
149261
  return signedLessThanEq(op);
244
}
245
246
template <>
247
1033
Cvc5Prop wrappedBitVector<true>::operator>=(
248
    const wrappedBitVector<true>& op) const
249
{
250
1033
  return !(signedLessThan(op));
251
}
252
253
template <>
254
5359
Cvc5Prop wrappedBitVector<true>::operator<(
255
    const wrappedBitVector<true>& op) const
256
{
257
5359
  return signedLessThan(op);
258
}
259
260
template <>
261
5483
Cvc5Prop wrappedBitVector<true>::operator>(
262
    const wrappedBitVector<true>& op) const
263
{
264
5483
  return !(signedLessThanEq(op));
265
}
266
267
template <>
268
416
Cvc5Prop wrappedBitVector<false>::operator<=(
269
    const wrappedBitVector<false>& op) const
270
{
271
416
  return unsignedLessThanEq(op);
272
}
273
274
template <>
275
5123
Cvc5Prop wrappedBitVector<false>::operator>=(
276
    const wrappedBitVector<false>& op) const
277
{
278
5123
  return !(unsignedLessThan(op));
279
}
280
281
template <>
282
1063
Cvc5Prop wrappedBitVector<false>::operator<(
283
    const wrappedBitVector<false>& op) const
284
{
285
1063
  return unsignedLessThan(op);
286
}
287
288
template <>
289
16
Cvc5Prop wrappedBitVector<false>::operator>(
290
    const wrappedBitVector<false>& op) const
291
{
292
16
  return !(unsignedLessThanEq(op));
293
}
294
295
/*** Type conversion ***/
296
297
// Node makes no distinction between signed and unsigned, thus ...
298
template <bool isSigned>
299
1247
wrappedBitVector<true> wrappedBitVector<isSigned>::toSigned(void) const
300
{
301
1247
  return wrappedBitVector<true>(*this);
302
}
303
304
template <bool isSigned>
305
25258
wrappedBitVector<false> wrappedBitVector<isSigned>::toUnsigned(void) const
306
{
307
25258
  return wrappedBitVector<false>(*this);
308
}
309
310
/*** Bit hacks ***/
311
312
template <bool isSigned>
313
65324
wrappedBitVector<isSigned> wrappedBitVector<isSigned>::extend(
314
    Cvc5BitWidth extension) const
315
{
316
  if (isSigned)
317
  {
318
16113
    return BitVector::signExtend(extension);
319
  }
320
  else
321
  {
322
49211
    return BitVector::zeroExtend(extension);
323
  }
324
}
325
326
template <bool isSigned>
327
1579
wrappedBitVector<isSigned> wrappedBitVector<isSigned>::contract(
328
    Cvc5BitWidth reduction) const
329
{
330
1579
  Assert(getWidth() > reduction);
331
332
1579
  return extract((getWidth() - 1) - reduction, 0);
333
}
334
335
template <bool isSigned>
336
20578
wrappedBitVector<isSigned> wrappedBitVector<isSigned>::resize(
337
    Cvc5BitWidth newSize) const
338
{
339
20578
  Cvc5BitWidth width = getWidth();
340
341
20578
  if (newSize > width)
342
  {
343
20578
    return extend(newSize - width);
344
  }
345
  else if (newSize < width)
346
  {
347
    return contract(width - newSize);
348
  }
349
  else
350
  {
351
    return *this;
352
  }
353
}
354
355
template <bool isSigned>
356
27194
wrappedBitVector<isSigned> wrappedBitVector<isSigned>::matchWidth(
357
    const wrappedBitVector<isSigned>& op) const
358
{
359
27194
  Assert(getWidth() <= op.getWidth());
360
27194
  return extend(op.getWidth() - getWidth());
361
}
362
363
template <bool isSigned>
364
15215
wrappedBitVector<isSigned> wrappedBitVector<isSigned>::append(
365
    const wrappedBitVector<isSigned>& op) const
366
{
367
15215
  return BitVector::concat(op);
368
}
369
370
// Inclusive of end points, thus if the same, extracts just one bit
371
template <bool isSigned>
372
47581
wrappedBitVector<isSigned> wrappedBitVector<isSigned>::extract(
373
    Cvc5BitWidth upper, Cvc5BitWidth lower) const
374
{
375
47581
  Assert(upper >= lower);
376
47581
  return BitVector::extract(upper, lower);
377
}
378
379
// Explicit instantiation
380
template class wrappedBitVector<true>;
381
template class wrappedBitVector<false>;
382
383
3247
traits::rm traits::RNE(void)
384
{
385
3247
  return RoundingMode::ROUND_NEAREST_TIES_TO_EVEN;
386
};
387
1854
traits::rm traits::RNA(void)
388
{
389
1854
  return RoundingMode::ROUND_NEAREST_TIES_TO_AWAY;
390
};
391
1692
traits::rm traits::RTP(void) { return RoundingMode::ROUND_TOWARD_POSITIVE; };
392
2779
traits::rm traits::RTN(void) { return RoundingMode::ROUND_TOWARD_NEGATIVE; };
393
1432
traits::rm traits::RTZ(void) { return RoundingMode::ROUND_TOWARD_ZERO; };
394
// This is a literal back-end so props are actually bools
395
// so these can be handled in the same way as the internal assertions above
396
397
54812
void traits::precondition(const traits::prop& p)
398
{
399
54812
  Assert(p);
400
54812
  return;
401
}
402
10925
void traits::postcondition(const traits::prop& p)
403
{
404
10925
  Assert(p);
405
10925
  return;
406
}
407
52553
void traits::invariant(const traits::prop& p)
408
{
409
52553
  Assert(p);
410
52553
  return;
411
}
412
}  // namespace symfpuLiteral
413
22746
}  // namespace cvc5