• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

stillwater-sc / universal / 30667833245

31 Jul 2026 09:29PM UTC coverage: 85.249%. Remained the same
30667833245

Pull #1285

github

web-flow
Merge 5f3ba16ab into 228a57c15
Pull Request #1285: fix(internal): clear -Wsign-conversion in blockbinary + blocksignificand (#1280)

23 of 26 new or added lines in 3 files covered. (88.46%)

20 existing lines in 3 files now uncovered.

41698 of 48913 relevant lines covered (85.25%)

7267551.6 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

79.41
/internal/blockbinary/logic/shift_left.cpp
1
// shift_left.cpp: functional tests for block binary number shifts
2
//
3
// Copyright (C) 2017 Stillwater Supercomputing, Inc.
4
// SPDX-License-Identifier: MIT
5
//
6
// This file is part of the universal numbers project, which is released under an MIT Open Source license.
7
#include <universal/utility/directives.hpp>
8
#include <universal/utility/long_double.hpp>
9
#include <iostream>
10
#include <iomanip>
11

12
#include <universal/internal/blockbinary/blockbinary.hpp>
13
#include <universal/verification/test_status.hpp>
14
#include <universal/verification/test_reporters.hpp>
15
#include <universal/verification/blockbinary_test_status.hpp>
16

17
// enumerate all shift left cases for an blockbinary<nbits,BlockType> configuration
18
template<size_t nbits, typename BlockType = uint8_t>
19
int VerifyLeftShift(bool reportTestCases) {
30✔
20
        using namespace sw::universal;
21
        using BlockBinary = blockbinary<nbits, BlockType>;
22

23
        if (reportTestCases) std::cout << type_tag(BlockBinary()) << '\n';
30✔
24

25
        // take 1 and shift it left in all possible strides
26
        int nrOfFailedTests = 0;
30✔
27
        BlockBinary a, result;
28
        int64_t shiftRef, resultRef;
29
        for (size_t i = 0; i < nbits + 1; i++) {
782✔
30
                if (i >= 64) {
752✔
31
                        shiftRef = 0; // shift all bits out
2✔
32
                }
33
                else {
34
                        shiftRef = static_cast<int64_t>(0xFFFF'FFFF'FFFF'FFFFull << i);
750✔
35
                }
36
                if (i == nbits) shiftRef = 0; // shift all bits out
752✔
37

38
                a = -1;
752✔
39
                result = a << long(i);
752✔
40
                resultRef = (long long)result;
752✔
41

42
                if (shiftRef != resultRef) {
752✔
43
                        nrOfFailedTests++;
×
44
                        if (reportTestCases) ReportArithmeticShiftError("FAIL", "<<", a, i, result, resultRef);
×
45
                }
46
                else {
47
                        if (reportTestCases) ReportArithmeticShiftSuccess("PASS", "<<", a, i, result, resultRef);
752✔
48
                }
49
                if (nrOfFailedTests > 100) return nrOfFailedTests;
752✔
50
        }
51
        return nrOfFailedTests;
30✔
52
}
53

54

55
// Regression testing guards: typically set by the cmake configuration, but MANUAL_TESTING is an override
56
#define MANUAL_TESTING 0
57
// REGRESSION_LEVEL_OVERRIDE is set by the cmake file to drive a specific regression intensity
58
// It is the responsibility of the regression test to organize the tests in a quartile progression.
59
#undef REGRESSION_LEVEL_OVERRIDE
60
#ifndef REGRESSION_LEVEL_OVERRIDE
61
#undef REGRESSION_LEVEL_1
62
#undef REGRESSION_LEVEL_2
63
#undef REGRESSION_LEVEL_3
64
#undef REGRESSION_LEVEL_4
65
#define REGRESSION_LEVEL_1 1
66
#define REGRESSION_LEVEL_2 1
67
#define REGRESSION_LEVEL_3 1
68
#define REGRESSION_LEVEL_4 1
69
#endif
70

71
int main()
1✔
72
try {
73
        using namespace sw::universal;
74
        
75
        std::string test_suite  = "blockbinary logic left shifting";
2✔
76
        std::string test_tag    = "arithmetic/logic left shift";
1✔
77
        bool reportTestCases    = false;
1✔
78
        int nrOfFailedTestCases = 0;
1✔
79

80
        std::cout << test_suite << '\n';
1✔
81

82
#if MANUAL_TESTING
83

84
        nrOfFailedTestCases += ReportTestResult(VerifyLeftShift<12>(true), "blockbinary<12>", test_tag);
85

86
        {
87
                blockbinary<12> a;
88
                a.setbits(0x800);
89
                std::cout << to_hex(a) << ' ';
90
                a <<= 8;
91
                std::cout << to_hex(a) << '\n';
92
        }
93
        {
94
                blockbinary<8> a;
95
                for (int i = 0; i < 16; ++i) {
96
                        a.setbits(0x80);
97
                        a <<= i;
98
                        std::cout << to_binary(a, true) << ' ' << (long long)(a) << "  right shift by " << i << '\n';
99
                }
100
        }
101

102
        ReportTestSuiteResults(test_suite, nrOfFailedTestCases);
103
        return EXIT_SUCCESS; // ignore failures
104
#else
105

106
#if REGRESSION_LEVEL_1
107
        nrOfFailedTestCases += ReportTestResult(VerifyLeftShift<2>(reportTestCases), "blockbinary<2>", test_tag);
2✔
108
        nrOfFailedTestCases += ReportTestResult(VerifyLeftShift<3>(reportTestCases), "blockbinary<3>", test_tag);
2✔
109
        nrOfFailedTestCases += ReportTestResult(VerifyLeftShift<4>(reportTestCases), "blockbinary<4>", test_tag);
2✔
110
        nrOfFailedTestCases += ReportTestResult(VerifyLeftShift<5>(reportTestCases), "blockbinary<5>", test_tag);
2✔
111
        nrOfFailedTestCases += ReportTestResult(VerifyLeftShift<6>(reportTestCases), "blockbinary<6>", test_tag);
2✔
112
        nrOfFailedTestCases += ReportTestResult(VerifyLeftShift<7>(reportTestCases), "blockbinary<7>", test_tag);
2✔
113
        nrOfFailedTestCases += ReportTestResult(VerifyLeftShift<8>(reportTestCases), "blockbinary<8>", test_tag);
2✔
114
        nrOfFailedTestCases += ReportTestResult(VerifyLeftShift<9>(reportTestCases), "blockbinary<9>", test_tag);
2✔
115
        nrOfFailedTestCases += ReportTestResult(VerifyLeftShift<10>(reportTestCases), "blockbinary<10>", test_tag);
2✔
116
        nrOfFailedTestCases += ReportTestResult(VerifyLeftShift<11>(reportTestCases), "blockbinary<11>", test_tag);
2✔
117
        nrOfFailedTestCases += ReportTestResult(VerifyLeftShift<12>(reportTestCases), "blockbinary<12>", test_tag);
2✔
118
        nrOfFailedTestCases += ReportTestResult(VerifyLeftShift<13>(reportTestCases), "blockbinary<13>", test_tag);
2✔
119
        nrOfFailedTestCases += ReportTestResult(VerifyLeftShift<14>(reportTestCases), "blockbinary<14>", test_tag);
2✔
120
        nrOfFailedTestCases += ReportTestResult(VerifyLeftShift<15>(reportTestCases), "blockbinary<15>", test_tag);
2✔
121
        nrOfFailedTestCases += ReportTestResult(VerifyLeftShift<16>(reportTestCases), "blockbinary<16>", test_tag);
2✔
122
        nrOfFailedTestCases += ReportTestResult(VerifyLeftShift<17>(reportTestCases), "blockbinary<17>", test_tag);
2✔
123

124
#endif
125

126
#if REGRESSION_LEVEL_2
127
        nrOfFailedTestCases += ReportTestResult(VerifyLeftShift<18>(reportTestCases), "blockbinary<18>", test_tag);
2✔
128
        nrOfFailedTestCases += ReportTestResult(VerifyLeftShift<20>(reportTestCases), "blockbinary<20>", test_tag);
2✔
129
        nrOfFailedTestCases += ReportTestResult(VerifyLeftShift<24>(reportTestCases), "blockbinary<24>", test_tag);
2✔
130
        nrOfFailedTestCases += ReportTestResult(VerifyLeftShift<28>(reportTestCases), "blockbinary<28>", test_tag);
2✔
131
        nrOfFailedTestCases += ReportTestResult(VerifyLeftShift<32>(reportTestCases), "blockbinary<32>", test_tag);
2✔
132
        nrOfFailedTestCases += ReportTestResult(VerifyLeftShift<40>(reportTestCases), "blockbinary<40>", test_tag);
2✔
133
        nrOfFailedTestCases += ReportTestResult(VerifyLeftShift<48>(reportTestCases), "blockbinary<48>", test_tag);
2✔
134
        nrOfFailedTestCases += ReportTestResult(VerifyLeftShift<56>(reportTestCases), "blockbinary<56>", test_tag);
2✔
135
        nrOfFailedTestCases += ReportTestResult(VerifyLeftShift<64>(reportTestCases), "blockbinary<64>", test_tag);
2✔
136
#endif
137

138
#if REGRESSION_LEVEL_3
139
        // using a more efficient storage class
140
        nrOfFailedTestCases += ReportTestResult(VerifyLeftShift<32,uint32_t>(reportTestCases), "blockbinary<32,uint32_t>", test_tag);
2✔
141
        nrOfFailedTestCases += ReportTestResult(VerifyLeftShift<40,uint32_t>(reportTestCases), "blockbinary<40,uint32_t>", test_tag);
2✔
142
        nrOfFailedTestCases += ReportTestResult(VerifyLeftShift<48, uint32_t>(reportTestCases), "blockbinary<48,uint32_t>", test_tag);
2✔
143
        nrOfFailedTestCases += ReportTestResult(VerifyLeftShift<56, uint32_t>(reportTestCases), "blockbinary<56,uint32_t>", test_tag);
2✔
144
        nrOfFailedTestCases += ReportTestResult(VerifyLeftShift<64, uint32_t>(reportTestCases), "blockbinary<64,uint32_t>", test_tag);
1✔
145
#endif
146

147
#if        REGRESSION_LEVEL_4        
148
        // can't test this with VerifyLeftShift since we don't have a >64bit native integer type
149
        //nrOfFailedTestCases += ReportTestResult(VerifyLeftShift<128, uint32_t>(reportTestCases), "blockbinary<128,uint32_t>", test_tag);
150
        //nrOfFailedTestCases += ReportTestResult(VerifyLeftShift<256, uint32_t>(reportTestCases), "blockbinary<256,uint32_t>", test_tag);
151

152
#endif
153

154
        ReportTestSuiteResults(test_suite, nrOfFailedTestCases);
1✔
155
        return (nrOfFailedTestCases > 0 ? EXIT_FAILURE : EXIT_SUCCESS);
1✔
156
#endif  // MANUAL_TESTING
157
}
1✔
UNCOV
158
catch (char const* msg) {
×
UNCOV
159
        std::cerr << msg << std::endl;
×
NEW
160
        return EXIT_FAILURE;
×
NEW
161
}
×
NEW
162
catch (const std::runtime_error& err) {
×
UNCOV
163
        std::cerr << "Uncaught runtime exception: " << err.what() << std::endl;
×
UNCOV
164
        return EXIT_FAILURE;
×
UNCOV
165
}
×
UNCOV
166
catch (...) {
×
UNCOV
167
        std::cerr << "Caught unknown exception" << std::endl;
×
UNCOV
168
        return EXIT_FAILURE;
×
UNCOV
169
}
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc