Yet another simplification of Dragonbox - #2984
Conversation
| if (r < deltai) { | ||
| // Exclude the right endpoint if necessary. | ||
| if (r == 0 && z_mul.is_integer && !include_right_endpoint) { | ||
| if (r == 0 && (z_mul.is_integer & !include_right_endpoint)) { |
There was a problem hiding this comment.
Why switch to bitwise AND? Better codegen?
There was a problem hiding this comment.
Yes. With logical AND, it generates three test instructions and three conditional branches. With bitwise AND, it generates two test instructions and two conditional branches. I thought compilers are aware of how to optimize this when all the things are just booleans variables (thus no short-circuit is really involved), but apparently they don't bother doing so. I am not sure why...
There was a problem hiding this comment.
I guess, compilers are not sure if all boolean variables involved are really just 0 or 1. Like, if one is 2 and another is 1, they are both true so && should give true, but & will give 0. It is wrong from the first place to use bool for things with more than two states, but maybe the current standard allows bool variables to hold nonsensical values without UB.
| static const int divisibility_check_by_5_threshold = 39; | ||
| static const int case_fc_pm_half_lower_threshold = -1; |
There was a problem hiding this comment.
Should these be removed from float_info<double> as well?
There was a problem hiding this comment.
Ha. Another careless mistake. Sorry about that, it's fixed now.
|
Merged, thanks! |
jk-jeon/dragonbox#31 pointed out that I was doing something silly. I corrected that, which simplifies the source code a little bit (and the generated assembly as well), while the flow of the logic is not affected. Also, I replaced several logical operators into bitwise operators which seems to improve the code generation a little bit.