Skip to content

Commit

Permalink
Avoid unaligned loads in jit_lvn_copy
Browse files Browse the repository at this point in the history
  • Loading branch information
nickg committed Aug 6, 2023
1 parent e333b87 commit ea12e4a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/jit/jit-optim.c
Original file line number Diff line number Diff line change
Expand Up @@ -777,15 +777,15 @@ static void jit_lvn_copy(jit_ir_t *ir, lvn_state_t *state)
switch (count) {
case 8:
ir->size = JIT_SZ_64;
ir->arg1 = LVN_CONST(*(uint64_t *)src);
ir->arg1 = LVN_CONST(unaligned_load(src, uint64_t));
break;
case 4:
ir->size = JIT_SZ_32;
ir->arg1 = LVN_CONST(*(uint32_t *)src);
ir->arg1 = LVN_CONST(unaligned_load(src, uint32_t));
break;
case 2:
ir->size = JIT_SZ_16;
ir->arg1 = LVN_CONST(*(uint16_t *)src);
ir->arg1 = LVN_CONST(unaligned_load(src, uint16_t));
break;
case 1:
ir->size = JIT_SZ_8;
Expand Down
6 changes: 6 additions & 0 deletions src/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -451,4 +451,10 @@ void list_clear(ptr_list_t *l);
#define PACK_BE64(u) \
PACK_BE32(u >> 32), PACK_BE32(u)

#define unaligned_load(ptr, type) ({ \
const struct { type value; } \
__attribute__((packed)) *s = ptr; \
s->value; \
})

#endif // _UTIL_H

0 comments on commit ea12e4a

Please sign in to comment.