Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 0 additions & 25 deletions auto/clang
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,6 @@

# C language features.

njs_feature="GCC unsigned __int128"
njs_feature_name=NJS_HAVE_UNSIGNED_INT128
njs_feature_run=no
njs_feature_incs=
njs_feature_libs=
njs_feature_test="int main(void) {
unsigned __int128 p = 0;
return (int) p;
}"
. auto/feature


njs_feature="GCC __builtin_expect()"
njs_feature_name=NJS_HAVE_BUILTIN_EXPECT
njs_feature_run=no
Expand Down Expand Up @@ -203,16 +191,3 @@ njs_feature_test="#include <sanitizer/msan_interface.h>
return 0;
}"
. auto/feature


njs_feature="_mm_setcsr()"
njs_feature_name=NJS_HAVE_DENORMALS_CONTROL
njs_feature_run=no
njs_feature_incs=
njs_feature_libs=
njs_feature_test="#include <xmmintrin.h>
int main(void) {
_mm_setcsr(_mm_getcsr());
return 0;
}"
. auto/feature
3 changes: 0 additions & 3 deletions auto/sources
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
NJS_LIB_SRCS=" \
src/njs_diyfp.c \
src/njs_dtoa.c \
src/njs_dtoa_fixed.c \
src/njs_str.c \
src/njs_strtod.c \
src/njs_murmur_hash.c \
src/njs_djb_hash.c \
src/njs_utf8.c \
Expand Down
54 changes: 0 additions & 54 deletions auto/types
Original file line number Diff line number Diff line change
Expand Up @@ -118,57 +118,3 @@ njs_feature_test="#include <time.h>
return 0;
}"
. auto/feature


# Ensuring that double type is always evaluated at standard
# precision required by njs_diyfp_t


case $NJS_CC_NAME in

gcc)
NJS_CFLAGS="$NJS_CFLAGS -fexcess-precision=standard"
;;

clang)

njs_found=no

njs_feature="flag -ffp-eval-method=double"
njs_feature_name=NJS_HAVE_FP_EVAL_METHOD
njs_feature_run=no
njs_feature_incs="-ffp-eval-method=double"
njs_feature_libs=
njs_feature_test="int main(void) {
return 0;
}"

. auto/feature

if [ $njs_found = yes ]; then
NJS_CFLAGS="$NJS_CFLAGS -ffp-eval-method=double"
fi

;;

SunC)

njs_found=no

njs_feature="flag -xarch=sse2"
njs_feature_name=NJS_HAVE_XARCH_SSE2
njs_feature_run=no
njs_feature_incs="-xarch=sse2"
njs_feature_libs=
njs_feature_test="int main(void) {
return 0;
}"

. auto/feature

if [ $njs_found = yes ]; then
NJS_CFLAGS="$NJS_CFLAGS -xarch=sse2"
fi
;;

esac
8 changes: 0 additions & 8 deletions external/njs_shell.c
Original file line number Diff line number Diff line change
Expand Up @@ -412,8 +412,6 @@ njs_main(njs_opts_t *opts)
njs_int_t ret;
njs_engine_t *engine;

njs_mm_denormals(opts->denormals);

if (opts->file == NULL) {
if (opts->command.length != 0) {
opts->file = (char *) "string";
Expand Down Expand Up @@ -637,12 +635,6 @@ njs_options_parse(njs_opts_t *opts, int argc, char **argv)
return NJS_ERROR;

case 'f':

#if !(NJS_HAVE_DENORMALS_CONTROL)
njs_stderror("option \"-f\" is not supported\n");
return NJS_ERROR;
#endif

opts->denormals = 0;
break;

Expand Down
2 changes: 2 additions & 0 deletions src/njs.h
Original file line number Diff line number Diff line change
Expand Up @@ -312,11 +312,13 @@ NJS_EXPORT njs_vm_t *njs_vm_create(njs_vm_opt_t *options);
NJS_EXPORT void njs_vm_destroy(njs_vm_t *vm);
NJS_EXPORT njs_int_t njs_vm_call_exit_hook(njs_vm_t *vm);

/* Input must be null-terminated. */
NJS_EXPORT njs_int_t njs_vm_compile(njs_vm_t *vm, u_char **start, u_char *end);
NJS_EXPORT void njs_vm_set_module_loader(njs_vm_t *vm,
njs_module_loader_t module_loader, void *opaque);
NJS_EXPORT njs_mod_t *njs_vm_add_module(njs_vm_t *vm, njs_str_t *name,
njs_value_t *value);
/* Input must be null-terminated. */
NJS_EXPORT njs_mod_t *njs_vm_compile_module(njs_vm_t *vm, njs_str_t *name,
u_char **start, u_char *end);
NJS_EXPORT njs_int_t njs_vm_reuse(njs_vm_t *vm);
Expand Down
18 changes: 0 additions & 18 deletions src/njs_clang.h
Original file line number Diff line number Diff line change
Expand Up @@ -209,24 +209,6 @@ njs_unsafe_cast_double_to_int64(double num)
}


#if (NJS_HAVE_DENORMALS_CONTROL)
#include <xmmintrin.h>

/*
* 0x8000 Flush to zero
* 0x0040 Denormals are zeros
*/

#define NJS_MM_DENORMALS_MASK 0x8040

#define njs_mm_denormals(on) \
_mm_setcsr((_mm_getcsr() & ~NJS_MM_DENORMALS_MASK) | (!(on) ? 0x8040: 0x0))
#else

#define njs_mm_denormals(on)
#endif


#ifndef NJS_MAX_ALIGNMENT

#if (NJS_SOLARIS)
Expand Down
149 changes: 149 additions & 0 deletions src/njs_cutils.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
/*
* Selected C utilities adapted from QuickJS cutils.h
*
* Copyright (c) 2024 Fabrice Bellard
*/

#ifndef _NJS_CUTILS_H_INCLUDED_
#define _NJS_CUTILS_H_INCLUDED_

#include <stddef.h>
#include <stdint.h>

#ifndef likely
#define likely(x) __builtin_expect(!!(x), 1)
#endif

#ifndef unlikely
#define unlikely(x) __builtin_expect(!!(x), 0)
#endif

#ifndef no_inline
#define no_inline __attribute__((noinline))
#endif

/* compatibility attribute used in dtoa implementation */
#ifndef __maybe_unused
#define __maybe_unused __attribute__((unused))
#endif

typedef int BOOL;

#ifndef FALSE
#define FALSE 0
#endif

#ifndef TRUE
#define TRUE 1
#endif

static inline int
max_int(int a, int b)
{
return (a > b) ? a : b;
}

static inline int
min_int(int a, int b)
{
return (a < b) ? a : b;
}

static inline uint32_t
max_uint32(uint32_t a, uint32_t b)
{
return (a > b) ? a : b;
}

static inline uint32_t
min_uint32(uint32_t a, uint32_t b)
{
return (a < b) ? a : b;
}

static inline int64_t
max_int64(int64_t a, int64_t b)
{
return (a > b) ? a : b;
}

static inline int64_t
min_int64(int64_t a, int64_t b)
{
return (a < b) ? a : b;
}

/* WARNING: undefined if a = 0 */
static inline int
clz32(unsigned int a)
{
return __builtin_clz(a);
}

/* WARNING: undefined if a = 0 */
static inline int
clz64(uint64_t a)
{
return __builtin_clzll(a);
}

/* WARNING: undefined if a = 0 */
static inline int
ctz32(unsigned int a)
{
return __builtin_ctz(a);
}

/* WARNING: undefined if a = 0 */
static inline int
ctz64(uint64_t a)
{
return __builtin_ctzll(a);
}

static inline uint64_t
float64_as_uint64(double d)
{
union {
double d;
uint64_t u64;
} u;

u.d = d;
return u.u64;
}

static inline double
uint64_as_float64(uint64_t u64)
{
union {
double d;
uint64_t u64;
} u;

u.u64 = u64;
return u.d;
}

static inline int
strstart(const char *str, const char *val, const char **ptr)
{
const char *p = str;
const char *q = val;

while (*q != '\0') {
if (*p != *q) {
return 0;
}
p++;
q++;
}

if (ptr != NULL) {
*ptr = p;
}

return 1;
}

#endif /* _NJS_CUTILS_H_INCLUDED_ */
8 changes: 5 additions & 3 deletions src/njs_date.c
Original file line number Diff line number Diff line change
Expand Up @@ -1407,9 +1407,11 @@ njs_date_prototype_to_primitive(njs_vm_t *vm, njs_value_t *args,
}
}

ret = njs_atom_atomize_key(vm, &args[1]);
if (njs_slow_path(ret != NJS_OK)) {
return ret;
if (args[1].atom_id == NJS_ATOM_STRING_unknown) {
ret = njs_atom_atomize_key(vm, &args[1]);
if (njs_slow_path(ret != NJS_OK)) {
return ret;
}
}

switch (args[1].atom_id) {
Expand Down
Loading