Skip to content

Commit 689bd67

Browse files
committed
armv6m: add an assert for size_t size
Signed-off-by: Paul Guyot <pguyot@kallisys.net>
1 parent 65991ec commit 689bd67

File tree

3 files changed

+67
-16
lines changed

3 files changed

+67
-16
lines changed

libs/jit/src/jit_x86_64_asm.erl

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,36 @@ movq(RegA, {Offset, RegB, RegC, Scale}) when
209209
MODRM_BASE:3,
210210
Offset:32/little
211211
>>;
212+
movq(Imm, {Offset, Base, Index, Scale}) when
213+
is_integer(Imm),
214+
is_atom(Base),
215+
is_atom(Index),
216+
(Scale == 1 orelse Scale == 2 orelse Scale == 4 orelse Scale == 8),
217+
?IS_SINT8_T(Offset),
218+
Offset =/= 0
219+
->
220+
{REX_B, MODRM_BASE} = x86_64_x_reg(Base),
221+
{REX_X, MODRM_INDEX} = x86_64_x_reg(Index),
222+
ScaleBits =
223+
case Scale of
224+
1 -> 0;
225+
2 -> 1;
226+
4 -> 2;
227+
8 -> 3
228+
end,
229+
% rm=100 for SIB, mod=01 for disp8
230+
<<
231+
?X86_64_REX(1, 0, REX_X, REX_B),
232+
16#c7,
233+
1:2,
234+
0:3,
235+
4:3,
236+
ScaleBits:2,
237+
MODRM_INDEX:3,
238+
MODRM_BASE:3,
239+
Offset,
240+
Imm:32/little
241+
>>;
212242
movq(Imm, {Offset, Base, Index, Scale}) when
213243
is_integer(Imm),
214244
is_atom(Base),

src/libAtomVM/jit.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ _Static_assert(offsetof(JITState, continuation) == 0x4, "jit_state->continuation
222222
_Static_assert(offsetof(JITState, remaining_reductions) == 0x8, "jit_state->remaining_reductions is 0x8 in jit/src/jit_armv6m.erl");
223223

224224
_Static_assert(sizeof(avm_float_t) == 0x8, "sizeof(avm_float_t) is 0x8 in jit/src/jit_armv6m.erl");
225+
_Static_assert(sizeof(size_t) == 4, "size_t is expected to be 32 bits");
225226
#else
226227
#error Unknown jit target
227228
#endif

tests/libs/jit/jit_x86_64_asm_tests.erl

Lines changed: 36 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -716,35 +716,55 @@ leaq_test_() ->
716716

717717
movq_sib_test_() ->
718718
[
719-
% movq %rax, 16#10(%rdx,%rcx,2)
720-
?_assertEqual(
721-
% REX.W, ModRM, SIB, disp8
719+
?_assertAsmEqual(
722720
<<16#48, 16#89, 16#44, 16#4A, 16#10>>,
721+
"mov %rax,0x10(%rdx,%rcx,2)",
723722
jit_x86_64_asm:movq(rax, {16, rdx, rcx, 2})
724723
),
725-
% movq %r8, -0x80(%r9,%r10,4)
726-
?_assertEqual(
727-
% REX.WRXB, ModRM, SIB, disp32
724+
?_assertAsmEqual(
728725
<<16#4F, 16#89, 16#44, 16#91, 16#80>>,
726+
"mov %r8,-0x80(%r9,%r10,4)",
729727
jit_x86_64_asm:movq(r8, {-128, r9, r10, 4})
730728
),
731-
% movq %r11, 16#7f(%r8,%rdx,8)
732-
?_assertEqual(
733-
% REX.WRXB, ModRM, SIB, disp8
729+
?_assertAsmEqual(
734730
<<16#4D, 16#89, 16#5C, 16#D0, 16#7F>>,
731+
"mov %r11,0x7f(%r8,%rdx,8)",
735732
jit_x86_64_asm:movq(r11, {127, r8, rdx, 8})
736733
),
737-
% movq %rcx, 16#12345678(%rsi,%rdi,1)
738-
?_assertEqual(
739-
% REX.W, ModRM, SIB, disp32
734+
?_assertAsmEqual(
740735
<<16#48, 16#89, 16#8C, 16#3E, 16#78, 16#56, 16#34, 16#12>>,
736+
"mov %rcx,0x12345678(%rsi,%rdi,1)",
741737
jit_x86_64_asm:movq(rcx, {305419896, rsi, rdi, 1})
742738
),
743-
% movq $95, 16#18(%rax, %rcx, 8)
744-
?_assertEqual(
745-
% REX.W, ModRM, SIB, disp32
746-
<<16#48, 16#C7, 16#84, 16#C8, 16#18, 16#00, 16#00, 16#00, 16#5F, 16#00, 16#00, 16#00>>,
739+
?_assertAsmEqual(
740+
<<72,199,68,200,24,95,0,0,0>>,
741+
"movq $0x5f,0x18(%rax,%rcx,8)",
747742
jit_x86_64_asm:movq(95, {16#18, rax, rcx, 8})
743+
),
744+
?_assertAsmEqual(
745+
<<16#48, 16#89, 16#44, 16#0A, 16#10>>,
746+
"mov %rax,0x10(%rdx,%rcx,1)",
747+
jit_x86_64_asm:movq(rax, {16, rdx, rcx, 1})
748+
),
749+
?_assertAsmEqual(
750+
<<72,199,68,74,32,42,0,0,0>>,
751+
"movq $0x2a,0x20(%rdx,%rcx,2)",
752+
jit_x86_64_asm:movq(42, {32, rdx, rcx, 2})
753+
),
754+
?_assertAsmEqual(
755+
<<72,199,68,138,48,33,0,0,0>>,
756+
"movq $0x21,0x30(%rdx,%rcx,4)",
757+
jit_x86_64_asm:movq(33, {48, rdx, rcx, 4})
758+
),
759+
?_assertAsmEqual(
760+
<<72,199,68,10,64,55,0,0,0>>,
761+
"movq $0x37,0x40(%rdx,%rcx,1)",
762+
jit_x86_64_asm:movq(55, {64, rdx, rcx, 1})
763+
),
764+
?_assertAsmEqual(
765+
<<72,199,132,202,128,0,0,0,153,0,0,0>>,
766+
"movq $0x99,0x80(%rdx,%rcx,8)",
767+
jit_x86_64_asm:movq(16#99, {16#80, rdx, rcx, 8})
748768
)
749769
].
750770

0 commit comments

Comments
 (0)