Skip to content

Instantly share code, notes, and snippets.

View submachine's full-sized avatar

Arjun Shankar submachine

  • Brno, Czech Republic
View GitHub Profile
@submachine
submachine / memhash.c
Created July 6, 2012 23:34
A toy x86_64 pointer-hash benchmark to go with the StackOverflow answer at: http://stackoverflow.com/a/11364619/274261
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdbool.h>
#define HASH_BITS 10
#define BUCKETS (1 << HASH_BITS)
/* A half-avalanche 4 byte integer hash function, as described at:
http://burtleburtle.net/bob/hash/integer.html */
@submachine
submachine / xrenderstring.c
Created July 27, 2012 10:50
A program that takes: font, string, and renders accordingly using Xlib. Almost a verbatim copy of the one at: http://www.lemoda.net/c/xlib-text-box/index.html
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <X11/Xlib.h>
/* The window which contains the text. */
struct
{
int width;
@submachine
submachine / omp_atomic_capture_example.c
Created September 18, 2012 09:34
An atomic 'fetch and add' using OpenMP directives
/* Compiling with `gcc -fopenmp -m32 -O2 -S' produces:
movl $1, %eax
lock xaddl %eax, j
movl %eax, i
ret
*/
int i, j;
void foo (void)
@submachine
submachine / gen_rand_dag.c
Created October 9, 2012 00:37
A quick-n-dirty random DAG generator
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
/* http://stackoverflow.com/q/12790337/274261 */
/* Generates random DAGs. The key is to 'rank' the nodes, and
only draw edges from lower ranked nodes to higher ranked ones. */
/* Nodes/Rank: How 'fat' the DAG should be. */
@submachine
submachine / keep-pushing.c
Last active December 23, 2015 17:59
Keep pushing till we run out of stack area.
#include <stdio.h>
#include <string.h>
unsigned int stack_size;
struct huge_argument /* Not the verbal kind ;). */
{
char x[512];
};
@submachine
submachine / hello-pthread.c
Last active December 28, 2015 18:48
A 'Hello World!' program unnecessarily using libpthread
/*
gcc -O0 -std=c99 -pedantic -Wall -Werror -lpthread \
-o hello-pthread hello-pthread.c
*/
/* Enable 2008 edition functionality of POSIX.1,
required for pthread_rwlock_* functions. */
#define _POSIX_C_SOURCE 200809L
#include <stdio.h>
@submachine
submachine / glibc-tester.sh
Last active January 3, 2016 09:29
A [work in progress] script to fetch, build, and test fresh glibc sources.
#!/bin/bash
# TODO: Parse and report testsuite failures;
# fetch and execute gnulib testsuite.
GT_NAME=glibc-tester
GT_DIR=$HOME/.$GT_NAME
GT_CONFIG=$GT_DIR/config
if [ ! -d $GT_DIR ]; then
@submachine
submachine / tst-append-ftell.c
Last active August 29, 2015 13:57
A sequence of calls to test ftell with fseek/rewind/fread/fwrite functions while in append mode.
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include <unistd.h>
const char *data = "zzzzzzzzzz";
const char *more_data = "aaaaaaaaaa";
#define TEST_FILE_PATH "tst-rewind-ftell.out"
@submachine
submachine / glibc-use-test-skeleton.sh
Last active August 29, 2015 14:07
[committed] script to automatically modify as many glibc test cases as possible into using test-skeleton.c
#!/bin/bash
SRC_DIR=~/src/glibc/
pushd $SRC_DIR &> /dev/null \
|| { echo Unable to enter directory $SRC_DIR 1>&2; exit 1; }
let blkl=0
let good=0
let main=0
@submachine
submachine / tst-stack-switch-x86_64-linux.c
Created February 16, 2015 23:37
A program that tests valgrind's '--max-stackframe' option on an x86-64 running Linux
/*
$ gcc -Wall -pedantic -o test-stack-switching test-stack-switching.c
$ valgrind ./test-stack-switching
Expected program output:
> 55
> 55
> 55
Expected valgrind output: Three warnings that look like;