addvsi3.c revision 214152
1214152Sed/* ===-- addvsi3.c - Implement __addvsi3 -----------------------------------===
2214152Sed *
3214152Sed *                    The LLVM Compiler Infrastructure
4214152Sed *
5214152Sed * This file is distributed under the University of Illinois Open Source
6214152Sed * License. See LICENSE.TXT for details.
7214152Sed *
8214152Sed * ===----------------------------------------------------------------------===
9214152Sed *
10214152Sed * This file implements __addvsi3 for the compiler_rt library.
11214152Sed *
12214152Sed * ===----------------------------------------------------------------------===
13214152Sed */
14214152Sed
15214152Sed#include "int_lib.h"
16214152Sed#include <stdlib.h>
17214152Sed
18214152Sed/* Returns: a + b */
19214152Sed
20214152Sed/* Effects: aborts if a + b overflows */
21214152Sed
22214152Sedsi_int
23214152Sed__addvsi3(si_int a, si_int b)
24214152Sed{
25214152Sed    si_int s = a + b;
26214152Sed    if (b >= 0)
27214152Sed    {
28214152Sed        if (s < a)
29214152Sed            compilerrt_abort();
30214152Sed    }
31214152Sed    else
32214152Sed    {
33214152Sed        if (s >= a)
34214152Sed            compilerrt_abort();
35214152Sed    }
36214152Sed    return s;
37214152Sed}
38