Skip to content

Instantly share code, notes, and snippets.

View Raimo33's full-sized avatar
🧪

Raimo Raimo33

🧪
  • Florence, Italy
  • 03:13 (UTC +02:00)
View GitHub Profile
@Raimo33
Raimo33 / sort.c
Created April 4, 2025 17:32
branchless list sort
/*
description:
takes pointers to the head and tail of the singly-linked list.
sorts the list in ascending order by ASCII value.
implementation:
use of mergesort because linked lists inherently don't provide random access. could be bypassed by constructing an array of pointers but that's a poor design choice O(n)...
merge sort is the fastest known sorting algo for linked lists, even though finding the midpoint is O(n/2) = O(n).
use of the slow-fast pointer technique to find the midpoint of the list. same performance as the doubly-linked list -> <- approach.
implemented by changing pointers, even though a char is 1 byte and easier to copy, for better mantainability, reusability, and standard compliance.
@Raimo33
Raimo33 / strtolower.c
Last active March 3, 2025 19:48
SIMD strtolower
//TODO find a way to make them const, forcing prevention of thread safety issues, constexpr??
#ifdef __AVX512F__
static __m512i _512_vec_A_minus_1;
static __m512i _512_vec_case_range;
static __m512i _512_add_mask;
#endif
#ifdef __AVX2__
static __m256i _256_vec_A_minus_1;
static __m256i _256_vec_case_range;
@Raimo33
Raimo33 / speed_optimizations.md
Last active April 4, 2025 17:17
C Speed Optimizations

C Speed Optimization Checklist

This is a list of general-purpose optimizations for C programs, from the most impactful to the tiniest low-level micro-optimizations to squeeze out every last bit of performance. It is meant to be read top-down as a checklist, with each item being a potential optimization to consider. Everything is in order of speed gain.

Algorithm && Data Structures

Choose the best algorithm and data structure for the problem at hand by evaluating:

  1. time complexity
@Raimo33
Raimo33 / pre-commit
Last active March 22, 2025 10:23
Header pre-commit
#!/usr/bin/env python3
import os
import subprocess
import datetime
import re
CREATOR_NAME = "Claudio Raimondi"
CREATOR_EMAIL = "[email protected]"
HEADER_WIDTH = 80
@Raimo33
Raimo33 / Makefile
Last active December 22, 2024 23:16
Docker Compose Makefile
# **************************************************************************** #
# #
# ::: :::::::: #
# Makefile :+: :+: :+: #
# +:+ +:+ +:+ #
# By: craimond <[email protected]> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2024/08/06 01:09:08 by craimond #+# #+# #
# Updated: 2024/09/15 14:24:42 by craimond ### ########.fr #
# #
@Raimo33
Raimo33 / .clang-format
Last active June 4, 2024 19:39
c++ formatting
BasedOnStyle: LLVM
IndentWidth: 4
TabWidth: 4
UseTab: Always
BreakBeforeBraces: Custom
AllowShortIfStatementsOnASingleLine: true
ColumnLimit: 0
AccessModifierOffset: -2
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: false
@Raimo33
Raimo33 / Makefile
Last active June 21, 2024 08:52
Makefile Standard (c++)
# **************************************************************************** #
# #
# ::: :::::::: #
# Makefile :+: :+: :+: #
# +:+ +:+ +:+ #
# By: craimond <[email protected]> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2024/04/26 15:33:59 by craimond #+# #+# #
# Updated: 2024/06/21 10:51:48 by craimond ### ########.fr #
# #