From 3568f4b82b83a6c024751302d96ee499b24d6a5c Mon Sep 17 00:00:00 2001 From: Joseph Huber Date: Wed, 13 Sep 2023 11:27:31 -0500 Subject: [PATCH] [libc] Implement 'qsort' and 'bsearch' on the GPU Summary: This patch simply adds the necessary config to enable qsort and bsearch on the GPU. It is *highly* unlikely that anyone will use these, as they are single threaded, but we may as well support all entrypoints that we can. --- clang/lib/Headers/llvm_libc_wrappers/stdlib.h | 5 ++++- libc/config/gpu/api.td | 3 +++ libc/config/gpu/entrypoints.txt | 3 +++ libc/docs/gpu/support.rst | 3 +++ 4 files changed, 13 insertions(+), 1 deletion(-) diff --git a/clang/lib/Headers/llvm_libc_wrappers/stdlib.h b/clang/lib/Headers/llvm_libc_wrappers/stdlib.h index 9cb2b4e64aa68..7fce5a1a31d52 100644 --- a/clang/lib/Headers/llvm_libc_wrappers/stdlib.h +++ b/clang/lib/Headers/llvm_libc_wrappers/stdlib.h @@ -23,8 +23,11 @@ #pragma omp begin declare target -// The LLVM C library uses this type so we forward declare it. +// The LLVM C library uses these named types so we forward declare them. typedef void (*__atexithandler_t)(void); +typedef int (*__bsearchcompare_t)(const void *, const void *); +typedef int (*__qsortcompare_t)(const void *, const void *); +typedef int (*__qsortrcompare_t)(const void *, const void *, void *); // Enforce ABI compatibility with the structs used by the LLVM C library. _Static_assert(__builtin_offsetof(div_t, quot) == 0, "ABI mismatch!"); diff --git a/libc/config/gpu/api.td b/libc/config/gpu/api.td index f8db0742ac829..dbd212be56a3f 100644 --- a/libc/config/gpu/api.td +++ b/libc/config/gpu/api.td @@ -46,6 +46,9 @@ def StdlibAPI : PublicAPI<"stdlib.h"> { "ldiv_t", "lldiv_t", "size_t", + "__bsearchcompare_t", + "__qsortcompare_t", + "__qsortrcompare_t", "__atexithandler_t", ]; } diff --git a/libc/config/gpu/entrypoints.txt b/libc/config/gpu/entrypoints.txt index 0e314c60870c6..b8d09c9bb8a8b 100644 --- a/libc/config/gpu/entrypoints.txt +++ b/libc/config/gpu/entrypoints.txt @@ -58,9 +58,12 @@ set(TARGET_LIBC_ENTRYPOINTS libc.src.stdlib.atoll libc.src.stdlib.div libc.src.stdlib.labs + libc.src.stdlib.bsearch libc.src.stdlib.ldiv libc.src.stdlib.llabs libc.src.stdlib.lldiv + libc.src.stdlib.qsort + libc.src.stdlib.qsort_r libc.src.stdlib.strtod libc.src.stdlib.strtof libc.src.stdlib.strtol diff --git a/libc/docs/gpu/support.rst b/libc/docs/gpu/support.rst index fabdfb968a741..6d73addb28d05 100644 --- a/libc/docs/gpu/support.rst +++ b/libc/docs/gpu/support.rst @@ -96,6 +96,9 @@ llabs |check| div |check| ldiv |check| lldiv |check| +bsearch |check| +qsort |check| +qsort_r |check| strtod |check| strtof |check| strtol |check|