Skip to content

Instantly share code, notes, and snippets.

View loicmolinari's full-sized avatar

Loïc Molinari loicmolinari

  • ShopShot3D
  • Lyon, France
View GitHub Profile
@loicmolinari
loicmolinari / boilerplate.py
Last active March 10, 2022 16:11
Boilerplate Python script for a CLI that reads from an input file and writes to an output file with default files set to stdin and stdout and with standard option names. Provides basic support for parsing command-line parameters of different types (integers, reals, flags, positional parameters, etc).
#!/usr/bin/env python3
import os
import sys
from typing import Tuple, List, Iterator, IO, Callable, Any
# Terminal ECMA-48 SGR escape sequences.
ECMA48_BOLD: str = '\x1b[01m'
ECMA48_RESET: str = '\x1b[00m'
@loicmolinari
loicmolinari / fast_pow10_division.md
Created May 22, 2020 13:23
Fast power-of-10 division using multiply and shift magic constants in a look-up table instead of a costly division operation.
U64
DivPow10(U64 a, S64 index)
{
    ASSERT(index >= 0 && index < 19);

    // Generated using libdivide's reference implementation adapted to 64-bit unsigned integers.
    static const struct { U64 mul; U32 shr1; U32 shr2; } kPow10Magics[19] = {
        { 0xcccccccccccccccd,  0,  3 },  // 10^1
        { 0x28f5c28f5c28f5c3,  2,  2 },  // 10^2
@loicmolinari
loicmolinari / branch_free_4xU8_cache.md
Created May 22, 2020 13:09
Branch free 4xU8 elements ring buffer cache
typedef struct {
    U32 elements;
    S32 position;
}  Cache;

void
CacheInit(Cache* cache)
{
    ASSERT(cache);
diff --git a/src/binary-writer.cc b/src/binary-writer.cc
index 3155c206..7ffc2c6d 100644
--- a/src/binary-writer.cc
+++ b/src/binary-writer.cc
@@ -809,13 +809,17 @@ void BinaryWriter::WriteLinkingSection() {
}
}
stream_->WriteU8Enum(sym.type, "symbol type");
- WriteU32Leb128(stream_, is_defined ? 0 : WABT_SYMBOL_FLAG_UNDEFINED,
+ WriteU32Leb128(stream_, is_defined ?
@loicmolinari
loicmolinari / opengl.md
Created September 22, 2018 13:13
OpenGL reminder

OpenGL

Here is a list of the biggest features and changes in OpenGL throughout the years.

OpenGL 1.1 (March 4, 1997)

  • 2D textures

OpenGL 1.2 (March 16, 1998)

x86-64 ASM sheet

Addressing

  • No segmentation (except for fs and gs for special purposes like threading)

  • Relative to base register

    • used for data on the stack, arrays, structs and class members
    • [base + index * scale + immediate_offset]
  • base is mandatory, can be any 64-bit register

@loicmolinari
loicmolinari / building_ripgrep_avx.md
Last active March 5, 2018 15:04
Building ripgrep with AVX support

Building ripgrep with AVX support

Get the Rust environment. Press enter to validate the default Rust installation settings and put the files for the current platform in $HOME/.cargo and $HOME/.rustup.

$ curl https://sh.rustup.rs -sSf | sh

Switch to nightly builds to get SIMD support.