addvsi3.c 819 B

1234567891011121314151617181920212223242526272829
  1. //===-- addvsi3.c - Implement __addvsi3 -----------------------------------===//
  2. //
  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
  6. //
  7. //===----------------------------------------------------------------------===//
  8. //
  9. // This file implements __addvsi3 for the compiler_rt library.
  10. //
  11. //===----------------------------------------------------------------------===//
  12. #include "int_lib.h"
  13. // Returns: a + b
  14. // Effects: aborts if a + b overflows
  15. COMPILER_RT_ABI si_int __addvsi3(si_int a, si_int b) {
  16. si_int s = (su_int)a + (su_int)b;
  17. if (b >= 0) {
  18. if (s < a)
  19. compilerrt_abort();
  20. } else {
  21. if (s >= a)
  22. compilerrt_abort();
  23. }
  24. return s;
  25. }