Skip to content

Instantly share code, notes, and snippets.

@Araq
Araq / opt_dispatch.nim
Created November 21, 2012 19:10
Optimizing dynamic dispatch
if a of Z:
echo "Z"
elif a of Y:
echo "Y"
elif a of X:
echo "X"
'of' is expensive and will become MORE expensive for proper DLL support
(string comparisons!). Thus we reserve a slot for the exact matched object
@Araq
Araq / contexts.nim
Created May 14, 2013 22:17
contexts
# module A
var a: int
template tmp*(): expr =
# declaration context: the 'a' from module A
a
@Araq
Araq / bench1
Last active December 20, 2015 23:39
Some stupid benchmark with high variance on my machine
# Compile with nimrod c -d:release --passC:-fopenmp --passL:-fopenmp PN.nim
import os, strutils, unsigned
const
TileDim = 50'i32
Miw = 2
MaxWid = 8
NumLevs = 800
@Araq
Araq / gist:6428326
Created September 3, 2013 19:18
asm test
proc test() =
asm """
".byte 0xCC\n"
"push %rcx\n"
"push %rdx\n"
"push %r8\n"
"mov `navmBackendS1`, %rax\n"
"mov `navmBackendS2`, %r8\n"
"mov `navmBackendTempAdr`, %rdx\n"
"call *%rdx\n"
const
Identity = [
[1, 0, 0],
[0, 1, 0],
[0, 0, 1]
]
Identity = Matrix([
[1, 0, 0],
[0, 1, 0],
const CacheLineSize = 32 # true for most archs
type
Barrier {.compilerProc.} = object
entered: int
cv: CondVar # condvar takes 3 words at least
when sizeof(int) < 8:
cacheAlign: array[CacheLineSize-4*sizeof(int), byte]
left: int
cacheAlign2: array[CacheLineSize-sizeof(int), byte]
import threadpool, tables, strutils
var db {.threadvar.}: CountTable[string]
proc rawPut(key: string) =
inc(db, key)
proc rawInit() =
db = initCountTable[string]()
@Araq
Araq / LL.rst
Last active May 30, 2024 13:00

This document describes how Lambda Lifting (LL) works. LL is responsible for transforming 'closures' into (environment, function) pairs.

The basic approach is that captured vars need to be put on the heap and that the calling chain needs to be explicitly modelled. Things to consider:

proc a =
  var v = 0
var
a: array[2, Thread[int]]
proc worker(x: int) =
while true:
echo x
createThread(a[0], worker, 1)
createThread(a[1], worker, 2)
@Araq
Araq / release.bat
Last active January 18, 2016 14:20
Release instructions
REM - Run the full testsuite; tests\testament\tester all
REM - Uncomment the list of changes in news.txt
REM - write a news ticker entry
REM - Update the version
REM - Generate the full docs; koch web0
REM - Generate the installers;
REM - Update the version in system.nim
REM - Test the installers