Skip to content

Instantly share code, notes, and snippets.

@aqrit
aqrit / lulz_itoa.c
Last active December 1, 2024 03:25
/*
convert integer to ascii
see also:
https://johnnylee-sde.github.io/Fast-unsigned-integer-to-string/
http://www.numberworld.org/y-cruncher/internals/radix-conversion.html
*/
#include <stdio.h>
#include <stdint.h>
#include <stddef.h>
#include <stdint.h>
/// flags
#define SVB_NORMAL 0
#define SVB_SPECIALCASEZERO 1
#define SVB_DELTAASCENDING 2
#define SVB_DELTADESCENDING 4
#define SVB_VARSIGNEXTEND 8
#include <stdint.h>
#include <immintrin.h>
// credit: YumiYumiYumi
// (fixed by aqrit)
__m128i _mm_tzcnt_epi32(__m128i v) {
__m128i mask = _mm_set1_epi32(0xffffff81);
v = _mm_and_si128(v, _mm_sign_epi32(v, mask));
v = _mm_castps_si128(_mm_cvtepi32_ps(v));
@aqrit
aqrit / despace.cpp
Last active May 4, 2024 21:04
remove whitespace characters
/*
* various methods to strip whitespace from text
* (aka. despace, leftpack, copy_if)
*
* 'whitespace' is considered the following bytes:
* 0x09 - tab
* 0x20 - space
* 0x0A - line feed
* 0x0D - carriage return
*/
@aqrit
aqrit / base64_decode_sse2_x64.asm
Last active March 28, 2017 21:38
Base64 decoder SSE2
; Base64 decoder test using SSE2 instructions
; the program doesn't do '=' chars, bad chars, or bounds checks...
;
; License: WTFPL
; by: aqrit <bitpatch.com> in 2016
;
; build instructions:
; yasm -f x64 -m AMD64 base64_decode_sse2_x64.asm
; Golink base64_decode_sse2_x64.obj kernel32.dll user32.dll
;;;;;;;;;;;;;;;;