[libc][math] Add place-holder implementation for pow function.

Add place-holder implementation for pow function to unblock libc demo
examples.

Reviewed By: michaelrj

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

GitOrigin-RevId: 45233cc1ca26c2fb6eeddd9007c7bac2731557bd
diff --git a/config/linux/aarch64/entrypoints.txt b/config/linux/aarch64/entrypoints.txt
index 440bc2b..4accc14 100644
--- a/config/linux/aarch64/entrypoints.txt
+++ b/config/linux/aarch64/entrypoints.txt
@@ -280,6 +280,7 @@
     libc.src.math.nextafter
     libc.src.math.nextafterf
     libc.src.math.nextafterl
+    libc.src.math.pow
     libc.src.math.remainderf
     libc.src.math.remainder
     libc.src.math.remainderl
diff --git a/config/linux/x86_64/entrypoints.txt b/config/linux/x86_64/entrypoints.txt
index cef4e26..b8d962d 100644
--- a/config/linux/x86_64/entrypoints.txt
+++ b/config/linux/x86_64/entrypoints.txt
@@ -282,6 +282,7 @@
     libc.src.math.nextafter
     libc.src.math.nextafterf
     libc.src.math.nextafterl
+    libc.src.math.pow
     libc.src.math.remainderf
     libc.src.math.remainder
     libc.src.math.remainderl
diff --git a/config/windows/entrypoints.txt b/config/windows/entrypoints.txt
index d50927e..69a0aca 100644
--- a/config/windows/entrypoints.txt
+++ b/config/windows/entrypoints.txt
@@ -182,6 +182,7 @@
     libc.src.math.nextafter
     libc.src.math.nextafterf
     libc.src.math.nextafterl
+    libc.src.math.pow
     libc.src.math.remainderf
     libc.src.math.remainder
     libc.src.math.remainderl
diff --git a/spec/stdc.td b/spec/stdc.td
index 22e233c..1c0d7c2 100644
--- a/spec/stdc.td
+++ b/spec/stdc.td
@@ -477,6 +477,8 @@
           FunctionSpec<"nextafter", RetValSpec<DoubleType>, [ArgSpec<DoubleType>, ArgSpec<DoubleType>]>,
           FunctionSpec<"nextafterl", RetValSpec<LongDoubleType>, [ArgSpec<LongDoubleType>, ArgSpec<LongDoubleType>]>,
 
+          FunctionSpec<"pow", RetValSpec<DoubleType>, [ArgSpec<DoubleType>, ArgSpec<DoubleType>]>,
+
           FunctionSpec<"coshf", RetValSpec<FloatType>, [ArgSpec<FloatType>]>,
           FunctionSpec<"sinhf", RetValSpec<FloatType>, [ArgSpec<FloatType>]>,
           FunctionSpec<"tanhf", RetValSpec<FloatType>, [ArgSpec<FloatType>]>,
diff --git a/src/math/CMakeLists.txt b/src/math/CMakeLists.txt
index 0c425c7..cd0985a 100644
--- a/src/math/CMakeLists.txt
+++ b/src/math/CMakeLists.txt
@@ -171,6 +171,8 @@
 add_math_entrypoint_object(nextafterf)
 add_math_entrypoint_object(nextafterl)
 
+add_math_entrypoint_object(pow)
+
 add_math_entrypoint_object(remainder)
 add_math_entrypoint_object(remainderf)
 add_math_entrypoint_object(remainderl)
diff --git a/src/math/generic/CMakeLists.txt b/src/math/generic/CMakeLists.txt
index 5061759..21f993c 100644
--- a/src/math/generic/CMakeLists.txt
+++ b/src/math/generic/CMakeLists.txt
@@ -1368,3 +1368,15 @@
     -O3
 )
 
+add_entrypoint_object(
+  pow
+  SRCS
+    pow.cpp
+  HDRS
+    ../pow.h
+  DEPENDS
+    .expf
+    .logf
+  COMPILE_OPTIONS
+    -O3
+)
diff --git a/src/math/generic/pow.cpp b/src/math/generic/pow.cpp
new file mode 100644
index 0000000..77f8668
--- /dev/null
+++ b/src/math/generic/pow.cpp
@@ -0,0 +1,24 @@
+//===-- Implementation of pow 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/math/pow.h"
+#include "src/math/expf.h"
+#include "src/math/logf.h"
+
+#include "src/__support/common.h"
+
+namespace __llvm_libc {
+
+LLVM_LIBC_FUNCTION(double, pow, (double x, double y)) {
+  // Place-holder implementation for double precision pow function.
+  // TODO: Implement correctly rounded pow function for double precision.
+  return static_cast<double>(
+      expf(static_cast<float>(y) * logf(static_cast<float>(x))));
+}
+
+} // namespace __llvm_libc
diff --git a/src/math/pow.h b/src/math/pow.h
new file mode 100644
index 0000000..26fed17
--- /dev/null
+++ b/src/math/pow.h
@@ -0,0 +1,18 @@
+//===-- Implementation header for pow ---------------------------*- 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_POW_H
+#define LLVM_LIBC_SRC_MATH_POW_H
+
+namespace __llvm_libc {
+
+double pow(double x, double y);
+
+} // namespace __llvm_libc
+
+#endif // LLVM_LIBC_SRC_MATH_POW_H
diff --git a/test/src/math/CMakeLists.txt b/test/src/math/CMakeLists.txt
index c285c35..68adecb 100644
--- a/test/src/math/CMakeLists.txt
+++ b/test/src/math/CMakeLists.txt
@@ -1521,6 +1521,19 @@
     libc.src.__support.FPUtil.fp_bits
 )
 
+add_fp_unittest(
+  pow_test
+  NEED_MPFR
+  SUITE
+    libc_math_unittests
+  SRCS
+    pow_test.cpp
+  DEPENDS
+  libc.include.errno
+  libc.src.errno.errno
+  libc.src.math.pow
+)
+
 add_subdirectory(generic)
 add_subdirectory(exhaustive)
 add_subdirectory(differential_testing)
diff --git a/test/src/math/pow_test.cpp b/test/src/math/pow_test.cpp
new file mode 100644
index 0000000..effade0
--- /dev/null
+++ b/test/src/math/pow_test.cpp
@@ -0,0 +1,37 @@
+//===-- Unittests for pow -------------------------------------------------===//
+//
+// 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/pow.h"
+#include "utils/MPFRWrapper/MPFRUtils.h"
+#include "utils/UnitTest/FPMatcher.h"
+#include "utils/UnitTest/Test.h"
+#include <math.h>
+
+#include <errno.h>
+#include <stdint.h>
+
+using FPBits = __llvm_libc::fputil::FPBits<double>;
+
+namespace mpfr = __llvm_libc::testing::mpfr;
+
+DECLARE_SPECIAL_CONSTANTS(double)
+
+TEST(LlvmLibcAsinTest, SpecialNumbers) {
+  errno = 0;
+
+  EXPECT_FP_EQ(aNaN, __llvm_libc::pow(aNaN, aNaN));
+  EXPECT_MATH_ERRNO(0);
+
+  EXPECT_FP_EQ(1.0, __llvm_libc::pow(1.0, 1.0));
+  EXPECT_MATH_ERRNO(0);
+
+  EXPECT_FP_EQ(1.0, __llvm_libc::pow(1.0, 2.0));
+  EXPECT_MATH_ERRNO(0);
+
+  EXPECT_FP_EQ(inf, __llvm_libc::pow(2.0, inf));
+}