Skip to content

Instantly share code, notes, and snippets.

@jido
jido / int32.s
Last active March 17, 2019 19:02
.intel_syntax noprefix
_add:
mov eax, edi
add eax, esi
jo plus_overflow
jmp r8
plus_overflow:
jmp r9
@jido
jido / int32.s
Last active March 16, 2019 20:41
Why do I get libdyld.dylib`stack_not_16_byte_aligned_error ?
-> 0x100000ee4 <+5>: callq 0x100000f74 ; symbol stub for: malloc
0x100000ee9 <+10>: addq $0x10, %rsp
0x100000eed <+14>: cmpq $0x0, %rax
0x100000ef1 <+18>: je 0x100000f3b ; Integer_bits_32_outofmemory
Target 0: (int32) stopped.
(lldb) reg read rbp rsp
rbp = 0x00007ffeefbff9e0
rsp = 0x00007ffeefbff9d8
(lldb) n
Process 23851 stopped
@jido
jido / int32.ll
Last active March 14, 2019 23:12
Problem: the alloca calls reserve 16 bytes each, so pointer arithmetic in "plus" is wrong
; ModuleID = 'integer.dodo'
; Function Attrs: noinline nounwind
define void @int32() {
%frame = alloca i8*, align 8
%context = alloca i8*, align 8
br label %test
plus:
%plus1 = load i8*, i8** %frame, align 8
@jido
jido / decimalsense2.c
Last active June 30, 2018 08:36
Decimal number format with binary significand that makes some sense
/*
Decimal 64 bit numbers that make sense
Format:
=======
seeeeeee eepmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm
s = sign bit
e = 10-bit exponent (with p)
p = lowest bit of exponent or highest bit of mantissa (subnormal numbers)
@jido
jido / description.txt
Created June 18, 2018 17:08
Binary decimal format
Bit 63 = sign
Subnormal
0.0-9.999 999 999 999 999E-511
Stored as uint64
Normal fp
Bit 62-53 = exponent
Bit 52-0 = mantissa
Mantissa range 0-8 999 999 999 999 999
@jido
jido / decimalsense.c
Last active June 17, 2018 22:12
Decimal number format that makes some sense
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char * numberAsString(uint64_t num) {
static char result[] = "+1.234567890123456e-123";
char sign = (num & 0x8000000000000000L) ? '-' : '+';
uint16_t scale = (num >> 50) & 0x1fff;
if (scale << 2 == 0x7ff0)
$ git push
fatal: You are not currently on a branch.
To push the history leading to the current (detached HEAD)
state now, use
git push origin HEAD:<name-of-remote-branch>
@jido
jido / Mistigri.java
Last active June 29, 2016 23:10
Why is my Matcher not working?
private static final Pattern parser = Pattern.compile("/(\\S+)/");
private String parseAction(String tag) {
Matcher them = parser.matcher(tag);
if (!them.find()) return "YOLO";
return them.group(1);
}
Result:
@jido
jido / mafia2.mt
Last active June 19, 2016 19:52
Hung program
# An implementation of the Mafia party game state machine.
import "lib/enum" =~ [=> makeEnum]
exports (makeMafia, DAY, NIGHT)
def [MafiaState :DeepFrozen,
DAY :DeepFrozen,
NIGHT :DeepFrozen] := makeEnum(["day", "night"])
@jido
jido / ObjectCopy.js
Last active May 7, 2016 08:18
Why does this give a TypeError: cannot convert undefined or null to object?
"use strict";
function copy(proto, changes) {
if (changes === undefined) return Object.create(proto);
var props = Object.keys(changes).map(function(attr) {
var single = {};
single[attr] = {value: changes[attr], writable: false, enumerable: true};
return single;
});
return Object.create(proto, Object.assign.apply(props));