Skip to content

Instantly share code, notes, and snippets.

View racko.py
# Rack-O simulation
import random
class GreedyHeuristicPlayer():
def getScore(self, rack):
return 1
def choose(self, rack, newCard):
bestScore = self.getScore(rack)
View gist:3320068
#include <stdio.h>
static long long int positionsEvaluated = 0;
int inOrder(const int rack[10])
{
int i;
int last = 0;
for (i = 0; i < 10; i++)
@jbush001
jbush001 / import_blogger_images.py
Created Dec 31, 2016
Import blogger images into Jekyll
View import_blogger_images.py
# Jekyll will import posts from Blogger, but they still contain image
# references to Blogger's CDN. This script:
# - Finds all image references in an imported blogger page
# - Downloads the images into the assets/ directory
# - Rewrites the page with the appropriate image link
import re
import sys
import urllib
@jbush001
jbush001 / jekll_html2text_wrapper.py
Created Jan 1, 2017
Convert HTML to markup for Jekyll
View jekll_html2text_wrapper.py
#
# The Jekyll import tool (http://import.jekyllrb.com/docs/blogger/)
# creates HTML files. I'd like to use html2text
# (https://github.com/aaronsw/html2text) to convert those to Markdown.
# The challenge is that Jekyll files have a YAML header at the top that gets
# mangled by the conversion. This strips the header, passes the remainder
# of the body into html2text, then adds the header back to the result.
#
import os
@jbush001
jbush001 / mktorus.py
Created May 14, 2017
Create 3D model of a Torus
View mktorus.py
#!/usr/bin/env python
#
# Copyright 2011-2015 Jeff Bush
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
@jbush001
jbush001 / testfloat.txt
Last active May 28, 2017
Generating floating point test cases with Berkeley testfloat
View testfloat.txt
git clone https://github.com/ucb-bar/berkeley-testfloat-3.git
git clone https://github.com/ucb-bar/berkeley-softfloat-3.git
cd berkeley-softfloat-3/build/Linux-386-GCC/
make
cd ../../../berkeley-testfloat-3/build/Linux-386-GCC/
make
./testfloat_gen -precision32 f32 2 f32_add | awk '{ print "{ FADD, 0x" $1 ", 0x" $2 ", 0x" $3 " }," }' > test_cases.inc
./testfloat_gen -precision32 f32 2 f32_sub | awk '{ print "{ FSUB, 0x" $1 ", 0x" $2 ", 0x" $3 " }," }' >> test_cases.inc
./testfloat_gen -precision32 f32 2 f32_mul | awk '{ print "{ FMUL, 0x" $1 ", 0x" $2 ", 0x" $3 " }," }' >> test_cases.inc
./testfloat_gen -precision32 f32 f32_to_i32 | awk '{ print "{ ITOF, 0x" $1 ", 0x" $2 ", 0x" $3 " }," }' >> test_cases.inc
@jbush001
jbush001 / conventions.md
Last active Jun 4, 2017
Documentation Conventions
View conventions.md

Prefer present tense

No:

This function will update the value

Yes:

This function updates the value

Motivation: To be consistent and avoid switching tenses. Present tense is slightly more concise to write. It also avoids implying something hasn't been implemented yet.

View semaphore.md

Problem Description

Currently, the primitive for inter-thread/core synchronization is a spinlock, which is supported on this processor using the sync_load and sync_store instructions. This requires busy waiting, as the processor checks the variable in a tight loop until it changes.

On a multithreaded processor, this steals cycles that could be used by other threads. In the worst case, multiple threads may be waiting for a lock held by another thread on the same core, which slows it down and increases contention.

View large_tlb.md

Problem Description

The current Nyuzi TLB implementation caches virtual->physical translations on a page granularity, where pages are fixed size at 4k. However, the performance of programs that touch a large area of memory can be limited by the overhead of handling TLB misses. A way to mitigate this is to allow mapping pages that are larger than 4k, usually a power-of-two multiple like 4MB. Example use cases include mapping a physical memory alias into the kernel and mapping a graphics framebuffer (which is often contiguous).

Implementation

Although the TLB implementation is software managed and thus technically could use any encoding for page translations,

View coprocessor-memory-interface.md

Problem Description

Writes to addresses at high physical memory addresses, instead of going through the normal cache hierachy, use a special I/O bus. While this is useful for relatively low-speed peripherals, it has performance limitiations when used with coprocessors such as texture fetch units:

  • It can only write a single, 32-bit word at a time. For vectorized compute code, this requires 32 instructions to copy a vector value into our out of it (getlane/write).
  • It takes a rollback for every read or write, since the I/O bus is shared by all cores and transactions need to globally arbitrate