Skip to content

Instantly share code, notes, and snippets.

View fredrik-johansson's full-sized avatar
Deep into the code

Fredrik Johansson fredrik-johansson

Deep into the code
View GitHub Profile
View mulhigh.c
#include <stdint.h>
#include "profiler.h"
#include "mpn_extras.h"
#include "crt_helpers.h"
#include "ulong_extras.h"
flint_mpn_inline_addmul_1(mp_ptr res, mp_srcptr a, mp_size_t n, mp_limb_t c)
mp_limb_t hi, lo, cy_limb;
fredrik-johansson / addmul1.c
Last active December 8, 2023 22:24
mpn instrinsics
View addmul1.c
#include <x86intrin.h>
#include "flint.h"
#include "longlong.h"
#include "ulong_extras.h"
#include "mpn_extras.h"
#include "profiler.h"
#define umul_ppmm_mulx(w1, w0, u, v) \
__asm__ ("mulx\t%3, %q0, %q1" \
: "=r" (w0), "=r" (w1) \
View gist:b6b65bbab0c0c3eaf583976d0ab1ecbc
bits euclidean binary euclidean_improved
8 3.46e-07 5.05e-07 9.09e-08
16 5.91e-07 7.61e-07 1.65e-07
32 9.65e-07 1.55e-06 2.26e-07
64 5.48e-06 3.89e-06 1.05e-06
128 2.45e-05 1.4e-05 7.41e-06
256 6.06e-05 3.57e-05 1.82e-05
512 0.00015 4.11e-05
1024 0.000459 0.000103
2048 0.00176 0.000248
fredrik-johansson /
Created February 16, 2022 20:31
Color functions
from colorsys import hls_to_rgb, rgb_to_hls
import math
import cmath
CLAMP = lambda y: max(0.0, min(y, 1.0))
BLEND = lambda x, y: 0.5*x + 0.5*y
DODGE = lambda a, b: a / (1.0 - b + 1/256.0)
# gimp color balance algorithm
def balance_channel(value, l, shadows, midtones, highlights):
View gr.c
Generic Flint-style rings using void pointers + context objects.
todo: write -> print
* Small code size, fast compilation.
* Possible to pack data efficiently (down to 1 byte / element).
* Plain C, similar interface to existing Flint code.
fredrik-johansson / nmul.c
Created April 5, 2021 12:32
Some new nmod_poly multiplication code
View nmul.c
#include "flint/nmod_poly.h"
#include "flint/profiler.h"
Multiplication/squaring using Kronecker substitution at 2^b and -2^b.
_nmod_poly_mul_KS2B(mp_ptr res, mp_srcptr op1, slong n1,
mp_srcptr op2, slong n2, nmod_t mod)
fredrik-johansson / matperf.c
Created March 22, 2021 19:48
Some old matrix profiling code
View matperf.c
#include "flint/fmpz_mat.h"
#include "flint/profiler.h"
#define TIMEIT_PRINT1(__var, __timer, __reps) \
__var = __timer->cpu*0.001/__reps;
#define TIMEIT_REPEAT1(__timer, __reps) \
do \
{ \
slong __timeit_k; \
fredrik-johansson /
Created July 28, 2020 18:07
Extended Rademacher series
from flint import fmpq, fmpz
from cmath import *
from mpmath import plot
def dedekind_sum(r, k, _cache={}):
key = (r << 24) | k
if key in _cache:
return _cache[key]
if fmpz(r).gcd(k) != 1:
v = None
View illinois.c
#include "acb_dirichlet.h"
/* todo: separate prec, eval_prec... */
acb_dirichlet_zeta_zero_refine_illinois(arb_t res, const arf_t ra, const arf_t rb, slong prec)
arf_t a, b, fa, fb, c, fc, t;
acb_t z;
slong k;
int asign, bsign, csign;
fredrik-johansson / Arbdemo.ipynb
Created February 11, 2019 17:18
View Arbdemo.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.