blob: 92c2ccbfcbd01c76f880d5c0f8d0ee10e2209282 [file] [log] [blame]
// Copyright 2010 and onwards Google Inc.
// Author: Martin Thuresson
//
// Expose fast k8 implementation of math functions with the prefix
// "acml_". Currently acml_log(), acml_exp(), and acmp_pow() have
// shown to have significantly better performance over glibc libm
// and atleast as good precision.
// https://wiki.corp.google.com/twiki/bin/view/Main/CompilerMathOptimization
//
// When build with --cpu=piii, acml_* will call the pure libm functions,
// avoiding the need to special case the calls.
//
// TODO(martint): Update glibc to match the libacml performance.
#ifndef THIRD_PARTY__OPEN64_LIBACML_MV__LIBACML_H_
#define THIRD_PARTY__OPEN64_LIBACML_MV__LIBACML_H_
#ifndef USE_LIBACML_IMPLEMENTATION
#define USE_LIBACML_IMPLEMENTATION defined(__x86_64__)
#endif
#if USE_LIBACML_IMPLEMENTATION
#include "third_party/open64_libacml_mv/inc/fn_macros.h"
#else
#include <math.h>
#endif
extern "C" {
#if USE_LIBACML_IMPLEMENTATION
// The k8 implementation of the math functions.
#define acml_exp_k8 FN_PROTOTYPE(exp)
#define acml_expf_k8 FN_PROTOTYPE(expf)
#define acml_log_k8 FN_PROTOTYPE(log)
#define acml_pow_k8 FN_PROTOTYPE(pow)
double acml_exp_k8(double x);
float acml_expf_k8(float x);
double acml_log_k8(double x);
double acml_pow_k8(double x, double y);
#endif
static inline double acml_exp(double x) {
#if USE_LIBACML_IMPLEMENTATION
return acml_exp_k8(x);
#else
return exp(x);
#endif
}
static inline float acml_expf(float x) {
#if USE_LIBACML_IMPLEMENTATION
return acml_expf_k8(x);
#else
return expf(x);
#endif
}
static inline double acml_log(double x) {
#if USE_LIBACML_IMPLEMENTATION
return acml_log_k8(x);
#else
return log(x);
#endif
}
static inline double acml_pow(double x, double y) {
#if USE_LIBACML_IMPLEMENTATION
return acml_pow_k8(x, y);
#else
return pow(x, y);
#endif
}
}
#endif // THIRD_PARTY__OPEN64_LIBACML_MV__LIBACML_H_