try to compartmentalize rinterpolate's header files

parent c3778ef4
......@@ -15,6 +15,7 @@
#include <float.h>
#include <stdio.h>
#include <malloc.h>
#include "rinterpolate_compiler.h"
/************************************************************
* rinterpolate's macros
......@@ -107,153 +108,6 @@ typedef unsigned int rinterpolate_Boolean_t;
*/
#define RINTERPOLATE_CACHE_USE_MEMCMP
/*************************************************************
* Internal macros
*************************************************************/
#ifdef __RINTERPOLATE__
#ifndef FALSE
#define FALSE (0)
#endif
#ifndef TRUE
#define TRUE (1)
#endif
/* Convert a C (integer) expression to rinterpolate_Boolean_t type */
#ifndef Boolean_
#define Boolean_(EXPR) ((EXPR) ? (TRUE) : (FALSE))
#endif
/* fast bit-shift equivalent to pow(2,A) but for integers */
#define POWER2_INT(A) (1<<(A))
#if defined __GNUC__ && __GNUC__ > 3 && __GNUC_MINOR__ > 8
#define Autotype(X) __auto_type
#else
#define Autotype(X) typeof(X)
#endif // __GNUC__
/* macros to define less and more than operations */
#define LESS_THAN(A,B) ((A)<(B))
#define MORE_THAN(A,B) ((A)>(B))
#define MAX(A,B) ({ \
const Autotype(A) _a = (A); \
const Autotype(B) _b = (B); \
MORE_THAN(_a,_b) ? _a : _b; \
})
#define MIN(A,B) ({ \
const Autotype(A) _a = (A); \
const Autotype(B) _b = (B); \
LESS_THAN(_a,_b) ? _a : _b; \
})
#define FORCE_RANGE(A,B,X) ({ \
const Autotype(A) _a = (A); \
const Autotype(B) _b = (B); \
const Autotype(X) _x = (X); \
(unlikely(LESS_THAN(_x,_a))) ? _a : \
(unlikely(MORE_THAN(_x,_b)) ? _b : _x); \
})
#define IS_ZERO(A) (fabs((A))<TINY)
#define FEQUAL(A,B) (IS_ZERO((A)-(B)))
/*
* "safe" freeing of memory via the Safe_free macro,
* which enforces a NULL in the pointer after a call
* to free.
* Note tha the PTR must actually be a pointer (i.e. an lvalue),
* not an expression.
*/
#define Safe_free(PTR) \
if(likely((PTR)!=NULL)) \
{ \
free(PTR); \
(PTR)=NULL; \
};
#ifdef RINTERPOLATE_DEBUG
extern int rinterpolate_debug;
# define Iprint(...) if(rinterpolate_debug==TRUE) \
fprintf(RINTERPOLATE_STREAM,__VA_ARGS__);
#else
# define Iprint(...)
#endif // RINTERPOLATE_DEBUG
#undef TINY
#define TINY (DBL_EPSILON)
#ifdef RINTERPOLATE_DEBUG
# define FLUSH fflush(NULL);
#else
# define FLUSH /* */
#endif
#endif // __RINTERPOLATE__
/*************************************************************
* Compiler options
*************************************************************/
#ifdef __RINTERPOLATE__
/* do we want to try register variables? makes no difference with -O3 */
#define register /* */
/* if we're given an ALIGNSIZE, use it */
#if defined ALIGNSIZE && !defined Aligned
#define Aligned __attribute__ ((aligned (ALIGNSIZE)))
#else
#define Aligned
#endif
/* restrict if possible */
#if defined(__GNUC__) && ((__GNUC__ >= 4) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1))
# define RESTRICT __restrict
#elif defined(_MSC_VER) && _MSC_VER >= 1400
# define RESTRICT __restrict
#else
# define RESTRICT
#endif
#ifdef __GNUC__
# define pure_function __attribute__((pure))
# define const_function __attribute__((const))
# define likely(x) __builtin_expect(!!(x), 1)
# define unlikely(x) __builtin_expect(!!(x), 0)
#if __GNUC__ >= 9
# define equally_likely(x) __builtin_expect_with_probability(!!(x),0,0.5)
#else
# define equally_likely(x) (x)
#endif
# define prefetch(...) __builtin_prefetch(__VA_ARGS__)
# if __GNUC__ >=4
# define MAYBE_UNUSED __attribute__ ((unused))
# endif
#else // __GNUC__
#define likely(x) (x)
#define unlikely(x) (x)
#define equally_likely(x) (x)
#define prefetch(...) /* prefetch: do nothing */
#endif // __GNUC__
#ifndef MAYBE_UNUSED
# define MAYBE_UNUSED
#endif
#ifndef pure_function
# define pure_function
#endif
#ifndef const_function
# define const_function
#endif
#endif // __RINTERPOLATE__
/************************************************************
* rinterpolate's structures
......@@ -261,9 +115,9 @@ extern int rinterpolate_debug;
struct rinterpolate_hypertable_t {
struct rinterpolate_table_t * table;
rinterpolate_float_t Aligned * data;
rinterpolate_float_t Aligned * f;
rinterpolate_counter_t Aligned * sum;
rinterpolate_float_t * data;
rinterpolate_float_t * f;
rinterpolate_counter_t * sum;
#ifdef RINTERPOLATE_USE_REALLOC
size_t RINTERPOLATE_ALLOCD;
#endif
......@@ -272,16 +126,16 @@ struct rinterpolate_hypertable_t {
struct rinterpolate_table_t {
struct rinterpolate_data_t * parent;
struct rinterpolate_hypertable_t * hypertable;
rinterpolate_float_t Aligned * data;
rinterpolate_float_t * data;
#ifdef RINTERPOLATE_CACHE
rinterpolate_float_t Aligned * RESTRICT cache;
rinterpolate_float_t * RESTRICT cache;
rinterpolate_counter_t cache_match_line;
rinterpolate_signed_counter_t cache_spin_line;
#endif
rinterpolate_counter_t Aligned * RESTRICT steps;
rinterpolate_counter_t * RESTRICT steps;
#ifdef RINTERPOLATE_PRESEARCH
rinterpolate_float_t ** RESTRICT presearch;
rinterpolate_counter_t Aligned presearch_n;
rinterpolate_float_t ** RESTRICT presearch;
rinterpolate_counter_t presearch_n;
#endif
size_t d_float_sizeof;
size_t n_float_sizeof;
......@@ -304,7 +158,7 @@ struct rinterpolate_table_t {
struct rinterpolate_data_t {
struct rinterpolate_table_t Aligned * * RESTRICT tables;
struct rinterpolate_table_t * * RESTRICT tables;
rinterpolate_counter_t number_of_interpolation_tables;
};
......
#pragma once
#ifndef RINTERPOLATE_COMPILER_H
#define RINTERPOLATE_COMPILER_H
/*
* macros which depend on the compiler, for librinterpolate
*/
#ifndef Autotype
#if defined __GNUC__ && __GNUC__ > 3 && __GNUC_MINOR__ > 8
#define Autotype(X) __auto_type
#else
#define Autotype(X) typeof(X)
#endif // __GNUC__
#endif
/*
* "safe" freeing of memory via the Safe_free macro,
* which enforces a NULL in the pointer after a call
* to free.
* Note tha the PTR must actually be a pointer (i.e. an lvalue),
* not an expression.
*/
#ifndef Safe_free
#define Safe_free(PTR) \
if(likely((PTR)!=NULL)) \
{ \
free(PTR); \
(PTR)=NULL; \
};
#endif
/* do we want to try __rinterpolate_register = register variables?
* makes no difference with -O3 */
#define __rinterpolate_register /* */
/* if we're given an ALIGNSIZE, use it */
#if !defined Aligned && defined ALIGNSIZE
#define Aligned __attribute__ ((aligned (ALIGNSIZE)))
#else
#define Aligned
#endif
/* restrict if possible */
#ifndef RESTRICT
#if defined(__GNUC__) && ((__GNUC__ >= 4) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1))
# define RESTRICT __restrict
#elif defined(_MSC_VER) && _MSC_VER >= 1400
# define RESTRICT __restrict
#else
# define RESTRICT
#endif
#endif
#ifdef __GNUC__
# define likely(x) __builtin_expect(!!(x), 1)
# define unlikely(x) __builtin_expect(!!(x), 0)
#if __GNUC__ >= 9
# define equally_likely(x) __builtin_expect_with_probability(!!(x),0,0.5)
#else
# define equally_likely(x) (x)
#endif
# define prefetch(...) __builtin_prefetch(__VA_ARGS__)
# if __GNUC__ >=4
# define MAYBE_UNUSED __attribute__ ((unused))
# endif
#else // __GNUC__
#define likely(x) (x)
#define unlikely(x) (x)
#define equally_likely(x) (x)
#define prefetch(...) /* prefetch: do nothing */
#endif // __GNUC__
#ifndef MAYBE_UNUSED
# define MAYBE_UNUSED
#endif
#endif // RINTERPOLATE_COMPILER_H
#pragma once
#ifndef RINTERPOLATE_INTERNAL_H
#define RINTERPOLATE_INTERNAL_H
/*************************************************************
* librinterpolate's internal macros
*************************************************************/
#ifndef FALSE
#define FALSE (0)
#endif
#ifndef TRUE
#define TRUE (1)
#endif
/* Convert a C (integer) expression to rinterpolate_Boolean_t type */
#ifndef Boolean_
#define Boolean_(EXPR) ((EXPR) ? (TRUE) : (FALSE))
#endif
/* fast bit-shift equivalent to pow(2,A) but for integers */
#define POWER2_INT(A) (1<<(A))
/* macros to define less and more than operations */
#define LESS_THAN(A,B) ((A)<(B))
#define MORE_THAN(A,B) ((A)>(B))
#define MAX(A,B) ({ \
const Autotype(A) _a = (A); \
const Autotype(B) _b = (B); \
MORE_THAN(_a,_b) ? _a : _b; \
})
#define MIN(A,B) ({ \
const Autotype(A) _a = (A); \
const Autotype(B) _b = (B); \
LESS_THAN(_a,_b) ? _a : _b; \
})
#define FORCE_RANGE(A,B,X) ({ \
const Autotype(A) _a = (A); \
const Autotype(B) _b = (B); \
const Autotype(X) _x = (X); \
(unlikely(LESS_THAN(_x,_a))) ? _a : \
(unlikely(MORE_THAN(_x,_b)) ? _b : _x); \
})
#define IS_ZERO(A) (fabs((A))<TINY)
#define FEQUAL(A,B) (IS_ZERO((A)-(B)))
#ifdef RINTERPOLATE_DEBUG
extern int rinterpolate_debug;
# define Iprint(...) if(rinterpolate_debug==TRUE) \
fprintf(RINTERPOLATE_STREAM,__VA_ARGS__);
#else
# define Iprint(...)
#endif // RINTERPOLATE_DEBUG
#undef TINY
#define TINY (DBL_EPSILON)
#ifdef RINTERPOLATE_DEBUG
# define FLUSH fflush(NULL);
#else
# define FLUSH /* */
#endif // RINTERPOLATE_DEBUG
/*************************************************************
* Compiler options
*************************************************************/
#include "rinterpolate_compiler.h"
#endif // RINTERPOLATE_INTERNAL_H
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment