Skip to content

Instantly share code, notes, and snippets.

View CharCoding's full-sized avatar
💻
Confused

Charly Cui CharCoding

💻
Confused
View GitHub Profile
@CharCoding
CharCoding / gol_simd.c
Created July 6, 2023 00:10
Conway's Game of Life, 256x256 wrapped around, SIMD
// Compile on linux with `gcc gol_simd.c -O3 -march=native` with a modern intel CPU
#include <stdio.h>
#include <stdint.h>
#include <unistd.h>
#include <time.h>
#include <string.h>
#include <x86intrin.h>
#include <wchar.h>
#include <locale.h>
@CharCoding
CharCoding / pixel-scaling.css
Last active January 24, 2020 03:12 — forked from pixelpicosean/pixel-scaling.css
Pixel-art scaling on HTML5 canvas
canvas {
image-rendering: pixelated;
image-rendering: crisp-edges;
image-rendering: -moz-crisp-edges;
image-rendering: -webkit-optimize-contrast;
-ms-interpolation-mode: nearest-neighbor;
}
@CharCoding
CharCoding / bf.asm
Created March 25, 2019 12:11
NASM tests
; nasm -f elf printf-test.asm && gcc -m32 -o printf-test printf-test.o
; Variables
; multiplier a --> edx (doesn't work; using [mult])
; adder b --> ebx
; term x --> eax
; count i --> ecx
; x + 1 --> esi
; mask --> 255
; masj --> 254 = mask - 1
section .data
// gcc bfparallel.c -std=c17 -O3 -march=native -fno-stack-protector -Wall -Wextra -Werror -pedantic -o bfparallel
#include <stdio.h>
#include <pthread.h>
#include <signal.h>
#include <stdint.h>
#ifndef THREAD_COUNT
#define THREAD_COUNT 16
#endif
#ifndef modulus
#define modulus 0x7ffffff
@CharCoding
CharCoding / fn.js
Last active March 30, 2024 16:28
JavaScript miscellaneous functions collection
Math.umul = (a, b) => {
const aLow = a & 65535;
return (b * (a - aLow) >>> 0) + (b * aLow) >>> 0;
};
Math.umulhl = (a, b) => Uint32Array.of(a * b * 2.3283064365386963e-10, Math.umul(a, b));
Math.umul64 = (aHi, aLo, bHi, bLo) => {
const a0 = aHi & 65535, a1 = aHi - a0, a2 = aLo & 65535, a3 = aLo - a2,
lohi = bLo * a0 + (bLo * a1 >>> 0) >>> 0,
hilo = bHi * a2 + (bHi * a3 >>> 0) >>> 0,
carry = aLo * bLo * 2.3283064365386963e-10 >>> 0;
@CharCoding
CharCoding / annexation.json
Last active October 11, 2016 17:51
Edit gist
{
"name":"Charly",
"money":16,
"Capital":{"x":6,"y":5},
"Cities":[
{"x":4,"y":5}, {"x":6,"y":7}
],
"Colonies":[
{"x":5,"y":4}, {"x":7,"y":6}
],