tests: Delete authors lists from test files.
[gem5.git] / tests / test-progs / insttest / src / riscv / rv64m.cpp
1 /*
2 * Copyright (c) 2016 The University of Virginia
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29 #include <cstdint>
30 #include <limits>
31
32 #include "insttest.h"
33 #include "rv64m.h"
34
35 int main()
36 {
37 using namespace std;
38 using namespace insttest;
39
40 // MUL
41 expect<int64_t>(39285, []{return M::mul(873, 45);}, "mul");
42 expect<int64_t>(0, []{return M::mul(0x4000000000000000LL, 4);},
43 "mul, overflow");
44
45 // MULH
46 expect<int64_t>(1, []{return M::mulh(0x4000000000000000LL, 4);}, "mulh");
47 expect<int64_t>(-1, []{return M::mulh(numeric_limits<int64_t>::min(), 2);},
48 "mulh, negative");
49 expect<int64_t>(0, []{return M::mulh(-1, -1);}, "mulh, all bits set");
50
51 // MULHSU
52 expect<int64_t>(-1, []{return M::mulhsu(-1, -1);}, "mulhsu, all bits set");
53 expect<int64_t>(-1,
54 []{return M::mulhsu(numeric_limits<int64_t>::min(), 2);},\
55 "mulhsu");
56
57 // MULHU
58 expect<uint64_t>(1, []{return M::mulhu(0x8000000000000000ULL, 2);},
59 "mulhu");
60 expect<uint64_t>(0xFFFFFFFFFFFFFFFEULL, []{return M::mulhu(-1, -1);},
61 "mulhu, all bits set");
62
63 // DIV
64 expect<int64_t>(-7, []{return M::div(-59, 8);}, "div");
65 expect<int64_t>(-1, []{return M::div(255, 0);}, "div/0");
66 expect<int64_t>(numeric_limits<int64_t>::min(),
67 []{return M::div(numeric_limits<int64_t>::min(), -1);},
68 "div, overflow");
69
70 // DIVU
71 expect<uint64_t>(2305843009213693944LL, []{return M::divu(-59, 8);},
72 "divu");
73 expect<uint64_t>(numeric_limits<uint64_t>::max(),
74 []{return M::divu(255, 0);}, "divu/0");
75 expect<uint64_t>(0,
76 []{return M::divu(numeric_limits<uint64_t>::min(), -1);},
77 "divu, \"overflow\"");
78
79 // REM
80 expect<int64_t>(-3, []{return M::rem(-59, 8);}, "rem");
81 expect<int64_t>(255, []{return M::rem(255, 0);}, "rem/0");
82 expect<int64_t>(0, []{return M::rem(numeric_limits<int64_t>::min(), -1);},
83 "rem, overflow");
84
85 // REMU
86 expect<uint64_t>(5, []{return M::remu(-59, 8);}, "remu");
87 expect<uint64_t>(255, []{return M::remu(255, 0);}, "remu/0");
88 expect<uint64_t>(0x8000000000000000ULL,
89 []{return M::remu(0x8000000000000000ULL, -1);},
90 "remu, \"overflow\"");
91
92 // MULW
93 expect<int64_t>(-100,
94 []{return M::mulw(0x7FFFFFFF00000005LL, 0x80000000FFFFFFECLL);},
95 "mulw, truncate");
96 expect<int64_t>(0, []{return M::mulw(0x40000000, 4);}, "mulw, overflow");
97
98 // DIVW
99 expect<int64_t>(-7,
100 []{return M::divw(0x7FFFFFFFFFFFFFC5LL, 0xFFFFFFFF00000008LL);},
101 "divw, truncate");
102 expect<int64_t>(-1, []{return M::divw(65535, 0);}, "divw/0");
103 expect<int64_t>(numeric_limits<int32_t>::min(),
104 []{return M::divw(numeric_limits<int32_t>::min(), -1);},
105 "divw, overflow");
106
107 // DIVUW
108 expect<int64_t>(536870904,
109 []{return M::divuw(0x7FFFFFFFFFFFFFC5LL, 0xFFFFFFFF00000008LL);},
110 "divuw, truncate");
111 expect<int64_t>(numeric_limits<uint64_t>::max(),
112 []{return M::divuw(65535, 0);}, "divuw/0");
113 expect<int64_t>(0,
114 []{return M::divuw(numeric_limits<int32_t>::min(), -1);},
115 "divuw, \"overflow\"");
116 expect<int64_t>(-1,
117 []{return M::divuw(numeric_limits<uint32_t>::max(), 1);},
118 "divuw, sign extend");
119
120 // REMW
121 expect<int64_t>(-3,
122 []{return M::remw(0x7FFFFFFFFFFFFFC5LL, 0xFFFFFFFF00000008LL);},
123 "remw, truncate");
124 expect<int64_t>(65535, []{return M::remw(65535, 0);}, "remw/0");
125 expect<int64_t>(0, []{return M::remw(numeric_limits<int32_t>::min(), -1);},
126 "remw, overflow");
127
128 // REMUW
129 expect<int64_t>(5,
130 []{return M::remuw(0x7FFFFFFFFFFFFFC5LL, 0xFFFFFFFF00000008LL);},
131 "remuw, truncate");
132 expect<int64_t>(65535, []{return M::remuw(65535, 0);}, "remuw/0");
133 expect<int64_t>(numeric_limits<int32_t>::min(),
134 []{return M::remuw(numeric_limits<int32_t>::min(), -1);},
135 "remuw, \"overflow\"");
136 expect<int64_t>(0xFFFFFFFF80000000,
137 []{return M::remuw(0x80000000, 0xFFFFFFFF);},
138 "remuw, sign extend");
139
140 return 0;
141 }