Skip to content

Tweak SIMDWrapper conversions / operations

Olli Lupton requested to merge olupton_simdwrapper_tweaks into master

Various small changes to ensure that SIMDWrapper types behave predictably, particularly in generic code:

  • Specialise std::numeric_limits<T> for SIMDWrapper types, patching up the previous behaviour where std::numeric_limits<[some SIMDWrapper type> would despatch to the default implementation, returning default-constructed objects that were uninitialised values...
    • In generic code that uses std::numeric_limits we should strongly encourage the use of static_assert( std::numeric_limits<T>::is_specialized )...
    • Unfortunately the specialisations are not quite conformant, because they are not constexpr and some methods are missing...this is difficult to fix given that the underlying intrinsic functions are not constexpr
  • Add compile-time tests that std::common_type_t operating on combinations of SIMDWrapper types yields the expected (i.e. matching plain C++ types) results.
    • These did not pass; make some conversions explicit so that they do (now float_v -> int_v is explicit, int_v -> float_v and mask_v -> int_v are not)
    • Remove implicit scalar::mask_v -> int conversion and add bool cast() const
  • Ensure that mask_v{} + mask_v{} consistently yields int_v, as bool{} + bool{} does
    • This is incompatible with the old approach of avx2::mask_v being an alias for avx2::float_v, so define an explicit mask_v (which also makes the API more consistent across backends...)
    • Also try to ensure that int_v{mask_true()} == int_v{1} and int_v{mask_false()} == int_v{0}
  • Improve some output operators.
  • Tidy up function signatures to more consistently use int_v/float_v/mask_v types instead of relying on implicit conversions.
  • Add a converting constructor for Vec3<U> -> Vec3<T>
  • Add a deduction guide for Vec3{T1, T2, T3} -> Vec3<std::common_type_t<T1, T2, T3>>
  • Make the gather_XXX signature for Vec3 consistent by removing a template argument and instead deducing the return type from the index vector type.

There was some mild fallout in other code that relied on implicit conversions that are no longer implicit; depends on Rec!2109 (merged).

cc: @ahennequ @nnolte

Edited by Olli Lupton

Merge request reports