or1k: Add the l.muld, l.muldu, l.macu, l.msbu insns
[deliverable/binutils-gdb.git] / sim / testsuite / sim / or1k / div.S
1 /* Tests the divide instructions.
2
3 Copyright (C) 2017-2018 Free Software Foundation, Inc.
4
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.
9
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.
14
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/>. */
17
18 # mach: or1k
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
25 # output: \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
32 # output: \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
39 # output: \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
46 # output: \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
53 # output: \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
60 # output: \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
67 # output: \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
74 # output: \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
81 # output: \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
88 # output: \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
95 # output: \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
102 # output: \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
109 # output: \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
116 # output: \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
123 # output: \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
130 # output: \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
137 # output: \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
144 # output: \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
151 # output: \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
158 # output: \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
165 # output: \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
172 # output: \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
179 # output: \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
186 # output: \n
187 # output: exit(0)\n
188
189 #include "or1k-asm-test-helpers.h"
190
191 STANDARD_TEST_ENVIRONMENT
192
193 .section .exception_vectors
194
195 /* Range exception. */
196 .org 0xb00
197
198 l.addi r1, r1, -EXCEPTION_STACK_SKIP_SIZE
199 PUSH r2
200 PUSH r3
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 */
204 l.sw 0(r2), r3
205 POP r3
206 POP r2
207 l.addi r1, r1, EXCEPTION_STACK_SKIP_SIZE
208 l.rfe
209
210 .section .text
211 start_tests:
212 PUSH LINK_REGISTER_R9
213
214 /* Test l.div */
215
216 /* Divide two positive numbers and check rounding. Should set no
217 flags. */
218 TEST_INST_I32_I32 l.div, 0x0000000c, 0x00000003 /* 12 / 3 = 4 */
219 TEST_INST_I32_I32 l.div, 0x0000000b, 0x00000003 /* 11 / 3 = 3 */
220
221 /* Divide two negative numbers and check rounding. Should set no
222 flags. */
223 TEST_INST_I32_I32 l.div, 0xfffffff4, 0xfffffffd
224 TEST_INST_I32_I32 l.div, 0xfffffff5, 0xfffffffd
225
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
230
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
235
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
239
240 /* Check that range exceptions are triggered. */
241
242 SET_SPR_SR_FLAGS SPR_SR_OVE, r2, r3
243
244 /* Divide by zero. This will set the overflow flag and trigger an
245 exception. */
246 TEST_INST_I32_I32 l.div, 0x0000000c, 0x00000000
247 TEST_INST_I32_I32 l.div, 0xfffffff4, 0x00000000
248
249 CLEAR_SPR_SR_FLAGS SPR_SR_OVE, r2, r3
250
251 /* Test l.divu */
252
253 /* Divide two positive numbers and check rounding. Should set no
254 flags. */
255 TEST_INST_I32_I32 l.divu, 0x0000000c, 0x00000003
256 TEST_INST_I32_I32 l.divu, 0x0000000b, 0x00000003
257
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
262
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
268
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
274
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
278
279 /* Check that range exceptions are triggered. */
280
281 SET_SPR_SR_FLAGS SPR_SR_OVE, r2, r3
282
283 /* Divide by zero. This will set the carry flag and trigger an
284 exception. */
285 TEST_INST_I32_I32 l.divu, 0x0000000c, 0x00000000
286 TEST_INST_I32_I32 l.divu, 0xfffffff4, 0x00000000
287
288 CLEAR_SPR_SR_FLAGS SPR_SR_OVE, r2, r3
289
290 POP LINK_REGISTER_R9
291 RETURN_TO_LINK_REGISTER_R9
This page took 0.039135 seconds and 4 git commands to generate.