• source navigation  • diff markup  • identifier search  • freetext search  • 

Sources/ucode/lib/ffi/uc_def.h

  1 /*
  2 ** ucode common internal definitions.
  3 ** Copyright (C) 2005-2025 Mike Pall. See Copyright Notice in NOTICE.
  4 **
  5 ** Derived from LuaJIT's internal definitions.
  6 ** See NOTICE and ATTRIBUTION.md for complete attribution details.
  7 */
  8 
  9 #ifndef _UC_DEF_H
 10 #define _UC_DEF_H
 11 
 12 #include <stdint.h>
 13 #include <string.h>
 14 #include <stdlib.h>
 15 
 16 /* -- Target detection ---------------------------------------------------- */
 17 
 18 /* -- Arch-specific settings ---------------------------------------------- */
 19 
 20 #if defined(__i386__) || defined(__i386) || defined(__x86_64__) || defined(__x86_64)
 21 
 22 #define UC_TARGET_X86           1
 23 #define UC_TARGET_X86ORX64      1
 24 #if defined(__x86_64__) || defined(__x86_64)
 25 #define UC_TARGET_X64           1
 26 #endif
 27 
 28 #elif defined(__ppc__) || defined(__ppc) || defined(__PPC__) || defined(__PPC) || defined(__powerpc__) || defined(__powerpc) || defined(__POWERPC__) || defined(__POWERPC)
 29 
 30 #define UC_TARGET_PPC           1
 31 
 32 #endif
 33 
 34 /* -- Derived defines ----------------------------------------------------- */
 35 
 36 #if UINTPTR_MAX == 0xffffffffffffffffULL
 37 #define UC_64                   1
 38 #else
 39 #define UC_64                   0
 40 #endif
 41 
 42 #pragma pack(push, 8)
 43 typedef union TValue {
 44   uint64_t u64;
 45   double n;
 46   struct {
 47     uint32_t lo;
 48     uint32_t hi;
 49   } u32;
 50   int32_t i;
 51 } TValue;
 52 #pragma pack(pop)
 53 typedef const TValue cTValue;
 54 
 55 #define uc_num2int(n)   ((int32_t)(n))
 56 
 57 #define UC_STATIC_ASSERT(cond) \
 58   extern void uc_static_assert(int STATIC_ASSERTION_FAILED[(cond)?1:-1])
 59 
 60 #define uc_rol(x, n)    (((x)<<(n)) | ((x)>>(-(int)(n)&(8*sizeof(x)-1))))
 61 
 62 #if defined(__GNUC__) || defined(__clang__)
 63 
 64 #define UC_NORET                __attribute__((noreturn))
 65 #define UC_AINLINE              inline __attribute__((always_inline))
 66 #define UC_NOINLINE             __attribute__((noinline))
 67 
 68 #if defined(__ELF__) || defined(__MACH__)
 69 #define UC_NOAPI                extern __attribute__((visibility("hidden")))
 70 #endif
 71 
 72 #if defined(__i386__)
 73 #define UC_FASTCALL             __attribute__((fastcall))
 74 #endif
 75 
 76 #define UC_LIKELY(x)            __builtin_expect(!!(x), 1)
 77 #define UC_UNLIKELY(x)          __builtin_expect(!!(x), 0)
 78 
 79 #define uc_fls(x)               ((uint32_t)(__builtin_clz(x)^31))
 80 
 81 static UC_AINLINE uint64_t uc_num2u64(double n)
 82 {
 83 #if defined(__i386__) || defined(__x86_64__)
 84   int64_t i = (int64_t)n;
 85   if (i < 0) i = (int64_t)(n - 18446744073709551616.0);
 86   return (uint64_t)i;
 87 #else
 88   return (uint64_t)n;
 89 #endif
 90 }
 91 
 92 #ifndef UC_FASTCALL
 93 #define UC_FASTCALL
 94 #endif
 95 #ifndef UC_NORET
 96 #define UC_NORET
 97 #endif
 98 #ifndef UC_NOAPI
 99 #define UC_NOAPI        extern
100 #endif
101 #ifndef UC_LIKELY
102 #define UC_LIKELY(x)    (x)
103 #define UC_UNLIKELY(x)  (x)
104 #endif
105 
106 #ifdef LUA_USE_ASSERT
107 #define uc_assertG_(g, c, ...) \
108   ((c) ? (void)0 : uc_assert_fail((g), __FILE__, __LINE__, __func__, __VA_ARGS__))
109 #define uc_assertG(c, ...)      uc_assertG_(g, (c), __VA_ARGS__)
110 #define uc_assertX(c, ...)      uc_assertG_(NULL, (c), __VA_ARGS__)
111 #define check_exp(c, e)         (uc_assertX((c), #c), (e))
112 #else
113 #define uc_assertG_(g, c, ...)  ((void)0)
114 #define uc_assertG(c, ...)      ((void)g)
115 #define uc_assertX(c, ...)      ((void)0)
116 #define check_exp(c, e)         (e)
117 #endif
118 
119 #endif
120 
121 #endif
122 

This page was automatically generated by LXR 0.3.1.  •  OpenWrt