Skip to content

Instantly share code, notes, and snippets.

View twatorowski's full-sized avatar

Tomasz twatorowski

View GitHub Profile
@twatorowski
twatorowski / __aeabi_lmul.s
Created September 22, 2025 07:39
c-m0p multiplication (mine vs gcc's, both on -Os)
08000264 <__aeabi_lmul>:
8000264: b5f0 push {r4, r5, r6, r7, lr}
8000266: 46ce mov lr, r9
8000268: 4699 mov r9, r3
800026a: 0c03 lsrs r3, r0, #16
800026c: 469c mov ip, r3
800026e: 0413 lsls r3, r2, #16
8000270: 4647 mov r7, r8
8000272: 0c1b lsrs r3, r3, #16
8000274: 001d movs r5, r3
@twatorowski
twatorowski / print_float.c
Created September 20, 2025 11:48
float to string
#include <stdio.h>
#include <stdbool.h>
#include <stdint.h>
#include <float.h>
/* return the smaller of two values */
#define min(a, b) \
({ __auto_type _a = (a); \
__auto_type _b = (b); \
_a < _b ? _a : _b; })
@twatorowski
twatorowski / main.c
Created July 19, 2025 09:02
Time profiling in C
#include <stdlib.h>
#include "timeit.h"
/* Shell sort with Ciura gap array */
static void shell_sort(int *arr, int n)
{
/* Marcin Ciura gap array */
static const int gaps[] = {701, 301, 132, 57, 23, 10, 4, 1};
static const int gap_cnt = sizeof(gaps)/sizeof(gaps[0]);
@twatorowski
twatorowski / log.h
Created June 9, 2025 08:51
logging for C programs
/**
* @file log.h
* @author Tomasz Watorowski (tomasz.watorowski@gmail.com)
* @date 2025-05-22
*
* @copyright Copyright (c) 2025
**/
#ifndef LOG_H
#define LOG_H
@twatorowski
twatorowski / stuff_to_get_me_random_numbers.c
Last active January 4, 2025 10:25
Generating pseudo-random numbers on small microcontrollers
#include <stdint.h>
#include <stdarg.h>
/* get the next value from the register taps: (32, 22, 2, 1, 0)*/
uint32_t LFSR32_Next(uint32_t x)
{
/* get the bit generated by the taps */
uint32_t bit = ((x >> 0) ^ (x >> 10) ^ (x >> 30) ^ (x >> 31)) & 1;
/* push the data around */
return ((x >> 1) | (bit << 31));
import numpy as np
import matplotlib.pyplot as plt
Fs = 48000
# signal frequency
F = 12000
# sampling frequency (4x the signal freq)
Fs = 4 * F
# initial phase offset in degrees