blob: 03983f747e49f250552b5c773b93328ff1a23619 [file] [log] [blame]
Edward O'Callaghan4856eef2009-08-05 04:02:561/* ===-- subvsi3.c - Implement __subvsi3 -----------------------------------===
2 *
Anton Korobeynikove63da932011-04-19 17:52:093 * The LLVM Compiler Infrastructure
Edward O'Callaghan4856eef2009-08-05 04:02:564 *
Howard Hinnant5b791f62010-11-16 22:13:335 * This file is dual licensed under the MIT and the University of Illinois Open
6 * Source Licenses. See LICENSE.TXT for details.
Edward O'Callaghan4856eef2009-08-05 04:02:567 *
8 * ===----------------------------------------------------------------------===
9 *
10 * This file implements __subvsi3 for the compiler_rt library.
11 *
12 * ===----------------------------------------------------------------------===
13 */
Anton Korobeynikove63da932011-04-19 17:52:0914#include "abi.h"
Daniel Dunbarfd089992009-06-26 16:47:0315
16#include "int_lib.h"
17#include <stdlib.h>
18
Edward O'Callaghan4856eef2009-08-05 04:02:5619/* Returns: a - b */
Daniel Dunbarfd089992009-06-26 16:47:0320
Edward O'Callaghan4856eef2009-08-05 04:02:5621/* Effects: aborts if a - b overflows */
Daniel Dunbarfd089992009-06-26 16:47:0322
Anton Korobeynikove63da932011-04-19 17:52:0923COMPILER_RT_ABI si_int
Daniel Dunbarfd089992009-06-26 16:47:0324__subvsi3(si_int a, si_int b)
25{
26 si_int s = a - b;
27 if (b >= 0)
28 {
29 if (s > a)
Daniel Dunbarf2870082010-03-31 17:00:4530 compilerrt_abort();
Daniel Dunbarfd089992009-06-26 16:47:0331 }
32 else
33 {
34 if (s <= a)
Daniel Dunbarf2870082010-03-31 17:00:4535 compilerrt_abort();
Daniel Dunbarfd089992009-06-26 16:47:0336 }
37 return s;
38}