VcDevel / Vc

SIMD Vector Classes for C++
BSD 3-Clause "New" or "Revised" License
1.45k stars 152 forks source link

cannot advance `Vc::uint_v` by `Vc::uint_v::Size` #228

Closed milianw closed 5 years ago

milianw commented 5 years ago
Vc version / revision Operating System Compiler & Version Compiler Flags Assembler & Version CPU
1.4 / b725a903 Linux g++ 8.2.1 Vc defaults GNU as 2.31.1 Intel(R) Core(TM) i7-4770 CPU @ 3.40GHz

Testcase

Based on the mandelbrot example: https://godbolt.org/z/0K1zvC

I have just realized that the mandelbrot is actually using a custom uint_v and uint_m, which isn't Vc::uint_v or Vc::uint_m, but rather a Vc::SimdArray<uint, Vc::float_v::Size>. But why can't we get the same nice API for Vc::uint_v?

Actual Results

<source>:10:11: error: no match for 'operator+=' (operand types are 'Vc_1::uint_v' {aka 'Vc_1::Vector<unsigned int, Vc_1::VectorAbi::Avx>'} and 'const size_t' {aka 'const long unsigned int'})

https://raw.githubusercontent.com/VcDevel/Vc/1.4/godbolt/Vc:21109:1: note: candidate: 'template<class T, class Abi, class U, class R> Vc_1::enable_if<((Vc_1::Detail::is_a_type<decltype ((declval<typename R::value_type>() + declval<typename R::value_type>()))>::value && std::is_convertible<Vc_1::Vector<T, Abi>, R>::value) && std::is_convertible<U, R>::value), Vc_1::Vector<T, Abi>&> Vc_1::operator+=(Vc_1::Vector<T, Abi>&, U&&)'

https://raw.githubusercontent.com/VcDevel/Vc/1.4/godbolt/Vc:1073:43: note: in expansion of macro 'Vc_GENERIC_OPERATOR'

https://raw.githubusercontent.com/VcDevel/Vc/1.4/godbolt/Vc:1107:1: note: in expansion of macro 'Vc_APPLY_IMPL_1_'

https://raw.githubusercontent.com/VcDevel/Vc/1.4/godbolt/Vc:1112:33: note: in expansion of macro 'Vc_LIST_ARITHMETICS'

https://raw.githubusercontent.com/VcDevel/Vc/1.4/godbolt/Vc:1121:35: note: in expansion of macro 'Vc_APPLY_0'

https://raw.githubusercontent.com/VcDevel/Vc/1.4/godbolt/Vc:21169:1: note: in expansion of macro 'Vc_ALL_ARITHMETICS'

https://raw.githubusercontent.com/VcDevel/Vc/1.4/godbolt/Vc:21109:1: note:   template argument deduction/substitution failed:

https://raw.githubusercontent.com/VcDevel/Vc/1.4/godbolt/Vc:1073:43: note: in expansion of macro 'Vc_GENERIC_OPERATOR'

https://raw.githubusercontent.com/VcDevel/Vc/1.4/godbolt/Vc:1107:1: note: in expansion of macro 'Vc_APPLY_IMPL_1_'

https://raw.githubusercontent.com/VcDevel/Vc/1.4/godbolt/Vc:1112:33: note: in expansion of macro 'Vc_LIST_ARITHMETICS'

https://raw.githubusercontent.com/VcDevel/Vc/1.4/godbolt/Vc:1121:35: note: in expansion of macro 'Vc_APPLY_0'

https://raw.githubusercontent.com/VcDevel/Vc/1.4/godbolt/Vc:21169:1: note: in expansion of macro 'Vc_ALL_ARITHMETICS'

Expected Results

should compile fine without issues. For now, I workaround this via https://godbolt.org/z/pEU_WP. but I'll now also look at porting to SimdArray for the indices.

mattkretz commented 5 years ago

This is unfortunate. You can work around the issue by using an int instead of size_t: https://godbolt.org/z/QHC5p9. I believe the return type of Vector::size() shouldn't be size_t (which it is for consistency with all the other size() functions in the STL) but rather just int. (Please comment on https://github.com/mattkretz/wg21-papers/issues/72 if you want to support this change. I'll include it in the feedback to the C++ committee then.)

For now there's nothing I can/want to change. Rather I'd have to change SimdArray to make it ill-formed as well.