Skip to content

Instantly share code, notes, and snippets.

View ashafq's full-sized avatar

Ayan Shafqat ashafq

View GitHub Profile
#include <math.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <unistd.h>
/**
* @brief A shitty password generator in C++
*/
//
// It's 2019, yet no command line parsers in C++ :'(
//
#include <boost/program_options.hpp>
namespace opt = boost::program_options;
@ashafq
ashafq / fizzbuzz.S
Created May 8, 2020 17:23
Fizzbuzz in RV32IM assembly
//
// FizzBuzz in RISC-V Assembly
// build: riscv64-elf-gcc -mcmodel=medany -nostdlib \
// -march=rv32im -mabi=ilp32 -o start start.s
// run: Open in Ripes simulator ;)
//
.section .rodata
// Strings need to be aliged to two byte boundaries
#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));
/*
* 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
@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};
@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,
/**
* 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.
*
/*
* Public domain
*/
#include <iostream>
#include <string>
void fizzbuzz(int start, int stop) {
int i = start;
switch (i % 15) {
@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