Add count_scalar() function.

Change-Id: I63f09dd0479d0a6b016f5f857dd39dcbda56c7f9