update to 1.4: added const options for many pointers, Pure function when...

update to 1.4: added const options for many pointers, Pure function when possible, etc. (updates for gcc-9)
parent 9db98810
......@@ -12,7 +12,7 @@ C_SRC := $(wildcard *.c)
OBJECTS := $(C_SRC:.c=.o)
#OBJECTS := rinterpolate.o rinterpolate-debug.o
LIBRINTERPOLATE_ARCHFLAGS ?= -march=native -mtune=native
CFLAGS := -fPIC -O2 -g $(LIBRINTERPOLATE_ARCHFLAGS) -Wall -Wstrict-prototypes -ffast-math -D__RINTERPOLATE__ -D__RINTERPOLATE_BUILD_BUILD_FLAGS__ $(COPTFLAGS)
CFLAGS := -fPIC -O2 -g $(LIBRINTERPOLATE_ARCHFLAGS) -Wall -Wstrict-prototypes -ffast-math -D__RINTERPOLATE__ -D__RINTERPOLATE_BUILD_BUILD_FLAGS__ $(COPTFLAGS)
ifeq ($(PREFIX),)
PREFIX := /usr/local
endif
......
......@@ -149,13 +149,13 @@
struct rinterpolate_data_t * rinterpolate(
const rinterpolate_float_t * RESTRICT datatable, // (pointer to) the data table
const rinterpolate_float_t * RESTRICT const datatable, // (const pointer to) the data table
struct rinterpolate_data_t * rinterpolate_data, // where rinterpolate stores data
const rinterpolate_counter_t n, // the number of parameters (i.e. dimensions)
const rinterpolate_counter_t d, // the number of data items
const rinterpolate_counter_t l, // the number of lines of data
const rinterpolate_float_t * RESTRICT x, // the values of the parameters
rinterpolate_float_t * RESTRICT r, // the result of the interpolation
const rinterpolate_float_t * RESTRICT const x, // the values of the parameters
rinterpolate_float_t * RESTRICT const r, // the result of the interpolation
const rinterpolate_counter_t cache_length // number of cache lines
)
{
......
......@@ -21,9 +21,9 @@
* rinterpolate's macros
*************************************************************/
#define RINTERPOLATE_VERSION "1.3"
#define RINTERPOLATE_VERSION "1.4"
#define RINTERPOLATE_MAJOR_VERSION 1
#define RINTERPOLATE_MINOR_VERSION 3
#define RINTERPOLATE_MINOR_VERSION 4
/* types */
typedef unsigned int rinterpolate_counter_t;
......
......@@ -2,8 +2,8 @@
#include "rinterpolate_internal.h"
rinterpolate_counter_t rinterpolate_add_new_table(
struct rinterpolate_data_t * RESTRICT rinterpolate_data,
const rinterpolate_float_t * RESTRICT data,
struct rinterpolate_data_t * RESTRICT const rinterpolate_data,
const rinterpolate_float_t * RESTRICT const data,
const rinterpolate_counter_t n,
const rinterpolate_counter_t d,
const rinterpolate_counter_t l,
......
......@@ -3,7 +3,7 @@
#ifdef RINTERPOLATE_CACHE
void rinterpolate_alloc_cacheline(struct rinterpolate_table_t * table)
void rinterpolate_alloc_cacheline(struct rinterpolate_table_t * RESTRICT const table)
{
table->cache_match_line = 0;
table->cache_spin_line = -1;
......
......@@ -8,14 +8,13 @@
int rinterpolate_debug;
#endif
rinterpolate_counter_t rinterpolate_alloc_dataspace(struct rinterpolate_data_t ** RESTRICT r)
rinterpolate_counter_t rinterpolate_alloc_dataspace(struct rinterpolate_data_t ** RESTRICT const r)
{
if(*r != NULL)
{
rinterpolate_error(RINTERPOLATE_ALLOCATE_OVER,
"Attempted to allocate rinterpolate into %p (* = %p) which is non-NULL\n",
*r,
r);
"Attempted to allocate rinterpolate a non-NULL pointer\n",
*r);
return RINTERPOLATE_ALLOCATE_OVER;
}
else
......
......@@ -4,7 +4,7 @@
#include <malloc.h>
#endif
void rinterpolate_alloc_hypertable(struct rinterpolate_table_t * RESTRICT table)
void rinterpolate_alloc_hypertable(struct rinterpolate_table_t * RESTRICT const table)
{
/* make space for hypertable */
table->hypertable = RINTERPOLATE_MALLOC(sizeof(struct rinterpolate_hypertable_t));
......
#include "rinterpolate.h"
#include "rinterpolate_internal.h"
void rinterpolate_alloc_varcount(struct rinterpolate_table_t * RESTRICT table)
void rinterpolate_alloc_varcount(struct rinterpolate_table_t * RESTRICT const table)
{
table->varcount = RINTERPOLATE_CALLOC(table->n,sizeof(rinterpolate_counter_t));
#ifdef RINTERPOLATE_ALLOC_CHECKS
......
......@@ -30,7 +30,7 @@
Stringify(macro)) ? "on" : "off" ));
#endif
void rinterpolate_build_flags(struct rinterpolate_data_t * RESTRICT rinterpolate_data)
void rinterpolate_build_flags(struct rinterpolate_data_t * RESTRICT const rinterpolate_data)
{
Macrotest(RINTERPOLATE_USE_REALLOC);
Macrotest(RINTERPOLATE_USE_POINTER_ARITHMETIC);
......
......@@ -2,9 +2,9 @@
#ifdef RINTERPOLATE_CACHE
#include "rinterpolate_internal.h"
rinterpolate_Boolean_t rinterpolate_check_cache(
struct rinterpolate_table_t * RESTRICT table,
const rinterpolate_float_t * RESTRICT x,
rinterpolate_float_t * RESTRICT r)
struct rinterpolate_table_t * RESTRICT const table,
const rinterpolate_float_t * RESTRICT const x,
rinterpolate_float_t * RESTRICT const r)
{
/*
* Set the cache location
......
......@@ -86,10 +86,49 @@
#define prefetch(...) /* prefetch: do nothing */
#endif
#endif // __GNUC__
#ifndef MAYBE_UNUSED
# define MAYBE_UNUSED
#endif
#ifndef Pure_function
#if defined __GNUC__ && __GNUC__ >=3
#define Pure_function __attribute__((pure))
#endif
#endif
#ifndef Constant_function
#if defined __GNUC__ && __GNUC__ >=3
#define Constant_function __attribute__((const))
#endif
#endif
#ifndef No_return
#if defined __GNUC__ && __GNUC__ >=4
#define No_return __attribute__((noreturn))
#endif
#endif
#ifndef Gnu_format_args
#if (__GNUC__ ==4 && __GNU_MINOR__>=7) || __GNUC__ > 4
#define Gnu_format_args(...) __attribute__((format (gnu_printf,__VA_ARGS__)))
#endif
#endif
#ifndef Constant_function
#define Constant_function
#endif
#ifndef Pure_function
#define Pure_function
#endif
#ifndef No_return
# define No_return
#endif
#ifndef Gnu_format_args
# define Gnu_format_args(...)
#endif
#endif // RINTERPOLATE_COMPILER_H
#include "rinterpolate.h"
#include "rinterpolate_internal.h"
void rinterpolate_construct_hypercube(struct rinterpolate_table_t * RESTRICT table)
void rinterpolate_construct_hypercube(struct rinterpolate_table_t * RESTRICT const table)
{
/*
* Construct hypercube
......
......@@ -2,10 +2,10 @@
#include <stdarg.h>
#include "rinterpolate_internal.h"
void rinterpolate_error(rinterpolate_counter_t errnum,
char * RESTRICT format,
struct rinterpolate_data_t * RESTRICT rinterpolate_data,
...)
void No_return Gnu_format_args(2,4) rinterpolate_error(rinterpolate_counter_t errnum,
char * RESTRICT format,
struct rinterpolate_data_t * RESTRICT const rinterpolate_data,
...)
{
/*
* Report an error in librinterpolate and exit
......
......@@ -5,9 +5,9 @@
*
* Given a rinterpolate_data struct, free everything in it.
*/
static void rinterpolate_free_table(struct rinterpolate_table_t * table);
static void rinterpolate_free_table(struct rinterpolate_table_t * const table);
void rinterpolate_free_data(struct rinterpolate_data_t * RESTRICT rinterpolate_data)
void rinterpolate_free_data(struct rinterpolate_data_t * RESTRICT const rinterpolate_data)
{
if(rinterpolate_data)
{
......@@ -22,7 +22,7 @@ void rinterpolate_free_data(struct rinterpolate_data_t * RESTRICT rinterpolate_d
}
}
static void rinterpolate_free_table(struct rinterpolate_table_t * table)
static void rinterpolate_free_table(struct rinterpolate_table_t * const table)
{
#ifdef RINTERPOLATE_CACHE
......
......@@ -5,9 +5,9 @@
* data structure.
*/
rinterpolate_signed_counter_t rinterpolate_id_table(
struct rinterpolate_data_t * RESTRICT rinterpolate_data,
const rinterpolate_float_t * RESTRICT data
rinterpolate_signed_counter_t Pure_function rinterpolate_id_table(
struct rinterpolate_data_t * RESTRICT const rinterpolate_data,
const rinterpolate_float_t * RESTRICT const data
)
{
/* look for data table in the existing table_ids */
......
......@@ -2,9 +2,9 @@
#include "rinterpolate_internal.h"
void rinterpolate_interpolate(
const struct rinterpolate_table_t * table,
const rinterpolate_float_t * RESTRICT x,
rinterpolate_float_t * RESTRICT r)
const struct rinterpolate_table_t * const table,
const rinterpolate_float_t * RESTRICT const x,
rinterpolate_float_t * RESTRICT const r)
{
rinterpolate_float_t u,v;
rinterpolate_counter_t n = 0;
......
......@@ -2,7 +2,7 @@
#include "rinterpolate_internal.h"
#ifdef RINTERPOLATE_PRESEARCH
void rinterpolate_make_presearch(struct rinterpolate_table_t * RESTRICT table)
void rinterpolate_make_presearch(struct rinterpolate_table_t * RESTRICT const table)
{
/*
* First time with this table: Find the variable presearch
......
#include "rinterpolate.h"
#include "rinterpolate_internal.h"
void rinterpolate_make_steps(struct rinterpolate_table_t * RESTRICT table)
void rinterpolate_make_steps(struct rinterpolate_table_t * RESTRICT const table)
{
/*
* First time with this table: Find the variable steps
......
......@@ -5,7 +5,7 @@
#include "rinterpolate.h"
struct rinterpolate_data_t * rinterpolate(
const rinterpolate_float_t * RESTRICT table, // (pointer to) the data table
const rinterpolate_float_t * RESTRICT const table, // (const pointer to) the data table
struct rinterpolate_data_t * rinterpolate_data, // where rinterpolate stores data
const rinterpolate_counter_t n, // the number of parameters (i.e. dimensions)
const rinterpolate_counter_t d, // the number of data items
......@@ -15,9 +15,9 @@ struct rinterpolate_data_t * rinterpolate(
const rinterpolate_counter_t cache_length // tells us to use the cache, or not
);
void rinterpolate_free_data(struct rinterpolate_data_t * RESTRICT rinterpolate_data);
rinterpolate_counter_t rinterpolate_alloc_dataspace(struct rinterpolate_data_t ** RESTRICT r);
void rinterpolate_build_flags(struct rinterpolate_data_t * RESTRICT rinterpolate_data);
void rinterpolate_free_data(struct rinterpolate_data_t * RESTRICT const rinterpolate_data);
rinterpolate_counter_t rinterpolate_alloc_dataspace(struct rinterpolate_data_t ** RESTRICT const r);
void rinterpolate_build_flags(struct rinterpolate_data_t * RESTRICT const rinterpolate_data);
/*
* Internal functions
......@@ -25,58 +25,54 @@ void rinterpolate_build_flags(struct rinterpolate_data_t * RESTRICT rinterpolate
void rinterpolate_error(rinterpolate_counter_t errnum,
char * RESTRICT format,
struct rinterpolate_data_t * RESTRICT rinterpolate_data,
...);
rinterpolate_signed_counter_t rinterpolate_id_table(
struct rinterpolate_data_t * RESTRICT rinterpolate_data,
const rinterpolate_float_t * RESTRICT data
struct rinterpolate_data_t * RESTRICT const rinterpolate_data,
...) No_return Gnu_format_args(2,4);
rinterpolate_signed_counter_t Pure_function rinterpolate_id_table(
struct rinterpolate_data_t * RESTRICT const rinterpolate_data,
const rinterpolate_float_t * RESTRICT const data
);
rinterpolate_Boolean_t rinterpolate_check_cache(
struct rinterpolate_table_t * RESTRICT table,
const rinterpolate_float_t * RESTRICT x,
rinterpolate_float_t * RESTRICT r);
struct rinterpolate_table_t * RESTRICT const table,
const rinterpolate_float_t * RESTRICT const x,
rinterpolate_float_t * RESTRICT const r);
#ifdef RINTERPOLATE_CACHE
void rinterpolate_alloc_cacheline(struct rinterpolate_table_t * RESTRICT table);
void rinterpolate_alloc_cacheline(struct rinterpolate_table_t * RESTRICT const table);
#endif
void rinterpolate_make_steps(struct rinterpolate_table_t * RESTRICT table);
void rinterpolate_alloc_hypertable(struct rinterpolate_table_t * RESTRICT table);
void rinterpolate_alloc_varcount(struct rinterpolate_table_t * RESTRICT table);
void rinterpolate_make_steps(struct rinterpolate_table_t * RESTRICT const table);
void rinterpolate_alloc_hypertable(struct rinterpolate_table_t * RESTRICT const table);
void rinterpolate_alloc_varcount(struct rinterpolate_table_t * RESTRICT const table);
void rinterpolate_search_table(
struct rinterpolate_table_t * RESTRICT table,
const rinterpolate_float_t * RESTRICT x
struct rinterpolate_table_t * RESTRICT const table,
const rinterpolate_float_t * RESTRICT const x
);
void rinterpolate_construct_hypercube(
struct rinterpolate_table_t * RESTRICT table
struct rinterpolate_table_t * RESTRICT const table
);
void rinterpolate_interpolate(
const struct rinterpolate_table_t * RESTRICT table,
const rinterpolate_float_t * RESTRICT x,
rinterpolate_float_t * RESTRICT r);
const struct rinterpolate_table_t * RESTRICT const table,
const rinterpolate_float_t * RESTRICT const x,
rinterpolate_float_t * RESTRICT const r);
void rinterpolate_store_cache(struct rinterpolate_table_t * RESTRICT table,
const rinterpolate_float_t * RESTRICT x,
const rinterpolate_float_t * RESTRICT r);
void rinterpolate_store_cache(struct rinterpolate_table_t * RESTRICT const table,
const rinterpolate_float_t * RESTRICT const x,
const rinterpolate_float_t * RESTRICT const r);
void rinterpolate_make_presearch(struct rinterpolate_table_t * RESTRICT table);
void rinterpolate_make_presearch(struct rinterpolate_table_t * RESTRICT const table);
#ifdef RINTERPOLATE_CACHE
void rinterpolate_resize_cache(struct rinterpolate_table_t * RESTRICT table,
void rinterpolate_resize_cache(struct rinterpolate_table_t * RESTRICT const table,
const rinterpolate_counter_t cache_length);
#endif
#ifdef RINTERPOLATE_PRESEARCH
void rinterpolate_resize_presearch(struct rinterpolate_data_t * RESTRICT rinterpolate_data,
const size_t n);
#endif
rinterpolate_counter_t rinterpolate_add_new_table(
struct rinterpolate_data_t * RESTRICT rinterpolate_data,
const rinterpolate_float_t * RESTRICT table,
struct rinterpolate_data_t * RESTRICT const rinterpolate_data,
const rinterpolate_float_t * RESTRICT const table,
const rinterpolate_counter_t n,
const rinterpolate_counter_t d,
const rinterpolate_counter_t line_length,
......
......@@ -3,7 +3,7 @@
#ifdef RINTERPOLATE_CACHE
void rinterpolate_resize_cache(struct rinterpolate_table_t * RESTRICT table,
void rinterpolate_resize_cache(struct rinterpolate_table_t * RESTRICT const table,
const rinterpolate_counter_t cache_length)
{
/*
......
......@@ -2,8 +2,8 @@
#include "rinterpolate_internal.h"
void rinterpolate_search_table(
struct rinterpolate_table_t * RESTRICT table,
const rinterpolate_float_t * RESTRICT x
struct rinterpolate_table_t * RESTRICT const table,
const rinterpolate_float_t * RESTRICT const x
)
{
rinterpolate_counter_t j;
......
......@@ -2,9 +2,9 @@
#include "rinterpolate_internal.h"
#ifdef RINTERPOLATE_CACHE
void rinterpolate_store_cache(struct rinterpolate_table_t * RESTRICT table,
const rinterpolate_float_t * RESTRICT x,
const rinterpolate_float_t * RESTRICT r
void rinterpolate_store_cache(struct rinterpolate_table_t * RESTRICT const table,
const rinterpolate_float_t * RESTRICT const x,
const rinterpolate_float_t * RESTRICT const r
)
{
/* use the next line of the cache */
......
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