Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce header arb-defs.h #416

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export
SOURCES =
LIB_SOURCES = $(wildcard $(patsubst %, %/*.c, $(BUILD_DIRS))) $(patsubst %, %/*.c, $(TEMPLATE_DIRS))

HEADERS = $(patsubst %, %.h, $(BUILD_DIRS))
HEADERS = $(patsubst %, %.h, $(BUILD_DIRS)) arb-defs.h

OBJS = $(patsubst %.c, build/%.o, $(SOURCES))
LIB_OBJS = $(patsubst %, build/%/*.o, $(BUILD_DIRS))
Expand Down
148 changes: 148 additions & 0 deletions arb-defs.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
/*
Copyright (C) 2022 Albin Ahlbäck
Copyright (C) 2022 Fredrik Johansson
Comment on lines +2 to +3
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I really haven't contributed to this file's content, feel free to remove me here. Also feel free to change the order (I simply did alphabetical order (gissa vem som alltid var högst upp på klasslistan 😉)).


This file is part of Arb.

Arb is free software: you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License (LGPL) as published
by the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version. See <http://www.gnu.org/licenses/>.
*/

#include "flint/flint.h"

#ifndef ARB_DEFS_H
#define ARB_DEFS_H

#ifdef __cplusplus
extern "C" {
#endif

#define __ARB_VERSION 2
#define __ARB_VERSION_MINOR 22
#define __ARB_VERSION_PATCHLEVEL 1

#define ARB_VERSION "2.22.1"

#define __ARB_RELEASE (__ARB_VERSION * 10000 + \
__ARB_VERSION_MINOR * 100 + \
__ARB_VERSION_PATCHLEVEL)


#define TLS_PREFIX FLINT_TLS_PREFIX

#if defined(_MSC_VER) && defined(ARB_BUILD_DLL)
#define ARB_DLL __declspec(dllexport)
#else
#define ARB_DLL FLINT_DLL
#endif


#ifndef flint_abort
#if __FLINT_RELEASE <= 20502
#define flint_abort abort
#endif
#endif

#if __FLINT_RELEASE < 20600
#define flint_bitcnt_t ulong
#endif


#define LIMB_ONE ((mp_limb_t) 1)
#define LIMB_ONES (-(mp_limb_t) 1)
#define LIMB_TOP (((mp_limb_t) 1) << (FLINT_BITS - 1))
#define MASK_LIMB(n, c) ((n) & (LIMB_ONES << (c)))


/* FLINT_ABS is unsafe for x = WORD_MIN */
#define UI_ABS_SI(x) (((slong)(x) < 0) ? (-(ulong)(x)) : ((ulong)(x)))


#define nn_mul_2x1(r2, r1, r0, a1, a0, b0) \
do { \
mp_limb_t t1; \
umul_ppmm(r1, r0, a0, b0); \
umul_ppmm(r2, t1, a1, b0); \
add_ssaaaa(r2, r1, r2, r1, 0, t1); \
} while (0)

#define nn_mul_2x2(r3, r2, r1, r0, a1, a0, b1, b0) \
do { \
mp_limb_t t1, t2, t3; \
umul_ppmm(r1, r0, a0, b0); \
umul_ppmm(r2, t1, a1, b0); \
add_ssaaaa(r2, r1, r2, r1, 0, t1); \
umul_ppmm(t1, t2, a0, b1); \
umul_ppmm(r3, t3, a1, b1); \
add_ssaaaa(r3, t1, r3, t1, 0, t3); \
add_ssaaaa(r2, r1, r2, r1, t1, t2); \
r3 += r2 < t1; \
} while (0)


#ifndef NEWTON_INIT

#define NEWTON_INIT(from, to) \
{ \
slong __steps[FLINT_BITS], __i, __from, __to; \
__steps[__i = 0] = __to = (to); \
__from = (from); \
while (__to > __from) \
__steps[++__i] = (__to = (__to + 1) / 2); \

#define NEWTON_BASECASE(bc_to) { slong bc_to = __to;

#define NEWTON_END_BASECASE }

#define NEWTON_LOOP(step_from, step_to) \
{ \
for (__i--; __i >= 0; __i--) \
{ \
slong step_from = __steps[__i+1]; \
slong step_to = __steps[__i]; \

#define NEWTON_END_LOOP }}

#define NEWTON_END }

#endif


ARB_DLL extern const char * arb_version;

double arb_test_multiplier(void);

/* counts zero bits in the binary representation of e */
static __inline__
int
n_zerobits(mp_limb_t e)
{
int zeros = 0;

while (e > 1)
{
zeros += !(e & 1);
e >>= 1;
}

return zeros;
/* FIXME: Why doesn't the following work? */
/* #ifdef __GMP_SHORT_LIMB */
/* return (FLINT_BITS - 1) - __builtin_popcount(e); */
/* #else */
/* # ifdef _LONG_LONG_LIMB */
/* return (FLINT_BITS - 1) - __builtin_popcountll(e); */
/* # else */
/* return (FLINT_BITS - 1) - __builtin_popcountl(e); */
/* # endif */
/* #endif */
albinahlback marked this conversation as resolved.
Show resolved Hide resolved
}


#ifdef __cplusplus
}
#endif

#endif
11 changes: 0 additions & 11 deletions arb.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,6 @@
extern "C" {
#endif

#define __ARB_VERSION 2
#define __ARB_VERSION_MINOR 22
#define __ARB_VERSION_PATCHLEVEL 1
#define ARB_VERSION "2.22.1"
#define __ARB_RELEASE (__ARB_VERSION * 10000 + \
__ARB_VERSION_MINOR * 100 + \
__ARB_VERSION_PATCHLEVEL)

ARB_DLL extern const char * arb_version;
double arb_test_multiplier(void);

typedef struct
{
arf_struct mid;
Expand Down
43 changes: 0 additions & 43 deletions arb_poly.h
Original file line number Diff line number Diff line change
Expand Up @@ -730,22 +730,6 @@ arb_poly_allocated_bytes(const arb_poly_t x)

/* Macros */


/* counts zero bits in the binary representation of e */
ARB_POLY_INLINE int
n_zerobits(mp_limb_t e)
{
int zeros = 0;

while (e > 1)
{
zeros += !(e & 1);
e >>= 1;
}

return zeros;
}

/* Computes the length of the result when raising a polynomial of
length *len* to the power *exp* and truncating to length *trunc*,
without overflow. Assumes poly_len >= 1. */
Expand All @@ -760,33 +744,6 @@ poly_pow_length(slong poly_len, ulong exp, slong trunc)
return FLINT_MIN((slong) lo, trunc);
}

#ifndef NEWTON_INIT

#define NEWTON_INIT(from, to) \
{ \
slong __steps[FLINT_BITS], __i, __from, __to; \
__steps[__i = 0] = __to = (to); \
__from = (from); \
while (__to > __from) \
__steps[++__i] = (__to = (__to + 1) / 2); \

#define NEWTON_BASECASE(bc_to) { slong bc_to = __to;

#define NEWTON_END_BASECASE }

#define NEWTON_LOOP(step_from, step_to) \
{ \
for (__i--; __i >= 0; __i--) \
{ \
slong step_from = __steps[__i+1]; \
slong step_to = __steps[__i]; \

#define NEWTON_END_LOOP }}

#define NEWTON_END }

#endif

#ifdef __cplusplus
}
#endif
Expand Down
30 changes: 0 additions & 30 deletions arf.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,6 @@
#include "fmpr.h"
#include "mag.h"

#ifndef flint_abort
#if __FLINT_RELEASE <= 20502
#define flint_abort abort
#endif
#endif

#ifdef __cplusplus
extern "C" {
#endif
Expand Down Expand Up @@ -439,9 +433,6 @@ arf_init_set_ui(arf_t x, ulong v)
}
}

/* FLINT_ABS is unsafe for x = WORD_MIN */
#define UI_ABS_SI(x) (((slong)(x) < 0) ? (-(ulong)(x)) : ((ulong)(x)))

ARF_INLINE void
arf_init_set_si(arf_t x, slong v)
{
Expand Down Expand Up @@ -805,27 +796,6 @@ void arf_urandom(arf_t x, flint_rand_t state, slong bits, arf_rnd_t rnd);
#define MUL_MPFR_MIN_LIMBS 25
#define MUL_MPFR_MAX_LIMBS 10000

#define nn_mul_2x1(r2, r1, r0, a1, a0, b0) \
do { \
mp_limb_t t1; \
umul_ppmm(r1, r0, a0, b0); \
umul_ppmm(r2, t1, a1, b0); \
add_ssaaaa(r2, r1, r2, r1, 0, t1); \
} while (0)

#define nn_mul_2x2(r3, r2, r1, r0, a1, a0, b1, b0) \
do { \
mp_limb_t t1, t2, t3; \
umul_ppmm(r1, r0, a0, b0); \
umul_ppmm(r2, t1, a1, b0); \
add_ssaaaa(r2, r1, r2, r1, 0, t1); \
umul_ppmm(t1, t2, a0, b1); \
umul_ppmm(r3, t3, a1, b1); \
add_ssaaaa(r3, t1, r3, t1, 0, t3); \
add_ssaaaa(r2, r1, r2, r1, t1, t2); \
r3 += r2 < t1; \
} while (0)

#define ARF_MPN_MUL(_z, _x, _xn, _y, _yn) \
if ((_xn) == (_yn)) \
{ \
Expand Down
10 changes: 1 addition & 9 deletions bool_mat.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,12 @@
#include <stdio.h>
#include "flint/flint.h"
#include "flint/fmpz_mat.h"

#ifndef flint_abort
#if __FLINT_RELEASE <= 20502
#define flint_abort abort
#endif
#endif
#include "arb-defs.h"

#ifdef __cplusplus
extern "C" {
#endif

/* currently defined in the arb module, but global to the library */
double arb_test_multiplier(void);

typedef struct
{
int *entries;
Expand Down
8 changes: 1 addition & 7 deletions dlog.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,9 @@
#endif

#include "flint/flint.h"

#ifndef flint_abort
#if __FLINT_RELEASE <= 20502
#define flint_abort abort
#endif
#endif

#include "flint/ulong_extras.h"
#include "flint/nmod_vec.h"
#include "arb-defs.h"

#ifdef __cplusplus
extern "C" {
Expand Down
23 changes: 1 addition & 22 deletions fmpr.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,8 @@
#include "flint/flint.h"
#include "flint/fmpz.h"
#include "flint/fmpq.h"
#if __FLINT_RELEASE < 20600
#include "flint/config.h"
#else
#include "flint/flint-config.h"
#endif
#include "fmpz_extras.h"

#ifndef flint_abort
#if __FLINT_RELEASE <= 20502
#define flint_abort abort
#endif
#endif

#define TLS_PREFIX FLINT_TLS_PREFIX

#if defined(_MSC_VER) && defined(ARB_BUILD_DLL)
#define ARB_DLL __declspec(dllexport)
#else
#define ARB_DLL FLINT_DLL
#endif
#include "arb-defs.h"

#define fmpr_rnd_t int
#define FMPR_RND_DOWN 0
Expand All @@ -54,9 +36,6 @@
extern "C" {
#endif

/* currently defined in the arb module, but global to the library */
double arb_test_multiplier(void);

static __inline__ int
rounds_up(fmpr_rnd_t rnd, int negative)
{
Expand Down
14 changes: 1 addition & 13 deletions fmpz_extras.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,12 @@
#include <limits.h>
#include "flint/flint.h"
#include "flint/fmpz.h"
#include "arb-defs.h"

#ifdef __cplusplus
extern "C" {
#endif

#ifndef flint_abort
#if __FLINT_RELEASE <= 20502
#define flint_abort abort
#endif
#endif

#if __FLINT_RELEASE < 20600
#define flint_bitcnt_t ulong
#endif

/* currently defined in the arb module, but global to the library */
double arb_test_multiplier(void);

static __inline__ void
fmpz_add_inline(fmpz_t z, const fmpz_t x, const fmpz_t y)
{
Expand Down
Loading