Skip to content

Instantly share code, notes, and snippets.

Dan Gohman sunfishcode

Block or report user

Report or block sunfishcode

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View vfprintf.diff
--- 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) {
View gist:3c7412adab7566e11a9280e55e4e4da0
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.
@sunfishcode
sunfishcode / gist:b2c32cd1b448c2fcb6e6aa4ae385545a
Last active Oct 9, 2018
Custom calling convention for Rust for returning Result and Option on x86/x64:
View gist:b2c32cd1b448c2fcb6e6aa4ae385545a
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
@sunfishcode
sunfishcode / gist:859d97e2758e02015728f70f7cde15c3
Created Nov 10, 2017
Efficient x86 saturating float->int conversion
View gist:859d97e2758e02015728f70f7cde15c3
.globl bar
.p2align 4, 0x90
.type bar,@function
bar:
.cfi_startproc
cvttss2si %xmm0, %eax
cmpl $1, %eax
jo 0f
retq
0:
@sunfishcode
sunfishcode / gist:c050d4f60633c49ae6e54a3d45385031
Created Mar 23, 2017
"UTF-8 decode without BOM or fail" implementation in C
View gist:c050d4f60633c49ae6e54a3d45385031
#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;
View gist:78c6a752d60ee84410e9f8fbeb0d0291
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)
View gist:9234939
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;
You can’t perform that action at this time.