Skip to content

Instantly share code, notes, and snippets.

View bollu's full-sized avatar

Siddharth bollu

View GitHub Profile
; Emulating cps call using LLVM Coroutines
; RUN: opt coro-cps.ll -O2 -enable-coroutines -S
define void @f(i32 %arg) {
entry:
%bar.ret.addr = alloca i32
%id = call token @llvm.coro.id(i32 0, i8* null, i8* null, i8* null)
%size = call i32 @llvm.coro.size.i32()
%alloc = call i8* @malloc(i32 %size)
%hdl = call noalias i8* @llvm.coro.begin(token %id, i8* %alloc)
@bollu
bollu / Bytes.hs
Last active June 7, 2019 14:56
Swiss army knife when debugging low-level bit manipulation
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE NoImplicitPrelude #-}
module Bytes where
import Prelude hiding ((>>))
data Endian = Big | Little deriving(Eq, Ord)
data Interp = Signed | Unsigned deriving(Eq, Ord, Show)
instance Show Endian where
show Little = "L hi<-lo"
╭─bollu@strangeattractor ~/work/asterius/asterius/rts ‹june-2-pass-numrun012-on-top-of-cgrun044*›
╰─$ stack build && stack test asterius:ghc-testsuite --test-arguments=" -p FloatFnInverses --timeout 30" ; cat /home/bollu/work/asterius/asterius/test-report.csv
Building all executables for `asterius' once. After a successful build of all of them, only specified executables will be rebuilt.
asterius-0.0.1: build (lib + exe)
Log files have been written to: /home/bollu/work/asterius/.stack-work/logs/
-- While building package asterius-0.0.1 using:
/home/bollu/work/asterius/asterius/.stack-work/dist/x86_64-linux/Cabal-3.0.0.0/setup/setup --builddir=.stack-work/dist/x86_64-linux/Cabal-3.0.0.0 build lib:asterius exe:ahc exe:ahc-boot exe:ahc-cabal exe:ahc-dist exe:ahc-ld exe:ahc-link exe:ahc-pkg --ghc-options " -ddump-hi -ddump-to-file -fdiagnostics-color=always"
Process exited with code: ExitFailure 1
Logs have been written to: /home/bollu/work/asterius/.stack-work/logs/asterius-0.0.1.log
@bollu
bollu / from branch.json
Created May 17, 2019 09:00
Test suite data - from GHC and from the tasty wrapper
[
{
"trPath": "test/ghc-testsuite/perf/T10359.hs",
"trOutcome": "TestFailure",
"trErrorMessage": "expected: RunSuccess\n but got: RunFailureγ\"EvalException {evalErrorMessage = \\\"file:///home/bollu/work/asterius/asterius/test/ghc-testsuite/perf/rts.integer.mjs:73\\\\n ? this.decode(bi).toString(Number(this.decode(b))).length - 1\\\\n ^\\\\n\\\\nTypeError: Cannot read property 'toString' of undefined\\\\n at IntegerManager.integerLogBase (file:///home/bollu/work/asterius/asterius/test/ghc-testsuite/perf/rts.integer.mjs:73:33)\\\\n at __asterius_jsffi_integerzmwiredzminzuGHCziIntegerziLogarithmsziInternals_5332261958806686639 (file:///home/bollu/work/asterius/asterius/test/ghc-testsuite/perf/T10359.lib.mjs:3:481)\\\\n at __asterius_jsffi_integerzmwiredzminzuGHCziIntegerziLogarithmsziInternals_5332261958806686639_wrapper (wasm-function[111]:4)\\\\n at base_GHCziFloat_zdwzdsfromRatzqzq_entry (wasm-function[1375]:341)\\\\n at
@bollu
bollu / dump
Created May 10, 2019 14:54
Dump of module from bytearraymini.hs
This file has been truncated, but you can view the full file.
Module
{ sections =
[ TypeSection
{ types =
[ FunctionType { parameterTypes = [] , resultTypes = [] }
, FunctionType { parameterTypes = [] , resultTypes = [ I32 ] }
, FunctionType { parameterTypes = [ I32 ] , resultTypes = [] }
, FunctionType { parameterTypes = [ I32 ] , resultTypes = [ I32 ] }
, FunctionType { parameterTypes = [ I32 ] , resultTypes = [ F64 ] }
, FunctionType
@bollu
bollu / count-cloverleaf-openacc-delta.sh
Created April 6, 2019 19:20
find number of lines of code in openacc version versus normal version
#!/usr/bin/env bash
NUM_PRAGMA_LINES=$(grep '!$ACC' -R openacc | wc -l)
NUM_FORTRAN_LINES=$(cloc openacc/*.f90 -csv | tail -1 | rev | cut -d',' -f 1 | rev)
echo "num pragma lines: " $NUM_PRAGMA_LINES
echo "total lines in opanacc: " $NUM_FORTRAN_LINES
echo "ratio:"
python -c "print(100.0 * float($NUM_PRAGMA_LINES) / $NUM_FORTRAN_LINES)"
@bollu
bollu / dualz.hs
Last active March 20, 2019 11:24
A small implementation of automatic differentiation over the integers for finite differences, using the standard forward-mode-using-dual-numbers trick
import Control.Monad (forM_)
-- dual numbers of the form (x + ey), such that e^2 = 0. Formally, elements
-- of the ring (R[x] / x^2)
data Dual = Dual Double Double
instance Show Dual where
show (Dual x x') = "(" ++ show x ++ " + e" ++ show x' ++ ")"
-- create a differentiable dual quantity
-- has derivative 1
Goal
  IHn : (PureCRRec begin1' cr1) # n + (PureCRRec begin2' cr2) # n =
        (PureCRRec (begin1' + begin2') p) # n
  ============================
  (PureCRRec begin1' cr1) # n + (PureCRRec begin2' cr2) # n +
  (cr1 # (S n) + cr2 # (S n)) =
  (PureCRRec (begin1' + begin2') p) # n + p # (S n)
Tactic run:
@bollu
bollu / type-info-mismatch-ghci.md
Last active October 20, 2018 23:48
Some type magic I don't understand, seems like a.. bug? :info and :type report different types!

What is the explanation for this -- type?

awaits :: k i -> Plan k o i
  	-- .../src/Data/Machine/Plan.hs:193:1
type role T nominal nominal nominal
data T a b c where
  L :: T a b a
  ...
-- Defined at ...src//Data/Machine/Tee.hs:39:3
@bollu
bollu / delin.c
Created September 12, 2018 17:30
A[N][M][O]
A[x][y][z] = M * O * x + M * y + z
let y = O * 2
A[x][O * 2][z] = M * O * x + M * (O * 2) + z = M * O * (x + 2) + M * 0 + z = A[x + 2][2][z]