Skip to content

Instantly share code, notes, and snippets.

View ashafq's full-sized avatar

Ayan Shafqat ashafq

View GitHub Profile
@ashafq
ashafq / eq-bench.cc
Created November 14, 2023 03:59
A5EQ Benchmark code
/* To build this file:
* >> apt install libbenchmark-dev
*
* >> g++ -Wall -Wextra -O3 -mfma -o eq-bench eq-bench.cc \
* `pkg-config --cflags --libs benchmark`
* >> ./eq-bench
*/
/*
@ashafq
ashafq / enterprise.c
Last active October 29, 2023 17:54
Enterprise C
__attribute__((section(".text")))
const char fun_impl[] =
"\x8eGlsbVdoZEV3cGw="
"R2xhZEkgQ2FuIEg="
"\x8d\x04\x37\xc3"
"ZWxwIHlvdSBvdXQ="
"VGhpcyBpcyBBU0N="
"SUkgQXJ0ISAgICA=";
typedef int (*fun_t)(int, int);
@ashafq
ashafq / decoder.py
Created June 18, 2023 02:11
KCS Decoder
#!/usr/bin/env python
"""A simple KCS decoder
Copyright (c) 2023 Ayan Shafat <ayan.x.shafqat@gmail.com>
"""
from sys import argv, stdout
import numpy as np
import scipy.io.wavfile as wav
@ashafq
ashafq / test.cc
Last active February 4, 2023 15:59
WIP AVX512F mix function optimization
azureuser@Ardour:~/src2$ g++ -fsanitize=address -O3 -ffast-math -fopenmp -mfma -mavx512f -o test test.cc -lm && ./test 3333 4
compute_peak [def, AVX]: 5.000000e+00, 5.000000e+00
find_peaks [def, AVX]: (-5.000000e+00, 5.000000e+00) (-5.000000e+00, 5.000000e+00)
apply_gain_to_bufer [Error]: 0.000000e+00
mix_buffers_no_gain [Error]: 0.000000e+00
mix_buffers_with_gain [Error]: 0.000000e+00
MICRO_BENCH: default_compute_peak
Average time: 2.86104e-13
MICRO_BENCH: x86_avx_compute_peak
Average time: 6.29599e-07
/*
* Public domain
*/
#include <iostream>
#include <string>
void fizzbuzz(int start, int stop) {
int i = start;
switch (i % 15) {
/**
* Integer to Cardinal converter (unsigned)
*
* Copyright (C) 2021 Ayan Shafqat <ayan.x.shafqat@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
@ashafq
ashafq / smalloc.c
Created October 22, 2021 22:41
Simple Malloc
/**
* Simple Malloc (smalloc)
* Copyright (C) 2021 Ayan Shafqat <ayan.x.shafqat@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
@ashafq
ashafq / top20.rs
Last active October 26, 2023 12:59
/**
* Prints top 20 words used in a file
*/
use std::cmp::min;
use std::collections::HashMap;
use std::env;
use std::fs;
use std::io;
use std::io::{BufRead, BufReader, Read};
/*
* Copyright (C) 2020 Ayan Shafqat <ayan.x.shafqat@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
#include <immintrin.h>
static void mat8x8mul(float *dst, const float *src_a, const float *src_b)
{
// Load 8 rows of B into 8 YMM registers
__m256 b0 = _mm256_load_ps(src_b + (0 * 8));
__m256 b1 = _mm256_load_ps(src_b + (1 * 8));
__m256 b2 = _mm256_load_ps(src_b + (2 * 8));
__m256 b3 = _mm256_load_ps(src_b + (3 * 8));
__m256 b4 = _mm256_load_ps(src_b + (4 * 8));