CPUMeter: Improve spacing between sub-meter algorithm#1655
CPUMeter: Improve spacing between sub-meter algorithm#1655Explorer09 wants to merge 2 commits intohtop-dev:mainfrom
Conversation
CPUMeter.c
Outdated
| v = ((v * 0x00210842U) & 0x02082082U) * (unsigned int)(i / nrows); | ||
| v = (uint32_t)(((v + 0x02108420U) & 0x7DE71840U) * 0x00210842ULL) >> 27; |
There was a problem hiding this comment.
Please explain those magic numbers …
It's a bit difficult to explain in code. I wonder if you or other people have ideas to make the code more readable (maybe wrap it into a function or something - I don't know how to name such function, though). Anyway. Here're my explanations:
It technically requires a loop. So I use bit manipulation tricks to simplify this, utilising N is a power of two within the narrowed problem scope, and came up with the magic numbers for multiplication and mask values.
|
1fc267e to
a537577
Compare
292cd91 to
6b8ca65
Compare
6b8ca65 to
4ddac3e
Compare
Make the 'x' offset calculation in CPUMeterCommonDraw() a sub-function. There should be no changes to the compiled code. Signed-off-by: Kang-Che Sung <explorer09@gmail.com>
The new algorithm will make the meter bars aligned when groups of CPU meters with 2, 4 and 8 sub-columns are placed together in one larger column. It utilizes the fact that the number of sub-columns of CPU meters are in power of 2 only, and calculates spacing with bit tricks. Signed-off-by: Kang-Che Sung <explorer09@gmail.com>
4ddac3e to
3659c90
Compare
Fixes #1654.
The formula is derived by myself.
Interestingly, I asked both ChatGPT and Google Gemini (AI) on how to make a formula based on a table of given values, they either gave me a wrong result or simply fail to make one. (I don't trust these AIs in general, by the way.)
(https://chatgpt.com/share/67e6fb4a-da80-8004-a993-11cc19666fad)
(https://g.co/gemini/share/356fa79d2f5a)