Skip to content

Instantly share code, notes, and snippets.

Avatar
💭
Hacking

Bart Wiegmans bdw

💭
Hacking
View GitHub Profile
@bdw
bdw / calculate.nqp
Created Jun 10, 2018
A hopelessly optimal case for the JIT compiler
View calculate.nqp
#!/usr/bin/env nqp
# From https://www.johnhawthorn.com/2018/02/playing-with-ruby-jit-mjit/
sub calculate(int $a, int $b, int $n) {
my int $i := 0;
my int $c := 0;
while $i < $n {
$a := $a * 16807 % 2147483647;
$b := $b * 48271 % 2147483647;
@bdw
bdw / mislabel.sam
Created May 20, 2018
broken-label.asm
View mislabel.sam
;; we jump inbetween this and the next, and so corrupt our stack and our frame
505a: 4c 8b 5b 58 mov r11,QWORD PTR [rbx+0x58]
505e: 48 8b 53 60 mov rdx,QWORD PTR [rbx+0x60]
5062: 48 89 93 e8 02 00 00 mov QWORD PTR [rbx+0x2e8],rdx
5069: 48 c7 c2 04 00 00 00 mov rdx,0x4
5070: 48 8b 8b d8 02 00 00 mov rcx,QWORD PTR [rbx+0x2d8]
5077: 4c 89 5c 24 20 mov QWORD PTR [rsp+0x20],r11
507c: 48 89 54 24 30 mov QWORD PTR [rsp+0x30],rdx
5081: 4c 89 c0 mov rax,r8
5084: 4c 89 ca mov rdx,r9
@bdw
bdw / search_frame_handlers_lex.s
Created May 9, 2018
broken assembly on windows
View search_frame_handlers_lex.s
0x0000000069bc7443 <+0>: push rbp
0x0000000069bc7444 <+1>: push rbx
0x0000000069bc7445 <+2>: sub rsp,0x98
0x0000000069bc744c <+9>: lea rbp,[rsp+0x80]
0x0000000069bc7454 <+17>: mov QWORD PTR [rbp+0x30],rcx
0x0000000069bc7458 <+21>: mov QWORD PTR [rbp+0x38],rdx
0x0000000069bc745c <+25>: mov DWORD PTR [rbp+0x40],r8d
0x0000000069bc7460 <+29>: mov QWORD PTR [rbp+0x48],r9
0x0000000069bc7464 <+33>: mov rax,QWORD PTR [rbp+0x58]
0x0000000069bc7468 <+37>: mov eax,DWORD PTR [rax]
View gist:e9b7c6e3e92e788d2fdcec6df6c171ab
#!/usr/bin/env perl6
multi sub euclid ($a is copy, $b is copy) {
while ($b != 0) {
($a, $b) = ($b, $a % $b);
}
return $a;
}
multi sub euclid ($a, $b where $a < $b) {
View sub-declaration.pl
#!/usr/bin/env perl
use strict;
use warnings;
sub foo {
my ($x) = @_;
return 0 if ($x == 0);
return foo $x - 1;
}
foo 3;
View linear-scan.log
Starting dump of JIT expression tree
====================================
digraph {
n_0001 [label="LOCAL"];
n_0002 [label="ADDR(0xd8)"];
n_0002 -> n_0001;
n_0008 [label="TC"];
n_0009 [label="ADDR(0x1b0)"];
n_0009 -> n_0008;
n_0012 [label="LOAD(0x8)"];
@bdw
bdw / channel-breakage.pl6
Created Nov 16, 2017
breaking-expr-in-inline-lastpayload
View channel-breakage.pl6
#!/usr/bin/env perl6
use v6;
for (0..1000) {
my $channel = Channel.new;
$channel.close;
my $result = (try $channel.receive) // buf8;
say "Result is undefined" unless $result.defined;
}
View heapsnapshot.patch
diff --git a/src/profiler/heapsnapshot.c b/src/profiler/heapsnapshot.c
index 071954f..a4a6d9c 100644
--- a/src/profiler/heapsnapshot.c
+++ b/src/profiler/heapsnapshot.c
@@ -820,7 +820,7 @@ void references_to_filehandle(MVMThreadContext *tc, MVMHeapSnapshotCollection *c
MVMuint64 maxval = MAX(kind, cindex);
- if (maxval + 1 >= 1l << 32) {
+ if (maxval + 1 >= (UINT64_C(1) << 32)) {
View make-an-adhoc-jit-graph.c
static void adhoc_jit_graph (MVMThreadContext *tc) {
MVMJitGraph graph;
MVMJitNode label_node, call_node;
void *labels[2];
labels[0] = &label_node;
labels[1] = &graph;
MVMJitCode *code;
graph.labels = labels;
graph.first_node = &label_node;
label_node.type = MVM_JIT_NODE_LABEL;
@bdw
bdw / spesh-log.txt
Created Aug 23, 2017
we can miss an inline apparently!
View spesh-log.txt
Specialization of 'compile_node' (cuid: 118)
Before:
Spesh of 'compile_node' (cuid: 118, file: gen/moar/stage2/QAST.nqp:5747)
BB 0 (0x101d20430):
line: 5747 (pc 0)
Instructions:
no_op
Successors: 1