blob: d0ee07a3872ab479d59f7521ff095ebf6fa6e25b [file] [log] [blame]
Edward O'Callaghan1fcb40b2009-08-05 19:06:50 +00001/* ===-- addvti3.c - Implement __addvti3 -----------------------------------===
2 *
Chandler Carruth7a739a02019-01-19 10:56:40 +00003 * 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'Callaghan1fcb40b2009-08-05 19:06:50 +00006 *
7 * ===----------------------------------------------------------------------===
8 *
9 * This file implements __addvti3 for the compiler_rt library.
10 *
11 * ===----------------------------------------------------------------------===
12 */
Daniel Dunbarb3a69012009-06-26 16:47:03 +000013
Daniel Dunbarb3a69012009-06-26 16:47:03 +000014#include "int_lib.h"
Daniel Dunbarb3a69012009-06-26 16:47:03 +000015
Joerg Sonnenberger4733cca2014-02-21 23:53:03 +000016#ifdef CRT_HAS_128BIT
Chandler Carruth7f2d7c72012-06-22 21:09:22 +000017
Edward O'Callaghan1fcb40b2009-08-05 19:06:50 +000018/* Returns: a + b */
Daniel Dunbarb3a69012009-06-26 16:47:03 +000019
Edward O'Callaghan1fcb40b2009-08-05 19:06:50 +000020/* Effects: aborts if a + b overflows */
Daniel Dunbarb3a69012009-06-26 16:47:03 +000021
Joerg Sonnenbergerbfbb8bb2014-03-01 15:30:50 +000022COMPILER_RT_ABI ti_int
Daniel Dunbarb3a69012009-06-26 16:47:03 +000023__addvti3(ti_int a, ti_int b)
24{
Bob Wilsonb90f66b2014-11-12 23:01:24 +000025 ti_int s = (tu_int) a + (tu_int) b;
Daniel Dunbarb3a69012009-06-26 16:47:03 +000026 if (b >= 0)
27 {
28 if (s < a)
Daniel Dunbar48f46ac2010-03-31 17:00:45 +000029 compilerrt_abort();
Daniel Dunbarb3a69012009-06-26 16:47:03 +000030 }
31 else
32 {
33 if (s >= a)
Daniel Dunbar48f46ac2010-03-31 17:00:45 +000034 compilerrt_abort();
Daniel Dunbarb3a69012009-06-26 16:47:03 +000035 }
36 return s;
37}
38
Joerg Sonnenberger4733cca2014-02-21 23:53:03 +000039#endif /* CRT_HAS_128BIT */