[libc-commits] [PATCH] D72516: [llvm-libc] Add memory function benchmarks

Fangrui Song via Phabricator via libc-commits libc-commits at lists.llvm.org
Wed Jan 22 14:58:45 PST 2020


MaskRay added inline comments.


================
Comment at: libc/utils/benchmarks/Memcmp.cpp:64
+    FunctionPrototype Function =
+        StringSwitch<FunctionPrototype>(FunctionName).Case("memcmp", &::memcmp);
+    return llvm::libc_benchmarks::benchmark(
----------------
abrachet wrote:
> sivachandra wrote:
> > ckennelly wrote:
> > > Should we setup an analogous benchmark for `bcmp`?
> > Shoud llvm-libc provide bcmp at all?
> In what I believe was @gchatelet's email on the list said they were hoping `!memcmp(...)` would be emitted as `!bcmp(...)` for efficiency. [[ https://godbolt.org/z/5zBm4k | clang ]] does make this optimization.
TargetLibraryInfo.cpp

```
static bool hasBcmp(const Triple &TT) {
  // Posix removed support from bcmp() in 2001, but the glibc and several
  // implementations of the libc still have it.
  if (TT.isOSLinux())
    return TT.isGNUEnvironment() || TT.isMusl();
  // Both NetBSD and OpenBSD are planning to remove the function. Windows does
  // not have it.
  return TT.isOSFreeBSD() || TT.isOSSolaris();
}
```

On certain platforms (including Linux), memcmp can be optimized to bcmp if preferable.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D72516/new/

https://reviews.llvm.org/D72516





More information about the libc-commits mailing list