-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
sys/fmt: optimize scn_u32_hex() #19894
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR has an extra call to strnlen, does not check for out of hex range chars like c > 'f' or control char, fixing that will likely make this less efficient then our current impl.
check godbolt
godlblot cortex m0+ including a version 3 version 3 might be an improved version of this but I am not sure it covers all issues of this PR scn_u32_hex("9:3k",4) == 9 No it does not cortex m0+ cortex m4 |
one might want to look at #19027 |
As I stated in PR #19027 (comment), the unittest for the fmt module are lacking. Your changes break the API promised in |
@Teufelchen1 : You probably already got something in mind would you want to make that a PR? |
Hey hey, the new test just got merged. It will fail with the current implementation in this PR. |
0d4160e
to
b0b8167
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
uses more stack
How? |
seem like it needs an intermediate for the case-conversion |
https://godbolt.org/z/dz3c6d1oh for your experiments it has the old experiments (frome the previos comment) on top |
ah and the test ist still incomplete |
https://godbolt.org/z/KTYWf4v66 execute on x86 godlbolt reveals this PR will return i am not sure how it does that now i know : to ? are right behind 0-9 so they are alternative symbols for counting to f and the| 32 doesn't take a hit on them 0123456789:;<=>? |
b0b8167
to
1b6ab53
Compare
Yea I guess it's mostly obfuscation at this point… |
1b6ab53
to
e434332
Compare
e434332
to
53f6b9a
Compare
It's now even worse (more stack and more assembly, and the code is barely readable) https://godbolt.org/z/zMWGKWefT Do you really want to try to optimize this function? (I might be biased because i wrote the current implementation #19027 the pr also has a link to godbolt where you can find versions of this functions that are smaller on stack and in code but are also less safe ( one of them is probably also what this pr once was) ) If you do please provide some kind of proof for: "this is better" I like godbolt |
I am with @kfessel here. Closing this PR seems to be the best way to handle this? Even if we find an implementation that produces perfect out put for a given compiler: There are so many variables. So far we only looked at arm but RIOT supports more ISAs. How do their compilations compare? What is about run-time performance? etc. etc. |
In consent with benpicco: Closed, not worth the extra time. |
Contribution description
We can save a branch by always converting to lowercase first.
Testing procedure
tests-fmt
intests/unittests
covers this.Issues/PRs references