Skip to content

Instantly share code, notes, and snippets.

View 9il's full-sized avatar
☀️

Ilia Ki 9il

☀️
  • Bangkok
View GitHub Profile
@9il
9il / test.d
Created June 6, 2013 16:29
hellow world
import std.stdio;
void main() {
"Hellow World".writeln;
}
@9il
9il / realdotproduct.d
Last active December 21, 2015 05:18
SIMD implementation of dot-product for real numbers
F dotProduct(F)(in F[] a, in F[] b) @trusted
if(is(F == double) || is(F == float))
in
{
assert(a.length == b.length);
}
out(result)
{
assert(!result.isNaN);
}
@9il
9il / complexdotproduct.d
Last active December 21, 2015 05:19
SIMD implementation of dot-product for complex numbers (sum(a_i * conj(b_i])))
for(; ap < sbe; ap+=4*M, bp+=4*M)
{
auto a0 = load(cast(VP)ap+0);
auto a1 = load(cast(VP)ap+1);
auto a2 = load(cast(VP)ap+2);
auto a3 = load(cast(VP)ap+3);
auto b0 = load(cast(VP)bp+0);
auto b1 = load(cast(VP)bp+1);
auto b2 = load(cast(VP)bp+2);
@9il
9il / avx2dotproduct.asm
Created August 17, 2013 19:53
GDC-4.8.1 assembler output for dot product function.
.section .text._D4simd10dotproduct18__T10dotProductTfZ10dotProductFNexAfxAfZf,"axG",@progbits,_D4simd10dotproduct18__T10dotProductTfZ10dotProductFNexAfxAfZf,comdat
.p2align 4,,15
.weak _D4simd10dotproduct18__T10dotProductTfZ10dotProductFNexAfxAfZf
.type _D4simd10dotproduct18__T10dotProductTfZ10dotProductFNexAfxAfZf, @function
_D4simd10dotproduct18__T10dotProductTfZ10dotProductFNexAfxAfZf:
.LFB412:
.cfi_startproc
mov rdx, rdi
lea r10, [rsi+rdi*4]
and rdi, -32
@9il
9il / blasVersion.d
Last active December 22, 2015 20:09
sgemm(Order.RowMajor, Transpose.NoTrans, Transpose.NoTrans,
dl, wl, tl, 1.0, pdt.ptr, tl, ptw.ptr, wl, 0.0, qdw.ptr, wl);
qdw.array[] /= ndw.array[];
sgemm(Order.RowMajor, Transpose. Trans, Transpose.NoTrans,
tl, wl, dl, 1.0, pdt.ptr, tl, qdw.ptr, wl, 0.0, rtw.ptr, wl);
rtw.array[] *= ptw.array[];
sgemm(Order.RowMajor, Transpose.NoTrans, Transpose. Trans,
dl, tl, wl, 1.0, qdw.ptr, wl, ptw.ptr, wl, 0.0, rdt.ptr, tl);
foreach(d; 0..dl)
{
auto pt = pdt[d];
auto nw = ndw[d];
auto qw = qdw[d];
foreach(w; 0..wl)
qwd[w, d] = qw[w] = nw[w] / dotProduct(pt, pwt[w]);
}
foreach(t; 0..tl)
@9il
9il / matrix.d
Created September 12, 2013 18:08
struct Matrix(T)
{
this(size_t height, size_t width)
{
ptr = (new T[height * width]).ptr;
this.height = height;
this.width = width;
}
import std.stdio, std.datetime, std.uuid, std.conv;
struct NEW_UUID
{
union
{
ulong[2] ulongs;
static if(size_t.sizeof == 4)
uint[4] uints;
UUID id;
import std.datetime, std.stdio, std.uuid, std.traits;
void main()
{
import std.datetime, std.stdio, std.conv;
string str = "24c24a92-5fc8-11e5-9d70-feff819cdc9f";
ID id = ID("24c24a92-5fc8-11e5-9d70-feff819cdc9f");
UUID uuid = UUID("24c24a92-5fc8-11e5-9d70-feff819cdc9f");
size_t len;
auto b = benchmark!(
@9il
9il / ndslice_asm.d
Created December 25, 2015 07:50
NDSlice loops check
import std.experimental.ndslice;
//3D += number
void nd_test_val(Slice!(3, double*) slice, double value)
{
slice[] += value;
}
//3D += 1D
void nd_test_slice1(Slice!(3, double*) slice, Slice!(1, double*) value)