Skip to content

Improve shortstring comparisons, assignments, and searches (generic & i386).

Rika requested to merge runewalsh/source:ss into main
  • Improve generic.inc:fpc_shortstr_compare, i386.inc:fpc_shortstr_to_shortstr, and i386.inc:fpc_shortstr_compare. Particularly the latter is very slow presently, for a known reason; on my computer, 2× to 6× slower than new generic version — even if the first byte differs, and farther mismatches (including comparing the string with itself) are even worse!

  • Do #40088 (closed) for shortstrings.

  • Add i386.inc:fpc_shortstr_compare_equal, just for an extra bit of fanciness.

Warning: I did the assembly by guess as I don’t actually know how to call functions, and I’m especially uneasy about these PIC things and the way mcount works, so please verify. >_>

Benchmark: ShortstringBenchmark.pas.

My results.

                                           Existing       Generic          Asm
fpc_shortstr_to_shortstr(len = 1~6):      10 ns/call    5.5 ns/call    2.7 ns/call
fpc_shortstr_compare(diff. #1/3):         15 ns/call    4.3 ns/call    5.3 ns/call
fpc_shortstr_compare(diff. #3/3):         16 ns/call    5.6 ns/call    6.2 ns/call
                                                                       
fpc_shortstr_to_shortstr(len = 3~18):     16 ns/call    3.5 ns/call    2.8 ns/call
fpc_shortstr_compare(diff. #1/10):        15 ns/call    8.3 ns/call    5.4 ns/call
fpc_shortstr_compare(diff. #10/10):       41 ns/call    8.3 ns/call    5.2 ns/call
                                                                       
fpc_shortstr_to_shortstr(len = 5~60):     18 ns/call    4.4 ns/call    3.6 ns/call
fpc_shortstr_compare(diff. #1/32):        16 ns/call    4.8 ns/call    5.4 ns/call
fpc_shortstr_compare(diff. #32/32):       42 ns/call    5.1 ns/call    6.0 ns/call
                                                                       
fpc_shortstr_to_shortstr(len = 30~255):   20 ns/call    7.7 ns/call    6.5 ns/call
fpc_shortstr_compare(diff. #1/142):       16 ns/call    4.8 ns/call    5.5 ns/call
fpc_shortstr_compare(diff. #142/142):     57 ns/call    9.6 ns/call    8.5 ns/call
Edited by Rika

Merge request reports