Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View bdw's full-sized avatar
💭
Hacking

Bart Wiegmans bdw

💭
Hacking
View GitHub Profile
#!/usr/bin/env perl
use strict;
use warnings FATAL => 'all';
use Data::Dumper;
my $tokenize = qr/
\A
(?<open>\() |
(?<close>\)) |
(?<space>\s+) |
@bdw
bdw / epxr-jit-fastcreate.asm
Last active May 28, 2017 19:43
broken stuff
mov rcx,0x88
mov QWORD PTR [rbx+0xd8],rcx
mov rdi,r14
mov rsi,rcx
call QWORD PTR label_064 # rip
mov rdx,rax
mov rcx,QWORD PTR [rbx+0xd8]
mov rsi,QWORD PTR [r14+0x60]
mov rdi,QWORD PTR [rsi+0x88]
mov r8,0x3
@bdw
bdw / ffs.c
Last active March 8, 2017 12:09
cross-platform first set bit
#include <stdio.h>
#include <stdlib.h>
typedef unsigned int MVMuint32;
#ifdef __GNUC__
#define FFS(x) __builtin_ffs(x)
#elif defined(_MSC_VER)
static inline MVMuint32 FFS(MVMuint32 x) {
MVMuint32 i = 0;
if (_BitScanForward(&i, x) == 0)
return 0;
push rbp
mov rbp,rsp
sub rsp,0x100
mov QWORD PTR [rbp-0x8],r14
mov QWORD PTR [rbp-0x10],r13
mov QWORD PTR [rbp-0x18],rbx
mov r11d,DWORD PTR [rdi+0x268]
mov DWORD PTR [rbp-0x20],r11d
mov r14,rdi
mov r13,rsi
@bdw
bdw / line-neighbors.sql
Created October 26, 2016 09:36
SQL code to compute line-neighbor probabilities for bayesian estimater
begin;
-- compute all probabilities for line-neighbor voltage pairs
with voltage_pair (low_v, high_v, cnt) as (
select least(a.voltage, b.voltage), greatest(a.voltage, b.voltage), count(*)
from topology_nodes n
join line_structure a on a.line_id = any(n.line_id)
join line_structure b on b.line_id = any(n.line_id)
where a.line_id < b.line_id
and a.voltage is not null and b.voltage is not null
group by least(a.voltage, b.voltage), greatest(a.voltage, b.voltage)
@bdw
bdw / geojson-to-postgis.py
Created April 12, 2016 10:03
geojson to postgis
#!/usr/bin/env python
from __future__ import print_function, unicode_literals
import operator
import psycopg2
import psycopg2.extras
import io
import json
import sys
import logging
@bdw
bdw / fib.s
Created January 28, 2016 09:44
Fibonacci in 8 instructions
.intel_syntax noprefix
.section __TEXT,__text /* or .section .text on linux / elf */
.globl _fib
_fib:
mov rax, 1
mov rcx, 1
loop:
dec rdi
jl end
add rax, rcx
@bdw
bdw / proposal.md
Last active January 4, 2016 15:23
Proposal Presentation Perl devroom FOSDEM

My Name: Bart Wiegmans My Bio: I'm brrt, I develop the MoarVM JIT compiler, I'm interested in systems on all levels, and I'm nearly finished studying.

Title of presentation: (amd64) Assembly programming for Perl programmers Description of presentation:

Perl and Assembly language unexpectedly have a few things in common:

  • Not very hip
  • Dangerously permissive
@bdw
bdw / tilin.md
Last active January 14, 2016 15:28
Tiler Linearisation Plan

Tiler linearisation

The 'linearisation' step of tiling is more complex than might seem at first sight. This results from the work that is done between emitting the code for each tile, which sometimes uses the tree structure directly. That work consists of the following things:

  • Ensuring operand values are loaded into registers
    • inserting loads
  • Ensuring a register is assigned for the result of an operation,
@bdw
bdw / rulesets.pl
Created August 13, 2015 12:27
ruleset-generation.pl
#!/usr/bin/perl
use Data::Dumper;
use strict;
use warnings;
use sexpr;
sub sortn {
sort { $a <=> $b } @_;
}