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
, __builtin_va_list vlist
);
17 #ifndef OMPTARGET_HAS_LIBC
19 #pragma omp begin declare variant match( \
20 device = {arch(nvptx, nvptx64)}, \
21 implementation = {extension(match_any)})
22 extern "C" int vprintf(const char *format
, ...);
23 int omp_vprintf(const char *Format
, __builtin_va_list vlist
) {
24 return vprintf(Format
, vlist
);
26 #pragma omp end declare variant
28 #pragma omp begin declare variant match(device = {arch(amdgcn)})
29 int omp_vprintf(const char *Format
, __builtin_va_list
) { return -1; }
30 #pragma omp end declare variant
33 extern "C" int printf(const char *Format
, ...) {
34 __builtin_va_list vlist
;
35 __builtin_va_start(vlist
, Format
);
36 return impl::omp_vprintf(Format
, vlist
);
38 #endif // OMPTARGET_HAS_LIBC
41 [[gnu::weak
]] int memcmp(const void *lhs
, const void *rhs
, size_t count
) {
42 auto *L
= reinterpret_cast<const unsigned char *>(lhs
);
43 auto *R
= reinterpret_cast<const unsigned char *>(rhs
);
45 for (size_t I
= 0; I
< count
; ++I
)
47 return (int)L
[I
] - (int)R
[I
];
52 [[gnu::weak
]] void memset(void *dst
, int C
, size_t count
) {
53 auto *dstc
= reinterpret_cast<char *>(dst
);
54 for (size_t I
= 0; I
< count
; ++I
)
59 #pragma omp end declare target