Skip to content

Instantly share code, notes, and snippets.

@animetosho
animetosho / gf-affine-mul8-gen.c
Created November 28, 2022 12:07
Compute Affine table for GF(2^8) multiplication with 0x11d polynomial
#include <stdio.h>
#include <x86intrin.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
int main(void) {
__m128i polymask1 = _mm_set1_epi64x(0xff00ffffff000000ULL); // polynomial 0x11d: 0x1d = 0b11101, reverse bits -> 10111000, then replace 1->ff, 0->00
for(int val=0; val<256; val++) {
#include <stdint.h>
typedef unsigned char U8;
typedef unsigned short U16;
typedef unsigned int U32;
typedef unsigned long long U64;
typedef intptr_t SINTa;
struct KernelState
{
@animetosho
animetosho / galois-field-affine-uses.md
Last active February 6, 2024 00:42
A list of “out-of-band” uses for the GF2P8AFFINEQB instruction I haven’t seen documented elsewhere

Count Leading/Trailing Zero Bits (Byte-wise)

Counting the trailing zero bit count (TZCNT) can be done by isolating the lowest bit, then depositing this into the appropriate locations for the count. The leading zero bit count (LZCNT) can be done by reversing bits, then computing the TZCNT.

__m128i _mm_tzcnt_epi8(__m128i a) {
	// isolate lowest bit
	a = _mm_andnot_si128(_mm_add_epi8(a, _mm_set1_epi8(0xff)), a);
	// convert lowest bit to index
; NOTE: all just a quick sketch
; also I'm using xmm/ymm/zmm0-5 and then 16-31
; because Win64 ABI expects me to preserve ymm6-ymm15
; and I couldn't be bothered to set up a stack frame and save them :)
;
; Meant to be assembled with NASM
section .data
vone dd 1
@Daniel15
Daniel15 / 1_README.md
Last active February 12, 2024 19:14
Complete Google Drive File Picker example

Google Drive File Picker Example

This is an example of how to use the Google Drive file picker and Google Drive API to retrieve files from Google Drive using pure JavaScript. At the time of writing (14th July 2013), Google have good examples for using these two APIs separately, but no documentation on using them together.

Note that this is just sample code, designed to be concise to demonstrate the API. In a production environment, you should include more error handling.

See a demo at http://stuff.dan.cx/js/filepicker/google/