Skip to content

Commit 4377e08

Browse files
committed
[hist] Use correct SIMD size in the compiled TFormula code
Make sure that the `std::simd` class used arguments of the compiled TFormula has the same width as the one used in compile ROOT.
1 parent 4c8aa63 commit 4377e08

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

hist/hist/src/TFormula.cxx

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,21 @@ std::string doubleToString(double val)
4949
return ss.str();
5050
}
5151

52+
// To use the ROOT::Double_v type in the interpreter, we need to make sure that
53+
// we're using the SIMD type of the same size as in the compiled ROOT. If we
54+
// would use ROOT::Double_v directly, which aliases to native_simd, is might
55+
// choose different sized in compiled and interpreted contexts (especially if
56+
// compiling with march=native).
57+
std::string simdArgType()
58+
{
59+
#ifdef R__HAS_STD_SIMD
60+
auto n = ROOT::Double_v::size();
61+
return "std::experimental::resize_simd_t<" + std::to_string(n) + ", ROOT::Double_v>";
62+
#else
63+
return "ROOT::Double_v";
64+
#endif
65+
}
66+
5267
} // namespace
5368

5469
/** \class TFormula TFormula.h "inc/TFormula.h"
@@ -815,7 +830,7 @@ prepareMethod(bool HasParameters, bool HasVariables, const char* FuncName,
815830
TString prototypeArguments = "";
816831
if (HasVariables || HasParameters) {
817832
if (IsVectorized)
818-
prototypeArguments.Append("ROOT::Double_v const*");
833+
prototypeArguments.Append(simdArgType() + " const*");
819834
else
820835
prototypeArguments.Append("Double_t const*");
821836
}
@@ -2354,7 +2369,7 @@ void TFormula::ProcessFormula(TString &formula)
23542369
if (fVectorized)
23552370
inputFormulaVecFlag += " (vectorized)";
23562371

2357-
TString argType = fVectorized ? "ROOT::Double_v" : "Double_t";
2372+
TString argType = fVectorized ? simdArgType() : "Double_t";
23582373

23592374
// valid input formula - try to put into Cling (in case of no variables but only parameter we need to add the standard signature)
23602375
TString argumentsPrototype = TString::Format("%s%s%s", ( (hasVariables || hasParameters) ? (argType + " const *x").Data() : ""),

math/mathcore/inc/Math/Types.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,8 @@ namespace ROOT {
1313

1414
namespace Internal {
1515

16-
// We can't use SIMDNative here, because we need ABI compatible types between
17-
// the context of the interpreter and compiled code, for usage in the TFormula.
1816
template <typename T>
19-
using SIMDTag = std::experimental::simd_abi::compatible<T>;
17+
using SIMDTag = std::experimental::simd_abi::native<T>;
2018

2119
} // namespace Internal
2220

0 commit comments

Comments
 (0)