Improve the implementation of countOnes function to use only 12 operations.

Change-Id: I01b62606a0c87b2937572f8cb7beafc956867353