Skip to content

Instantly share code, notes, and snippets.

View kg's full-sized avatar

Katelyn Gadd kg

View GitHub Profile
@kg
kg / _howto.md
Last active April 2, 2024 00:30
How to get native disassembly for a wasm module

How to get native disassembly for a wasm module out of Firefox's JS runtime

Build Spidermonkey from source

Follow steps 1 and 2 here: https://firefox-source-docs.mozilla.org/setup/linux_build.html#building-firefox-on-linux

Then set up a debug mozconfig and build using it as described here: https://firefox-source-docs.mozilla.org/js/build.html#developer-debug-build

Once you're done you should have a mozilla-unified/obj-debug-x86_64-pc-linux-gnu/dist/bin/js. Building from source is necessary to get the ability to disassemble native code.

@kg
kg / murmur3-streaming.c
Created March 30, 2024 22:01
Streaming version of 32-bit murmurhash3
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// MurmurHash3 was written by Austin Appleby, and is placed in the public
// domain. The author hereby disclaims copyright to this source code.
inline static uint32_t
ROTL32 (uint32_t x, int8_t r)
{
#include <stdint.h>
#define gint32 int32_t
#define guint32 uint32_t
#define guint64 uint64_t
#define guint8 uint8_t
typedef guint8 v128_u1 __attribute__ ((vector_size (16)));
typedef gint32 v128_i4 __attribute__ ((vector_size (16)));
@kg
kg / decodeFloat.js
Created March 25, 2012 10:53
Decode 32/64-bit float from bytes in JavaScript
// Derived from http://stackoverflow.com/a/8545403/106786
function decodeFloat(bytes, signBits, exponentBits, fractionBits, eMin, eMax, littleEndian) {
var totalBits = (signBits + exponentBits + fractionBits);
var binary = "";
for (var i = 0, l = bytes.length; i < l; i++) {
var bits = bytes[i].toString(2);
while (bits.length < 8)
bits = "0" + bits;
source_filename = "/app/example.cpp"
target datalayout = "e-m:e-p:32:32-p10:8:8-p20:8:8-i64:64-f128:64-n32:64-S128-ni:1:10:20"
target triple = "wasm32-unknown-emscripten"
%struct.DoubleBox = type { double }
%struct.UlongBox = type { i64 }
@__main_void = hidden alias i32 (), ptr @main
define hidden void @AcceptDouble(DoubleBox)(double %0) #0 !dbg !6 {
@kg
kg / MetaProject.csproj
Created April 3, 2022 10:43
Automatically compile game scripts as part of visual studio build
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<ProjectGuid>{29214583-65ED-44D0-8DC6-F57539C6BC8E}</ProjectGuid>
<OutputType>Library</OutputType>
<AssemblyName>HeavenLens.Scripts</AssemblyName>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<LangVersion>latest</LangVersion>
@kg
kg / text.txt
Created September 30, 2021 17:31
Deathloop spoilery Q&A + theories
Deathloop spoilers ahead (mostly earlier-game stuff in this section)
* Why do only Cole and Julianna remember?
Cole and Julianna aren't the only ones who remember. 2-Bit also
remembers, and he's made out of part of Charlie's brain. So why
doesn't Charlie remember? Wenjie's lab has at least one note where
she explicitly calls out that Cole and Julianna remember the loops
@kg
kg / userContent.css
Last active May 25, 2021 21:43
Funimation userstyle to make its web player not awful
@-moz-document domain("www.funimation.com")
{
div.ribbon, section.header-promo-ribbon-wrap {
display: none !important;
}
main#main-content {
padding: 0px !important;
}
@kg
kg / gist:a1fbdd2a68c76d85bebcbc8be98b4609
Created January 29, 2021 16:46
Current bindings benchmark timings
| Method | Mean | Error | StdDev | Median | Min | Max | Gen 0 | Gen 1 | Gen 2 | Allocated |
|---------------------------------------------------------- |-------------:|------------:|------------:|-------------:|-------------:|-------------:|--------:|------:|------:|----------:|
| CallMethod_Void | 6,500.488 us | 128.9937 us | 132.4670 us | 6,421.108 us | 6,386.649 us | 6,794.649 us | - | - | - | 2 B |
| CallMethod_Sum | 6,825.421 us | 46.6149 us | 41.3229 us | 6,832.778 us | 6,737.056 us | 6,900.194 us | - | - | - | 16,018 B |
| CallMethod_ConcatString | 8,885.143 us | 67.5927 us | 59.9192 us | 8,890.518 us | 8,783.607 us | 8,991.107 us | - | - | - | 96,043 B |
| CallMethod_ReturnString | 8,345.665 us | 66.346
1> FNA3D.vcxproj -> E:\Documents\Projects\FNA3D\visualc\..\..\FNALibs\x64\FNA3D.dll
Target RunNativeCodeAnalysis:
e:\documents\projects\fna3d\mojoshader\mojoshader.c(474): warning C6255: _alloca indicates failure by raising a stack overflow exception. Consider using _malloca instead.
e:\documents\projects\fna3d\mojoshader\mojoshader.c(2763): warning C6246: Local declaration of 'len' hides declaration of the same name in outer scope. For additional information, see previous declaration at line '2571' of 'e:\documents\projects\fna3d\mojoshader\mojoshader.c'.
e:\documents\projects\fna3d\mojoshader\mojoshader.c(3462): warning C6011: Dereferencing NULL pointer 'retval->output'.
e:\documents\projects\fna3d\mojoshader\mojoshader.c(3473): warning C6011: Dereferencing NULL pointer 'binary'. See line 3462 for an earlier location where this can occur
e:\documents\projects\fna3d\mojoshader\mojoshader.c(3589): warning C6246: Local declaration of 'usage' hides declaration of the same name in outer scope. For a