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
#include "gr.h"
#include "arf.h"
#include "mpn_extras.h"
#include "crt_helpers.h"
typedef struct
{
slong sign;
slong exp;
mp_limb_t d[4];
@fredrik-johansson
fredrik-johansson / taylortest.c
Created March 7, 2024 19:54
Taylor experiment
#include <math.h>
#include "longlong.h"
#include "ulong_extras.h"
#include "mpn_extras.h"
#include "arf.h"
#include "arb.h"
#include "profiler.h"
/* util: print fixed-point number given by n limbs where fracn limbs are fractional. */
void
#include <stdint.h>
#include "profiler.h"
#include "mpn_extras.h"
#include "crt_helpers.h"
#include "ulong_extras.h"
FLINT_FORCE_INLINE mp_limb_t
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
fredrik-johansson / addmul1.c
Last active December 8, 2023 22:24
mpn instrinsics
#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) \
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
fredrik-johansson / color_function.py
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):
/*
Generic Flint-style rings using void pointers + context objects.
todo: write -> print
Principles/goals/benefits:
* 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
fredrik-johansson / nmul.c
Created April 5, 2021 12:32
Some new nmod_poly multiplication code
#include "flint/nmod_poly.h"
#include "flint/profiler.h"
/*
Multiplication/squaring using Kronecker substitution at 2^b and -2^b.
*/
void
_nmod_poly_mul_KS2B(mp_ptr res, mp_srcptr op1, slong n1,
mp_srcptr op2, slong n2, nmod_t mod)
@fredrik-johansson
fredrik-johansson / matperf.c
Created March 22, 2021 19:48
Some old matrix profiling code
#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
fredrik-johansson / rademacher.py
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