Skip to content

Commit

Permalink
Merge commit '52df41a709917bc8d55a5fe8d9848d15ed3941e4'
Browse files Browse the repository at this point in the history
  • Loading branch information
LukeUsher committed Nov 14, 2023
2 parents df8d5a6 + 52df41a commit dc385db
Show file tree
Hide file tree
Showing 21 changed files with 2,512 additions and 1,473 deletions.
5 changes: 5 additions & 0 deletions thirdparty/sljit/API_CHANGES
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
This file is the short summary of the API changes:

01.11.2023 - Non-backward compatible
The SLJIT_ARG_TYPE_VOID definition is changed
to SLJIT_ARG_TYPE_RET_VOID to improve Windows
compatibility.

05.9.2023 - Non-backward compatible
Turn SLJIT_IMM from a flag to a single value.

Expand Down
34 changes: 23 additions & 11 deletions thirdparty/sljit/GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,20 @@ ifndef EXTRA_LDFLAGS
EXTRA_LDFLAGS=
endif

ifndef EXTRA_LIBS
EXTRA_LIBS=
endif

ifndef OPT_FLAGS
OPT_FLAGS = -O2
endif

ifndef WERROR
WERROR = -Werror
endif

CPPFLAGS = $(EXTRA_CPPFLAGS) -Isljit_src
CFLAGS += -O2 -Wall -Wextra -Wconversion -Wsign-compare -Werror
CFLAGS += $(OPT_FLAGS) -Wall -Wextra -Wconversion -Wsign-compare -Wdeclaration-after-statement $(WERROR)
REGEX_CFLAGS += $(CFLAGS) -fshort-wchar
LDFLAGS = $(EXTRA_LDFLAGS)

Expand Down Expand Up @@ -67,33 +79,33 @@ $(BINDIR)/regexJIT.o : $(REGEXDIR)/regexJIT.c $(BINDIR)/.keep $(SLJIT_HEADERS) $
$(CC) $(CPPFLAGS) $(REGEX_CFLAGS) -c -o $@ $(REGEXDIR)/regexJIT.c

$(BINDIR)/sljit_test: $(BINDIR)/.keep $(BINDIR)/sljitMain.o $(TESTDIR)/sljitTest.c $(SRCDIR)/sljitLir.c $(SLJIT_LIR_FILES) $(SLJIT_HEADERS) $(TESTDIR)/sljitConfigPre.h $(TESTDIR)/sljitConfigPost.h
$(CC) $(CPPFLAGS) -DSLJIT_HAVE_CONFIG_PRE=1 -I$(TESTDIR) $(CFLAGS) $(LDFLAGS) $(BINDIR)/sljitMain.o $(TESTDIR)/sljitTest.c $(SRCDIR)/sljitLir.c -o $@ -lm -lpthread
$(CC) $(CPPFLAGS) -DSLJIT_HAVE_CONFIG_PRE=1 -I$(TESTDIR) $(CFLAGS) $(LDFLAGS) $(BINDIR)/sljitMain.o $(TESTDIR)/sljitTest.c $(SRCDIR)/sljitLir.c -o $@ -lm -lpthread $(EXTRA_LIBS)

$(BINDIR)/regex_test: $(BINDIR)/.keep $(BINDIR)/regexMain.o $(BINDIR)/regexJIT.o $(BINDIR)/sljitLir.o
$(CC) $(CFLAGS) $(LDFLAGS) $(BINDIR)/regexMain.o $(BINDIR)/regexJIT.o $(BINDIR)/sljitLir.o -o $@ -lm -lpthread
$(CC) $(CFLAGS) $(LDFLAGS) $(BINDIR)/regexMain.o $(BINDIR)/regexJIT.o $(BINDIR)/sljitLir.o -o $@ -lm -lpthread $(EXTRA_LIBS)

examples: $(EXAMPLE_TARGET)

$(BINDIR)/first_program: $(EXAMPLEDIR)/first_program.c $(BINDIR)/.keep $(BINDIR)/sljitLir.o
$(CC) $(CPPFLAGS) $(LDFLAGS) $(EXAMPLEDIR)/first_program.c $(BINDIR)/sljitLir.o -o $@ -lm -lpthread
$(CC) $(CPPFLAGS) $(LDFLAGS) $(EXAMPLEDIR)/first_program.c $(BINDIR)/sljitLir.o -o $@ -lm -lpthread $(EXTRA_LIBS)

$(BINDIR)/branch: $(EXAMPLEDIR)/branch.c $(BINDIR)/.keep $(BINDIR)/sljitLir.o
$(CC) $(CPPFLAGS) $(LDFLAGS) $(EXAMPLEDIR)/branch.c $(BINDIR)/sljitLir.o -o $@ -lm -lpthread
$(CC) $(CPPFLAGS) $(LDFLAGS) $(EXAMPLEDIR)/branch.c $(BINDIR)/sljitLir.o -o $@ -lm -lpthread $(EXTRA_LIBS)

$(BINDIR)/loop: $(EXAMPLEDIR)/loop.c $(BINDIR)/.keep $(BINDIR)/sljitLir.o
$(CC) $(CPPFLAGS) $(LDFLAGS) $(EXAMPLEDIR)/loop.c $(BINDIR)/sljitLir.o -o $@ -lm -lpthread
$(CC) $(CPPFLAGS) $(LDFLAGS) $(EXAMPLEDIR)/loop.c $(BINDIR)/sljitLir.o -o $@ -lm -lpthread $(EXTRA_LIBS)

$(BINDIR)/array_access: $(EXAMPLEDIR)/array_access.c $(BINDIR)/.keep $(BINDIR)/sljitLir.o
$(CC) $(CPPFLAGS) $(LDFLAGS) $(EXAMPLEDIR)/array_access.c $(BINDIR)/sljitLir.o -o $@ -lm -lpthread
$(CC) $(CPPFLAGS) $(LDFLAGS) $(EXAMPLEDIR)/array_access.c $(BINDIR)/sljitLir.o -o $@ -lm -lpthread $(EXTRA_LIBS)

$(BINDIR)/func_call: $(EXAMPLEDIR)/func_call.c $(BINDIR)/.keep $(BINDIR)/sljitLir.o
$(CC) $(CPPFLAGS) $(LDFLAGS) $(EXAMPLEDIR)/func_call.c $(BINDIR)/sljitLir.o -o $@ -lm -lpthread
$(CC) $(CPPFLAGS) $(LDFLAGS) $(EXAMPLEDIR)/func_call.c $(BINDIR)/sljitLir.o -o $@ -lm -lpthread $(EXTRA_LIBS)

$(BINDIR)/struct_access: $(EXAMPLEDIR)/struct_access.c $(BINDIR)/.keep $(BINDIR)/sljitLir.o
$(CC) $(CPPFLAGS) $(LDFLAGS) $(EXAMPLEDIR)/struct_access.c $(BINDIR)/sljitLir.o -o $@ -lm -lpthread
$(CC) $(CPPFLAGS) $(LDFLAGS) $(EXAMPLEDIR)/struct_access.c $(BINDIR)/sljitLir.o -o $@ -lm -lpthread $(EXTRA_LIBS)

$(BINDIR)/temp_var: $(EXAMPLEDIR)/temp_var.c $(BINDIR)/.keep $(BINDIR)/sljitLir.o
$(CC) $(CPPFLAGS) $(LDFLAGS) $(EXAMPLEDIR)/temp_var.c $(BINDIR)/sljitLir.o -o $@ -lm -lpthread
$(CC) $(CPPFLAGS) $(LDFLAGS) $(EXAMPLEDIR)/temp_var.c $(BINDIR)/sljitLir.o -o $@ -lm -lpthread $(EXTRA_LIBS)

$(BINDIR)/brainfuck: $(EXAMPLEDIR)/brainfuck.c $(BINDIR)/.keep $(BINDIR)/sljitLir.o
$(CC) $(CPPFLAGS) $(LDFLAGS) $(EXAMPLEDIR)/brainfuck.c $(BINDIR)/sljitLir.o -o $@ -lm -lpthread
$(CC) $(CPPFLAGS) $(LDFLAGS) $(EXAMPLEDIR)/brainfuck.c $(BINDIR)/sljitLir.o -o $@ -lm -lpthread $(EXTRA_LIBS)
8 changes: 4 additions & 4 deletions thirdparty/sljit/doc/tutorial/sljit_tutorial.html
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ <h2>First program</h2>
func3_t func;<br>
<br>
/* Create a SLJIT compiler */<br>
struct sljit_compiler *C = sljit_create_compiler();<br>
struct sljit_compiler *C = sljit_create_compiler(NULL, NULL);<br>
<br>
/* Start a context(function entry), has 3 arguments, discuss later */<br>
sljit_emit_enter(C, 0, SLJIT_ARGS3(W, W, W, W), 1, 3, 0, 0, 0);<br>
Expand Down Expand Up @@ -121,7 +121,7 @@ <h2>First program</h2>
<br>
/* Clean up */<br>
sljit_free_compiler(C);<br>
sljit_free_code(code);<br>
sljit_free_code(code, NULL);<br>
return 0;<br>
</ul>
}<br>
Expand Down Expand Up @@ -212,7 +212,7 @@ <h2>Branch</h2>
struct sljit_jump *out;<br>
<br>
/* Create a SLJIT compiler */<br>
struct sljit_compiler *C = sljit_create_compiler();<br>
struct sljit_compiler *C = sljit_create_compiler(NULL, NULL);<br>
<br>
/* 3 arg, 1 temp reg, 3 save reg */<br>
sljit_emit_enter(C, 0, SLJIT_ARGS3(W, W, W, W), 1, 3, 0, 0, 0);<br>
Expand Down Expand Up @@ -253,7 +253,7 @@ <h2>Branch</h2>
<br>
/* Clean up */<br>
sljit_free_compiler(C);<br>
sljit_free_code(code);<br>
sljit_free_code(code, NULL);<br>
return 0;<br>
</ul>
}<br>
Expand Down
2 changes: 1 addition & 1 deletion thirdparty/sljit/regex_src/regexJIT.c
Original file line number Diff line number Diff line change
Expand Up @@ -1966,7 +1966,7 @@ struct regex_machine* regex_compile(const regex_char_t *regex_string, int length
}

/* Step 4.1: Generate entry. */
CHECK(sljit_emit_enter(compiler_common.compiler, 0, SLJIT_ARGS3(VOID, P, P, 32), 5, 5, 0, 0, 0));
CHECK(sljit_emit_enter(compiler_common.compiler, 0, SLJIT_ARGS3V(P, P, 32), 5, 5, 0, 0, 0));

/* Copy arguments to their place. */
EMIT_OP1(SLJIT_MOV, R_REGEX_MATCH, 0, SLJIT_S0, 0);
Expand Down
32 changes: 24 additions & 8 deletions thirdparty/sljit/sljit_src/allocator_src/sljitExecAllocatorApple.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,18 @@
On non-macOS systems, returns MAP_JIT if it is defined.
*/
#include <TargetConditionals.h>
#if TARGET_OS_OSX
#if defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86

#if (defined(TARGET_OS_OSX) && TARGET_OS_OSX) || (TARGET_OS_MAC && !TARGET_OS_IPHONE)

#if defined(SLJIT_CONFIG_X86) && SLJIT_CONFIG_X86

#include <sys/utsname.h>
#include <stdlib.h>

#define SLJIT_MAP_JIT (get_map_jit_flag())
#define SLJIT_UPDATE_WX_FLAGS(from, to, enable_exec)

static SLJIT_INLINE int get_map_jit_flag()
static SLJIT_INLINE int get_map_jit_flag(void)
{
size_t page_size;
void *ptr;
Expand All @@ -67,10 +70,8 @@ static SLJIT_INLINE int get_map_jit_flag()
}
return map_jit_flag;
}
#else /* !SLJIT_CONFIG_X86 */
#if !(defined SLJIT_CONFIG_ARM && SLJIT_CONFIG_ARM)
#error "Unsupported architecture"
#endif /* SLJIT_CONFIG_ARM */

#elif defined(SLJIT_CONFIG_ARM) && SLJIT_CONFIG_ARM

#include <AvailabilityMacros.h>
#include <pthread.h>
Expand All @@ -86,9 +87,24 @@ static SLJIT_INLINE void apple_update_wx_flags(sljit_s32 enable_exec)
#endif /* BigSur */
pthread_jit_write_protect_np(enable_exec);
}
#endif /* SLJIT_CONFIG_X86 */

#elif defined(SLJIT_CONFIG_PPC) && SLJIT_CONFIG_PPC

#define SLJIT_MAP_JIT (0)
#define SLJIT_UPDATE_WX_FLAGS(from, to, enable_exec)

#else
#error "Unsupported architecture"
#endif /* SLJIT_CONFIG */

#else /* !TARGET_OS_OSX */

#ifdef MAP_JIT
#define SLJIT_MAP_JIT (MAP_JIT)
#else
#define SLJIT_MAP_JIT (0)
#endif

#endif /* TARGET_OS_OSX */

static SLJIT_INLINE void* alloc_chunk(sljit_uw size)
Expand Down
8 changes: 5 additions & 3 deletions thirdparty/sljit/sljit_src/sljitConfigInternal.h
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,10 @@ extern "C" {
/* Instruction cache flush. */
/****************************/

#ifdef __APPLE__
#include <AvailabilityMacros.h>
#endif

/*
* TODO:
*
Expand Down Expand Up @@ -243,9 +247,7 @@ extern "C" {
/* Not required to implement on archs with unified caches. */
#define SLJIT_CACHE_FLUSH(from, to)

#elif defined __APPLE__ && \
defined __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ && \
__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ >= 1050
#elif defined(__APPLE__) && MAC_OS_X_VERSION_MIN_REQUIRED >= 1050

/* Supported by all macs since Mac OS 10.5.
However, it does not work on non-jailbroken iOS devices,
Expand Down
72 changes: 54 additions & 18 deletions thirdparty/sljit/sljit_src/sljitLir.c
Original file line number Diff line number Diff line change
Expand Up @@ -1301,7 +1301,7 @@ static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_return_void(struct sljit_
}

#if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
CHECK_ARGUMENT(compiler->last_return == SLJIT_ARG_TYPE_VOID);
CHECK_ARGUMENT(compiler->last_return == SLJIT_ARG_TYPE_RET_VOID);
#endif

#if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
Expand Down Expand Up @@ -1449,13 +1449,6 @@ static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_op1(struct sljit_compiler
CHECK_RETURN_OK;
}

/* experimental API, only implemented for: */

#if (defined(SLJIT_CONFIG_X86) && SLJIT_CONFIG_X86) \
|| (defined(SLJIT_CONFIG_ARM) && SLJIT_CONFIG_ARM) \
|| (defined(SLJIT_CONFIG_S390X) && SLJIT_CONFIG_S390X) \
|| (defined(SLJIT_CONFIG_LOONGARCH) && SLJIT_CONFIG_LOONGARCH)

static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_atomic_load(struct sljit_compiler *compiler, sljit_s32 op,
sljit_s32 dst_reg,
sljit_s32 mem_reg)
Expand All @@ -1466,6 +1459,7 @@ static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_atomic_load(struct sljit_
}

#if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
CHECK_ARGUMENT(sljit_has_cpu_feature(SLJIT_HAS_ATOMIC));
CHECK_ARGUMENT(GET_OPCODE(op) >= SLJIT_MOV && GET_OPCODE(op) <= SLJIT_MOV_P);
CHECK_ARGUMENT(GET_OPCODE(op) != SLJIT_MOV_S8 && GET_OPCODE(op) != SLJIT_MOV_S16 && GET_OPCODE(op) != SLJIT_MOV_S32);

Expand Down Expand Up @@ -1507,6 +1501,7 @@ static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_atomic_store(struct sljit
}

#if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
CHECK_ARGUMENT(sljit_has_cpu_feature(SLJIT_HAS_ATOMIC));
CHECK_ARGUMENT(GET_OPCODE(op) >= SLJIT_MOV && GET_OPCODE(op) <= SLJIT_MOV_P);
CHECK_ARGUMENT(GET_OPCODE(op) != SLJIT_MOV_S8 && GET_OPCODE(op) != SLJIT_MOV_S16 && GET_OPCODE(op) != SLJIT_MOV_S32);

Expand All @@ -1518,7 +1513,7 @@ static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_atomic_store(struct sljit
CHECK_ARGUMENT(!(op & VARIABLE_FLAG_MASK) || GET_FLAG_TYPE(op) == SLJIT_ATOMIC_STORED);

if (GET_OPCODE(op) == SLJIT_MOV_U8 || GET_OPCODE(op) == SLJIT_MOV_U16) {
/* Only SLJIT_32, SLJIT_ATOMIC_STORED is allowed. */
/* Only SLJIT_32, SLJIT_ATOMIC_STORED are allowed. */
CHECK_ARGUMENT(!(op & SLJIT_SET_Z));
} else {
/* Only SLJIT_ATOMIC_STORED is allowed. */
Expand All @@ -1542,8 +1537,6 @@ static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_atomic_store(struct sljit
CHECK_RETURN_OK;
}

#endif /* !SLJIT_CONFIG_PPC && !SLJIT_CONFIG_MIPS && !SLJIT_CONFIG_RISCV */

static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_op2(struct sljit_compiler *compiler, sljit_s32 op, sljit_s32 unset,
sljit_s32 dst, sljit_sw dstw,
sljit_s32 src1, sljit_sw src1w,
Expand Down Expand Up @@ -2386,14 +2379,16 @@ static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_mem(struct sljit_compiler
sljit_s32 reg,
sljit_s32 mem, sljit_sw memw)
{
#if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
sljit_s32 allowed_flags;
#endif /* SLJIT_ARGUMENT_CHECKS */

if (SLJIT_UNLIKELY(compiler->skip_checks)) {
compiler->skip_checks = 0;
CHECK_RETURN_OK;
}

#if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
sljit_s32 allowed_flags;

if (type & SLJIT_MEM_UNALIGNED) {
CHECK_ARGUMENT(!(type & (SLJIT_MEM_ALIGNED_16 | SLJIT_MEM_ALIGNED_32)));
} else if (type & SLJIT_MEM_ALIGNED_16) {
Expand All @@ -2405,14 +2400,14 @@ static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_mem(struct sljit_compiler
allowed_flags = SLJIT_MEM_UNALIGNED;

switch (type & 0xff) {
case SLJIT_MOV_P:
case SLJIT_MOV:
allowed_flags |= SLJIT_MEM_ALIGNED_32;
/* fallthrough */
case SLJIT_MOV_U32:
case SLJIT_MOV_S32:
case SLJIT_MOV32:
allowed_flags = SLJIT_MEM_UNALIGNED | SLJIT_MEM_ALIGNED_16;
break;
case SLJIT_MOV:
case SLJIT_MOV_P:
allowed_flags = SLJIT_MEM_UNALIGNED | SLJIT_MEM_ALIGNED_16 | SLJIT_MEM_ALIGNED_32;
allowed_flags |= SLJIT_MEM_ALIGNED_16;
break;
}

Expand Down Expand Up @@ -3332,6 +3327,47 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_simd_sign(struct sljit_compiler *c

#endif /* !SLJIT_CONFIG_X86 && !SLJIT_CONFIG_ARM */

#if !(defined(SLJIT_CONFIG_X86) && SLJIT_CONFIG_X86) \
&& !(defined(SLJIT_CONFIG_ARM) && SLJIT_CONFIG_ARM) \
&& !(defined(SLJIT_CONFIG_S390X) && SLJIT_CONFIG_S390X) \
&& !(defined(SLJIT_CONFIG_LOONGARCH) && SLJIT_CONFIG_LOONGARCH)

SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_atomic_load(struct sljit_compiler *compiler,
sljit_s32 op,
sljit_s32 dst_reg,
sljit_s32 mem_reg)
{
SLJIT_UNUSED_ARG(compiler);
SLJIT_UNUSED_ARG(op);
SLJIT_UNUSED_ARG(dst_reg);
SLJIT_UNUSED_ARG(mem_reg);

CHECK_ERROR();
CHECK(check_sljit_emit_atomic_load(compiler, op, dst_reg, mem_reg));

return SLJIT_ERR_UNSUPPORTED;
}

SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_atomic_store(struct sljit_compiler *compiler,
sljit_s32 op,
sljit_s32 src_reg,
sljit_s32 mem_reg,
sljit_s32 temp_reg)
{
SLJIT_UNUSED_ARG(compiler);
SLJIT_UNUSED_ARG(op);
SLJIT_UNUSED_ARG(src_reg);
SLJIT_UNUSED_ARG(mem_reg);
SLJIT_UNUSED_ARG(temp_reg);

CHECK_ERROR();
CHECK(check_sljit_emit_atomic_store(compiler, op, src_reg, mem_reg, temp_reg));

return SLJIT_ERR_UNSUPPORTED;
}

#endif /* !SLJIT_CONFIG_X86 && !SLJIT_CONFIG_ARM && !SLJIT_CONFIG_S390X && !SLJIT_CONFIG_LOONGARCH */

#if !(defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86) \
&& !(defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64)

Expand Down
Loading

0 comments on commit dc385db

Please sign in to comment.