1 // Copyright 2020, 2021 Francesco Biscani (bluescarni@gmail.com), Dario Izzo (dario.izzo@gmail.com)
2 //
3 // This file is part of the heyoka library.
4 //
5 // This Source Code Form is subject to the terms of the Mozilla
6 // Public License v. 2.0. If a copy of the MPL was not distributed
7 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 
9 #ifndef HEYOKA_MATH_SQRT_HPP
10 #define HEYOKA_MATH_SQRT_HPP
11 
12 #include <cstdint>
13 #include <string>
14 #include <unordered_map>
15 #include <vector>
16 
17 #include <heyoka/config.hpp>
18 #include <heyoka/detail/fwd_decl.hpp>
19 #include <heyoka/detail/llvm_fwd.hpp>
20 #include <heyoka/detail/visibility.hpp>
21 #include <heyoka/func.hpp>
22 #include <heyoka/s11n.hpp>
23 
24 namespace heyoka
25 {
26 
27 namespace detail
28 {
29 
30 class HEYOKA_DLL_PUBLIC sqrt_impl : public func_base
31 {
32     friend class boost::serialization::access;
33     template <typename Archive>
serialize(Archive & ar,unsigned)34     void serialize(Archive &ar, unsigned)
35     {
36         ar &boost::serialization::base_object<func_base>(*this);
37     }
38 
39 public:
40     sqrt_impl();
41     explicit sqrt_impl(expression);
42 
43     llvm::Value *codegen_dbl(llvm_state &, const std::vector<llvm::Value *> &) const;
44     llvm::Value *codegen_ldbl(llvm_state &, const std::vector<llvm::Value *> &) const;
45 #if defined(HEYOKA_HAVE_REAL128)
46     llvm::Value *codegen_f128(llvm_state &, const std::vector<llvm::Value *> &) const;
47 #endif
48 
49     expression diff(std::unordered_map<const void *, expression> &, const std::string &) const;
50     expression diff(std::unordered_map<const void *, expression> &, const param &) const;
51 
52     double eval_dbl(const std::unordered_map<std::string, double> &, const std::vector<double> &) const;
53     long double eval_ldbl(const std::unordered_map<std::string, long double> &, const std::vector<long double> &) const;
54 #if defined(HEYOKA_HAVE_REAL128)
55     mppp::real128 eval_f128(const std::unordered_map<std::string, mppp::real128> &,
56                             const std::vector<mppp::real128> &) const;
57 #endif
58 
59     void eval_batch_dbl(std::vector<double> &, const std::unordered_map<std::string, std::vector<double>> &,
60                         const std::vector<double> &) const;
61     double eval_num_dbl(const std::vector<double> &) const;
62     double deval_num_dbl(const std::vector<double> &, std::vector<double>::size_type) const;
63 
64     llvm::Value *taylor_diff_dbl(llvm_state &, const std::vector<std::uint32_t> &, const std::vector<llvm::Value *> &,
65                                  llvm::Value *, llvm::Value *, std::uint32_t, std::uint32_t, std::uint32_t,
66                                  std::uint32_t, bool) const;
67     llvm::Value *taylor_diff_ldbl(llvm_state &, const std::vector<std::uint32_t> &, const std::vector<llvm::Value *> &,
68                                   llvm::Value *, llvm::Value *, std::uint32_t, std::uint32_t, std::uint32_t,
69                                   std::uint32_t, bool) const;
70 #if defined(HEYOKA_HAVE_REAL128)
71     llvm::Value *taylor_diff_f128(llvm_state &, const std::vector<std::uint32_t> &, const std::vector<llvm::Value *> &,
72                                   llvm::Value *, llvm::Value *, std::uint32_t, std::uint32_t, std::uint32_t,
73                                   std::uint32_t, bool) const;
74 #endif
75     llvm::Function *taylor_c_diff_func_dbl(llvm_state &, std::uint32_t, std::uint32_t, bool) const;
76     llvm::Function *taylor_c_diff_func_ldbl(llvm_state &, std::uint32_t, std::uint32_t, bool) const;
77 #if defined(HEYOKA_HAVE_REAL128)
78     llvm::Function *taylor_c_diff_func_f128(llvm_state &, std::uint32_t, std::uint32_t, bool) const;
79 #endif
80 };
81 
82 } // namespace detail
83 
84 HEYOKA_DLL_PUBLIC expression sqrt(expression);
85 
86 } // namespace heyoka
87 
88 HEYOKA_S11N_FUNC_EXPORT_KEY(heyoka::detail::sqrt_impl)
89 
90 #endif
91