xref: /netbsd-src/sys/external/bsd/compiler_rt/dist/lib/builtins/addvdi3.c (revision ef84fd3bd8895f4e6be1e38baf19e6dc3255bc64)
1156cd587Sjoerg /* ===-- addvdi3.c - Implement __addvdi3 -----------------------------------===
2156cd587Sjoerg  *
3156cd587Sjoerg  *                     The LLVM Compiler Infrastructure
4156cd587Sjoerg  *
5156cd587Sjoerg  * This file is dual licensed under the MIT and the University of Illinois Open
6156cd587Sjoerg  * Source Licenses. See LICENSE.TXT for details.
7156cd587Sjoerg  *
8156cd587Sjoerg  * ===----------------------------------------------------------------------===
9156cd587Sjoerg  *
10156cd587Sjoerg  * This file implements __addvdi3 for the compiler_rt library.
11156cd587Sjoerg  *
12156cd587Sjoerg  * ===----------------------------------------------------------------------===
13156cd587Sjoerg  */
14156cd587Sjoerg 
15156cd587Sjoerg #include "int_lib.h"
16156cd587Sjoerg 
17156cd587Sjoerg /* Returns: a + b */
18156cd587Sjoerg 
19156cd587Sjoerg /* Effects: aborts if a + b overflows */
20156cd587Sjoerg 
21156cd587Sjoerg COMPILER_RT_ABI di_int
__addvdi3(di_int a,di_int b)22156cd587Sjoerg __addvdi3(di_int a, di_int b)
23156cd587Sjoerg {
24*ef84fd3bSjoerg     di_int s = (du_int) a + (du_int) b;
25156cd587Sjoerg     if (b >= 0)
26156cd587Sjoerg     {
27156cd587Sjoerg         if (s < a)
28156cd587Sjoerg             compilerrt_abort();
29156cd587Sjoerg     }
30156cd587Sjoerg     else
31156cd587Sjoerg     {
32156cd587Sjoerg         if (s >= a)
33156cd587Sjoerg             compilerrt_abort();
34156cd587Sjoerg     }
35156cd587Sjoerg     return s;
36156cd587Sjoerg }
37