extensions
Volodymyr Shymanskyy 5 years ago
parent 61e8eb03f2
commit b7663b255c

@ -44,32 +44,30 @@ const void * const cvptr_t;
# define or ||
# endif
#define M3_COUNT_OF(x) ((sizeof(x)/sizeof(0[x])) / ((size_t)(!(sizeof(x) % sizeof(0[x])))))
# if defined(M3_COMPILER_MSVC)
# define M3_WEAK
# else
# define M3_WEAK __attribute__((weak))
# endif
#define M3_INIT(field) memset(&field, 0, sizeof(field))
static const char * m3LogTruncFilename (const char * i_file)
{
const char * file = i_file + strlen (i_file);
while (true)
{
char c = * (file - 1);
if (c == '/' or c == '\\')
break;
# if defined(M3_COMPILER_MSVC)
# define UNLIKELY(x) (x)
# define LIKELY(x) (x)
# else
# define UNLIKELY(x) __builtin_expect(!!(x), 0)
# define LIKELY(x) __builtin_expect(!!(x), 1)
# endif
--file;
}
# ifndef min
# define min(A,B) (A < B) ? A : B
# endif
# ifndef max
# define max(A,B) (A > B) ? A : B
# endif
return file;
}
#define M3_INIT(field) memset(&field, 0, sizeof(field))
#define M3_COUNT_OF(x) ((sizeof(x)/sizeof(0[x])) / ((size_t)(!(sizeof(x) % sizeof(0[x])))))
# define d_m3Log_parse d_m3LogParse // required for m3logif
@ -79,8 +77,6 @@ static const char * m3LogTruncFilename (const char * i_file)
# if d_m3LogOutput
// with filename:
//# define d_m3Log(CATEGORY, FMT, ...) printf (" %-12s | %-8s | " FMT, m3LogTruncFilename (M3_FILE), #CATEGORY, ##__VA_ARGS__);
# define d_m3Log(CATEGORY, FMT, ...) printf (" %8s | " FMT, #CATEGORY, ##__VA_ARGS__);
# if d_m3LogParse
@ -196,8 +192,9 @@ M3CodePageHeader;
static const char * const c_waTypes [] = { "nil", "i32", "i64", "f32", "f64", "void", "void *" };
#define m3Alloc(OPTR, STRUCT, NUM) m3Malloc ((void **) OPTR, sizeof (STRUCT) * (NUM))
#define m3RellocArray(PTR, STRUCT, NEW, OLD) m3Realloc ((PTR), sizeof (STRUCT) * (NEW), sizeof (STRUCT) * (OLD))
#define m3Alloc(OPTR, STRUCT, NUM) m3Malloc ((void **) OPTR, sizeof (STRUCT) * (NUM))
#define m3RellocArray(PTR, STRUCT, NEW, OLD) m3Realloc ((PTR), sizeof (STRUCT) * (NEW), sizeof (STRUCT) * (OLD))
#define m3Free(P) { m3Free_impl((void*)(P)); P = NULL; }
#ifdef DEBUG
#define _m3Error(RESULT, RT, MOD, FUN, FILE, LINE, FORMAT, ...) m3Error (RESULT, RT, MOD, FUN, FILE, LINE, FORMAT, ##__VA_ARGS__)
@ -209,12 +206,6 @@ static const char * const c_waTypes [] = { "nil", "i32", "i64", "f3
#define ErrorCompile(RESULT, COMP, FORMAT, ...) _m3Error (RESULT, COMP->runtime, COMP->module, NULL, __FILE__, __LINE__, FORMAT, ##__VA_ARGS__)
//#define ErrorExec(RESULT, MODULE, FORMAT, ...) _m3Error (RESULT, COMP->runtime, COMP->module, NULL, __FILE__, __LINE__, FORMAT, ##__VA_ARGS__)
#ifndef min
#define min(A,B) (A < B) ? A : B
#endif
#ifndef max
#define max(A,B) (A > B) ? A : B
#endif
#if d_m3LogNativeStack
void m3StackCheckInit ();
@ -235,8 +226,6 @@ M3Result m3Malloc (void ** o_ptr, size_t i_size);
void * m3Realloc (void * i_ptr, size_t i_newSize, size_t i_oldSize);
void m3Free_impl (void * o_ptr);
#define m3Free(P) { m3Free_impl((void*)(P)); P = NULL; }
bool IsIntType (u8 i_wasmType);
bool IsFpType (u8 i_wasmType);
M3Result NormalizeType (u8 * o_type, i8 i_convolutedWasmType);
@ -261,12 +250,4 @@ size_t SPrintArg (char * o_string, size_t i_n, m3stack_t i_sp
void ReportError (IM3Runtime io_runtime, IM3Module i_module, IM3Function i_function, ccstr_t i_errorMessage, ccstr_t i_file, u32 i_lineNum);
//static __inline__ unsigned long GetCC(void)
//{
// unsigned a, d;
// asm volatile("rdtsc" : "=a" (a), "=d" (d));
// return ((unsigned long)a) | (((unsigned long)d) << 32);
//}
#endif

@ -51,22 +51,10 @@ int __builtin_clzll(unsigned long long x) {
#endif
#if defined(M3_COMPILER_MSVC)
#define UNLIKELY(x) (x)
#define LIKELY(x) (x)
#else
#define UNLIKELY(x) __builtin_expect(!!(x), 0)
#define LIKELY(x) __builtin_expect(!!(x), 1)
#endif
// TODO: not sure why, signbit is actually defined in math.h
#if defined(ESP8266)
#define signbit(__x) \
((sizeof(__x) == sizeof(float)) ? __signbitf(__x) : __signbitd(__x))
#define signbit(__x) \
((sizeof(__x) == sizeof(float)) ? __signbitf(__x) : __signbitd(__x))
#endif
/*
@ -206,23 +194,4 @@ f64 max_f64(f64 a, f64 b) {
return a > b ? a : b;
}
/*
* Nearest
*/
static inline
f32 nearest_f32(f32 a) {
if (UNLIKELY(a > 0.f and a <= 0.5f)) return 0.f; // TODO: Unneded?
if (UNLIKELY(a < 0.f and a >= -0.5f)) return -0.f;
return rintf(a);
}
static inline
f64 nearest_f64(f64 a) {
if (UNLIKELY(a > 0.0 and a <= 0.5)) return 0.0;
if (UNLIKELY(a < 0.0 and a >= -0.5)) return -0.0;
return rint(a);
}
#endif /* m3_math_utils_h */

Loading…
Cancel
Save