Skip to content

Instantly share code, notes, and snippets.

View cyanreg's full-sized avatar

Lynne cyanreg

View GitHub Profile
@cyanreg
cyanreg / ANSI.md
Created August 9, 2021 10:44 — forked from fnky/ANSI.md
ANSI Escape Codes

ANSI Escape Sequences

Standard escape codes are prefixed with Escape:

  • Ctrl-Key: ^[
  • Octal: \033
  • Unicode: \u001b
  • Hexadecimal: \x1b
  • Decimal: 27
@cyanreg
cyanreg / tx_float_init.c
Created April 19, 2021 13:10
FFmpeg transform debugging code
/*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* FFmpeg is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
@cyanreg
cyanreg / tx_float.asm
Last active April 20, 2021 23:59
libavutil/tx x86 assembly
;******************************************************************************
;* Copyright (c) Lynne
;*
;* This file is part of FFmpeg.
;*
;* FFmpeg is free software; you can redistribute it and/or
;* modify it under the terms of the GNU Lesser General Public
;* License as published by the Free Software Foundation; either
;* version 2.1 of the License, or (at your option) any later version.
;*
@cyanreg
cyanreg / qmf_forward.c
Created March 13, 2021 19:27
Forward QMF
void forward_qmf(float *out_low, float *out_high, float *delay, const float *in,
int samples, int delay_samples)
{
memcpy(delay, delay + samples, delay_samples * sizeof(float));
memcpy(delay + delay_samples, in, samples * sizeof(float));
for (int i = 0; i < samples; i += 2) {
float low = 0.0f, high = 0.0f;
/* Can be done via float_dsp */
@cyanreg
cyanreg / fft_split_radix_recombine.c
Last active April 2, 2021 14:47
Split-Radix recombine loop
#define BF(x, y, a, b) \
do { \
x = (a) - (b); \
y = (a) + (b); \
} while (0)
#define BUTTERFLIES_MIX(a0,a1,a2,a3, P1, P2, P5, P6) \
do { \
r0=a0.re; \
i0=a0.im; \
@cyanreg
cyanreg / fft8_double.c
Created March 9, 2021 03:17
8-point FFT (2x at a time)
static void fft8(void *s, FFTComplex *z, FFTComplex *temp)
{
FFTSample r1 = z[0].re - z[4].re;
FFTSample r2 = z[0].im - z[4].im;
FFTSample r3 = z[1].re - z[5].re;
FFTSample r4 = z[1].im - z[5].im;
FFTSample j1 = z[2].re - z[6].re;
FFTSample j2 = z[2].im - z[6].im;
FFTSample j3 = z[3].re - z[7].re;
@cyanreg
cyanreg / fft16.c
Last active March 3, 2021 11:02
16-point FFT
// from https://gist.github.com/cyanreg/665b9c79cbe51df9296a969257f2a16c
static void fft4(FFTComplex *z)
{
FFTSample r1 = z[0].re - z[4].re;
FFTSample r2 = z[0].im - z[4].im;
FFTSample r3 = z[1].re - z[5].re;
FFTSample r4 = z[1].im - z[5].im;
/* r5-r8 second transform */
FFTSample t1 = z[0].re + z[4].re;
@cyanreg
cyanreg / fft4.c
Last active March 7, 2021 21:15
4-point FFT
static void fft4(void *s, FFTComplex *z, FFTComplex *temp)
{
FFTSample r1 = z[0].re - z[2].re;
FFTSample r2 = z[0].im - z[2].im;
FFTSample r3 = z[1].re - z[3].re;
FFTSample r4 = z[1].im - z[3].im;
/* r5-r8 second transform */
FFTSample t1 = z[0].re + z[2].re;
FFTSample t2 = z[0].im + z[2].im;
@cyanreg
cyanreg / fft8.c
Last active January 27, 2021 02:01
8-point FFT (permuted input)
static void fft8(FFTComplex *z)
{
FFTSample r1 = z[0].re - z[4].re;
FFTSample r2 = z[0].im - z[4].im;
FFTSample r3 = z[1].re - z[5].re;
FFTSample r4 = z[1].im - z[5].im;
FFTSample r5 = z[2].re - z[6].re;
FFTSample r6 = z[2].im - z[6].im;
FFTSample r7 = z[3].re - z[7].re;
@cyanreg
cyanreg / latency.txt
Last active December 13, 2020 15:58 — forked from jboner/latency.txt
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers (~2012)
----------------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD