blob: 52634d9c336233b130ae035ee835f9e43785f1d5 [file] [log] [blame]
Edward O'Callaghan37a6a452009-08-07 20:30:09 +00001/* ===-- cmpdi2.c - Implement __cmpdi2 -------------------------------------===
2 *
3 * The LLVM Compiler Infrastructure
4 *
Howard Hinnant9ad441f2010-11-16 22:13:33 +00005 * This file is dual licensed under the MIT and the University of Illinois Open
6 * Source Licenses. See LICENSE.TXT for details.
Edward O'Callaghan37a6a452009-08-07 20:30:09 +00007 *
8 * ===----------------------------------------------------------------------===
Anton Korobeynikov1c5f89b2011-04-19 17:52:09 +00009 *
Edward O'Callaghan37a6a452009-08-07 20:30:09 +000010 * This file implements __cmpdi2 for the compiler_rt library.
11 *
12 * ===----------------------------------------------------------------------===
13 */
Daniel Dunbarb3a69012009-06-26 16:47:03 +000014
15#include "int_lib.h"
16
Anton Korobeynikov1c5f89b2011-04-19 17:52:09 +000017/* Returns: if (a < b) returns 0
Edward O'Callaghan37a6a452009-08-07 20:30:09 +000018* if (a == b) returns 1
19* if (a > b) returns 2
20*/
Daniel Dunbarb3a69012009-06-26 16:47:03 +000021
Anton Korobeynikov1c5f89b2011-04-19 17:52:09 +000022COMPILER_RT_ABI si_int
Daniel Dunbarb3a69012009-06-26 16:47:03 +000023__cmpdi2(di_int a, di_int b)
24{
25 dwords x;
26 x.all = a;
27 dwords y;
28 y.all = b;
Edward O'Callaghan8bf1e092009-08-09 18:41:02 +000029 if (x.s.high < y.s.high)
Daniel Dunbarb3a69012009-06-26 16:47:03 +000030 return 0;
Edward O'Callaghan8bf1e092009-08-09 18:41:02 +000031 if (x.s.high > y.s.high)
Daniel Dunbarb3a69012009-06-26 16:47:03 +000032 return 2;
Edward O'Callaghan8bf1e092009-08-09 18:41:02 +000033 if (x.s.low < y.s.low)
Daniel Dunbarb3a69012009-06-26 16:47:03 +000034 return 0;
Edward O'Callaghan8bf1e092009-08-09 18:41:02 +000035 if (x.s.low > y.s.low)
Daniel Dunbarb3a69012009-06-26 16:47:03 +000036 return 2;
37 return 1;
38}
Tim Northover4785a772013-01-13 19:18:02 +000039
40#ifdef __ARM_EABI__
41/* Returns: if (a < b) returns -1
42* if (a == b) returns 0
43* if (a > b) returns 1
44*/
45COMPILER_RT_ABI si_int
46__aeabi_lcmp(di_int a, di_int b)
47{
48 return __cmpdi2(a, b) - 1;
49}
50#endif
51