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 // We do not have a vprintf implementation for AMD GPU yet so we use a stub.
29 #pragma omp begin declare variant match(device = {arch(amdgcn)})
31 int32_t omp_vprintf(const char *Format
, void *Arguments
, uint32_t) {
35 #pragma omp end declare variant
39 int memcmp(const void *lhs
, const void *rhs
, size_t count
) {
40 auto *L
= reinterpret_cast<const unsigned char *>(lhs
);
41 auto *R
= reinterpret_cast<const unsigned char *>(rhs
);
43 for (size_t I
= 0; I
< count
; ++I
)
45 return (int)L
[I
] - (int)R
[I
];
50 void memset(void *dst
, int C
, size_t count
) {
51 auto *dstc
= reinterpret_cast<char *>(dst
);
52 for (size_t I
= 0; I
< count
; ++I
)
56 /// printf() calls are rewritten by CGGPUBuiltin to __llvm_omp_vprintf
57 int32_t __llvm_omp_vprintf(const char *Format
, void *Arguments
, uint32_t Size
) {
58 return impl::omp_vprintf(Format
, Arguments
, Size
);
62 #pragma omp end declare target