Skip to content

Instantly share code, notes, and snippets.

@chethega
chethega / readme.md
Last active July 3, 2020 00:01
xoshiro tests

Use clang -Ofast xoshiro256plusplus.c -march=native -shared -fpic to compile.

Use gcc -Ofast xoshiro256plusplus.c -march=native -S or clang -Ofast xoshiro256plusplus.c -march=native -emit-llvm -S to see the generated code, and weep.

Output of julia ./xoshiro256plusplus.jl on my admittedly anemic machine:

julia dsfmt 1024 x UInt64
  2.209 μs (0 allocations: 0 bytes)
ref impl, 1 x interleaved, 1024 x UInt64
  1.579 μs (0 allocations: 0 bytes)
module AbstractAlgebra
export ZZ, FreeModule, Submodule, Generic, test_submodule
abstract type RingElem end
abstract type Ring end
abstract type FPModule{T} end
abstract type FPModuleElem{T} end
mutable struct Integers{T <: Integer} <: Ring
@chethega
chethega / dict.jl
Created July 5, 2019 13:25
swissdict for julia
# This file is a part of Julia. License is MIT: https://julialang.org/license
function _truncate_at_width_or_chars(str, width, chars="", truncmark="…")
truncwidth = textwidth(truncmark)
(width <= 0 || width < truncwidth) && return ""
wid = truncidx = lastidx = 0
for (idx, c) in pairs(str)
lastidx = idx
wid += textwidth(c)
@chethega
chethega / dict_del.jl
Created March 6, 2019 18:04
dictionary maintenance
using Random
println("start...", Base.VERSION)
function gentape(Nsz, Ntape, rf)
init = [rf() for i=1:Nsz]
unique!(init)
Nsz = length(init)
state = copy(init)
@chethega
chethega / aesmbed.jl
Last active February 28, 2019 22:53
canonical equipartitions of graphs via diffusion
#fallback aes via mbedtls.
#officially, mbedtls is a binary dependency of julia, so this should always work?
#also, results are (same as other versions) dependent on system endianness.
#factor 5 slower than native on my system, and causes no allocations. Probably fast enough.
module AESmbed
using Libdl
export Aes_wrap
@chethega
chethega / BitMatVec.jl
Last active November 16, 2018 02:21
static Bitvectors, vector version
if VERSION >= v"1.0.2"
import Base._blsr
else
@inline _blsr(x) = x & (x-1)
end
struct BitVec{N} <:AbstractVector{Bool}
chunks::NTuple{N,UInt64}
end
@chethega
chethega / BitMatSet.jl
Last active November 16, 2018 02:21
static bitvectors, set version
if VERSION >= v"1.0.2"
import Base._blsr
else
@inline _blsr(x) = x & (x-1)
end
struct SBitSet{N} <:AbstractSet{Int64}
chunks::NTuple{N,UInt64}
end
@chethega
chethega / hilb_ordering.jl
Created November 28, 2017 19:33
hilbert-ordering for pairwise! in Distances.jl
@enum hilb_state _down _up _left _right
function pairwise_recurse_multithreaded!(res,d,A,B, thresh, nthreads)
# thresh = threshcompute(A);
jobs = Vector{UnitRange{Int}}(nthreads)
resize!(jobs, 0)
si = round(Int,size(A,2)/nthreads)
el = 0
for i in 1 : nthreads-1
push!(jobs, 1 + el : el+si)