Skip to content

Instantly share code, notes, and snippets.

Avatar

Simon Lindholm simonlindholm

View GitHub Profile
View bitarray-par.cpp
#ifdef USE_AVX256
#pragma GCC target ("avx2")
#else
#define NDEBUG
#pragma GCC target ("avx512f,avx512bw")
#endif
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize ("O4")
#include <bits/stdc++.h>
#include <immintrin.h>
View modmul-simd.cpp
#include <bits/stdc++.h>
#include <immintrin.h>
using namespace std;
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define trav(a, x) for (auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
View incl.h
namespace ttmath{typedef unsigned int U;typedef signed int sint;typedef uint64_t ulint;typedef int64_t slint;}namespace ttmath{enum LibTypeCode{asm_vc_32=0,asm_gcc_32,asm_vc_64,asm_gcc_64,no_asm_32,no_asm_64};enum ErrorCode{err_ok=0,err_nothing_has_read,err_unknown_character,err_unexpected_final_bracket,err_stack_not_clear,err_unknown_variable,err_division_by_zero,err_interrupt,err_overflow,err_unknown_function,err_unknown_operator,err_unexpected_semicolon_operator,err_improper_amount_of_arguments,err_improper_argument,err_unexpected_end,err_internal_error,err_incorrect_name,err_incorrect_value,err_variable_exists,err_variable_loop,err_functions_loop,err_must_be_only_one_value,err_object_exists,err_unknown_object,err_still_calculating,err_in_short_form_used_function,err_percent_from};struct Conv{U base;bool scient;sint scient_from;bool base_round;sint round;bool trim_zeroes;U comma;U comma2;U group;U group_digits;U group_exp;Conv(){base=10;scient=false;scient_from=15;base_round=true;round=-1;trim_zeroes=true;
View seqdecoder.py
#!/usr/bin/env python3
import sys
commands = {}
commands['seq'] = {
# non-arg commands
0xff: ['end'],
0xfe: ['delay1'],
0xfd: ['delay', 'var'],
0xfc: ['call', 'addr'],
@simonlindholm
simonlindholm / barrett.cpp
Created Apr 18, 2019
Fast modulo (via Barrett reduction, works for arbitrary 64-bit integers except d = 1)
View barrett.cpp
typedef long long ll;
typedef unsigned long long ull;
typedef __uint128_t L;
struct Barrett {
ull d, m;
Barrett(ull d) : d(d), m(ull((L(1) << 64) / d)) {}
ull reduce(ull a) {
ull q = (ull)((L(m) * a) >> 64);
View fast-mod.cpp
typedef unsigned long long ull;
struct FastMod {
ull multiplier;
ull divisor;
int shift_size;
int mode = 0;
FastMod(ull divisor) : divisor(divisor) {
shift_size = 64 - __builtin_clzll(divisor) - 1;
if (divisor & (divisor - 1)) {
auto a = (__uint128_t)1 << (shift_size + 64);
@simonlindholm
simonlindholm / __init__.py
Last active Nov 1, 2020
pycparser type annotations
View __init__.py
# -----------------------------------------------------------------
# pycparser: __init__.py
#
# This package file exports some convenience functions for
# interacting with pycparser
#
# Eli Bendersky [https://eli.thegreenplace.net/]
# License: BSD
# -----------------------------------------------------------------
__all__ = ["c_parser", "c_ast"]
@simonlindholm
simonlindholm / breakage.md
Created Mar 23, 2019
What would break if CSS introduced single-line comments?
View breakage.md
@simonlindholm
simonlindholm / kattio.js
Created Nov 30, 2018
Kattio.js - fast IO for NodeJS
View kattio.js
var fs = require("fs");
var Kattio = {
_buf: new Buffer(1 << 14),
_bufPos: 0,
_bufLen: 0,
_ensure: function() {
if (this._bufPos === this._bufLen) {
this._bufPos = 0;
this._bufLen = fs.readSync(0, this._buf, 0, this._buf.length, null);
}
View keybase.md

Keybase proof

I hereby claim:

  • I am simonlindholm on github.
  • I am simonlindholm (https://keybase.io/simonlindholm) on keybase.
  • I have a public key ASDb0pN28sqNZe8GMR2mkeenn3ctqeYgFfLO7SMSvOwKAQo

To claim this, I am signing this object: