Skip to content

Instantly share code, notes, and snippets.

@sorear
sorear / ftoa.c
Created August 18, 2019 14:12
log-space, quasipolynomial-time floating point base converter
#define __STDC_WANT_IEC_60559_BFP_EXT__
#define __STDC_WANT_IEC_60559_TYPES_EXT__
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
int memo_max_exp;
#ifdef CHEAT
static char **memo[6];
#endif
@sorear
sorear / 1_output.txt
Last active March 18, 2017 21:46
Static code size comparison of go backends (b53f0f8c + riscv64 patches)
TEXT SEGMENT SIZES FOR GO CMD AND X BINARIES RELATIVE TO AMD64
386 amd64 arm arm64 mips mips64 ppc64 riscv s390x
golang.org/x/blog/blog 79.4 100.0 82.7 81.4 99.4 101.8 87.2 53.5 113.1 100%=3.30 MB
golang.org/x/blog/content/context/server 79.6 100.0 83.0 81.4 99.5 101.8 87.1 53.6 112.9 100%=2.95 MB
golang.org/x/blog/content/survey2016 85.3 100.0 95.4 90.2 108.8 113.0 94.4 59.9 123.1 100%=0.64 MB
golang.org/x/blog/support/racy 85.4 100.0 96.4 90.2 108.6 113.1 94.2 59.4 123.5 100%=0.50 MB
golang.org/x/exp/ebnflint 84.7 100.0 95.0 89.9 108.4 112.7 94.0 59.2 122.7 100%=0.63 MB
golang.org/x/exp/io/i2c/example/displayip 84.4 100.0 94.4 89.3 108.2 112.2 94.0
@sorear
sorear / hypervisor.md
Created January 13, 2017 07:31
action plan for major Q1 project, RISC-V hypervisor
  1. Initial definition of new SBI
    1. sbi_config_string_base is a problem because chain loaders may want to revise the configuration. Pass a pointer in a0 instead.
    2. Memory map in the config string instead of sbi_query_memory. Config string section for "bootstrap page tables" to eliminate walking requirement.
    3. ECALLs are defined in a new section of the config string rather than being simply assumed. Most (eventually all?) ECALLs become optional.
    4. ECALLs are individually versioned. Config string blocks become more explicit; sifive_uart_v0 and sifive_uart_v1 can't use the same drivers anyway.
    5. Yes you can chainload BBL-SBI to sorear-SBI.
    6. Define the missing ECALLs for enable/disable paging, mucounteren manipulation, etc. (Patch BBL to add them?)
    7. Maybe pin down a simpler load image format (not ELF, entry occurs with S-paging disabled). Needs research.
  2. Write a classical hypervisor
  3. Run all guest code in U-mode
@sorear
sorear / bootstrap.md
Created December 11, 2016 03:18
Early draft of Fedora bootstrap procedure

The facts

  1. Most software is not designed for cross-compilation. ~All spec files are not designed for cross-compilation. The procedure must appear to be native compilation as much as possible.

  2. Most software which is used during build procedures is not actually a compiler and does not need detailed knowledge of the current arch.

  3. Breaking build-dep cycles is very labor intensive. We would like to

@sorear
sorear / nexp.sql
Created November 26, 2016 07:41
SQL is NEXP-hard with just strings, inner join, and temp tables
-- our model of computation is 2-symbol, N-state Turing machines;
-- tape is represented as ...0010$1234$1110... ; $$-bracketed part
-- is _one before_ the logical head position, so the head is over a
-- "1" symbol.
create table rule(before text, after text);
insert into rule values
('0$123$0','$124$01'),..., -- write 1 and shift left
('$124$11','0$125$1'),..., -- write 0 and shift right
('$125$0','$$'),..., -- halt
@sorear
sorear / riscv64-spidermonkey.patch
Created November 16, 2016 07:27
Patch to make SpiderMonkey build on RISC-V
diff -ur mozilla-central-79feeed42933.orig/build/autoconf/config.guess mozilla-central-79feeed42933/build/autoconf/config.guess
--- mozilla-central-79feeed42933.orig/build/autoconf/config.guess 2016-11-15 23:25:35.000000000 +0000
+++ mozilla-central-79feeed42933/build/autoconf/config.guess 2016-11-16 05:01:37.000000000 +0000
@@ -2,7 +2,7 @@
# Attempt to guess a canonical system name.
# Copyright 1992-2016 Free Software Foundation, Inc.
-timestamp='2016-03-24'
+timestamp='2016-10-02'
@sorear
sorear / zf.lac
Last active May 10, 2016 19:13
first-order logic and ZF set theory in Adam Yedidia's Laconic
/* Cantor pair manipulation functions */
/* t0 and t1 clobbered by pairing, also use t0 as blackhole a la MIPS */
int t0;
int t1;
func pair(out, in1, in2) {
t0 = in1 + in2;
out = (t0 * (t0 + 1)) / 2 + in2;
}
@sorear
sorear / split_setmm_archive.pl
Created April 18, 2016 00:57
set.mm split thing
#!/usr/bin/perl
use strict; use warnings;
use Text::CleanFragment;
use Time::ParseDate;
use File::Slurper qw( read_text read_dir );
use HTML::Entities;
my %breaks = ( '######' => 1, '#*#*#*' => 2, '=-=-=-' => 3 );
@sorear
sorear / goals.pod
Created July 8, 2013 08:14
Rakudo Java interop UI goals for jnthn

Introduction

This infodump describes aspects of the most desirable interface for Java interop functionality in Rakudo, based on experience with CLR interop functionality in Niecza. No aspects of implementation per se are discussed.

Unsolved questions

Mainly, "should wrapper types be invariant or covariant?". A wrapper of type Subclass is not necessarily substitutable for a wrapper of type Superclass, because the subclass may have added methods which cause an ambiguous overload (in the CLR we have the additional issue of shadowing, but that doesn't apply here). Invariant wrappers (all wrappers are assignable to JavaObject and Any) are the safer option, but covariant wrappers (reflecting the Java type DAG) would be more convenient in some cases. I did covariant wrappers for Niecza and was not quite happy with the associated traps; I'd like to see if invariant wrappers can be made to work.

General object features

@sorear
sorear / gist:5939789
Created July 6, 2013 12:48
how ugly can we make a callback demo?
my %gc := nqp::jvmbootinterop('org.perl6.nqp.runtime.GlobalContext');
my %thr := nqp::jvmbootinterop('java.lang.Thread');
my %bji := nqp::jvmbootinterop('org.perl6.nqp.runtime.BootJavaInterop');
my %cls := nqp::jvmbootinterop('java.lang.Class');
my $gc_get_bji := %gc<getfield:bootInterop;Lorg/perl6/nqp/runtime/BootJavaInterop;>;
my $bji_implement := %bji<method:implementClass(Lorg/perl6/nqp/sixmodel/SixModelObject;Lorg/perl6/nqp/runtime/ThreadContext;)Lorg/perl6/nqp/sixmodel/SixModelObject;>;
my $cls_new := %cls<method:newInstance()Ljava/lang/Object;>;
my $thr_run := %thr<method:start()V>;