Um, no, I mean that pytorch processes 8 items at once, that’s potential reason why you can’t reach its speed. It may be possible to rewrite your loop with AVX intinsics, but it is not trivial; it may also auto-vectorize if you replace branches with b?x:y operations, and add __restrict to pointers, I’m just not sure if signbit is supported.
PS Oh, I misundserstood - if you’ll use “slow” pytorch for comparision, then yes, I don’t rule out that your routine will be faster. It screws the branch predictor though.