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