Edward O'Callaghan | 1fcb40b | 2009-08-05 19:06:50 +0000 | [diff] [blame] | 1 | /* ===-- addvti3.c - Implement __addvti3 -----------------------------------=== |
| 2 | * |
Chandler Carruth | 7a739a0 | 2019-01-19 10:56:40 +0000 | [diff] [blame] | 3 | * Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | * See https://llvm.org/LICENSE.txt for license information. |
| 5 | * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
Edward O'Callaghan | 1fcb40b | 2009-08-05 19:06:50 +0000 | [diff] [blame] | 6 | * |
| 7 | * ===----------------------------------------------------------------------=== |
| 8 | * |
| 9 | * This file implements __addvti3 for the compiler_rt library. |
| 10 | * |
| 11 | * ===----------------------------------------------------------------------=== |
| 12 | */ |
Daniel Dunbar | b3a6901 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 13 | |
Daniel Dunbar | b3a6901 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 14 | #include "int_lib.h" |
Daniel Dunbar | b3a6901 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 15 | |
Joerg Sonnenberger | 4733cca | 2014-02-21 23:53:03 +0000 | [diff] [blame] | 16 | #ifdef CRT_HAS_128BIT |
Chandler Carruth | 7f2d7c7 | 2012-06-22 21:09:22 +0000 | [diff] [blame] | 17 | |
Edward O'Callaghan | 1fcb40b | 2009-08-05 19:06:50 +0000 | [diff] [blame] | 18 | /* Returns: a + b */ |
Daniel Dunbar | b3a6901 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 19 | |
Edward O'Callaghan | 1fcb40b | 2009-08-05 19:06:50 +0000 | [diff] [blame] | 20 | /* Effects: aborts if a + b overflows */ |
Daniel Dunbar | b3a6901 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 21 | |
Joerg Sonnenberger | bfbb8bb | 2014-03-01 15:30:50 +0000 | [diff] [blame] | 22 | COMPILER_RT_ABI ti_int |
Daniel Dunbar | b3a6901 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 23 | __addvti3(ti_int a, ti_int b) |
| 24 | { |
Bob Wilson | b90f66b | 2014-11-12 23:01:24 +0000 | [diff] [blame] | 25 | ti_int s = (tu_int) a + (tu_int) b; |
Daniel Dunbar | b3a6901 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 26 | if (b >= 0) |
| 27 | { |
| 28 | if (s < a) |
Daniel Dunbar | 48f46ac | 2010-03-31 17:00:45 +0000 | [diff] [blame] | 29 | compilerrt_abort(); |
Daniel Dunbar | b3a6901 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 30 | } |
| 31 | else |
| 32 | { |
| 33 | if (s >= a) |
Daniel Dunbar | 48f46ac | 2010-03-31 17:00:45 +0000 | [diff] [blame] | 34 | compilerrt_abort(); |
Daniel Dunbar | b3a6901 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 35 | } |
| 36 | return s; |
| 37 | } |
| 38 | |
Joerg Sonnenberger | 4733cca | 2014-02-21 23:53:03 +0000 | [diff] [blame] | 39 | #endif /* CRT_HAS_128BIT */ |