4 ms·
I have a memset that's not only 10x faster than glibc, but also secure. The trick is to bypass the generic asm, and let the compiler optimize it, esp. with cons
by rurban 5y ago
I have a memset that's not only 10x faster than glibc, but also secure. The trick is to bypass the generic asm, and let the compiler optimize it, esp. with constant sizes and known alignments. Esp. with clang.
- errcorrectcode 5y agoDon't do this. Security. explicit_bzero() won't be optimized away.
- rurban 5y agoI do it because nobody else implemented a secure memset. What they call secure is just avoiding that the compiler ignores it. A secure memset also cleans the caches with a memory barrier, so that meltdown cannot read it. explicit_bzero and it's numerous variants are not only insecure, but also slow. (byte wise!) Only safelibc has a secure memset_s. https://github.com/rurban/safeclib/blob/master/tests/perf_memset_s.c https://github.com/rurban/safeclib/blob/master/tests/perf_me...