Dug up this historic example from glibc of why optimizing compilers are a necessary mitigation against hideous code: https://sourceware.org/git/?p=glibc.git;a=blob;f=string/strstr.c;hb=0ecb606cb6cf65de1d9fc8a919bceb4be476c602 …
-
-
My point isn't to poke fun at the code, but that this kind of coding is the necessary evolutionary endgame with non-optimizing compilers.
-
You end up stuck in local extrema ("fast" ver of quadratic algo) b/c nobody's qualified to rewrite the linear-time one in "high-level asm".
-
And you end up with code that's impossible to debug/verify/audit because it's not even obvious what it's doing.
- 1 more reply
New conversation -
-
-
Is that still faster than a modern properly optimized boyer-moore impl? BM should be linear.
-
No, it's much slower. BM isn't constant-space, but there are at least two known, very good constant-space and linear-time algorithms.
-
Doesn't BM become linear time with Galil's addition? What are the two known alternative algorithms?
-
The problem is failure to be constant-space. strstr needs ability to run in constant-space because it does not admit errors.
End of conversation
New conversation -
-
-
The point of this code is that it's deeply unpleasant to read, correct?
Thanks. Twitter will use this to make your timeline better. UndoUndo
-
-
-
Not sure what's more of an eyesore: the code, or the brace/indentation style ;)
Thanks. Twitter will use this to make your timeline better. UndoUndo
-
-
-
that comment is so cute
Thanks. Twitter will use this to make your timeline better. UndoUndo
-
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.