[llvm-branch-commits] [libc] a513be4 - [libc][Obvious] Fix typo in strnlen_test.cpp.

2020-11-27 Thread Cheng Wang via llvm-branch-commits

Author: Cheng Wang
Date: 2020-11-27T15:56:19+08:00
New Revision: a513be490080ce7b974c5411a9de38e118c25991

URL: 
https://github.com/llvm/llvm-project/commit/a513be490080ce7b974c5411a9de38e118c25991
DIFF: 
https://github.com/llvm/llvm-project/commit/a513be490080ce7b974c5411a9de38e118c25991.diff

LOG: [libc][Obvious] Fix typo in strnlen_test.cpp.

Added: 


Modified: 
libc/test/src/string/strnlen_test.cpp

Removed: 




diff  --git a/libc/test/src/string/strnlen_test.cpp 
b/libc/test/src/string/strnlen_test.cpp
index 9d8616bc8bd7..b15ec2f8cef2 100644
--- a/libc/test/src/string/strnlen_test.cpp
+++ b/libc/test/src/string/strnlen_test.cpp
@@ -1,4 +1,4 @@
-//===-- Unittests for 
strnlen--===//
+//===-- Unittests for strnlen 
-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [libc] a8beb4a - [libc] Fix typo in buildbot README.txt.

2020-11-27 Thread Cheng Wang via llvm-branch-commits

Author: Cheng Wang
Date: 2020-11-27T19:01:21+08:00
New Revision: a8beb4ada4bd01980e9effc8a2671d4c6454a7ba

URL: 
https://github.com/llvm/llvm-project/commit/a8beb4ada4bd01980e9effc8a2671d4c6454a7ba
DIFF: 
https://github.com/llvm/llvm-project/commit/a8beb4ada4bd01980e9effc8a2671d4c6454a7ba.diff

LOG: [libc] Fix typo in buildbot README.txt.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D90381

Added: 


Modified: 
libc/utils/buildbot/README.txt

Removed: 




diff  --git a/libc/utils/buildbot/README.txt b/libc/utils/buildbot/README.txt
index 3edec0e416c3..40c2cb5b8776 100644
--- a/libc/utils/buildbot/README.txt
+++ b/libc/utils/buildbot/README.txt
@@ -1,5 +1,5 @@
 This folder contains resources needed to create a docker container for
-llvm-libc builbot worker.
+llvm-libc buildbot worker.
 
 Dockerfile: Sets up the docker image with all pre-requisites.
 



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [libc] 60cef89 - [libc] Add strncpy implementation.

2020-12-02 Thread Cheng Wang via llvm-branch-commits

Author: Cheng Wang
Date: 2020-12-02T20:45:51+08:00
New Revision: 60cef893627be169f22dc540834c4d085847d94a

URL: 
https://github.com/llvm/llvm-project/commit/60cef893627be169f22dc540834c4d085847d94a
DIFF: 
https://github.com/llvm/llvm-project/commit/60cef893627be169f22dc540834c4d085847d94a.diff

LOG: [libc] Add strncpy implementation.

Add libc strncpy implementation.

Reviewed By: sivachandra, gchatelet

Differential Revision: https://reviews.llvm.org/D91399

Added: 
libc/src/string/strncpy.cpp
libc/src/string/strncpy.h
libc/test/src/string/strncpy_test.cpp

Modified: 
libc/config/linux/aarch64/entrypoints.txt
libc/config/linux/x86_64/entrypoints.txt
libc/src/string/CMakeLists.txt
libc/test/src/string/CMakeLists.txt

Removed: 




diff  --git a/libc/config/linux/aarch64/entrypoints.txt 
b/libc/config/linux/aarch64/entrypoints.txt
index 3a34d95b36e1..1d8e5dd83672 100644
--- a/libc/config/linux/aarch64/entrypoints.txt
+++ b/libc/config/linux/aarch64/entrypoints.txt
@@ -29,6 +29,7 @@ set(TARGET_LIBC_ENTRYPOINTS
 libc.src.string.strcpy
 libc.src.string.strcspn
 libc.src.string.strlen
+libc.src.string.strncpy
 libc.src.string.strnlen
 libc.src.string.strpbrk
 libc.src.string.strrchr

diff  --git a/libc/config/linux/x86_64/entrypoints.txt 
b/libc/config/linux/x86_64/entrypoints.txt
index 4eb964b2c047..d6d56f2e33a5 100644
--- a/libc/config/linux/x86_64/entrypoints.txt
+++ b/libc/config/linux/x86_64/entrypoints.txt
@@ -47,6 +47,7 @@ set(TARGET_LIBC_ENTRYPOINTS
 libc.src.string.strcpy
 libc.src.string.strcspn
 libc.src.string.strlen
+libc.src.string.strncpy
 libc.src.string.strnlen
 libc.src.string.strpbrk
 libc.src.string.strrchr

diff  --git a/libc/src/string/CMakeLists.txt b/libc/src/string/CMakeLists.txt
index 8a2adbe08e0b..94df8a9d2166 100644
--- a/libc/src/string/CMakeLists.txt
+++ b/libc/src/string/CMakeLists.txt
@@ -74,6 +74,14 @@ add_entrypoint_object(
 strstr.h
 )
 
+add_entrypoint_object(
+  strncpy
+  SRCS
+strncpy.cpp
+  HDRS
+strncpy.h
+)
+
 add_entrypoint_object(
   strnlen
   SRCS

diff  --git a/libc/src/string/strncpy.cpp b/libc/src/string/strncpy.cpp
new file mode 100644
index ..45255e30ac52
--- /dev/null
+++ b/libc/src/string/strncpy.cpp
@@ -0,0 +1,28 @@
+//===-- Implementation of strncpy 
-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "src/string/strncpy.h"
+
+#include "src/__support/common.h"
+#include  // For size_t.
+
+namespace __llvm_libc {
+
+char *LLVM_LIBC_ENTRYPOINT(strncpy)(char *__restrict dest,
+const char *__restrict src, size_t n) {
+  size_t i = 0;
+  // Copy up until \0 is found.
+  for (; i < n && src[i] != '\0'; ++i)
+dest[i] = src[i];
+  // When n>strlen(src), n-strlen(src) \0 are appended.
+  for (; i < n; ++i)
+dest[i] = '\0';
+  return dest;
+}
+
+} // namespace __llvm_libc

diff  --git a/libc/src/string/strncpy.h b/libc/src/string/strncpy.h
new file mode 100644
index ..c419df990cd7
--- /dev/null
+++ b/libc/src/string/strncpy.h
@@ -0,0 +1,20 @@
+//===-- Implementation header for strncpy ---*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLVM_LIBC_SRC_STRING_STRNCPY_H
+#define LLVM_LIBC_SRC_STRING_STRNCPY_H
+
+#include 
+
+namespace __llvm_libc {
+
+char *strncpy(char *__restrict dest, const char *__restrict src, size_t n);
+
+} // namespace __llvm_libc
+
+#endif // LLVM_LIBC_SRC_STRING_STRNCPY_H

diff  --git a/libc/test/src/string/CMakeLists.txt 
b/libc/test/src/string/CMakeLists.txt
index df824cd18ecc..8b78fcfdd020 100644
--- a/libc/test/src/string/CMakeLists.txt
+++ b/libc/test/src/string/CMakeLists.txt
@@ -72,6 +72,16 @@ add_libc_unittest(
 libc.src.string.strstr
 )
 
+add_libc_unittest(
+  strncpy_test
+  SUITE
+libc_string_unittests
+  SRCS
+strncpy_test.cpp
+  DEPENDS
+libc.src.string.strncpy
+)
+
 add_libc_unittest(
   strnlen_test
   SUITE

diff  --git a/libc/test/src/string/strncpy_test.cpp 
b/libc/test/src/string/strncpy_test.cpp
new file mode 100644
index ..814870613251
--- /dev/null
+++ b/libc/test/src/string/strncpy_test.cpp
@@ -0,0 +1,57 @@
+//===-- Unittests for strncpy 
-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Ex

[llvm-branch-commits] [libc] 2423ec5 - [libc] Add memmove implementation.

2021-01-14 Thread Cheng Wang via llvm-branch-commits

Author: Cheng Wang
Date: 2021-01-15T12:08:25+08:00
New Revision: 2423ec583761304f93b5d01493a26aeb11cb5b8f

URL: 
https://github.com/llvm/llvm-project/commit/2423ec583761304f93b5d01493a26aeb11cb5b8f
DIFF: 
https://github.com/llvm/llvm-project/commit/2423ec583761304f93b5d01493a26aeb11cb5b8f.diff

LOG: [libc] Add memmove implementation.

Use `memcpy` rather than copying bytes one by one, for there might be large
size structs to move.

Reviewed By: gchatelet, sivachandra

Differential Revision: https://reviews.llvm.org/D93195

Added: 
libc/src/string/memmove.cpp
libc/src/string/memmove.h
libc/test/src/string/memmove_test.cpp

Modified: 
libc/config/linux/aarch64/entrypoints.txt
libc/config/linux/x86_64/entrypoints.txt
libc/src/string/CMakeLists.txt
libc/test/src/string/CMakeLists.txt

Removed: 




diff  --git a/libc/config/linux/aarch64/entrypoints.txt 
b/libc/config/linux/aarch64/entrypoints.txt
index 2b70cafd6fbf..4e20903ad260 100644
--- a/libc/config/linux/aarch64/entrypoints.txt
+++ b/libc/config/linux/aarch64/entrypoints.txt
@@ -30,6 +30,7 @@ set(TARGET_LIBC_ENTRYPOINTS
 libc.src.string.memchr
 libc.src.string.memcmp
 libc.src.string.memcpy
+libc.src.string.memmove
 libc.src.string.memset
 libc.src.string.memrchr
 libc.src.string.strcat

diff  --git a/libc/config/linux/x86_64/entrypoints.txt 
b/libc/config/linux/x86_64/entrypoints.txt
index 7c5367a9d528..d073e63d715f 100644
--- a/libc/config/linux/x86_64/entrypoints.txt
+++ b/libc/config/linux/x86_64/entrypoints.txt
@@ -52,6 +52,7 @@ set(TARGET_LIBC_ENTRYPOINTS
 libc.src.string.memchr
 libc.src.string.memcmp
 libc.src.string.memcpy
+libc.src.string.memmove
 libc.src.string.memrchr
 libc.src.string.memset
 libc.src.string.strcat

diff  --git a/libc/src/string/CMakeLists.txt b/libc/src/string/CMakeLists.txt
index 683b85720c60..e40eeb16b907 100644
--- a/libc/src/string/CMakeLists.txt
+++ b/libc/src/string/CMakeLists.txt
@@ -66,6 +66,18 @@ add_entrypoint_object(
 memcmp.h
 )
 
+add_entrypoint_object(
+  memmove
+  SRCS
+memmove.cpp
+  HDRS
+memmove.h
+  DEPENDS
+libc.include.unistd
+libc.src.stdlib.abs_utils
+libc.src.string.memcpy
+)
+
 add_entrypoint_object(
   strchr
   SRCS

diff  --git a/libc/src/string/memmove.cpp b/libc/src/string/memmove.cpp
new file mode 100644
index ..8958027d1d58
--- /dev/null
+++ b/libc/src/string/memmove.cpp
@@ -0,0 +1,61 @@
+//===-- Implementation of memmove 
-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "src/string/memmove.h"
+#include "src/__support/common.h"
+#include "src/stdlib/abs_utils.h"
+#include "src/string/memcpy.h"
+#include  // size_t, ptr
diff _t
+#include  // ssize_t
+
+namespace __llvm_libc {
+
+// src_m and dest_m might be the beginning or end.
+static inline void move_byte(unsigned char *dest_m, const unsigned char *src_m,
+ size_t count, ssize_t direction) {
+  for (ssize_t offset = 0; count; --count, offset += direction)
+dest_m[offset] = src_m[offset];
+}
+
+LLVM_LIBC_FUNCTION(void *, memmove,
+   (void *dest, const void *src, size_t count)) {
+  unsigned char *dest_c = reinterpret_cast(dest);
+  const unsigned char *src_c = reinterpret_cast(src);
+
+  // If the distance between src_c and dest_c is equal to or greater
+  // than count (integer_abs(src_c - dest_c) >= count), they would not overlap.
+  // e.g.   greater equal   overlapping
+  //[12345678]  [12345678]  [12345678]
+  // src_c: [_ab_]  [_ab_]  [_ab_]
+  // dest_c:[_yz_]  [___yz___]  [__yz]
+
+  // Use memcpy if src_c and dest_c do not overlap.
+  if (__llvm_libc::integer_abs(src_c - dest_c) >= static_cast(count))
+return __llvm_libc::memcpy(dest_c, src_c, count);
+
+  // Overlap cases.
+  // If dest_c starts before src_c (dest_c < src_c), copy forward(pointer add 
1)
+  // from beginning to end.
+  // If dest_c starts after src_c (dest_c > src_c), copy backward(pointer add
+  // -1) from end to beginning.
+  // If dest_c and src_c start at the same address (dest_c == src_c),
+  // just return dest.
+  // e.g.forward  backward
+  // *--><--*
+  // src_c : [___abcde_]  [_abcde___]
+  // dest_c: [_abc--___]  [___--cde_]
+
+  // TODO: Optimize `move_byte(...)` function.
+  if (dest_c < src_c)
+move_byte(dest_c, src_c, count, /*pointer add*/ 1);
+  if (dest_c > src_c)
+move_byte(dest_c + count - 1, src_c + count - 1, count, /*pointer add*/ 
-1);
+  return dest;
+}
+
+} // namespace __llvm_libc

diff  --git a/libc/src/string/m

[llvm-branch-commits] [libc] 1fd32dc - [libc] Add [l|ll]abs implementation.

2020-12-10 Thread Cheng Wang via llvm-branch-commits

Author: Cheng Wang
Date: 2020-12-11T09:25:20+08:00
New Revision: 1fd32dcb294e16781fcfcf1a468180d00cf1e3ca

URL: 
https://github.com/llvm/llvm-project/commit/1fd32dcb294e16781fcfcf1a468180d00cf1e3ca
DIFF: 
https://github.com/llvm/llvm-project/commit/1fd32dcb294e16781fcfcf1a468180d00cf1e3ca.diff

LOG: [libc] Add [l|ll]abs implementation.

Implement abs, labs and llabs with template.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D92626

Added: 
libc/src/stdlib/abs.cpp
libc/src/stdlib/abs.h
libc/src/stdlib/abs_utils.h
libc/src/stdlib/labs.cpp
libc/src/stdlib/labs.h
libc/src/stdlib/llabs.cpp
libc/src/stdlib/llabs.h
libc/test/src/stdlib/abs_test.cpp
libc/test/src/stdlib/labs_test.cpp
libc/test/src/stdlib/llabs_test.cpp

Modified: 
libc/config/linux/aarch64/entrypoints.txt
libc/config/linux/x86_64/entrypoints.txt
libc/spec/spec.td
libc/spec/stdc.td
libc/src/stdlib/CMakeLists.txt
libc/test/src/stdlib/CMakeLists.txt

Removed: 




diff  --git a/libc/config/linux/aarch64/entrypoints.txt 
b/libc/config/linux/aarch64/entrypoints.txt
index 3a3b050a6e06..534a4bdd6131 100644
--- a/libc/config/linux/aarch64/entrypoints.txt
+++ b/libc/config/linux/aarch64/entrypoints.txt
@@ -18,6 +18,11 @@ set(TARGET_LIBC_ENTRYPOINTS
 # errno.h entrypoints
 libc.src.errno.__errno_location
 
+# stdlib.h entrypoints
+libc.src.stdlib.abs
+libc.src.stdlib.labs
+libc.src.stdlib.llabs
+
 # string.h entrypoints
 libc.src.string.bzero
 libc.src.string.memchr

diff  --git a/libc/config/linux/x86_64/entrypoints.txt 
b/libc/config/linux/x86_64/entrypoints.txt
index 2b461c4eede5..4cae553ac6d4 100644
--- a/libc/config/linux/x86_64/entrypoints.txt
+++ b/libc/config/linux/x86_64/entrypoints.txt
@@ -41,6 +41,9 @@ set(TARGET_LIBC_ENTRYPOINTS
 # stdlib.h entrypoints
 libc.src.stdlib._Exit
 libc.src.stdlib.abort
+libc.src.stdlib.abs
+libc.src.stdlib.labs
+libc.src.stdlib.llabs
 
 # string.h entrypoints
 libc.src.string.bzero

diff  --git a/libc/spec/spec.td b/libc/spec/spec.td
index 29c11a9c2199..9a31d85c148c 100644
--- a/libc/spec/spec.td
+++ b/libc/spec/spec.td
@@ -42,6 +42,8 @@ def IntType : NamedType<"int">;
 def FloatType : NamedType<"float">;
 def DoubleType : NamedType<"double">;
 def LongDoubleType : NamedType<"long double">;
+def LongLongType : NamedType<"long long">;
+def LongType : NamedType<"long">;
 def CharType : NamedType<"char">;
 
 // Common types

diff  --git a/libc/spec/stdc.td b/libc/spec/stdc.td
index 70cc2600a612..051e0a89eb27 100644
--- a/libc/spec/stdc.td
+++ b/libc/spec/stdc.td
@@ -400,6 +400,9 @@ def StdC : StandardSpec<"stdc"> {
   [], // Enumerations
   [
   FunctionSpec<"abort", RetValSpec, [ArgSpec]>,
+  FunctionSpec<"abs", RetValSpec, [ArgSpec]>,
+  FunctionSpec<"labs", RetValSpec, [ArgSpec]>,
+  FunctionSpec<"llabs", RetValSpec, 
[ArgSpec]>,
   FunctionSpec<"_Exit", RetValSpec, [ArgSpec]>,
   ]
   >;

diff  --git a/libc/src/stdlib/CMakeLists.txt b/libc/src/stdlib/CMakeLists.txt
index 50b7421944dd..a599d8a59065 100644
--- a/libc/src/stdlib/CMakeLists.txt
+++ b/libc/src/stdlib/CMakeLists.txt
@@ -2,6 +2,12 @@ if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_OS})
   add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_OS})
 endif()
 
+add_header_library(
+  abs_utils
+  HDRS
+abs_utils.h
+)
+
 add_entrypoint_object(
   _Exit
   ALIAS
@@ -20,3 +26,33 @@ add_entrypoint_object(
 libc.src.signal.raise
 ._Exit
 )
+
+add_entrypoint_object(
+  abs
+  SRCS
+abs.cpp
+  HDRS
+abs.h
+  DEPENDS
+.abs_utils
+)
+
+add_entrypoint_object(
+  labs
+  SRCS
+labs.cpp
+  HDRS
+labs.h
+  DEPENDS
+.abs_utils
+)
+
+add_entrypoint_object(
+  llabs
+  SRCS
+llabs.cpp
+  HDRS
+llabs.h
+  DEPENDS
+.abs_utils
+)

diff  --git a/libc/src/stdlib/abs.cpp b/libc/src/stdlib/abs.cpp
new file mode 100644
index ..74c47cdb242d
--- /dev/null
+++ b/libc/src/stdlib/abs.cpp
@@ -0,0 +1,20 @@
+//===-- Implementation of abs 
-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "src/stdlib/abs.h"
+#include "src/__support/common.h"
+#include "src/stdlib/abs_utils.h"
+
+namespace __llvm_libc {
+
+int LLVM_LIBC_ENTRYPOINT(abs)(int n) {
+  // integer_abs from abs_utils.h.
+  return integer_abs(n);
+}
+
+} // namespace __llvm_libc

diff  --git a/libc/src/stdlib/abs.h b/libc/src/stdlib/abs.h
new file mode 100644
index ..42ef7f885ed6
--- /dev/null
+++ b/libc/src/stdlib/abs.h
@@ -0,0 +1,18 @@
+//===-- Implementat

[llvm-branch-commits] [libc] af68c3b - [libc] Add memcmp implementation.

2020-12-14 Thread Cheng Wang via llvm-branch-commits

Author: Cheng Wang
Date: 2020-12-15T09:47:29+08:00
New Revision: af68c3b8924218596ecee948cc22cbb2c69c7f42

URL: 
https://github.com/llvm/llvm-project/commit/af68c3b8924218596ecee948cc22cbb2c69c7f42
DIFF: 
https://github.com/llvm/llvm-project/commit/af68c3b8924218596ecee948cc22cbb2c69c7f42.diff

LOG: [libc] Add memcmp implementation.

Reviewed By: gchatelet

Differential Revision: https://reviews.llvm.org/D93009

Added: 
libc/src/string/memcmp.cpp
libc/src/string/memcmp.h
libc/test/src/string/memcmp_test.cpp

Modified: 
libc/config/linux/aarch64/entrypoints.txt
libc/config/linux/x86_64/entrypoints.txt
libc/src/string/CMakeLists.txt
libc/test/src/string/CMakeLists.txt

Removed: 




diff  --git a/libc/config/linux/aarch64/entrypoints.txt 
b/libc/config/linux/aarch64/entrypoints.txt
index 534a4bdd6131..89f910b5766c 100644
--- a/libc/config/linux/aarch64/entrypoints.txt
+++ b/libc/config/linux/aarch64/entrypoints.txt
@@ -26,6 +26,7 @@ set(TARGET_LIBC_ENTRYPOINTS
 # string.h entrypoints
 libc.src.string.bzero
 libc.src.string.memchr
+libc.src.string.memcmp
 libc.src.string.memcpy
 libc.src.string.memset
 libc.src.string.memrchr

diff  --git a/libc/config/linux/x86_64/entrypoints.txt 
b/libc/config/linux/x86_64/entrypoints.txt
index fce28231f319..d5a2f295d9d9 100644
--- a/libc/config/linux/x86_64/entrypoints.txt
+++ b/libc/config/linux/x86_64/entrypoints.txt
@@ -48,6 +48,7 @@ set(TARGET_LIBC_ENTRYPOINTS
 # string.h entrypoints
 libc.src.string.bzero
 libc.src.string.memchr
+libc.src.string.memcmp
 libc.src.string.memcpy
 libc.src.string.memrchr
 libc.src.string.memset

diff  --git a/libc/src/string/CMakeLists.txt b/libc/src/string/CMakeLists.txt
index 94df8a9d2166..683b85720c60 100644
--- a/libc/src/string/CMakeLists.txt
+++ b/libc/src/string/CMakeLists.txt
@@ -58,6 +58,14 @@ add_entrypoint_object(
 .string_utils
 )
 
+add_entrypoint_object(
+  memcmp
+  SRCS
+memcmp.cpp
+  HDRS
+memcmp.h
+)
+
 add_entrypoint_object(
   strchr
   SRCS

diff  --git a/libc/src/string/memcmp.cpp b/libc/src/string/memcmp.cpp
new file mode 100644
index ..1bd1c60ee1be
--- /dev/null
+++ b/libc/src/string/memcmp.cpp
@@ -0,0 +1,27 @@
+//===-- Implementation of memcmp 
--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "src/string/memcmp.h"
+#include "src/__support/common.h"
+#include  // size_t
+
+namespace __llvm_libc {
+
+// TODO: It is a simple implementation, an optimized version is preparing.
+int LLVM_LIBC_ENTRYPOINT(memcmp)(const void *lhs, const void *rhs,
+ size_t count) {
+  const unsigned char *_lhs = reinterpret_cast(lhs);
+  const unsigned char *_rhs = reinterpret_cast(rhs);
+  for (size_t i = 0; i < count; ++i)
+if (_lhs[i] != _rhs[i])
+  return _lhs[i] - _rhs[i];
+  // count is 0 or _lhs and _rhs are the same.
+  return 0;
+}
+
+} // namespace __llvm_libc

diff  --git a/libc/src/string/memcmp.h b/libc/src/string/memcmp.h
new file mode 100644
index ..1d79df5d4591
--- /dev/null
+++ b/libc/src/string/memcmp.h
@@ -0,0 +1,20 @@
+//===-- Implementation header for memcmp *- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLVM_LIBC_SRC_STRING_MEMCMP_H
+#define LLVM_LIBC_SRC_STRING_MEMCMP_H
+
+#include  // size_t
+
+namespace __llvm_libc {
+
+int memcmp(const void *lhs, const void *rhs, size_t count);
+
+} // namespace __llvm_libc
+
+#endif // LLVM_LIBC_SRC_STRING_MEMCMP_H

diff  --git a/libc/test/src/string/CMakeLists.txt 
b/libc/test/src/string/CMakeLists.txt
index 8b78fcfdd020..8202c699f20b 100644
--- a/libc/test/src/string/CMakeLists.txt
+++ b/libc/test/src/string/CMakeLists.txt
@@ -52,6 +52,16 @@ add_libc_unittest(
 libc.src.string.memchr
 )
 
+add_libc_unittest(
+  memcmp_test
+  SUITE
+libc_string_unittests
+  SRCS
+memcmp_test.cpp
+  DEPENDS
+libc.src.string.memcmp
+)
+
 add_libc_unittest(
   strchr_test
   SUITE

diff  --git a/libc/test/src/string/memcmp_test.cpp 
b/libc/test/src/string/memcmp_test.cpp
new file mode 100644
index ..3cfde0e8a34f
--- /dev/null
+++ b/libc/test/src/string/memcmp_test.cpp
@@ -0,0 +1,34 @@
+//===-- Unittests for memcmp 
--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with L