summaryrefslogtreecommitdiffstats
path: root/libc/src/math/round
diff options
context:
space:
mode:
authorSiva Chandra Reddy <sivachandra@google.com>2019-10-15 13:25:36 -0700
committerSiva Chandra Reddy <sivachandra@google.com>2019-11-01 11:06:12 -0700
commit9364107cf348c7d4a2d05b8906bda6ba384ce6f6 (patch)
tree6e9b56d55d882f360a19eb927be5af4e1998640e /libc/src/math/round
parent9b0dfdf5e1939b4129df75cc8e8d57fcf451b786 (diff)
downloadbcm5719-llvm-9364107cf348c7d4a2d05b8906bda6ba384ce6f6.tar.gz
bcm5719-llvm-9364107cf348c7d4a2d05b8906bda6ba384ce6f6.zip
Illustrate a redirector using the example of round function from math.h.
Setup demonstrated in this patch is only for ELF-ish platforms. Also note: 1. Use of redirectors is a temporary scheme. They will be removed once LLVM-libc has implementations for the redirected functions. 2. Redirectors are optional. One can choose to not include them in the LLVM-libc build for their platform. 3. Even with redirectors used, we want to link to the system libc dynamically. Reviewers: dlj, hfinkel, jakehehrlich, phosek, stanshebs, theraven, alexshap Subscribers: mgorny, libc-commits Tags: #libc-project Differential Revision: https://reviews.llvm.org/D69020
Diffstat (limited to 'libc/src/math/round')
-rw-r--r--libc/src/math/round/CMakeLists.txt14
-rw-r--r--libc/src/math/round/round.cpp21
-rw-r--r--libc/src/math/round/round.h18
-rw-r--r--libc/src/math/round/round_redirector.cpp17
4 files changed, 70 insertions, 0 deletions
diff --git a/libc/src/math/round/CMakeLists.txt b/libc/src/math/round/CMakeLists.txt
new file mode 100644
index 00000000000..e7ad9d2a73f
--- /dev/null
+++ b/libc/src/math/round/CMakeLists.txt
@@ -0,0 +1,14 @@
+add_entrypoint_object(
+ round
+ REDIRECTED
+ SRCS
+ round.cpp
+ HDRS
+ round.h
+)
+
+add_redirector_object(
+ round_redirector
+ SRC
+ round_redirector.cpp
+)
diff --git a/libc/src/math/round/round.cpp b/libc/src/math/round/round.cpp
new file mode 100644
index 00000000000..7352b98269f
--- /dev/null
+++ b/libc/src/math/round/round.cpp
@@ -0,0 +1,21 @@
+//===---------------------- Implementation of round -----------------------===//
+//
+// 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/math/round/round.h"
+
+#include "src/__support/common.h"
+
+namespace llvm_libc {
+
+double __round_redirector(double x);
+
+double LLVM_LIBC_ENTRYPOINT(round)(double x) {
+ return __round_redirector(x);
+}
+
+} // namespace llvm_libc
diff --git a/libc/src/math/round/round.h b/libc/src/math/round/round.h
new file mode 100644
index 00000000000..c13ecccfeca
--- /dev/null
+++ b/libc/src/math/round/round.h
@@ -0,0 +1,18 @@
+//===------------------ Implementation header for round -------------------===//
+//
+// 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_ROUND_H
+#define LLVM_LIBC_SRC_MATH_ROUND_H
+
+namespace llvm_libc {
+
+double round(double x);
+
+} // namespace llvm_libc
+
+#endif // LLVM_LIBC_SRC_MATH_ROUND_H
diff --git a/libc/src/math/round/round_redirector.cpp b/libc/src/math/round/round_redirector.cpp
new file mode 100644
index 00000000000..8d37b0895c7
--- /dev/null
+++ b/libc/src/math/round/round_redirector.cpp
@@ -0,0 +1,17 @@
+//===---------------- Implementation of round redirector -----------------===//
+//
+// 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 <math.h>
+
+namespace llvm_libc {
+
+double __round_redirector(double x) {
+ return ::round(x);
+}
+
+} // namespace llvm_libc
OpenPOWER on IntegriCloud