From 2377d51e74e580b9362f80fdcc751489bc9d7ab2 Mon Sep 17 00:00:00 2001 From: Robert Izzard <r.izzard@surrey.ac.uk> Date: Sat, 7 Sep 2019 14:20:52 +0000 Subject: [PATCH] fix build on rpi: timers was broken unless on an intel-compatible CPU, now we use the standard timer functions where rdtsc ticks are not available fixed formatting of size_t and other types --- src/binary_c_code_options.h | 3 +- src/buffering/buffered_printf.c | 8 +-- src/evolution/evolve_system.c | 2 +- src/libmemoize/memoize.c | 34 ++++----- src/logging/load_stardata.c | 6 +- src/setup/parse_arguments.c | 2 +- src/setup/version.c | 118 ++++++++++++++++---------------- src/timers/timers.c | 2 + 8 files changed, 89 insertions(+), 86 deletions(-) diff --git a/src/binary_c_code_options.h b/src/binary_c_code_options.h index 1af3d25e6..2f95efa1d 100644 --- a/src/binary_c_code_options.h +++ b/src/binary_c_code_options.h @@ -616,9 +616,10 @@ void Print_trace(void); */ #if defined __GNUC__ && \ - (defined __i386__ || defined __x86_64__ || defined __ia64__) + (defined __i386__ || defined __x86_64__ || defined __ia64__) #define TIMER #endif +#define TIMER #ifdef TIMER diff --git a/src/buffering/buffered_printf.c b/src/buffering/buffered_printf.c index 87af000ea..8dabd75e6 100644 --- a/src/buffering/buffered_printf.c +++ b/src/buffering/buffered_printf.c @@ -175,7 +175,7 @@ int Gnu_format_args(3,4) buffered_printf(struct stardata_t * RESTRICT const star t->raw_buffer_alloced; new_alloc_size++; - printf("cf new_alloc_size %ld to alloced %ld\n", + printf("cf new_alloc_size %zu to alloced %zu\n", new_alloc_size, t->raw_buffer_alloced); @@ -229,9 +229,9 @@ int Gnu_format_args(3,4) buffered_printf(struct stardata_t * RESTRICT const star snprintf( string, BUFFERED_PRINTF_ERROR_BUFFER_SIZE-1, - "SYSTEM_ERROR Cannot Printf because buffer has been exceeded (want %ld bytes, max is %ld)\n", - (long int)new_alloc_size, - (long int)BUFFERED_PRINTF_MAX_BUFFER_SIZE); + "SYSTEM_ERROR Cannot Printf because buffer has been exceeded (want %zu bytes, max is %zu)\n", + new_alloc_size, + BUFFERED_PRINTF_MAX_BUFFER_SIZE); memcpy(t->raw_buffer + t->raw_buffer_size,string,dn); t->raw_buffer_size += dn; } diff --git a/src/evolution/evolve_system.c b/src/evolution/evolve_system.c index a3ebe46e9..c9301ae9f 100644 --- a/src/evolution/evolve_system.c +++ b/src/evolution/evolve_system.c @@ -40,7 +40,7 @@ int evolve_system(struct stardata_t * RESTRICT const stardata) stardata->evolving = TRUE; - Dprint("EVOLVE SYSTEM stardata=%p previous_stardata=%p stardata = %p store = %p (buffer = %p, size %ld)\n", + Dprint("EVOLVE SYSTEM stardata=%p previous_stardata=%p stardata = %p store = %p (buffer = %p, size %zu)\n", stardata, stardata->previous_stardata, stardata, diff --git a/src/libmemoize/memoize.c b/src/libmemoize/memoize.c index 04d02e46d..867bb34a0 100644 --- a/src/libmemoize/memoize.c +++ b/src/libmemoize/memoize.c @@ -242,7 +242,7 @@ void * memoize_store_result(struct memoize_hash_t * RESTRICT const memo, * * This should be a rare occurrance (~once for each function). */ - vb("store_result: need new hash item, realloc memo stack (sizeof %ld) at %p\n", + vb("store_result: need new hash item, realloc memo stack (sizeof %zu) at %p\n", sizeof(struct memoize_hash_item_t) * (memo->n+1), memo->item); @@ -295,7 +295,7 @@ void * memoize_store_result(struct memoize_hash_t * RESTRICT const memo, h->funcname = Malloc((s+1)*sizeof(char)); strlcpy(h->funcname,funcname,s+1); - vb("store_result: new is at # %ld, at %p (lists: parameter=%p (memsize %ld (double=%ld int=%ld char=%ld)) result=%p (memsize %ld)), h=%p, h->funcname=\"%s\", h->n=%ld, strlen %ld)\n", + vb("store_result: new is at # %zu, at %p (lists: parameter=%p (memsize %zu (double=%zu int=%zu char=%zu)) result=%p (memsize %zu)), h=%p, h->funcname=\"%s\", h->n=%zu, strlen %zu)\n", memo->n-1, memo->item, h->parameter, @@ -328,7 +328,7 @@ void * memoize_store_result(struct memoize_hash_t * RESTRICT const memo, #endif if(nmax>1) { - vb("store_result: mv parameter %p to %p size %ld*%ld=%ld\n", + vb("store_result: mv parameter %p to %p size %zu*%zu=%zu\n", h->parameter, h->parameter+1, h->parameter_memsize,nmax-1,h->parameter_memsize*(nmax-1)); @@ -336,7 +336,7 @@ void * memoize_store_result(struct memoize_hash_t * RESTRICT const memo, h->parameter, h->parameter_memsize*(nmax-1)); - vb("store_result: mv result %p to %p size %ld*%ld=%ld\n", + vb("store_result: mv result %p to %p size %zu*%zu=%zu\n", h->result, h->result +1, h->result_memsize,nmax-1,h->result_memsize*(nmax-1)); @@ -370,7 +370,7 @@ void * memoize_store_result(struct memoize_hash_t * RESTRICT const memo, * Increase number of stored items */ h->n = Min(nmax,h->n+1); - vb("store_result: h->n increased to %ld\n",h->n); + vb("store_result: h->n increased to %zu\n",h->n); /* * Store in the top of the stack @@ -378,7 +378,7 @@ void * memoize_store_result(struct memoize_hash_t * RESTRICT const memo, memcpy(item(h,parameter,0), parameter, h->parameter_memsize); memcpy(item(h,result,0), result, h->result_memsize); - vb("store_result: Return pointer at %p (h=%p h->n=%ld)\n\n", + vb("store_result: Return pointer at %p (h=%p h->n=%zu)\n\n", item(h,result,0), h, h->n); @@ -407,7 +407,7 @@ struct memoize_hash_item_t Pure_function * memoize_search_hash(const struct memo vb("search: try to match against memo=%p, funcname = \"%s\"\n", memo, funcname); - vb("search: memo has n=%ld entries\n", + vb("search: memo has n=%zu entries\n", memo->n); size_t i; @@ -415,8 +415,8 @@ struct memoize_hash_item_t Pure_function * memoize_search_hash(const struct memo { struct memoize_hash_item_t * h = & memo->item[i]; - vb("search : h = %p from i = %ld\n",h,i); - vb("search: cf. item %ld at %p : item with %ld parameters, funcname = \"%s\" to required funcname = \"%s\"\n", + vb("search : h = %p from i = %zu\n",h,i); + vb("search: cf. item %zu at %p : item with %zu parameters, funcname = \"%s\" to required funcname = \"%s\"\n", i, h, h->n, @@ -440,7 +440,7 @@ struct memoize_hash_t * memoize_initialize(struct memoize_hash_t * RESTRICT * RE * * Returns the pointer to the memo, or NULL on failure. */ - vb("initialize: Try to malloc %ld bytes\n",sizeof(struct memoize_hash_t)); + vb("initialize: Try to malloc %zu bytes\n",sizeof(struct memoize_hash_t)); *m = Malloc(sizeof(struct memoize_hash_t)); if(*m != NULL) { @@ -479,7 +479,7 @@ void memoize_free(struct memoize_hash_t ** RESTRICT m) { struct memoize_hash_item_t * h = &memo->item[i]; #ifdef MEMOIZE_STATS - printf("Memoize: function \"%s\" : %ld hits (%g s), %ld misses (%g s)\n", + printf("Memoize: function \"%s\" : %zu hits (%g s), %zu misses (%g s)\n", h->funcname, h->nhits, (double)h->thits, @@ -579,7 +579,7 @@ void * Pure_function memoize_search_result( for(j=0; j<h->n; j++) { - vb("search_result: Match paramter at %p to h->parameter[%ld] at %p, memsize %ld : equal? %d\n", + vb("search_result: Match paramter at %p to h->parameter[%zu] at %p, memsize %zu : equal? %d\n", parameter, j, item(h,parameter,j), @@ -615,7 +615,7 @@ void * Pure_function memoize_search_result( /* * Matched: return pointer to the result */ - vb("search_result: return pointer %ld at %p\n", + vb("search_result: return pointer %zu at %p\n", j, item(h,result,j)); #ifdef MEMOIZE_STATS @@ -655,14 +655,14 @@ void memoize_status(const struct memoize_hash_t * const memo) printf("Memoize status: \n"); if(memo!=NULL) { - printf(" memo = %p and contains %ld items\n", + printf(" memo = %p and contains %zu items\n", memo, memo->n); int i; for(i=0;i<memo->n;i++) { struct memoize_hash_item_t * h = &memo->item[i]; - printf(" % 5d at %p contains %ld parameter/result pairs for function %s : { ", + printf(" % 5d at %p contains %zu parameter/result pairs for function %s : { ", i, h, h->n, @@ -674,7 +674,7 @@ void memoize_status(const struct memoize_hash_t * const memo) { void * p = item(h,parameter,j); void * r = item(h,result,j); - printf("%ld p=%p r=%p ", + printf("%zu p=%p r=%p ", j,p,r); if(j != h->n-1) printf(" : "); } @@ -710,4 +710,4 @@ size_t Pure_function memoize_sizeof(struct memoize_hash_t * const memo) #endif // MEMOIZE #endif // __HAVE_LIBMEMOIZE__ - \ No newline at end of file + diff --git a/src/logging/load_stardata.c b/src/logging/load_stardata.c index f2fb94c43..6b670fd70 100644 --- a/src/logging/load_stardata.c +++ b/src/logging/load_stardata.c @@ -70,7 +70,7 @@ void load_stardata(struct stardata_t * const stardata, if(have_read_bytes != sizeof(struct stardata_dump_t)) { Exit_binary_c(BINARY_C_FILE_READ_ERROR, - "Error when reading from stardata dump file at %s: expected %ld bytes of data, but only read %ld.\n", + "Error when reading from stardata dump file at %s: expected %zu bytes of data, but only read %zu.\n", filename, sizeof(struct stardata_dump_t), have_read_bytes); @@ -187,14 +187,14 @@ void load_stardata(struct stardata_t * const stardata, 1, sizeof(struct stardata_t), dumpfile); - printf("read %ld bytes into %p\n", + printf("read %zu bytes into %p\n", have_read_bytes, stardata->previous_stardatas[i]); if(have_read_bytes != sizeof(struct stardata_t)) { Exit_binary_c(BINARY_C_FILE_READ_ERROR, - "Error when reading from stardata dump file (previous stardata %d/%d) at %s: expected %ld bytes of data, but only read %ld.\n", + "Error when reading from stardata dump file (previous stardata %d/%d) at %s: expected %zu bytes of data, but only read %zu.\n", i, stardata->n_previous_stardatas, filename, diff --git a/src/setup/parse_arguments.c b/src/setup/parse_arguments.c index 12f94ca6d..489b378be 100644 --- a/src/setup/parse_arguments.c +++ b/src/setup/parse_arguments.c @@ -52,7 +52,7 @@ void parse_arguments(const int start, arg_count); /* copy to tmpstore */ - Dprint("Allocate %ld bytes for cmd_line_args table\n", + Dprint("Allocate %zu bytes for cmd_line_args table\n", sizeof(cmd_line_args2)); if(tmpstore->cmd_line_args==NULL) tmpstore->cmd_line_args=Malloc(sizeof(cmd_line_args2)); diff --git a/src/setup/version.c b/src/setup/version.c index e0613bd11..b1e9225ee 100644 --- a/src/setup/version.c +++ b/src/setup/version.c @@ -219,50 +219,50 @@ void version(struct stardata_t * RESTRICT const stardata) Show_string_macro(__unsigned__); Show_string_macro(__const__); Show_string_macro(__static__); - - Printf("Size of : unsigned int %ld, short int %ld, int %ld, long int %ld, long long int %ld, float %ld, double %ld, long double %ld, char %ld, Boolean %ld, stardata_t %ld, preferences_t %ld, star_t %ld, common_t %ld, model_t %ld, diffstats_t %ld, probability_distribution_t %ld, RLOF_orbit_t %ld, store_t %ld, tmpstore_t %ld, data_table_t %ld, Random_seed %ld, Random_buffer %ld, FILE %ld, void* %ld, unsigned int* %ld, int* %ld, long int* %ld, long long int* %ld, float* %ld, double* %ld, long double* %ld, char* %ld, Boolean* %ld, stardata_t* %ld, star_t* %ld, FILE* %ld, __int__ %ld, __double__ %ld, __unsigned__ __int__ %ld, __short__ __int__ %ld, __long__ __int__ %ld\n", - (long int)sizeof(unsigned int), - (long int)sizeof(short int), - (long int)sizeof(int), - (long int)sizeof(long int), - (long int)sizeof(long long int), - (long int)sizeof(float), - (long int)sizeof(double), - (long int)sizeof(long double), - (long int)sizeof(char), - (long int)sizeof(Boolean), - (long int)sizeof(struct stardata_t), - (long int)sizeof(struct preferences_t), - (long int)sizeof(struct star_t), - (long int)sizeof(struct common_t), - (long int)sizeof(struct model_t), - (long int)sizeof(struct diffstats_t), - (long int)sizeof(struct probability_distribution_t), - (long int)sizeof(struct RLOF_orbit_t), - (long int)sizeof(struct store_t), - (long int)sizeof(struct tmpstore_t), - (long int)sizeof(struct data_table_t), - (long int)sizeof(Random_seed), - (long int)sizeof(Random_buffer), - (long int)sizeof(FILE), - (long int)sizeof(void *), - (long int)sizeof(unsigned int *), - (long int)sizeof(int *), - (long int)sizeof(long int *), - (long int)sizeof(long long int *), - (long int)sizeof(float *), - (long int)sizeof(double *), - (long int)sizeof(long double *), - (long int)sizeof(char *), - (long int)sizeof(Boolean *), - (long int)sizeof(struct stardata_t *), - (long int)sizeof(struct star_t *), - (long int)sizeof(FILE *), - (long int)sizeof(__int__), - (long int)sizeof(__double__), - (long int)sizeof(__unsigned__ __int__), - (long int)sizeof(__short__ __int__), - (long int)sizeof(__long__ __int__) + + Printf("Size of : unsigned int %zu, short int %zu, int %zu, long int %zu, long long int %zu, float %zu, double %zu, long double %zu, char %zu, Boolean %zu, stardata_t %zu, preferences_t %zu, star_t %zu, common_t %zu, model_t %zu, diffstats_t %zu, probability_distribution_t %zu, RLOF_orbit_t %zu, store_t %zu, tmpstore_t %zu, data_table_t %zu, Random_seed %zu, Random_buffer %zu, FILE %zu, void* %zu, unsigned int* %zu, int* %zu, long int* %zu, long long int* %zu, float* %zu, double* %zu, long double* %zu, char* %zu, Boolean* %zu, stardata_t* %zu, star_t* %zu, FILE* %zu, __int__ %zu, __double__ %zu, __unsigned__ __int__ %zu, __short__ __int__ %zu, __long__ __int__ %zu\n", + sizeof(unsigned int), + sizeof(short int), + sizeof(int), + sizeof(long int), + sizeof(long long int), + sizeof(float), + sizeof(double), + sizeof(long double), + sizeof(char), + sizeof(Boolean), + sizeof(struct stardata_t), + sizeof(struct preferences_t), + sizeof(struct star_t), + sizeof(struct common_t), + sizeof(struct model_t), + sizeof(struct diffstats_t), + sizeof(struct probability_distribution_t), + sizeof(struct RLOF_orbit_t), + sizeof(struct store_t), + sizeof(struct tmpstore_t), + sizeof(struct data_table_t), + sizeof(Random_seed), + sizeof(Random_buffer), + sizeof(FILE), + sizeof(void *), + sizeof(unsigned int *), + sizeof(int *), + sizeof(long int *), + sizeof(long long int *), + sizeof(float *), + sizeof(double *), + sizeof(long double *), + sizeof(char *), + sizeof(Boolean *), + sizeof(struct stardata_t *), + sizeof(struct star_t *), + sizeof(FILE *), + sizeof(__int__), + sizeof(__double__), + sizeof(__unsigned__ __int__), + sizeof(__short__ __int__), + sizeof(__long__ __int__) ); @@ -278,14 +278,14 @@ void version(struct stardata_t * RESTRICT const stardata) Show_string_macro(_printf); #ifdef EVOLUTION_SPLITTING - Printf(", splitinfo_t %ld", - (long int)sizeof(struct splitinfo_t)); + Printf(", splitinfo_t %zu", + sizeof(struct splitinfo_t)); #endif #ifdef DISCS - Printf(", disc_t %ld, disc_thermal_zone_t %ld, power_law_t %ld", - (long int)sizeof(struct disc_t), - (long int)sizeof(struct disc_thermal_zone_t), - (long int)sizeof(struct power_law_t) + Printf(", disc_t %zu, disc_thermal_zone_t %zu, power_law_t %zu", + sizeof(struct disc_t), + sizeof(struct disc_thermal_zone_t), + sizeof(struct power_law_t) ); #endif Printf("\n"); @@ -412,7 +412,7 @@ void version(struct stardata_t * RESTRICT const stardata) struct stardata_t * s1 = Malloc(malloc_size); struct stardata_t * s2 = Malloc(malloc_size); size_t i; - printf("sizeof stardata %ld\n",size); + printf("sizeof stardata %zu\n",size); Reset_buffers; /* @@ -448,7 +448,7 @@ void version(struct stardata_t * RESTRICT const stardata) strided_memcpy(s2,s1,size,blocksize); i++; } - Printf("Speed of strided_memcpy (blocksize = %ld, all same) %g GiByte/s\n", + Printf("Speed of strided_memcpy (blocksize = %zu, all same) %g GiByte/s\n", blocksize, sizeof(struct stardata_t)*((float)i)/( GIGABYTE * (TIME_LEN * 1e-6) )); fflush(NULL); @@ -475,7 +475,7 @@ void version(struct stardata_t * RESTRICT const stardata) strided_memcpy(s2,s1,size,blocksize); i++; } - Printf("Speed of strided_memcpy (blocksize = %ld, 10%% different) %g GiByte/s\n", + Printf("Speed of strided_memcpy (blocksize = %zu, 10%% different) %g GiByte/s\n", blocksize, sizeof(struct stardata_t)*((float)i)/( GIGABYTE * (TIME_LEN * 1e-6) )); fflush(NULL); @@ -499,7 +499,7 @@ void version(struct stardata_t * RESTRICT const stardata) strided_memcpy(s2,s1,size,blocksize); i++; } - Printf("Speed of strided_memcpy (blocksize = %ld, 20%% different) %g GiByte/s\n", + Printf("Speed of strided_memcpy (blocksize = %zu, 20%% different) %g GiByte/s\n", blocksize, sizeof(struct stardata_t)*((float)i)/( GIGABYTE * (TIME_LEN * 1e-6) )); fflush(NULL); @@ -526,7 +526,7 @@ void version(struct stardata_t * RESTRICT const stardata) strided_memcpy(s2,s1,size,blocksize); i++; } - Printf("Speed of strided_memcpy (blocksize = %ld, 100%% different) %g GiByte/s\n", + Printf("Speed of strided_memcpy (blocksize = %zu, 100%% different) %g GiByte/s\n", blocksize, sizeof(struct stardata_t)*((float)i)/( GIGABYTE * (TIME_LEN * 1e-6) )); fflush(NULL); @@ -559,7 +559,7 @@ void version(struct stardata_t * RESTRICT const stardata) strided_memcpy(s2,s1,size,blocksize); i++; } - Printf("Speed of strided_memcpy (blocksize = %ld, 10%% different) %g GiByte/s\n", + Printf("Speed of strided_memcpy (blocksize = %zu, 10%% different) %g GiByte/s\n", blksize, sizeof(struct stardata_t)*((float)i)/( GIGABYTE * (TIME_LEN * 1e-6) )); fflush(NULL); @@ -684,9 +684,9 @@ void version(struct stardata_t * RESTRICT const stardata) { struct rlimit limit; getrlimit (RLIMIT_STACK, &limit); - Printf("Stack limit current = %ld, max = %ld (-1 means no limit)\n", - (long int) limit.rlim_cur, - (long int) limit.rlim_max); + Printf("Stack limit current = %ju, max = %ju (-1 means no limit)\n", + (uintmax_t)limit.rlim_cur, + (uintmax_t)limit.rlim_max); } Macrotest(SEGFAULTS); Macrotest(CATCH_SIGVTALRM); diff --git a/src/timers/timers.c b/src/timers/timers.c index 1f330debb..dc228354f 100644 --- a/src/timers/timers.c +++ b/src/timers/timers.c @@ -22,7 +22,9 @@ #endif //__INTEL_COMPILER #include <time.h> #include <stdint.h> +#if (defined __i386__ || defined __x86_64__ || defined __ia64__) #include <x86intrin.h> +#endif #endif //TIMER -- GitLab