xref: /netbsd-src/sys/external/bsd/compiler_rt/dist/lib/builtins/subvti3.c (revision ef84fd3bd8895f4e6be1e38baf19e6dc3255bc64)
1156cd587Sjoerg /* ===-- subvti3.c - Implement __subvti3 -----------------------------------===
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 __subvti3 for the compiler_rt library.
11156cd587Sjoerg  *
12156cd587Sjoerg  * ===----------------------------------------------------------------------===
13156cd587Sjoerg  */
14156cd587Sjoerg 
15156cd587Sjoerg #include "int_lib.h"
16156cd587Sjoerg 
17156cd587Sjoerg #ifdef CRT_HAS_128BIT
18156cd587Sjoerg 
19156cd587Sjoerg /* Returns: a - b */
20156cd587Sjoerg 
21156cd587Sjoerg /* Effects: aborts if a - b overflows */
22156cd587Sjoerg 
23f7f78b33Sjoerg COMPILER_RT_ABI ti_int
__subvti3(ti_int a,ti_int b)24156cd587Sjoerg __subvti3(ti_int a, ti_int b)
25156cd587Sjoerg {
26*ef84fd3bSjoerg     ti_int s = (tu_int) a - (tu_int) b;
27156cd587Sjoerg     if (b >= 0)
28156cd587Sjoerg     {
29156cd587Sjoerg         if (s > a)
30156cd587Sjoerg             compilerrt_abort();
31156cd587Sjoerg     }
32156cd587Sjoerg     else
33156cd587Sjoerg     {
34156cd587Sjoerg         if (s <= a)
35156cd587Sjoerg             compilerrt_abort();
36156cd587Sjoerg     }
37156cd587Sjoerg     return s;
38156cd587Sjoerg }
39156cd587Sjoerg 
40156cd587Sjoerg #endif /* CRT_HAS_128BIT */
41