836d771a1674972ba75e4ade6656a03e32c03054
2 * Copyright (c) 2016 The University of Virginia
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.
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.
28 * Authors: Alec Roelke
40 using namespace insttest
;
43 expect
<int64_t>(39285, []{return M::mul(873, 45);}, "mul");
44 expect
<int64_t>(0, []{return M::mul(0x4000000000000000LL
, 4);},
48 expect
<int64_t>(1, []{return M::mulh(0x4000000000000000LL
, 4);}, "mulh");
49 expect
<int64_t>(-1, []{return M::mulh(numeric_limits
<int64_t>::min(), 2);},
51 expect
<int64_t>(0, []{return M::mulh(-1, -1);}, "mulh, all bits set");
54 expect
<int64_t>(-1, []{return M::mulhsu(-1, -1);}, "mulhsu, all bits set");
56 []{return M::mulhsu(numeric_limits
<int64_t>::min(), 2);},\
60 expect
<uint64_t>(1, []{return M::mulhu(0x8000000000000000ULL
, 2);},
62 expect
<uint64_t>(0xFFFFFFFFFFFFFFFEULL
, []{return M::mulhu(-1, -1);},
63 "mulhu, all bits set");
66 expect
<int64_t>(-7, []{return M::div(-59, 8);}, "div");
67 expect
<int64_t>(-1, []{return M::div(255, 0);}, "div/0");
68 expect
<int64_t>(numeric_limits
<int64_t>::min(),
69 []{return M::div(numeric_limits
<int64_t>::min(), -1);},
73 expect
<uint64_t>(2305843009213693944LL, []{return M::divu(-59, 8);},
75 expect
<uint64_t>(numeric_limits
<uint64_t>::max(),
76 []{return M::divu(255, 0);}, "divu/0");
78 []{return M::divu(numeric_limits
<uint64_t>::min(), -1);},
79 "divu, \"overflow\"");
82 expect
<int64_t>(-3, []{return M::rem(-59, 8);}, "rem");
83 expect
<int64_t>(255, []{return M::rem(255, 0);}, "rem/0");
84 expect
<int64_t>(0, []{return M::rem(numeric_limits
<int64_t>::min(), -1);},
88 expect
<uint64_t>(5, []{return M::remu(-59, 8);}, "remu");
89 expect
<uint64_t>(255, []{return M::remu(255, 0);}, "remu/0");
90 expect
<uint64_t>(0x8000000000000000ULL
,
91 []{return M::remu(0x8000000000000000ULL
, -1);},
92 "remu, \"overflow\"");
96 []{return M::mulw(0x7FFFFFFF00000005LL
, 0x80000000FFFFFFECLL
);},
98 expect
<int64_t>(0, []{return M::mulw(0x40000000, 4);}, "mulw, overflow");
102 []{return M::divw(0x7FFFFFFFFFFFFFC5LL
, 0xFFFFFFFF00000008LL
);},
104 expect
<int64_t>(-1, []{return M::divw(65535, 0);}, "divw/0");
105 expect
<int64_t>(numeric_limits
<int32_t>::min(),
106 []{return M::divw(numeric_limits
<int32_t>::min(), -1);},
110 expect
<int64_t>(536870904,
111 []{return M::divuw(0x7FFFFFFFFFFFFFC5LL
, 0xFFFFFFFF00000008LL
);},
113 expect
<int64_t>(numeric_limits
<uint64_t>::max(),
114 []{return M::divuw(65535, 0);}, "divuw/0");
116 []{return M::divuw(numeric_limits
<int32_t>::min(), -1);},
117 "divuw, \"overflow\"");
119 []{return M::divuw(numeric_limits
<uint32_t>::max(), 1);},
120 "divuw, sign extend");
124 []{return M::remw(0x7FFFFFFFFFFFFFC5LL
, 0xFFFFFFFF00000008LL
);},
126 expect
<int64_t>(65535, []{return M::remw(65535, 0);}, "remw/0");
127 expect
<int64_t>(0, []{return M::remw(numeric_limits
<int32_t>::min(), -1);},
132 []{return M::remuw(0x7FFFFFFFFFFFFFC5LL
, 0xFFFFFFFF00000008LL
);},
134 expect
<int64_t>(65535, []{return M::remuw(65535, 0);}, "remuw/0");
135 expect
<int64_t>(numeric_limits
<int32_t>::min(),
136 []{return M::remuw(numeric_limits
<int32_t>::min(), -1);},
137 "remuw, \"overflow\"");
138 expect
<int64_t>(0xFFFFFFFF80000000,
139 []{return M::remuw(0x80000000, 0xFFFFFFFF);},
140 "remuw, sign extend");