Skip to content

Instantly share code, notes, and snippets.

View bollu's full-sized avatar

Siddharth bollu

View GitHub Profile
@bollu
bollu / mlir-regions.md
Created May 5, 2021 13:48
Thinking about a good design for MLIR regions

In my opinion, one of the problems with MLIR's freedom of operation semantics is that we have no idea what the Region attached to an Operation actually means. Hence, it's impossible to automatically extend well-known SSA constructs such as GVN, CSE, ... into Regions, simply because we have no idea about the dominance relationship between the parent region containing the operation, and the child regions of the operation.

Here's a proposal on how we fix this. We add two three instructions into the base IR:

run: args * Region -> value
callcc: label * args * Region -> ()
/usr/bin/env python3
N = 10
def p(x): print(x, end="")
# forward decl
p("int even(")
for i in range(N):
if i > 0: p(", ")
p("int")
p(");\n");
@bollu
bollu / graded1.hs
Created December 22, 2020 16:46 — forked from emilypi/graded1.hs
Graded semigroups/monoids/groups - two versions
{-# language FlexibleInstances #-}
{-# language DefaultSignatures #-}
{-# language RankNTypes #-}
{-# language MultiParamTypeClasses #-}
{-# language QuantifiedConstraints #-}
module Data.Group.Graded where
import Data.Functor.WithIndex
import Data.Group
import Data.Map (Map)
@bollu
bollu / flows-problems.txt
Created October 27, 2020 15:31 — forked from anurudhp/flows-problems.md
Collection of problems on flows
http://codeforces.com/problemset/problem/628/F
http://codeforces.com/gym/100729 : Problem F
http://codeforces.com/gym/100517 : Problem H
http://codeforces.com/gym/101128 : Problem F
http://codeforces.com/gym/100491 : Problem A
http://codeforces.com/gym/101175 : Problem D (WF)
http://codeforces.com/gym/101221 : Problem I (WF)
http://codeforces.com/gym/100800 : Problem A
http://codeforces.com/gym/101239 : Problem C (WF)
http://codeforces.com/gym/101208 : Problem C (WF)
[11:48 PM] Goose: OK I finished the epilogue
[11:54 PM] cantordust: Mm, right, so now it's time to read the webpage
[11:54 PM] cantordust: https://www.gregegan.net/DICHRONAUTS/DICHRONAUTS.html
Dichronauts — Greg Egan
Illustrations for Dichronauts by Greg Egan
[11:54 PM] Goose: I am reading the webpage already. :stuck_out_tongue:
[11:54 PM] cantordust: There's basically an entire treatise :stuck_out_tongue:
[11:54 PM] Goose: I am going through it right now.
[11:54 PM] cantordust: man nice, he has the same thing for incandescence which is about SR/GR
[11:54 PM] cantordust: https://www.gregegan.net/INCANDESCENCE/Incandescence.html#CONTENTS
@bollu
bollu / nanpun.cpp
Created August 22, 2020 13:11
Use NaN punning to box an int32_t and a double together
#include <assert.h>
#include <iostream>
#include <limits>
using namespace std;
#define INT32_TAG 0xfffffffe
// https://github.com/WebKit/webkit/blob/950143da027e80924b4bb86defa8a3f21fd3fb1e/Source/JavaScriptCore/runtime/JSCJSValueInlines.h
// https://github.com/WebKit/webkit/blob/950143da027e80924b4bb86defa8a3f21fd3fb1e/Source/JavaScriptCore/runtime/JSCJSValue.h
// https://en.wikipedia.org/wiki/NaN
union PunDouble {
double d;
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE RebindableSyntax #-}
-- | to define <*> in terms of monad.
import Control.Monad (ap)
import Control.Category
import GHC.Types (Int, Float)
import GHC.Float
import GHC.Real hiding (fromIntegral, floor, Real)
import qualified GHC.Real
import GHC.Num
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE RebindableSyntax #-}
-- | to define <*> in terms of monad.
import Control.Monad (ap)
import Control.Category
import GHC.Types (Int, Float)
import GHC.Float
import GHC.Real hiding (fromIntegral, floor, Real)
import qualified GHC.Real
import GHC.Num
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE RebindableSyntax #-}
-- | to define <*> in terms of monad.
import Control.Monad (ap)
import Control.Category
import GHC.Types (Int, Float)
import GHC.Float
import GHC.Real hiding (fromIntegral, floor, Real)
import qualified GHC.Real
import GHC.Num
@bollu
bollu / localization-intuition-sage.py
Created August 1, 2020 07:39
Code to compute localization in SAGE of Z/nZ at a particular choice of multiplicative subset S = { s0^i }
import itertools
# check all pairs (a, c in R | b, d in S):
# (a/b) ~ (c/d)
# check exists e in S: (ad - bc)e = 0
R = IntegerModRing(10)
S = []
s0 = R(6)
for i in range(0, 10000):