1 /* Tests instruction l.sub.
3 Copyright (C) 2017-2024 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(0x00000003);\n
20 # output: report(0x00000002);\n
21 # output: report(0x00000001);\n
22 # output: report(0x00000000);\n
23 # output: report(0x00000000);\n
24 # output: report(0x00000000);\n
26 # output: report(0x00000001);\n
27 # output: report(0x00000002);\n
28 # output: report(0xffffffff);\n
29 # output: report(0x00000001);\n
30 # output: report(0x00000000);\n
31 # output: report(0x00000000);\n
33 # output: report(0x00000003);\n
34 # output: report(0x00000002);\n
35 # output: report(0x00000001);\n
36 # output: report(0x00000000);\n
37 # output: report(0x00000000);\n
38 # output: report(0x00000000);\n
40 # output: report(0xfffffffd);\n
41 # output: report(0xfffffffe);\n
42 # output: report(0xffffffff);\n
43 # output: report(0x00000001);\n
44 # output: report(0x00000000);\n
45 # output: report(0x00000000);\n
47 # output: report(0xffffffff);\n
48 # output: report(0xfffffffe);\n
49 # output: report(0x00000001);\n
50 # output: report(0x00000000);\n
51 # output: report(0x00000000);\n
52 # output: report(0x00000000);\n
54 # output: report(0x7fffffff);\n
55 # output: report(0x3fffffff);\n
56 # output: report(0x40000000);\n
57 # output: report(0x00000000);\n
58 # output: report(0x00000000);\n
59 # output: report(0x00000000);\n
61 # output: report(0x40000000);\n
62 # output: report(0x40000000);\n
63 # output: report(0x00000000);\n
64 # output: report(0x00000000);\n
65 # output: report(0x00000000);\n
66 # output: report(0x00000000);\n
68 # output: report(0x3fffffff);\n
69 # output: report(0x40000000);\n
70 # output: report(0xffffffff);\n
71 # output: report(0x00000001);\n
72 # output: report(0x00000000);\n
73 # output: report(0x00000000);\n
75 # output: report(0x40000000);\n
76 # output: report(0x3fffffff);\n
77 # output: report(0x00000001);\n
78 # output: report(0x00000000);\n
79 # output: report(0x00000000);\n
80 # output: report(0x00000000);\n
82 # output: report(0x80000000);\n
83 # output: report(0x7fffffff);\n
84 # output: report(0x00000001);\n
85 # output: report(0x00000000);\n
86 # output: report(0x00000001);\n
87 # output: report(0x00000000);\n
89 # output: report(0x7fffffff);\n
90 # output: report(0x80000000);\n
91 # output: report(0xffffffff);\n
92 # output: report(0x00000001);\n
93 # output: report(0x00000001);\n
94 # output: report(0x00000000);\n
96 # output: report(0x80000000);\n
97 # output: report(0x7fffffff);\n
98 # output: report(0x00000001);\n
99 # output: report(0x00000000);\n
100 # output: report(0x00000001);\n
101 # output: report(0x00000001);\n
103 # output: report(0x3fffffff);\n
104 # output: report(0x40000000);\n
105 # output: report(0xffffffff);\n
106 # output: report(0x00000001);\n
107 # output: report(0x00000000);\n
108 # output: report(0x00000000);\n
110 # output: report(0x7fffffff);\n
111 # output: report(0x80000000);\n
112 # output: report(0xffffffff);\n
113 # output: report(0x00000001);\n
114 # output: report(0x00000001);\n
115 # output: report(0x00000001);\n
119 #include "or1k-asm-test-helpers.h"
121 STANDARD_TEST_ENVIRONMENT
123 .section .exception_vectors
125 /* Range exception. */
128 /* The handling is a bit dubious at present. We just patch the
129 instruction with l.nop and restart. This will go wrong in branch
130 delay slots. But we don't have those in this test. */
131 l.addi r1, r1, -EXCEPTION_STACK_SKIP_SIZE
134 /* Save the address of the instruction that caused the problem. */
135 MOVE_FROM_SPR r2, SPR_EPCR_BASE
136 LOAD_IMMEDIATE r3, 0x15000000 /* Opcode for l.nop */
140 l.addi r1, r1, EXCEPTION_STACK_SKIP_SIZE
145 PUSH LINK_REGISTER_R9
149 /* Subtract two small positive numbers. Sets the carry, but never
150 the overflow if the result is negative. */
151 TEST_INST_FF_I32_I32 0, SPR_SR_CY | SPR_SR_OV, l.sub, 0x00000003, \
153 TEST_INST_FF_I32_I32 0, SPR_SR_CY | SPR_SR_OV, l.sub, 0x00000001, \
156 /* Check carry in is ignored. */
157 TEST_INST_FF_I32_I32 SPR_SR_CY, SPR_SR_OV, l.sub, 0x00000003, 0x00000002
159 /* Subtract two small negative numbers. Sets the carry flag if
160 the result is negative, but never the overflow flag. */
161 TEST_INST_FF_I32_I32 0, SPR_SR_CY | SPR_SR_OV, l.sub, 0xfffffffd, \
163 TEST_INST_FF_I32_I32 0, SPR_SR_CY | SPR_SR_OV, l.sub, 0xffffffff, \
166 /* Subtract two quite large positive numbers. Should set neither
167 the overflow nor the carry flag. */
168 TEST_INST_FF_I32_I32 0, SPR_SR_CY | SPR_SR_OV, l.sub, 0x7fffffff, \
171 /* Subtract two quite large negative numbers. Should set neither
172 the overflow nor the carry flag. */
173 TEST_INST_FF_I32_I32 0, SPR_SR_CY | SPR_SR_OV, l.sub, 0x40000000, \
176 /* Subtract two large positive numbers with a negative result.
177 Should set the carry, but not the overflow flag. */
178 TEST_INST_FF_I32_I32 0, SPR_SR_CY | SPR_SR_OV, l.sub, 0x3fffffff, \
181 /* Subtract two large negative numbers with a positive result.
182 Should set neither the carry nor the overflow flag. */
183 TEST_INST_FF_I32_I32 0, SPR_SR_CY | SPR_SR_OV, l.sub, 0x40000000, \
186 /* Subtract a large positive from a large negative number. Should
187 set overflow but not the carry flag. */
188 TEST_INST_FF_I32_I32 0, SPR_SR_CY | SPR_SR_OV, l.sub, 0x80000000, \
191 /* Subtract a large negative from a large positive number. Should
192 set both the overflow and carry flags. */
193 TEST_INST_FF_I32_I32 0, SPR_SR_CY | SPR_SR_OV, l.sub, 0x7fffffff, \
196 /* Check that range exceptions are triggered. */
198 SET_SPR_SR_FLAGS SPR_SR_OVE, r2, r3
200 /* Check that an overflow alone causes a RANGE Exception. */
201 TEST_INST_FF_I32_I32 0, SPR_SR_CY | SPR_SR_OV, l.sub, 0x80000000, \
204 /* Check that a carry alone does not cause a RANGE Exception. */
205 TEST_INST_FF_I32_I32 0, SPR_SR_CY | SPR_SR_OV, l.sub, 0x3fffffff, \
208 /* Check that carry and overflow together cause an exception. */
209 TEST_INST_FF_I32_I32 0, SPR_SR_CY | SPR_SR_OV, l.sub, 0x7fffffff, \
212 CLEAR_SPR_SR_FLAGS SPR_SR_OVE, r2, r3
215 RETURN_TO_LINK_REGISTER_R9