Skip to content

Commit

Permalink
Merge pull request #1974 from albinahlback/declude_longlong
Browse files Browse the repository at this point in the history
Declude longlong
  • Loading branch information
albinahlback authored May 15, 2024
2 parents 8c395e8 + 2a6c93c commit 0d6152b
Show file tree
Hide file tree
Showing 57 changed files with 345 additions and 204 deletions.
11 changes: 0 additions & 11 deletions doc/source/flint.rst
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,6 @@ The file ``flint.h`` contains various useful macros.
Returns the sign of `x` where `x` is interpreted as a :type:`slong`, that
is, returns `-1` if `x < 0`, `0` if `x = 0` and `1` if `x > 0`.

.. function:: flint_bitcnt_t FLINT_BIT_COUNT(ulong x)

Returns the number of binary bits required to represent *x*. If *x* is zero
it returns *0*. This is an inline-function only.

.. macro:: FLINT_FLOG2(x)
FLINT_CLOG2(x)

For `x \ge 1`, it returns `\lfloor \log_2 x \rfloor`
and `\lceil \log_2 x \rceil`, respectively.

Integer types
-----------------------------------------------

Expand Down
13 changes: 12 additions & 1 deletion doc/source/longlong.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
**longlong.h** -- support functions for multi-word arithmetic
===============================================================================

Leading and trailing zeroes
Bit manipulation
-------------------------------------------------------------------------------

.. macro:: flint_clz(x)
Expand All @@ -18,6 +18,17 @@ Leading and trailing zeroes
As for ``flint_clz()``, but counts from the least significant end. If `x` is
zero then the return value is undefined.

.. function:: flint_bitcnt_t FLINT_BIT_COUNT(ulong x)

Returns the number of binary bits required to represent *x*. If *x* is zero
it returns *0*. This is an inline-function only.

.. macro:: FLINT_FLOG2(x)
FLINT_CLOG2(x)

For `x \ge 1`, it returns `\lfloor \log_2 x \rfloor`
and `\lceil \log_2 x \rceil`, respectively.

Addition and subtraction
-------------------------------------------------------------------------------

Expand Down
1 change: 1 addition & 0 deletions src/bernoulli/bound_2exp_si.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
(at your option) any later version. See <https://www.gnu.org/licenses/>.
*/

#include "longlong.h"
#include "bernoulli.h"

const short bernoulli_bound_tab[256] = {
Expand Down
1 change: 1 addition & 0 deletions src/bool_mat/pow_ui.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
(at your option) any later version. See <https://www.gnu.org/licenses/>.
*/

#include "longlong.h"
#include "bool_mat.h"

void
Expand Down
2 changes: 1 addition & 1 deletion src/crt_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
# include <intrin.h>
#endif

#include "flint.h"
#include "longlong.h"
#include "templates.h"

#ifdef __cplusplus
Expand Down
21 changes: 15 additions & 6 deletions src/d_mat/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
(at your option) any later version. See <https://www.gnu.org/licenses/>.
*/

#include "long_extras.h"
#include "d_mat.h"

void
Expand All @@ -18,13 +19,24 @@ d_mat_init(d_mat_t mat, slong rows, slong cols)
slong i;

if (rows != 0)
mat->rows = (double **) flint_malloc(rows * sizeof(double *));
mat->rows = flint_malloc(rows * sizeof(double *));
else
mat->rows = NULL;

if (rows != 0 && cols != 0) /* Allocate space for r*c small entries */
mat->r = rows;
mat->c = cols;

if (rows != 0 && cols != 0)
{
mat->entries = (double *) flint_calloc(flint_mul_sizes(rows, cols), sizeof(double));
slong num;
int of;

of = z_mul_checked(&num, rows, cols);

if (of)
flint_throw(FLINT_ERROR, "Overflow creating a %wd x %wd object\n", rows, cols);

mat->entries = flint_calloc(num, sizeof(double));

for (i = 0; i < rows; i++)
mat->rows[i] = mat->entries + i * cols;
Expand All @@ -35,7 +47,4 @@ d_mat_init(d_mat_t mat, slong rows, slong cols)
for (i = 0; i < rows; i++)
mat->rows[i] = NULL;
}

mat->r = rows;
mat->c = cols;
}
1 change: 1 addition & 0 deletions src/fft_small.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#ifndef FFT_SMALL_H
#define FFT_SMALL_H

#include "longlong.h"
#include "machine_vectors.h"

#define LG_BLK_SZ 8
Expand Down
35 changes: 0 additions & 35 deletions src/flint.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,6 @@ typedef const ulong * nn_srcptr;
# endif
#endif

#include "longlong.h"

/* memory ********************************************************************/

FLINT_WARN_UNUSED FLINT_MALLOC FLINT_RETURNS_NONNULL void * flint_malloc(size_t size);
Expand Down Expand Up @@ -366,25 +364,6 @@ FLINT_INLINE ulong n_randint(flint_rand_t state, ulong limit)
#define FLINT_SGN(x) ((0 < (slong)(x)) - ((slong)(x) < 0))
#define FLINT_SWAP(T, x, y) do { T _swap_t = (x); (x) = (y); (y) = _swap_t; } while(0)

#define r_shift(in, shift) \
((shift == FLINT_BITS) ? WORD(0) : ((in) >> (shift)))

#define l_shift(in, shift) \
((shift == FLINT_BITS) ? WORD(0) : ((in) << (shift)))

/* Beware when using the unsigned return value in signed arithmetic */
FLINT_FORCE_INLINE
flint_bitcnt_t FLINT_BIT_COUNT(ulong x)
{
flint_bitcnt_t zeros = FLINT_BITS;
if (x) zeros = flint_clz(x);
return FLINT_BITS - zeros;
}

#define FLINT_FLOG2(k) (FLINT_BIT_COUNT(k) - 1)

#define FLINT_CLOG2(k) FLINT_BIT_COUNT((k) - 1)

/* allocation macros *********************************************************/

#define FLINT_ARRAY_ALLOC(n, T) (T *) flint_malloc((n)*sizeof(T))
Expand Down Expand Up @@ -463,20 +442,6 @@ typedef enum

FLINT_NORETURN void flint_throw(flint_err_t exc, const char * msg, ...);

/* checked multiplication ****************************************************/

FLINT_INLINE slong flint_mul_sizes(slong x, slong y)
{
ulong hi, lo;

umul_ppmm(hi, lo, (ulong) x, (ulong) y);

if (hi != 0 || lo > WORD_MAX)
flint_throw(FLINT_OVERFLOW, "Overflow creating size %wd x %wd object.\n", x, y);

return lo;
}

/* FLINT generic type definitions ********************************************/

typedef struct
Expand Down
19 changes: 14 additions & 5 deletions src/fmpq_mat/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,32 @@
(at your option) any later version. See <https://www.gnu.org/licenses/>.
*/

#include "long_extras.h"
#include "fmpq_mat.h"

void fmpq_mat_init(fmpq_mat_t mat, slong rows, slong cols)
{
slong i;

if (rows != 0)
mat->rows = (fmpq **) flint_malloc(rows * sizeof(fmpq *));
mat->rows = flint_malloc(rows * sizeof(fmpq *));
else
mat->rows = NULL;

mat->r = rows;
mat->c = cols;

if (rows != 0 && cols != 0)
{
mat->entries = (fmpq *) flint_calloc(flint_mul_sizes(rows, cols), sizeof(fmpq));
slong num;
int of;

of = z_mul_checked(&num, rows, cols);

if (of)
flint_throw(FLINT_ERROR, "Overflow creating a %wd x %wd object\n", rows, cols);

mat->entries = flint_calloc(num, sizeof(fmpq));

/* Set denominators */
for (i = 0; i < rows * cols; i++)
Expand All @@ -41,7 +53,4 @@ void fmpq_mat_init(fmpq_mat_t mat, slong rows, slong cols)
mat->rows[i] = NULL;
}
}

mat->r = rows;
mat->c = cols;
}
1 change: 1 addition & 0 deletions src/fmpz.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

#include <gmp.h>
#include "fmpz_types.h"
#include "longlong.h"

#ifdef __cplusplus
extern "C" {
Expand Down
19 changes: 14 additions & 5 deletions src/fmpz_lll/mpf-impl.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
(at your option) any later version. See <https://www.gnu.org/licenses/>.
*/

#include "long_extras.h"
#include "gmpcompat.h"
#include "mpf-impl.h"
#include "fmpz.h"
Expand Down Expand Up @@ -108,10 +109,22 @@ _mpf_vec_dot2(mpf_t res, const mpf * vec1, const mpf * vec2, slong len2, flint_b
void
mpf_mat_init(mpf_mat_t mat, slong rows, slong cols, flint_bitcnt_t prec)
{
mat->r = rows;
mat->c = cols;
mat->prec = prec;

if (rows != 0 && cols != 0)
{
slong i;
mat->entries = flint_malloc(flint_mul_sizes(rows, cols) * sizeof(mpf));
slong num;
int of;

of = z_mul_checked(&num, rows, cols);

if (of)
flint_throw(FLINT_ERROR, "Overflow creating a %wd x %wd object\n", rows, cols);

mat->entries = flint_malloc(num * sizeof(mpf));
mat->rows = flint_malloc(rows * sizeof(mpf *));

for (i = 0; i < rows * cols; i++)
Expand All @@ -124,10 +137,6 @@ mpf_mat_init(mpf_mat_t mat, slong rows, slong cols, flint_bitcnt_t prec)
mat->entries = NULL;
mat->rows = NULL;
}

mat->r = rows;
mat->c = cols;
mat->prec = prec;
}

void mpf_mat_clear(mpf_mat_t mat)
Expand Down
2 changes: 2 additions & 0 deletions src/fmpz_mat/fflu.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

#define E(j,k) fmpz_mat_entry(B,j,k)

#define r_shift(in, c) (((c) == FLINT_BITS) ? WORD(0) : ((in) >> (c)))

slong
fmpz_mat_fflu(fmpz_mat_t B, fmpz_t den, slong * perm,
const fmpz_mat_t A, int rank_check)
Expand Down
21 changes: 15 additions & 6 deletions src/fmpz_mat/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
(at your option) any later version. See <https://www.gnu.org/licenses/>.
*/

#include "long_extras.h"
#include "fmpz_mat.h"

void
Expand All @@ -18,13 +19,24 @@ fmpz_mat_init(fmpz_mat_t mat, slong rows, slong cols)
slong i;

if (rows != 0)
mat->rows = (fmpz **) flint_malloc(rows * sizeof(fmpz *));
mat->rows = flint_malloc(rows * sizeof(fmpz *));
else
mat->rows = NULL;

if (rows != 0 && cols != 0) /* Allocate space for r*c small entries */
mat->r = rows;
mat->c = cols;

if (rows != 0 && cols != 0)
{
mat->entries = (fmpz *) flint_calloc(flint_mul_sizes(rows, cols), sizeof(fmpz));
slong num;
int of;

of = z_mul_checked(&num, rows, cols);

if (of)
flint_throw(FLINT_ERROR, "Overflow creating a %wd x %wd object\n", rows, cols);

mat->entries = flint_calloc(num, sizeof(fmpz));

for (i = 0; i < rows; i++)
mat->rows[i] = mat->entries + i * cols;
Expand All @@ -35,9 +47,6 @@ fmpz_mat_init(fmpz_mat_t mat, slong rows, slong cols)
for (i = 0; i < rows; i++)
mat->rows[i] = NULL;
}

mat->r = rows;
mat->c = cols;
}

void
Expand Down
4 changes: 4 additions & 0 deletions src/fmpz_mat/mul.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
#include "fmpz.h"
#include "fmpz_mat.h"

#if FLINT_USES_BLAS
# include "longlong.h"
#endif

void _fmpz_mat_mul_small_1(fmpz_mat_t C, const fmpz_mat_t A, const fmpz_mat_t B)
{
slong ar, br, bc;
Expand Down
1 change: 1 addition & 0 deletions src/fmpz_mat/mul_blas.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
*/

#include "fmpz_mat.h"
#include "longlong.h"

/* todo: squaring optimizations */

Expand Down
2 changes: 2 additions & 0 deletions src/fmpz_mat/solve_fflu_precomp.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
#define BB(ii,jj) fmpz_mat_entry(B,(ii),(jj))
#define LU(ii,jj) fmpz_mat_entry(FFLU,(ii),(jj))

#define r_shift(in, c) (((c) == FLINT_BITS) ? WORD(0) : ((in) >> (c)))

void
fmpz_mat_set_perm(fmpz_mat_t X, const slong * perm, const fmpz_mat_t B)
{
Expand Down
1 change: 1 addition & 0 deletions src/fmpz_mod_poly/frobenius_powers_2exp_precomp.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#include "fmpz_mod.h"
#include "fmpz_mod_poly.h"
#include "longlong.h"

void fmpz_mod_poly_frobenius_powers_2exp_precomp(
fmpz_mod_poly_frobenius_powers_2exp_t pow, const fmpz_mod_poly_t f,
Expand Down
1 change: 1 addition & 0 deletions src/fmpz_mpoly.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#define FMPZ_MPOLY_INLINE static inline
#endif

#include "longlong.h"
#include "mpoly_types.h"

#ifdef __cplusplus
Expand Down
Loading

0 comments on commit 0d6152b

Please sign in to comment.