27 #include <cairo/cairo.h> 42 #define M_PI 3.141592653589793238462643383 51 #define NC_DEFLATE_LEVEL 9 57 #define H2_MACH_EPS 1e-13 91 #define h2_malloc(sz) _mm_malloc(sz, VALIGN) 93 #define h2_malloc(sz) malloc(sz) 101 #define h2_free(p) _mm_free(p) 103 #define h2_free(p) free(p) 120 #define ROUNDUP(x, N) ((((x) + (N) - 1) / (N)) * (N)) 135 #define REAL(x) crealf(x) 137 #define REAL(x) creal(x) 146 #define IMAG(x) cimagf(x) 148 #define IMAG(x) cimag(x) 157 #define CONJ(x) conjf(x) 159 #define CONJ(x) conj(x) 166 #define ABSSQR(x) _h2_abssqr(x) 169 #define ABS(x) REAL_SQRT(ABSSQR(x)) 173 #define SIGN1(x) _h2_sgn1(x) 176 #define FIELD_RAND() _h2_fieldrand() 181 #define REAL_ABS(x) fabs(x) 184 #define REAL_SQR(x) _h2_real_sqr(x) 188 #define REAL_SIN(x) sinf(x) 190 #define REAL_SIN(x) sin(x) 195 #define REAL_COS(x) cosf(x) 197 #define REAL_COS(x) cos(x) 202 #define REAL_ASIN(x) asinf(x) 204 #define REAL_ASIN(x) asin(x) 209 #define REAL_ACOS(x) acosf(x) 211 #define REAL_ACOS(x) acos(x) 216 #define REAL_TAN(x) tanf(x) 218 #define REAL_TAN(x) tan(x) 223 #define REAL_SQRT(x) sqrtf(x) 225 #define REAL_SQRT(x) sqrt(x) 230 #define REAL_RSQRT(x) _h2_rsqrt(x) 234 #define REAL_POW(x, y) powf(x, y) 236 #define REAL_POW(x, y) pow(x, y) 241 #define REAL_LOG(x) logf(x) 243 #define REAL_LOG(x) log(x) 248 #define REAL_EXP(x) expf(x) 250 #define REAL_EXP(x) exp(x) 254 #define REAL_RAND() _h2_realrand() 258 #define DOT2(x,y) (CONJ((x)[0]) * (y)[0] + CONJ((x)[1]) * (y)[1]) 262 #define DOT3(x,y) (CONJ((x)[0]) * (y)[0] + CONJ((x)[1]) * (y)[1] + CONJ((x)[2]) * (y)[2]) 266 #define NORMSQR2(x,y) (ABSSQR(x) + ABSSQR(y)) 270 #define NORMSQR3(x,y,z) (ABSSQR(x) + ABSSQR(y) + ABSSQR(z)) 274 #define NORM2(x,y) REAL_SQRT(ABSSQR(x) + ABSSQR(y)) 278 #define NORM3(x,y,z) REAL_SQRT(ABSSQR(x) + ABSSQR(y) + ABSSQR(z)) 282 #define REAL_DOT2(x,y) ((x)[0] * (y)[0] + (x)[1] * (y)[1]) 286 #define REAL_DOT3(x,y) ((x)[0] * (y)[0] + (x)[1] * (y)[1] + (x)[2] * (y)[2]) 290 #define REAL_NORMSQR2(x,y) (REAL_SQR(x) + REAL_SQR(y)) 294 #define REAL_NORMSQR3(x,y,z) (REAL_SQR(x) + REAL_SQR(y) + REAL_SQR(z)) 298 #define REAL_NORM2(x,y) REAL_SQRT(REAL_SQR(x) + REAL_SQR(y)) 302 #define REAL_NORM3(x,y,z) REAL_SQRT(REAL_SQR(x) + REAL_SQR(y) + REAL_SQR(z)) 305 #define REAL_MAX(x, y) _h2_realmax(x, y) 308 #define REAL_MAX3(x, y, z) _h2_realmax3(x, y, z) 311 #define REAL_MIN(x, y) _h2_realmin(x, y) 314 #define REAL_MIN3(x, y, z) _h2_realmin3(x, y, z) 319 #define UINT_MAX(x, y) _h2_uintmax(x, y) 322 #define UINT_MAX3(x, y, z) _h2_uintmax3(x, y, z) 325 #define UINT_MIN(x, y) _h2_uintmin(x, y) 328 #define UINT_MIN3(x, y, z) _h2_uintmin3(x, y, z) 366 return rx * rx + ix * ix;
389 return rx * norm + ix * norm * I;
407 x +=
f_i * _h2_realrand();
427 return (x < y ? y : x);
437 return (x < y ? (y < z ? z : y) : (x < z ? z : x));
446 return (a < b ? a : b);
456 return (x < y ? (z < x ? z : x) : (z < y ? z : y));
463 return 2.0 * rand() / RAND_MAX - 1.0;
472 return (x < y ? y : x);
482 return (x < y ? (y < z ? z : y) : (x < z ? z : x));
491 return (x < y ? x : y);
501 return (x < y ? (z < x ? z : x) : (z < y ? z : y));
512 #define allocmem(sz) _h2_allocmem(sz,__FILE__,__LINE__) 520 _h2_allocmem(
size_t sz,
const char *filename,
int line);
526 #define allocuint(sz) _h2_allocuint(sz,__FILE__,__LINE__) 534 _h2_allocuint(
size_t sz,
const char *filename,
int line);
540 #define allocreal(sz) _h2_allocreal(sz,__FILE__,__LINE__) 548 _h2_allocreal(
size_t sz,
const char *filename,
int line);
554 #define allocfield(sz) _h2_allocfield(sz,__FILE__,__LINE__) 562 _h2_allocfield(
size_t sz,
const char *filename,
int line);
571 #define allocmatrix(rows,cols) _h2_allocmatrix(rows,cols,__FILE__,__LINE__) 583 _h2_allocmatrix(
size_t rows,
size_t cols,
const char *filename,
int line);
607 #define heapsort(n,leq,swap,data) _h2_heapsort(n,leq,swap,data) 623 void swap(
uint,
uint,
void *),
void *data);
678 new_cairopdf(
const char *filename,
double width,
double height);
#define ABSSQR(x)
Compute the square of the absolute value of a field element .
Definition: basic.h:166
const field f_zero
field constant zero
cairo_t * new_cairopng(uint width, uint height)
Create a PNG canvas for Cairo drawing.
#define REAL_SQRT(x)
Compute the square root of a non-negative real nunber .
Definition: basic.h:225
void uninit_h2lib()
Uninitialize the library.
unsigned uint
Unsigned integer type.
Definition: settings.h:70
stopwatch * pstopwatch
Pointer to a stopwatch object.
Definition: basic.h:21
#define H2_ALMOST_ZERO
Definition: settings.h:132
double _Complex field
Field type.
Definition: settings.h:171
pstopwatch new_stopwatch()
Create a stopwatch object.
const field f_i
field constant for the imaginary number.
#define INLINE_PREFIX
Prefix for inline functions.
Definition: settings.h:36
#define IMAG(x)
Get the imaginary part of a field element .
Definition: basic.h:148
cairo_t * new_cairopdf(const char *filename, double width, double height)
Create a PDF canvas for Cairo drawing.
real stop_stopwatch(pstopwatch sw)
Stop a stopwatch.
size_t get_current_memory()
Current amount of allocated memory (bytes)
void freemem(void *ptr)
Release allocated storage.
#define HEADER_PREFIX
Prefix for function declarations.
Definition: settings.h:43
const field f_minusone
field constant minus one.
double real
real floating point type.
Definition: settings.h:97
const field f_one
field constant one.
void start_stopwatch(pstopwatch sw)
Start a stopwatch.
bool write_cairopng(cairo_t *cr, const char *filename)
Write Cairo image to PNG file.
const real r_one
real constant one.
#define REAL(x)
Get the real part of a field element .
Definition: basic.h:137
void del_stopwatch(pstopwatch sw)
Delete a stopwatch object.
#define REAL_RSQRT(x)
Compute the reciprocal square root of a non-negative real nunber .
Definition: basic.h:230
int max_pardepth
Reasonable cut-off depth for parallelization.
struct _stopwatch stopwatch
Stop watch for run-time measurements.
Definition: basic.h:18
void init_h2lib(int *argc, char ***argv)
Initialize the library.