News for hackers. Stuff that matters.
Re:Six times faster than C by fuber2018 on Friday July 07, 2023 @05:36AM (#36629313)
I took the 64-bit SWAR ('S'IMD-'W'ithin-'A'-'R'egister) road and passed in the string length - the calling code has the length "right there"!!!

Using the original run_switches function, app took 3.554s (average of 10 runs).

With the SWAR-version with the string length passed in, app took 0.117s (average of 10 runs).

That's an overall 27.6x speedup.

Re:Six times faster than C by fuber2018 on Friday July 07, 2023 @06:10AM (#36629583)
If I unroll the main while loop to handle 4x as much each time through the loop in the SWAR-version, the runtime drops to 0.0562s (average 10 runs).

That's an overall 57.5x speedup.

Re:Six times faster than C by fuber2018 on Friday July 07, 2023 @07:13AM (#36630014)
If I convert the unrolled-64-bit SWAR function to use 32-bit chunks instead, average runtime almost doubles, approx. 0.1s now.

Need sleep now.

Re:Six times faster than C by fuber2018 on Friday July 07, 2023 @07:35AM (#36630162)
If I unroll the 64-bit SWAR version by 8x instead of 4x, the runtime is reduced by another 10% over the 4x-unrolled SWAR version. Diminishing returns...