mem
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
|
||||

|
||||
|
||||
Cell is an actor-based scripting language for building concurrent applications. It combines a familiar JavaScript-like syntax with the actor model of computation.
|
||||
Cell is an actor-based scripting language for building concurrent applications. It combines a familiar C-like syntax with the actor model of computation, optimized for low memory usage and simplicity.
|
||||
|
||||
## Key Features
|
||||
|
||||
|
||||
93
fash.c
Normal file
93
fash.c
Normal file
@@ -0,0 +1,93 @@
|
||||
/*
|
||||
Fash64: Douglas Crockford (2017-02-02)
|
||||
64-bit hash that uses the high 64 bits of a 128-bit product for feedback.
|
||||
|
||||
Notes:
|
||||
- Requires a way to get the high half of a 64x64->128 multiply.
|
||||
- Uses __uint128_t when available; otherwise uses MSVC _umul128.
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
|
||||
typedef struct fash64_state {
|
||||
uint64_t result;
|
||||
uint64_t sum;
|
||||
} fash64_state;
|
||||
|
||||
enum {
|
||||
FASH64_PRIME_11 = 11111111111111111027ull,
|
||||
FASH64_PRIME_8 = 8888888888888888881ull,
|
||||
FASH64_PRIME_3 = 3333333333333333271ull
|
||||
};
|
||||
|
||||
static inline void fash64_mul_hi_lo(uint64_t a, uint64_t b, uint64_t *hi, uint64_t *lo)
|
||||
{
|
||||
#if defined(__SIZEOF_INT128__)
|
||||
__uint128_t p = (__uint128_t)a * (__uint128_t)b;
|
||||
*lo = (uint64_t)p;
|
||||
*hi = (uint64_t)(p >> 64);
|
||||
#elif defined(_MSC_VER) && defined(_M_X64)
|
||||
*lo = _umul128(a, b, hi);
|
||||
#else
|
||||
/* Portable fallback (no 128-bit type, no _umul128). */
|
||||
uint64_t a0 = (uint32_t)a;
|
||||
uint64_t a1 = a >> 32;
|
||||
uint64_t b0 = (uint32_t)b;
|
||||
uint64_t b1 = b >> 32;
|
||||
|
||||
uint64_t p00 = a0 * b0;
|
||||
uint64_t p01 = a0 * b1;
|
||||
uint64_t p10 = a1 * b0;
|
||||
uint64_t p11 = a1 * b1;
|
||||
|
||||
uint64_t mid = (p00 >> 32) + (uint32_t)p01 + (uint32_t)p10;
|
||||
*lo = (p00 & 0xffffffffull) | (mid << 32);
|
||||
*hi = p11 + (p01 >> 32) + (p10 >> 32) + (mid >> 32);
|
||||
#endif
|
||||
}
|
||||
|
||||
static inline void fash64_begin(fash64_state *s)
|
||||
{
|
||||
s->result = (uint64_t)FASH64_PRIME_8;
|
||||
s->sum = (uint64_t)FASH64_PRIME_3;
|
||||
}
|
||||
|
||||
static inline void fash64_word(fash64_state *s, uint64_t word)
|
||||
{
|
||||
uint64_t high, low;
|
||||
uint64_t mixed = s->result ^ word;
|
||||
|
||||
fash64_mul_hi_lo(mixed, (uint64_t)FASH64_PRIME_11, &high, &low);
|
||||
|
||||
s->sum += high;
|
||||
s->result = low ^ s->sum;
|
||||
}
|
||||
|
||||
static inline void fash64_block(fash64_state *s, const uint64_t *block, size_t word_count)
|
||||
{
|
||||
for (size_t i = 0; i < word_count; i++) fash64_word(s, block[i]);
|
||||
}
|
||||
|
||||
static inline uint64_t fash64_end(const fash64_state *s)
|
||||
{
|
||||
return s->result;
|
||||
}
|
||||
|
||||
/* Convenience one-shot helper */
|
||||
static inline uint64_t fash64_hash_words(const uint64_t *words, size_t word_count, uint64_t extra_word)
|
||||
{
|
||||
fash64_state s;
|
||||
fash64_begin(&s);
|
||||
fash64_block(&s, words, word_count);
|
||||
fash64_word(&s, extra_word);
|
||||
return fash64_end(&s);
|
||||
}
|
||||
|
||||
static inline uint64_t fash64_hash_one(uint64_t word)
|
||||
{
|
||||
uint64_t high, low;
|
||||
uint64_t mixed = (uint64_t)FASH64_PRIME_8 ^ word;
|
||||
fash64_mul_hi_lo(mixed, (uint64_t)FASH64_PRIME_11, &high, &low);
|
||||
return low ^ ((uint64_t)FASH64_PRIME_3 + high);
|
||||
}
|
||||
@@ -34,17 +34,12 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
#define js_likely(x) __builtin_expect(!!(x), 1)
|
||||
#define js_unlikely(x) __builtin_expect(!!(x), 0)
|
||||
#define js_force_inline inline __attribute__((always_inline))
|
||||
#define __js_printf_like(f, a) __attribute__((format(printf, f, a)))
|
||||
#else
|
||||
#define js_likely(x) (x)
|
||||
#define js_unlikely(x) (x)
|
||||
#define js_force_inline inline
|
||||
#define __js_printf_like(a, b)
|
||||
#endif
|
||||
|
||||
// #define BINARY16 // 16 bit word type (half)
|
||||
// #define BINARY32 // 32 bit word type (float)
|
||||
// #define BINARY64 // 64 bit word type (double)
|
||||
// #define DEC64 // 64 bit word type (dec)
|
||||
@@ -54,6 +49,8 @@ extern "C" {
|
||||
Half: 10 bits
|
||||
Float: 23 bits
|
||||
Double: 52 bits
|
||||
Dec16: 11 bits
|
||||
Dec32: 26 bits
|
||||
Dec64: 56 bits
|
||||
|
||||
On double builds, 48 bits
|
||||
@@ -105,10 +102,9 @@ static inline KeyId key_rec(uint32_t payload) { return (K_REC << KEY_KIND_SHIFT)
|
||||
|
||||
/*
|
||||
Mist tags:
|
||||
0: false
|
||||
1: true
|
||||
2: null
|
||||
4: object
|
||||
0: object
|
||||
1: special (null, true, false)
|
||||
2: number
|
||||
*/
|
||||
|
||||
enum {
|
||||
|
||||
Reference in New Issue
Block a user