1 //===-- comparesf2.S - Implement single-precision soft-float comparisons --===//
3 // The LLVM Compiler Infrastructure
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file implements the following soft-fp_t comparison routines:
12 // __eqsf2 __gesf2 __unordsf2
17 // The semantics of the routines grouped in each column are identical, so there
18 // is a single implementation for each, with multiple names.
20 // The routines behave as follows:
22 // __lesf2(a,b) returns -1 if a < b
25 // 1 if either a or b is NaN
27 // __gesf2(a,b) returns -1 if a < b
30 // -1 if either a or b is NaN
32 // __unordsf2(a,b) returns 0 if both a and b are numbers
33 // 1 if either a or b is NaN
35 // Note that __lesf2( ) and __gesf2( ) are identical except in their handling of
38 //===----------------------------------------------------------------------===//
40 #include "../assembly.h"
42 #if __ARM_ARCH_ISA_THUMB == 2
46 @ int __eqsf2(float a, float b)
49 DEFINE_COMPILERRT_FUNCTION(__eqsf2)
50 #if defined(COMPILER_RT_ARMHF_TARGET)
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.
56 #if __ARM_ARCH_ISA_THUMB == 1
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.
70 #if __ARM_ARCH_ISA_THUMB == 1
74 orrs r12, r2, r3, lsr #1
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.
78 #if __ARM_ARCH_ISA_THUMB == 1
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.
92 #if __ARM_ARCH_ISA_THUMB == 1
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
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
111 #if __ARM_ARCH_ISA_THUMB == 1
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).
117 bne LOCAL_LABEL(CHECK_NAN)
119 b LOCAL_LABEL(CHECK_NAN)
123 mvnlo r0, r1, asr #31
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.
130 #if __ARM_ARCH_ISA_THUMB == 1
132 // Here both have the same sign and absA > absB.
135 beq LOCAL_LABEL(CHECK_NAN)
140 movhi r0, r1, asr #31
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.
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
153 // Finally, we need to deal with NaNs. If either argument is NaN, replace
154 // the value in r0 with 1.
155 #if __ARM_ARCH_ISA_THUMB == 1
156 LOCAL_LABEL(CHECK_NAN):
170 cmpls r3, #0xff000000
174 END_COMPILERRT_FUNCTION(__eqsf2)
176 DEFINE_COMPILERRT_FUNCTION_ALIAS(__lesf2, __eqsf2)
177 DEFINE_COMPILERRT_FUNCTION_ALIAS(__ltsf2, __eqsf2)
178 DEFINE_COMPILERRT_FUNCTION_ALIAS(__nesf2, __eqsf2)
180 @ int __gtsf2(float a, float b)
183 DEFINE_COMPILERRT_FUNCTION(__gtsf2)
184 // Identical to the preceding except in that we return -1 for NaN values.
185 // Given that the two paths share so much code, one might be tempted to
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.
188 #if defined(COMPILER_RT_ARMHF_TARGET)
192 #if __ARM_ARCH_ISA_THUMB == 1
208 bne LOCAL_LABEL(CHECK_NAN_2)
210 b LOCAL_LABEL(CHECK_NAN_2)
215 beq LOCAL_LABEL(CHECK_NAN_2)
218 LOCAL_LABEL(CHECK_NAN_2):
233 orrs r12, r2, r3, lsr #1
239 mvnlo r0, r1, asr #31
241 movhi r0, r1, asr #31
246 cmpls r3, #0xff000000
250 END_COMPILERRT_FUNCTION(__gtsf2)
252 DEFINE_COMPILERRT_FUNCTION_ALIAS(__gesf2, __gtsf2)
254 @ int __unordsf2(float a, float b)
257 DEFINE_COMPILERRT_FUNCTION(__unordsf2)
258 #if defined(COMPILER_RT_ARMHF_TARGET)
262 // Return 1 for NaN values, 0 otherwise.
266 #if __ARM_ARCH_ISA_THUMB == 1
279 cmpls r3, #0xff000000
283 END_COMPILERRT_FUNCTION(__unordsf2)
285 #if defined(COMPILER_RT_ARMHF_TARGET)
286 DEFINE_COMPILERRT_FUNCTION(__aeabi_fcmpum)
289 b SYMBOL_NAME(__unordsf2)
290 END_COMPILERRT_FUNCTION(__aeabi_fcmpum)
292 DEFINE_AEABI_FUNCTION_ALIAS(__aeabi_fcmpun, __unordsf2)
295 NO_EXEC_STACK_DIRECTIVE