]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/compiler-rt/lib/builtins/arm/comparesf2.S
Merge llvm, clang, lld and lldb trunk r291476.
[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 #if __ARM_ARCH_ISA_THUMB == 2
43 .thumb
44 #endif
45
46 .p2align 2
47 DEFINE_COMPILERRT_FUNCTION(__eqsf2)
48     // Make copies of a and b with the sign bit shifted off the top.  These will
49     // be used to detect zeros and NaNs.
50     mov     r2,         r0, lsl #1
51     mov     r3,         r1, lsl #1
52
53     // We do the comparison in three stages (ignoring NaN values for the time
54     // being).  First, we orr the absolute values of a and b; this sets the Z
55     // flag if both a and b are zero (of either sign).  The shift of r3 doesn't
56     // effect this at all, but it *does* make sure that the C flag is clear for
57     // the subsequent operations.
58     orrs    r12,    r2, r3, lsr #1
59
60     // Next, we check if a and b have the same or different signs.  If they have
61     // opposite signs, this eor will set the N flag.
62     it ne
63     eorsne  r12,    r0, r1
64
65     // If a and b are equal (either both zeros or bit identical; again, we're
66     // ignoring NaNs for now), this subtract will zero out r0.  If they have the
67     // same sign, the flags are updated as they would be for a comparison of the
68     // absolute values of a and b.
69     it pl
70     subspl  r0,     r2, r3
71
72     // If a is smaller in magnitude than b and both have the same sign, place
73     // the negation of the sign of b in r0.  Thus, if both are negative and
74     // a > b, this sets r0 to 0; if both are positive and a < b, this sets
75     // r0 to -1.
76     //
77     // This is also done if a and b have opposite signs and are not both zero,
78     // because in that case the subtract was not performed and the C flag is
79     // still clear from the shift argument in orrs; if a is positive and b
80     // negative, this places 0 in r0; if a is negative and b positive, -1 is
81     // placed in r0.
82     it lo
83     mvnlo   r0,         r1, asr #31
84
85     // If a is greater in magnitude than b and both have the same sign, place
86     // the sign of b in r0.  Thus, if both are negative and a < b, -1 is placed
87     // in r0, which is the desired result.  Conversely, if both are positive
88     // and a > b, zero is placed in r0.
89     it hi
90     movhi   r0,         r1, asr #31
91
92     // If you've been keeping track, at this point r0 contains -1 if a < b and
93     // 0 if a >= b.  All that remains to be done is to set it to 1 if a > b.
94     // If a == b, then the Z flag is set, so we can get the correct final value
95     // into r0 by simply or'ing with 1 if Z is clear.
96     it ne
97     orrne   r0,     r0, #1
98
99     // Finally, we need to deal with NaNs.  If either argument is NaN, replace
100     // the value in r0 with 1.
101     cmp     r2,         #0xff000000
102     ite ls
103     cmpls   r3,         #0xff000000
104     movhi   r0,         #1
105     JMP(lr)
106 END_COMPILERRT_FUNCTION(__eqsf2)
107 DEFINE_COMPILERRT_FUNCTION_ALIAS(__lesf2, __eqsf2)
108 DEFINE_COMPILERRT_FUNCTION_ALIAS(__ltsf2, __eqsf2)
109 DEFINE_COMPILERRT_FUNCTION_ALIAS(__nesf2, __eqsf2)
110
111 .p2align 2
112 DEFINE_COMPILERRT_FUNCTION(__gtsf2)
113     // Identical to the preceding except in that we return -1 for NaN values.
114     // Given that the two paths share so much code, one might be tempted to 
115     // unify them; however, the extra code needed to do so makes the code size
116     // to performance tradeoff very hard to justify for such small functions.
117     mov     r2,         r0, lsl #1
118     mov     r3,         r1, lsl #1
119     orrs    r12,    r2, r3, lsr #1
120     it ne
121     eorsne  r12,    r0, r1
122     it pl
123     subspl  r0,     r2, r3
124     it lo
125     mvnlo   r0,         r1, asr #31
126     it hi
127     movhi   r0,         r1, asr #31
128     it ne
129     orrne   r0,     r0, #1
130     cmp     r2,         #0xff000000
131     ite ls
132     cmpls   r3,         #0xff000000
133     movhi   r0,         #-1
134     JMP(lr)
135 END_COMPILERRT_FUNCTION(__gtsf2)
136 DEFINE_COMPILERRT_FUNCTION_ALIAS(__gesf2, __gtsf2)
137
138 .p2align 2
139 DEFINE_COMPILERRT_FUNCTION(__unordsf2)
140     // Return 1 for NaN values, 0 otherwise.
141     mov     r2,         r0, lsl #1
142     mov     r3,         r1, lsl #1
143     mov     r0,         #0
144     cmp     r2,         #0xff000000
145     ite ls
146     cmpls   r3,         #0xff000000
147     movhi   r0,         #1
148     JMP(lr)
149 END_COMPILERRT_FUNCTION(__unordsf2)
150
151 DEFINE_AEABI_FUNCTION_ALIAS(__aeabi_fcmpun, __unordsf2)
152
153 NO_EXEC_STACK_DIRECTIVE
154