I'm writing performance-intensive Fortran code, which has at its core a matrix-free matrix multiplication subroutine mfmult(x,y), which takes an input vector x, and returns an output vector y such that if i = i_{n-1}i_{n-2}...i_2i_1i_0 is an n-bit binary number (possibly with leading zeros), then
y(i) = sum{x(j) : j is any 1-bit negation of i}
i.e.
y(000) = x(001)+x(010)+x(100)
y(1101) = x(0101)+x(1001)+x(1111) + x(1100) etc.
What would be an efficient way to implement this? A related question is: does there exist a fast intrinsic in Fortran for single-bit negation? I've had a look at the intrinsics and https://rosettacode.org/wiki/Bitwise_operations#Fortran, but there is no single-bit negation operation, and I worry any manual coding/branching statements will make things too slow.