jemnotesversion 2 / featuring c or see all/search

Aug 4
To see the assembly instructions generated for a piece of C code, use this:
gcc -c -g -Wa,-ahl src.c
Find out the macros, and values, predefined by gcc (includes useful things like __INT_MAX__).
gcc -dM -E - < /dev/null
Jul 22
Version 4.3 of gcc, has some significant improvements (more info), including this nice feature:
>> gcc -c -Q -Os --help=optimizers
The following options control optimizations:
  -falign-jumps                         [disabled]
  -falign-labels                        [disabled]
  -falign-loops                         [enabled]
# ...
  -fwhole-program                       [disabled]
  -fwrapv                               [disabled]
Jul 21
First, tic() and toc() functions. These work like Matlab: tic() starts the timer, and toc() stops it and gives formatted output. There’s also a tocq() function which just returns the number of elapsed seconds.
#include <time.h>
static clock_t tic_timestart;

void tic(void) {
   tic_timestart = clock();
}

float toc(void) {
   clock_t tic_timestop;
   tic_timestop = clock();
   printf("time: %8.2f.\n", (float)(tic_timestop - tic_timestart) / CLOCKS_PER_SEC);
   return (float)(tic_timestop - tic_timestart) / CLOCKS_PER_SEC;
}

float tocq(void) {
   clock_t tic_timestop;
   tic_timestop = clock();
   return (float)(tic_timestop - tic_timestart) / CLOCKS_PER_SEC;
}
A bit of code for counting flops: first, a statistics structure, then some defines.
/* CFDIV    divides             1/a[3]
* CFADD    adds                c[12] + d[12]
* CFMUL    multiplies          b[4] * h[7]
* CFASN    assigns             A[5] = 0
* CFSTO    stores              A[5] = (...)
* CFTFR    transfers           A[5] = b[7]
* CFNTF    negated transfers   A[5] = -b[7]
* CFCOM    compares            c[5] < b[7]
*/
typedef struct statistics_t *statistics;
typedef struct statistics_t {
   long div;
   long add;
   long mul;
   long asn;
   long sto;
   long tfr;
   long ntf;
   long com;
} Statistics;