sys/div: calculate magic numbers at compile time#9280
sys/div: calculate magic numbers at compile time#9280ZetaR60 wants to merge 12 commits intoRIOT-OS:masterfrom
Conversation
|
I have been tinkering with this a bit, and I cannot get it to come out exactly like what unittests expects. I was hoping that this wouldn't force me to implement floats, but there may be a loss in precision due to the general nature of the calculation method. |
|
Interesting improvement. Did you compare the computed inverses against the old hard coded magic numbers? |
|
Now tested and working properly via tests/unittests (tests-div). Comparison between the magic numbers (the new ones are a single bitshift from the old): Test results: |
|
Added |
|
@ZetaR60 perhaps we can combine the frac and div modules and get the performance of div and the runtime configurable constants of frac? |
|
@gebart How are you considering doing this combination? Is div still clearly better than frac when frac is used with constant parameters? I rewrote div primarily because I am working on adding multiple timer support (including RTT/RTC) to xtimer, and it is difficult to convert clocks when things are not all hard-coded. This is still very WIP, but I can create a PR early for it so that it is easier to discuss what the requirements are for clock conversion moving forward. |
|
@gebart What do you think about the best way to interface something like #9308 with div or frac? When writing a function to convert ticks to us the most straightforward way is to have |
|
@ZetaR60 for runtime configurable frequencies I would just add a static frac_t inside the module, or a frac_t member in the params struct. |
|
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you want me to ignore this issue, please mark it with the "State: don't stale" label. Thank you for your contributions. |
This is a rewrite of sys/div to provide much simpler division by calculating the required magic numbers at compile time, rather than hard-coding them.
tests/unittests/tests-div is partially working, with a few rounding errors that I need to fix: