Skip to content

Instantly share code, notes, and snippets.

@MasterDuke17
Last active July 28, 2021 14:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MasterDuke17/6529dfddc3cb7716386c11363b16b392 to your computer and use it in GitHub Desktop.
Save MasterDuke17/6529dfddc3cb7716386c11363b16b392 to your computer and use it in GitHub Desktop.
699 MVM_JIT_TILE_DECL(shl_reg) {
700 MVMint8 reg[2];
701 ensure_two_operand_pre(tc, compiler, tile, reg);
~ 702 | test rcx, rcx;
+ 703 | jz >shift;
+ 704 | mov r11, rcx;
+ 705 |shift:
+ 706 | mov CL, Rb(reg[1]);
+ 707 | shl Rq(reg[0]), CL;
+ 708 | test r11, r11;
+ 709 | jz >done;
+ 710 | mov rcx, r11;
+ 711 |done:
712 ensure_two_operand_post(tc, compiler, tile, reg);
713 }
[dan@alexandria nqp]$ gdb --args '/home/dan/Source/perl6/install/bin/moar' --libpath=src/vm/moar/stage0 src/vm/moar/stage0/nqp.moarvm --bootstrap --no-regex-lib --target=mbc --setting=NULL --stable-sc=stage1 --output=gen/moar/stage1/nqpmo.moarvm gen/moar/stage1/nqpmo.nqp
GNU gdb (GDB) 10.2
Copyright (C) 2021 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-pc-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from /home/dan/Source/perl6/install/bin/moar...
(gdb) r
Starting program: /home/dan/Source/perl6/install/bin/moar --libpath=src/vm/moar/stage0 src/vm/moar/stage0/nqp.moarvm --bootstrap --no-regex-lib --target=mbc --setting=NULL --stable-sc=stage1 --output=gen/moar/stage1/nqpmo.moarvm gen/moar/stage1/nqpmo.nqp
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/usr/lib/libthread_db.so.1".
[New Thread 0x7ffff6d9d640 (LWP 1940095)]
Thread 2 "spesh optimizer" received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7ffff6d9d640 (LWP 1940095)]
tile_node (tc=<optimized out>, traverser=<optimized out>, tree=<optimized out>, node=31) at src/jit/tile.c:124
124 tiler->states[node].state = state_info[3];
(gdb) bt
#0 tile_node (tc=<optimized out>, traverser=<optimized out>, tree=<optimized out>, node=31) at src/jit/tile.c:124
#1 0x00007ffff79a7d5e in walk_tree (node=154, traverser=0x7ffff6d9c3e0, tree=0x7ffff01a8ee0, tc=0x5555555f4770) at src/jit/expr.c:926
#2 MVM_jit_expr_tree_traverse (tc=0x5555555f4770, tree=0x7ffff01a8ee0, traverser=0x7ffff6d9c3e0) at src/jit/expr.c:943
#3 0x00007ffff79abc53 in MVM_jit_tile_expr_tree (tc=tc@entry=0x5555555f4770, compiler=compiler@entry=0x7ffff6d9c4a0, tree=tree@entry=0x7ffff01a8ee0) at src/jit/tile.c:787
#4 0x00007ffff79a5d4f in MVM_jit_compile_expr_tree (tc=0x5555555f4770, compiler=0x7ffff6d9c4a0, jg=<optimized out>, tree=0x7ffff01a8ee0) at src/jit/compile.c:321
#5 0x00007ffff79a5ed2 in MVM_jit_compile_graph (tc=tc@entry=0x5555555f4770, jg=jg@entry=0x7ffff0361a69) at src/jit/compile.c:107
#6 0x00007ffff79419af in MVM_spesh_candidate_add (tc=0x5555555f4770, p=0x7ffff0046d30) at src/6model/reprs/MVMSpeshCandidate.c:308
#7 0x00007ffff7936a85 in worker (tc=0x5555555f4770, callsite=<optimized out>, args=<optimized out>) at src/spesh/worker.c:24
#8 0x00007ffff78a25f1 in thread_initial_invoke (tc=0x5555555f4770, data=<optimized out>) at src/core/threads.c:58
#9 0x00007ffff7878476 in MVM_interp_run (tc=0x4092, tc@entry=0x5555555f4770, initial_invoke=0x18, initial_invoke@entry=0x7ffff78a25b0 <thread_initial_invoke>, invoke_data=0x18, invoke_data@entry=0x7ffff78a25b0 <thread_initial_invoke>,
outer_runloop=0xc1b6, outer_runloop@entry=0x0) at src/core/interp.c:158
#10 0x00007ffff78a2689 in start_thread (data=0x5555555f5b00) at src/core/threads.c:91
#11 0x00007ffff7310259 in start_thread () from /usr/lib/libpthread.so.0
#12 0x00007ffff756a5e3 in clone () from /usr/lib/libc.so.6
(gdb)
[dan@alexandria perl6]$ sudo gdb -p 1994761
GNU gdb (GDB) 10.2
Copyright (C) 2021 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-pc-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word".
Attaching to process 1994761
[New LWP 1994762]
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/usr/lib/libthread_db.so.1".
0x00007fc65175ccd0 in MVM_fixed_size_alloc (tc=0x55d1c927cde0, al=0x55d1c927e640, bytes=672) at src/core/fixedsizealloc.c:202
202 MVMFixedSizeAllocFreeListEntry *fle = bin_ptr->free_list;
(gdb) bt
#0 0x00007fc65175ccd0 in MVM_fixed_size_alloc (tc=0x55d1c927cde0, al=0x55d1c927e640, bytes=672) at src/core/fixedsizealloc.c:202
#1 0x00007fc65175cd51 in MVM_fixed_size_alloc_zeroed (tc=0x55d1c927cde0, al=0x55d1c927e640, bytes=672) at src/core/fixedsizealloc.c:217
#2 0x00007fc65173e64a in allocate_frame (tc=0x55d1c927cde0, static_frame=0x55d1c94d4038, spesh_cand=0x7fc650c43160, heap=0) at src/core/frame.c:315
#3 0x00007fc65173eff7 in MVM_frame_invoke (tc=0x55d1c927cde0, static_frame=0x55d1c94d4038, callsite=0x7fc651d116e0 <inv_arg_callsite>, args=0x55d1c999a0f0, outer=0x7fc650c70a70, code_ref=0x55d1c94e0ea0, spesh_cand=0) at src/core/frame.c:517
#4 0x00007fc6517b44fe in invoke_handler (tc=0x55d1c927cde0, invokee=0x55d1c94e0ea0, callsite=0x7fc651d116e0 <inv_arg_callsite>, args=0x55d1c999a0f0) at src/6model/reprs/MVMCode.c:10
#5 0x00007fc6514bf25d in ?? ()
#6 0x0000000000000008 in ?? ()
#7 0x000055d1c927cde0 in ?? ()
#8 0x000055d1c927dcd0 in ?? ()
#9 0x000055d1c9533ff0 in ?? ()
#10 0x00007fff8560a4b0 in ?? ()
#11 0x00007fc65175d032 in MVM_fixed_size_free (tc=0x7fc6514d0484, al=0x7fff8560a590, bytes=94359518814448, to_free=0x7fc651d116e0 <inv_arg_callsite>) at src/core/fixedsizealloc.c:320
#12 0x00007fc6518aea81 in MVM_jit_code_enter (tc=0x55d1c927cde0, code=0x7fc64816bfa0, cu=0x55d1c9319170) at src/jit/interface.c:24
#13 0x00007fc65172ec7b in MVM_interp_run (tc=0x55d1c927cde0, initial_invoke=0x7fc65188c256 <toplevel_initial_invoke>, invoke_data=0x55d1c9352bd0, outer_runloop=0x0) at src/core/interp.c:6465
#14 0x00007fc65188c3d0 in MVM_vm_run_file (instance=0x55d1c927c2a0, filename=0x7fff8560d5d3 "src/vm/moar/stage0/nqp.moarvm") at src/moar.c:504
#15 0x000055d1c7d5dc84 in main (argc=10, argv=0x7fff8560c048) at src/main.c:305
(gdb)
709 MVM_JIT_TILE_DECL(shr_reg) {
710 MVMint8 reg[2];
711 ensure_two_operand_pre(tc, compiler, tile, reg);
~ 712 | mov rax, rcx;
+ 713 | mov cl, Rb(reg[1]);
+ 714 | sar Rq(reg[0]), cl;
+ 715 | mov rcx, rax;
716 ensure_two_operand_post(tc, compiler, tile, reg);
717 }
diff --git src/jit/core_templates.expr src/jit/core_templates.expr
index adcc82023..5fd211685 100644
--- src/jit/core_templates.expr
+++ src/jit/core_templates.expr
@@ -217,6 +217,9 @@
(template: bxor_i (xor $1 $2))
(template: bnot_i (not $1))
+(template: blshift_i (shl $1 $2))
+#(template: brshift_i (shr $1 $2))
+
(template: not_i (flagval (zr $1)))
(template: coerce_is
diff --git src/jit/expr_ops.h src/jit/expr_ops.h
index b03ab8ba5..8c5b2966e 100644
--- src/jit/expr_ops.h
+++ src/jit/expr_ops.h
@@ -44,6 +44,9 @@
/* type conversion */ \
_(SCAST, 1, 2), \
_(UCAST, 1, 2), \
+ /* shifts */ \
+ _(SHL, 2, 0), \
+ _(SHR, 2, 0), \
/* integer arithmetic */ \
_(ADD, 2, 0), \
_(SUB, 2, 0), \
diff --git src/jit/x64/tile_pattern.tile src/jit/x64/tile_pattern.tile
index 65d056400..cfaf18ddb 100644
--- src/jit/x64/tile_pattern.tile
+++ src/jit/x64/tile_pattern.tile
@@ -67,6 +67,14 @@
(tile: cast_signed_load_addr (scast (load (addr reg $ofs) $src_sz) $to_size $from_size) reg 5)
(tile: cast_unsigned_load_addr (ucast (load (addr reg $ofs) $src_sz) $to_size $from_size) reg 5)
+#
+# SHIFTS
+#
+
+(tile: shl_const (shl reg (const $val $size)) reg 3)
+
+(tile: shr_const (shr reg (const $val $size)) reg 3)
+
#
# ARITHMETIC
#
diff --git src/jit/x64/tiles.dasc src/jit/x64/tiles.dasc
index 616c53de7..54cd3cc5c 100644
--- src/jit/x64/tiles.dasc
+++ src/jit/x64/tiles.dasc
@@ -696,6 +696,27 @@ MVM_JIT_TILE_DECL(sub_load_idx) {
}
+MVM_JIT_TILE_DECL(shl_const) {
+ MVMint8 out = tile->values[0];
+ MVMint8 in1 = tile->values[1];
+ MVMint32 val = tile->args[0];
+ MVMint32 sz = tile->args[1];
+ if (out != in1) {
+ | mov Rq(out), Rq(in1);
+ }
+ | shl Rq(out), val;
+}
+
+MVM_JIT_TILE_DECL(shr_const) {
+ MVMint8 out = tile->values[0];
+ MVMint8 in1 = tile->values[1];
+ MVMint32 val = tile->args[0];
+ MVMint32 sz = tile->args[1];
+ if (out != in1) {
+ | mov Rq(out), Rq(in1);
+ }
+ | sar Rq(out), val;
+}
MVM_JIT_TILE_DECL(test) {
diff --git tools/expr-template-compiler.pl tools/expr-template-compiler.pl
index 5d60e7b10..abc518d58 100755
--- tools/expr-template-compiler.pl
+++ tools/expr-template-compiler.pl
@@ -58,7 +58,7 @@ my %OPERATOR_TYPES = (
(map { $_ => 'void' } qw(store store_num discard dov when ifv branch mark callv guard)),
(map { $_ => 'flag' } qw(lt le eq ne ge gt nz zr all any)),
(map { $_ => 'num' } qw(const_num load_num calln)),
- (map { $_ => '?' } qw(if copy do add sub mul)),
+ (map { $_ => '?' } qw(if copy do add sub mul shl shr)),
qw(arglist) x 2,
qw(carg) x 2,
);
@@ -84,7 +84,7 @@ my %OPERAND_TYPES = (
guard => 'void',
# anything on numbers is polymorphic,
# because the output type is the input type
- map(($_ => '?'), qw(lt le eq ne ge gt nz zr add sub mul)),
+ map(($_ => '?'), qw(lt le eq ne ge gt nz zr add sub mul shl shr)),
);
# which list item is the size
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment