Skip to content

Instantly share code, notes, and snippets.

Avatar
🍥
bottomless pit

Francesco Mazzoli bitonic

🍥
bottomless pit
View GitHub Profile
View test-avx2.cpp
/*
Benchmark for Eigen change, see <https://gitlab.com/libeigen/eigen/-/merge_requests/734#note_743674873>
Comment reported here for posterity:
Here's a synthetic "benchmark" which I _believe_ shows the difference: https://gist.github.com/bitonic/2d09df858ba2233b7f472f5f8c0512b4 .
I say that I believe that it exhibits the difference because it shows the runtime differences that I'd expect, with some caveats (see comments on number of instructions below).
However, I have not inspected the assembly manually to check that the code varies in the way I'd expect, which would be a requirement to ensure that things change in the way we expect. That is a bit more labor intensive, and while I might do it, I don't have time to do it right now.
@bitonic
bitonic / configuration.nix
Last active Nov 25, 2021
NixOS configuration for a remote ZFS server on Hetzner
View configuration.nix
# Full NixOS configuration for a ZFS server with full disk encryption hosted on Hetzner.
# See <https://mazzo.li/posts/hetzner-zfs.html> for more information.
{ config, pkgs, ... }:
let
# Deployment-specific parameters -- you need to fill these in where the ... are
hostName = "...";
publicKey = "...";
# From `ls -lh /dev/disk/by-id`
View mathematica.nix
{ lib
, stdenv
, coreutils
, callPackage
, makeWrapper
, requireFile
, python3
, writeTextFile
, binutils
, patchelf
@bitonic
bitonic / vectorized-atan2f.cpp
Last active Aug 25, 2021
Vectorized & branchless atan2f
View vectorized-atan2f.cpp
// Copyright (c) 2021 Francesco Mazzoli <f@mazzo.li>
//
// Permission to use, copy, modify, and distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
View value-speculation-linux.c
// See <https://gist.github.com/pervognsen/b58108d134824e61caedffcc01004e03> for
// Per Vognsen gist on value speculation.
//
// I compile this on linux with
//
// $ clang --version
// clang version 12.0.0
// Target: x86_64-unknown-linux-gnu
// $ clang -static -Wall -O3 value-speculation-linux.c -o value-speculation-linux
//
View forward.hs
{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE RecordWildCards #-}
import Data.List (transpose)
data Forward a = Forward { _value :: !a, _grad :: !a }
deriving (Show, Eq)
lift :: Num a => a -> Forward a
lift a = Forward { _value = a, _grad = 0 }
@bitonic
bitonic / reverse.hs
Last active Mar 22, 2021
Simple reverse AD
View reverse.hs
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE BangPatterns #-}
{-# OPTIONS_GHC -Wall #-}
import Data.IORef
View nixos desktop
# Edit this configuration file to define what should be installed on
# your system. Help is available in the configuration.nix(5) man page
# and in the NixOS manual (accessible by running ‘nixos-help’).
{ config, pkgs, ... }:
{
imports =
[ # Include the results of the hardware scan.
./hardware-configuration.nix
View nixos-install-hetzner-cloud.sh
#! /usr/bin/env bash
# Script to install NixOS from the Hetzner Cloud NixOS bootable ISO image.
# (tested with Hetzner's `NixOS 20.03 (amd64/minimal)` ISO image).
#
# This script wipes the disk of the server!
#
# Instructions:
#
# 1. Mount the above mentioned ISO image from the Hetzner Cloud GUI
@bitonic
bitonic / poly.ts
Created Jun 5, 2020
polygon cube intersection in threejs
View poly.ts
function signNonZero(x: number): number {
return x < 0 ? -1 : 1;
}
function inClosedInterval(a: number, x: number, b: number): boolean {
return (x-a) * (x-b) <= 0;
}
function segContainsPoint(a: number, b: number, x: number): number {
return (b > x ? 1 : 0) - (a > x ? 1 : 0);