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.
38 using namespace insttest
;
41 expect
<int64_t>(39285, []{return M::mul(873, 45);}, "mul");
42 expect
<int64_t>(0, []{return M::mul(0x4000000000000000LL
, 4);},
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);},
49 expect
<int64_t>(0, []{return M::mulh(-1, -1);}, "mulh, all bits set");
52 expect
<int64_t>(-1, []{return M::mulhsu(-1, -1);}, "mulhsu, all bits set");
54 []{return M::mulhsu(numeric_limits
<int64_t>::min(), 2);},\
58 expect
<uint64_t>(1, []{return M::mulhu(0x8000000000000000ULL
, 2);},
60 expect
<uint64_t>(0xFFFFFFFFFFFFFFFEULL
, []{return M::mulhu(-1, -1);},
61 "mulhu, all bits set");
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);},
71 expect
<uint64_t>(2305843009213693944LL, []{return M::divu(-59, 8);},
73 expect
<uint64_t>(numeric_limits
<uint64_t>::max(),
74 []{return M::divu(255, 0);}, "divu/0");
76 []{return M::divu(numeric_limits
<uint64_t>::min(), -1);},
77 "divu, \"overflow\"");
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);},
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\"");
94 []{return M::mulw(0x7FFFFFFF00000005LL
, 0x80000000FFFFFFECLL
);},
96 expect
<int64_t>(0, []{return M::mulw(0x40000000, 4);}, "mulw, overflow");
100 []{return M::divw(0x7FFFFFFFFFFFFFC5LL
, 0xFFFFFFFF00000008LL
);},
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);},
108 expect
<int64_t>(536870904,
109 []{return M::divuw(0x7FFFFFFFFFFFFFC5LL
, 0xFFFFFFFF00000008LL
);},
111 expect
<int64_t>(numeric_limits
<uint64_t>::max(),
112 []{return M::divuw(65535, 0);}, "divuw/0");
114 []{return M::divuw(numeric_limits
<int32_t>::min(), -1);},
115 "divuw, \"overflow\"");
117 []{return M::divuw(numeric_limits
<uint32_t>::max(), 1);},
118 "divuw, sign extend");
122 []{return M::remw(0x7FFFFFFFFFFFFFC5LL
, 0xFFFFFFFF00000008LL
);},
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);},
130 []{return M::remuw(0x7FFFFFFFFFFFFFC5LL
, 0xFFFFFFFF00000008LL
);},
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");