Write a function to count the number of set bits in a 32-bit integer, and optimize it for performance.