Skip to content

Commit

Permalink
Merge jumps and put_labels
Browse files Browse the repository at this point in the history
References to put_label are renamed to mov_addr.
  • Loading branch information
Zoltan Herczeg committed Feb 21, 2024
1 parent b6b79d5 commit a5503d6
Show file tree
Hide file tree
Showing 14 changed files with 689 additions and 885 deletions.
9 changes: 7 additions & 2 deletions API_CHANGES
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
This file is the short summary of the API changes:

21.02.2024 - Non-backward compatible
The sljit_set_put_label() function is renamed
to sljit_emit_mov_addr() and sljit_put_label
is merged into sljit_jump and removed.

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
05.09.2023 - Non-backward compatible
Turn SLJIT_IMM from a flag to a single value.

10.8.2023 - Non-backward compatible
10.08.2023 - Non-backward compatible
Rename SLJIT_INT_REGISTER to SLJIT_GP_REGISTER.

01.08.2023 - Non-backward compatible
Expand Down
44 changes: 17 additions & 27 deletions sljit_src/sljitLir.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@

/* Jump flags. */
#define JUMP_ADDR 0x1
#define JUMP_MOV_ADDR 0x2
/* SLJIT_REWRITABLE_JUMP is 0x1000. */

#if (defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86)
Expand Down Expand Up @@ -200,6 +201,8 @@
# define PATCH_TYPE4 0x40
/* BL + imm24 */
# define PATCH_TYPE5 0x50
/* addwi/subwi */
# define PATCH_TYPE6 0x60
/* 0xf00 cc code for branches */
# define JUMP_SIZE_SHIFT 26
# define JUMP_MAX_SIZE ((sljit_uw)5)
Expand Down Expand Up @@ -602,12 +605,6 @@ SLJIT_API_FUNC_ATTRIBUTE void sljit_set_target(struct sljit_jump *jump, sljit_uw
}
}

SLJIT_API_FUNC_ATTRIBUTE void sljit_set_put_label(struct sljit_put_label *put_label, struct sljit_label *label)
{
if (SLJIT_LIKELY(!!put_label))
put_label->label = label;
}

#define SLJIT_CURRENT_FLAGS_ALL \
(SLJIT_CURRENT_FLAGS_32 | SLJIT_CURRENT_FLAGS_ADD | SLJIT_CURRENT_FLAGS_SUB | SLJIT_CURRENT_FLAGS_COMPARE)

Expand Down Expand Up @@ -712,29 +709,22 @@ static SLJIT_INLINE void reverse_buf(struct sljit_compiler *compiler)
#define SLJIT_NEXT_DEFINE_TYPES \
sljit_uw next_label_size; \
sljit_uw next_jump_addr; \
sljit_uw next_put_label_addr; \
sljit_uw next_const_addr; \
sljit_uw next_min_addr

#define SLJIT_NEXT_INIT_TYPES() \
next_label_size = SLJIT_GET_NEXT_SIZE(label); \
next_jump_addr = SLJIT_GET_NEXT_ADDRESS(jump); \
next_put_label_addr = SLJIT_GET_NEXT_ADDRESS(put_label); \
next_const_addr = SLJIT_GET_NEXT_ADDRESS(const_);

#define SLJIT_GET_NEXT_MIN() \
next_min_addr = sljit_get_next_min(next_label_size, next_jump_addr, next_put_label_addr, next_const_addr);
next_min_addr = sljit_get_next_min(next_label_size, next_jump_addr, next_const_addr);

static SLJIT_INLINE sljit_uw sljit_get_next_min(sljit_uw next_label_size, sljit_uw next_jump_addr,
sljit_uw next_put_label_addr, sljit_uw next_const_addr)
static SLJIT_INLINE sljit_uw sljit_get_next_min(sljit_uw next_label_size,
sljit_uw next_jump_addr, sljit_uw next_const_addr)
{
sljit_uw result = next_jump_addr;

SLJIT_ASSERT(result == SLJIT_MAX_ADDRESS || result != next_put_label_addr);

if (next_put_label_addr < result)
result = next_put_label_addr;

SLJIT_ASSERT(result == SLJIT_MAX_ADDRESS || result != next_const_addr);

if (next_const_addr < result)
Expand Down Expand Up @@ -808,17 +798,17 @@ static SLJIT_INLINE void set_jump(struct sljit_jump *jump, struct sljit_compiler
compiler->last_jump = jump;
}

static SLJIT_INLINE void set_put_label(struct sljit_put_label *put_label, struct sljit_compiler *compiler, sljit_uw offset)
static SLJIT_INLINE void set_mov_addr(struct sljit_jump *jump, struct sljit_compiler *compiler, sljit_uw offset)
{
put_label->next = NULL;
put_label->label = NULL;
put_label->addr = compiler->size - offset;
put_label->flags = 0;
if (compiler->last_put_label != NULL)
compiler->last_put_label->next = put_label;
jump->next = NULL;
jump->addr = compiler->size - offset;
jump->flags = JUMP_MOV_ADDR;
jump->u.label = NULL;
if (compiler->last_jump != NULL)
compiler->last_jump->next = jump;
else
compiler->put_labels = put_label;
compiler->last_put_label = put_label;
compiler->jumps = jump;
compiler->last_jump = jump;
}

static SLJIT_INLINE void set_const(struct sljit_const *const_, struct sljit_compiler *compiler)
Expand Down Expand Up @@ -2970,14 +2960,14 @@ static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_const(struct sljit_compil
CHECK_RETURN_OK;
}

static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_put_label(struct sljit_compiler *compiler, sljit_s32 dst, sljit_sw dstw)
static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_mov_addr(struct sljit_compiler *compiler, sljit_s32 dst, sljit_sw dstw)
{
#if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
FUNCTION_CHECK_DST(dst, dstw);
#endif
#if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
if (SLJIT_UNLIKELY(!!compiler->verbose)) {
fprintf(compiler->verbose, " put_label ");
fprintf(compiler->verbose, " mov_addr ");
sljit_verbose_param(compiler, dst, dstw);
fprintf(compiler->verbose, "\n");
}
Expand Down
39 changes: 13 additions & 26 deletions sljit_src/sljitLir.h
Original file line number Diff line number Diff line change
Expand Up @@ -446,13 +446,6 @@ struct sljit_jump {
} u;
};

struct sljit_put_label {
struct sljit_put_label *next;
struct sljit_label *label;
sljit_uw addr;
sljit_uw flags;
};

struct sljit_const {
struct sljit_const *next;
sljit_uw addr;
Expand All @@ -464,11 +457,9 @@ struct sljit_compiler {

struct sljit_label *labels;
struct sljit_jump *jumps;
struct sljit_put_label *put_labels;
struct sljit_const *consts;
struct sljit_label *last_label;
struct sljit_jump *last_jump;
struct sljit_put_label *last_put_label;
struct sljit_const *last_const;

void *allocator_data;
Expand Down Expand Up @@ -2156,12 +2147,9 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_get_local_base(struct sljit_compiler *c
Flags: - (does not modify flags) */
SLJIT_API_FUNC_ATTRIBUTE struct sljit_const* sljit_emit_const(struct sljit_compiler *compiler, sljit_s32 dst, sljit_sw dstw, sljit_sw init_value);

/* Store the value of a label (see: sljit_set_put_label)
/* Store the value of a label (see: sljit_set_label / sljit_set_target)
Flags: - (does not modify flags) */
SLJIT_API_FUNC_ATTRIBUTE struct sljit_put_label* sljit_emit_put_label(struct sljit_compiler *compiler, sljit_s32 dst, sljit_sw dstw);

/* Set the value stored by put_label to this label. */
SLJIT_API_FUNC_ATTRIBUTE void sljit_set_put_label(struct sljit_put_label *put_label, struct sljit_label *label);
SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_mov_addr(struct sljit_compiler *compiler, sljit_s32 dst, sljit_sw dstw);

/* Provides the address of label, jump and const instructions after sljit_generate_code
is called. The returned value is unspecified before the sljit_generate_code call.
Expand Down Expand Up @@ -2244,20 +2232,18 @@ SLJIT_API_FUNC_ATTRIBUTE void sljit_set_current_flags(struct sljit_compiler *com
/* Serialization functions */
/* --------------------------------------------------------------------- */

/* Label/jump/const/put_label enumeration functions. The items in each
group are enumerated in creation order. Serialization / deserialization
preserves this order for each group. For example the fifth label after
deserialization refers to the same machine code location as the fifth
label before the serialization. */
/* Label/jump/const enumeration functions. The items in each group
are enumerated in creation order. Serialization / deserialization
preserves this order for each group. For example the fifth label
after deserialization refers to the same machine code location as
the fifth label before the serialization. */
static SLJIT_INLINE struct sljit_label *sljit_get_first_label(struct sljit_compiler *compiler) { return compiler->labels; }
static SLJIT_INLINE struct sljit_jump *sljit_get_first_jump(struct sljit_compiler *compiler) { return compiler->jumps; }
static SLJIT_INLINE struct sljit_const *sljit_get_first_const(struct sljit_compiler *compiler) { return compiler->consts; }
static SLJIT_INLINE struct sljit_put_label *sljit_get_first_put_label(struct sljit_compiler *compiler) { return compiler->put_labels; }

static SLJIT_INLINE struct sljit_label *sljit_get_next_label(struct sljit_label *label) { return label->next; }
static SLJIT_INLINE struct sljit_jump *sljit_get_next_jump(struct sljit_jump *jump) { return jump->next; }
static SLJIT_INLINE struct sljit_const *sljit_get_next_const(struct sljit_const *const_) { return const_->next; }
static SLJIT_INLINE struct sljit_put_label *sljit_get_next_put_label(struct sljit_put_label *put_label) { return put_label->next; }

/* A number starting from 0 is assigned to each label, which
represents its creation index. The first label created by the
Expand All @@ -2274,6 +2260,7 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_jump_has_label(struct sljit_jump *jump)
static SLJIT_INLINE struct sljit_label *sljit_jump_get_label(struct sljit_jump *jump) { return jump->u.label; }
SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_jump_has_target(struct sljit_jump *jump);
static SLJIT_INLINE sljit_uw sljit_jump_get_target(struct sljit_jump *jump) { return jump->u.target; }
SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_jump_is_mov_addr(struct sljit_jump *jump);

/* Option bits for sljit_serialize_compiler. */

Expand Down Expand Up @@ -2318,11 +2305,11 @@ compiler instance is returned. Otherwise the returned value is NULL.
specific data similar to sljit_create_compiler()
Notes:
- Labels assigned to jumps or put_labels are restored with
their corresponding label in the label set created by
the deserializer. Target addresses assigned to jumps are
also restored. Uninitialized jumps and put_labels remain
uninitialized.
- Labels assigned to jumps are restored with their
corresponding label in the label set created by
the deserializer. Target addresses assigned to
jumps are also restored. Uninitialized jumps
remain uninitialized.
- After the deserialization, sljit_generate_code() does
not need to be the next operation on the returned
compiler, the code generation can be continued.
Expand Down
Loading

0 comments on commit a5503d6

Please sign in to comment.