Skip to content

Instantly share code, notes, and snippets.

View 0x1F9F1's full-sized avatar
🧱

Brick 0x1F9F1

🧱
  • Nottingham, United Kingdom
View GitHub Profile
@0x1F9F1
0x1F9F1 / neon.c
Created October 10, 2023 21:49
Rough attempt and some neon audio conversion
void SDL_Convert_S8_to_F32_NEON(const Sint8* src, float* dst)
{
uint8x16_t flipper = vdupq_n_u8(0x80);
uint32x4_t caster = vdupq_n_u32(0x47800000u);
float32x4_t offset = vdupq_n_f32(-65537.0f);
uint8x16_t bytes = veorq_u8(vld1q_u8((const uint8_t*) src), flipper);
uint16x8_t shorts1 = vmovl_u8(vget_low_u8(bytes));
uint16x8_t shorts2 = vmovl_u8(vget_high_u8(bytes));
@0x1F9F1
0x1F9F1 / blend.cpp
Last active September 10, 2023 09:49
Thoughts on SDL_BLENDMODE_BLEND
#include <stdint.h>
uint8_t blend_classic(uint8_t sC, uint8_t dC, uint8_t sA)
{
// The blend equation as specified in SDL_BLENDMODE_BLEND, which uses 2 multiplies and a divide
return ((sC * sA) + (dC * (255 - sA))) / 255;
}
uint8_t blend_sdl(uint8_t sC, uint8_t dC, uint8_t sA)
{
#include <stdint.h>
#include <stddef.h>
#include <stdio.h>
#include <string.h>
uint32_t joaat_loop(const uint8_t* key, size_t length, uint32_t hash)
{
size_t i = 0;
while (i != length) {
@0x1F9F1
0x1F9F1 / casefold.cpp
Created June 22, 2022 13:15
Case Folding
#include <vector>
using u16 = uint16_t;
using u32 = uint32_t;
using usize = size_t;
// clang-format off
static const u16 casefold_mph_tab[] {
0x563,0x4B3,0x040,0x04C,0x4C2,0x36A,0x50F,0x2F8,0x09F,0x587,0x150,0x20A,0x4D0,0x34E,0x2D1,0x1E8,
0x5AD,0x0F2,0x133,0x3CF,0x567,0x179,0x423,0x5E3,0x33D,0x51B,0x577,0x2F6,0x2DD,0x33A,0x23E,0x52C,
@0x1F9F1
0x1F9F1 / gf2.py
Last active March 1, 2023 09:58
Python class for performing matrix operations over GF(2)
# https://wiki.sagemath.org/quickref?action=AttachFile&do=get&target=quickref-linalg.pdf
# https://github.com/emin63/pyfinite
# https://github.com/malb/m4ri
from functools import reduce
import sys
def extract_rows(table):
'''
Extracts a set linearly independent rows from a lookup table
@0x1F9F1
0x1F9F1 / lcg.cpp
Last active March 27, 2022 12:50
Fun with LCG's
#include <cstdint>
bool PolyMul(uint32_t from, uint32_t to, uint32_t& out_mul)
{
for (; ~from & 1; from >>= 1, to >>= 1) {
if (to & 1)
return false;
}
uint32_t result = 0;
@0x1F9F1
0x1F9F1 / sdl_app.cpp
Last active October 3, 2021 13:15
An example of using WM_PAINT and WM_TIMER with SDL2 to allow updates when moving/resizing
#include <SDL.h>
#include <SDL_opengl.h>
#include <SDL_syswm.h>
#include <Windows.h>
enum class UpdateReason
{
Main,
@0x1F9F1
0x1F9F1 / int_cast.cpp
Last active August 22, 2021 18:25
Safely cast integers
#include <limits>
#include <type_traits>
enum class int_cast_mode
{
lossless,
check_sign,
check_max,
check_trip,
};
#include <cstddef>
#include <cstdint>
#include <initializer_list>
#include <limits>
#include <type_traits>
constexpr std::size_t popcount(std::uint8_t value) noexcept
{
value -= (value >> 1) & 0x55;
value = (value & 0x33) + ((value >> 2) & 0x33);
@0x1F9F1
0x1F9F1 / read_bndb_snapshot.py
Created February 14, 2019 16:41
Convert a bndb snapshot to json
import struct
import json
if True:
import lzf # pip install python-lzf
else:
import ctypes
class lzf:
_lzf_dll = ctypes.CDLL('lzf.dll')