Skip to content

[libc] Implement 'qsort' and 'bsearch' on the GPU #66230

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion clang/lib/Headers/llvm_libc_wrappers/stdlib.h
Original file line number Diff line number Diff line change
Expand Up @@ -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!");
Expand Down
3 changes: 3 additions & 0 deletions libc/config/gpu/api.td
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ def StdlibAPI : PublicAPI<"stdlib.h"> {
"ldiv_t",
"lldiv_t",
"size_t",
"__bsearchcompare_t",
"__qsortcompare_t",
"__qsortrcompare_t",
"__atexithandler_t",
];
}
Expand Down
3 changes: 3 additions & 0 deletions libc/config/gpu/entrypoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions libc/docs/gpu/support.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand Down