Skip to content

Instantly share code, notes, and snippets.

@yinwang0
yinwang0 / chez-future.ss
Last active April 28, 2023 06:49
experimental implementation of future with Chez Scheme threads
(define-record fitem (result ready mutex cond))
(define future
(lambda (thunk)
(let ([item (make-fitem #f #f (make-mutex) (make-condition))])
(fork-thread
(lambda ()
(let ([result (thunk)])
(with-mutex (fitem-mutex item)
(set-fitem-result! item result)
@yinwang0
yinwang0 / adc-demo.c
Last active October 28, 2018 15:24
demo of using adc instruction to add a bignum
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
typedef int bigit;
typedef long int iptr;
void asm_add(xp, xl, yp, yl, zp) bigit *xp, *yp, *zp; iptr xl, yl;
{
@yinwang0
yinwang0 / fib-clang.s
Created April 27, 2016 23:10
assembly code generated by clang and gcc for recursive fib.c
.text
.file "fib.c"
.globl fib
.align 16, 0x90
.type fib,@function
fib: # @fib
.cfi_startproc
# BB#0:
pushq %r14
.Ltmp0:
@yinwang0
yinwang0 / fib.cs
Created April 27, 2016 22:56
fib in C#
using System;
namespace ConsoleApplication
{
class Program
{
public static long fib(int n)
{
if (n < 2) {
return n;