This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <immintrin.h> | |
#include <math.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <sys/time.h> | |
// PRNG modified from the public domain RKISS by Bob Jenkins. See: | |
// http://www.burtleburtle.net/bob/rand/smallprng.html | |
typedef struct { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Proof of optimality of 4-move solution to adversarial Wordle | |
# https://qntm.org/files/wordle/index.html | |
import array | |
import collections | |
with open('wordle-words.txt') as f: | |
normal_words = [word.strip() for word in f] | |
with open('wordle-fake-words.txt') as f: | |
all_words = [word.strip() for word in f] + normal_words |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Test address matching in store forwarding | |
# | |
# This tests a mechanism discussed in these references: | |
# | |
# * US Patent 2008/0082765 A1 | |
# https://patentimages.storage.googleapis.com/73/b9/bf/b258f3e3985f47/US20080082765A1.pdf | |
# * Fallout: Leaking Data on Meltdown-resistant CPUs | |
# https://mdsattacks.com/files/fallout.pdf | |
# * Stack Overflow: What are the microarchitectural details behind MSBDS (Fallout)? | |
# https://stackoverflow.com/a/56213609 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
from x86_info_term import get_cache | |
args, cache = get_cache() | |
uops_info = cache['datasets']['uops_info']['data'] | |
for inst in uops_info: | |
for form in uops_info[inst]['forms']: | |
if 'ICL' in form['arch'] and 'SKX' in form['arch']: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
def hamming(a, b): | |
x = a ^ b | |
c = 0 | |
while x: | |
x &= x - 1 | |
c += 1 | |
return c |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import collections | |
import contextlib | |
import sys | |
# Register class, for GPRs and vector registers | |
_Reg = collections.namedtuple('Reg', 't v') | |
class Reg(_Reg): | |
def __str__(self): | |
names = ['ax', 'cx', 'dx', 'bx', 'sp', 'bp', 'si', 'di'] | |
if self.t == 'r' and self.v < 8: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from fractions import Fraction | |
ascii = range(0, 0x80) | |
cont = range(0x80, 0xC0) | |
cont_2_0 = range(0xA0, 0xC0) | |
cont_2_2 = range(0x80, 0xA0) | |
cont_3_0 = range(0x90, 0xC0) | |
cont_3_2 = range(0x80, 0x90) | |
leader2 = range(0xC2, 0xE0) | |
leader3_0 = range(0xE0, 0xE1) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import itertools | |
N_BITS = 8 | |
MASK = (1 << N_BITS) - 1 | |
# Bit class, which stores values as a truth table of up to two variables | |
class Bit: | |
def __init__(self, op, bit_a=None, bit_b=None): | |
self.op = op | |
# Remove variables when the truth table doesn't depend on them |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
N_BITS = 8 | |
MASK = (1 << N_BITS) - 1 | |
class Ternary: | |
def __init__(self, ones, unknowns): | |
self.ones = ones & MASK | |
self.unknowns = unknowns & MASK | |
def __add__(self, other): | |
x = self.ones + other.ones | |
u = self.unknowns | other.unknowns | (x ^ (x + self.unknowns + other.unknowns)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
const int mask[4] = { 0x5555, 0x3333, 0x0F0F, 0x00FF }; | |
int count_table(int *table, char *lbl) { | |
int count, x; | |
for (count = x = 0; x < 1<<16; x++) | |
count += table[x]; |