in reply to Re: Challenge: CPU-optimized byte-wise or-equals (for a meter of beer)
in thread Challenge: CPU-optimized byte-wise or-equals (for a meter of beer)

Since there are not so many bytes to substitute it pays off to search for these rare cases instead of working "blindly" with bit ops.

Creating $mask takes one pass through the string, and then there are three binary bit ops on the string(s). That makes four passes, while only 1/256 of the bytes being zero bytes.

Thus a solution that actually looks for zeros (one pass) may have an overhead of 3*256 compared to the bit operations to be still as fast. (Rough estimation only)

  • Comment on Re^2: Challenge: CPU-optimized byte-wise or-equals (for a meter of beer)