blob: ec4594c9f0e95483d26598b87faa9f0ea5018a52 [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 */
Daniel Dunbarfd089992009-06-26 16:47:0314
15#include "int_lib.h"
Daniel Dunbarfd089992009-06-26 16:47:0316
Edward O'Callaghan4856eef2009-08-05 04:02:5617/* Returns: a - b */
Daniel Dunbarfd089992009-06-26 16:47:0318
Edward O'Callaghan4856eef2009-08-05 04:02:5619/* Effects: aborts if a - b overflows */
Daniel Dunbarfd089992009-06-26 16:47:0320
Anton Korobeynikove63da932011-04-19 17:52:0921COMPILER_RT_ABI si_int
Daniel Dunbarfd089992009-06-26 16:47:0322__subvsi3(si_int a, si_int b)
23{
24 si_int s = a - b;
25 if (b >= 0)
26 {
27 if (s > a)
Daniel Dunbarf2870082010-03-31 17:00:4528 compilerrt_abort();
Daniel Dunbarfd089992009-06-26 16:47:0329 }
30 else
31 {
32 if (s <= a)
Daniel Dunbarf2870082010-03-31 17:00:4533 compilerrt_abort();
Daniel Dunbarfd089992009-06-26 16:47:0334 }
35 return s;
36}