shithub: femtolisp

ref: e68062e70197ebe7aded32ef48bf2aefac2c26b6
dir: /llt.h/

View raw version
#pragma once

#include "platform.h"
#include "utf8.h"
#include "ios.h"
#include "bitvector.h"

#include "htableh.inc"
HTPROT(ptrhash)

#ifdef __GNUC__
#define __unlikely(x) __builtin_expect(!!(x), 0)
#define __likely(x) __builtin_expect(!!(x), 1)
#else
#define __unlikely(x) (x)
#define __likely(x) (x)
#endif

#ifdef BOEHM_GC /* boehm GC allocator */
#include <gc.h>
#define LLT_ALLOC(n) GC_MALLOC(n)
#define LLT_REALLOC(p, n) GC_REALLOC((p), (n))
#define LLT_FREE(x) USED(x)
#else /* standard allocator */
#define LLT_ALLOC(n) malloc(n)
#define LLT_REALLOC(p, n) realloc((p), (n))
#define LLT_FREE(x) free(x)
#endif

#define bswap_16(x) (((x) & 0x00ff) << 8 | ((x) & 0xff00) >> 8)
#define bswap_32(x) \
    ((((x) & 0xff000000) >> 24) | (((x) & 0x00ff0000) >> 8) | \
    (((x) & 0x0000ff00) << 8) | (((x) & 0x000000ff) << 24))
#define bswap_64(x) \
    (uint64_t)bswap_32((x) & 0xffffffffULL)<<32 | \
    (uint64_t)bswap_32(((x)>>32) & 0xffffffffULL)

#define DBL_MAXINT (1LL<<53)
#define FLT_MAXINT (1<<24)
#define BIT63 0x8000000000000000ULL
#define BIT31 0x80000000UL

#ifdef BITS64
#define NBITS 64
#define TOP_BIT BIT63
typedef uint64_t lltuint_t;
typedef int64_t lltint_t;
#else
#define NBITS 32
#define TOP_BIT BIT31
typedef uint32_t lltuint_t;
typedef int32_t lltint_t;
#endif

#define LOG2_10 3.3219280948873626
#define rel_zero(a, b) (fabs((a)/(b)) < DBL_EPSILON)
#define LABS(n) (((n)^((n)>>(NBITS-1))) - ((n)>>(NBITS-1)))
#define NBABS(n, nb) (((n)^((n)>>((nb)-1))) - ((n)>>((nb)-1)))
#define LLT_ALIGN(x, sz) (((x) + (sz-1)) & (-sz))

// a mask with n set lo or hi bits
#define lomask(n) (uint32_t)((((uint32_t)1)<<(n))-1)

extern double D_PNAN, D_NNAN, D_PINF, D_NINF;
extern float F_PNAN, F_NNAN, F_PINF, F_NINF;

char *uint2str(char *dest, size_t len, uint64_t num, uint32_t base);
int isdigit_base(char c, int base);
void llt_init(void);

int flmain(const char *boot, int bootsz, int argc, char **argv);