strcmp optimization#6
Conversation
| sub a0, a4, a5 | ||
| ret | ||
| rev8 a2, a2 | ||
| rev8 a3, a3 |
There was a problem hiding this comment.
Had a quick question for this change:
- Do I retain this change? Because it adds up an overhead of 2 instructions every time .Lmismatch is executed compared to the already existing code, but it is a significant size reduction.
- If I should retain the change, should I reverse byte order for little endian or big endian?
There was a problem hiding this comment.
i like the change, but overall, it does not improve speed or code size. So it is better to keep both versions.
| or t0, t0, t1 | ||
|
|
||
| bne t0, t2, .Lnull\i | ||
| orc.b a4, a2 |
There was a problem hiding this comment.
the file still needs to compile for targets without Zbb. Check out e.g. in Erics patch how you can guard this.
There was a problem hiding this comment.
Oh yes, sorry I missed that...
| .macro check_one_word i n | ||
| REG_L a2, \i*SZREG(a0) | ||
|
|
||
| and t0, a2, a5 |
There was a problem hiding this comment.
if this was a C function, you could simply call __libc_detect_null(). Eric has already optimized this for Zbb in his patch.
I do not see anything in this function that would not work in C. Maybe this is a candidate to move from asm to C
|
I could imagine that you will find a faster algorithm for .Lmismatch using bitmanip. |
I realized that you could even use sub instead of xnor, and then you are back to finding a NULL byte |
|
@puranikvinit If you check out the |
I tried this, works perfectly right with the |
There is no need to change the algorithm for the non Zbb version. |
Wouldn't just having the same algorithm for both versions ease up things for maintainability and algorithm efficiency in general? Do you want me to try and get improvements comparing both the algorithms for the non Zbb version? |
i cannot judge right now how different it would be. But it clearly does not make sense to count leading zeros if you do not have an instruction for that, so you will have to have both versions if you want the bitmanip acceleration |
|
Here are some metrics I observed for the test cases provided in the testsuite for TEST - 1: Cycle count with TEST - 2: Cycle count with TEST - 3: Cycle count with TEST - 4: Cycle count with TEST - 5 -> Random data filled in Cycle count with |
|
Code Size comparison: |
52adca2 to
a50ed31
Compare
…ets with Zb* extension support
… with Zb* extension support
Zbbextension:orc.binstruction for the Hacker's Delight algorithm used to check for the presence of a null byte in a word.rev8instruction for reversing the byte order in case of endianness being little endian.testsuite/newlib.string/strcmp-1.cwas compiled and run successfully on spike withpk, indicating no issues with the functionality.Size of the size-optimized version could not be reduced, as it was pretty simple.
Size of perf-optimized version reduced from 278b to 174b.
I am currently working on getting an approximate count on the number of retired instructions, but I believe it must be lesser at the end for almost all average cases due to the reduction in the number of instructions itself.