1 //===------- LibC.cpp - Simple implementation of libc functions --- C++ ---===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
11 #pragma omp begin declare target device_type(nohost)
14 int32_t omp_vprintf(const char *Format
, void *Arguments
, uint32_t);
17 #pragma omp begin declare variant match( \
18 device = {arch(nvptx, nvptx64)}, \
19 implementation = {extension(match_any)})
20 extern "C" int32_t vprintf(const char *, void *);
22 int32_t omp_vprintf(const char *Format
, void *Arguments
, uint32_t) {
23 return vprintf(Format
, Arguments
);
26 #pragma omp end declare variant
28 #pragma omp begin declare variant match(device = {arch(amdgcn)})
30 #ifdef OMPTARGET_HAS_LIBC
31 // TODO: Remove this handling once we have varargs support.
32 extern "C" struct FILE *stdout
;
33 extern "C" int32_t rpc_fprintf(FILE *, const char *, void *, uint64_t);
36 int32_t omp_vprintf(const char *Format
, void *Arguments
, uint32_t Size
) {
37 return rpc_fprintf(stdout
, Format
, Arguments
, Size
);
41 // We do not have a vprintf implementation for AMD GPU so we use a stub.
43 int32_t omp_vprintf(const char *Format
, void *Arguments
, uint32_t) {
48 #pragma omp end declare variant
52 [[gnu::weak
]] int memcmp(const void *lhs
, const void *rhs
, size_t count
) {
53 auto *L
= reinterpret_cast<const unsigned char *>(lhs
);
54 auto *R
= reinterpret_cast<const unsigned char *>(rhs
);
56 for (size_t I
= 0; I
< count
; ++I
)
58 return (int)L
[I
] - (int)R
[I
];
63 [[gnu::weak
]] void memset(void *dst
, int C
, size_t count
) {
64 auto *dstc
= reinterpret_cast<char *>(dst
);
65 for (size_t I
= 0; I
< count
; ++I
)
69 /// printf() calls are rewritten by CGGPUBuiltin to __llvm_omp_vprintf
70 int32_t __llvm_omp_vprintf(const char *Format
, void *Arguments
, uint32_t Size
) {
71 return impl::omp_vprintf(Format
, Arguments
, Size
);
75 #pragma omp end declare target