xref: /minix3/sys/external/bsd/compiler_rt/dist/lib/builtins/cmpdi2.c (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1*0a6a1f1dSLionel Sambuc /* ===-- cmpdi2.c - Implement __cmpdi2 -------------------------------------===
2*0a6a1f1dSLionel Sambuc  *
3*0a6a1f1dSLionel Sambuc  *                     The LLVM Compiler Infrastructure
4*0a6a1f1dSLionel Sambuc  *
5*0a6a1f1dSLionel Sambuc  * This file is dual licensed under the MIT and the University of Illinois Open
6*0a6a1f1dSLionel Sambuc  * Source Licenses. See LICENSE.TXT for details.
7*0a6a1f1dSLionel Sambuc  *
8*0a6a1f1dSLionel Sambuc  * ===----------------------------------------------------------------------===
9*0a6a1f1dSLionel Sambuc  *
10*0a6a1f1dSLionel Sambuc  * This file implements __cmpdi2 for the compiler_rt library.
11*0a6a1f1dSLionel Sambuc  *
12*0a6a1f1dSLionel Sambuc  * ===----------------------------------------------------------------------===
13*0a6a1f1dSLionel Sambuc  */
14*0a6a1f1dSLionel Sambuc 
15*0a6a1f1dSLionel Sambuc #include "int_lib.h"
16*0a6a1f1dSLionel Sambuc 
17*0a6a1f1dSLionel Sambuc /* Returns: if (a <  b) returns 0
18*0a6a1f1dSLionel Sambuc *           if (a == b) returns 1
19*0a6a1f1dSLionel Sambuc *           if (a >  b) returns 2
20*0a6a1f1dSLionel Sambuc */
21*0a6a1f1dSLionel Sambuc 
22*0a6a1f1dSLionel Sambuc COMPILER_RT_ABI si_int
__cmpdi2(di_int a,di_int b)23*0a6a1f1dSLionel Sambuc __cmpdi2(di_int a, di_int b)
24*0a6a1f1dSLionel Sambuc {
25*0a6a1f1dSLionel Sambuc     dwords x;
26*0a6a1f1dSLionel Sambuc     x.all = a;
27*0a6a1f1dSLionel Sambuc     dwords y;
28*0a6a1f1dSLionel Sambuc     y.all = b;
29*0a6a1f1dSLionel Sambuc     if (x.s.high < y.s.high)
30*0a6a1f1dSLionel Sambuc         return 0;
31*0a6a1f1dSLionel Sambuc     if (x.s.high > y.s.high)
32*0a6a1f1dSLionel Sambuc         return 2;
33*0a6a1f1dSLionel Sambuc     if (x.s.low < y.s.low)
34*0a6a1f1dSLionel Sambuc         return 0;
35*0a6a1f1dSLionel Sambuc     if (x.s.low > y.s.low)
36*0a6a1f1dSLionel Sambuc         return 2;
37*0a6a1f1dSLionel Sambuc     return 1;
38*0a6a1f1dSLionel Sambuc }
39*0a6a1f1dSLionel Sambuc 
40*0a6a1f1dSLionel Sambuc #ifdef __ARM_EABI__
41*0a6a1f1dSLionel Sambuc /* Returns: if (a <  b) returns -1
42*0a6a1f1dSLionel Sambuc *           if (a == b) returns  0
43*0a6a1f1dSLionel Sambuc *           if (a >  b) returns  1
44*0a6a1f1dSLionel Sambuc */
45*0a6a1f1dSLionel Sambuc COMPILER_RT_ABI si_int
__aeabi_lcmp(di_int a,di_int b)46*0a6a1f1dSLionel Sambuc __aeabi_lcmp(di_int a, di_int b)
47*0a6a1f1dSLionel Sambuc {
48*0a6a1f1dSLionel Sambuc 	return __cmpdi2(a, b) - 1;
49*0a6a1f1dSLionel Sambuc }
50*0a6a1f1dSLionel Sambuc #endif
51*0a6a1f1dSLionel Sambuc 
52