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 //===----------------------------------------------------------------------===// 8 9 #include "LibC.h" 10 11 #pragma omp begin declare target device_type(nohost) 12 13 #if defined(__AMDGPU__) && !defined(OMPTARGET_HAS_LIBC) 14 extern "C" int vprintf(const char *format, __builtin_va_list) { return -1; } 15 #else 16 extern "C" int vprintf(const char *format, __builtin_va_list); 17 #endif 18 19 extern "C" { 20 [[gnu::weak]] int memcmp(const void *lhs, const void *rhs, size_t count) { 21 auto *L = reinterpret_cast<const unsigned char *>(lhs); 22 auto *R = reinterpret_cast<const unsigned char *>(rhs); 23 24 for (size_t I = 0; I < count; ++I) 25 if (L[I] != R[I]) 26 return (int)L[I] - (int)R[I]; 27 28 return 0; 29 } 30 31 [[gnu::weak]] void memset(void *dst, int C, size_t count) { 32 auto *dstc = reinterpret_cast<char *>(dst); 33 for (size_t I = 0; I < count; ++I) 34 dstc[I] = C; 35 } 36 37 [[gnu::weak]] int printf(const char *Format, ...) { 38 __builtin_va_list vlist; 39 __builtin_va_start(vlist, Format); 40 return ::vprintf(Format, vlist); 41 } 42 } 43 44 namespace ompx { 45 [[clang::no_builtin("printf")]] int printf(const char *Format, ...) { 46 __builtin_va_list vlist; 47 __builtin_va_start(vlist, Format); 48 return ::vprintf(Format, vlist); 49 } 50 } // namespace ompx 51 52 #pragma omp end declare target 53