4 ms·
It's interesting to read the sources[1] of lots of djb's[2] code, as he often works around problems with (or perhaps dislikes the style of) standard libraries b
by rikkus 10y ago
It's interesting to read the sources[1] of lots of djb's[2] code, as he often works around problems with (or perhaps dislikes the style of) standard libraries by re-implementing parts.
[1] https://github.com/abh/djbdns/blob/master/str_len.c https://github.com/abh/djbdns/blob/master/str_len.c
[2] http://cr.yp.to/djb.html http://cr.yp.to/djb.html
- csl 10y agoOn a side note, isn't the choice of exactly four unrolls very architecture specific? As in, it works, but may be sub-optimal for your specific machine. I've done the exact same thing myself, and IIRC its performance varied a lot between which ISA it was compiled for. This is almost what Duff's device solves, except then you need to know the length beforehand.
- rikkus 10y agoAbsolutely. It's a (possible) optimisation that is either based on evidence (seems likely, because DJB) or hope. Actual behaviour is impossible to predict on untested platforms. My assumption is that DJB tested this locally and found enough of a speedup that it was worth it, considering the very low added complexity and risk of major degradation / defects on untested platforms.