[NFC][MLIR][Linalg] Refactor linalg.matmul tablegen ODS and related C++ code. (#116377)
[llvm-project.git] / offload / DeviceRTL / src / LibC.cpp
blob291ceb023a69c54f0f4a0dfaef3bba19568cce91
1 //===------- LibC.cpp - Simple implementation of libc functions --- C++ ---===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
9 #include "LibC.h"
11 #pragma omp begin declare target device_type(nohost)
13 namespace impl {
14 int32_t omp_vprintf(const char *Format, __builtin_va_list vlist);
17 #ifndef OMPTARGET_HAS_LIBC
18 namespace impl {
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
31 } // namespace impl
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
40 extern "C" {
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)
46 if (L[I] != R[I])
47 return (int)L[I] - (int)R[I];
49 return 0;
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)
55 dstc[I] = C;
59 #pragma omp end declare target