Closed sirinath closed 3 years ago
Some of the compile time code perhaps can be optimised further. For this implementation there is not runtime impact but when porting to other languages it might be helpful when there is no constexpr
.
Checking here is not needed. There is no instance where shift_amount of 0 is passed. Besides the result is the same.
The function floor_shift
is only called inside a constexpr
context, so as you have mentioned it does not impact the runtime performance. And I doubt it will really have a measurable impact on the compiler-time performance as well. There are too many similar floor_log
type functions and it was not fun to manage all of them independently, thus I tried to merge them with some compile-time abstraction. And I think the most important is the correctness and robustness when it comes to compile-time programming. I agree that it is unlikely that the case shift_amount == 0
will be ever useful, but I believe there is little to loose here by being a bit more careful.
when porting to other languages it might be helpful when there is no
constexpr
.
Could you elaborate on this?
I am trying to port this to Java. All the I am converting all the constexpr
to static
which in this case has a runtime penalty.
I think in that case you should write it differently.
Yes.
But also some of the code can be written with translation in mind to help porters to other languages.
That's fair enough. I'll keep that in mind from now on.
Checking here is not needed. There is no instance where
shift_amount
of0
is passed. Besides the result is the same.