Skip to content

Commit bf85f27

Browse files
authored
[libc] Implement 'qsort' and 'bsearch' on the GPU (#66230)
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.
1 parent 8d99bf9 commit bf85f27

File tree

4 files changed

+13
-1
lines changed

4 files changed

+13
-1
lines changed

clang/lib/Headers/llvm_libc_wrappers/stdlib.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,11 @@
2323

2424
#pragma omp begin declare target
2525

26-
// The LLVM C library uses this type so we forward declare it.
26+
// The LLVM C library uses these named types so we forward declare them.
2727
typedef void (*__atexithandler_t)(void);
28+
typedef int (*__bsearchcompare_t)(const void *, const void *);
29+
typedef int (*__qsortcompare_t)(const void *, const void *);
30+
typedef int (*__qsortrcompare_t)(const void *, const void *, void *);
2831

2932
// Enforce ABI compatibility with the structs used by the LLVM C library.
3033
_Static_assert(__builtin_offsetof(div_t, quot) == 0, "ABI mismatch!");

libc/config/gpu/api.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ def StdlibAPI : PublicAPI<"stdlib.h"> {
4646
"ldiv_t",
4747
"lldiv_t",
4848
"size_t",
49+
"__bsearchcompare_t",
50+
"__qsortcompare_t",
51+
"__qsortrcompare_t",
4952
"__atexithandler_t",
5053
];
5154
}

libc/config/gpu/entrypoints.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,12 @@ set(TARGET_LIBC_ENTRYPOINTS
5858
libc.src.stdlib.atoll
5959
libc.src.stdlib.div
6060
libc.src.stdlib.labs
61+
libc.src.stdlib.bsearch
6162
libc.src.stdlib.ldiv
6263
libc.src.stdlib.llabs
6364
libc.src.stdlib.lldiv
65+
libc.src.stdlib.qsort
66+
libc.src.stdlib.qsort_r
6467
libc.src.stdlib.strtod
6568
libc.src.stdlib.strtof
6669
libc.src.stdlib.strtol

libc/docs/gpu/support.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ llabs |check|
9696
div |check|
9797
ldiv |check|
9898
lldiv |check|
99+
bsearch |check|
100+
qsort |check|
101+
qsort_r |check|
99102
strtod |check|
100103
strtof |check|
101104
strtol |check|

0 commit comments

Comments
 (0)