Skip to content

Commit c6da02c

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 02ac741 commit c6da02c

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

hist/hist/src/TFormula.cxx

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,18 @@ 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+
auto n = ROOT::Double_v::size();
60+
61+
return "std::experimental::resize_simd_t<" + std::to_string(n) + ", ROOT::Double_v>";
62+
}
63+
5264
} // namespace
5365

5466
/** \class TFormula TFormula.h "inc/TFormula.h"
@@ -815,7 +827,7 @@ prepareMethod(bool HasParameters, bool HasVariables, const char* FuncName,
815827
TString prototypeArguments = "";
816828
if (HasVariables || HasParameters) {
817829
if (IsVectorized)
818-
prototypeArguments.Append("ROOT::Double_v const*");
830+
prototypeArguments.Append(simdArgType() + " const*");
819831
else
820832
prototypeArguments.Append("Double_t const*");
821833
}
@@ -2354,7 +2366,7 @@ void TFormula::ProcessFormula(TString &formula)
23542366
if (fVectorized)
23552367
inputFormulaVecFlag += " (vectorized)";
23562368

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

23592371
// valid input formula - try to put into Cling (in case of no variables but only parameter we need to add the standard signature)
23602372
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)