swd: Improve parity calculation and move it to types.h