]> git.proxmox.com Git - rustc.git/blame - src/compiler-rt/lib/builtins/arm/comparesf2.S
New upstream version 1.19.0+dfsg3
[rustc.git] / src / compiler-rt / lib / builtins / arm / comparesf2.S
CommitLineData
1a4d82fc
JJ
1//===-- comparesf2.S - Implement single-precision soft-float comparisons --===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is dual licensed under the MIT and the University of Illinois Open
6// Source Licenses. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file implements the following soft-fp_t comparison routines:
11//
12// __eqsf2 __gesf2 __unordsf2
13// __lesf2 __gtsf2
14// __ltsf2
15// __nesf2
16//
17// The semantics of the routines grouped in each column are identical, so there
18// is a single implementation for each, with multiple names.
19//
20// The routines behave as follows:
21//
22// __lesf2(a,b) returns -1 if a < b
23// 0 if a == b
24// 1 if a > b
25// 1 if either a or b is NaN
26//
27// __gesf2(a,b) returns -1 if a < b
28// 0 if a == b
29// 1 if a > b
30// -1 if either a or b is NaN
31//
32// __unordsf2(a,b) returns 0 if both a and b are numbers
33// 1 if either a or b is NaN
34//
35// Note that __lesf2( ) and __gesf2( ) are identical except in their handling of
36// NaN values.
37//
38//===----------------------------------------------------------------------===//
39
40#include "../assembly.h"
41.syntax unified
7cac9316
XL
42#if __ARM_ARCH_ISA_THUMB == 2
43.thumb
44#endif
1a4d82fc 45
7cac9316
XL
46@ int __eqsf2(float a, float b)
47
48 .p2align 2
1a4d82fc 49DEFINE_COMPILERRT_FUNCTION(__eqsf2)
7cac9316
XL
50#if defined(COMPILER_RT_ARMHF_TARGET)
51 vmov r0, s0
52 vmov r1, s1
53#endif
1a4d82fc
JJ
54 // Make copies of a and b with the sign bit shifted off the top. These will
55 // be used to detect zeros and NaNs.
7cac9316
XL
56#if __ARM_ARCH_ISA_THUMB == 1
57 push {r6, lr}
58 lsls r2, r0, #1
59 lsls r3, r1, #1
60#else
1a4d82fc
JJ
61 mov r2, r0, lsl #1
62 mov r3, r1, lsl #1
7cac9316 63#endif
1a4d82fc
JJ
64
65 // We do the comparison in three stages (ignoring NaN values for the time
66 // being). First, we orr the absolute values of a and b; this sets the Z
67 // flag if both a and b are zero (of either sign). The shift of r3 doesn't
68 // effect this at all, but it *does* make sure that the C flag is clear for
69 // the subsequent operations.
7cac9316
XL
70#if __ARM_ARCH_ISA_THUMB == 1
71 lsrs r6, r3, #1
72 orrs r6, r2, r6
73#else
1a4d82fc 74 orrs r12, r2, r3, lsr #1
7cac9316 75#endif
1a4d82fc
JJ
76 // Next, we check if a and b have the same or different signs. If they have
77 // opposite signs, this eor will set the N flag.
7cac9316
XL
78#if __ARM_ARCH_ISA_THUMB == 1
79 beq 1f
80 movs r6, r0
81 eors r6, r1
821:
83#else
1a4d82fc
JJ
84 it ne
85 eorsne r12, r0, r1
7cac9316 86#endif
1a4d82fc
JJ
87
88 // If a and b are equal (either both zeros or bit identical; again, we're
89 // ignoring NaNs for now), this subtract will zero out r0. If they have the
90 // same sign, the flags are updated as they would be for a comparison of the
91 // absolute values of a and b.
7cac9316
XL
92#if __ARM_ARCH_ISA_THUMB == 1
93 bmi 1f
94 subs r0, r2, r3
951:
96#else
1a4d82fc
JJ
97 it pl
98 subspl r0, r2, r3
7cac9316 99#endif
1a4d82fc
JJ
100
101 // If a is smaller in magnitude than b and both have the same sign, place
102 // the negation of the sign of b in r0. Thus, if both are negative and
103 // a > b, this sets r0 to 0; if both are positive and a < b, this sets
104 // r0 to -1.
105 //
106 // This is also done if a and b have opposite signs and are not both zero,
107 // because in that case the subtract was not performed and the C flag is
108 // still clear from the shift argument in orrs; if a is positive and b
109 // negative, this places 0 in r0; if a is negative and b positive, -1 is
110 // placed in r0.
7cac9316
XL
111#if __ARM_ARCH_ISA_THUMB == 1
112 bhs 1f
113 // Here if a and b have the same sign and absA < absB, the result is thus
114 // b < 0 ? 1 : -1. Same if a and b have the opposite sign (ignoring Nan).
115 movs r0, #1
116 lsrs r1, #31
117 bne LOCAL_LABEL(CHECK_NAN)
118 negs r0, r0
119 b LOCAL_LABEL(CHECK_NAN)
1201:
121#else
1a4d82fc
JJ
122 it lo
123 mvnlo r0, r1, asr #31
7cac9316 124#endif
1a4d82fc
JJ
125
126 // If a is greater in magnitude than b and both have the same sign, place
127 // the sign of b in r0. Thus, if both are negative and a < b, -1 is placed
128 // in r0, which is the desired result. Conversely, if both are positive
129 // and a > b, zero is placed in r0.
7cac9316
XL
130#if __ARM_ARCH_ISA_THUMB == 1
131 bls 1f
132 // Here both have the same sign and absA > absB.
133 movs r0, #1
134 lsrs r1, #31
135 beq LOCAL_LABEL(CHECK_NAN)
136 negs r0, r0
1371:
138#else
1a4d82fc
JJ
139 it hi
140 movhi r0, r1, asr #31
7cac9316 141#endif
1a4d82fc
JJ
142
143 // If you've been keeping track, at this point r0 contains -1 if a < b and
144 // 0 if a >= b. All that remains to be done is to set it to 1 if a > b.
145 // If a == b, then the Z flag is set, so we can get the correct final value
146 // into r0 by simply or'ing with 1 if Z is clear.
7cac9316
XL
147 // For Thumb-1, r0 contains -1 if a < b, 0 if a > b and 0 if a == b.
148#if __ARM_ARCH_ISA_THUMB != 1
1a4d82fc
JJ
149 it ne
150 orrne r0, r0, #1
7cac9316 151#endif
1a4d82fc
JJ
152
153 // Finally, we need to deal with NaNs. If either argument is NaN, replace
154 // the value in r0 with 1.
7cac9316
XL
155#if __ARM_ARCH_ISA_THUMB == 1
156LOCAL_LABEL(CHECK_NAN):
157 movs r6, #0xff
158 lsls r6, #24
159 cmp r2, r6
160 bhi 1f
161 cmp r3, r6
1621:
163 bls 2f
164 movs r0, #1
1652:
166 pop {r6, pc}
167#else
1a4d82fc
JJ
168 cmp r2, #0xff000000
169 ite ls
170 cmpls r3, #0xff000000
171 movhi r0, #1
172 JMP(lr)
7cac9316 173#endif
1a4d82fc 174END_COMPILERRT_FUNCTION(__eqsf2)
7cac9316 175
1a4d82fc
JJ
176DEFINE_COMPILERRT_FUNCTION_ALIAS(__lesf2, __eqsf2)
177DEFINE_COMPILERRT_FUNCTION_ALIAS(__ltsf2, __eqsf2)
178DEFINE_COMPILERRT_FUNCTION_ALIAS(__nesf2, __eqsf2)
179
7cac9316
XL
180@ int __gtsf2(float a, float b)
181
182 .p2align 2
1a4d82fc 183DEFINE_COMPILERRT_FUNCTION(__gtsf2)
92a42be0 184 // Identical to the preceding except in that we return -1 for NaN values.
7cac9316 185 // Given that the two paths share so much code, one might be tempted to
1a4d82fc
JJ
186 // unify them; however, the extra code needed to do so makes the code size
187 // to performance tradeoff very hard to justify for such small functions.
7cac9316
XL
188#if defined(COMPILER_RT_ARMHF_TARGET)
189 vmov r0, s0
190 vmov r1, s1
191#endif
192#if __ARM_ARCH_ISA_THUMB == 1
193 push {r6, lr}
194 lsls r2, r0, #1
195 lsls r3, r1, #1
196 lsrs r6, r3, #1
197 orrs r6, r2, r6
198 beq 1f
199 movs r6, r0
200 eors r6, r1
2011:
202 bmi 2f
203 subs r0, r2, r3
2042:
205 bhs 3f
206 movs r0, #1
207 lsrs r1, #31
208 bne LOCAL_LABEL(CHECK_NAN_2)
209 negs r0, r0
210 b LOCAL_LABEL(CHECK_NAN_2)
2113:
212 bls 4f
213 movs r0, #1
214 lsrs r1, #31
215 beq LOCAL_LABEL(CHECK_NAN_2)
216 negs r0, r0
2174:
218LOCAL_LABEL(CHECK_NAN_2):
219 movs r6, #0xff
220 lsls r6, #24
221 cmp r2, r6
222 bhi 5f
223 cmp r3, r6
2245:
225 bls 6f
226 movs r0, #1
227 negs r0, r0
2286:
229 pop {r6, pc}
230#else
1a4d82fc
JJ
231 mov r2, r0, lsl #1
232 mov r3, r1, lsl #1
233 orrs r12, r2, r3, lsr #1
234 it ne
235 eorsne r12, r0, r1
236 it pl
237 subspl r0, r2, r3
238 it lo
239 mvnlo r0, r1, asr #31
240 it hi
241 movhi r0, r1, asr #31
242 it ne
243 orrne r0, r0, #1
244 cmp r2, #0xff000000
245 ite ls
246 cmpls r3, #0xff000000
247 movhi r0, #-1
248 JMP(lr)
7cac9316 249#endif
1a4d82fc 250END_COMPILERRT_FUNCTION(__gtsf2)
7cac9316 251
1a4d82fc
JJ
252DEFINE_COMPILERRT_FUNCTION_ALIAS(__gesf2, __gtsf2)
253
7cac9316
XL
254@ int __unordsf2(float a, float b)
255
256 .p2align 2
1a4d82fc 257DEFINE_COMPILERRT_FUNCTION(__unordsf2)
7cac9316
XL
258#if defined(COMPILER_RT_ARMHF_TARGET)
259 vmov r0, s0
260 vmov r1, s1
261#endif
1a4d82fc 262 // Return 1 for NaN values, 0 otherwise.
7cac9316
XL
263 lsls r2, r0, #1
264 lsls r3, r1, #1
265 movs r0, #0
266#if __ARM_ARCH_ISA_THUMB == 1
267 movs r1, #0xff
268 lsls r1, #24
269 cmp r2, r1
270 bhi 1f
271 cmp r3, r1
2721:
273 bls 2f
274 movs r0, #1
2752:
276#else
1a4d82fc
JJ
277 cmp r2, #0xff000000
278 ite ls
279 cmpls r3, #0xff000000
280 movhi r0, #1
7cac9316 281#endif
1a4d82fc
JJ
282 JMP(lr)
283END_COMPILERRT_FUNCTION(__unordsf2)
284
7cac9316
XL
285#if defined(COMPILER_RT_ARMHF_TARGET)
286DEFINE_COMPILERRT_FUNCTION(__aeabi_fcmpum)
287 vmov s0, r0
288 vmov s1, r1
289 b SYMBOL_NAME(__unordsf2)
290END_COMPILERRT_FUNCTION(__aeabi_fcmpum)
291#else
1a4d82fc 292DEFINE_AEABI_FUNCTION_ALIAS(__aeabi_fcmpun, __unordsf2)
7cac9316 293#endif
3157f602
XL
294
295NO_EXEC_STACK_DIRECTIVE
296