Question on UnsafePointer and SIMD

I have some ints in memory, eg I have an UnsafePointer[UInt8] of arbitrary size. I would like to count the number of bits set to 1 with reduce_bit_count.

Can I get somehow a SIMD view inside my data, for example windows of 8 bytes at a time, and then use reduce_bit_count on that? I tried going through Span but that doesn’t immediately
work.

Or do I need to copy my ints inside a newly created SIMD object?

Or is there a better/different way to look at the problem?

Many thanks!

Marius

You want this with width > 1. I’d limit it to sys.info. simdwidthof and increment your loop by that. Alternatively, use vectorize to manage the loop and the required drain loop.

Awesome, many thanks @owenhilyard :person_bowing:

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.