diff --git a/utils/alt/sizeof_01.c b/utils/alt/sizeof_01.c deleted file mode 100644 index cb23c574e9b463cbd667208fa829f33912a04c9f..0000000000000000000000000000000000000000 --- a/utils/alt/sizeof_01.c +++ /dev/null @@ -1,70 +0,0 @@ -#include <stdio.h> - -int main () -{ - - char vetor_01[5], var_01; - int vetor_02[6], var_02; - float vetor_03[7], var_03; - double vetor_04[6], var_04; - long int var_05; - long long int var_06; - short int var_07; - - struct cls { - int a; - char b[5]; - int c[10]; - }; - - printf("\n"); - printf("\n"); - - printf("\n"); - printf(" ================================== \n"); - printf("| TIPO | TAMANHO EM BYTES |\n"); - printf("|==================================|\n"); - printf("| char | %2lu |\n", sizeof(char)); - printf("| int | %2lu |\n", sizeof(int)); - printf("| unsig int | %2lu |\n", sizeof(unsigned int)); - printf("| short int | %2lu |\n", sizeof(short int)); - printf("| long int | %2lu |\n", sizeof(long int)); - printf("| long long int | %2lu |\n", sizeof(long long int)); - printf("| float | %2lu |\n", sizeof(float)); - printf("| double | %2lu |\n", sizeof(double)); - printf("| long double | %2lu |\n", sizeof(long double)); - printf("| struct cls | %2lu |\n", sizeof(struct cls)); - printf(" ==================================|\n"); - printf("| void * | %2lu |\n", sizeof(void *)); - printf("| char * | %2lu |\n", sizeof(char *)); - printf("| int * | %2lu |\n", sizeof(int *)); - printf("| short int * | %2lu |\n", sizeof(short int *)); - printf("| long int * | %2lu |\n", sizeof(long int *)); - printf("| float * | %2lu |\n", sizeof(float *)); - printf("| double * | %2lu |\n", sizeof(double *)); - printf("| long double * | %2lu |\n", sizeof(long double *)); - printf(" ================================== \n"); - - printf("\n"); - printf("\n"); - - printf(" ====================================== \n"); - printf("| VARIAVEL | TAMANHO EM BYTES |\n"); - printf("|======================================|\n"); - printf("| char v[5] | %2lu |\n", sizeof vetor_01 ); - printf("| int v[6] | %2lu |\n", sizeof vetor_02 ); - printf("| float v[7] | %2lu |\n", sizeof vetor_03 ); - printf("| double v[6] | %2lu |\n", sizeof(vetor_04)); - printf("| char var | %2lu |\n", sizeof var_01 ); - printf("| int var | %2lu |\n", sizeof var_02 ); - printf("| short int var | %2lu |\n", sizeof(var_07)); - printf("| long int var | %2lu |\n", sizeof(var_05)); - printf("| long long int var | %2lu |\n", sizeof(var_06)); - printf("| float var | %2lu |\n", sizeof var_03 ); - printf("| double var | %2lu |\n", sizeof(var_04)); - printf(" ====================================== \n"); - - printf("\n"); - printf("\n"); - -} diff --git a/utils/alt/sizeof_02.c b/utils/alt/sizeof_02.c deleted file mode 100644 index cddc32dace570b71fbce2d86bb114c282e1ca904..0000000000000000000000000000000000000000 --- a/utils/alt/sizeof_02.c +++ /dev/null @@ -1,34 +0,0 @@ -#include <stdio.h> - -#define BITCOUNT(x) (((BX_(x) + (BX_(x) >> 4)) & 0x0F0F0F0F) % 255) -#define BX_(x) ((x) - \ - (((x) >> 1) & 0x77777777) - \ - (((x) >> 2) & 0x33333333) - \ - (((x) >> 3) & 0x11111111)) -int main () -{ - - char var_01 = 0x80; - int var_02 = 0x8000; - long int var_05 = 0x800000; - long long int var_06 = 0x800000000000; - short int var_07 = 0x8000; - - printf("\n"); - printf("\n"); - - printf(" ====================================== \n"); - printf("| VARIAVEL | TAMANHO EM BITS |\n"); - printf("|======================================|\n"); - printf("| char var | %2d |\n", BITCOUNT(var_01) ); - printf("| int var | %2d |\n", BITCOUNT(var_02) ); - printf("| short int var | %2lu |\n", sizeof(var_07)); - printf("| long int var | %2lu |\n", sizeof(var_05)); - printf("| long long int var | %2lu |\n", sizeof(var_06)); - printf(" ====================================== \n"); - - printf("\n"); - printf("\n"); - -} - diff --git a/utils/alt/sizeof_03.c b/utils/alt/sizeof_03.c deleted file mode 100644 index 7fb08649547bf3264cc88c799e6ffc1539fdf271..0000000000000000000000000000000000000000 --- a/utils/alt/sizeof_03.c +++ /dev/null @@ -1,14 +0,0 @@ -#include <stdio.h> -#include <stdlib.h> -#include <math.h> -#include <string.h> - -int main () -{ - - printf("%lu %lu %lu %lu %lu\n", sizeof(long long int), sizeof(long int), sizeof(int), sizeof(short int), sizeof(char)); - - return 0; - -} - diff --git a/utils/alt/utils-00.c b/utils/alt/utils-00.c deleted file mode 100644 index e712d67f3658502f8af37ce5a0ab0e1ef2390dd7..0000000000000000000000000000000000000000 --- a/utils/alt/utils-00.c +++ /dev/null @@ -1,21 +0,0 @@ -#include <stdio.h> -#include "utils.h" - -/* Retorna tempo em milisegundos - - Forma de uso: - - double tempo; - tempo = timestamp(); - <trecho de programa do qual se deseja medir tempo> - tempo = timestamp() - tempo; -*/ - -double timestamp(void) -{ - struct timeval tp; - gettimeofday(&tp, NULL); - // printf("\n*** %7.10lf ms %7.10lf ms\n", tp.tv_sec*1.0e3, tp.tv_usec*1.0e-3); - return((double)(tp.tv_sec*1.0e3 + tp.tv_usec*1.0e-3)); -} - diff --git a/utils/alt/utils-00.h b/utils/alt/utils-00.h deleted file mode 100644 index 14a0ccece58b66243a5b8eade70a09b17154a8d1..0000000000000000000000000000000000000000 --- a/utils/alt/utils-00.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef __UTILS_H__ -#define __UTILS_H__ - -#include <stdlib.h> -#include <sys/time.h> - -double timestamp(void); - -#endif // __UTILS_H__ - diff --git a/utils/alt/utils-01.c b/utils/alt/utils-01.c deleted file mode 100644 index 8acfd1733b81478802044691b8cfbf460fcc1197..0000000000000000000000000000000000000000 --- a/utils/alt/utils-01.c +++ /dev/null @@ -1,35 +0,0 @@ -#include <stdio.h> -#include <string.h> -#include <math.h> - -#include "utils.h" - -/* Retorna tempo em milisegundos - - Forma de uso: - - double tempo; - tempo = timestamp(); - <trecho de programa do qual se deseja medir tempo> - tempo = timestamp() - tempo; -*/ - -double timestamp(void) -{ - struct timespec tp; - clock_gettime(CLOCK_MONOTONIC_RAW, &tp); - return((double)(tp.tv_sec*1.0e3 + tp.tv_nsec*1.0e-6)); -} - -string_t markerName(string_t baseName, int n) -{ - string_t mark = (string_t) malloc( (strlen(baseName)+1) + (log10(n)+1) + 1 ); - - sprintf(mark, "%s_%u", baseName,n); - - // printf("*** %s\n", mark); - - return mark; - -} - diff --git a/utils/alt/utils-01.h b/utils/alt/utils-01.h deleted file mode 100644 index 5c10efd7d0d334285953832a26b42954bc9c4870..0000000000000000000000000000000000000000 --- a/utils/alt/utils-01.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef __UTILS_H__ -#define __UTILS_H__ - -#include <stdlib.h> -#include <time.h> - - -typedef double real_t; -typedef double rtime_t; -typedef char * string_t; - -double timestamp(void); -string_t markerName(string_t baseName, int n); - -#endif // __UTILS_H__ - diff --git a/utils/alt/utils-02.c b/utils/alt/utils-02.c deleted file mode 100644 index 95c887f1631b0e704fc9f46750b6ab4c89b98e5f..0000000000000000000000000000000000000000 --- a/utils/alt/utils-02.c +++ /dev/null @@ -1,51 +0,0 @@ -// by W.Zola (2017) - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <math.h> - -#include <sys/types.h> -#include <sys/stat.h> -#include <fcntl.h> -#include <sys/mman.h> - -#include "utils.h" - -/* Retorna tempo em nanosegundos - - Forma de uso: - - chronometer_t *tempo; - chrono_reset( &tempo); - - chrono_start( &tempo); - <trecho de programa do qual se deseja medir tempo> - chrono_stop( &tempo); - - chrono_reportTime( &tempo, "Tempo: "); -*/ - -void chrono_reset( chronometer_t *chrono ) -{ - chrono->xtotal_ns = 0; - chrono->xn_events = 0; -} - -void chrono_start( chronometer_t *chrono ) { - clock_gettime(CLOCK_MONOTONIC_RAW, &(chrono->xadd_time1) ); -} - -void chrono_stop( chronometer_t *chrono ) { - - clock_gettime(CLOCK_MONOTONIC_RAW, &(chrono->xadd_time2) ); - - long long ns1 = chrono->xadd_time1.tv_sec*1.0e9 + chrono->xadd_time1.tv_nsec; - long long ns2 = chrono->xadd_time2.tv_sec*1.0e9 + chrono->xadd_time2.tv_nsec; - chrono->deltaT_ns = ns2 - ns1; -} - -void chrono_reportTime( chronometer_t *chrono, char *prompt ) { - printf("\n%s (ns): %llu ns\n", prompt, chrono->deltaT_ns); -} - diff --git a/utils/alt/utils-02.h b/utils/alt/utils-02.h deleted file mode 100644 index 092dfec00c97b9053ec1cf2116aeb8fa79913b72..0000000000000000000000000000000000000000 --- a/utils/alt/utils-02.h +++ /dev/null @@ -1,36 +0,0 @@ -#ifndef __UTILS_H__ -#define __UTILS_H__ - -// by W.Zola (2017) - -#include <time.h> - -typedef struct { - - struct timespec xadd_time1, xadd_time2; - long long deltaT_ns; - -} chronometer_t; - - -/* Retorna intervlo de tempo em nanosegundos - - Forma de uso: - - chronometer_t *tempo; - chrono_reset( &tempo); - - chrono_start( &tempo); - <trecho de programa do qual se deseja medir tempo> - chrono_stop( &tempo); - - chrono_reportTime( &tempo, "Tempo: "); -*/ - -void chrono_reset( chronometer_t *chrono ); -void chrono_start( chronometer_t *chrono ); -void chrono_stop( chronometer_t *chrono ); -void chrono_reportTime( chronometer_t *chrono, chr *prompt ); - -#endif // __UTILS_H__ - diff --git a/utils/utils.c b/utils/utils.c index 8acfd1733b81478802044691b8cfbf460fcc1197..53aeb74e18751fb641593add1a4540922f5dab26 100644 --- a/utils/utils.c +++ b/utils/utils.c @@ -33,3 +33,8 @@ string_t markerName(string_t baseName, int n) } +int isPot2(int n) +{ + int k; + return (k = log2(n)) == log2(n) ; +} diff --git a/utils/utils.h b/utils/utils.h index 5c10efd7d0d334285953832a26b42954bc9c4870..7d10cb04fe727fecf700f0c64768bc241003d4f6 100644 --- a/utils/utils.h +++ b/utils/utils.h @@ -11,6 +11,7 @@ typedef char * string_t; double timestamp(void); string_t markerName(string_t baseName, int n); +int isPot2 (int n); #endif // __UTILS_H__