swab.c(libc): use a simplified version of byte swapping
This version of swab function simplifies the logic of swapping adjacent bytes. Previous version of swab() used an arbitrary unrolling, which was relevant back in the day but unnecessary for modern compilers, as if the input size is known at compile time, they can do it automatically.
This version of swab() is inspired by musl. A similar version can be found at: https://github.com/openbsd/src/blob/master/lib/libc/string/swab.c Godbolt testing: https://godbolt.org/z/8TMxx1jos
Note: I didn't remove the "derived from ..." section. I'm not sure whether this would be necessary to do, and if so, please let me know!
This seems like a fine cleanup. With this change there is no copyrightable content left so I'd replace the license block entirely, ideally with a 2-clause BSD or MIT license.
but unnecessary for modern compilers, as if the input size is known at compile time, they can do it automatically.
The size is never known within the translation unit of swab.c so short of using LTO, the compiler's ability to optimize it is zero, but this "optimization" doesn't seems to make much sense on a modern processor.
This seems like a fine cleanup. With this change there is no copyrightable content left so I'd replace the license block entirely, ideally with a 2-clause BSD or MIT license.
Thanks for the brief explanation! I've updated the license information. However, I also added "copyright by rilysh" part (in OpenBSD swab, they also seem added this), but if it isn't required, I'll remove it too!
The size is never known within the translation unit of swab.c so short of using LTO, the compiler's ability to optimize it is zero.
I agree, I forgot (didn't notice) that the call would be from a different source unit...sorry for the confusion.
Looking very close. A couple minor nits on the license. If you change, could you also fold these two commits together? Thanks!
Style checker seems didn't run (https://github.com/freebsd/freebsd-src/actions/runs/7758887131/job/21161673147?pr=1086) here, hmm, but seems unrelated...
I think this is ready, but it may still bounce due to style (I'll re-run it before I land, but the change looks good so far).
pushed