| 
 | 1 | +//==- cstdlib --------------------------------------------------------------==//  | 
 | 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 | +#pragma once  | 
 | 10 | + | 
 | 11 | +// Include real STL <cstdlib> header - the next one from the include search  | 
 | 12 | +// directories.  | 
 | 13 | +#if defined(__has_include_next)  | 
 | 14 | +// GCC/clang support go through this path.  | 
 | 15 | +#include_next <cstdlib>  | 
 | 16 | +#else  | 
 | 17 | +// MSVC doesn't support "#include_next", so we have to be creative.  | 
 | 18 | +// Our header is located in "stl_wrappers/cstdlib" so it won't be picked by the  | 
 | 19 | +// following include. MSVC's installation, on the other hand, has the layout  | 
 | 20 | +// where the following would result in the <cstdlib> we want. This is obviously  | 
 | 21 | +// hacky, but the best we can do...  | 
 | 22 | +#include <../include/cstdlib>  | 
 | 23 | +#endif  | 
 | 24 | + | 
 | 25 | +#ifdef __SYCL_DEVICE_ONLY__  | 
 | 26 | +extern "C" {  | 
 | 27 | +[[clang::sycl_device_only, clang::always_inline]] div_t div(int x, int y) { return {x / y, x % y}; }  | 
 | 28 | +[[clang::sycl_device_only, clang::always_inline]] ldiv_t ldiv(long x, long y) { return {x / y, x % y}; }  | 
 | 29 | +[[clang::sycl_device_only, clang::always_inline]] lldiv_t lldiv(long long x, long long y) { return {x / y, x % y}; }  | 
 | 30 | + | 
 | 31 | +[[clang::sycl_device_only, clang::always_inline]] int abs(int n) { return n < 0 ? -n : n; }  | 
 | 32 | +[[clang::sycl_device_only, clang::always_inline]] long labs(long n) { return n < 0 ? -n : n; }  | 
 | 33 | +[[clang::sycl_device_only, clang::always_inline]] long long llabs(long long n) { return n < 0 ? -n : n; }  | 
 | 34 | +}  | 
 | 35 | + | 
 | 36 | +#ifdef _LIBCPP_BEGIN_NAMESPACE_STD  | 
 | 37 | +_LIBCPP_BEGIN_NAMESPACE_STD  | 
 | 38 | +#else  | 
 | 39 | +namespace std {  | 
 | 40 | +#ifdef _GLIBCXX_BEGIN_NAMESPACE_VERSION  | 
 | 41 | +_GLIBCXX_BEGIN_NAMESPACE_VERSION  | 
 | 42 | +#endif  | 
 | 43 | +#endif  | 
 | 44 | + | 
 | 45 | +using ::div;  | 
 | 46 | +[[clang::sycl_device_only, clang::always_inline]] ldiv_t div(long x, long y) { return {x / y, x % y}; }  | 
 | 47 | +[[clang::sycl_device_only, clang::always_inline]] lldiv_t div(long long x, long long y) { return {x / y, x % y}; }  | 
 | 48 | +using ::ldiv;  | 
 | 49 | +using ::lldiv;  | 
 | 50 | + | 
 | 51 | +using ::abs;  | 
 | 52 | +[[clang::sycl_device_only, clang::always_inline]] long abs(long n) { return n < 0 ? -n : n; }  | 
 | 53 | +[[clang::sycl_device_only, clang::always_inline]] long long abs(long long n) { return n < 0 ? -n : n; }  | 
 | 54 | +using ::labs;  | 
 | 55 | +using ::llabs;  | 
 | 56 | + | 
 | 57 | +#ifdef _LIBCPP_END_NAMESPACE_STD  | 
 | 58 | +_LIBCPP_END_NAMESPACE_STD  | 
 | 59 | +#else  | 
 | 60 | +#ifdef _GLIBCXX_BEGIN_NAMESPACE_VERSION  | 
 | 61 | +_GLIBCXX_END_NAMESPACE_VERSION  | 
 | 62 | +#endif  | 
 | 63 | +} // namespace std  | 
 | 64 | +#endif  | 
 | 65 | +#endif // __SYCL_DEVICE_ONLY__  | 
0 commit comments