74 changes: 74 additions & 0 deletions libc/src/math/generic/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3145,6 +3145,80 @@ add_entrypoint_object(
libc.src.__support.FPUtil.basic_operations
)

add_entrypoint_object(
fdiv
SRCS
fdiv.cpp
HDRS
../fdiv.h
COMPILE_OPTIONS
-O3
DEPENDS
libc.src.__support.FPUtil.generic.div
)

add_entrypoint_object(
fdivl
SRCS
fdivl.cpp
HDRS
../fdivl.h
COMPILE_OPTIONS
-O3
DEPENDS
libc.src.__support.FPUtil.generic.div
)

add_entrypoint_object(
fdivf128
SRCS
fdivf128.cpp
HDRS
../fdivf128.h
COMPILE_OPTIONS
-O3
DEPENDS
libc.src.__support.macros.properties.types
libc.src.__support.FPUtil.generic.div
)

add_entrypoint_object(
ffma
SRCS
ffma.cpp
HDRS
../ffma.h
COMPILE_OPTIONS
-O3
DEPENDS
libc.src.__support.FPUtil.fma
)

add_entrypoint_object(
ffmal
SRCS
ffmal.cpp
HDRS
../ffmal.h
COMPILE_OPTIONS
-O3
DEPENDS
libc.src.__support.FPUtil.fma
)

add_entrypoint_object(
ffmaf128
SRCS
ffmaf128.cpp
HDRS
../ffmaf128.h
COMPILE_OPTIONS
-O3
DEPENDS
libc.src.__support.macros.properties.types
libc.src.__support.FPUtil.fma
)

add_entrypoint_object(
hypot
SRCS
Expand Down
20 changes: 20 additions & 0 deletions libc/src/math/generic/fdiv.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//===-- Implementation of fdiv 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/fdiv.h"
#include "src/__support/FPUtil/generic/div.h"
#include "src/__support/common.h"
#include "src/__support/macros/config.h"

namespace LIBC_NAMESPACE_DECL {

LLVM_LIBC_FUNCTION(float, fdiv, (double x, double y)) {
return fputil::generic::div<float>(x, y);
}

} // namespace LIBC_NAMESPACE_DECL
20 changes: 20 additions & 0 deletions libc/src/math/generic/fdivf128.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//===-- Implementation of fdivf128 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/fdivf128.h"
#include "src/__support/FPUtil/generic/div.h"
#include "src/__support/common.h"
#include "src/__support/macros/config.h"

namespace LIBC_NAMESPACE_DECL {

LLVM_LIBC_FUNCTION(float, fdivf128, (float128 x, float128 y)) {
return fputil::generic::div<float>(x, y);
}

} // namespace LIBC_NAMESPACE_DECL
20 changes: 20 additions & 0 deletions libc/src/math/generic/fdivl.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//===-- Implementation of fdivl 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/fdivl.h"
#include "src/__support/FPUtil/generic/div.h"
#include "src/__support/common.h"
#include "src/__support/macros/config.h"

namespace LIBC_NAMESPACE_DECL {

LLVM_LIBC_FUNCTION(float, fdivl, (long double x, long double y)) {
return fputil::generic::div<float>(x, y);
}

} // namespace LIBC_NAMESPACE_DECL
20 changes: 20 additions & 0 deletions libc/src/math/generic/ffma.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//===-- Implementation of ffma 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/ffma.h"
#include "src/__support/FPUtil/FMA.h"
#include "src/__support/common.h"
#include "src/__support/macros/config.h"

namespace LIBC_NAMESPACE_DECL {

LLVM_LIBC_FUNCTION(float, ffma, (double x, double y, double z)) {
return fputil::fma<float>(x, y, z);
}

} // namespace LIBC_NAMESPACE_DECL
20 changes: 20 additions & 0 deletions libc/src/math/generic/ffmaf128.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//===-- Implementation of ffmaf128 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/ffmaf128.h"
#include "src/__support/FPUtil/FMA.h"
#include "src/__support/common.h"
#include "src/__support/macros/config.h"

namespace LIBC_NAMESPACE_DECL {

LLVM_LIBC_FUNCTION(float, ffmaf128, (float128 x, float128 y, float128 z)) {
return fputil::fma<float>(x, y, z);
}

} // namespace LIBC_NAMESPACE_DECL
21 changes: 21 additions & 0 deletions libc/src/math/generic/ffmal.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//===-- Implementation of ffmal 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/ffmal.h"
#include "src/__support/FPUtil/FMA.h"
#include "src/__support/common.h"
#include "src/__support/macros/config.h"

namespace LIBC_NAMESPACE_DECL {

LLVM_LIBC_FUNCTION(float, ffmal,
(long double x, long double y, long double z)) {
return fputil::fma<float>(x, y, z);
}

} // namespace LIBC_NAMESPACE_DECL
57 changes: 57 additions & 0 deletions libc/test/src/math/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2455,6 +2455,63 @@ add_fp_unittest(
libc.src.math.dsubl
)

add_fp_unittest(
fdiv_test
NEED_MPFR
SUITE
libc-math-unittests
SRCS
fdiv_test.cpp
HDRS
DivTest.h
DEPENDS
libc.src.math.fdiv
)

add_fp_unittest(
fdivl_test
NEED_MPFR
SUITE
libc-math-unittests
SRCS
fdivl_test.cpp
HDRS
DivTest.h
DEPENDS
libc.src.math.fdivl
)


add_fp_unittest(
ffma_test
NEED_MPFR
SUITE
libc-math-unittests
SRCS
ffma_test.cpp
HDRS
FmaTest.h
DEPENDS
libc.src.math.ffma
libc.src.stdlib.rand
libc.src.stdlib.srand
)

add_fp_unittest(
ffmal_test
NEED_MPFR
SUITE
libc-math-unittests
SRCS
ffmal_test.cpp
HDRS
FmaTest.h
DEPENDS
libc.src.math.ffmal
libc.src.stdlib.rand
libc.src.stdlib.srand
)


add_subdirectory(generic)
add_subdirectory(smoke)
Expand Down
13 changes: 13 additions & 0 deletions libc/test/src/math/fdiv_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//===-- Unittests for fdiv ------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#include "DivTest.h"

#include "src/math/fdiv.h"

LIST_DIV_TESTS(float, double, LIBC_NAMESPACE::fdiv)
13 changes: 13 additions & 0 deletions libc/test/src/math/fdivl_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//===-- Unittests for fdivl -----------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#include "DivTest.h"

#include "src/math/fdivl.h"

LIST_DIV_TESTS(float, long double, LIBC_NAMESPACE::fdivl)
13 changes: 13 additions & 0 deletions libc/test/src/math/ffma_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//===-- Unittests for ffma ------------------------------------------------===//
//
// 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 "FmaTest.h"

#include "src/math/ffma.h"

LIST_NARROWING_FMA_TESTS(float, double, LIBC_NAMESPACE::ffma)
13 changes: 13 additions & 0 deletions libc/test/src/math/ffmal_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//===-- Unittests for ffmal -----------------------------------------------===//
//
// 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 "FmaTest.h"

#include "src/math/ffmal.h"

LIST_NARROWING_FMA_TESTS(float, long double, LIBC_NAMESPACE::ffmal)
86 changes: 82 additions & 4 deletions libc/test/src/math/smoke/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4070,8 +4070,8 @@ add_fp_unittest(
HDRS
DivTest.h
DEPENDS
libc.hdr.errno_macros
libc.hdr.fenv_macros
libc.src.__support.FPUtil.basic_operations
libc.src.math.f16div
)

Expand All @@ -4084,8 +4084,8 @@ add_fp_unittest(
HDRS
DivTest.h
DEPENDS
libc.hdr.errno_macros
libc.hdr.fenv_macros
libc.src.__support.FPUtil.basic_operations
libc.src.math.f16divf
)

Expand All @@ -4098,8 +4098,8 @@ add_fp_unittest(
HDRS
DivTest.h
DEPENDS
libc.hdr.errno_macros
libc.hdr.fenv_macros
libc.src.__support.FPUtil.basic_operations
libc.src.math.f16divl
)

Expand All @@ -4112,8 +4112,8 @@ add_fp_unittest(
HDRS
DivTest.h
DEPENDS
libc.hdr.errno_macros
libc.hdr.fenv_macros
libc.src.__support.FPUtil.basic_operations
libc.src.math.f16divf128
)

Expand Down Expand Up @@ -4213,6 +4213,84 @@ add_fp_unittest(
libc.src.math.f16sqrtf128
)

add_fp_unittest(
fdiv_test
SUITE
libc-math-smoke-tests
SRCS
fdiv_test.cpp
HDRS
DivTest.h
DEPENDS
libc.hdr.errno_macros
libc.hdr.fenv_macros
libc.src.math.fdiv
)

add_fp_unittest(
fdivl_test
SUITE
libc-math-smoke-tests
SRCS
fdivl_test.cpp
HDRS
DivTest.h
DEPENDS
libc.hdr.errno_macros
libc.hdr.fenv_macros
libc.src.math.fdivl
)

add_fp_unittest(
fdivf128_test
SUITE
libc-math-smoke-tests
SRCS
fdivf128_test.cpp
HDRS
DivTest.h
DEPENDS
libc.hdr.errno_macros
libc.hdr.fenv_macros
libc.src.math.fdivf128
)

add_fp_unittest(
ffma_test
SUITE
libc-math-smoke-tests
SRCS
ffma_test.cpp
HDRS
FmaTest.h
DEPENDS
libc.src.math.ffma
)

add_fp_unittest(
ffmal_test
SUITE
libc-math-smoke-tests
SRCS
ffmal_test.cpp
HDRS
FmaTest.h
DEPENDS
libc.src.math.ffmal
)

add_fp_unittest(
ffmaf128_test
SUITE
libc-math-smoke-tests
SRCS
ffmaf128_test.cpp
HDRS
FmaTest.h
DEPENDS
libc.src.math.ffmaf128
)

add_fp_unittest(
fsqrt_test
SUITE
Expand Down
2 changes: 1 addition & 1 deletion libc/test/src/math/smoke/DivTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
#ifndef LLVM_LIBC_TEST_SRC_MATH_SMOKE_DIVTEST_H
#define LLVM_LIBC_TEST_SRC_MATH_SMOKE_DIVTEST_H

#include "hdr/errno_macros.h"
#include "hdr/fenv_macros.h"
#include "src/__support/FPUtil/BasicOperations.h"
#include "test/UnitTest/FEnvSafeTest.h"
#include "test/UnitTest/FPMatcher.h"
#include "test/UnitTest/RoundingModeUtils.h"
Expand Down
13 changes: 13 additions & 0 deletions libc/test/src/math/smoke/fdiv_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//===-- Unittests for fdiv ------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#include "DivTest.h"

#include "src/math/fdiv.h"

LIST_DIV_TESTS(float, double, LIBC_NAMESPACE::fdiv)
13 changes: 13 additions & 0 deletions libc/test/src/math/smoke/fdivf128_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//===-- Unittests for fdivf128 --------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#include "DivTest.h"

#include "src/math/fdivf128.h"

LIST_DIV_TESTS(float, float128, LIBC_NAMESPACE::fdivf128)
13 changes: 13 additions & 0 deletions libc/test/src/math/smoke/fdivl_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//===-- Unittests for fdivl -----------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#include "DivTest.h"

#include "src/math/fdivl.h"

LIST_DIV_TESTS(float, long double, LIBC_NAMESPACE::fdivl)
13 changes: 13 additions & 0 deletions libc/test/src/math/smoke/ffma_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//===-- Unittests for ffma ------------------------------------------------===//
//
// 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 "FmaTest.h"

#include "src/math/ffma.h"

LIST_NARROWING_FMA_TESTS(float, double, LIBC_NAMESPACE::ffma)
13 changes: 13 additions & 0 deletions libc/test/src/math/smoke/ffmaf128_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//===-- Unittests for ffmaf128 --------------------------------------------===//
//
// 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 "FmaTest.h"

#include "src/math/ffmaf128.h"

LIST_NARROWING_FMA_TESTS(float, float128, LIBC_NAMESPACE::ffmaf128)
13 changes: 13 additions & 0 deletions libc/test/src/math/smoke/ffmal_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//===-- Unittests for ffmal -----------------------------------------------===//
//
// 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 "FmaTest.h"

#include "src/math/ffmal.h"

LIST_NARROWING_FMA_TESTS(float, long double, LIBC_NAMESPACE::ffmal)
17 changes: 13 additions & 4 deletions libc/utils/MPFRWrapper/MPFRUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1080,15 +1080,19 @@ void explain_ternary_operation_one_output_error(

template void explain_ternary_operation_one_output_error(
Operation, const TernaryInput<float> &, float, double, RoundingMode);
template void explain_ternary_operation_one_output_error(
Operation, const TernaryInput<double> &, float, double, RoundingMode);
template void explain_ternary_operation_one_output_error(
Operation, const TernaryInput<double> &, double, double, RoundingMode);
template void explain_ternary_operation_one_output_error(
Operation, const TernaryInput<long double> &, float, double, RoundingMode);
template void explain_ternary_operation_one_output_error(
Operation, const TernaryInput<long double> &, double, double, RoundingMode);
template void
explain_ternary_operation_one_output_error(Operation,
const TernaryInput<long double> &,
long double, double, RoundingMode);

template void explain_ternary_operation_one_output_error(
Operation, const TernaryInput<long double> &, double, double, RoundingMode);
#ifdef LIBC_TYPES_HAS_FLOAT16
template void explain_ternary_operation_one_output_error(
Operation, const TernaryInput<float> &, float16, double, RoundingMode);
Expand Down Expand Up @@ -1266,17 +1270,22 @@ bool compare_ternary_operation_one_output(Operation op,
template bool compare_ternary_operation_one_output(Operation,
const TernaryInput<float> &,
float, double, RoundingMode);
template bool compare_ternary_operation_one_output(Operation,
const TernaryInput<double> &,
float, double, RoundingMode);
template bool compare_ternary_operation_one_output(Operation,
const TernaryInput<double> &,
double, double,
RoundingMode);
template bool compare_ternary_operation_one_output(
Operation, const TernaryInput<long double> &, float, double, RoundingMode);
template bool compare_ternary_operation_one_output(
Operation, const TernaryInput<long double> &, double, double, RoundingMode);
template bool
compare_ternary_operation_one_output(Operation,
const TernaryInput<long double> &,
long double, double, RoundingMode);

template bool compare_ternary_operation_one_output(
Operation, const TernaryInput<long double> &, double, double, RoundingMode);
#ifdef LIBC_TYPES_HAS_FLOAT16
template bool compare_ternary_operation_one_output(Operation,
const TernaryInput<float> &,
Expand Down