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