Skip to content

Instantly share code, notes, and snippets.

@GoWind
GoWind / compile_program.sh
Created July 24, 2024 09:43
Popcount in a few instructions
as -o popcnt.o popcnt.s
gcc -c popcount.c
gcc popcnt.o popcount.o -o popo
import sys
import json
input_file = sys.argv[1]
output_file = sys.argv[2]
f = open(input_file, "r").read()
if len(f) == 0:
raise Exception("emputee file")
file_of_cells = json.loads(f)
@GoWind
GoWind / vector_norm.c
Created May 9, 2024 21:49
NEON vs normal implementation for Vector Norm
#include<arm_neon.h>
#include<stdio.h>
#include<time.h>
#include<stdlib.h>
#include <mach/mach_time.h>
#include<math.h>
#include<unistd.h>
int calculatePaddedLength(int n) {
int pad = (4 - (n % 4)) % 4;
@GoWind
GoWind / file.sh
Last active August 1, 2023 21:33
perf counter access for m1 mac (including pros)
gcc sgemm_ref.c -o sgemm_ref
sudo ./sgemm_ref
@GoWind
GoWind / adder_user.c
Last active July 12, 2023 15:26
Implementing custom atomic adder
#include<stdio.h>
#include<stdlib.h>
#include<stdatomic.h>
#include<pthread.h>
extern int atomic_adder(atomic_int*);
extern int atomic_adder_simple_32(atomic_int*, int y);
int simple_adder(int* x) {
int y = *x + 1;
@GoWind
GoWind / run_program.py
Created June 23, 2023 08:08
See the list of fns called by an executable
# Load lldb with the executable you want to debug first
# lldb --file your-exe
# load this command script
# command script import run_program.py
# this script installs a command rp that will run your executable and print the list of fn calls in the exe
import lldb
def run_program(debugger, command, result, internal_dict):
target = debugger.GetSelectedTarget()
```
thompson_nfa git:(thomson_nfa_zig) ✗ zig test src/main.zig
src/main.zig:127:45: error: use of undeclared identifier 'q_items'
try r.ensureTotalCapacity(p.items.len + q_items.len);
^
➜ thompson_nfa git:(thomson_nfa_zig) ✗ vim src/main.zig
➜ thompson_nfa git:(thomson_nfa_zig) ✗ zig test src/main.zig
src/main.zig:129:33: error: use of undeclared identifier 'q_items'
r.appendSliceAssumeCapacity(q_items);
^
@GoWind
GoWind / rememberhistory.clj
Created May 24, 2020 16:06
remember commands
#!/usr/bin/env bb
(defn what-to-do [arg]
(condp
= arg
"save" :save
arg))
(defn save-a-command
[db db-location args]
(ns transducertutorial.core)
;; a Reducing function is one that takes
;; an accumulator and an item
;; and returns a new accumulator with the item processed
(defn my-reducing-fn
[accumulator item]
(conj accumulator item))
;; conj is smart enough to know how to how to add the item to the
@GoWind
GoWind / ansisyscall.rs
Created May 17, 2019 17:14
Make syscalls from Rust lang
use std::io;
use std::io::Write;
use std::{thread, time};
use std::process::{Command, Stdio};
use rand::Rng;
use libc;
use nix::{ioctl_read_bad, convert_ioctl_res};
fn get_tty_rows_columns() -> Result<(i32, i32), String> {