Skip to content

Commit

Permalink
OK
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrii Verbytskyi committed Dec 14, 2024
1 parent 6aed397 commit 3163999
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 25 deletions.
2 changes: 1 addition & 1 deletion src/cache.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace std {
seed ^= hasher(v) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
}

#ifdef __x86_64__
#if defined(__x86_64__) || defined(__i386__)
template <>
struct hash<ql::qdouble> : public __hash_base<size_t, ql::qdouble>
{
Expand Down
35 changes: 21 additions & 14 deletions src/qcdloop/maths.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,43 +21,47 @@ namespace ql
{
// Logarithms
inline double Log(double const& x) { return std::log(x); }
#ifdef __x86_64__
#if defined(__x86_64__) || defined(__i386__)
inline qdouble Log(qdouble const& x) { return logq(x); }
inline qcomplex Log(qcomplex const& x) { return clogq(x); }
#else
#endif
#if defined(__aarch64__)
inline qdouble Log(qdouble const& x) { return std::log(x); }
inline qcomplex Log(qcomplex const& x) { return clogl(x); }
#endif
inline complex Log(complex const& x) { return std::log(x); }

// Power
inline double Pow(double const& x, int const& a) { return std::pow(x, a); }
#ifdef __x86_64__
#if defined(__x86_64__) || defined(__i386__)
inline qdouble Pow(qdouble const& x, int const& a) { return powq(x,a); }
inline qcomplex Pow(qcomplex const& x, int const& a){ return cpowq(x,a); }
#else
#endif
#if defined(__aarch64__)
inline qdouble Pow(qdouble const& x, int const& a) { return std::pow(x,a); }
inline qcomplex Pow(qcomplex const& x, int const& a){ return cpowl(x,a); }
#endif
inline complex Pow(complex const& x, int const& a) { return std::pow(x,a); }

// Root
inline double Sqrt(double const& x) { return std::sqrt(x); }
#ifdef __x86_64__
#if defined(__x86_64__) || defined(__i386__)
inline qdouble Sqrt(qdouble const& x) { return sqrtq(x); }
inline qcomplex Sqrt(qcomplex const& x){ return csqrtq(x); }
#else
#endif
#if defined(__aarch64__)
inline qdouble Sqrt(qdouble const& x) { return std::sqrt(x); }
inline qcomplex Sqrt(qcomplex const& x){ return csqrtl(x); }
#endif
inline complex Sqrt(complex const& x) { return std::sqrt(x); }

// Absolute value
inline double Abs(double const& x) { return std::abs(x); }
#ifdef __x86_64__
#if defined(__x86_64__) || defined(__i386__)
inline qdouble Abs(qdouble const& x) { return fabsq(x);}
inline qdouble Abs(qcomplex const& x) { return cabsq(x); }
#else
#endif
#if defined(__aarch64__)
inline qdouble Abs(qdouble const& x) { return std::abs(x);}
inline qdouble Abs(qcomplex const& x) { return cabsl(x); }
#endif
Expand All @@ -67,25 +71,28 @@ namespace ql
inline double Imag(double const& x) { UNUSED(x); return 0; }
inline qdouble Imag(qdouble const& x) { UNUSED(x); return qdouble(0); }
inline double Imag(complex const& x) { return x.imag(); }
#ifdef __x86_64__
#if defined(__x86_64__) || defined(__i386__)
inline qdouble Imag(qcomplex const& x){ return cimagq(x);}
#else
#endif
#if defined(__aarch64__)
inline qdouble Imag(qcomplex const& x){ return cimagl(x);}
#endif

inline double Real(double const& x) { return x; }
inline qdouble Real(qdouble const& x) { return x; }
inline double Real(complex const& x) { return x.real(); }
#ifdef __x86_64__
#if defined(__x86_64__) || defined(__i386__)
inline qdouble Real(qcomplex const& x) { return crealq(x); }
#else
#endif
#if defined(__aarch64__)
inline qdouble Real(qcomplex const& x) { return creall(x); }
#endif

inline complex Conjg(complex const& x) { return std::conj(x); }
#ifdef __x86_64__
#if defined(__x86_64__) || defined(__i386__)
inline qcomplex Conjg(qcomplex const& x){ return conjq(x); }
#else
#endif
#if defined(__aarch64__)
inline qcomplex Conjg(qcomplex const& x){ return conjl(x); }
#endif

Expand Down
11 changes: 5 additions & 6 deletions src/qcdloop/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,18 @@

#pragma once

#ifdef __x86_64__
#if defined(__x86_64__) || defined(__i386__)
extern "C" { // for gcc4.7 compatibility
#include <quadmath.h>
}
#else
#endif
#ifdef __aarch64__
#if defined(__aarch64__)
#include <stdlib.h>
#include <complex.h>
#include <tgmath.h>
#include <float.h>
typedef long double __float128;
using __complex128 = long double _Complex ;
using __float128 = long double;
using __complex128 = long double _Complex;
extern "C" {
__complex128 conjl(__complex128);
__float128 cimagl(__complex128);
Expand Down Expand Up @@ -50,7 +49,7 @@ namespace ql
namespace std
{

#ifdef __x86_64__
#if defined(__x86_64__) || defined(__i386__)
//! implementation of operator<< for qdouble
ostream& operator<<(std::ostream& out, ql::qdouble f);
#endif
Expand Down
5 changes: 3 additions & 2 deletions src/tools.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ namespace ql {
template<typename TOutput, typename TMass, typename TScale>
Tools<TOutput,TMass,TScale>::Tools():
_qlonshellcutoff(is_same<TScale,double>::value ? 1e-10 : 1e-20q),
#ifdef __x86_64__
#if defined(__x86_64__) || defined(__i386__)
_pi(is_same<TScale,double>::value ? M_PI : M_PIq),
#else
#endif
#if defined(__aarch64__)
_pi(is_same<TScale,double>::value ? M_PI : M_PIl),
#endif
_pi2 (_pi*_pi),
Expand Down
5 changes: 3 additions & 2 deletions src/types.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

namespace std
{
#ifdef __x86_64__
#if defined(__x86_64__) || defined(__i386__)
ostream& operator<<(std::ostream& out, ql::qdouble f)
{
char buf[200];
Expand All @@ -25,7 +25,8 @@ namespace std
out << "(" << crealq(f) << "," << cimagq(f) << ")";
return out;
}
#else
#endif
#if defined(__aarch64__)
ostream& operator<<(std::ostream& out, ql::qcomplex f)
{
out << "(" << creall(f) << "," << cimagl(f) << ")";
Expand Down

0 comments on commit 3163999

Please sign in to comment.