Skip to content

Instantly share code, notes, and snippets.

View clausecker's full-sized avatar

Robert Clausecker clausecker

View GitHub Profile
@clausecker
clausecker / rdffrtest.c
Created October 19, 2023 21:56
Test the behaviour of rdffr with extending loads
/* test the behaviour of rdffr with extending loads */
#include <assert.h>
#include <arm_sve.h>
#include <sys/mman.h>
#include <stdio.h>
#include <unistd.h>
int main()
{
@clausecker
clausecker / caesar.s
Created October 8, 2020 18:01
Caesar cipher in x86 ASM with MMX
# MMX caeasar chiffre implementation
# for i686 with MMX
# signature:
# caesar(out, in, len, key)
# key is between 0 and 25
.section .text
.globl caesar
.type caesar,@function
.align 16
@clausecker
clausecker / getnumericvalue.S
Created September 2, 2020 14:19
summing decimal digits with different approaches
// getnumericvalue(ptr)
.section .text
.type getnumericvalue, @function
.globl getnumericvalue
getnumericvalue:
xor %eax, %eax // digit counter
// process string until we reach cache-line alignment
test $64-1, %dil // is ptr aligned to 64 byte?
jz 0f
@clausecker
clausecker / count8asm15.s
Created August 18, 2020 23:51
ARM64 8-bit position population count prototype
// b:a = a+b+c, v31.16b used for scratch space
.macro csa, a, b, c
eor v31.16b, \a\().16b, \b\().16b
eor \a\().16b, v31.16b, \c\().16b
bit \b\().16b, \c\().16b, v31.16b
.endm
// d:a = a+b+c
.macro csac a, b, c, d
eor \d\().16b, \a\().16b, \b\().16b
@clausecker
clausecker / mem.s
Created August 4, 2020 18:18
Vectorised positional popcount for Go
#include "textflag.h"
// func PospopcntMem(counts *[8]int32, buf []byte)
TEXT ·PospopcntMem(SB),NOSPLIT,$0-32
MOVQ counts+0(FP), DI
MOVQ buf_base+8(FP), SI // SI = &buf[0]
MOVQ buf_len+16(FP), CX // CX = len(buf)
SUBQ $32, CX // pre-subtract 32 bit from CX
JL scalar
@clausecker
clausecker / harness.c
Last active August 4, 2020 16:00
8 bit positional popcount with AVX2 without too much code
#define _XOPEN_SOURCE 700
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
extern void pospopcnt_reg(int accum[8], const char *buf, size_t len);
extern void pospopcnt_mem(int accum[8], const char *buf, size_t len);
extern void
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
extern int
main(int argc, char *argv[])
{
ssize_t count;
int flags;
@clausecker
clausecker / wc.c
Created October 17, 2019 14:41
parallel wc example
/* parallel wc(1) demo program */
/* cc -O3 -fopenmp -o wc wc.c */
#include <ctype.h>
#include <unistd.h>
#include <omp.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdbool.h>
#include <sys/stat.h>
@clausecker
clausecker / url.l
Last active October 2, 2019 23:10
Lexer that detects links in html documents
/* http://stackoverflow.com/a/1732454/417501 */
%{
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#define MYEOF EOF
#define TOKEN_URL 257
@clausecker
clausecker / locate.sh
Last active April 8, 2021 22:19
locate(1) as a CGI script
#!/bin/sh
PATH="$PATH:/usr/local/bin"
export LC_CTYPE=C
export LC_COLLATE=C
# decode URL encoded $1 and print result to stdout
urldecode() {
gawk "BEGIN { print \"$(echo "$1" | sed -e 's/"/\\"/' -e 's/+/ /g' -e 's/%/\\x/g')\" }" </dev/null
}