]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/compiler-rt/lib/builtins/arm/comparesf2.S
Merge llvm, clang, lld, lldb, compiler-rt and libc++ r304460, and update
[FreeBSD/FreeBSD.git] / contrib / compiler-rt / lib / builtins / arm / comparesf2.S
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
42     .text
43 #if defined(USE_THUMB_PROLOGUE)
44     .thumb
45 #endif
46
47 @ int __eqsf2(float a, float b)
48
49     .p2align 2
50 #if defined(USE_THUMB_PROLOGUE)
51 DEFINE_COMPILERRT_THUMB_FUNCTION(__eqsf2)
52 #else
53 DEFINE_COMPILERRT_FUNCTION(__eqsf2)
54 #endif
55 #if defined(COMPILER_RT_ARMHF_TARGET)
56     vmov r0, s0
57     vmov r1, s1
58 #endif
59     // Make copies of a and b with the sign bit shifted off the top.  These will
60     // be used to detect zeros and NaNs.
61 #if __ARM_ARCH_ISA_THUMB == 1
62     push    {r6, lr}
63     lsls    r2,         r0, #1
64     lsls    r3,         r1, #1
65 #else
66     mov     r2,         r0, lsl #1
67     mov     r3,         r1, lsl #1
68 #endif
69
70     // We do the comparison in three stages (ignoring NaN values for the time
71     // being).  First, we orr the absolute values of a and b; this sets the Z
72     // flag if both a and b are zero (of either sign).  The shift of r3 doesn't
73     // effect this at all, but it *does* make sure that the C flag is clear for
74     // the subsequent operations.
75 #if defined(USE_THUMB_1)
76     lsrs    r6,     r3, #1
77     orrs    r6,     r2
78 #else
79     orrs    r12,    r2, r3, lsr #1
80 #endif
81     // Next, we check if a and b have the same or different signs.  If they have
82     // opposite signs, this eor will set the N flag.
83 #if defined(USE_THUMB_1)
84     beq     1f
85     movs    r6,     r0
86     eors    r6,     r1
87 1:
88 #else
89     it ne
90     eorsne  r12,    r0, r1
91 #endif
92
93     // If a and b are equal (either both zeros or bit identical; again, we're
94     // ignoring NaNs for now), this subtract will zero out r0.  If they have the
95     // same sign, the flags are updated as they would be for a comparison of the
96     // absolute values of a and b.
97 #if defined(USE_THUMB_1)
98     bmi     1f
99     subs    r0,     r2, r3
100 1:
101 #else
102     it pl
103     subspl  r0,     r2, r3
104 #endif
105
106     // If a is smaller in magnitude than b and both have the same sign, place
107     // the negation of the sign of b in r0.  Thus, if both are negative and
108     // a > b, this sets r0 to 0; if both are positive and a < b, this sets
109     // r0 to -1.
110     //
111     // This is also done if a and b have opposite signs and are not both zero,
112     // because in that case the subtract was not performed and the C flag is
113     // still clear from the shift argument in orrs; if a is positive and b
114     // negative, this places 0 in r0; if a is negative and b positive, -1 is
115     // placed in r0.
116 #if defined(USE_THUMB_1)
117     bhs     1f
118     // Here if a and b have the same sign and absA < absB, the result is thus
119     // b < 0 ? 1 : -1. Same if a and b have the opposite sign (ignoring Nan).
120     movs    r0,         #1
121     lsrs    r1,         #31
122     bne     LOCAL_LABEL(CHECK_NAN)
123     negs    r0,         r0
124     b       LOCAL_LABEL(CHECK_NAN)
125 1:
126 #else
127     it lo
128     mvnlo   r0,         r1, asr #31
129 #endif
130
131     // If a is greater in magnitude than b and both have the same sign, place
132     // the sign of b in r0.  Thus, if both are negative and a < b, -1 is placed
133     // in r0, which is the desired result.  Conversely, if both are positive
134     // and a > b, zero is placed in r0.
135 #if defined(USE_THUMB_1)
136     bls     1f
137     // Here both have the same sign and absA > absB.
138     movs    r0,         #1
139     lsrs    r1,         #31
140     beq     LOCAL_LABEL(CHECK_NAN)
141     negs    r0, r0
142 1:
143 #else
144     it hi
145     movhi   r0,         r1, asr #31
146 #endif
147
148     // If you've been keeping track, at this point r0 contains -1 if a < b and
149     // 0 if a >= b.  All that remains to be done is to set it to 1 if a > b.
150     // If a == b, then the Z flag is set, so we can get the correct final value
151     // into r0 by simply or'ing with 1 if Z is clear.
152     // For Thumb-1, r0 contains -1 if a < b, 0 if a > b and 0 if a == b.
153 #if defined(USE_THUMB_1)
154     it ne
155     orrne   r0,     r0, #1
156 #endif
157
158     // Finally, we need to deal with NaNs.  If either argument is NaN, replace
159     // the value in r0 with 1.
160 #if defined(USE_THUMB_1)
161 LOCAL_LABEL(CHECK_NAN):
162     movs    r6,         #0xff
163     lsls    r6,         #24
164     cmp     r2,         r6
165     bhi     1f
166     cmp     r3,         r6
167 1:
168     bls     2f
169     movs    r0,         #1
170 2:
171     pop     {r6, pc}
172 #else
173     cmp     r2,         #0xff000000
174     ite ls
175     cmpls   r3,         #0xff000000
176     movhi   r0,         #1
177     JMP(lr)
178 #endif
179 END_COMPILERRT_FUNCTION(__eqsf2)
180
181 DEFINE_COMPILERRT_FUNCTION_ALIAS(__lesf2, __eqsf2)
182 DEFINE_COMPILERRT_FUNCTION_ALIAS(__ltsf2, __eqsf2)
183 DEFINE_COMPILERRT_FUNCTION_ALIAS(__nesf2, __eqsf2)
184
185 @ int __gtsf2(float a, float b)
186
187     .p2align 2
188 #if defined(USE_THUMB)
189 DEFINE_COMPILERRT_THUMB_FUNCTION(__gtsf2)
190 #else
191 DEFINE_COMPILERRT_FUNCTION(__gtsf2)
192 #endif
193     // Identical to the preceding except in that we return -1 for NaN values.
194     // Given that the two paths share so much code, one might be tempted to
195     // unify them; however, the extra code needed to do so makes the code size
196     // to performance tradeoff very hard to justify for such small functions.
197 #if defined(COMPILER_RT_ARMHF_TARGET)
198     vmov r0, s0
199     vmov r1, s1
200 #endif
201 #if defined(USE_THUMB_1)
202     push    {r6, lr}
203     lsls    r2,        r0, #1
204     lsls    r3,        r1, #1
205     lsrs    r6,        r3, #1
206     orrs    r6,        r2
207     beq     1f
208     movs    r6,        r0
209     eors    r6,        r1
210 1:
211     bmi     2f
212     subs    r0,        r2, r3
213 2:
214     bhs     3f
215     movs    r0,        #1
216     lsrs    r1,        #31
217     bne     LOCAL_LABEL(CHECK_NAN_2)
218     negs    r0, r0
219     b       LOCAL_LABEL(CHECK_NAN_2)
220 3:
221     bls     4f
222     movs    r0,         #1
223     lsrs    r1,         #31
224     beq     LOCAL_LABEL(CHECK_NAN_2)
225     negs    r0, r0
226 4:
227 LOCAL_LABEL(CHECK_NAN_2):
228     movs    r6,         #0xff
229     lsls    r6,         #24
230     cmp     r2,         r6
231     bhi     5f
232     cmp     r3,         r6
233 5:
234     bls     6f
235     movs    r0,         #1
236     negs    r0,         r0
237 6:
238     pop     {r6, pc}
239 #else
240     mov     r2,         r0, lsl #1
241     mov     r3,         r1, lsl #1
242     orrs    r12,    r2, r3, lsr #1
243     it ne
244     eorsne  r12,    r0, r1
245     it pl
246     subspl  r0,     r2, r3
247     it lo
248     mvnlo   r0,         r1, asr #31
249     it hi
250     movhi   r0,         r1, asr #31
251     it ne
252     orrne   r0,     r0, #1
253     cmp     r2,         #0xff000000
254     ite ls
255     cmpls   r3,         #0xff000000
256     movhi   r0,         #-1
257     JMP(lr)
258 #endif
259 END_COMPILERRT_FUNCTION(__gtsf2)
260
261 DEFINE_COMPILERRT_FUNCTION_ALIAS(__gesf2, __gtsf2)
262
263 @ int __unordsf2(float a, float b)
264
265     .p2align 2
266 #if defined(USE_THUMB)
267 DEFINE_COMPILERRT_THUMB_FUNCTION(__unordsf2)
268 #else
269 DEFINE_COMPILERRT_FUNCTION(__unordsf2)
270 #endif
271
272 #if defined(COMPILER_RT_ARMHF_TARGET)
273     vmov    r0,         s0
274     vmov    r1,         s1
275 #endif
276     // Return 1 for NaN values, 0 otherwise.
277     lsls    r2,         r0, #1
278     lsls    r3,         r1, #1
279     movs    r0,         #0
280 #if defined(USE_THUMB_1)
281     movs    r1,         #0xff
282     lsls    r1,         #24
283     cmp     r2,         r1
284     bhi     1f
285     cmp     r3,         r1
286 1:
287     bls     2f
288     movs    r0,         #1
289 2:
290 #else
291     cmp     r2,         #0xff000000
292     ite ls
293     cmpls   r3,         #0xff000000
294     movhi   r0,         #1
295 #endif
296     JMP(lr)
297 END_COMPILERRT_FUNCTION(__unordsf2)
298
299 #if defined(COMPILER_RT_ARMHF_TARGET)
300 DEFINE_COMPILERRT_FUNCTION(__aeabi_fcmpum)
301         vmov s0, r0
302         vmov s1, r1
303         b SYMBOL_NAME(__unordsf2)
304 END_COMPILERRT_FUNCTION(__aeabi_fcmpum)
305 #else
306 DEFINE_AEABI_FUNCTION_ALIAS(__aeabi_fcmpun, __unordsf2)
307 #endif
308
309 NO_EXEC_STACK_DIRECTIVE
310