[llvm-branch-commits] [libc] 0c8466c - [libc][NFC] Use more specific comparison macros in LdExpTest.h.

2021-01-12 Thread Siva Chandra Reddy via llvm-branch-commits

Author: Siva Chandra Reddy
Date: 2021-01-12T16:13:10-08:00
New Revision: 0c8466c0015eb8e4061b177e125e588b2138cc8a

URL: 
https://github.com/llvm/llvm-project/commit/0c8466c0015eb8e4061b177e125e588b2138cc8a
DIFF: 
https://github.com/llvm/llvm-project/commit/0c8466c0015eb8e4061b177e125e588b2138cc8a.diff

LOG: [libc][NFC] Use more specific comparison macros in LdExpTest.h.

Added: 


Modified: 
libc/test/src/math/LdExpTest.h

Removed: 




diff  --git a/libc/test/src/math/LdExpTest.h b/libc/test/src/math/LdExpTest.h
index b4be06bdaad7..0a910bddb371 100644
--- a/libc/test/src/math/LdExpTest.h
+++ b/libc/test/src/math/LdExpTest.h
@@ -131,11 +131,11 @@ class LdExpTestTemplate : public 
__llvm_libc::testing::Test {
 // The result should not be infinity.
 x = NormalFloat(-FPBits::exponentBias + 1, NormalFloat::one >> 10, 0);
 exp = FPBits::maxExponent + 5;
-ASSERT_EQ(isinf(func(x, exp)), 0);
+ASSERT_FALSE(FPBits(func(x, exp)).isInf());
 // But if the exp is large enough to oversome than the normalization shift,
 // then it should result in infinity.
 exp = FPBits::maxExponent + 15;
-ASSERT_NE(isinf(func(x, exp)), 0);
+ASSERT_FP_EQ(func(x, exp), inf);
   }
 };
 



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [libc] bfbbb62 - [libc][NFC] Use ASSERT_EQ instead of EXPECT_EQ in fenv/exception_status_test

2021-01-18 Thread Siva Chandra Reddy via llvm-branch-commits

Author: Siva Chandra Reddy
Date: 2021-01-18T21:38:11-08:00
New Revision: bfbbb62b22f8ba7cabd3b4dece4e72f62b2d972b

URL: 
https://github.com/llvm/llvm-project/commit/bfbbb62b22f8ba7cabd3b4dece4e72f62b2d972b
DIFF: 
https://github.com/llvm/llvm-project/commit/bfbbb62b22f8ba7cabd3b4dece4e72f62b2d972b.diff

LOG: [libc][NFC] Use ASSERT_EQ instead of EXPECT_EQ in 
fenv/exception_status_test

Added: 


Modified: 
libc/test/src/fenv/exception_status_test.cpp

Removed: 




diff  --git a/libc/test/src/fenv/exception_status_test.cpp 
b/libc/test/src/fenv/exception_status_test.cpp
index 193bc58298e1..0706b5525c00 100644
--- a/libc/test/src/fenv/exception_status_test.cpp
+++ b/libc/test/src/fenv/exception_status_test.cpp
@@ -26,28 +26,28 @@ TEST(ExceptionStatusTest, RaiseAndTest) {
FE_UNDERFLOW};
   for (int e : excepts) {
 int r = __llvm_libc::feraiseexcept(e);
-EXPECT_EQ(r, 0);
+ASSERT_EQ(r, 0);
 int s = __llvm_libc::fetestexcept(e);
-EXPECT_EQ(s, e);
+ASSERT_EQ(s, e);
 
 r = __llvm_libc::feclearexcept(e);
-EXPECT_EQ(r, 0);
+ASSERT_EQ(r, 0);
 s = __llvm_libc::fetestexcept(e);
-EXPECT_EQ(s, 0);
+ASSERT_EQ(s, 0);
   }
 
   for (int e1 : excepts) {
 for (int e2 : excepts) {
   int e = e1 | e2;
   int r = __llvm_libc::feraiseexcept(e);
-  EXPECT_EQ(r, 0);
+  ASSERT_EQ(r, 0);
   int s = __llvm_libc::fetestexcept(e);
-  EXPECT_EQ(s, e);
+  ASSERT_EQ(s, e);
 
   r = __llvm_libc::feclearexcept(e);
-  EXPECT_EQ(r, 0);
+  ASSERT_EQ(r, 0);
   s = __llvm_libc::fetestexcept(e);
-  EXPECT_EQ(s, 0);
+  ASSERT_EQ(s, 0);
 }
   }
 
@@ -56,14 +56,14 @@ TEST(ExceptionStatusTest, RaiseAndTest) {
   for (int e3 : excepts) {
 int e = e1 | e2 | e3;
 int r = __llvm_libc::feraiseexcept(e);
-EXPECT_EQ(r, 0);
+ASSERT_EQ(r, 0);
 int s = __llvm_libc::fetestexcept(e);
-EXPECT_EQ(s, e);
+ASSERT_EQ(s, e);
 
 r = __llvm_libc::feclearexcept(e);
-EXPECT_EQ(r, 0);
+ASSERT_EQ(r, 0);
 s = __llvm_libc::fetestexcept(e);
-EXPECT_EQ(s, 0);
+ASSERT_EQ(s, 0);
   }
 }
   }
@@ -74,14 +74,14 @@ TEST(ExceptionStatusTest, RaiseAndTest) {
 for (int e4 : excepts) {
   int e = e1 | e2 | e3 | e4;
   int r = __llvm_libc::feraiseexcept(e);
-  EXPECT_EQ(r, 0);
+  ASSERT_EQ(r, 0);
   int s = __llvm_libc::fetestexcept(e);
-  EXPECT_EQ(s, e);
+  ASSERT_EQ(s, e);
 
   r = __llvm_libc::feclearexcept(e);
-  EXPECT_EQ(r, 0);
+  ASSERT_EQ(r, 0);
   s = __llvm_libc::fetestexcept(e);
-  EXPECT_EQ(s, 0);
+  ASSERT_EQ(s, 0);
 }
   }
 }
@@ -94,14 +94,14 @@ TEST(ExceptionStatusTest, RaiseAndTest) {
   for (int e5 : excepts) {
 int e = e1 | e2 | e3 | e4 | e5;
 int r = __llvm_libc::feraiseexcept(e);
-EXPECT_EQ(r, 0);
+ASSERT_EQ(r, 0);
 int s = __llvm_libc::fetestexcept(e);
-EXPECT_EQ(s, e);
+ASSERT_EQ(s, e);
 
 r = __llvm_libc::feclearexcept(e);
-EXPECT_EQ(r, 0);
+ASSERT_EQ(r, 0);
 s = __llvm_libc::fetestexcept(e);
-EXPECT_EQ(s, 0);
+ASSERT_EQ(s, 0);
   }
 }
   }
@@ -109,7 +109,7 @@ TEST(ExceptionStatusTest, RaiseAndTest) {
   }
 
   int r = __llvm_libc::feraiseexcept(FE_ALL_EXCEPT);
-  EXPECT_EQ(r, 0);
+  ASSERT_EQ(r, 0);
   int s = __llvm_libc::fetestexcept(FE_ALL_EXCEPT);
-  EXPECT_EQ(s, FE_ALL_EXCEPT);
+  ASSERT_EQ(s, FE_ALL_EXCEPT);
 }



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [libc] ff6fd38 - [libc] Add implementations of rounding functions which depend rounding mode.

2020-12-29 Thread Siva Chandra Reddy via llvm-branch-commits

Author: Siva Chandra Reddy
Date: 2020-12-29T22:22:02-08:00
New Revision: ff6fd3855244bc90094e7de3f07853a5971cf8ef

URL: 
https://github.com/llvm/llvm-project/commit/ff6fd3855244bc90094e7de3f07853a5971cf8ef
DIFF: 
https://github.com/llvm/llvm-project/commit/ff6fd3855244bc90094e7de3f07853a5971cf8ef.diff

LOG: [libc] Add implementations of rounding functions which depend rounding 
mode.

Namely, implementations for rint, rintf, rintl, lrint, lrintf, lrintl,
llrint, llrintf and llrintl have been added.

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D93889

Added: 
libc/src/math/llrint.cpp
libc/src/math/llrint.h
libc/src/math/llrintf.cpp
libc/src/math/llrintf.h
libc/src/math/llrintl.cpp
libc/src/math/llrintl.h
libc/src/math/lrint.cpp
libc/src/math/lrint.h
libc/src/math/lrintf.cpp
libc/src/math/lrintf.h
libc/src/math/lrintl.cpp
libc/src/math/lrintl.h
libc/src/math/rint.cpp
libc/src/math/rint.h
libc/src/math/rintf.cpp
libc/src/math/rintf.h
libc/src/math/rintl.cpp
libc/src/math/rintl.h
libc/test/src/math/RIntTest.h
libc/test/src/math/llrint_test.cpp
libc/test/src/math/llrintf_test.cpp
libc/test/src/math/llrintl_test.cpp
libc/test/src/math/lrint_test.cpp
libc/test/src/math/lrintf_test.cpp
libc/test/src/math/lrintl_test.cpp
libc/test/src/math/rint_test.cpp
libc/test/src/math/rintf_test.cpp
libc/test/src/math/rintl_test.cpp

Modified: 
libc/config/linux/x86_64/entrypoints.txt
libc/spec/stdc.td
libc/src/math/CMakeLists.txt
libc/test/src/math/CMakeLists.txt
libc/test/src/math/RoundToIntegerTest.h
libc/utils/FPUtil/NearestIntegerOperations.h
libc/utils/MPFRWrapper/MPFRUtils.cpp
libc/utils/MPFRWrapper/MPFRUtils.h

Removed: 




diff  --git a/libc/config/linux/x86_64/entrypoints.txt 
b/libc/config/linux/x86_64/entrypoints.txt
index d5a2f295d9d9..8e430afbcfc8 100644
--- a/libc/config/linux/x86_64/entrypoints.txt
+++ b/libc/config/linux/x86_64/entrypoints.txt
@@ -123,12 +123,18 @@ set(TARGET_LIBM_ENTRYPOINTS
 libc.src.math.ldexp
 libc.src.math.ldexpf
 libc.src.math.ldexpl
+libc.src.math.llrint
+libc.src.math.llrintf
+libc.src.math.llrintl
 libc.src.math.llround
 libc.src.math.llroundf
 libc.src.math.llroundl
 libc.src.math.logb
 libc.src.math.logbf
 libc.src.math.logbl
+libc.src.math.lrint
+libc.src.math.lrintf
+libc.src.math.lrintl
 libc.src.math.lround
 libc.src.math.lroundf
 libc.src.math.lroundl
@@ -141,6 +147,9 @@ set(TARGET_LIBM_ENTRYPOINTS
 libc.src.math.remquof
 libc.src.math.remquo
 libc.src.math.remquol
+libc.src.math.rint
+libc.src.math.rintf
+libc.src.math.rintl
 libc.src.math.round
 libc.src.math.roundf
 libc.src.math.roundl

diff  --git a/libc/spec/stdc.td b/libc/spec/stdc.td
index aca9a1020b1e..0eea8e55701f 100644
--- a/libc/spec/stdc.td
+++ b/libc/spec/stdc.td
@@ -371,6 +371,18 @@ def StdC : StandardSpec<"stdc"> {
   FunctionSpec<"llroundf", RetValSpec, 
[ArgSpec]>,
   FunctionSpec<"llroundl", RetValSpec, 
[ArgSpec]>,
 
+  FunctionSpec<"rint", RetValSpec, [ArgSpec]>,
+  FunctionSpec<"rintf", RetValSpec, [ArgSpec]>,
+  FunctionSpec<"rintl", RetValSpec, 
[ArgSpec]>,
+
+  FunctionSpec<"lrint", RetValSpec, [ArgSpec]>,
+  FunctionSpec<"lrintf", RetValSpec, [ArgSpec]>,
+  FunctionSpec<"lrintl", RetValSpec, 
[ArgSpec]>,
+
+  FunctionSpec<"llrint", RetValSpec, 
[ArgSpec]>,
+  FunctionSpec<"llrintf", RetValSpec, 
[ArgSpec]>,
+  FunctionSpec<"llrintl", RetValSpec, 
[ArgSpec]>,
+
   FunctionSpec<"sqrt", RetValSpec, [ArgSpec]>,
   FunctionSpec<"sqrtf", RetValSpec, [ArgSpec]>,
   FunctionSpec<"sqrtl", RetValSpec, 
[ArgSpec]>,

diff  --git a/libc/src/math/CMakeLists.txt b/libc/src/math/CMakeLists.txt
index c4de1b1eae86..ff9d79131a60 100644
--- a/libc/src/math/CMakeLists.txt
+++ b/libc/src/math/CMakeLists.txt
@@ -308,6 +308,114 @@ add_entrypoint_object(
 -O2
 )
 
+add_entrypoint_object(
+  rint
+  SRCS
+rint.cpp
+  HDRS
+rint.h
+  DEPENDS
+libc.utils.FPUtil.fputil
+  COMPILE_OPTIONS
+-O2
+)
+
+add_entrypoint_object(
+  rintf
+  SRCS
+rintf.cpp
+  HDRS
+rintf.h
+  DEPENDS
+libc.utils.FPUtil.fputil
+  COMPILE_OPTIONS
+-O2
+)
+
+add_entrypoint_object(
+  rintl
+  SRCS
+rintl.cpp
+  HDRS
+rintl.h
+  DEPENDS
+libc.utils.FPUtil.fputil
+  COMPILE_OPTIONS
+-O2
+)
+
+add_entrypoint_object(
+  lrint
+  SRCS
+lrint.cpp
+  HDRS
+lrint.h
+  DEPENDS
+libc.utils.FPUtil.fputil
+  COMPILE_OPTIONS
+-O2
+)
+
+add_entrypoint_object(
+  lrintf
+  SRCS
+lrintf.cpp
+  HDRS
+lrintf.h
+  DEPENDS
+libc.utils.FPUtil.fputil
+  COMPILE_OPTIONS
+-O2
+)
+
+add_entrypoint_object(
+  lrintl
+  SRCS
+lrintl.

[llvm-branch-commits] [libc] cc07d52 - [libc][NFC] Use ASSERT_FP_EQ to compare nan values in tests.

2020-12-30 Thread Siva Chandra Reddy via llvm-branch-commits

Author: Siva Chandra Reddy
Date: 2020-12-30T13:06:40-08:00
New Revision: cc07d5251144e12cc089748ec66af0423ba57ad1

URL: 
https://github.com/llvm/llvm-project/commit/cc07d5251144e12cc089748ec66af0423ba57ad1
DIFF: 
https://github.com/llvm/llvm-project/commit/cc07d5251144e12cc089748ec66af0423ba57ad1.diff

LOG: [libc][NFC] Use ASSERT_FP_EQ to compare nan values in tests.

This change "fixes" one of the uses that was missed in
0524da67b448dcce6569fae0f54c10f208c2dc56.

Added: 


Modified: 
libc/test/src/math/RemQuoTest.h

Removed: 




diff  --git a/libc/test/src/math/RemQuoTest.h b/libc/test/src/math/RemQuoTest.h
index 66f2f0956348..1e00ee14927e 100644
--- a/libc/test/src/math/RemQuoTest.h
+++ b/libc/test/src/math/RemQuoTest.h
@@ -123,7 +123,7 @@ class RemQuoTestTemplate : public 
__llvm_libc::testing::Test {
   // In normal range on x86 platforms, the long double implicit 1 bit can 
be
   // zero making the numbers NaN. Hence we test for them separately.
   if (isnan(x) || isnan(y)) {
-ASSERT_NE(isnan(result.f), 0);
+ASSERT_FP_EQ(result.f, nan);
 continue;
   }
 



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [libc] 993d8ac - [libc] Add implementations of nearbyint[f|l].

2021-01-05 Thread Siva Chandra Reddy via llvm-branch-commits

Author: Siva Chandra Reddy
Date: 2021-01-05T21:51:10-08:00
New Revision: 993d8ac5cb935b78fb136c25a7e4bae18852f429

URL: 
https://github.com/llvm/llvm-project/commit/993d8ac5cb935b78fb136c25a7e4bae18852f429
DIFF: 
https://github.com/llvm/llvm-project/commit/993d8ac5cb935b78fb136c25a7e4bae18852f429.diff

LOG: [libc] Add implementations of nearbyint[f|l].

The implementation is exactly the same as rint* as even rint does not
raise any floating point exceptions currently. [Note that the standards
do not specify that floating point exceptions must be raised - they
leave it up to the implementation to choose to raise FE_INEXACT when
rounding non-integral values.]

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D94112

Added: 
libc/src/math/nearbyint.cpp
libc/src/math/nearbyint.h
libc/src/math/nearbyintf.cpp
libc/src/math/nearbyintf.h
libc/src/math/nearbyintl.cpp
libc/src/math/nearbyintl.h

Modified: 
libc/config/linux/x86_64/entrypoints.txt
libc/spec/stdc.td
libc/src/math/CMakeLists.txt

Removed: 




diff  --git a/libc/config/linux/x86_64/entrypoints.txt 
b/libc/config/linux/x86_64/entrypoints.txt
index 8e430afbcfc8..45571ee85d49 100644
--- a/libc/config/linux/x86_64/entrypoints.txt
+++ b/libc/config/linux/x86_64/entrypoints.txt
@@ -141,6 +141,9 @@ set(TARGET_LIBM_ENTRYPOINTS
 libc.src.math.modf
 libc.src.math.modff
 libc.src.math.modfl
+libc.src.math.nearbyint
+libc.src.math.nearbyintf
+libc.src.math.nearbyintl
 libc.src.math.remainderf
 libc.src.math.remainder
 libc.src.math.remainderl

diff  --git a/libc/spec/stdc.td b/libc/spec/stdc.td
index 0eea8e55701f..355321c4025d 100644
--- a/libc/spec/stdc.td
+++ b/libc/spec/stdc.td
@@ -390,6 +390,10 @@ def StdC : StandardSpec<"stdc"> {
   FunctionSpec<"trunc", RetValSpec, [ArgSpec]>,
   FunctionSpec<"truncf", RetValSpec, [ArgSpec]>,
   FunctionSpec<"truncl", RetValSpec, 
[ArgSpec]>,
+
+  FunctionSpec<"nearbyint", RetValSpec, 
[ArgSpec]>,
+  FunctionSpec<"nearbyintf", RetValSpec, 
[ArgSpec]>,
+  FunctionSpec<"nearbyintl", RetValSpec, 
[ArgSpec]>,
   ]
   >;
 

diff  --git a/libc/src/math/CMakeLists.txt b/libc/src/math/CMakeLists.txt
index ff9d79131a60..aa4b4a5d4a79 100644
--- a/libc/src/math/CMakeLists.txt
+++ b/libc/src/math/CMakeLists.txt
@@ -416,6 +416,42 @@ add_entrypoint_object(
 -O2
 )
 
+add_entrypoint_object(
+  nearbyint
+  SRCS
+nearbyint.cpp
+  HDRS
+nearbyint.h
+  DEPENDS
+libc.utils.FPUtil.fputil
+  COMPILE_OPTIONS
+-O2
+)
+
+add_entrypoint_object(
+  nearbyintf
+  SRCS
+nearbyintf.cpp
+  HDRS
+nearbyintf.h
+  DEPENDS
+libc.utils.FPUtil.fputil
+  COMPILE_OPTIONS
+-O2
+)
+
+add_entrypoint_object(
+  nearbyintl
+  SRCS
+nearbyintl.cpp
+  HDRS
+nearbyintl.h
+  DEPENDS
+libc.utils.FPUtil.fputil
+  COMPILE_OPTIONS
+-O2
+)
+
 add_object_library(
   exp_utils
   HDRS

diff  --git a/libc/src/math/nearbyint.cpp b/libc/src/math/nearbyint.cpp
new file mode 100644
index ..0938952752dd
--- /dev/null
+++ b/libc/src/math/nearbyint.cpp
@@ -0,0 +1,18 @@
+//===-- Implementation of nearbyint function 
--===//
+//
+// 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/__support/common.h"
+#include "utils/FPUtil/NearestIntegerOperations.h"
+
+namespace __llvm_libc {
+
+double LLVM_LIBC_ENTRYPOINT(nearbyint)(double x) {
+  return fputil::roundUsingCurrentRoundingMode(x);
+}
+
+} // namespace __llvm_libc

diff  --git a/libc/src/math/nearbyint.h b/libc/src/math/nearbyint.h
new file mode 100644
index ..957a06b97921
--- /dev/null
+++ b/libc/src/math/nearbyint.h
@@ -0,0 +1,18 @@
+//===-- Implementation header for nearbyint -*- 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
+//
+//===--===//
+
+#ifndef LLVM_LIBC_SRC_MATH_NEARBYINT_H
+#define LLVM_LIBC_SRC_MATH_NEARBYINT_H
+
+namespace __llvm_libc {
+
+double nearbyint(double x);
+
+} // namespace __llvm_libc
+
+#endif // LLVM_LIBC_SRC_MATH_NEARBYINT_H

diff  --git a/libc/src/math/nearbyintf.cpp b/libc/src/math/nearbyintf.cpp
new file mode 100644
index ..cc19da6f3814
--- /dev/null
+++ b/libc/src/math/nearbyintf.cpp
@@ -0,0 +1,18 @@
+//===-- Implementation of nearbyintf function 
-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 

[llvm-branch-commits] [libc] 7f7b0dc - [libc] Add implementations of nextafter[f|l] functions.

2021-01-05 Thread Siva Chandra Reddy via llvm-branch-commits

Author: Siva Chandra Reddy
Date: 2021-01-05T22:32:39-08:00
New Revision: 7f7b0dc4e15fac5f91f8f6dcc7f91c9025f41ae0

URL: 
https://github.com/llvm/llvm-project/commit/7f7b0dc4e15fac5f91f8f6dcc7f91c9025f41ae0
DIFF: 
https://github.com/llvm/llvm-project/commit/7f7b0dc4e15fac5f91f8f6dcc7f91c9025f41ae0.diff

LOG: [libc] Add implementations of nextafter[f|l] functions.

A differential fuzzer for these functions has also been added.
Along the way, a small correction has been done to the normal/subnormal
limits of x86 long double values.

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D94109

Added: 
libc/fuzzing/math/nextafter_differential_fuzz.cpp
libc/src/math/nextafter.cpp
libc/src/math/nextafter.h
libc/src/math/nextafterf.cpp
libc/src/math/nextafterf.h
libc/src/math/nextafterl.cpp
libc/src/math/nextafterl.h
libc/test/src/math/NextAfterTest.h
libc/test/src/math/nextafter_test.cpp
libc/test/src/math/nextafterf_test.cpp
libc/test/src/math/nextafterl_test.cpp
libc/utils/FPUtil/NextAfterLongDoubleX86.h

Modified: 
libc/config/linux/aarch64/entrypoints.txt
libc/config/linux/x86_64/entrypoints.txt
libc/fuzzing/math/CMakeLists.txt
libc/fuzzing/math/Compare.h
libc/spec/stdc.td
libc/src/math/CMakeLists.txt
libc/test/src/math/CMakeLists.txt
libc/utils/FPUtil/LongDoubleBitsX86.h
libc/utils/FPUtil/ManipulationFunctions.h

Removed: 




diff  --git a/libc/config/linux/aarch64/entrypoints.txt 
b/libc/config/linux/aarch64/entrypoints.txt
index 67e2b72aa1af..b9042625e666 100644
--- a/libc/config/linux/aarch64/entrypoints.txt
+++ b/libc/config/linux/aarch64/entrypoints.txt
@@ -88,6 +88,9 @@ set(TARGET_LIBM_ENTRYPOINTS
 libc.src.math.modf
 libc.src.math.modff
 libc.src.math.modfl
+libc.src.math.nextafter
+libc.src.math.nextafterf
+libc.src.math.nextafterl
 libc.src.math.remainderf
 libc.src.math.remainder
 libc.src.math.remainderl

diff  --git a/libc/config/linux/x86_64/entrypoints.txt 
b/libc/config/linux/x86_64/entrypoints.txt
index 45571ee85d49..a34c59646149 100644
--- a/libc/config/linux/x86_64/entrypoints.txt
+++ b/libc/config/linux/x86_64/entrypoints.txt
@@ -144,6 +144,9 @@ set(TARGET_LIBM_ENTRYPOINTS
 libc.src.math.nearbyint
 libc.src.math.nearbyintf
 libc.src.math.nearbyintl
+libc.src.math.nextafter
+libc.src.math.nextafterf
+libc.src.math.nextafterl
 libc.src.math.remainderf
 libc.src.math.remainder
 libc.src.math.remainderl

diff  --git a/libc/fuzzing/math/CMakeLists.txt 
b/libc/fuzzing/math/CMakeLists.txt
index 7c710fcecfdb..af9a5d30765e 100644
--- a/libc/fuzzing/math/CMakeLists.txt
+++ b/libc/fuzzing/math/CMakeLists.txt
@@ -48,3 +48,15 @@ add_libc_fuzzer(
 libc.utils.FPUtil.fputil
 libc.utils.CPP.standalone_cpp
 )
+
+add_libc_fuzzer(
+  nextafter_
diff erential_fuzz
+  SRCS
+nextafter_
diff erential_fuzz.cpp
+  HDRS
+TwoInputSingleOutputDiff.h
+  DEPENDS
+libc.src.math.nextafter
+libc.src.math.nextafterf
+libc.src.math.nextafterl
+)

diff  --git a/libc/fuzzing/math/Compare.h b/libc/fuzzing/math/Compare.h
index 62ab6c791070..11d54650f66f 100644
--- a/libc/fuzzing/math/Compare.h
+++ b/libc/fuzzing/math/Compare.h
@@ -10,6 +10,7 @@
 #define LLVM_LIBC_FUZZING_MATH_COMPARE_H
 
 #include "utils/CPP/TypeTraits.h"
+#include "utils/FPUtil/FPBits.h"
 
 template 
 __llvm_libc::cpp::EnableIfType<__llvm_libc::cpp::IsFloatingPointType::Value,

diff  --git a/libc/fuzzing/math/nextafter_
diff erential_fuzz.cpp b/libc/fuzzing/math/nextafter_
diff erential_fuzz.cpp
new file mode 100644
index ..f4a7891df2aa
--- /dev/null
+++ b/libc/fuzzing/math/nextafter_
diff erential_fuzz.cpp
@@ -0,0 +1,26 @@
+//===-- nextafter_
diff erential_fuzz.cpp
+//---===//
+//
+// 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
+//
+//===--===//
+///
+/// Differential fuzz test for llvm-libc nextafter implementation.
+///
+//===--===//
+
+#include "fuzzing/math/TwoInputSingleOutputDiff.h"
+
+#include "src/math/nextafter.h"
+#include "src/math/nextafterf.h"
+#include "src/math/nextafterl.h"
+
+extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
+  TwoInputSingleOutputDiff(&__llvm_libc::nextafterf,
+ &::nextafterf, data, size);
+  TwoInputSingleOutputDiff(&__llvm_libc::nextafter,
+   &::nextafter, data, size);
+  return 0;
+}

diff  --git a/libc/spec/stdc.td b/libc/spec/stdc.td
index 355321c4025d..41f6083a2336 100644
--- a/libc/spec/stdc.td
+++ b/l

[llvm-branch-commits] [libc] f9e858f - [libc] Use a wrapper for rand instead of calling std::rand in fma tests.

2021-01-06 Thread Siva Chandra Reddy via llvm-branch-commits

Author: Siva Chandra Reddy
Date: 2021-01-06T15:07:44-08:00
New Revision: f9e858f5fd74d0a1b127bf8979dc36bcad8b06d2

URL: 
https://github.com/llvm/llvm-project/commit/f9e858f5fd74d0a1b127bf8979dc36bcad8b06d2
DIFF: 
https://github.com/llvm/llvm-project/commit/f9e858f5fd74d0a1b127bf8979dc36bcad8b06d2.diff

LOG: [libc] Use a wrapper for rand instead of calling std::rand in fma tests.

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D94198

Added: 
libc/utils/testutils/RandUtils.cpp
libc/utils/testutils/RandUtils.h

Modified: 
libc/test/src/math/FmaTest.h
libc/utils/testutils/CMakeLists.txt

Removed: 




diff  --git a/libc/test/src/math/FmaTest.h b/libc/test/src/math/FmaTest.h
index c39c4ad0f1da..9f90c8627af9 100644
--- a/libc/test/src/math/FmaTest.h
+++ b/libc/test/src/math/FmaTest.h
@@ -13,8 +13,7 @@
 #include "utils/FPUtil/TestHelpers.h"
 #include "utils/MPFRWrapper/MPFRUtils.h"
 #include "utils/UnitTest/Test.h"
-
-#include 
+#include "utils/testutils/RandUtils.h"
 
 namespace mpfr = __llvm_libc::testing::mpfr;
 
@@ -32,8 +31,9 @@ class FmaTestTemplate : public __llvm_libc::testing::Test {
 
   UIntType getRandomBitPattern() {
 UIntType bits{0};
-for (size_t i = 0; i < sizeof(UIntType) / 2; ++i) {
-  bits = (bits << 2) + static_cast(std::rand());
+for (UIntType i = 0; i < sizeof(UIntType) / 2; ++i) {
+  bits =
+  (bits << 2) + static_cast(__llvm_libc::testutils::rand());
 }
 return bits;
   }

diff  --git a/libc/utils/testutils/CMakeLists.txt 
b/libc/utils/testutils/CMakeLists.txt
index 70237ddc1f8d..c39a8399895d 100644
--- a/libc/utils/testutils/CMakeLists.txt
+++ b/libc/utils/testutils/CMakeLists.txt
@@ -5,6 +5,8 @@ endif()
 
 add_llvm_library(
   libc_test_utils
+  RandUtils.cpp
+  RandUtils.h
   StreamWrapper.cpp
   StreamWrapper.h
   ${EFFile}

diff  --git a/libc/utils/testutils/RandUtils.cpp 
b/libc/utils/testutils/RandUtils.cpp
new file mode 100644
index ..0ccc62327f05
--- /dev/null
+++ b/libc/utils/testutils/RandUtils.cpp
@@ -0,0 +1,19 @@
+//===-- RandUtils.cpp 
-===//
+//
+// 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 "RandUtils.h"
+
+#include 
+
+namespace __llvm_libc {
+namespace testutils {
+
+int rand() { return std::rand(); }
+
+} // namespace testutils
+} // namespace __llvm_libc

diff  --git a/libc/utils/testutils/RandUtils.h 
b/libc/utils/testutils/RandUtils.h
new file mode 100644
index ..b65a98bfed21
--- /dev/null
+++ b/libc/utils/testutils/RandUtils.h
@@ -0,0 +1,16 @@
+//===-- RandUtils.h -*- 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
+//
+//===--===//
+
+namespace __llvm_libc {
+namespace testutils {
+
+// Wrapper for std::rand.
+int rand();
+
+} // namespace testutils
+} // namespace __llvm_libc



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [libc] aefeb5f - [libc][NFC] Make __support/common.h an in tree header.

2021-01-11 Thread Siva Chandra Reddy via llvm-branch-commits

Author: Siva Chandra Reddy
Date: 2021-01-11T13:10:56-08:00
New Revision: aefeb5f136e7b72b251ce2881cb39a1fe8f0d76a

URL: 
https://github.com/llvm/llvm-project/commit/aefeb5f136e7b72b251ce2881cb39a1fe8f0d76a
DIFF: 
https://github.com/llvm/llvm-project/commit/aefeb5f136e7b72b251ce2881cb39a1fe8f0d76a.diff

LOG: [libc][NFC] Make __support/common.h an in tree header.

It was previously a generated header. It can easily converted to a
generated header if required in future.

Reviewed By: michaelrj

Differential Revision: https://reviews.llvm.org/D94445

Added: 
libc/src/__support/common.h

Modified: 
libc/src/__support/CMakeLists.txt

Removed: 
libc/src/__support/common.h.def



diff  --git a/libc/src/__support/CMakeLists.txt 
b/libc/src/__support/CMakeLists.txt
index e9f9579b6d0f..980b510e374c 100644
--- a/libc/src/__support/CMakeLists.txt
+++ b/libc/src/__support/CMakeLists.txt
@@ -1,9 +1,5 @@
-add_gen_header(
+add_header_library(
   common
-  DEF_FILE common.h.def
-  PARAMS
-platform_defs=../../config/${LIBC_TARGET_OS}/platform_defs.h.inc
-  GEN_HDR common.h
-  DATA_FILES
-../../config/${LIBC_TARGET_OS}/platform_defs.h.inc
+  HDRS
+common.h
 )

diff  --git a/libc/src/__support/common.h.def b/libc/src/__support/common.h
similarity index 54%
rename from libc/src/__support/common.h.def
rename to libc/src/__support/common.h
index d2d18c696dff..208c8bdfea41 100644
--- a/libc/src/__support/common.h.def
+++ b/libc/src/__support/common.h
@@ -11,22 +11,22 @@
 
 #define LIBC_INLINE_ASM __asm__ __volatile__
 
-#define likely(x) __builtin_expect (!!(x), 1)
-#define unlikely(x) __builtin_expect (x, 0)
+#define likely(x) __builtin_expect(!!(x), 1)
+#define unlikely(x) __builtin_expect(x, 0)
 #define UNUSED __attribute__((unused))
 
 #ifndef LLVM_LIBC_FUNCTION_ATTR
-  #define LLVM_LIBC_FUNCTION_ATTR
+#define LLVM_LIBC_FUNCTION_ATTR
 #endif
 
 #ifdef LLVM_LIBC_PUBLIC_PACKAGING
-#define LLVM_LIBC_FUNCTION(type, name, arglist) \
-  LLVM_LIBC_FUNCTION_ATTR decltype(__llvm_libc::name) __##name##_impl__ 
__asm__(#name); \
-  decltype(__llvm_libc::name) name [[gnu::alias(#name)]]; \
-  type __##name##_impl__ arglist
+#define LLVM_LIBC_FUNCTION(type, name, arglist)
\
+  LLVM_LIBC_FUNCTION_ATTR decltype(__llvm_libc::name)  
\
+  __##name##_impl__ __asm__(#name);
\
+  decltype(__llvm_libc::name) name [[gnu::alias(#name)]];  
\
+  type __##name##_impl__ arglist
 #else
-#define LLVM_LIBC_FUNCTION(type, name, arglist)\
-  type name arglist
+#define LLVM_LIBC_FUNCTION(type, name, arglist) type name arglist
 #endif
 
 #endif // LLVM_LIBC_SUPPORT_COMMON_H



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [libc] b266c81 - [libc][Obvious] Mark functions in DummyFEnv.h as static inline.

2020-12-14 Thread Siva Chandra Reddy via llvm-branch-commits

Author: Siva Chandra Reddy
Date: 2020-12-14T17:12:54-08:00
New Revision: b266c818e7cb30464a7bb9e5f8241375ac1722b1

URL: 
https://github.com/llvm/llvm-project/commit/b266c818e7cb30464a7bb9e5f8241375ac1722b1
DIFF: 
https://github.com/llvm/llvm-project/commit/b266c818e7cb30464a7bb9e5f8241375ac1722b1.diff

LOG: [libc][Obvious] Mark functions in DummyFEnv.h as static inline.

Added: 


Modified: 
libc/utils/FPUtil/DummyFEnv.h

Removed: 




diff  --git a/libc/utils/FPUtil/DummyFEnv.h b/libc/utils/FPUtil/DummyFEnv.h
index 4f4c2c05a231..19c661fd23eb 100644
--- a/libc/utils/FPUtil/DummyFEnv.h
+++ b/libc/utils/FPUtil/DummyFEnv.h
@@ -17,15 +17,15 @@ namespace fputil {
 
 // All dummy functions silently succeed.
 
-int clearExcept(int) { return 0; }
+static inline int clearExcept(int) { return 0; }
 
-int testExcept(int) { return 0; }
+static inline int testExcept(int) { return 0; }
 
-int raiseExcept(int) { return 0; }
+static inline int raiseExcept(int) { return 0; }
 
-int getRound() { return FE_TONEAREST; }
+static inline int getRound() { return FE_TONEAREST; }
 
-int setRound(int) { return 0; }
+static inline int setRound(int) { return 0; }
 
 } // namespace fputil
 } // namespace __llvm_libc



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [libc] cee1e7d - [libc][NFC][Obvious] Remove few unnecessary #include directives in tests.

2020-12-15 Thread Siva Chandra Reddy via llvm-branch-commits

Author: Siva Chandra Reddy
Date: 2020-12-15T21:41:44-08:00
New Revision: cee1e7d14f4628d6174b33640d502bff3b54ae45

URL: 
https://github.com/llvm/llvm-project/commit/cee1e7d14f4628d6174b33640d502bff3b54ae45
DIFF: 
https://github.com/llvm/llvm-project/commit/cee1e7d14f4628d6174b33640d502bff3b54ae45.diff

LOG: [libc][NFC][Obvious] Remove few unnecessary #include directives in tests.

Added: 


Modified: 
libc/test/src/math/HypotTest.h
libc/test/src/math/RoundToIntegerTest.h
libc/test/src/math/hypot_test.cpp
libc/test/src/math/hypotf_test.cpp
libc/test/src/math/ldexp_test.cpp
libc/test/src/math/ldexpf_test.cpp
libc/test/src/math/ldexpl_test.cpp
libc/test/src/math/llround_test.cpp
libc/test/src/math/llroundf_test.cpp
libc/test/src/math/llroundl_test.cpp
libc/test/src/math/lround_test.cpp
libc/test/src/math/lroundf_test.cpp
libc/test/src/math/lroundl_test.cpp
libc/test/utils/FPUtil/x86_long_double_test.cpp
libc/utils/FPUtil/ManipulationFunctions.h

Removed: 




diff  --git a/libc/test/src/math/HypotTest.h b/libc/test/src/math/HypotTest.h
index f90807b62c5f..34b1ff6a08b6 100644
--- a/libc/test/src/math/HypotTest.h
+++ b/libc/test/src/math/HypotTest.h
@@ -9,13 +9,14 @@
 #ifndef LLVM_LIBC_TEST_SRC_MATH_HYPOTTEST_H
 #define LLVM_LIBC_TEST_SRC_MATH_HYPOTTEST_H
 
-#include "include/math.h"
 #include "utils/FPUtil/FPBits.h"
 #include "utils/FPUtil/Hypot.h"
 #include "utils/FPUtil/TestHelpers.h"
 #include "utils/MPFRWrapper/MPFRUtils.h"
 #include "utils/UnitTest/Test.h"
 
+#include 
+
 namespace mpfr = __llvm_libc::testing::mpfr;
 
 template 

diff  --git a/libc/test/src/math/RoundToIntegerTest.h 
b/libc/test/src/math/RoundToIntegerTest.h
index 7c0605ebcadd..37b42f385247 100644
--- a/libc/test/src/math/RoundToIntegerTest.h
+++ b/libc/test/src/math/RoundToIntegerTest.h
@@ -13,7 +13,6 @@
 #include "src/fenv/feclearexcept.h"
 #include "src/fenv/feraiseexcept.h"
 #include "src/fenv/fetestexcept.h"
-#include "utils/CPP/TypeTraits.h"
 #include "utils/FPUtil/FPBits.h"
 #include "utils/MPFRWrapper/MPFRUtils.h"
 #include "utils/UnitTest/Test.h"

diff  --git a/libc/test/src/math/hypot_test.cpp 
b/libc/test/src/math/hypot_test.cpp
index d723f5264afc..0607dbdcb6eb 100644
--- a/libc/test/src/math/hypot_test.cpp
+++ b/libc/test/src/math/hypot_test.cpp
@@ -8,7 +8,6 @@
 
 #include "HypotTest.h"
 
-#include "include/math.h"
 #include "src/math/hypot.h"
 
 using HypotTest = HypotTestTemplate;

diff  --git a/libc/test/src/math/hypotf_test.cpp 
b/libc/test/src/math/hypotf_test.cpp
index 21d1bea03291..864e56602d27 100644
--- a/libc/test/src/math/hypotf_test.cpp
+++ b/libc/test/src/math/hypotf_test.cpp
@@ -8,7 +8,6 @@
 
 #include "HypotTest.h"
 
-#include "include/math.h"
 #include "src/math/hypotf.h"
 
 using HypotfTest = HypotTestTemplate;

diff  --git a/libc/test/src/math/ldexp_test.cpp 
b/libc/test/src/math/ldexp_test.cpp
index 0f5974c018f7..c078aa4b7ef8 100644
--- a/libc/test/src/math/ldexp_test.cpp
+++ b/libc/test/src/math/ldexp_test.cpp
@@ -8,14 +8,6 @@
 
 #include "LdExpTest.h"
 
-#include "include/math.h"
 #include "src/math/ldexp.h"
-#include "utils/CPP/Functional.h"
-#include "utils/FPUtil/FPBits.h"
-#include "utils/FPUtil/ManipulationFunctions.h"
-#include "utils/FPUtil/TestHelpers.h"
-#include "utils/UnitTest/Test.h"
-
-#include 
 
 LIST_LDEXP_TESTS(double, __llvm_libc::ldexp)

diff  --git a/libc/test/src/math/ldexpf_test.cpp 
b/libc/test/src/math/ldexpf_test.cpp
index d9a44b3f4125..4fe80fc79151 100644
--- a/libc/test/src/math/ldexpf_test.cpp
+++ b/libc/test/src/math/ldexpf_test.cpp
@@ -8,14 +8,6 @@
 
 #include "LdExpTest.h"
 
-#include "include/math.h"
 #include "src/math/ldexpf.h"
-#include "utils/CPP/Functional.h"
-#include "utils/FPUtil/FPBits.h"
-#include "utils/FPUtil/ManipulationFunctions.h"
-#include "utils/FPUtil/TestHelpers.h"
-#include "utils/UnitTest/Test.h"
-
-#include 
 
 LIST_LDEXP_TESTS(float, __llvm_libc::ldexpf)

diff  --git a/libc/test/src/math/ldexpl_test.cpp 
b/libc/test/src/math/ldexpl_test.cpp
index 69444b6edbaf..5e6e6e75ae08 100644
--- a/libc/test/src/math/ldexpl_test.cpp
+++ b/libc/test/src/math/ldexpl_test.cpp
@@ -8,14 +8,6 @@
 
 #include "LdExpTest.h"
 
-#include "include/math.h"
 #include "src/math/ldexpl.h"
-#include "utils/CPP/Functional.h"
-#include "utils/FPUtil/FPBits.h"
-#include "utils/FPUtil/ManipulationFunctions.h"
-#include "utils/FPUtil/TestHelpers.h"
-#include "utils/UnitTest/Test.h"
-
-#include 
 
 LIST_LDEXP_TESTS(long double, __llvm_libc::ldexpl)

diff  --git a/libc/test/src/math/llround_test.cpp 
b/libc/test/src/math/llround_test.cpp
index e7d5b9006621..c86095dc9aae 100644
--- a/libc/test/src/math/llround_test.cpp
+++ b/libc/test/src/math/llround_test.cpp
@@ -8,7 +8,6 @@
 
 #include "RoundToIntegerTest.h"
 
-#include "include/math.h"
 #include "src/math/llround.h"
 
 LIST_ROUND_TO_INTEGER_TESTS(double, long long, __llvm_libc::llround)

di

[llvm-branch-commits] [libc] f66cf13 - [libc][NFC] Rename global `nan` in tests to `aNaN`.

2020-12-15 Thread Siva Chandra Reddy via llvm-branch-commits

Author: Siva Chandra Reddy
Date: 2020-12-15T22:37:02-08:00
New Revision: f66cf13d5d0bc4099d452088c03fd6705aae2bc7

URL: 
https://github.com/llvm/llvm-project/commit/f66cf13d5d0bc4099d452088c03fd6705aae2bc7
DIFF: 
https://github.com/llvm/llvm-project/commit/f66cf13d5d0bc4099d452088c03fd6705aae2bc7.diff

LOG: [libc][NFC] Rename global `nan` in tests to `aNaN`.

The name `nan` conflicts with the function `nan` defined declared in
math.h.

Added: 


Modified: 
libc/test/src/math/ceil_test.cpp
libc/test/src/math/ceilf_test.cpp
libc/test/src/math/ceill_test.cpp
libc/test/src/math/copysign_test.cpp
libc/test/src/math/copysignf_test.cpp
libc/test/src/math/copysignl_test.cpp
libc/test/src/math/fabs_test.cpp
libc/test/src/math/fabsf_test.cpp
libc/test/src/math/fabsl_test.cpp
libc/test/src/math/floor_test.cpp
libc/test/src/math/floorf_test.cpp
libc/test/src/math/floorl_test.cpp
libc/test/src/math/fmax_test.cpp
libc/test/src/math/fmaxf_test.cpp
libc/test/src/math/fmaxl_test.cpp
libc/test/src/math/fmin_test.cpp
libc/test/src/math/fminf_test.cpp
libc/test/src/math/fminl_test.cpp
libc/test/src/math/round_test.cpp
libc/test/src/math/roundf_test.cpp
libc/test/src/math/roundl_test.cpp
libc/test/src/math/sqrt_test.cpp
libc/test/src/math/sqrtf_test.cpp
libc/test/src/math/sqrtl_test.cpp
libc/test/src/math/trunc_test.cpp
libc/test/src/math/truncf_test.cpp
libc/test/src/math/truncl_test.cpp
libc/utils/FPUtil/TestHelpers.h

Removed: 




diff  --git a/libc/test/src/math/ceil_test.cpp 
b/libc/test/src/math/ceil_test.cpp
index 0e17b0a7984b..1537227d3180 100644
--- a/libc/test/src/math/ceil_test.cpp
+++ b/libc/test/src/math/ceil_test.cpp
@@ -26,8 +26,8 @@ TEST(CeilTest, SpecialNumbers) {
   EXPECT_FP_EQ(inf, __llvm_libc::ceil(inf));
   EXPECT_FP_EQ(negInf, __llvm_libc::ceil(negInf));
 
-  ASSERT_NE(isnan(nan), 0);
-  ASSERT_NE(isnan(__llvm_libc::ceil(nan)), 0);
+  ASSERT_NE(isnan(aNaN), 0);
+  ASSERT_NE(isnan(__llvm_libc::ceil(aNaN)), 0);
 }
 
 TEST(CeilTest, RoundedNumbers) {

diff  --git a/libc/test/src/math/ceilf_test.cpp 
b/libc/test/src/math/ceilf_test.cpp
index 3d7db68eea3b..aa3ea73f0352 100644
--- a/libc/test/src/math/ceilf_test.cpp
+++ b/libc/test/src/math/ceilf_test.cpp
@@ -26,8 +26,8 @@ TEST(CeilfTest, SpecialNumbers) {
   EXPECT_FP_EQ(inf, __llvm_libc::ceilf(inf));
   EXPECT_FP_EQ(negInf, __llvm_libc::ceilf(negInf));
 
-  ASSERT_NE(isnan(nan), 0);
-  ASSERT_NE(isnan(__llvm_libc::ceilf(nan)), 0);
+  ASSERT_NE(isnan(aNaN), 0);
+  ASSERT_NE(isnan(__llvm_libc::ceilf(aNaN)), 0);
 }
 
 TEST(CeilfTest, RoundedNumbers) {

diff  --git a/libc/test/src/math/ceill_test.cpp 
b/libc/test/src/math/ceill_test.cpp
index 950a97622023..b33d317e0ac6 100644
--- a/libc/test/src/math/ceill_test.cpp
+++ b/libc/test/src/math/ceill_test.cpp
@@ -26,8 +26,8 @@ TEST(CeillTest, SpecialNumbers) {
   EXPECT_FP_EQ(inf, __llvm_libc::ceill(inf));
   EXPECT_FP_EQ(negInf, __llvm_libc::ceill(negInf));
 
-  ASSERT_NE(isnan(nan), 0);
-  ASSERT_NE(isnan(__llvm_libc::ceill(nan)), 0);
+  ASSERT_NE(isnan(aNaN), 0);
+  ASSERT_NE(isnan(__llvm_libc::ceill(aNaN)), 0);
 }
 
 TEST(CeillTest, RoundedNumbers) {

diff  --git a/libc/test/src/math/copysign_test.cpp 
b/libc/test/src/math/copysign_test.cpp
index 09067fa10b56..7ab7ccfdb700 100644
--- a/libc/test/src/math/copysign_test.cpp
+++ b/libc/test/src/math/copysign_test.cpp
@@ -17,8 +17,8 @@ using FPBits = __llvm_libc::fputil::FPBits;
 DECLARE_SPECIAL_CONSTANTS(double)
 
 TEST(CopySignTest, SpecialNumbers) {
-  EXPECT_FP_EQ(nan, __llvm_libc::copysign(nan, -1.0));
-  EXPECT_FP_EQ(nan, __llvm_libc::copysign(nan, 1.0));
+  EXPECT_FP_EQ(aNaN, __llvm_libc::copysign(aNaN, -1.0));
+  EXPECT_FP_EQ(aNaN, __llvm_libc::copysign(aNaN, 1.0));
 
   EXPECT_FP_EQ(negInf, __llvm_libc::copysign(inf, -1.0));
   EXPECT_FP_EQ(inf, __llvm_libc::copysign(negInf, 1.0));

diff  --git a/libc/test/src/math/copysignf_test.cpp 
b/libc/test/src/math/copysignf_test.cpp
index e43055041dc3..72082cac8d43 100644
--- a/libc/test/src/math/copysignf_test.cpp
+++ b/libc/test/src/math/copysignf_test.cpp
@@ -17,8 +17,8 @@ using FPBits = __llvm_libc::fputil::FPBits;
 DECLARE_SPECIAL_CONSTANTS(float)
 
 TEST(CopySinfTest, SpecialNumbers) {
-  EXPECT_FP_EQ(nan, __llvm_libc::copysignf(nan, -1.0));
-  EXPECT_FP_EQ(nan, __llvm_libc::copysignf(nan, 1.0));
+  EXPECT_FP_EQ(aNaN, __llvm_libc::copysignf(aNaN, -1.0));
+  EXPECT_FP_EQ(aNaN, __llvm_libc::copysignf(aNaN, 1.0));
 
   EXPECT_FP_EQ(negInf, __llvm_libc::copysignf(inf, -1.0));
   EXPECT_FP_EQ(inf, __llvm_libc::copysignf(negInf, 1.0));

diff  --git a/libc/test/src/math/copysignl_test.cpp 
b/libc/test/src/math/copysignl_test.cpp
index 47f439f10ca2..69daa038d991 100644
--- a/libc/test/src/math/copysignl_test.cpp
+++ b/libc/test/src/math/copysignl_test.cpp
@@ -17,8 +17,8 @@ using FPBits = __llvm_libc::fputil::FPBits;
 DEC

[llvm-branch-commits] [libc] 0524da6 - [libc][NFC] Use ASSERT_FP_EQ to comapre NaN values in tests.

2020-12-15 Thread Siva Chandra Reddy via llvm-branch-commits

Author: Siva Chandra Reddy
Date: 2020-12-15T23:48:54-08:00
New Revision: 0524da67b448dcce6569fae0f54c10f208c2dc56

URL: 
https://github.com/llvm/llvm-project/commit/0524da67b448dcce6569fae0f54c10f208c2dc56
DIFF: 
https://github.com/llvm/llvm-project/commit/0524da67b448dcce6569fae0f54c10f208c2dc56.diff

LOG: [libc][NFC] Use ASSERT_FP_EQ to comapre NaN values in tests.

Added: 


Modified: 
libc/test/src/math/LdExpTest.h
libc/test/src/math/ceil_test.cpp
libc/test/src/math/ceilf_test.cpp
libc/test/src/math/ceill_test.cpp
libc/test/src/math/floor_test.cpp
libc/test/src/math/floorf_test.cpp
libc/test/src/math/floorl_test.cpp
libc/test/src/math/round_test.cpp
libc/test/src/math/roundf_test.cpp
libc/test/src/math/roundl_test.cpp
libc/test/src/math/trunc_test.cpp
libc/test/src/math/truncf_test.cpp
libc/test/src/math/truncl_test.cpp

Removed: 




diff  --git a/libc/test/src/math/LdExpTest.h b/libc/test/src/math/LdExpTest.h
index ebc2cd32f73a..b4be06bdaad7 100644
--- a/libc/test/src/math/LdExpTest.h
+++ b/libc/test/src/math/LdExpTest.h
@@ -44,7 +44,7 @@ class LdExpTestTemplate : public __llvm_libc::testing::Test {
   ASSERT_FP_EQ(negZero, func(negZero, exp));
   ASSERT_FP_EQ(inf, func(inf, exp));
   ASSERT_FP_EQ(negInf, func(negInf, exp));
-  ASSERT_NE(isnan(func(nan, exp)), 0);
+  ASSERT_FP_EQ(nan, func(nan, exp));
 }
   }
 

diff  --git a/libc/test/src/math/ceil_test.cpp 
b/libc/test/src/math/ceil_test.cpp
index 1537227d3180..6019ce5a8337 100644
--- a/libc/test/src/math/ceil_test.cpp
+++ b/libc/test/src/math/ceil_test.cpp
@@ -26,8 +26,7 @@ TEST(CeilTest, SpecialNumbers) {
   EXPECT_FP_EQ(inf, __llvm_libc::ceil(inf));
   EXPECT_FP_EQ(negInf, __llvm_libc::ceil(negInf));
 
-  ASSERT_NE(isnan(aNaN), 0);
-  ASSERT_NE(isnan(__llvm_libc::ceil(aNaN)), 0);
+  EXPECT_FP_EQ(aNaN, __llvm_libc::ceil(aNaN));
 }
 
 TEST(CeilTest, RoundedNumbers) {

diff  --git a/libc/test/src/math/ceilf_test.cpp 
b/libc/test/src/math/ceilf_test.cpp
index aa3ea73f0352..9f4cc74d249a 100644
--- a/libc/test/src/math/ceilf_test.cpp
+++ b/libc/test/src/math/ceilf_test.cpp
@@ -26,8 +26,7 @@ TEST(CeilfTest, SpecialNumbers) {
   EXPECT_FP_EQ(inf, __llvm_libc::ceilf(inf));
   EXPECT_FP_EQ(negInf, __llvm_libc::ceilf(negInf));
 
-  ASSERT_NE(isnan(aNaN), 0);
-  ASSERT_NE(isnan(__llvm_libc::ceilf(aNaN)), 0);
+  EXPECT_FP_EQ(aNaN, __llvm_libc::ceilf(aNaN));
 }
 
 TEST(CeilfTest, RoundedNumbers) {

diff  --git a/libc/test/src/math/ceill_test.cpp 
b/libc/test/src/math/ceill_test.cpp
index b33d317e0ac6..89ff9542bec1 100644
--- a/libc/test/src/math/ceill_test.cpp
+++ b/libc/test/src/math/ceill_test.cpp
@@ -26,8 +26,7 @@ TEST(CeillTest, SpecialNumbers) {
   EXPECT_FP_EQ(inf, __llvm_libc::ceill(inf));
   EXPECT_FP_EQ(negInf, __llvm_libc::ceill(negInf));
 
-  ASSERT_NE(isnan(aNaN), 0);
-  ASSERT_NE(isnan(__llvm_libc::ceill(aNaN)), 0);
+  EXPECT_FP_EQ(aNaN, __llvm_libc::ceill(aNaN));
 }
 
 TEST(CeillTest, RoundedNumbers) {

diff  --git a/libc/test/src/math/floor_test.cpp 
b/libc/test/src/math/floor_test.cpp
index 35f107a918cc..5421bb00dfaa 100644
--- a/libc/test/src/math/floor_test.cpp
+++ b/libc/test/src/math/floor_test.cpp
@@ -26,8 +26,7 @@ TEST(FloorTest, SpecialNumbers) {
   EXPECT_FP_EQ(inf, __llvm_libc::floor(inf));
   EXPECT_FP_EQ(negInf, __llvm_libc::floor(negInf));
 
-  ASSERT_NE(isnan(aNaN), 0);
-  ASSERT_NE(isnan(__llvm_libc::floor(aNaN)), 0);
+  EXPECT_FP_EQ(aNaN, __llvm_libc::floor(aNaN));
 }
 
 TEST(FloorTest, RoundedNumbers) {

diff  --git a/libc/test/src/math/floorf_test.cpp 
b/libc/test/src/math/floorf_test.cpp
index e6bc974f1fc8..f545de2941ba 100644
--- a/libc/test/src/math/floorf_test.cpp
+++ b/libc/test/src/math/floorf_test.cpp
@@ -26,8 +26,7 @@ TEST(FloorfTest, SpecialNumbers) {
   EXPECT_FP_EQ(inf, __llvm_libc::floorf(inf));
   EXPECT_FP_EQ(negInf, __llvm_libc::floorf(negInf));
 
-  ASSERT_NE(isnan(aNaN), 0);
-  ASSERT_NE(isnan(__llvm_libc::floorf(aNaN)), 0);
+  EXPECT_FP_EQ(aNaN, __llvm_libc::floorf(aNaN));
 }
 
 TEST(FloorfTest, RoundedNumbers) {

diff  --git a/libc/test/src/math/floorl_test.cpp 
b/libc/test/src/math/floorl_test.cpp
index cad5c70c2f5b..16f630967f76 100644
--- a/libc/test/src/math/floorl_test.cpp
+++ b/libc/test/src/math/floorl_test.cpp
@@ -26,8 +26,7 @@ TEST(FloorlTest, SpecialNumbers) {
   EXPECT_FP_EQ(inf, __llvm_libc::floorl(inf));
   EXPECT_FP_EQ(negInf, __llvm_libc::floorl(negInf));
 
-  ASSERT_NE(isnan(aNaN), 0);
-  ASSERT_NE(isnan(__llvm_libc::floorl(aNaN)), 0);
+  EXPECT_FP_EQ(aNaN, __llvm_libc::floorl(aNaN));
 }
 
 TEST(FloorlTest, RoundedNumbers) {

diff  --git a/libc/test/src/math/round_test.cpp 
b/libc/test/src/math/round_test.cpp
index defa22a05d44..4ab248a2349c 100644
--- a/libc/test/src/math/round_test.cpp
+++ b/libc/test/src/math/round_test.cpp
@@ -26,8 +26,7 @@ TEST(RoundTest, SpecialNumbers) {
   EXPECT_FP_EQ(inf, __llvm_libc::round(inf));
   EXP

[llvm-branch-commits] [libc] bf03eba - [libc] Refactor WrapperGen to make the flow cleaner.

2020-12-17 Thread Siva Chandra Reddy via llvm-branch-commits

Author: Siva Chandra Reddy
Date: 2020-12-17T08:56:45-08:00
New Revision: bf03eba1f99b8408e6f8961256ffb3409df7f995

URL: 
https://github.com/llvm/llvm-project/commit/bf03eba1f99b8408e6f8961256ffb3409df7f995
DIFF: 
https://github.com/llvm/llvm-project/commit/bf03eba1f99b8408e6f8961256ffb3409df7f995.diff

LOG: [libc] Refactor WrapperGen to make the flow cleaner.

Reviewed By: michaelrj

Differential Revision: https://reviews.llvm.org/D93417

Added: 


Modified: 
libc/test/utils/tools/WrapperGen/wrappergen_test.cpp
libc/utils/tools/WrapperGen/Main.cpp

Removed: 




diff  --git a/libc/test/utils/tools/WrapperGen/wrappergen_test.cpp 
b/libc/test/utils/tools/WrapperGen/wrappergen_test.cpp
index 4cb7a31de942..923b318288ea 100644
--- a/libc/test/utils/tools/WrapperGen/wrappergen_test.cpp
+++ b/libc/test/utils/tools/WrapperGen/wrappergen_test.cpp
@@ -72,8 +72,12 @@ TEST_F(WrapperGenTest, RunWrapperGenAndGetNoErrors) {
   llvm::None, llvm::StringRef(STDOutFile.get().TmpName),
   llvm::StringRef(STDErrFile.get().TmpName)};
 
-  llvm::StringRef ArgV[] = {ProgPath, llvm::StringRef(IncludeArg),
-llvm::StringRef(APIArg), "--name", "strlen"};
+  llvm::StringRef ArgV[] = {ProgPath,
+llvm::StringRef(IncludeArg),
+llvm::StringRef(APIArg),
+"--gen-wrapper",
+"--name",
+"strlen"};
 
   int ExitCode =
   llvm::sys::ExecuteAndWait(ProgPath, ArgV, llvm::None, Redirects);
@@ -90,8 +94,12 @@ TEST_F(WrapperGenTest, RunWrapperGenOnStrlen) {
   llvm::None, llvm::StringRef(STDOutFile.get().TmpName),
   llvm::StringRef(STDErrFile.get().TmpName)};
 
-  llvm::StringRef ArgV[] = {ProgPath, llvm::StringRef(IncludeArg),
-llvm::StringRef(APIArg), "--name", "strlen"};
+  llvm::StringRef ArgV[] = {ProgPath,
+llvm::StringRef(IncludeArg),
+llvm::StringRef(APIArg),
+"--gen-wrapper",
+"--name",
+"strlen"};
 
   int ExitCode =
   llvm::sys::ExecuteAndWait(ProgPath, ArgV, llvm::None, Redirects);
@@ -116,7 +124,7 @@ TEST_F(WrapperGenTest, RunWrapperGenOnStrlen) {
   // would break this test.
 }
 
-TEST_F(WrapperGenTest, RunWrapperGenOnStrlenWithAliasee) {
+TEST_F(WrapperGenTest, GenAliasForStrlen) {
   llvm::Optional Redirects[] = {
   llvm::None, llvm::StringRef(STDOutFile.get().TmpName),
   llvm::StringRef(STDErrFile.get().TmpName)};
@@ -124,8 +132,9 @@ TEST_F(WrapperGenTest, RunWrapperGenOnStrlenWithAliasee) {
   llvm::StringRef ArgV[] = {ProgPath,
 llvm::StringRef(IncludeArg),
 llvm::StringRef(APIArg),
-"--aliasee",
-"STRLEN_ALIAS",
+"--gen-alias",
+"--mangled-name",
+"__llvm_libc_strlen_mangled_name",
 "--name",
 "strlen"};
 
@@ -142,35 +151,38 @@ TEST_F(WrapperGenTest, RunWrapperGenOnStrlenWithAliasee) {
   auto STDOutOrError = llvm::MemoryBuffer::getFile(STDOutFile.get().TmpName);
   std::string STDOutOutput = STDOutOrError.get()->getBuffer().str();
 
-  ASSERT_EQ(STDOutOutput, "extern \"C\" size_t strlen(const char * __arg0) "
-  "__attribute__((alias(\"STRLEN_ALIAS\")));\n");
+  ASSERT_EQ(STDOutOutput,
+"extern \"C\" size_t strlen(const char * __arg0) "
+"__attribute__((alias(\"__llvm_libc_strlen_mangled_name\")));\n");
   // TODO:(michaelrj) Figure out how to make this output comparison
   // less brittle. Currently it's just comparing the output of the program
   // to an exact string, this means that even a small formatting change
   // would break this test.
 }
 
-TEST_F(WrapperGenTest, DeclStrlenAliasUsingAliaseeFile) {
+TEST_F(WrapperGenTest, DeclStrlenAliasUsingMangledNameFile) {
   llvm::Optional Redirects[] = {
   llvm::None, llvm::StringRef(STDOutFile.get().TmpName),
   llvm::StringRef(STDErrFile.get().TmpName)};
 
-  const char *AliaseeFileContent = "abc\nxyz__llvm_libcSTRLEN_ALIAS\nijk\n";
-  llvm::SmallVector AliaseeFilePath;
-  auto AliaseeFileCreateError = llvm::sys::fs::createUniqueFile(
-  "libc-wrappergen-test-aliasee-file-%%-%%-%%-%%.txt", AliaseeFilePath);
-  ASSERT_FALSE(AliaseeFileCreateError);
-  auto AliaseeFileWriteError = llvm::writeFileAtomically(
+  const char *MangledNameFileContent =
+  "abc\nxyz__llvm_libc_strlen_mangled_name\nijk\n";
+  llvm::SmallVector MangledNameFilePath;
+  auto MangledNameFileCreateError = llvm::sys::fs::createUniqueFile(
+  "libc-wrappergen-test-aliasee-file-%%-%%-%%-%%.txt", 
MangledNameFilePath);
+  ASSERT_FALSE(Mang

[llvm-branch-commits] [libc] e1a5b23 - [libc][Obvious] Fix typo is wrappergen unittest.

2020-12-17 Thread Siva Chandra Reddy via llvm-branch-commits

Author: Siva Chandra Reddy
Date: 2020-12-17T09:13:23-08:00
New Revision: e1a5b234ef94adb87fdf01371a672053c0d814a7

URL: 
https://github.com/llvm/llvm-project/commit/e1a5b234ef94adb87fdf01371a672053c0d814a7
DIFF: 
https://github.com/llvm/llvm-project/commit/e1a5b234ef94adb87fdf01371a672053c0d814a7.diff

LOG: [libc][Obvious] Fix typo is wrappergen unittest.

Added: 


Modified: 
libc/test/utils/tools/WrapperGen/wrappergen_test.cpp

Removed: 




diff  --git a/libc/test/utils/tools/WrapperGen/wrappergen_test.cpp 
b/libc/test/utils/tools/WrapperGen/wrappergen_test.cpp
index 923b318288ea..c4f64a095fc3 100644
--- a/libc/test/utils/tools/WrapperGen/wrappergen_test.cpp
+++ b/libc/test/utils/tools/WrapperGen/wrappergen_test.cpp
@@ -238,7 +238,7 @@ TEST_F(WrapperGenTest, 
RunWrapperGenOnStrlenWithMangledNameAndMangledNameFile) {
 
   ASSERT_EQ(STDErrOutput,
 "error: The options 'mangled-name' and 'mangled-name-file' "
-"cannot be specified simultaniously.\n");
+"cannot be specified simultaneously.\n");
 
   auto STDOutOrError = llvm::MemoryBuffer::getFile(STDOutFile.get().TmpName);
   std::string STDOutOutput = STDOutOrError.get()->getBuffer().str();



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [libc] d599ed4 - [libc][NFC] Use ASSERT_FP_EQ to comapre NaN values in tests.

2020-12-17 Thread Siva Chandra Reddy via llvm-branch-commits

Author: Siva Chandra Reddy
Date: 2020-12-17T23:16:26-08:00
New Revision: d599ed49b355f1481bf8b22774e1a902352c9766

URL: 
https://github.com/llvm/llvm-project/commit/d599ed49b355f1481bf8b22774e1a902352c9766
DIFF: 
https://github.com/llvm/llvm-project/commit/d599ed49b355f1481bf8b22774e1a902352c9766.diff

LOG: [libc][NFC] Use ASSERT_FP_EQ to comapre NaN values in tests.

This is a continuation of the previous CL which did a similar change in
other tests. To elaborate a little about why we need this - under C++
compilation with headers not from LLVM libc, libraries like libc++ and
libstdc++ provide their own math.h which undefine macros like `isnan`
and provide the overloaded C++ isnan functions which return a boolean
value instead of an integer value returned by the isnan macro.

Added: 


Modified: 
libc/test/src/math/FDimTest.h
libc/test/src/math/RemQuoTest.h
libc/test/src/math/fmax_test.cpp
libc/test/src/math/fmaxf_test.cpp
libc/test/src/math/fmaxl_test.cpp
libc/test/src/math/fmin_test.cpp
libc/test/src/math/fminf_test.cpp
libc/test/src/math/fminl_test.cpp

Removed: 




diff  --git a/libc/test/src/math/FDimTest.h b/libc/test/src/math/FDimTest.h
index f052dc382f16..4b95427b113b 100644
--- a/libc/test/src/math/FDimTest.h
+++ b/libc/test/src/math/FDimTest.h
@@ -26,7 +26,7 @@ class FDimTestTemplate : public __llvm_libc::testing::Test {
 EXPECT_FP_EQ(nan, func(negZero, nan));
 EXPECT_FP_EQ(nan, func(nan, T(-1.2345)));
 EXPECT_FP_EQ(nan, func(T(1.2345), nan));
-EXPECT_NE(isnan(func(nan, nan)), 0);
+EXPECT_FP_EQ(func(nan, nan), nan);
   }
 
   void testInfArg(FuncPtr func) {

diff  --git a/libc/test/src/math/RemQuoTest.h b/libc/test/src/math/RemQuoTest.h
index 29fcdb83b6a2..66f2f0956348 100644
--- a/libc/test/src/math/RemQuoTest.h
+++ b/libc/test/src/math/RemQuoTest.h
@@ -38,27 +38,27 @@ class RemQuoTestTemplate : public 
__llvm_libc::testing::Test {
 
 y = T(1.0);
 x = inf;
-EXPECT_NE(isnan(func(x, y, "ient)), 0);
+EXPECT_FP_EQ(nan, func(x, y, "ient));
 x = negInf;
-EXPECT_NE(isnan(func(x, y, "ient)), 0);
+EXPECT_FP_EQ(nan, func(x, y, "ient));
 
 x = T(1.0);
 y = zero;
-EXPECT_NE(isnan(func(x, y, "ient)), 0);
+EXPECT_FP_EQ(nan, func(x, y, "ient));
 y = negZero;
-EXPECT_NE(isnan(func(x, y, "ient)), 0);
+EXPECT_FP_EQ(nan, func(x, y, "ient));
 
 y = nan;
 x = T(1.0);
-EXPECT_NE(isnan(func(x, y, "ient)), 0);
+EXPECT_FP_EQ(nan, func(x, y, "ient));
 
 y = T(1.0);
 x = nan;
-EXPECT_NE(isnan(func(x, y, "ient)), 0);
+EXPECT_FP_EQ(nan, func(x, y, "ient));
 
 x = nan;
 y = nan;
-EXPECT_NE(isnan(func(x, y, "ient)), 0);
+EXPECT_FP_EQ(nan, func(x, y, "ient));
 
 x = zero;
 y = T(1.0);

diff  --git a/libc/test/src/math/fmax_test.cpp 
b/libc/test/src/math/fmax_test.cpp
index b84db3003cc6..4be7e0208dc7 100644
--- a/libc/test/src/math/fmax_test.cpp
+++ b/libc/test/src/math/fmax_test.cpp
@@ -23,7 +23,7 @@ TEST(FmaxTest, NaNArg) {
   EXPECT_FP_EQ(-0.0, __llvm_libc::fmax(-0.0, aNaN));
   EXPECT_FP_EQ(-1.2345, __llvm_libc::fmax(aNaN, -1.2345));
   EXPECT_FP_EQ(1.2345, __llvm_libc::fmax(1.2345, aNaN));
-  EXPECT_NE(isnan(__llvm_libc::fmax(aNaN, aNaN)), 0);
+  EXPECT_FP_EQ(aNaN, __llvm_libc::fmax(aNaN, aNaN));
 }
 
 TEST(FmaxTest, InfArg) {

diff  --git a/libc/test/src/math/fmaxf_test.cpp 
b/libc/test/src/math/fmaxf_test.cpp
index 7d6661cb4b8b..812dd4c8e5af 100644
--- a/libc/test/src/math/fmaxf_test.cpp
+++ b/libc/test/src/math/fmaxf_test.cpp
@@ -23,7 +23,7 @@ TEST(FmaxfTest, NaNArg) {
   EXPECT_FP_EQ(-0.0f, __llvm_libc::fmaxf(-0.0f, aNaN));
   EXPECT_FP_EQ(-1.2345f, __llvm_libc::fmaxf(aNaN, -1.2345f));
   EXPECT_FP_EQ(1.2345f, __llvm_libc::fmaxf(1.2345f, aNaN));
-  EXPECT_NE(isnan(__llvm_libc::fmaxf(aNaN, aNaN)), 0);
+  EXPECT_FP_EQ(aNaN, __llvm_libc::fmaxf(aNaN, aNaN));
 }
 
 TEST(FmaxfTest, InfArg) {

diff  --git a/libc/test/src/math/fmaxl_test.cpp 
b/libc/test/src/math/fmaxl_test.cpp
index 72f7636cb0eb..6eac0095c62a 100644
--- a/libc/test/src/math/fmaxl_test.cpp
+++ b/libc/test/src/math/fmaxl_test.cpp
@@ -23,7 +23,7 @@ TEST(FmaxlTest, NaNArg) {
   EXPECT_FP_EQ(-0.0L, __llvm_libc::fmaxl(-0.0L, aNaN));
   EXPECT_FP_EQ(-1.2345L, __llvm_libc::fmaxl(aNaN, -1.2345L));
   EXPECT_FP_EQ(1.2345L, __llvm_libc::fmaxl(1.2345L, aNaN));
-  EXPECT_NE(isnan(__llvm_libc::fmaxl(aNaN, aNaN)), 0);
+  EXPECT_FP_EQ(aNaN, __llvm_libc::fmaxl(aNaN, aNaN));
 }
 
 TEST(FmaxlTest, InfArg) {

diff  --git a/libc/test/src/math/fmin_test.cpp 
b/libc/test/src/math/fmin_test.cpp
index 5deaa857c1f2..6782e8cb9e80 100644
--- a/libc/test/src/math/fmin_test.cpp
+++ b/libc/test/src/math/fmin_test.cpp
@@ -23,7 +23,7 @@ TEST(FminTest, NaNArg) {
   EXPECT_FP_EQ(-0.0, __llvm_libc::fmin(-0.0, aNaN));
   EXPECT_FP_EQ(-1.2345, __llvm_libc::fmin(aNaN, -1.2345));
   EXPECT_FP_EQ(1.2345, __llvm_libc::fmin(1.2345, aNaN));
-  EXPECT_N

[llvm-branch-commits] [libc] 2d9ae1d - [libc][NFC] Use `#include ` in utils/FPUtil/ManipulationFunctions.h.

2020-12-18 Thread Siva Chandra Reddy via llvm-branch-commits

Author: Siva Chandra Reddy
Date: 2020-12-18T00:05:02-08:00
New Revision: 2d9ae1d217890639518252ee1f39c9cc759749ef

URL: 
https://github.com/llvm/llvm-project/commit/2d9ae1d217890639518252ee1f39c9cc759749ef
DIFF: 
https://github.com/llvm/llvm-project/commit/2d9ae1d217890639518252ee1f39c9cc759749ef.diff

LOG: [libc][NFC] Use `#include ` in 
utils/FPUtil/ManipulationFunctions.h.

This reverts commit 352cba2441c6c4e00f067c9c68358cc0a6a5fffb.
"add back math.h #include utils/FPUtil/ManipulationFunctions.h".

Using `` correct so downstream setup should be fixed.

Added: 


Modified: 
libc/utils/FPUtil/ManipulationFunctions.h

Removed: 




diff  --git a/libc/utils/FPUtil/ManipulationFunctions.h 
b/libc/utils/FPUtil/ManipulationFunctions.h
index 2bac1b5c229f..79dc741ff629 100644
--- a/libc/utils/FPUtil/ManipulationFunctions.h
+++ b/libc/utils/FPUtil/ManipulationFunctions.h
@@ -13,10 +13,10 @@
 #include "NearestIntegerOperations.h"
 #include "NormalFloat.h"
 
-#include "include/math.h"
 #include "utils/CPP/TypeTraits.h"
 
 #include 
+#include 
 
 namespace __llvm_libc {
 namespace fputil {



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [libc] 19c3894 - [libc] Fix couple of corner cases in remquo.

2020-12-02 Thread Siva Chandra Reddy via llvm-branch-commits

Author: Siva Chandra Reddy
Date: 2020-12-02T11:48:49-08:00
New Revision: 19c3894f9436ef68f33f80ee1fd589166267b5a1

URL: 
https://github.com/llvm/llvm-project/commit/19c3894f9436ef68f33f80ee1fd589166267b5a1
DIFF: 
https://github.com/llvm/llvm-project/commit/19c3894f9436ef68f33f80ee1fd589166267b5a1.diff

LOG: [libc] Fix couple of corner cases in remquo.

These two cases are fixed:
1. If numerator is not zero and denominator is infinity, then the
numerator is returned as the remainder.
2. If numerator and denominator are equal in magnitude, then quotient
with the right sign is returned.

The differet tests of remquo, remquof and remquol have been unified
into a single file to avoid duplication.

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D92353

Added: 
libc/test/src/math/RemQuoTest.h

Modified: 
libc/test/src/math/CMakeLists.txt
libc/test/src/math/remquo_test.cpp
libc/test/src/math/remquof_test.cpp
libc/test/src/math/remquol_test.cpp
libc/utils/FPUtil/DivisionAndRemainderOperations.h

Removed: 




diff  --git a/libc/test/src/math/CMakeLists.txt 
b/libc/test/src/math/CMakeLists.txt
index 2220cef00791..cdffe737d8df 100644
--- a/libc/test/src/math/CMakeLists.txt
+++ b/libc/test/src/math/CMakeLists.txt
@@ -686,6 +686,8 @@ add_fp_unittest(
 libc_math_unittests
   SRCS
 remquof_test.cpp
+  HDRS
+RemQuoTest.h
   DEPENDS
 libc.include.math
 libc.src.math.remquof
@@ -699,6 +701,8 @@ add_fp_unittest(
 libc_math_unittests
   SRCS
 remquo_test.cpp
+  HDRS
+RemQuoTest.h
   DEPENDS
 libc.include.math
 libc.src.math.remquo
@@ -712,6 +716,8 @@ add_fp_unittest(
 libc_math_unittests
   SRCS
 remquol_test.cpp
+  HDRS
+RemQuoTest.h
   DEPENDS
 libc.include.math
 libc.src.math.remquol

diff  --git a/libc/test/src/math/RemQuoTest.h b/libc/test/src/math/RemQuoTest.h
new file mode 100644
index ..29fcdb83b6a2
--- /dev/null
+++ b/libc/test/src/math/RemQuoTest.h
@@ -0,0 +1,144 @@
+//===-- Utility class to test 
diff erent flavors of remquo ---*- 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
+//
+//===--===//
+
+#ifndef LLVM_LIBC_TEST_SRC_MATH_REMQUOTEST_H
+#define LLVM_LIBC_TEST_SRC_MATH_REMQUOTEST_H
+
+#include "utils/FPUtil/BasicOperations.h"
+#include "utils/FPUtil/FPBits.h"
+#include "utils/FPUtil/TestHelpers.h"
+#include "utils/MPFRWrapper/MPFRUtils.h"
+#include "utils/UnitTest/Test.h"
+#include 
+
+namespace mpfr = __llvm_libc::testing::mpfr;
+
+template 
+class RemQuoTestTemplate : public __llvm_libc::testing::Test {
+  using FPBits = __llvm_libc::fputil::FPBits;
+  using UIntType = typename FPBits::UIntType;
+
+  const T zero = __llvm_libc::fputil::FPBits::zero();
+  const T negZero = __llvm_libc::fputil::FPBits::negZero();
+  const T inf = __llvm_libc::fputil::FPBits::inf();
+  const T negInf = __llvm_libc::fputil::FPBits::negInf();
+  const T nan = __llvm_libc::fputil::FPBits::buildNaN(1);
+
+public:
+  typedef T (*RemQuoFunc)(T, T, int *);
+
+  void testSpecialNumbers(RemQuoFunc func) {
+int quotient;
+T x, y;
+
+y = T(1.0);
+x = inf;
+EXPECT_NE(isnan(func(x, y, "ient)), 0);
+x = negInf;
+EXPECT_NE(isnan(func(x, y, "ient)), 0);
+
+x = T(1.0);
+y = zero;
+EXPECT_NE(isnan(func(x, y, "ient)), 0);
+y = negZero;
+EXPECT_NE(isnan(func(x, y, "ient)), 0);
+
+y = nan;
+x = T(1.0);
+EXPECT_NE(isnan(func(x, y, "ient)), 0);
+
+y = T(1.0);
+x = nan;
+EXPECT_NE(isnan(func(x, y, "ient)), 0);
+
+x = nan;
+y = nan;
+EXPECT_NE(isnan(func(x, y, "ient)), 0);
+
+x = zero;
+y = T(1.0);
+EXPECT_FP_EQ(func(x, y, "ient), zero);
+
+x = negZero;
+y = T(1.0);
+EXPECT_FP_EQ(func(x, y, "ient), negZero);
+
+x = T(1.125);
+y = inf;
+EXPECT_FP_EQ(func(x, y, "ient), x);
+EXPECT_EQ(quotient, 0);
+  }
+
+  void testEqualNumeratorAndDenominator(RemQuoFunc func) {
+T x = T(1.125), y = T(1.125);
+int q;
+
+// When the remainder is zero, the standard requires it to
+// have the same sign as x.
+
+EXPECT_FP_EQ(func(x, y, &q), zero);
+EXPECT_EQ(q, 1);
+
+EXPECT_FP_EQ(func(x, -y, &q), zero);
+EXPECT_EQ(q, -1);
+
+EXPECT_FP_EQ(func(-x, y, &q), negZero);
+EXPECT_EQ(q, -1);
+
+EXPECT_FP_EQ(func(-x, -y, &q), negZero);
+EXPECT_EQ(q, 1);
+  }
+
+  void testSubnormalRange(RemQuoFunc func) {
+constexpr UIntType count = 101;
+constexpr UIntType step =
+(FPBits::maxSubnormal - FPBits::minSubnormal) / count;
+for (UIntType v = FPBits::minSubnormal, w = FPBits::maxSubnormal;
+ v <= FPBits::maxSubnormal && w >= FPBits::minSubnormal;

[llvm-branch-commits] [libc] 4fff2a7 - [libc] Add simple x86_64 floating point exception and rounding mode support.

2020-12-03 Thread Siva Chandra Reddy via llvm-branch-commits

Author: Siva Chandra Reddy
Date: 2020-12-03T12:55:12-08:00
New Revision: 4fff2a7e8964574b05c77d76a8d63d1f3593a258

URL: 
https://github.com/llvm/llvm-project/commit/4fff2a7e8964574b05c77d76a8d63d1f3593a258
DIFF: 
https://github.com/llvm/llvm-project/commit/4fff2a7e8964574b05c77d76a8d63d1f3593a258.diff

LOG: [libc] Add simple x86_64 floating point exception and rounding mode 
support.

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D92546

Added: 
libc/include/fenv.h.def
libc/src/fenv/CMakeLists.txt
libc/src/fenv/feclearexcept.cpp
libc/src/fenv/feclearexcept.h
libc/src/fenv/fegetround.cpp
libc/src/fenv/fegetround.h
libc/src/fenv/feraiseexcept.cpp
libc/src/fenv/feraiseexcept.h
libc/src/fenv/fesetround.cpp
libc/src/fenv/fesetround.h
libc/src/fenv/fetestexcept.cpp
libc/src/fenv/fetestexcept.h
libc/test/src/fenv/CMakeLists.txt
libc/test/src/fenv/exception_status_test.cpp
libc/test/src/fenv/rounding_mode_test.cpp
libc/utils/FPUtil/DummyFEnv.h
libc/utils/FPUtil/FEnv.h
libc/utils/FPUtil/x86_64/FEnv.h

Modified: 
libc/config/linux/api.td
libc/config/linux/x86_64/entrypoints.txt
libc/include/CMakeLists.txt
libc/spec/stdc.td
libc/src/CMakeLists.txt
libc/test/src/CMakeLists.txt
libc/utils/FPUtil/CMakeLists.txt

Removed: 




diff  --git a/libc/config/linux/api.td b/libc/config/linux/api.td
index d66d55f65027..72ca4e8bd349 100644
--- a/libc/config/linux/api.td
+++ b/libc/config/linux/api.td
@@ -179,6 +179,22 @@ def MathAPI : PublicAPI<"math.h"> {
   ];
 }
 
+def FenvAPI: PublicAPI<"fenv.h"> {
+  let Macros = [
+SimpleMacroDef<"FE_DIVBYZERO", "1">,
+SimpleMacroDef<"FE_INEXACT", "2">,
+SimpleMacroDef<"FE_INVALID", "4">,
+SimpleMacroDef<"FE_OVERFLOW", "8">,
+SimpleMacroDef<"FE_UNDERFLOW", "16">,
+SimpleMacroDef<"FE_ALL_EXCEPT", 
"(FE_DIVBYZERO|FE_INEXACT|FE_INVALID|FE_OVERFLOW|FE_UNDERFLOW)">,
+
+SimpleMacroDef<"FE_DOWNWARD", "1">,
+SimpleMacroDef<"FE_TONEAREST", "2">,
+SimpleMacroDef<"FE_TOWARDZERO", "4">,
+SimpleMacroDef<"FE_UPWARD", "8">,
+  ];
+}
+
 def StringAPI : PublicAPI<"string.h"> {
   let TypeDeclarations = [
 SizeT,

diff  --git a/libc/config/linux/x86_64/entrypoints.txt 
b/libc/config/linux/x86_64/entrypoints.txt
index 7401715058ac..2b461c4eede5 100644
--- a/libc/config/linux/x86_64/entrypoints.txt
+++ b/libc/config/linux/x86_64/entrypoints.txt
@@ -21,6 +21,13 @@ set(TARGET_LIBC_ENTRYPOINTS
 # errno.h entrypoints
 libc.src.errno.__errno_location
 
+# fenv.h entrypoints
+libc.src.fenv.feclearexcept
+libc.src.fenv.fegetround
+libc.src.fenv.fesetround
+libc.src.fenv.feraiseexcept
+libc.src.fenv.fetestexcept
+
 # signal.h entrypoints
 libc.src.signal.raise
 libc.src.signal.sigaction

diff  --git a/libc/include/CMakeLists.txt b/libc/include/CMakeLists.txt
index ddfdb8caa2ac..4c52a7615c91 100644
--- a/libc/include/CMakeLists.txt
+++ b/libc/include/CMakeLists.txt
@@ -25,6 +25,14 @@ add_gen_header(
 .llvm_libc_common_h
 )
 
+add_gen_header(
+  fenv
+  DEF_FILE fenv.h.def
+  GEN_HDR fenv.h
+  DEPENDS
+.llvm_libc_common_h
+)
+
 add_gen_header(
   math
   DEF_FILE math.h.def

diff  --git a/libc/include/fenv.h.def b/libc/include/fenv.h.def
new file mode 100644
index ..489756cf6325
--- /dev/null
+++ b/libc/include/fenv.h.def
@@ -0,0 +1,16 @@
+//===-- C standard library header fenv.h 
--===//
+//
+// 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
+//
+//===--===//
+
+#ifndef LLVM_LIBC_FENV_H
+#define LLVM_LIBC_FENV_H
+
+#include <__llvm-libc-common.h>
+
+%%public_api()
+
+#endif // LLVM_LIBC_FENV_H

diff  --git a/libc/spec/stdc.td b/libc/spec/stdc.td
index d40fe8df3942..70cc2600a612 100644
--- a/libc/spec/stdc.td
+++ b/libc/spec/stdc.td
@@ -95,7 +95,53 @@ def StdC : StandardSpec<"stdc"> {
   >,
   ]
   >;
- 
+
+  HeaderSpec Fenv = HeaderSpec<
+  "fenv.h",
+  [
+  Macro<"FE_DIVBYZERO">,
+  Macro<"FE_INEXACT">,
+  Macro<"FE_INVALID">,
+  Macro<"FE_OVERFLOW">,
+  Macro<"FE_UNDERFLOW">,
+  Macro<"FE_ALL_EXCEPT">,
+
+  Macro<"FE_DOWNWARD">,
+  Macro<"FE_TONEAREST">,
+  Macro<"FE_TOWARDZERO">,
+  Macro<"FE_UPWARD">
+  ],
+  [], // Types
+  [], // Enumerations
+  [
+  FunctionSpec<
+  "feclearexcept",
+  RetValSpec,
+  [ArgSpec]
+  >,
+  FunctionSpec<
+  "fetestexcept",
+  RetValSpec,
+  [ArgSpec]
+  >,
+  FunctionSpec<
+  "feraiseex

[llvm-branch-commits] [libc] 3a37512 - [libc][NFC] Remove dependence on xmmintrin.h to read/write MXCSR.

2020-12-03 Thread Siva Chandra Reddy via llvm-branch-commits

Author: Siva Chandra Reddy
Date: 2020-12-03T13:49:17-08:00
New Revision: 3a375125b01cbb84e90d688f19b0168e2c07862d

URL: 
https://github.com/llvm/llvm-project/commit/3a375125b01cbb84e90d688f19b0168e2c07862d
DIFF: 
https://github.com/llvm/llvm-project/commit/3a375125b01cbb84e90d688f19b0168e2c07862d.diff

LOG: [libc][NFC] Remove dependence on xmmintrin.h to read/write MXCSR.

The version of clang on the bots is unhappy with using xmmintrin.h.
So, this change removes dependence on xmmintrin by using inline
assembly.

Added: 


Modified: 
libc/utils/FPUtil/x86_64/FEnv.h

Removed: 




diff  --git a/libc/utils/FPUtil/x86_64/FEnv.h b/libc/utils/FPUtil/x86_64/FEnv.h
index 63c9d41557cd..92ae8049e1d5 100644
--- a/libc/utils/FPUtil/x86_64/FEnv.h
+++ b/libc/utils/FPUtil/x86_64/FEnv.h
@@ -11,7 +11,6 @@
 
 #include 
 #include 
-#include 
 
 namespace __llvm_libc {
 namespace fputil {
@@ -89,6 +88,16 @@ static inline void clearX87Exceptions() {
   __asm__ __volatile__("fnclex" : : :);
 }
 
+static inline uint32_t getMXCSR() {
+  uint32_t w;
+  __asm__ __volatile__("stmxcsr %0" : "=m"(w)::);
+  return w;
+}
+
+static inline void writeMXCSR(uint32_t w) {
+  __asm__ __volatile__("ldmxcsr %0" : : "m"(w) :);
+}
+
 } // namespace internal
 
 static inline int clearExcept(int excepts) {
@@ -99,9 +108,9 @@ static inline int clearExcept(int excepts) {
   // really required.
   internal::clearX87Exceptions();
 
-  uint32_t mxcsr = _mm_getcsr();
+  uint32_t mxcsr = internal::getMXCSR();
   mxcsr &= ~internal::getStatusValueForExcept(excepts);
-  _mm_setcsr(mxcsr);
+  internal::writeMXCSR(mxcsr);
   return 0;
 }
 
@@ -110,7 +119,7 @@ static inline int testExcept(int excepts) {
   // Check both x87 status word and MXCSR.
   return internal::exceptionStatusToMacro(
   (statusValue & internal::getX87StatusWord()) |
-  (statusValue & _mm_getcsr()));
+  (statusValue & internal::getMXCSR()));
 }
 
 static inline int raiseExcept(int excepts) {
@@ -119,15 +128,15 @@ static inline int raiseExcept(int excepts) {
   // followed with an fwait instruction before writing the flag for the
   // next exception.
   uint16_t statusValue = internal::getStatusValueForExcept(excepts);
-  uint32_t sse = _mm_getcsr();
-  sse = sse | statusValue;
-  _mm_setcsr(sse);
+  uint32_t mxcsr = internal::getMXCSR();
+  mxcsr = mxcsr | statusValue;
+  internal::writeMXCSR(mxcsr);
   return 0;
 }
 
 static inline int getRound() {
   uint16_t bitValue =
-  (_mm_getcsr() >> internal::MXCSRRoundingControlBitPosition) & 0x3;
+  (internal::getMXCSR() >> internal::MXCSRRoundingControlBitPosition) & 
0x3;
   switch (bitValue) {
   case internal::RoundingControlValue::ToNearest:
 return FE_TONEAREST;
@@ -169,11 +178,11 @@ static inline int setRound(int mode) {
   internal::writeX87ControlWord(x87Control);
 
   uint32_t mxcsrValue = bitValue << internal::MXCSRRoundingControlBitPosition;
-  uint32_t mxcsrControl = _mm_getcsr();
+  uint32_t mxcsrControl = internal::getMXCSR();
   mxcsrControl =
   (mxcsrControl & ~(0x3 << internal::MXCSRRoundingControlBitPosition)) |
   mxcsrValue;
-  _mm_setcsr(mxcsrControl);
+  internal::writeMXCSR(mxcsrControl);
 
   return 0;
 }



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [libc] ab3cbe4 - [libc] Raise x87 exceptions by synchronizing with "fwait".

2020-12-08 Thread Siva Chandra Reddy via llvm-branch-commits

Author: Siva Chandra Reddy
Date: 2020-12-08T13:16:19-08:00
New Revision: ab3cbe4bc0d952ca58a3e2263629591ef898de3f

URL: 
https://github.com/llvm/llvm-project/commit/ab3cbe4bc0d952ca58a3e2263629591ef898de3f
DIFF: 
https://github.com/llvm/llvm-project/commit/ab3cbe4bc0d952ca58a3e2263629591ef898de3f.diff

LOG: [libc] Raise x87 exceptions by synchronizing with "fwait".

Couple of helper functions enableExcept and disableExcept have been
added. In a later round, they will be used to implemented the GNU
extension functions feenableexcept and fedisableexcept.

Differential Revision: https://reviews.llvm.org/D92821

Added: 
libc/test/src/fenv/enabled_exceptions_test.cpp

Modified: 
libc/cmake/modules/LLVMLibCTestRules.cmake
libc/test/src/fenv/CMakeLists.txt
libc/test/src/fenv/exception_status_test.cpp
libc/utils/FPUtil/x86_64/FEnv.h

Removed: 




diff  --git a/libc/cmake/modules/LLVMLibCTestRules.cmake 
b/libc/cmake/modules/LLVMLibCTestRules.cmake
index a30259c05382..33dc2cc7ca74 100644
--- a/libc/cmake/modules/LLVMLibCTestRules.cmake
+++ b/libc/cmake/modules/LLVMLibCTestRules.cmake
@@ -137,7 +137,7 @@ function(add_libc_unittest target_name)
   )
   if(LIBC_UNITTEST_COMPILE_OPTIONS)
 target_compile_options(
-  ${target_name}
+  ${fq_target_name}
   PRIVATE ${LIBC_UNITTEST_COMPILE_OPTIONS}
 )
   endif()

diff  --git a/libc/test/src/fenv/CMakeLists.txt 
b/libc/test/src/fenv/CMakeLists.txt
index fb9666e2ed91..09e37b15a7f2 100644
--- a/libc/test/src/fenv/CMakeLists.txt
+++ b/libc/test/src/fenv/CMakeLists.txt
@@ -21,4 +21,23 @@ add_libc_unittest(
 libc.src.fenv.feclearexcept
 libc.src.fenv.feraiseexcept
 libc.src.fenv.fetestexcept
+libc.utils.FPUtil.fputil
 )
+
+if (NOT LLVM_USE_SANITIZER)
+  # Sanitizers don't like SIGFPE. So, we will run the 
+  # tests which raise SIGFPE only in non-sanitizer builds.
+  add_libc_unittest(
+enabled_exceptions_test
+SUITE
+  libc_fenv_unittests
+SRCS
+  enabled_exceptions_test.cpp
+DEPENDS
+  libc.include.signal
+  libc.src.fenv.feclearexcept
+  libc.src.fenv.feraiseexcept
+  libc.src.fenv.fetestexcept
+  libc.utils.FPUtil.fputil
+  )
+endif()

diff  --git a/libc/test/src/fenv/enabled_exceptions_test.cpp 
b/libc/test/src/fenv/enabled_exceptions_test.cpp
new file mode 100644
index ..23151286a907
--- /dev/null
+++ b/libc/test/src/fenv/enabled_exceptions_test.cpp
@@ -0,0 +1,50 @@
+//===-- Unittests for feraiseexcept with exceptions enabled 
---===//
+//
+// 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/fenv/feclearexcept.h"
+#include "src/fenv/feraiseexcept.h"
+#include "src/fenv/fetestexcept.h"
+
+#include "utils/FPUtil/FEnv.h"
+#include "utils/UnitTest/Test.h"
+
+#include 
+#include 
+
+// This test enables an exception and verifies that raising that exception
+// triggers SIGFPE.
+TEST(ExceptionStatusTest, RaiseAndCrash) {
+  // TODO: Install a floating point exception handler and verify that the
+  // the expected exception was raised. One will have to longjmp back from
+  // that exception handler, so such a testing can be done after we have
+  // longjmp implemented.
+
+  int excepts[] = {FE_DIVBYZERO, FE_INVALID, FE_INEXACT, FE_OVERFLOW,
+   FE_UNDERFLOW};
+
+  for (int e : excepts) {
+ASSERT_DEATH(
+[=] {
+  __llvm_libc::fputil::disableExcept(FE_ALL_EXCEPT);
+  __llvm_libc::fputil::enableExcept(e);
+  ASSERT_EQ(__llvm_libc::feclearexcept(FE_ALL_EXCEPT), 0);
+  // Raising all exceptions except |e| should not call the
+  // SIGFPE handler. They should set the exception flag though,
+  // so we verify that.
+  int others = FE_ALL_EXCEPT & ~e;
+  ASSERT_EQ(__llvm_libc::feraiseexcept(others), 0);
+  ASSERT_EQ(__llvm_libc::fetestexcept(others), others);
+
+  // We don't check the return value when raising |e| as
+  // feraiseexcept will not return when it raises an enabled
+  // exception.
+  __llvm_libc::feraiseexcept(e);
+},
+SIGFPE);
+  }
+}

diff  --git a/libc/test/src/fenv/exception_status_test.cpp 
b/libc/test/src/fenv/exception_status_test.cpp
index 353e5aa6b0e7..193bc58298e1 100644
--- a/libc/test/src/fenv/exception_status_test.cpp
+++ b/libc/test/src/fenv/exception_status_test.cpp
@@ -10,11 +10,18 @@
 #include "src/fenv/feraiseexcept.h"
 #include "src/fenv/fetestexcept.h"
 
+#include "utils/FPUtil/FEnv.h"
 #include "utils/UnitTest/Test.h"
 
 #include 
 
 TEST(ExceptionStatusTest, RaiseAndTest) {
+  // This test raises a set of exceptions and checks that the exception
+  //

[llvm-branch-commits] [libc] 7aeb380 - [libc] Add implementations of lround[f|l] and llround[f|l].

2020-12-11 Thread Siva Chandra Reddy via llvm-branch-commits

Author: Siva Chandra Reddy
Date: 2020-12-11T11:12:40-08:00
New Revision: 7aeb3804c46cc6c8f291415ca09ae34021301eb8

URL: 
https://github.com/llvm/llvm-project/commit/7aeb3804c46cc6c8f291415ca09ae34021301eb8
DIFF: 
https://github.com/llvm/llvm-project/commit/7aeb3804c46cc6c8f291415ca09ae34021301eb8.diff

LOG: [libc] Add implementations of lround[f|l] and llround[f|l].

A new function to MPFRWrapper has been added, which is used to set up
the unit tests.

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D93007

Added: 
libc/src/math/llround.cpp
libc/src/math/llround.h
libc/src/math/llroundf.cpp
libc/src/math/llroundf.h
libc/src/math/llroundl.cpp
libc/src/math/llroundl.h
libc/src/math/lround.cpp
libc/src/math/lround.h
libc/src/math/lroundf.cpp
libc/src/math/lroundf.h
libc/src/math/lroundl.cpp
libc/src/math/lroundl.h
libc/test/src/math/RoundToIntegerTest.h
libc/test/src/math/llround_test.cpp
libc/test/src/math/llroundf_test.cpp
libc/test/src/math/llroundl_test.cpp
libc/test/src/math/lround_test.cpp
libc/test/src/math/lroundf_test.cpp
libc/test/src/math/lroundl_test.cpp

Modified: 
libc/config/linux/x86_64/entrypoints.txt
libc/spec/spec.td
libc/spec/stdc.td
libc/src/math/CMakeLists.txt
libc/test/src/math/CMakeLists.txt
libc/utils/FPUtil/CMakeLists.txt
libc/utils/FPUtil/NearestIntegerOperations.h
libc/utils/MPFRWrapper/MPFRUtils.cpp
libc/utils/MPFRWrapper/MPFRUtils.h

Removed: 




diff  --git a/libc/config/linux/x86_64/entrypoints.txt 
b/libc/config/linux/x86_64/entrypoints.txt
index 4cae553ac6d4..fce28231f319 100644
--- a/libc/config/linux/x86_64/entrypoints.txt
+++ b/libc/config/linux/x86_64/entrypoints.txt
@@ -122,9 +122,15 @@ set(TARGET_LIBM_ENTRYPOINTS
 libc.src.math.ldexp
 libc.src.math.ldexpf
 libc.src.math.ldexpl
+libc.src.math.llround
+libc.src.math.llroundf
+libc.src.math.llroundl
 libc.src.math.logb
 libc.src.math.logbf
 libc.src.math.logbl
+libc.src.math.lround
+libc.src.math.lroundf
+libc.src.math.lroundl
 libc.src.math.modf
 libc.src.math.modff
 libc.src.math.modfl

diff  --git a/libc/spec/spec.td b/libc/spec/spec.td
index 9a31d85c148c..c78c0f053e06 100644
--- a/libc/spec/spec.td
+++ b/libc/spec/spec.td
@@ -39,11 +39,11 @@ class RestrictedPtrType : Type {
 def VarArgType : Type {}
 def VoidType : NamedType<"void">;
 def IntType : NamedType<"int">;
+def LongType : NamedType<"long">;
+def LongLongType : NamedType<"long long">;
 def FloatType : NamedType<"float">;
 def DoubleType : NamedType<"double">;
 def LongDoubleType : NamedType<"long double">;
-def LongLongType : NamedType<"long long">;
-def LongType : NamedType<"long">;
 def CharType : NamedType<"char">;
 
 // Common types

diff  --git a/libc/spec/stdc.td b/libc/spec/stdc.td
index 051e0a89eb27..aca9a1020b1e 100644
--- a/libc/spec/stdc.td
+++ b/libc/spec/stdc.td
@@ -363,6 +363,14 @@ def StdC : StandardSpec<"stdc"> {
   FunctionSpec<"roundf", RetValSpec, [ArgSpec]>,
   FunctionSpec<"roundl", RetValSpec, 
[ArgSpec]>,
 
+  FunctionSpec<"lround", RetValSpec, [ArgSpec]>,
+  FunctionSpec<"lroundf", RetValSpec, [ArgSpec]>,
+  FunctionSpec<"lroundl", RetValSpec, 
[ArgSpec]>,
+
+  FunctionSpec<"llround", RetValSpec, 
[ArgSpec]>,
+  FunctionSpec<"llroundf", RetValSpec, 
[ArgSpec]>,
+  FunctionSpec<"llroundl", RetValSpec, 
[ArgSpec]>,
+
   FunctionSpec<"sqrt", RetValSpec, [ArgSpec]>,
   FunctionSpec<"sqrtf", RetValSpec, [ArgSpec]>,
   FunctionSpec<"sqrtl", RetValSpec, 
[ArgSpec]>,

diff  --git a/libc/src/math/CMakeLists.txt b/libc/src/math/CMakeLists.txt
index 8201d737ddb1..c4de1b1eae86 100644
--- a/libc/src/math/CMakeLists.txt
+++ b/libc/src/math/CMakeLists.txt
@@ -236,6 +236,78 @@ add_entrypoint_object(
 -O2
 )
 
+add_entrypoint_object(
+  lround
+  SRCS
+lround.cpp
+  HDRS
+lround.h
+  DEPENDS
+libc.utils.FPUtil.fputil
+  COMPILE_OPTIONS
+-O2
+)
+
+add_entrypoint_object(
+  lroundf
+  SRCS
+lroundf.cpp
+  HDRS
+lroundf.h
+  DEPENDS
+libc.utils.FPUtil.fputil
+  COMPILE_OPTIONS
+-O2
+)
+
+add_entrypoint_object(
+  lroundl
+  SRCS
+lroundl.cpp
+  HDRS
+lroundl.h
+  DEPENDS
+libc.utils.FPUtil.fputil
+  COMPILE_OPTIONS
+-O2
+)
+
+add_entrypoint_object(
+  llround
+  SRCS
+llround.cpp
+  HDRS
+llround.h
+  DEPENDS
+libc.utils.FPUtil.fputil
+  COMPILE_OPTIONS
+-O2
+)
+
+add_entrypoint_object(
+  llroundf
+  SRCS
+llroundf.cpp
+  HDRS
+llroundf.h
+  DEPENDS
+libc.utils.FPUtil.fputil
+  COMPILE_OPTIONS
+-O2
+)
+
+add_entrypoint_object(
+  llroundl
+  SRCS
+llroundl.cpp
+  HDRS
+llroundl.h
+  DEPENDS
+libc.utils.FPUtil.fputil
+  COMPILE_OPTIONS
+-O2
+)
+
 add_object_library(
   exp_utils
   HDRS

diff  --git

[llvm-branch-commits] [libc] 9ab6c1a - [libc] Let wrappergen pick LLVM libc mangled name from aliasee file.

2020-12-11 Thread Siva Chandra Reddy via llvm-branch-commits

Author: Siva Chandra Reddy
Date: 2020-12-11T14:33:03-08:00
New Revision: 9ab6c1a99f82fa13017ddccc606eecfe24e92043

URL: 
https://github.com/llvm/llvm-project/commit/9ab6c1a99f82fa13017ddccc606eecfe24e92043
DIFF: 
https://github.com/llvm/llvm-project/commit/9ab6c1a99f82fa13017ddccc606eecfe24e92043.diff

LOG: [libc] Let wrappergen pick LLVM libc mangled name from aliasee file.

Along the way, made a change to run tool unittests when the target
"check-libc" is run by introducing a libc testsuite for tool unittests.

Reviewed By: michaelrj

Differential Revision: https://reviews.llvm.org/D93142

Added: 


Modified: 
libc/test/utils/tools/CMakeLists.txt
libc/test/utils/tools/WrapperGen/CMakeLists.txt
libc/test/utils/tools/WrapperGen/wrappergen_test.cpp
libc/utils/tools/WrapperGen/Main.cpp

Removed: 




diff  --git a/libc/test/utils/tools/CMakeLists.txt 
b/libc/test/utils/tools/CMakeLists.txt
index 9a06be546115..0e343f154eac 100644
--- a/libc/test/utils/tools/CMakeLists.txt
+++ b/libc/test/utils/tools/CMakeLists.txt
@@ -1,4 +1,4 @@
-add_custom_target(libc-tool-util-tests)
+add_libc_testsuite(libc-tool-unittests)
 
 function(add_libc_tool_unittest target_name)
 
@@ -27,7 +27,7 @@ function(add_libc_tool_unittest target_name)
 COMMAND $ 
 ${LIBC_TOOL_UNITTEST_ARGS}
   )
-  add_dependencies(libc-tool-util-tests ${target_name})
+  add_dependencies(libc-tool-unittests ${target_name})
 
   target_compile_options(${target_name} PUBLIC -fno-rtti)
   target_link_libraries(${target_name} PRIVATE LLVMSupport)

diff  --git a/libc/test/utils/tools/WrapperGen/CMakeLists.txt 
b/libc/test/utils/tools/WrapperGen/CMakeLists.txt
index cfb3dab15ebf..8f41badd48c4 100644
--- a/libc/test/utils/tools/WrapperGen/CMakeLists.txt
+++ b/libc/test/utils/tools/WrapperGen/CMakeLists.txt
@@ -1,4 +1,5 @@
-add_libc_tool_unittest( wrappergen_test
+add_libc_tool_unittest(
+  wrappergen_test
   SRCS 
 wrappergen_test.cpp   
   ARGS

diff  --git a/libc/test/utils/tools/WrapperGen/wrappergen_test.cpp 
b/libc/test/utils/tools/WrapperGen/wrappergen_test.cpp
index a6c29b7640e8..4cb7a31de942 100644
--- a/libc/test/utils/tools/WrapperGen/wrappergen_test.cpp
+++ b/libc/test/utils/tools/WrapperGen/wrappergen_test.cpp
@@ -12,6 +12,7 @@
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/Error.h"
 #include "llvm/Support/FileSystem.h"
+#include "llvm/Support/FileUtilities.h"
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/Program.h"
 #include "llvm/Support/raw_ostream.h"
@@ -149,6 +150,49 @@ TEST_F(WrapperGenTest, RunWrapperGenOnStrlenWithAliasee) {
   // would break this test.
 }
 
+TEST_F(WrapperGenTest, DeclStrlenAliasUsingAliaseeFile) {
+  llvm::Optional Redirects[] = {
+  llvm::None, llvm::StringRef(STDOutFile.get().TmpName),
+  llvm::StringRef(STDErrFile.get().TmpName)};
+
+  const char *AliaseeFileContent = "abc\nxyz__llvm_libcSTRLEN_ALIAS\nijk\n";
+  llvm::SmallVector AliaseeFilePath;
+  auto AliaseeFileCreateError = llvm::sys::fs::createUniqueFile(
+  "libc-wrappergen-test-aliasee-file-%%-%%-%%-%%.txt", AliaseeFilePath);
+  ASSERT_FALSE(AliaseeFileCreateError);
+  auto AliaseeFileWriteError = llvm::writeFileAtomically(
+  "libc-wrappergen-temp-test-aliasee-file-%%-%%-%%-%%.txt",
+  llvm::StringRef(AliaseeFilePath.data()),
+  llvm::StringRef(AliaseeFileContent));
+  ASSERT_FALSE(AliaseeFileWriteError);
+
+  llvm::StringRef ArgV[] = {ProgPath,
+llvm::StringRef(IncludeArg),
+llvm::StringRef(APIArg),
+"--aliasee-file",
+llvm::StringRef(AliaseeFilePath.data()),
+"--name",
+"strlen"};
+
+  int ExitCode =
+  llvm::sys::ExecuteAndWait(ProgPath, ArgV, llvm::None, Redirects);
+
+  EXPECT_EQ(ExitCode, 0);
+
+  auto STDErrOrError = llvm::MemoryBuffer::getFile(STDErrFile.get().TmpName);
+  std::string STDErrOutput = STDErrOrError.get()->getBuffer().str();
+
+  ASSERT_EQ(STDErrOutput, "");
+
+  auto STDOutOrError = llvm::MemoryBuffer::getFile(STDOutFile.get().TmpName);
+  std::string STDOutOutput = STDOutOrError.get()->getBuffer().str();
+
+  ASSERT_EQ(STDOutOutput,
+"extern \"C\" size_t strlen(const char * __arg0) "
+"__attribute__((alias(\"xyz__llvm_libcSTRLEN_ALIAS\")));\n");
+}
+
+/
 /
 // BAD INPUT TESTS
 // all of the tests after this point are testing inputs that should
@@ -245,3 +289,34 @@ TEST_F(WrapperGenTest, 
RunWrapperGenOnStrlenWithBadAliaseeFile) {
 
   ASSERT_EQ(STDOutOutput, "");
 }
+
+TEST_F(WrapperGenTest, RunWithAliaseeFileMissingLLVMLibcName) {
+  llvm::Optional Redirects[] = {
+  llvm::None, llvm::StringRef(STDOutFile.get().TmpName),
+  l

[llvm-branch-commits] [libc] 9ad2091 - [libc][Obvious] Include from DummyFenv.h.

2020-12-14 Thread Siva Chandra Reddy via llvm-branch-commits

Author: Siva Chandra Reddy
Date: 2020-12-14T08:51:54-08:00
New Revision: 9ad2091e78eb47e6707abbc7c83e208ea1150589

URL: 
https://github.com/llvm/llvm-project/commit/9ad2091e78eb47e6707abbc7c83e208ea1150589
DIFF: 
https://github.com/llvm/llvm-project/commit/9ad2091e78eb47e6707abbc7c83e208ea1150589.diff

LOG: [libc][Obvious] Include  from DummyFenv.h.

Added: 


Modified: 
libc/utils/FPUtil/DummyFEnv.h

Removed: 




diff  --git a/libc/utils/FPUtil/DummyFEnv.h b/libc/utils/FPUtil/DummyFEnv.h
index e303f6c2e690..4f4c2c05a231 100644
--- a/libc/utils/FPUtil/DummyFEnv.h
+++ b/libc/utils/FPUtil/DummyFEnv.h
@@ -9,6 +9,7 @@
 #ifndef LLVM_LIBC_UTILS_FPUTIL_DUMMY_FENV_H
 #define LLVM_LIBC_UTILS_FPUTIL_DUMMY_FENV_H
 
+#include 
 #include 
 
 namespace __llvm_libc {



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits