1 /* Tests the divide instructions.
3 Copyright (C) 2017-2018 Free Software Foundation, Inc.
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
19 # output: report(0x0000000c);\n
20 # output: report(0x00000003);\n
21 # output: report(0x00000004);\n
22 # output: report(0x00000000);\n
23 # output: report(0x00000000);\n
24 # output: report(0x00000000);\n
26 # output: report(0x0000000b);\n
27 # output: report(0x00000003);\n
28 # output: report(0x00000003);\n
29 # output: report(0x00000000);\n
30 # output: report(0x00000000);\n
31 # output: report(0x00000000);\n
33 # output: report(0xfffffff4);\n
34 # output: report(0xfffffffd);\n
35 # output: report(0x00000004);\n
36 # output: report(0x00000000);\n
37 # output: report(0x00000000);\n
38 # output: report(0x00000000);\n
40 # output: report(0xfffffff5);\n
41 # output: report(0xfffffffd);\n
42 # output: report(0x00000003);\n
43 # output: report(0x00000000);\n
44 # output: report(0x00000000);\n
45 # output: report(0x00000000);\n
47 # output: report(0xfffffff4);\n
48 # output: report(0x00000003);\n
49 # output: report(0xfffffffc);\n
50 # output: report(0x00000000);\n
51 # output: report(0x00000000);\n
52 # output: report(0x00000000);\n
54 # output: report(0xfffffff5);\n
55 # output: report(0x00000003);\n
56 # output: report(0xfffffffd);\n
57 # output: report(0x00000000);\n
58 # output: report(0x00000000);\n
59 # output: report(0x00000000);\n
61 # output: report(0x0000000c);\n
62 # output: report(0xfffffffd);\n
63 # output: report(0xfffffffc);\n
64 # output: report(0x00000000);\n
65 # output: report(0x00000000);\n
66 # output: report(0x00000000);\n
68 # output: report(0x0000000b);\n
69 # output: report(0xfffffffd);\n
70 # output: report(0xfffffffd);\n
71 # output: report(0x00000000);\n
72 # output: report(0x00000000);\n
73 # output: report(0x00000000);\n
75 # output: report(0x0000000c);\n
76 # output: report(0x00000000);\n
77 # output: report(0xfffffffd);\n
78 # output: report(0x00000000);\n
79 # output: report(0x00000001);\n
80 # output: report(0x00000000);\n
82 # output: report(0xfffffff4);\n
83 # output: report(0x00000000);\n
84 # output: report(0xfffffffd);\n
85 # output: report(0x00000000);\n
86 # output: report(0x00000001);\n
87 # output: report(0x00000000);\n
89 # output: report(0x0000000c);\n
90 # output: report(0x00000000);\n
91 # output: report(0xfffffffd);\n
92 # output: report(0x00000000);\n
93 # output: report(0x00000001);\n
94 # output: report(0x00000001);\n
96 # output: report(0xfffffff4);\n
97 # output: report(0x00000000);\n
98 # output: report(0xfffffffd);\n
99 # output: report(0x00000000);\n
100 # output: report(0x00000001);\n
101 # output: report(0x00000001);\n
103 # output: report(0x0000000c);\n
104 # output: report(0x00000003);\n
105 # output: report(0x00000004);\n
106 # output: report(0x00000000);\n
107 # output: report(0x00000000);\n
108 # output: report(0x00000000);\n
110 # output: report(0x0000000b);\n
111 # output: report(0x00000003);\n
112 # output: report(0x00000003);\n
113 # output: report(0x00000000);\n
114 # output: report(0x00000000);\n
115 # output: report(0x00000000);\n
117 # output: report(0xfffffff4);\n
118 # output: report(0xfffffffd);\n
119 # output: report(0x00000000);\n
120 # output: report(0x00000000);\n
121 # output: report(0x00000000);\n
122 # output: report(0x00000000);\n
124 # output: report(0xfffffff5);\n
125 # output: report(0xfffffffd);\n
126 # output: report(0x00000000);\n
127 # output: report(0x00000000);\n
128 # output: report(0x00000000);\n
129 # output: report(0x00000000);\n
131 # output: report(0xfffffff4);\n
132 # output: report(0x00000003);\n
133 # output: report(0x55555551);\n
134 # output: report(0x00000000);\n
135 # output: report(0x00000000);\n
136 # output: report(0x00000000);\n
138 # output: report(0xfffffff5);\n
139 # output: report(0x00000003);\n
140 # output: report(0x55555551);\n
141 # output: report(0x00000000);\n
142 # output: report(0x00000000);\n
143 # output: report(0x00000000);\n
145 # output: report(0x0000000c);\n
146 # output: report(0xfffffffd);\n
147 # output: report(0x00000000);\n
148 # output: report(0x00000000);\n
149 # output: report(0x00000000);\n
150 # output: report(0x00000000);\n
152 # output: report(0x0000000b);\n
153 # output: report(0xfffffffd);\n
154 # output: report(0x00000000);\n
155 # output: report(0x00000000);\n
156 # output: report(0x00000000);\n
157 # output: report(0x00000000);\n
159 # output: report(0x0000000c);\n
160 # output: report(0x00000000);\n
161 # output: report(0x00000000);\n
162 # output: report(0x00000001);\n
163 # output: report(0x00000000);\n
164 # output: report(0x00000000);\n
166 # output: report(0xfffffff4);\n
167 # output: report(0x00000000);\n
168 # output: report(0x00000000);\n
169 # output: report(0x00000001);\n
170 # output: report(0x00000000);\n
171 # output: report(0x00000000);\n
173 # output: report(0x0000000c);\n
174 # output: report(0x00000000);\n
175 # output: report(0x00000000);\n
176 # output: report(0x00000001);\n
177 # output: report(0x00000000);\n
178 # output: report(0x00000001);\n
180 # output: report(0xfffffff4);\n
181 # output: report(0x00000000);\n
182 # output: report(0x00000000);\n
183 # output: report(0x00000001);\n
184 # output: report(0x00000000);\n
185 # output: report(0x00000001);\n
189 #include "or1k-asm-test-helpers.h"
191 STANDARD_TEST_ENVIRONMENT
193 .section .exception_vectors
195 /* Range exception. */
198 l.addi r1, r1, -EXCEPTION_STACK_SKIP_SIZE
201 /* Save the address of the instruction that caused the problem. */
202 MOVE_FROM_SPR r2, SPR_EPCR_BASE
203 LOAD_IMMEDIATE r3, 0x15000000 /* Opcode for l.nop */
207 l.addi r1, r1, EXCEPTION_STACK_SKIP_SIZE
212 PUSH LINK_REGISTER_R9
216 /* Divide two positive numbers and check rounding. Should set no
218 TEST_INST_I32_I32 l.div, 0x0000000c, 0x00000003 /* 12 / 3 = 4 */
219 TEST_INST_I32_I32 l.div, 0x0000000b, 0x00000003 /* 11 / 3 = 3 */
221 /* Divide two negative numbers and check rounding. Should set no
223 TEST_INST_I32_I32 l.div, 0xfffffff4, 0xfffffffd
224 TEST_INST_I32_I32 l.div, 0xfffffff5, 0xfffffffd
226 /* Divide a negative number by a positive number and check
227 rounding. Should set no flags. */
228 TEST_INST_I32_I32 l.div, 0xfffffff4, 0x00000003
229 TEST_INST_I32_I32 l.div, 0xfffffff5, 0x00000003
231 /* Divide a positive number by a negative number and check
232 rounding. Should set no flags. */
233 TEST_INST_I32_I32 l.div, 0x0000000c, 0xfffffffd
234 TEST_INST_I32_I32 l.div, 0x0000000b, 0xfffffffd
236 /* Divide by zero. This will set the overflow flag. */
237 TEST_INST_I32_I32 l.div, 0x0000000c, 0x00000000
238 TEST_INST_I32_I32 l.div, 0xfffffff4, 0x00000000
240 /* Check that range exceptions are triggered. */
242 SET_SPR_SR_FLAGS SPR_SR_OVE, r2, r3
244 /* Divide by zero. This will set the overflow flag and trigger an
246 TEST_INST_I32_I32 l.div, 0x0000000c, 0x00000000
247 TEST_INST_I32_I32 l.div, 0xfffffff4, 0x00000000
249 CLEAR_SPR_SR_FLAGS SPR_SR_OVE, r2, r3
253 /* Divide two positive numbers and check rounding. Should set no
255 TEST_INST_I32_I32 l.divu, 0x0000000c, 0x00000003
256 TEST_INST_I32_I32 l.divu, 0x0000000b, 0x00000003
258 /* Divide two numbers that would be negative under 2's complement
259 and check rounding. Should set no flags. */
260 TEST_INST_I32_I32 l.divu, 0xfffffff4, 0xfffffffd
261 TEST_INST_I32_I32 l.divu, 0xfffffff5, 0xfffffffd
263 /* Divide a number that would be negative under 2's complement by a
264 number that would be positive under 2's complement and check
265 rounding. This should set no flags. */
266 TEST_INST_I32_I32 l.divu, 0xfffffff4, 0x00000003
267 TEST_INST_I32_I32 l.divu, 0xfffffff5, 0x00000003
269 /* Divide a number that would be positive under 2's complement by a
270 number that would be negative under 2's complement and check
271 rounding. This should set no flags. */
272 TEST_INST_I32_I32 l.divu, 0x0000000c, 0xfffffffd
273 TEST_INST_I32_I32 l.divu, 0x0000000b, 0xfffffffd
275 /* Divide by zero. This will set the carry flag. */
276 TEST_INST_I32_I32 l.divu, 0x0000000c, 0x00000000
277 TEST_INST_I32_I32 l.divu, 0xfffffff4, 0x00000000
279 /* Check that range exceptions are triggered. */
281 SET_SPR_SR_FLAGS SPR_SR_OVE, r2, r3
283 /* Divide by zero. This will set the carry flag and trigger an
285 TEST_INST_I32_I32 l.divu, 0x0000000c, 0x00000000
286 TEST_INST_I32_I32 l.divu, 0xfffffff4, 0x00000000
288 CLEAR_SPR_SR_FLAGS SPR_SR_OVE, r2, r3
291 RETURN_TO_LINK_REGISTER_R9