Skip to content

Instantly share code, notes, and snippets.

View thoughtpolice's full-sized avatar
👊
omae wa mou shindeiru

Austin Seipp thoughtpolice

👊
omae wa mou shindeiru
View GitHub Profile
@thoughtpolice
thoughtpolice / ksuid.ts
Created June 9, 2023 02:21
Standalone implementation of KSUIDs for TypeScript
// SPDX-License-Identifier: MIT
// SPDX-FileCopyrightText: 2017-2021 Mark Wubben <mark@novemberborn.net>
// SPDX-FileCopyrightText: 2017-2023 Segment.io
// SPDX-FileCopyrightText: 2023 Austin Seipp <aseipp@pobox.com>
// Implementation of KSUIDs, a K-Sortable Globally Unique IDentifier, as defined
// by https://github.com/segmentio/ksuid -- this is a port of the upstream
// project to typescript/deno, with some modifications.
//
// External API based on the one from https://github.com/novemberborn/ksuid,
#include <stddef.h>
char get_first_cap(const char *in, int size) {
const char *first_cap = NULL;
if (size == 0)
return ' ';
for (int i = 0 ; i++ < size && *in != 0; in++) {
if (*in >= 'A' && *in <= 'Z') {
first_cap = in;
@thoughtpolice
thoughtpolice / Assert.hs
Last active January 21, 2023 07:01
Formal verification of a Clash circuit, using Yosys/SymbiYosys.
{-# LANGUAGE GADTs #-}
{-# LANGUAGE ImplicitParams #-}
{-# LANGUAGE TypeFamilies #-}
module Assert
( assertProperty
, initialAssume
, getReset
) where
import Clash.Prelude
with Ada.Command_Line;
with Ada.Text_IO;
procedure Hello_World is
You : constant String :=
-- Change to strict inequality below to prove
(if Ada.Command_Line.Argument_Count >= 0 then
Ada.Command_Line.Argument (1)
else "世界");
begin
//! this program exists only to launch RPCS3, pointed to the Tekken Tag
//! Tournament 2 ROM on my hard drive, with Steam Remote Play. there are a very
//! weird set of circumstances leading to this:
//!
//! as a prerequisite: modern Steam supports a full userspace gamepad input
//! device stack, called "Steam Input". games launched by steam have the Steam
//! Overlay injected into them, which also handles Steam Input. in effect, Steam
//! Input allows arbitrary gamepads, such as PS4 DualShocks or Nintendo Joycons,
//! or even exotic devices like Hitbox/PS4 Hori Fightpads, to be registered and
//! control mapped on the system, entirely through Steam and without any other
@thoughtpolice
thoughtpolice / RegAlloc1.hs
Last active July 26, 2022 13:49
Simple register allocation, see "Essentials of Compilation" for more https://jeapostrophe.github.io/courses/2017/spring/406/notes/book.pdf
{-# OPTIONS_GHC -Wall #-}
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE PartialTypeSignatures #-}
module RegAlloc1
( -- * Types
Var
@thoughtpolice
thoughtpolice / questa-example.do
Created February 10, 2022 23:55
intel questa simulation example
# Setup compilation
set QSYS_SIMDIR ../prj
source $QSYS_SIMDIR/mentor/msim_setup.tcl
dev_com
com
# add sources, but skip the top level BSP since its unused
foreach f [glob -type f path/to/sources/*.sv] {
vlog -sv -work work "$f"
}
@thoughtpolice
thoughtpolice / mmult.c
Created December 28, 2021 02:48
matrix multiply with clang extended vector types
#include <stdint.h>
#include <stddef.h>
#include <stdbool.h>
#ifndef __wasm__
#define LLVM_MCA_BEGIN(l) __asm__ __volatile__("# LLVM-MCA-BEGIN " l);
#define LLVM_MCA_END(l) __asm__ __volatile__("# LLVM-MCA-END " l);
#else
#define LLVM_MCA_BEGIN(_)
#define LLVM_MCA_END(_)
@thoughtpolice
thoughtpolice / llvm-static-musl.nix
Created January 11, 2019 00:34
Static C++17 binaries with Clang, Musl, and libc++, using Nix
{ useMusl ? false
}:
let
nixpkgs = import (builtins.fetchTarball {
url = "https://github.com/NixOS/nixpkgs/archive/004cb5a694e39bd91b27b0adddc127daf2cb76cb.tar.gz";
sha256 = "0v5pfrisz0xspd3h54vx005fijmhrxwh0la7zmdk97hqm01x3mz4";
}) {};
pkgs = if useMusl then nixpkgs.pkgsMusl else nixpkgs;
#! /usr/bin/env bluetcl
# bsc-libdir: a tcl script that looks up Verilog primitives for
# the bluespec compiler, and emits them to stdout. this tool
# is more useful when combined with `bsc-rpc`, but might be
# of use on its own.
#
# usage:
#
# $ bluetcl bsc-libdir RegUN > RegUN.v