forked from OSchip/llvm-project
[AMDGPU] Use math constants defined in MathExtras (NFC)
Use the the new math constants in `MathExtras.h`. Differential revision: https://reviews.llvm.org/D68285 llvm-svn: 374208
This commit is contained in:
parent
e60415a0db
commit
c57a9dc487
|
@ -12,10 +12,6 @@
|
|||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#define AMDGPU_LOG2E_F 1.44269504088896340735992468100189214f
|
||||
#define AMDGPU_LN2_F 0.693147180559945309417232121458176568f
|
||||
#define AMDGPU_LN10_F 2.30258509299404568401799145468436421f
|
||||
|
||||
#include "AMDGPUISelLowering.h"
|
||||
#include "AMDGPU.h"
|
||||
#include "AMDGPUCallLowering.h"
|
||||
|
@ -37,6 +33,7 @@
|
|||
#include "llvm/IR/DataLayout.h"
|
||||
#include "llvm/IR/DiagnosticInfo.h"
|
||||
#include "llvm/Support/KnownBits.h"
|
||||
#include "llvm/Support/MathExtras.h"
|
||||
using namespace llvm;
|
||||
|
||||
#include "AMDGPUGenCallingConv.inc"
|
||||
|
@ -1135,9 +1132,9 @@ SDValue AMDGPUTargetLowering::LowerOperation(SDValue Op,
|
|||
case ISD::FROUND: return LowerFROUND(Op, DAG);
|
||||
case ISD::FFLOOR: return LowerFFLOOR(Op, DAG);
|
||||
case ISD::FLOG:
|
||||
return LowerFLOG(Op, DAG, 1 / AMDGPU_LOG2E_F);
|
||||
return LowerFLOG(Op, DAG, 1.0F / numbers::log2ef);
|
||||
case ISD::FLOG10:
|
||||
return LowerFLOG(Op, DAG, AMDGPU_LN2_F / AMDGPU_LN10_F);
|
||||
return LowerFLOG(Op, DAG, numbers::ln2f / numbers::ln10f);
|
||||
case ISD::FEXP:
|
||||
return lowerFEXP(Op, DAG);
|
||||
case ISD::SINT_TO_FP: return LowerSINT_TO_FP(Op, DAG);
|
||||
|
@ -2285,30 +2282,13 @@ SDValue AMDGPUTargetLowering::LowerFLOG(SDValue Op, SelectionDAG &DAG,
|
|||
return DAG.getNode(ISD::FMUL, SL, VT, Log2Operand, Log2BaseInvertedOperand);
|
||||
}
|
||||
|
||||
// Return M_LOG2E of appropriate type
|
||||
static SDValue getLog2EVal(SelectionDAG &DAG, const SDLoc &SL, EVT VT) {
|
||||
switch (VT.getScalarType().getSimpleVT().SimpleTy) {
|
||||
case MVT::f32:
|
||||
return DAG.getConstantFP(1.44269504088896340735992468100189214f, SL, VT);
|
||||
case MVT::f16:
|
||||
return DAG.getConstantFP(
|
||||
APFloat(APFloat::IEEEhalf(), "1.44269504088896340735992468100189214"),
|
||||
SL, VT);
|
||||
case MVT::f64:
|
||||
return DAG.getConstantFP(
|
||||
APFloat(APFloat::IEEEdouble(), "0x1.71547652b82fep+0"), SL, VT);
|
||||
default:
|
||||
llvm_unreachable("unsupported fp type");
|
||||
}
|
||||
}
|
||||
|
||||
// exp2(M_LOG2E_F * f);
|
||||
SDValue AMDGPUTargetLowering::lowerFEXP(SDValue Op, SelectionDAG &DAG) const {
|
||||
EVT VT = Op.getValueType();
|
||||
SDLoc SL(Op);
|
||||
SDValue Src = Op.getOperand(0);
|
||||
|
||||
const SDValue K = getLog2EVal(DAG, SL, VT);
|
||||
const SDValue K = DAG.getConstantFP(numbers::log2e, SL, VT);
|
||||
SDValue Mul = DAG.getNode(ISD::FMUL, SL, VT, Src, K, Op->getFlags());
|
||||
return DAG.getNode(ISD::FEXP2, SL, VT, Mul, Op->getFlags());
|
||||
}
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
#include "llvm/IR/Module.h"
|
||||
#include "llvm/IR/ValueSymbolTable.h"
|
||||
#include "llvm/Support/Debug.h"
|
||||
#include "llvm/Support/MathExtras.h"
|
||||
#include "llvm/Support/raw_ostream.h"
|
||||
#include "llvm/Target/TargetMachine.h"
|
||||
#include "llvm/Target/TargetOptions.h"
|
||||
|
@ -48,18 +49,10 @@ static cl::list<std::string> UseNative("amdgpu-use-native",
|
|||
cl::CommaSeparated, cl::ValueOptional,
|
||||
cl::Hidden);
|
||||
|
||||
#define MATH_PI 3.14159265358979323846264338327950288419716939937511
|
||||
#define MATH_E 2.71828182845904523536028747135266249775724709369996
|
||||
#define MATH_SQRT2 1.41421356237309504880168872420969807856967187537695
|
||||
|
||||
#define MATH_LOG2E 1.4426950408889634073599246810018921374266459541529859
|
||||
#define MATH_LOG10E 0.4342944819032518276511289189166050822943970058036665
|
||||
// Value of log2(10)
|
||||
#define MATH_LOG2_10 3.3219280948873623478703194294893901758648313930245806
|
||||
// Value of 1 / log2(10)
|
||||
#define MATH_RLOG2_10 0.3010299956639811952137388947244930267681898814621085
|
||||
// Value of 1 / M_LOG2E_F = 1 / log2(e)
|
||||
#define MATH_RLOG2_E 0.6931471805599453094172321214581765680755001343602552
|
||||
#define MATH_PI numbers::pi
|
||||
#define MATH_E numbers::e
|
||||
#define MATH_SQRT2 numbers::sqrt2
|
||||
#define MATH_SQRT1_2 numbers::inv_sqrt2
|
||||
|
||||
namespace llvm {
|
||||
|
||||
|
@ -254,8 +247,8 @@ struct TableEntry {
|
|||
|
||||
/* a list of {result, input} */
|
||||
static const TableEntry tbl_acos[] = {
|
||||
{MATH_PI/2.0, 0.0},
|
||||
{MATH_PI/2.0, -0.0},
|
||||
{MATH_PI / 2.0, 0.0},
|
||||
{MATH_PI / 2.0, -0.0},
|
||||
{0.0, 1.0},
|
||||
{MATH_PI, -1.0}
|
||||
};
|
||||
|
@ -271,8 +264,8 @@ static const TableEntry tbl_acospi[] = {
|
|||
static const TableEntry tbl_asin[] = {
|
||||
{0.0, 0.0},
|
||||
{-0.0, -0.0},
|
||||
{MATH_PI/2.0, 1.0},
|
||||
{-MATH_PI/2.0, -1.0}
|
||||
{MATH_PI / 2.0, 1.0},
|
||||
{-MATH_PI / 2.0, -1.0}
|
||||
};
|
||||
static const TableEntry tbl_asinh[] = {
|
||||
{0.0, 0.0},
|
||||
|
@ -287,8 +280,8 @@ static const TableEntry tbl_asinpi[] = {
|
|||
static const TableEntry tbl_atan[] = {
|
||||
{0.0, 0.0},
|
||||
{-0.0, -0.0},
|
||||
{MATH_PI/4.0, 1.0},
|
||||
{-MATH_PI/4.0, -1.0}
|
||||
{MATH_PI / 4.0, 1.0},
|
||||
{-MATH_PI / 4.0, -1.0}
|
||||
};
|
||||
static const TableEntry tbl_atanh[] = {
|
||||
{0.0, 0.0},
|
||||
|
@ -359,7 +352,7 @@ static const TableEntry tbl_log10[] = {
|
|||
};
|
||||
static const TableEntry tbl_rsqrt[] = {
|
||||
{1.0, 1.0},
|
||||
{1.0/MATH_SQRT2, 2.0}
|
||||
{MATH_SQRT1_2, 2.0}
|
||||
};
|
||||
static const TableEntry tbl_sin[] = {
|
||||
{0.0, 0.0},
|
||||
|
@ -868,7 +861,7 @@ static double log2(double V) {
|
|||
#if _XOPEN_SOURCE >= 600 || defined(_ISOC99_SOURCE) || _POSIX_C_SOURCE >= 200112L
|
||||
return ::log2(V);
|
||||
#else
|
||||
return log(V) / 0.693147180559945309417;
|
||||
return log(V) / numbers::ln2;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,6 +41,7 @@
|
|||
#include "llvm/Support/Compiler.h"
|
||||
#include "llvm/Support/ErrorHandling.h"
|
||||
#include "llvm/Support/MachineValueType.h"
|
||||
#include "llvm/Support/MathExtras.h"
|
||||
#include <cassert>
|
||||
#include <cstdint>
|
||||
#include <iterator>
|
||||
|
@ -782,7 +783,7 @@ SDValue R600TargetLowering::LowerTrig(SDValue Op, SelectionDAG &DAG) const {
|
|||
return TrigVal;
|
||||
// On R600 hw, COS/SIN input must be between -Pi and Pi.
|
||||
return DAG.getNode(ISD::FMUL, DL, VT, TrigVal,
|
||||
DAG.getConstantFP(3.14159265359, DL, MVT::f32));
|
||||
DAG.getConstantFP(numbers::pif, DL, MVT::f32));
|
||||
}
|
||||
|
||||
SDValue R600TargetLowering::LowerSHLParts(SDValue Op, SelectionDAG &DAG) const {
|
||||
|
|
Loading…
Reference in New Issue