Skip to content

Commit 1578cff

Browse files
committed
[Math] Don't use scalar fallback for types like ROOT::Double_v
The fallback to the vector types being defined as scalars if `std::simd` is not available is confusing, and doesn't help anyway because the code for scalar types and `std::simd` usage has to look different.
1 parent 4377e08 commit 1578cff

File tree

2 files changed

+13
-25
lines changed

2 files changed

+13
-25
lines changed

hist/hist/inc/TF1.h

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -717,34 +717,33 @@ namespace ROOT {
717717
template<class Func>
718718
void TF1Builder<Func>::Build(TF1 *f, Func func)
719719
{
720+
#ifdef R__HAS_STD_SIMD
720721
// check if vector interface is supported by Func
721722
if constexpr(std::is_invocable_r_v<Double_v, Func, Double_v*, double *>) {
722-
// if ROOT was not built with std::experimental::simd support, Double_v is just an alias for the scalar
723-
// double
724-
f->fType = std::is_same<Double_v, double>::value ? TF1::EFType::kTemplScalar : TF1::EFType::kTemplVec;
723+
f->fType = TF1::EFType::kTemplVec;
725724
f->fFunctor.reset(new TF1::TF1FunctorPointerImpl(ROOT::Math::ParamFunctorTempl<Double_v>(func)));
726-
} else {
727-
f->fType = TF1::EFType::kTemplScalar;
728-
f->fFunctor.reset(new TF1::TF1FunctorPointerImpl(ROOT::Math::ParamFunctorTempl<double>(func)));
725+
f->fParams = std::make_unique<TF1Parameters>(f->fNpar);
729726
}
727+
#endif
730728

729+
f->fType = TF1::EFType::kTemplScalar;
730+
f->fFunctor.reset(new TF1::TF1FunctorPointerImpl(ROOT::Math::ParamFunctorTempl<double>(func)));
731731
f->fParams = std::make_unique<TF1Parameters>(f->fNpar);
732732
}
733733

734734
template<class Func>
735735
void TF1Builder<Func *>::Build(TF1 *f, Func *func)
736736
{
737+
#ifdef R__HAS_STD_SIMD
737738
// check if vector interface is supported by Func
738739
if constexpr(std::is_invocable_r_v<Double_v, Func, Double_v*, double *>) {
739-
// if ROOT was not built with std::experimental::simd support, Double_v is just an alias for the scalar
740-
// double
741-
f->fType = std::is_same<Double_v, double>::value ? TF1::EFType::kTemplScalar : TF1::EFType::kTemplVec;
740+
f->fType = TF1::EFType::kTemplVec;
742741
f->fFunctor.reset(new TF1::TF1FunctorPointerImpl(ROOT::Math::ParamFunctorTempl<Double_v>(func)));
743-
} else {
744-
f->fType = TF1::EFType::kTemplScalar;
745-
f->fFunctor.reset(new TF1::TF1FunctorPointerImpl(ROOT::Math::ParamFunctorTempl<double>(func)));
742+
f->fParams = std::make_unique<TF1Parameters>(f->fNpar);
746743
}
747-
744+
#endif
745+
f->fType = TF1::EFType::kTemplScalar;
746+
f->fFunctor.reset(new TF1::TF1FunctorPointerImpl(ROOT::Math::ParamFunctorTempl<double>(func)));
748747
f->fParams = std::make_unique<TF1Parameters>(f->fNpar);
749748
}
750749

math/mathcore/inc/Math/Types.h

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ using SIMDTag = std::experimental::simd_abi::native<T>;
1818

1919
} // namespace Internal
2020

21+
// FIXME: Should we introduce Int32_t and UInt32_t in RtypesCore.h?
2122
using Float_v = std::experimental::simd<Float_t, Internal::SIMDTag<Float_t>>;
2223
using Double_v = std::experimental::simd<Double_t, Internal::SIMDTag<Double_t>>;
2324
using Int_v = std::experimental::simd<Int_t, Internal::SIMDTag<Int_t>>;
@@ -27,18 +28,6 @@ using UInt32_v = std::experimental::simd<UInt_t, Internal::SIMDTag<UInt_t>>;
2728

2829
} // namespace ROOT
2930

30-
#else // R__HAS_STD_SIMD
31-
32-
// We do not have explicit vectorisation support enabled. Fall back to regular ROOT types.
33-
34-
namespace ROOT {
35-
using Float_v = Float_t;
36-
using Double_v = Double_t;
37-
using Int_v = Int_t;
38-
using Int32_v = Int_t; // FIXME: Should we introduce Int32_t in RtypesCore.h?
39-
using UInt_v = UInt_t;
40-
using UInt32_v = UInt_t; // FIXME: Should we introduce UInt32_t in RtypesCore.h?
41-
}
4231
#endif
4332

4433
#endif // ROOT_Math_VecTypes

0 commit comments

Comments
 (0)