16 #ifndef INCLUDE_NN_NLIB_PLATFORM_H_ 17 #define INCLUDE_NN_NLIB_PLATFORM_H_ 20 # error Sorry, ILP64 not supported 24 #define NLIB_VERSION_YEAR 2017 25 #define NLIB_VERSION_YEAR_SHORT 17 26 #define NLIB_VERSION_DATE 0926 27 #define NLIB_VERSION 20170926 30 # ifndef __STDC_FORMAT_MACROS 32 # pragma message(__FILE__ ": __STDC_FORMAT_MACROS not defined, compile may fail") 33 # elif !defined(NN_PLATFORM_CTR) && !defined(CAFE) 34 # warning __STDC_FORMAT_MACROS not defined, compile may fail 36 # define __STDC_FORMAT_MACROS 39 #ifndef __STDC_WANT_LIB_EXT1__ 40 # define __STDC_WANT_LIB_EXT1__ 1 44 # define __has_builtin(x) 0 48 # define __has_feature(x) 0 51 #ifndef __has_cpp_attribute 52 # define __has_cpp_attribute(x) 0 55 #ifndef __has_attribute 56 # define __has_attribute(x) 0 59 #ifndef __has_declspec_attribute 60 # define __has_declspec_attribute(x) 0 64 # define __has_include(x) 0 67 #if __has_feature(thread_sanitizer) 68 # define NLIB_NO_TSAN __attribute__((no_sanitize("thread"))) 73 #if __has_feature(address_sanitizer) 74 # define NLIB_NO_ASAN __attribute__((no_sanitize("address"))) 79 #if __has_feature(memory_sanitizer) 80 # define NLIB_NO_MSAN __attribute__((no_sanitize("memory"))) 89 # define NLIB_UNUSED(x) (void)(x) 97 #if !defined(NLIB_THREAD_AA_) && defined(__clang__) && \ 98 (!defined(SWIG)) && __has_attribute(capability) 99 #define NLIB_THREAD_AA_(x) __attribute__((x)) 101 #ifdef NLIB_THREAD_AA_ 102 #undef NLIB_THREAD_AA_ 104 #define NLIB_THREAD_AA_(x) 107 #define NLIB_CAPABILITY(x) NLIB_THREAD_AA_(capability(x)) 108 #define NLIB_SCOPED_CAPABILITY NLIB_THREAD_AA_(scoped_lockable) 109 #define NLIB_GUARDED_BY(x) NLIB_THREAD_AA_(guarded_by(x)) 110 #define NLIB_PT_GUARDED_BY(x) NLIB_THREAD_AA_(pt_guarded_by(x)) 111 #define NLIB_ACQUIRED_BEFORE(...) NLIB_THREAD_AA_(acquired_before(__VA_ARGS__)) 112 #define NLIB_ACQUIRED_AFTER(...) NLIB_THREAD_AA_(acquired_after(__VA_ARGS__)) 113 #define NLIB_REQUIRES(...) NLIB_THREAD_AA_(requires_capability(__VA_ARGS__)) 114 #define NLIB_REQUIRES_SHARED(...) NLIB_THREAD_AA_(requires_shared_capability(__VA_ARGS__)) 115 #define NLIB_ACQUIRE(...) NLIB_THREAD_AA_(acquire_capability(__VA_ARGS__)) 116 #define NLIB_ACQUIRE_SHARED(...) NLIB_THREAD_AA_(acquire_shared_capability(__VA_ARGS__)) 117 #define NLIB_RELEASE(...) NLIB_THREAD_AA_(release_capability(__VA_ARGS__)) 118 #define NLIB_RELEASE_SHARED(...) NLIB_THREAD_AA_(release_shared_capability(__VA_ARGS__)) 119 #define NLIB_TRY_ACQUIRE(...) NLIB_THREAD_AA_(try_acquire_capability(__VA_ARGS__)) 120 #define NLIB_TRY_ACQUIRE_SHARED(...) NLIB_THREAD_AA_(try_acquire_shared_capability(__VA_ARGS__)) 121 #define NLIB_EXCLUDES(...) NLIB_THREAD_AA_(locks_excluded(__VA_ARGS__)) 122 #define NLIB_ASSERT_CAPABILITY(x) NLIB_THREAD_AA_(assert_capability(x)) 123 #define NLIB_ASSERT_SHARED_CAPABILITY(x) NLIB_THREAD_AA_(assert_shared_capability(x)) 124 #define NLIB_RETURN_CAPABILITY(x) NLIB_THREAD_AA_(lock_returned(x)) 125 #define NLIB_NO_THREAD_SAFETY_ANALYSIS NLIB_THREAD_AA_(no_thread_safety_analysis) 132 #if (defined(__cplusplus) && __cplusplus >= 201703L) || \ 133 (defined(_MSVC_LANG) && _MSVC_LANG >= 201703L) 137 #if defined(NLIB_RENAME_CAPI) 138 #include "nn/nlib/Platform_rename.h" 143 #define NLIB_CAPI(x) x 146 #define NLIB_STRINGIFY_(s) #s 147 #define NLIB_STRINGIFY(s) NLIB_STRINGIFY_(s) 149 #if defined(_MSC_VER) 150 # include "nn/nlib/Platform_win32.h" 151 #elif defined(__linux__) || \ 152 defined(__FreeBSD__) || \ 153 defined(__CYGWIN__) || \ 154 (defined(__APPLE__) && defined(__MACH__)) 158 # include "nn/nlib/Platform_unix.h" 159 #elif defined(NN_PLATFORM_CTR) 160 # include "nn/nlib/Platform_ctr.h" 162 # include "nn/nlib/Platform_cafe.h" 163 #elif defined(__NX__) 164 # include "nn/nlib/Platform_nx.h" 167 #if defined(_MSC_VER) && defined(n_EXPORTS) 168 #undef NLIB_VIS_PUBLIC 169 #define NLIB_VIS_PUBLIC NLIB_WINEXPORT 172 #ifndef __analysis_assume 173 # define __analysis_assume(expr) 176 #ifndef _Printf_format_string_ 177 # define _Printf_format_string_ 180 #if defined(__ARM_NEON__) || defined(__aarch64__) 201 #if defined(NLIB_SSE41) || defined(NLIB_NEON) 204 # include <arm_neon.h> 207 # include <smmintrin.h> 210 # include <nmmintrin.h> 214 #if defined(__ARM_ACLE) 215 #include <arm_acle.h> 222 # define RSIZE_MAX 0x7FFFFFFFL 224 # define RSIZE_MAX 0x7FFFFFFFFFFFFFFFLL 229 # define NLIB_WARN(exp) ("WARNING: " exp) 239 #ifndef __PRIS_PREFIX 240 # define __PRIS_PREFIX "z" 244 # define PRIdS __PRIS_PREFIX "d" 248 # define PRIxS __PRIS_PREFIX "x" 252 # define PRIuS __PRIS_PREFIX "u" 256 # define PRIXS __PRIS_PREFIX "X" 260 # define PRIoS __PRIS_PREFIX "o" 264 # define NLIB_ASSUME(cond) switch (0) case 0: default: if (cond) ; else __builtin_unreachable() 267 #ifdef NLIB_NONNULL_ENABLED 268 # define NLIB_EINVAL_IFNULL(p) 270 # define NLIB_EINVAL_IFNULL(p) if (!p) return EINVAL 273 #ifndef NLIB_C_INLINE 274 # define NLIB_C_INLINE __inline 286 #include <inttypes.h> 289 #ifdef __cpp_unicode_characters 310 #if defined(__cplusplus) && !defined(NLIB_DOXYGEN) 311 #if __cplusplus >= 201703L || (defined(_HAS_STD_BYTE) && _HAS_STD_BYTE != 0) 313 #elif __cplusplus >= 201103L || defined(_MSC_VER) 322 #if defined(__LP64__) && __LP64__ == 1 332 #ifndef NLIB_VIS_PUBLIC_ALT 333 #define NLIB_VIS_PUBLIC_ALT NLIB_VIS_PUBLIC 336 #ifndef NLIB_EXPIMP_TEMPLATE 337 # define NLIB_EXPIMP_TEMPLATE(x) NLIB_STATIC_ASSERT(sizeof(char) == 1) 367 #if defined(__INTELLISENSE__) 368 #define NLIB_ATOMIC_RELAXED (0) 369 #define NLIB_ATOMIC_ACQUIRE (1) 370 #define NLIB_ATOMIC_RELEASE (2) 371 #define NLIB_ATOMIC_ACQ_REL (3) 372 #define NLIB_ATOMIC_SEQ_CST (7) 378 int32_t val,
int memorder);
384 int success_memorder,
385 int failure_memorder);
413 int64_t desired,
int weak,
414 int success_memorder,
int failure_memorder);
441 int weak,
int success_memorder,
int failure_memorder);
449 #ifndef NLIB_TIMESPEC_HAS_NATIVE 468 #define NLIB_TO_TIMESPEC(tm, t) \ 469 (tm)->tv_sec = (time_t)((t) / (1000 * 10000)); \ 470 (tm)->tv_nsec = ((long)((t) % (1000 * 10000)) * 100) // NOLINT 472 #define NLIB_FROM_TIMESPEC(tm, t) \ 473 (t) = (nlib_time)((tm)->tv_sec) * (1000 * 10000) + ((tm)->tv_nsec / 100) 475 #define NLIB_TO_SEC_NSEC(sec, nsec, t) \ 476 (sec) = (int64_t)((t) / (1000 * 10000)); \ 477 (nsec) = ((uint32_t)((t) % (1000 * 10000)) * 100) 479 #define NLIB_FROM_SEC_NSEC(sec, nsec, t) \ 480 (t) = (nlib_time)(sec) * (1000 * 10000) + ((nsec) / 100) 486 NLIB_TO_TIMESPEC(tm, t);
494 NLIB_TO_TIMESPEC(tm, d);
500 NLIB_FROM_TIMESPEC(tm, d);
504 #if !defined(NLIB_TIMER_HAS_NATIVE) 506 #elif defined(_MSC_VER) 508 #elif defined(__linux__) 514 struct nlib_timerspec_ {
515 nlib_duration due_time;
516 nlib_duration interval;
518 typedef struct nlib_timerspec_ nlib_timerspec;
520 struct nlib_timerspec {
526 void* param, uint32_t flags);
528 nlib_timerspec* old_value);
533 #define NLIB_TIMER_SHORTTERM_TASK 0x00000001 534 #define NLIB_TIMER_LONGTERM_TASK 0x00000002 554 #define NLIB_PHYSICAL_ALLOC_PROT_NONE 0 555 #define NLIB_PHYSICAL_ALLOC_PROT_READ 1 556 #define NLIB_PHYSICAL_ALLOC_PROT_WRITE 2 557 #define NLIB_PHYSICAL_ALLOC_PROT_EXEC 4 563 #define NLIB_TLS_INVALID (nlib_tls)(-1) 566 #ifdef NLIB_PTHREAD_nlib_tls_alloc 584 #ifdef NLIB_PTHREAD_nlib_tls_alloc 587 return pthread_key_create(tls, destr);
589 errno_t e = pthread_key_create(tls, destr);
592 (void)pthread_setspecific(*tls, NULL);
598 #ifdef NLIB_PTHREAD_nlib_tls_free 600 return pthread_key_delete(tls);
605 #ifdef NLIB_PTHREAD_nlib_tls_setvalue 611 #ifdef NLIB_PTHREAD_nlib_tls_setvalue 613 return pthread_setspecific(tls, value);
617 #ifdef NLIB_PTHREAD_nlib_tls_getvalue 624 #ifdef NLIB_PTHREAD_nlib_tls_getvalue 626 *value = pthread_getspecific(tls);
635 #ifdef NLIB_PTHREAD_nlib_mutex_init 643 #ifdef NLIB_PTHREAD_nlib_mutex_init 645 return pthread_mutex_init(mutex, NULL);
651 NLIB_NONNULL NLIB_EXCLUDES(*mutex);
654 NLIB_NONNULL NLIB_EXCLUDES(*mutex);
656 #ifdef NLIB_PTHREAD_nlib_mutex_lock 669 #ifdef NLIB_PTHREAD_nlib_mutex_lock 671 return pthread_mutex_lock(mutex);
677 #ifdef NLIB_PTHREAD_nlib_mutex_trylock 683 #ifdef NLIB_PTHREAD_nlib_mutex_trylock 685 return pthread_mutex_trylock(mutex);
691 nlib_duration delta) NLIB_NONNULL NLIB_TRY_ACQUIRE(0, *mutex);
692 #ifdef NLIB_PTHREAD_nlib_mutex_unlock 698 #ifdef NLIB_PTHREAD_nlib_mutex_unlock 700 return pthread_mutex_unlock(mutex);
704 #ifdef NLIB_PTHREAD_nlib_mutex_destroy 711 #ifdef NLIB_PTHREAD_nlib_mutex_destroy 713 return pthread_mutex_destroy(mutex);
718 const struct timespec* tm)
719 NLIB_TRY_ACQUIRE(0, *mutex) {
721 NLIB_FROM_TIMESPEC(tm, delta);
744 nlib_duration duration;
745 NLIB_FROM_TIMESPEC(tm, duration);
753 #ifdef NLIB_PTHREAD_nlib_cond_init 761 #ifdef NLIB_PTHREAD_nlib_cond_init 763 return pthread_cond_init(cond, NULL);
767 #ifdef NLIB_PTHREAD_nlib_cond_signal 773 #ifdef NLIB_PTHREAD_nlib_cond_signal 775 return pthread_cond_signal(cond);
779 #ifdef NLIB_PTHREAD_nlib_cond_broadcast 785 #ifdef NLIB_PTHREAD_nlib_cond_broadcast 787 return pthread_cond_broadcast(cond);
791 #ifdef NLIB_PTHREAD_nlib_cond_wait 818 NLIB_NONNULL NLIB_REQUIRES(*mutex);
819 #ifdef NLIB_PTHREAD_nlib_cond_wait 822 return pthread_cond_wait(cond, mutex);
830 nlib_duration duration) NLIB_NONNULL NLIB_REQUIRES(*mutex);
835 nlib_time abstime) NLIB_NONNULL NLIB_REQUIRES(*mutex);
837 #ifdef NLIB_PTHREAD_nlib_cond_destroy 843 #ifdef NLIB_PTHREAD_nlib_cond_destroy 845 return pthread_cond_destroy(cond);
851 NLIB_REQUIRES(*mutex) {
853 NLIB_FROM_TIMESPEC(tm, d);
859 const struct timespec* tm) NLIB_REQUIRES(*mutex) {
861 NLIB_FROM_TIMESPEC(tm, d);
868 #ifndef NLIB_RWLOCK_HAS_NATIVE 869 struct nlib_rwlock_ {
874 NLIB_CAPABILITY(
"mutex")
877 #define NLIB_RWLOCK_INITIALIZER { \ 879 { NLIB_RECURSIVE_TIMED_MUTEX_INITIALIZER, NLIB_RECURSIVE_TIMED_MUTEX_INITIALIZER }, \ 880 NLIB_COND_INITIALIZER } 883 #ifdef NLIB_PTHREAD_nlib_rwlock_init 890 #ifdef NLIB_PTHREAD_nlib_rwlock_init 892 return pthread_rwlock_init(rwlock, NULL);
896 #ifdef NLIB_PTHREAD_nlib_rwlock_destroy 902 #ifdef NLIB_PTHREAD_nlib_rwlock_destroy 904 return pthread_rwlock_destroy(rwlock);
908 #ifdef NLIB_PTHREAD_nlib_rwlock_rdlock 914 #ifdef NLIB_PTHREAD_nlib_rwlock_rdlock 916 NLIB_NO_THREAD_SAFETY_ANALYSIS {
917 return pthread_rwlock_rdlock(rwlock);
921 #ifdef NLIB_PTHREAD_nlib_rwlock_tryrdlock 927 NLIB_NONNULL NLIB_TRY_ACQUIRE_SHARED(0, *rwlock);
928 #ifdef NLIB_PTHREAD_nlib_rwlock_tryrdlock 930 NLIB_NO_THREAD_SAFETY_ANALYSIS {
931 return pthread_rwlock_tryrdlock(rwlock);
937 NLIB_NONNULL NLIB_TRY_ACQUIRE_SHARED(0, *rwlock);
940 NLIB_NONNULL NLIB_TRY_ACQUIRE_SHARED(0, *rwlock);
942 #ifdef NLIB_PTHREAD_nlib_rwlock_rdunlock 948 NLIB_NONNULL NLIB_RELEASE_SHARED(*rwlock);
949 #ifdef NLIB_PTHREAD_nlib_rwlock_rdunlock 951 NLIB_NO_THREAD_SAFETY_ANALYSIS {
952 return pthread_rwlock_unlock(rwlock);
956 #ifdef NLIB_PTHREAD_nlib_rwlock_wrlock 962 #ifdef NLIB_PTHREAD_nlib_rwlock_wrlock 964 NLIB_NO_THREAD_SAFETY_ANALYSIS {
965 return pthread_rwlock_wrlock(rwlock);
969 #ifdef NLIB_PTHREAD_nlib_rwlock_trywrlock 975 #ifdef NLIB_PTHREAD_nlib_rwlock_trywrlock 977 NLIB_NO_THREAD_SAFETY_ANALYSIS {
978 return pthread_rwlock_trywrlock(rwlock);
984 NLIB_NONNULL NLIB_TRY_ACQUIRE(0, *rwlock);
987 NLIB_NONNULL NLIB_TRY_ACQUIRE(0, *rwlock);
989 #ifdef NLIB_PTHREAD_nlib_rwlock_wrunlock 995 #ifdef NLIB_PTHREAD_nlib_rwlock_wrunlock 997 NLIB_NO_THREAD_SAFETY_ANALYSIS {
998 return pthread_rwlock_unlock(rwlock);
1002 static NLIB_C_INLINE
1004 NLIB_TRY_ACQUIRE_SHARED(0, *rwlock) {
1006 NLIB_FROM_TIMESPEC(tm, d);
1010 static NLIB_C_INLINE
1012 NLIB_TRY_ACQUIRE_SHARED(0, *rwlock) {
1014 NLIB_FROM_TIMESPEC(tm, d);
1018 static NLIB_C_INLINE
1020 NLIB_TRY_ACQUIRE(0, *rwlock) {
1022 NLIB_FROM_TIMESPEC(tm, d);
1026 static NLIB_C_INLINE
1028 NLIB_TRY_ACQUIRE(0, *rwlock) {
1030 NLIB_FROM_TIMESPEC(tm, d);
1035 #if defined(_MSC_VER) && defined(NLIB_RWLOCK_HAS_NATIVE) 1036 typedef struct nlib_condrwlock_ {
1037 CONDITION_VARIABLE cond;
1039 #define NLIB_CONDRWLOCK_INITIALIZER { CONDITION_VARIABLE_INIT } 1041 typedef struct nlib_condrwlock_ {
1045 #define NLIB_CONDRWLOCK_INITIALIZER { NLIB_COND_INITIALIZER, NLIB_MUTEX_INITIALIZER } 1053 nlib_rwlock* __restrict rwlock,
1056 nlib_rwlock* __restrict rwlock,
1057 nlib_duration duration,
1060 nlib_rwlock* __restrict rwlock,
1065 nlib_rwlock* rwlock,
1066 const struct timespec* tm,
1069 NLIB_FROM_TIMESPEC(tm, d);
1074 nlib_rwlock* rwlock,
1075 const struct timespec* tm,
1078 NLIB_FROM_TIMESPEC(tm, d);
1085 #ifndef NLIB_BARRIER_HAS_NATIVE 1086 struct nlib_barrier_ {
1094 #ifdef NLIB_PTHREAD_nlib_barrier_init 1100 #ifdef NLIB_PTHREAD_nlib_barrier_init 1102 return pthread_barrier_init(barrier, NULL, count);
1106 #ifdef NLIB_PTHREAD_nlib_barrier_destroy 1112 #ifdef NLIB_PTHREAD_nlib_barrier_destroy 1114 return pthread_barrier_destroy(barrier);
1123 #ifndef NLIB_ONCE_HAS_NATIVE 1124 struct nlib_onceflag_ {
1128 #define NLIB_ONCE_INIT { 0 } 1137 #elif defined(_MSC_VER) 1139 #define NLIB_ONCE_INIT INIT_ONCE_STATIC_INIT 1142 #elif defined(__APPLE__) || defined(__FreeBSD__) 1144 #define NLIB_ONCE_INIT 0 1149 #define NLIB_ONCE_INIT PTHREAD_ONCE_INIT 1153 return pthread_once(flag, func);
1163 typedef struct nlib_mq_ {
1169 #define NLIB_MQ_BLOCK 0 1170 #define NLIB_MQ_NONBLOCK 1 1171 #define NLIB_MQ_LOCKFREE 2 1182 typedef struct nlib_mq_attr_ {
1212 #if defined(__x86_64__) || defined(__i386__) || defined(_M_IX86) || defined(_M_AMD64) 1214 #elif defined(__ARM_ACLE) 1221 #define NLIB_THREAD_INVALID (nlib_thread)(0) // NOLINT 1223 #ifndef NLIB_SPINLOCK_HAS_NATIVE 1227 #ifndef NLIB_THREAD_ATTR_HAS_NATIVE 1228 struct nlib_thread_attr_ {
1239 struct nlib_thread_attr_ {
1240 pthread_attr_t attr;
1257 #ifdef NLIB_PTHREAD_nlib_thread_join 1263 #ifdef NLIB_PTHREAD_nlib_thread_join 1265 return pthread_join(thread, NULL);
1269 #ifdef NLIB_PTHREAD_nlib_thread_detach 1275 #ifdef NLIB_PTHREAD_nlib_thread_detach 1277 return pthread_detach(thread);
1281 #ifdef NLIB_PTHREAD_nlib_thread_self 1287 #ifdef NLIB_PTHREAD_nlib_thread_self 1289 *thread = pthread_self();
1297 #ifdef NLIB_PTHREAD_nlib_thread_equal 1303 #ifdef NLIB_PTHREAD_nlib_thread_equal 1305 return pthread_equal(th1, th2);
1313 #ifdef NLIB_PTHREAD_nlib_thread_getname 1319 #ifdef NLIB_PTHREAD_nlib_thread_getname 1321 return pthread_getname_np(thread, name, len);
1346 void** __restrict stack_addr,
size_t* __restrict stack_size)
1350 #define NLIB_THREAD_ATTR_KEY_DETACHSTATE (1) 1351 #define NLIB_THREAD_ATTR_KEY_STACKSIZE (2) 1352 #define NLIB_THREAD_ATTR_KEY_PRIORITY (4) 1353 #define NLIB_THREAD_ATTR_KEY_AFFINITY (5) 1354 #define NLIB_THREAD_ATTR_KEY_EXPLICIT_SCHED (6) 1362 #ifndef NN_PLATFORM_CTR 1370 #elif defined(pthread_cleanup_push) 1371 # define nlib_thread_cleanup_push(fn, arg) pthread_cleanup_push(fn, arg) 1372 # define nlib_thread_cleanup_pop(exec) pthread_cleanup_pop(exec) 1373 #elif !defined(NN_PLATFORM_CTR) 1374 struct nlib_thread_cleanup_handler_ {
1375 void (*func)(
void*);
1377 struct nlib_thread_cleanup_handler_* next;
1379 #define nlib_thread_cleanup_push(fn, arg) switch (0) case 0: default: { \ 1380 struct nlib_thread_cleanup_handler_ _thread_cleanup_handler = { fn, arg, NULL }; \ 1381 nlib_thread_cleanup_push_(&_thread_cleanup_handler) 1382 #define nlib_thread_cleanup_pop(exec) nlib_thread_cleanup_pop_(exec); } 1384 NLIB_VIS_PUBLIC void nlib_thread_cleanup_push_(
struct nlib_thread_cleanup_handler_* handler);
1406 void*
const* __restrict buf,
size_t count)
NLIB_NONNULL;
1412 kNlibLogUnknown = 0,
1424 NLIB_LOG_UNKNOWN = kNlibLogUnknown,
1425 NLIB_LOG_DEAFULT = kNlibLogDefault,
1432 NLIB_LOG_SILENT = kNlibLogSilent,
1438 typedef enum nlib_log_key {
1439 kNlibLogAttrUnknown = 0,
1442 kNlibLogAttrMsvcTrace,
1446 NLIB_LOG_ATTR_UNKNOWN = kNlibLogAttrUnknown,
1447 NLIB_LOG_ATTR_STDOUT = kNlibLogAttrStdout,
1448 NLIB_LOG_ATTR_STDERR = kNlibLogAttrStderr,
1449 NLIB_LOG_ATTR_MSVC_TRACE = kNlibLogAttrMsvcTrace,
1450 NLIB_LOG_ATTR_SYSLOG = kNlibLogAttrSyslog,
1451 NLIB_LOG_ATTR_NLIB_FD = kNlibLogAttrNlibFd,
1452 NLIB_LOG_ATTR_MAX = kNlibLogAttrMax
1455 #ifndef NLIB_ATTRIBUTE_PRINTF 1456 # define NLIB_ATTRIBUTE_PRINTF(x, y) __attribute__((format(printf, x, y))) 1460 const char* __restrict fmt, ...)
1469 #ifndef NLIB_FD_O_RDONLY 1473 # define NLIB_FD_O_RDONLY O_RDONLY 1476 #ifndef NLIB_FD_O_WRONLY 1480 # define NLIB_FD_O_WRONLY O_WRONLY 1483 #ifndef NLIB_FD_O_RDWR 1487 # define NLIB_FD_O_RDWR O_RDWR 1490 #ifndef NLIB_FD_O_APPEND 1494 # define NLIB_FD_O_APPEND O_APPEND 1497 #ifndef NLIB_FD_O_CREAT 1501 # define NLIB_FD_O_CREAT O_CREAT 1504 #ifndef NLIB_FD_O_TRUNC 1508 # define NLIB_FD_O_TRUNC O_TRUNC 1511 #ifndef NLIB_FD_O_EXCL 1515 # define NLIB_FD_O_EXCL O_EXCL 1518 #ifndef NLIB_SEEK_SET 1522 # define NLIB_SEEK_SET SEEK_SET 1525 #ifndef NLIB_SEEK_CUR 1529 # define NLIB_SEEK_CUR SEEK_CUR 1537 #define NLIB_FD_INVALID (-1) 1544 errno_t nlib_fd_open(nlib_fd* fd,
const char* native_path,
unsigned int flags, ...) NLIB_NONNULL_1;
1553 errno_t nlib_fd_read(
size_t* __restrict result, nlib_fd fd,
void* __restrict buf,
size_t count)
1578 #if !defined(NLIB_IOVEC_HAS_NATIVE) 1579 struct nlib_fd_iovec_ {
1583 typedef struct nlib_fd_iovec_ nlib_fd_iovec;
1585 typedef struct iovec nlib_fd_iovec;
1588 errno_t nlib_fd_readv(
size_t* __restrict result, nlib_fd fd,
const nlib_fd_iovec* __restrict iov,
1603 unsigned int flags);
1607 errno_t nlib_rename(
const char* __restrict old_path,
const char* __restrict new_path);
1612 typedef struct nlib_dir_ nlib_dir;
1613 typedef struct nlib_dirent_ {
1634 uint64_t* __restrict free_bytes_available,
1635 uint64_t* __restrict total_bytes,
1636 uint64_t* __restrict total_free_bytes);
1642 struct nlib_fileid_ {
1643 #if defined(_MSC_VER) 1645 #elif defined(NLIB_UNIX) 1652 typedef struct nlib_fileid_ nlib_fileid;
1660 #if defined(_MSC_VER) || defined(NLIB_UNIX) 1661 #include "nn/nlib/Platform_socket.h" 1672 # warning Do not define EDQUOT. nlib may not work correctly. 1676 #ifndef NLIB_SKIP_ERRNO_DEFINE 1678 #if !defined(__CYGWIN__) && !defined(__linux__) && !defined(__FreeBSD__) && !defined(__NX__) 1679 #include "nn/nlib/Platform_errno.h" 1686 #ifndef NLIB_SPINLOCK_HAS_NATIVE 1687 #define NLIB_SPINLOCK_INITIALIZER (0) 1689 #ifndef NN_PLATFORM_CTR 1702 #if defined(__arm__) 1703 #if __has_builtin(__builtin_arm_ldrex) 1704 int R5 = __builtin_arm_ldrex(lock);
1706 int R5 = __ldrex(lock);
1709 #if __has_builtin(__builtin_arm_strex) 1710 if (__builtin_arm_strex(1, lock) == 0) {
1712 if (__strex(1, lock) == 0) {
1714 #if !defined(NN_PLATFORM_CTR) 1722 nlib_spinlock_lock_(lock);
1724 int32_t expected = 0;
1727 nlib_spinlock_lock_(lock);
1732 #if defined(__arm__) 1733 #if __has_builtin(__builtin_arm_ldrex) 1734 int R5 = __builtin_arm_ldrex(lock);
1736 int R5 = __ldrex(lock);
1739 #if __has_builtin(__builtin_arm_strex) 1740 if (__builtin_arm_strex(1, lock) == 0) {
1742 if (__strex(1, lock) == 0) {
1744 #if !defined(NN_PLATFORM_CTR) 1754 int32_t expected = 0;
1763 #if defined(NN_PLATFORM_CTR) 1766 int32_t expected = 1;
1770 nlib_spinlock_unlock_(lock);
1772 #if defined(__arm__) 1784 _Printf_format_string_
const char* __restrict fmt, va_list args)
1788 _Printf_format_string_
const char* __restrict fmt, ...)
1792 _Printf_format_string_
const char* __restrict fmt, va_list args)
1796 _Printf_format_string_
const char* __restrict fmt, ...)
1800 int nlib_printf(_Printf_format_string_
const char* fmt, ...)
1805 _Printf_format_string_
const wchar_t* __restrict fmt, va_list args)
1809 _Printf_format_string_
const wchar_t* __restrict fmt, ...)
1813 _Printf_format_string_
const wchar_t* __restrict fmt, va_list args)
1817 _Printf_format_string_
const wchar_t* __restrict fmt, ...)
NLIB_NONNULL_3;
1822 errno_t nlib_vsnprintf_fallback(
size_t* __restrict count,
char* __restrict buf,
size_t size,
1823 _Printf_format_string_
const char* __restrict fmt, va_list args)
1826 errno_t nlib_snprintf_fallback(
size_t* __restrict count,
char* __restrict buf,
1827 size_t size, _Printf_format_string_
const char* __restrict fmt, ...)
1830 errno_t nlib_vsnwprintf_fallback(
size_t* __restrict count,
wchar_t* __restrict buf,
size_t size,
1831 _Printf_format_string_
const wchar_t* __restrict fmt, va_list args)
1834 errno_t nlib_snwprintf_fallback(
size_t* __restrict count,
wchar_t* __restrict buf,
size_t size,
1835 _Printf_format_string_
const wchar_t* __restrict fmt, ...)
1843 static errno_t nlib_memcpy(
void* __restrict s1,
size_t s1max,
const void* __restrict s2,
size_t n)
1848 void*
nlib_memccpy(
void* __restrict dest,
size_t dest_size,
const void* __restrict src,
1851 #ifdef NLIB_LIBC_nlib_memcmp 1857 #ifdef NLIB_LIBC_nlib_memcmp 1858 static NLIB_C_INLINE
int nlib_memcmp(
const void* buf1,
const void* buf2,
size_t n) {
1859 return memcmp(buf1, buf2, n);
1863 NLIB_VIS_PUBLIC_ALT
const void*
nlib_memchr(
const void* s,
int c,
size_t n)
1865 NLIB_VIS_PUBLIC_ALT
const void*
nlib_memrchr(
const void* s,
int c,
size_t n)
1867 NLIB_VIS_PUBLIC_ALT
const void*
nlib_memchr_not(
const void* s,
int c,
size_t n)
1872 NLIB_VIS_PUBLIC_ALT
const void*
nlib_memchr_lt(
const void* s,
int c,
size_t n)
1874 NLIB_VIS_PUBLIC_ALT
const void*
nlib_memchr_gt(
const void* s,
int c,
size_t n)
1877 NLIB_VIS_PUBLIC_ALT
const void*
nlib_memchr_mb(
const void* s,
size_t n)
1880 const char* __restrict
set,
size_t n)
1883 const char* __restrict
set,
size_t n)
1888 const char*
nlib_skipws(
size_t* __restrict cnt_lf,
const char** __restrict last_lf,
1891 #ifdef NLIB_LIBC_nlib_strlen 1897 #ifdef NLIB_LIBC_nlib_strlen 1898 static NLIB_C_INLINE
size_t nlib_strlen(
const char* s) {
return strlen(s); }
1901 #ifdef NLIB_LIBC_nlib_strnlen 1907 #ifdef NLIB_LIBC_nlib_strnlen 1908 static NLIB_C_INLINE
size_t nlib_strnlen(
const char* s,
size_t maxsize) {
1909 #if defined(_MSC_VER) || defined(__STDC_LIB_EXT1__) 1910 return strnlen_s(s, maxsize);
1912 return strnlen(s, maxsize);
1917 #ifdef NLIB_LIBC_nlib_strcpy 1923 #ifdef NLIB_LIBC_nlib_strcpy 1924 static NLIB_C_INLINE
1926 #if defined(_MSC_VER) || defined(__STDC_LIB_EXT1__) 1927 return strcpy_s(s1, s1max, s2);
1934 #ifdef NLIB_LIBC_nlib_strncpy 1939 errno_t nlib_strncpy(
char* __restrict s1,
size_t s1max,
const char* __restrict s2,
size_t n)
1941 #ifdef NLIB_LIBC_nlib_strncpy 1942 static NLIB_C_INLINE
1943 errno_t nlib_strncpy(
char* __restrict s1,
size_t s1max,
const char* __restrict s2,
size_t n) {
1944 #if defined(_MSC_VER) || defined(__STDC_LIB_EXT1__) 1945 return strncpy_s(s1, s1max, s2, n);
1952 #ifdef NLIB_LIBC_nlib_strchr 1958 #ifdef NLIB_LIBC_nlib_strchr 1959 static NLIB_C_INLINE
const char*
nlib_strchr(
const char* s,
int c) {
return strchr(s, c); }
1962 #ifdef NLIB_LIBC_nlib_strrchr 1968 #ifdef NLIB_LIBC_nlib_strrchr 1969 static NLIB_C_INLINE
const char*
nlib_strrchr(
const char* s,
int c) {
return strrchr(s, c); }
1974 static NLIB_C_INLINE
const char* nlib_strchr_mb(
const char* s) {
1978 return (
const char*)p;
1984 #ifdef NLIB_LIBC_nlib_wcslen 1990 #ifdef NLIB_LIBC_nlib_wcslen 1991 static NLIB_C_INLINE
size_t nlib_wcslen(
const wchar_t* s) {
return wcslen(s); }
1994 #ifdef NLIB_LIBC_nlib_wcsnlen 2000 #ifdef NLIB_LIBC_nlib_wcsnlen 2001 static NLIB_C_INLINE
size_t nlib_wcsnlen(
const wchar_t* s,
size_t maxsize) {
2002 #if defined(_MSC_VER) || defined(__STDC_LIB_EXT1__) 2003 return wcsnlen_s(s, maxsize);
2005 return wcsnlen(s, maxsize);
2010 #ifdef NLIB_LIBC_nlib_wcscpy 2015 errno_t nlib_wcscpy(
wchar_t* __restrict s1,
size_t s1max,
const wchar_t* __restrict s2)
2017 #ifdef NLIB_LIBC_nlib_wcscpy 2018 static NLIB_C_INLINE
2019 errno_t nlib_wcscpy(
wchar_t* __restrict s1,
size_t s1max,
const wchar_t* __restrict s2) {
2020 #if defined(_MSC_VER) || defined(__STDC_LIB_EXT1__) 2021 return wcscpy_s(s1, s1max, s2);
2028 #ifdef NLIB_LIBC_nlib_wcsncpy 2033 errno_t nlib_wcsncpy(
wchar_t* __restrict s1,
size_t s1max,
const wchar_t* __restrict s2,
size_t n)
2035 #ifdef NLIB_LIBC_nlib_wcsncpy 2036 static NLIB_C_INLINE
2037 errno_t nlib_wcsncpy(
wchar_t* __restrict s1,
size_t s1max,
const wchar_t* __restrict s2,
size_t n) {
2038 #if defined(_MSC_VER) || defined(__STDC_LIB_EXT1__) 2039 return wcsncpy_s(s1, s1max, s2, n);
2082 static NLIB_C_INLINE
2083 errno_t nlib_strto_int8(int8_t* result,
const char* nptr,
char** endptr,
int base) {
2087 if (e != 0 && e != ERANGE)
return e;
2088 if (tmp > 127 || tmp < -128) {
2089 *result = tmp < 0 ? -128 : 127;
2092 *result = (int8_t)tmp;
2095 static NLIB_C_INLINE
2096 errno_t nlib_strto_int16(int16_t* result,
const char* nptr,
char** endptr,
int base) {
2100 if (e != 0 && e != ERANGE)
return e;
2101 if (tmp > 32767 || tmp < -32768) {
2102 *result = tmp < 0 ? -32768 : 32767;
2105 *result = (int16_t)tmp;
2108 static NLIB_C_INLINE
2109 errno_t nlib_strto_uint8(uint8_t* result,
const char* nptr,
char** endptr,
int base) {
2113 if (e != 0 && e != ERANGE)
return e;
2118 *result = (uint8_t)tmp;
2121 static NLIB_C_INLINE
2122 errno_t nlib_strto_uint16(uint16_t* result,
const char* nptr,
char** endptr,
int base) {
2126 if (e != 0 && e != ERANGE)
return e;
2131 *result = (uint16_t)tmp;
2136 const char* first,
const char* last,
int base);
2139 const char* first,
const char* last,
int base);
2142 const char* first,
const char* last,
int base);
2145 const char* first,
const char* last,
int base);
2148 const char* first,
const char* last,
int base);
2151 const char* first,
const char* last,
int base);
2154 const char* first,
const char* last,
int base);
2157 const char* first,
const char* last,
int base);
2160 const char* first,
const char* last);
2163 const char* first,
const char* last);
2174 const wchar_t* __restrict from,
size_t from_size)
2178 wchar_t* __restrict to,
size_t to_size,
2179 const nlib_utf8_t* __restrict from,
size_t from_size)
2186 size_t* __restrict supplementary_codepoint_count,
2187 size_t* __restrict len,
2191 size_t* __restrict supplementary_codepoint_count,
2192 size_t* __restrict from_read,
2234 const nlib_utf8_t* __restrict from,
size_t from_size)
2244 const nlib_utf8_t* __restrict from,
size_t from_size)
2248 size_t nlib_utf16len_(
const uint16_t* str)
NLIB_NONNULL;
2250 size_t nlib_utf16nlen_(
const uint16_t* str,
size_t maxsize)
NLIB_NONNULL;
2254 errno_t nlib_utf16ncpy_(uint16_t* s1,
size_t s1max,
const uint16_t* s2,
size_t n)
NLIB_NONNULL;
2257 return nlib_utf16len_((
const uint16_t*)str);
2261 return nlib_utf16nlen_((
const uint16_t*)str, maxsize);
2265 return nlib_utf16cpy_((uint16_t*)s1, s1max, (
const uint16_t*)s2);
2269 return nlib_utf16ncpy_((uint16_t*)s1, s1max, (
const uint16_t*)s2, n);
2273 size_t nlib_utf32len_(
const uint32_t* str)
NLIB_NONNULL;
2275 size_t nlib_utf32nlen_(
const uint32_t* str,
size_t maxsize)
NLIB_NONNULL;
2279 errno_t nlib_utf32ncpy_(uint32_t* s1,
size_t s1max,
const uint32_t* s2,
size_t n)
NLIB_NONNULL;
2282 return nlib_utf32len_((
const uint32_t*)str);
2286 return nlib_utf32nlen_((
const uint32_t*)str, maxsize);
2290 return nlib_utf32cpy_((uint32_t*)s1, s1max, (
const uint32_t*)s2);
2294 return nlib_utf32ncpy_((uint32_t*)s1, s1max, (
const uint32_t*)s2, n);
2302 return nlib_utf16cplen_ex_(count, NULL, (
const uint16_t*)str);
2306 return nlib_utf16cplen_ex_(count, len, (
const uint16_t*)str);
2311 #if defined(CAFE) || defined(NN_PLATFORM_CTR) 2313 return ((x & 0xFF) << 8) | ((x >> 8) & 0xFF);
2316 return (x << 24) | ((x & 0xFF00U) << 8) | ((x >> 8) & 0xFF00U) | (x >> 24);
2320 ((x & 0xFF00U) << 40) |
2321 ((x & 0xFF0000U) << 24) |
2322 ((x & 0xFF000000U) << 8) |
2323 ((x >> 8) & 0xFF000000U) |
2324 ((x >> 24) & 0xFF0000U) |
2325 ((x >> 40) & 0xFF00U) |
2328 #elif defined(_MSC_VER) 2356 NLIB_VIS_PUBLIC_ALT
void nlib_free(
void* ptr);
2379 # define NLIB_MEMCPY(a, b, c) memcpy((a), (b), (c)) 2382 #ifndef NLIB_MEMMOVE 2383 # define NLIB_MEMMOVE(a, b, c) memmove((a), (b), (c)) 2387 # define NLIB_MEMSET(a, b, c) memset((a), (b), (c)) 2407 return (
'0' <= ch && ch <=
'9') || (
'A' <= ch && ch <=
'Z') || (
'a' <= ch && ch <=
'z');
2410 return (
'A' <= ch && ch <=
'Z') || (
'a' <= ch && ch <=
'z');
2412 static NLIB_C_INLINE
int nlib_isblank(
int ch) {
return ch ==
' ' || ch ==
'\t'; }
2413 static NLIB_C_INLINE
int nlib_iscntrl(
int ch) {
return (ch >= 0 && ch <= 0x1F) || ch == 0x7F; }
2414 static NLIB_C_INLINE
int nlib_isdigit(
int ch) {
return (
'0' <= ch && ch <=
'9'); }
2415 static NLIB_C_INLINE
int nlib_isgraph(
int ch) {
return ch >= 0x21 && ch <= 0x7E; }
2416 static NLIB_C_INLINE
int nlib_islower(
int ch) {
return (ch >=
'a' && ch <=
'z'); }
2417 static NLIB_C_INLINE
int nlib_isprint(
int ch) {
return ch >= 0x20 && ch <= 0x7E; }
2418 static NLIB_C_INLINE
int nlib_ispunct(
int ch) {
return (ch >= 0x00 && ch <= 0x20) || ch == 0x7F; }
2420 return ((ch) ==
' ' || (ch) ==
'\t' || (ch) ==
'\n');
2422 static NLIB_C_INLINE
int nlib_isupper(
int ch) {
return (ch >=
'A' && ch <=
'Z'); }
2424 return (
unsigned int)(ch -
'0') < 10u ||
2425 (
unsigned int)((ch | 0x20) -
'a') < 6u;
2428 return (ch >=
'A' && ch <=
'Z') ? ch + (
'a' -
'A') : ch;
2431 return (ch >=
'a' && ch <=
'z') ? ch - (
'a' -
'A') : ch;
2436 static NLIB_C_INLINE
2438 #if defined(_MSC_VER) || defined(__STDC_LIB_EXT1__) 2439 return memcpy_s(s1, s1max, s2, n);
2441 #ifndef NLIB_NONNULL_ENABLED 2442 if (!s1 || !s2)
return ERANGE;
2445 NLIB_MEMSET(s1, 0, s1max);
2448 NLIB_MEMCPY(s1, s2, n);
2454 static NLIB_C_INLINE
2456 #if defined(_MSC_VER) || defined(__STDC_LIB_EXT1__) 2457 return memmove_s(s1, s1max, s2, n);
2459 #ifndef NLIB_NONNULL_ENABLED 2460 if (!s1 || !s2)
return ERANGE;
2462 if (s1max < n)
return ERANGE;
2463 NLIB_MEMMOVE(s1, s2, n);
2468 static NLIB_C_INLINE
2470 NLIB_EINVAL_IFNULL(buf);
2471 NLIB_MEMSET(buf, ch, n);
2478 #if defined(NLIB_SSE42) 2480 return _mm_popcnt_u32(x);
2483 return _mm_popcnt_u32(x);
2487 return (
int)_mm_popcnt_u64(x);
2489 uint32_t lo = (uint32_t)(x & 0xFFFFFFFFU);
2490 uint32_t hi = (uint32_t)((x >> 32) & 0xFFFFFFFFU);
2491 return _mm_popcnt_u32(lo) + _mm_popcnt_u32(hi);
2494 #elif defined(NLIB_NEON) 2496 uint8x8_t x0 = vcnt_u8(vreinterpret_u8_u64(vcreate_u64(x)));
2498 return vaddv_u8(x0);
2500 uint8x8_t x1 = vpadd_u8(x0, x0);
2501 return vget_lane_u8(x1, 0);
2505 uint8x8_t x0 = vcnt_u8(vreinterpret_u8_u64(vcreate_u64(x)));
2507 return vaddv_u8(x0);
2509 uint8x8_t x1 = vpadd_u8(x0, x0);
2510 uint8x8_t x2 = vpadd_u8(x1, x1);
2511 return vget_lane_u8(x2, 0);
2515 uint8x8_t x0 = vcnt_u8(vreinterpret_u8_u64(vcreate_u64(x)));
2517 return vaddv_u8(x0);
2519 uint8x8_t x1 = vpadd_u8(x0, x0);
2520 uint8x8_t x2 = vpadd_u8(x1, x1);
2521 uint8x8_t x3 = vpadd_u8(x2, x2);
2522 return vget_lane_u8(x3, 0);
2528 return _nlib_popcnt_array[(x >> 24) & 0xFF] + _nlib_popcnt_array[(x >> 16) & 0xFF] +
2529 _nlib_popcnt_array[(x >> 8) & 0xFF] + _nlib_popcnt_array[(x)& 0xFF];
2532 return _nlib_popcnt_array[(x >> 56) & 0xFF] + _nlib_popcnt_array[(x >> 48) & 0xFF] +
2533 _nlib_popcnt_array[(x >> 40) & 0xFF] + _nlib_popcnt_array[(x >> 32) & 0xFF] +
2534 _nlib_popcnt_array[(x >> 24) & 0xFF] + _nlib_popcnt_array[(x >> 16) & 0xFF] +
2535 _nlib_popcnt_array[(x >> 8) & 0xFF] + _nlib_popcnt_array[(x)& 0xFF];
2538 return _nlib_popcnt_array[(x >> 8) & 0xFF] + _nlib_popcnt_array[(x)& 0xFF];
2550 #if defined(_MSC_VER) 2553 return _BitScanReverse(&cnt, x) ? (int)(31 - cnt) : 32;
2558 return _BitScanForward(&cnt, x) ? cnt : 32;
2563 return _BitScanReverse64(&cnt, x) ? (int)(63 - cnt) : 64;
2567 DWORD dw = (DWORD)(x >> 32);
2568 if (_BitScanReverse(&cnt, dw)) {
2569 return (
int)(31 - cnt);
2572 return _BitScanReverse(&cnt, dw) ?
2573 (int)(63 - cnt) : 64;
2580 return _BitScanForward64(&cnt, x) ? cnt : 64;
2583 DWORD dw = (DWORD)(x);
2584 if (_BitScanForward(&cnt, dw)) {
2587 dw = (DWORD)(x >> 32);
2588 return _BitScanForward(&cnt, dw) ?
2589 (int)(32 + cnt) : 64;
2598 unsigned int dw = (
unsigned int)(x >> 32);
2603 dw = (
unsigned int)(x);
2609 #elif defined(NN_PLATFORM_CTR) 2621 static size_t nlib_strlcpy(
char* __restrict s1,
const char* __restrict s2,
size_t s1max)
2623 static NLIB_C_INLINE
2624 size_t nlib_strlcpy(
char* __restrict s1,
const char* __restrict s2,
size_t s1max) {
2625 #if defined(__FreeBSD__) 2626 return strlcpy(s1, s2, s1max);
2630 NLIB_MEMCPY(s1, s2, len + 1);
2632 NLIB_MEMCPY(s1, s2, s1max - 1);
2633 s1[s1max - 1] =
'\0';
2643 #if __has_builtin(__builtin_bitreverse32) 2644 return __builtin_bitreverse32(x);
2645 #elif __has_builtin(__builtin_arm_rbit) 2646 return __builtin_arm_rbit(x);
2647 #elif defined(__arm__) && !defined(NN_PLATFORM_CTR) 2650 x = ((x & 0x55555555U) << 1) | ((x >> 1) & 0x55555555U);
2651 x = ((x & 0x33333333U) << 2) | ((x >> 2) & 0x33333333U);
2652 x = ((x & 0x0F0F0F0FU) << 4) | ((x >> 4) & 0x0F0F0F0FU);
2654 x = _byteswap_ulong(x);
2655 #elif defined(CAFE) || defined(NN_PLATFORM_CTR) 2656 x = (x << 24) | ((x & 0xFF00) << 8) |
2657 ((x >> 8) & 0xFF00) | (x >> 24);
2659 x = __builtin_bswap32(x);
2666 #if __has_builtin(__builtin_bitreverse64) 2667 return __builtin_bitreverse64(x);
2668 #elif __has_builtin(__builtin_arm_rbit64) 2669 return __builtin_arm_rbit64(x);
2670 #elif __has_builtin(__builtin_arm_rbit) 2671 return __builtin_arm_rbit(x >> 32) |
2672 (((uint64_t)__builtin_arm_rbit(x)) << 32);
2673 #elif defined(__arm__) && !defined(NN_PLATFORM_CTR) 2674 return __rbit(x >> 32) |
2675 (((uint64_t)__rbit(x)) << 32);
2677 x = ((x & 0x5555555555555555ULL) << 1) | ((x >> 1) & 0x5555555555555555ULL);
2678 x = ((x & 0x3333333333333333ULL) << 2) | ((x >> 2) & 0x3333333333333333ULL);
2679 x = ((x & 0x0F0F0F0F0F0F0F0FULL) << 4) | ((x >> 4) & 0x0F0F0F0F0F0F0F0FULL);
2681 x = _byteswap_uint64(x);
2682 #elif defined(CAFE) || defined(NN_PLATFORM_CTR) 2685 ((x & 0xFF00U) << 40) |
2686 ((x & 0xFF0000U) << 24) |
2687 ((x & 0xFF000000U) << 8) |
2688 ((x >> 8) & 0xFF000000U) |
2689 ((x >> 24) & 0xFF0000U) |
2690 ((x >> 40) & 0xFF00U) |
2693 x = __builtin_bswap64(x);
2707 #if defined(_MSC_VER) 2708 #if defined(n_EXPORTS) 2709 #undef NLIB_VIS_PUBLIC 2710 #define NLIB_VIS_PUBLIC NLIB_WINIMPORT 2711 #elif defined(nx_misc_EXPORTS) 2712 # undef NLIB_VIS_PUBLIC 2713 # define NLIB_VIS_PUBLIC NLIB_WINEXPORT 2717 #endif // INCLUDE_NN_NLIB_PLATFORM_H_
メッセージキューの設定や現在の状態を格納する構造体です。