Skip to content

Instantly share code, notes, and snippets.

View sunfishcode's full-sized avatar

Dan Gohman sunfishcode

View GitHub Profile
STACKTOP = STACKTOP + 8 | 0;
$nHeight$i9409 = STACKTOP;
STACKTOP = STACKTOP + 8 | 0;
$nHeight$i9363 = STACKTOP;
STACKTOP = STACKTOP + 8 | 0;
$nHeight$i9316 = STACKTOP;
STACKTOP = STACKTOP + 8 | 0;
$nHeight$i9091 = STACKTOP;
STACKTOP = STACKTOP + 8 | 0;
$nHeight$i9044 = STACKTOP;
Here's some C code:
void extern_func(int *, int*, int*, int*);
static int static_var = 3;
int global_var = 4;
extern int extern_var;
__attribute__((noinline))
static void static_func(void)
@sunfishcode
sunfishcode / gist:c050d4f60633c49ae6e54a3d45385031
Created March 23, 2017 07:42
"UTF-8 decode without BOM or fail" implementation in C
#include <stddef.h>
#include <stdbool.h>
#include <stdint.h>
bool is_valid_utf8(const uint8_t *str, size_t len)
{
size_t bytes_seen = 0;
size_t bytes_needed = 0;
uint8_t lower_boundary = 0x80;
uint8_t upper_boundary = 0xbf;
@sunfishcode
sunfishcode / gist:859d97e2758e02015728f70f7cde15c3
Created November 10, 2017 04:55
Efficient x86 saturating float->int conversion
.globl bar
.p2align 4, 0x90
.type bar,@function
bar:
.cfi_startproc
cvttss2si %xmm0, %eax
cmpl $1, %eax
jo 0f
retq
0:
@sunfishcode
sunfishcode / gist:b2c32cd1b448c2fcb6e6aa4ae385545a
Last active October 9, 2018 16:45
Custom calling convention for Rust for returning Result and Option on x86/x64:
foo() -> Result<T, E>
When returning an Ok, foo would clear CF via "clc", and then return
the value as if the return type were just a plain T.
When returning an Err, foo would set the CF flag via "stc", and then
return the value as if the return type were just a plain E.
On the caller side, immediately after a call to foo, the caller could
do a "jc error_label". Fallthrough would be the success path and it'd
Cretonne IL is tuned for codegen. You can see this in the use of EBBs, br_table
not taking arguments, the lack of builtin def-use lists, the lack of a
general-purpose switch statement, the precense of instructions specialized to
take an immediate argument, and other places.
I'm entertaining the idea that this works out well for Rustc. It'll make
"fast compile" use cases, both "debug" and "pretty good optimization" builds
faster. Compared to LLVM's 4 layers in a typical compile (LLVM IR, SelectionDAG,
MachineFunction, MC), Cretonne uses one IL throughout, and it's designed
to be very compact.
--- vfprintf.c.orig 2019-01-08 16:56:58.147457674 -0800
+++ vfprintf.c 2019-01-11 13:49:08.320056831 -0800
@@ -11,6 +11,54 @@
#include <math.h>
#include <float.h>
+#if defined(WASM_NO_FLOATING_POINT_SUPPORT)
+
+__attribute__((__cold__, __noreturn__))
+static void floating_point_not_supported(void) {
@sunfishcode
sunfishcode / normalization-test.txt
Last active December 3, 2020 01:17
Unicode normalization
U+0x2f8a6: 慈 ('慈')
U+0x6148: 慈 ('慈')
U+0x2f999: 茝 ('茝')
U+0x831d: 茝 ('茝')
U+0x387: · ('·')
U+0xb7: · ('·')
U+6148 U+0xfe00: 慈︀ ('\u{fe00}')
U+6148 U+0xfe01: 慈︁ ('\u{fe01}')
U+6148 U+0xfe02: 慈︂ ('\u{fe02}')
U+6148 U+0xfe03: 慈︃ ('\u{fe03}')
@sunfishcode
sunfishcode / gist:f4a94eecd24bf7e5a6facd1cd97b8d5b
Created December 13, 2023 01:58
Implemented functions in Eyra
abort
abs
accept
accept4
access
acos
acosf
acosh
acoshf
__aeabi_unwind_cpp_pr0
@sunfishcode
sunfishcode / BigWave.md
Last active January 24, 2024 15:18
BigWave

BigWave

👋

BigWave is a hypothetical data serialization language for configuration files, using the datatypes of the Wasm Component Model. It extends the Wasm Value Encoding (WAVE) with syntax for quoteless strings, multi-line strings, and comments.