fast_float icon indicating copy to clipboard operation
fast_float copied to clipboard

Possible simplification of is_made_of_eight_digits_fast

Open Kristine1975 opened this issue 4 years ago • 2 comments

This function could be simplified a bit:

https://github.com/lemire/fast_float/blob/7eae925b51fd0f570ccd5c880c12e3e27a23b86f/include/fast_float/ascii_number.h#L27

replace its implementation with:

return ((val & 0xF0F0F0F0F0F0F0F0u) & (val + 0x0606060606060606u)) == 0x3030303030303030u;

Kristine1975 avatar Nov 12 '20 17:11 Kristine1975

To be reviewed and assessed. Thanks.

lemire avatar Nov 12 '20 18:11 lemire

From #28: return !((((val + 0x4646464646464646) | (val - 0x3030303030303030)) & 0x8080808080808080));

The ! and & operations should become a test instruction on x86. So it should be the same speed as @Kristine1975 suggestion. The term val - 0x3030303030303030 is needed immediately after the check ... so calculating it during the check may save one instruction down the road.

aqrit avatar Nov 12 '20 20:11 aqrit