updaate headers for binary_c integration

parent ca1ccbc2
......@@ -162,7 +162,7 @@ struct rinterpolate_data_t * rinterpolate(
#if defined RINTERPOLATE_DEBUG && defined RINTERPOLATE_SHOW_TABLE
register rinterpolate_counter_t i=0;
#endif
Iprint("DEBUG RINTERPOLATE datatable=%p n=%d d=%d l=%d x=%p r=%p cache_length=%d\n",
Rinterpolate_print("DEBUG RINTERPOLATE datatable=%p n=%d d=%d l=%d x=%p r=%p cache_length=%d\n",
datatable,
n,d,l,x,r,cache_length);
......@@ -197,7 +197,7 @@ struct rinterpolate_data_t * rinterpolate(
datatable);
}
Iprint("Table ID %d\n",table_id);
Rinterpolate_print("Table ID %d\n",table_id);
if(table_id == -1)
{
......@@ -210,7 +210,7 @@ struct rinterpolate_data_t * rinterpolate(
d,
l,
cache_length);
Iprint("New table ID %d\n",table_id);
Rinterpolate_print("New table ID %d\n",table_id);
}
/*
......@@ -236,13 +236,13 @@ struct rinterpolate_data_t * rinterpolate(
{
for(i=0;i<l;i++)
{
Iprint("L%d ",i);
Rinterpolate_print("L%d ",i);
rinterpolate_counter_t j;
for(j=0;j<table->line_length;j++)
{
Iprint("%g ",*(datatable+i*table->line_length+j));
Rinterpolate_print("%g ",*(datatable+i*table->line_length+j));
}
Iprint("\n");
Rinterpolate_print("\n");
FLUSH;
}
}
......@@ -271,20 +271,20 @@ struct rinterpolate_data_t * rinterpolate(
if(rinterpolate_debug==TRUE)
{
rinterpolate_counter_t j;
Iprint("Parameter (x) values: ");
Rinterpolate_print("Parameter (x) values: ");
for(j=0;j<table->n;j++)
{
Iprint("% 3.3e ",x[j]);
Rinterpolate_print("% 3.3e ",x[j]);
}
Iprint("\n");
Rinterpolate_print("\n");
Iprint("Interpolation (f) factors: ");
Rinterpolate_print("Interpolation (f) factors: ");
for(j=0;j<table->n;j++)
{
Iprint("% 3.3e ",table->hypertable->f[j]);
Rinterpolate_print("% 3.3e ",table->hypertable->f[j]);
}
Iprint("\n");
Iprint("Interpolation hypertable:\n");
Rinterpolate_print("\n");
Rinterpolate_print("Interpolation hypertable:\n");
}
#endif
......@@ -301,17 +301,17 @@ struct rinterpolate_data_t * rinterpolate(
#ifdef RINTERPOLATE_DEBUG
{
rinterpolate_counter_t j;
Iprint("Result\n");
Rinterpolate_print("Result\n");
for(j=0;j<table->n;j++)
{
Iprint("% 3.3e ",*(table->hypertable->data+j));
Rinterpolate_print("% 3.3e ",*(table->hypertable->data+j));
}
Iprint(" | ");
Rinterpolate_print(" | ");
for(j=n;j<table->line_length;j++)
{
Iprint("% 3.3e ",*(table->hypertable->data+j));
Rinterpolate_print("% 3.3e ",*(table->hypertable->data+j));
}
Iprint("\n");FLUSH;
Rinterpolate_print("\n");FLUSH;
}
#endif
......
......@@ -126,27 +126,40 @@ typedef unsigned int rinterpolate_Boolean_t;
#endif
/* fast bit-shift equivalent to pow(2,A) but for integers */
#ifndef POWER2_INT
#define POWER2_INT(A) (1<<(A))
#endif
#ifndef Autotype
#if defined __GNUC__ && __GNUC__ > 3 && __GNUC_MINOR__ > 8
#define Autotype(X) __auto_type
#else
#define Autotype(X) typeof(X)
#endif // __GNUC__
#endif
/* macros to define less and more than operations */
#ifndef LESS_THAN
#define LESS_THAN(A,B) ((A)<(B))
#endif
#ifndef MORE_THAN
#define MORE_THAN(A,B) ((A)>(B))
#endif
#ifndef MAX
#define MAX(A,B) ({ \
const Autotype(A) _a = (A); \
const Autotype(B) _b = (B); \
MORE_THAN(_a,_b) ? _a : _b; \
})
#endif
#ifndef MIN
#define MIN(A,B) ({ \
const Autotype(A) _a = (A); \
const Autotype(B) _b = (B); \
LESS_THAN(_a,_b) ? _a : _b; \
})
#endif
#ifndef FORCE_RANGE
#define FORCE_RANGE(A,B,X) ({ \
const Autotype(A) _a = (A); \
const Autotype(B) _b = (B); \
......@@ -154,9 +167,14 @@ typedef unsigned int rinterpolate_Boolean_t;
(unlikely(LESS_THAN(_x,_a))) ? _a : \
(unlikely(MORE_THAN(_x,_b)) ? _b : _x); \
})
#endif
#ifndef IS_ZERO
#define IS_ZERO(A) (fabs((A))<TINY)
#endif
#ifndef FEQUAL
#define FEQUAL(A,B) (IS_ZERO((A)-(B)))
#endif
/*
* "safe" freeing of memory via the Safe_free macro,
......@@ -165,26 +183,28 @@ typedef unsigned int rinterpolate_Boolean_t;
* 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
#ifdef RINTERPOLATE_DEBUG
extern int rinterpolate_debug;
# define Iprint(...) if(rinterpolate_debug==TRUE) \
# define Rinterpolate_print(...) if(rinterpolate_debug==TRUE) \
fprintf(RINTERPOLATE_STREAM,__VA_ARGS__);
#else
# define Iprint(...)
# define Rinterpolate_print(...)
#endif // RINTERPOLATE_DEBUG
#undef TINY
#ifndef TINY
#define TINY (DBL_EPSILON)
#endif
#ifdef RINTERPOLATE_DEBUG
#if defined RINTERPOLATE_DEBUG && !defined FLUSH
# define FLUSH fflush(NULL);
#else
# define FLUSH /* */
......@@ -200,16 +220,21 @@ extern int rinterpolate_debug;
#ifdef __RINTERPOLATE__
/* do we want to try register variables? makes no difference with -O3 */
#ifndef register
#define register /* */
#endif
/* if we're given an ALIGNSIZE, use it */
#ifndef Aligned
#if defined ALIGNSIZE && !defined Aligned
#define Aligned __attribute__ ((aligned (ALIGNSIZE)))
#else
#define Aligned
#endif
#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
......@@ -217,29 +242,55 @@ extern int rinterpolate_debug;
#else
# define RESTRICT
#endif
#endif
#ifdef __GNUC__
#ifndef pure_function
# define pure_function __attribute__((pure))
#endif
#ifndef const_functions
# define const_function __attribute__((const))
#endif
#ifndef likely
# define likely(x) __builtin_expect(!!(x), 1)
#endif
#ifndef unlikely
# define unlikely(x) __builtin_expect(!!(x), 0)
#endif
#ifndef equally_likely
#if __GNUC__ >= 9
# define equally_likely(x) __builtin_expect_with_probability(!!(x),0,0.5)
#else
# define equally_likely(x) (x)
#endif
#endif
#ifndef prefetch
# define prefetch(...) __builtin_prefetch(__VA_ARGS__)
#endif
#ifndef MAYBE_UNUSED
# if __GNUC__ >=4
# define MAYBE_UNUSED __attribute__ ((unused))
# endif
#endif
#else // __GNUC__
#ifndef likely
#define likely(x) (x)
#endif
#ifndef unlikely
#define unlikely(x) (x)
#endif
#ifndef equally_likely
#define equally_likely(x) (x)
#endif
#ifndef prefetch
#define prefetch(...) /* prefetch: do nothing */
#endif
#endif // __GNUC__
......
......@@ -8,7 +8,7 @@ void rinterpolate_alloc_cacheline(struct rinterpolate_table_t * table)
table->cache_spin_line = -1;
#ifdef RINTERPOLATE_DEBUG
Iprint("Allocated new cache array for table_id=%d\n",
Rinterpolate_print("Allocated new cache array for table_id=%d\n",
table->table_number);
#endif
/*
......
......@@ -9,7 +9,7 @@ void rinterpolate_alloc_hypertable(struct rinterpolate_table_t * RESTRICT table)
table->hypertable = RINTERPOLATE_MALLOC(sizeof(struct rinterpolate_hypertable_t));
#ifdef RINTERPOLATE_DEBUG
Iprint("Interpolate: memory allocation\n");FLUSH;
Rinterpolate_print("Interpolate: memory allocation\n");FLUSH;
#endif
table->hypertable->table = table;
table->hypertable->data = RINTERPOLATE_MALLOC(table->hypertable_length*table->line_length_sizeof);
......@@ -17,7 +17,7 @@ void rinterpolate_alloc_hypertable(struct rinterpolate_table_t * RESTRICT table)
table->hypertable->sum = RINTERPOLATE_CALLOC(1,table->sum_sizeof);
#ifdef RINTERPOLATE_DEBUG
Iprint("MALLOC data at %p size %ld, f at %p size %ld, sum at %p size %ld\n",
Rinterpolate_print("MALLOC data at %p size %ld, f at %p size %ld, sum at %p size %ld\n",
table->hypertable->data,table->hypertable_length*table->line_length_sizeof,
table->hypertable->f,table->n_float_sizeof,
table->hypertable->sum,table->sum_sizeof);
......@@ -34,7 +34,7 @@ void rinterpolate_alloc_hypertable(struct rinterpolate_table_t * RESTRICT table)
#endif//RINTERPOLATE_ALLOC_CHECKS
#ifdef RINTERPOLATE_DEBUG
Iprint("table->hypertable->data alloc 2 * %d * %ld\n",table->hypertable_length,table->line_length_sizeof);
Rinterpolate_print("table->hypertable->data alloc 2 * %d * %ld\n",table->hypertable_length,table->line_length_sizeof);
#endif
#ifdef RINTERPOLATE_USE_REALLOC
......
......@@ -18,7 +18,7 @@ void rinterpolate_alloc_varcount(struct rinterpolate_table_t * RESTRICT table)
for(j=0; j<table->n; j++)
{
#ifdef RINTERPOLATE_DEBUG
Iprint("Interpolate debug: varcount[%d]=%d, b=%d, steps[%d]=%d\n",
Rinterpolate_print("Interpolate debug: varcount[%d]=%d, b=%d, steps[%d]=%d\n",
j,table->varcount[j],b,j,table->steps[j]);
FLUSH;
#endif
......
......@@ -5,12 +5,18 @@
/*
* Macro to convert a macro to a string
*/
#ifndef Stringify
#define Stringify(item) "" #item
#endif
/*
* Macro to expand a macro and then convert to a string
*/
#ifndef Stringify_macro
#define Stringify_macro(item) (Stringify(item))
#endif
#ifndef Macrotest
/*
* Macro to test a macro
*/
......@@ -19,6 +25,7 @@
"" #macro, \
(strcmp("" #macro, \
Stringify(macro)) ? "on" : "off" ));
#endif
void rinterpolate_build_flags(struct rinterpolate_data_t * RESTRICT rinterpolate_data)
{
......
......@@ -42,33 +42,33 @@ rinterpolate_Boolean_t rinterpolate_check_cache(
#ifdef RINTERPOLATE_CACHE_USE_MEMCMP
#ifdef RINTERPOLATE_DEBUG
{
Iprint("check cache : cf %d\n x={ ",iline);
Rinterpolate_print("check cache : cf %d\n x={ ",iline);
int m;
for(m=0;m<table->n;m++)
{
Iprint("%g%s",*(x+m),m==(table->n-1) ? " }\n":",");
Rinterpolate_print("%g%s",*(x+m),m==(table->n-1) ? " }\n":",");
}
rinterpolate_float_t * cl = RINTERPOLATE_CACHE_PARAM(iline);
Iprint(" c={ ");
Rinterpolate_print(" c={ ");
for(m=0;m<table->n;m++)
{
Iprint("%g%s",*(cl+m),m==(table->n-1) ? " }\n":",");
Rinterpolate_print("%g%s",*(cl+m),m==(table->n-1) ? " }\n":",");
}
Iprint("memcmp = %d\n",
Rinterpolate_print("memcmp = %d\n",
memcmp(RINTERPOLATE_CACHE_PARAM(iline),x,table->n_float_sizeof));
}
Iprint("end1\n");
Rinterpolate_print("end1\n");
#endif//RINTERPOLATE_DEBUG
Iprint("end2\n");
Rinterpolate_print("end2\n");
match = (memcmp(RINTERPOLATE_CACHE_PARAM(iline),x,table->n_float_sizeof)==0) ? TRUE : FALSE;
Iprint("Match0 = %d\n",match);
Rinterpolate_print("Match0 = %d\n",match);
#else // RINTERPOLATE_CACHE_USE_MEMCMP
rinterpolate_counter_t m;
rinterpolate_float_t * cacheline = RINTERPOLATE_CACHE_PARAM(iline);
match = TRUE;
Iprint("start of for loop\n");
Rinterpolate_print("start of for loop\n");
for(m=0; m<table->n; m++)
{
if(!FEQUAL(x[m],cacheline[m]))
......@@ -77,11 +77,11 @@ rinterpolate_Boolean_t rinterpolate_check_cache(
break;
}
}
Iprint("end of for loop\n");
Rinterpolate_print("end of for loop\n");
#endif // RINTERPOLATE_CACHE_USE_MEMCMP
Iprint("Post Match = %d\n",match);
Rinterpolate_print("Post Match = %d\n",match);
if(match==TRUE)
{
......@@ -92,7 +92,7 @@ rinterpolate_Boolean_t rinterpolate_check_cache(
*/
memcpy(r,RINTERPOLATE_CACHE_RESULT(iline),table->d_float_sizeof);
Iprint("cache match at line iline=%d (iloop=%d loop start %d)\n",iline,iloop,table->cache_match_line);
Rinterpolate_print("cache match at line iline=%d (iloop=%d loop start %d)\n",iline,iloop,table->cache_match_line);
/*
* Save the position of the match for
......@@ -108,7 +108,7 @@ rinterpolate_Boolean_t rinterpolate_check_cache(
}
cache_match:
Iprint("return match = %d\n",match);
Rinterpolate_print("return match = %d\n",match);
return match;
}
#endif//RINTERPOLATE_CACHE
......@@ -12,9 +12,9 @@ void rinterpolate_construct_hypercube(struct rinterpolate_table_t * RESTRICT tab
rinterpolate_counter_t i;
for(i=0;i<table->hypertable_length;i++)
{
Iprint("SUM %d was %d now ",i,hypertable->sum[i]);
Rinterpolate_print("SUM %d was %d now ",i,hypertable->sum[i]);
hypertable->sum[i] *= table->line_length;
Iprint("%d (lnl = %d)\n",hypertable->sum[i],table->line_length);
Rinterpolate_print("%d (lnl = %d)\n",hypertable->sum[i],table->line_length);
}
register rinterpolate_counter_t k = 0;
......@@ -23,7 +23,7 @@ void rinterpolate_construct_hypercube(struct rinterpolate_table_t * RESTRICT tab
#ifdef RINTERPOLATE_DEBUG
if(rinterpolate_debug==TRUE)
{
Iprint("memcpy k=%d i=%d : from %p to %p ( = %p + %d )\n",
Rinterpolate_print("memcpy k=%d i=%d : from %p to %p ( = %p + %d )\n",
k,
i,
hypertable->data + k,
......@@ -42,18 +42,18 @@ void rinterpolate_construct_hypercube(struct rinterpolate_table_t * RESTRICT tab
#ifdef RINTERPOLATE_DEBUG
{
Iprint("Line %d : ",i);FLUSH;
Rinterpolate_print("Line %d : ",i);FLUSH;
rinterpolate_counter_t j;
for(j=0;j<table->n;j++)
{
Iprint("% 3.3e ",*(hypertable->data+i*table->line_length+j));FLUSH;
Rinterpolate_print("% 3.3e ",*(hypertable->data+i*table->line_length+j));FLUSH;
}
Iprint(" | ");FLUSH;
Rinterpolate_print(" | ");FLUSH;
for(j=table->n;j<table->line_length;j++)
{
Iprint("% 3.3e ",*(hypertable->data+i*table->line_length+j));FLUSH;
Rinterpolate_print("% 3.3e ",*(hypertable->data+i*table->line_length+j));FLUSH;
}
Iprint(" %d/%d\n",i,table->hypertable_length-1);FLUSH;
Rinterpolate_print(" %d/%d\n",i,table->hypertable_length-1);FLUSH;
}
#endif
......@@ -61,14 +61,14 @@ void rinterpolate_construct_hypercube(struct rinterpolate_table_t * RESTRICT tab
#ifdef RINTERPOLATE_DEBUG
{
Iprint("done hypertable\n");
Iprint("Interpolation (f) factors: ");
Rinterpolate_print("done hypertable\n");
Rinterpolate_print("Interpolation (f) factors: ");
rinterpolate_counter_t j;
for(j=0;j<table->n;j++)
{
Iprint("% 3.3e ",hypertable->f[j]);
Rinterpolate_print("% 3.3e ",hypertable->f[j]);
}
Iprint("\n");
Rinterpolate_print("\n");
}
#endif
}
......@@ -14,8 +14,8 @@ rinterpolate_signed_counter_t rinterpolate_id_table(
rinterpolate_Boolean_t found = FALSE;
Iprint("Look for table in existing table ids\n");
Iprint("currently have %d tables\n",rinterpolate_data->number_of_interpolation_tables);
Rinterpolate_print("Look for table in existing table ids\n");
Rinterpolate_print("currently have %d tables\n",rinterpolate_data->number_of_interpolation_tables);
rinterpolate_counter_t table_num = 0;
while(table_num < rinterpolate_data->number_of_interpolation_tables)
......@@ -34,12 +34,12 @@ rinterpolate_signed_counter_t rinterpolate_id_table(
if(found==FALSE)
{
/* if not found, allocate */
Iprint("Not found : realloc\n");
Rinterpolate_print("Not found : realloc\n");
table_num = -1;
}
else
{
Iprint("Found at %d\n",table_num);
Rinterpolate_print("Found at %d\n",table_num);
}
return table_num;
......
......@@ -26,7 +26,7 @@ void rinterpolate_interpolate(
* Do the interpolation
*/
#ifdef RINTERPOLATE_DEBUG
Iprint("Interpolate n=%d f=%g\n",table->n,hypertable->f[n]);
Rinterpolate_print("Interpolate n=%d f=%g\n",table->n,hypertable->f[n]);
FLUSH;
#endif
#ifdef RINTERPOLATE_USE_POINTER_ARITHMETIC
......@@ -41,7 +41,7 @@ void rinterpolate_interpolate(
{
// u=0 v=1: unusual case but easy to calculate (no inner loop required)
#ifdef RINTERPOLATE_DEBUG
Iprint("u=0 v=1\n");
Rinterpolate_print("u=0 v=1\n");
#endif
rinterpolate_float_t *xxx;
rinterpolate_counter_t i;
......@@ -97,7 +97,7 @@ void rinterpolate_interpolate(
}
#ifdef RINTERPOLATE_DEBUG
Iprint("memcopy results\n");
Rinterpolate_print("memcopy results\n");
FLUSH;
#endif
......
......@@ -18,7 +18,7 @@ void rinterpolate_make_steps(struct rinterpolate_table_t * RESTRICT table)
/* loop, find where variables change */
#ifdef RINTERPOLATE_DEBUG
Iprint("Find where vars change (i.e. set steps_array/steps) \n");
Rinterpolate_print("Find where vars change (i.e. set steps_array/steps) \n");
#endif
rinterpolate_counter_t i,j;
......@@ -42,7 +42,7 @@ void rinterpolate_make_steps(struct rinterpolate_table_t * RESTRICT table)
for(i=1; i<table->l; i++)
{
/*
Iprint("Line %d, item %d/%d : cf %g to prev %g \n",
Rinterpolate_print("Line %d, item %d/%d : cf %g to prev %g \n",
i,
j,
table->n,
......@@ -59,7 +59,7 @@ void rinterpolate_make_steps(struct rinterpolate_table_t * RESTRICT table)
{
// change
table->steps[j] = i;
Iprint("SET STEPS for var %d to %d\n",j,table->steps[j]);
Rinterpolate_print("SET STEPS for var %d to %d\n",j,table->steps[j]);
i=table->l+1; // break i loop
}
}
......
......@@ -7,10 +7,10 @@ void rinterpolate_search_table(
{
register rinterpolate_counter_t j;
#ifdef RINTERPOLATE_DEBUG
Iprint("search table for span of { ");
Rinterpolate_print("search table for span of { ");
for(j=0;j<table->n;j++)
{
Iprint("x[%d]=%g%s",j,x[j],j!=(table->n-1)?", ":" }\n");
Rinterpolate_print("x[%d]=%g%s",j,x[j],j!=(table->n-1)?", ":" }\n");
}
FLUSH;
#endif
......@@ -58,7 +58,7 @@ void rinterpolate_search_table(
#ifdef RINTERPOLATE_DEBUG
if(rinterpolate_debug)
{
Iprint("Construct variable %d hypertable position\n",
Rinterpolate_print("Construct variable %d hypertable position\n",
j);
FLUSH;
......@@ -142,7 +142,7 @@ void rinterpolate_search_table(
}
#endif // BINARY_SEARCH
Iprint("Binary search : indices a=%d b=%d : vars %g < v=%g < %g\n",
Rinterpolate_print("Binary search : indices a=%d b=%d : vars %g < v=%g < %g\n",
a,
b,
*(tpre+a),
......@@ -219,10 +219,10 @@ void rinterpolate_search_table(
//sum[i] += tmp*a+(1-tmp)*b;
/* same thing without a temporary variable */
Iprint("DSUM(%d)=%d += (%d%%%d)==0? %d : %d -> ",
Rinterpolate_print("DSUM(%d)=%d += (%d%%%d)==0? %d : %d -> ",
m,sum[m],m,c,a,b);
sum[m] += ((m&c)==0 ? a : b);
Iprint("%d\n",sum[m]);
Rinterpolate_print("%d\n",sum[m]);
}
}
......
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