Improved constant-time cmp func