blob: 5d693dc9aba4bfa79dceecb5a2726135fefabf91 [file] [log] [blame]
Edward O'Callaghan2bf62722009-08-05 04:02:56 +00001/* ===-- subvti3.c - Implement __subvti3 -----------------------------------===
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'Callaghan2bf62722009-08-05 04:02:56 +00007 *
8 * ===----------------------------------------------------------------------===
9 *
10 * This file implements __subvti3 for the compiler_rt library.
11 *
12 * ===----------------------------------------------------------------------===
13 */
Daniel Dunbarb3a69012009-06-26 16:47:03 +000014
15#if __x86_64
16
17#include "int_lib.h"
18#include <stdlib.h>
19
Edward O'Callaghan2bf62722009-08-05 04:02:56 +000020/* Returns: a - b */
Daniel Dunbarb3a69012009-06-26 16:47:03 +000021
Edward O'Callaghan2bf62722009-08-05 04:02:56 +000022/* Effects: aborts if a - b overflows */
Daniel Dunbarb3a69012009-06-26 16:47:03 +000023
24ti_int
25__subvti3(ti_int a, ti_int b)
26{
27 ti_int s = a - b;
28 if (b >= 0)
29 {
30 if (s > a)
Daniel Dunbar48f46ac2010-03-31 17:00:45 +000031 compilerrt_abort();
Daniel Dunbarb3a69012009-06-26 16:47:03 +000032 }
33 else
34 {
35 if (s <= a)
Daniel Dunbar48f46ac2010-03-31 17:00:45 +000036 compilerrt_abort();
Daniel Dunbarb3a69012009-06-26 16:47:03 +000037 }
38 return s;
39}
40
Edward O'Callaghan8bf1e092009-08-09 18:41:02 +000041#endif /* __x86_64 */