3 ms·
Worth patching libc?
by londons_explore 4y ago
Worth patching libc?
- vinkelhake 4y agolibc tolower() works on a single char at a time. This post is about the gains you can get by converting multiple chars at once.
- londons_explore 4y agoPresumably with the right __inline stuff it could be vectorized by a compiler, since tolower is normally called from a loop? Although I guess since it's often a dynamically linked library, said optimizations would have to happen at load time, and the dynamic loader doesn't do such things... :-(
- mananaysiempre 4y agoThe standard tolower() / toupper() take a single character only; bulk strlwr() / strupr() are nonstandard (if commonly present) and—more importantly—virtually unused. I suppose implementing this technique in the C/POSIX-locale version of nonstandard stricmp() / POSIX strcasecmp() might be helpful in some cases, because people do use that one, but I still expect that any situations that truly call for an ASCII-only case-insensitive comparison (parsers?) will be doing much more work per byte for other reasons (state machine, perfect hash, etc.).
- stabbles 4y agoIt's not the same, libc's tolower takes an int as an individual character
- Findecanor 4y agoAlthough ... the existence of a libc with SIMD versions of its functions is not implausible. There are compilers that would produce such functions beside the normal ones if the source is decorated with the right #pragma. Such functions would be called only from within vectorised loops (or other SIMD versions of functions).
- moonchild 4y agoIndeed. For instance, glibc's math library has vectorised trig functions, and gcc can generate calls to them if it sees fit. For the rest of us, there is sleef.
- Findecanor 4y agoThis type of bit manipulation will only work with pure ASCII, which had been designed to make this transformation simple with only bit manipulation — just not in parallel. Most systems default to using Unicode these days, for which the problem is much more complex even when the language is set to English.
- xxpor 4y agoI was really disappointed when I found out the author didn't have to deal with the dotless I problem.