| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| //===-- Implementation of lldiv -------------------------------------------===// | ||
| // | ||
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #include "src/stdlib/lldiv.h" | ||
| #include "src/__support/common.h" | ||
| #include "src/__support/integer_operations.h" | ||
|
|
||
| namespace __llvm_libc { | ||
|
|
||
| LLVM_LIBC_FUNCTION(lldiv_t, lldiv, (long long x, long long y)) { | ||
| lldiv_t res; | ||
| integerRemQuo(x, y, res.quot, res.rem); | ||
| return res; | ||
| } | ||
|
|
||
| } // namespace __llvm_libc |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| //===-- Implementation header for lldiv -------------------------*- C++ -*-===// | ||
| // | ||
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #include <stdlib.h> | ||
|
|
||
| #ifndef LLVM_LIBC_SRC_STDLIB_LLDIV_H | ||
| #define LLVM_LIBC_SRC_STDLIB_LLDIV_H | ||
|
|
||
| namespace __llvm_libc { | ||
|
|
||
| lldiv_t lldiv(long long x, long long y); | ||
|
|
||
| } // namespace __llvm_libc | ||
|
|
||
| #endif // LLVM_LIBC_SRC_STDLIB_LDIV_H |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| //===-- Unittests for imaxdiv ---------------------------------------------===// | ||
| // | ||
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #include "../stdlib/DivTest.h" | ||
|
|
||
| #include "src/inttypes/imaxdiv.h" | ||
|
|
||
| #include <inttypes.h> | ||
|
|
||
| LIST_DIV_TESTS(intmax_t, imaxdiv_t, __llvm_libc::imaxdiv) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| //===-- A template class for testing div functions --------------*- C++ -*-===// | ||
| // | ||
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #include "utils/UnitTest/Test.h" | ||
|
|
||
| template <typename IntType, typename ReturnType> | ||
| class DivTest : public __llvm_libc::testing::Test { | ||
| public: | ||
| using DivFunc = ReturnType(IntType, IntType); | ||
|
|
||
| void simpleTest(DivFunc func) { | ||
| auto result = func(10, 3); | ||
| EXPECT_EQ(result.quot, IntType(3)); | ||
| EXPECT_EQ(result.rem, IntType(1)); | ||
|
|
||
| result = func(-10, 3); | ||
| EXPECT_EQ(result.quot, IntType(-3)); | ||
| EXPECT_EQ(result.rem, IntType(-1)); | ||
|
|
||
| result = func(-10, -3); | ||
| EXPECT_EQ(result.quot, IntType(3)); | ||
| EXPECT_EQ(result.rem, IntType(-1)); | ||
|
|
||
| result = func(10, -3); | ||
| EXPECT_EQ(result.quot, IntType(-3)); | ||
| EXPECT_EQ(result.rem, IntType(1)); | ||
| } | ||
| }; | ||
|
|
||
| #define LIST_DIV_TESTS(IntType, ReturnType, func) \ | ||
| using LlvmLibcDivTest = DivTest<IntType, ReturnType>; \ | ||
| TEST_F(LlvmLibcDivTest, SimpleTest) { simpleTest(func); } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| //===-- Unittests for div -------------------------------------------------===// | ||
| // | ||
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #include "DivTest.h" | ||
|
|
||
| #include "src/stdlib/div.h" | ||
|
|
||
| #include <stdlib.h> | ||
|
|
||
| LIST_DIV_TESTS(int, div_t, __llvm_libc::div) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| //===-- Unittests for ldiv ------------------------------------------------===// | ||
| // | ||
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #include "DivTest.h" | ||
|
|
||
| #include "src/stdlib/ldiv.h" | ||
|
|
||
| #include <stdlib.h> | ||
|
|
||
| LIST_DIV_TESTS(long, ldiv_t, __llvm_libc::ldiv) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| //===-- Unittests for lldiv -----------------------------------------------===// | ||
| // | ||
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #include "DivTest.h" | ||
|
|
||
| #include "src/stdlib/lldiv.h" | ||
|
|
||
| #include <stdlib.h> | ||
|
|
||
| LIST_DIV_TESTS(long long, lldiv_t, __llvm_libc::lldiv) |