When computing the expression, the result of uint16_t / int is an int. The resulting int then needs to be stored into vOutput as a uint16_t. As a result, std::copy is getting called in the inner loop inside load_aligned. The following code resolves this issue:
Ha indeed, I forgot not all architectures provide instruction for integer division. But then I'm a bit confused with "When computing the expression, the result of uint16_t / int is an int"; from what I understand it should compute uint16_t / double as a double, and then copy the result to uint16_t.
Anyway, I'm afraid we cannot get rid of the conversion here, but maybe we could explore a different implementation of the load_aligned / store_aligned functions in xsimd, based on batch_cast instead of copying buffers. Not sure how faster it would be, though.
Activity
JohanMabille commented on Jan 5, 2026
Does it fix the issue if you explicitely cast the scalar to uint16_t ?
spectre-ns commented on Jan 5, 2026
It eliminates the simd assignment which does get rid of the copy but shouldn't we be able to vectorize the whole operation right?
JohanMabille commented on Jan 6, 2026
Ha indeed, I forgot not all architectures provide instruction for integer division. But then I'm a bit confused with "When computing the expression, the result of uint16_t / int is an int"; from what I understand it should compute uint16_t / double as a double, and then copy the result to uint16_t.
Anyway, I'm afraid we cannot get rid of the conversion here, but maybe we could explore a different implementation of the load_aligned / store_aligned functions in xsimd, based on batch_cast instead of copying buffers. Not sure how faster it would be, though.