fft-run.c 3.56 KB
//
// fft-run.c: this file is part of the SL program suite.
//
// Copyright (C) 2020, 2021 daiteq.
//
//


// #include <stdint.h>
#include <leon-myuart.h>
#include <sysregs.h>
#include <lconf.h>

#include <my_printf.h>

/* for clearing BSS section */
extern unsigned long __bss_start;  /* start address for the .bss section. defined in linker script */
extern unsigned long _end;         /* end address for the .bss section. defined in linker script */


#define counter_t int

#define putchar m_putchar

// extern FILE *stduart;
// extern FILE *dbgstdout;

void report_perf(int sz, int b, const char *pre, counter_t t, counter_t i) {
    printf("%s %d %u %lu %lu\n", pre, b, sz, t, i);
}

#ifndef TABLE_SIZE
#define TABLE_SIZE 10
#endif
#include "fft.h"

#include "fft_impl4.c"

__attribute__((always_inline))
unsigned delta(counter_t end, counter_t start) {
    return (start <= end) ? (end - start) : ((0xffffffffu-end) + start + 1);
}

#ifndef BLOCKSIZES
#define BLOCKSIZES 1,2,4,8,16,30
#endif
static const int blocksizes[] = { BLOCKSIZES };
#define NBLSZ (sizeof(blocksizes)/sizeof(blocksizes[0]))

#define dtime clock

#define Y_FFT_ARRAY_SIZE  ((1<<TABLE_SIZE)) // * sizeof(cpx_t))
cpx_t y_fft[Y_FFT_ARRAY_SIZE];

int main(void)
{
#ifndef LSZ
#define LSZ 1
#endif
    counter_t c1, c2;
    counter_t i1, i2;

//     cpx_t *y_fft = (cpx_t*)calloc((1<<TABLE_SIZE), sizeof(cpx_t));
//     dbgstdout = stduart;


  /* reset BSS section to zero */
  for(unsigned long *pMem = &__bss_start; pMem < &_end;) {
    *(pMem++) = 0;
  }

  init_uart();
  init_timer();

//   init_softfloat();

#ifndef NOHWCONF
  do {
//    printf(" > Y_FFT #elms=%d  size=%d <\n", Y_FFT_ARRAY_SIZE, sizeof(y_fft));
    lconf_type lconf;
    lconf_fpu_type lconf_fpu;
    lconf_swar_type lconf_swar;
    get_lconf(&lconf);
    get_lconf_fpu(&lconf_fpu);
    get_lconf_swar(&lconf_swar);
    report_lconf(&lconf);
    if ((lconf.fpu==FPU_DAIFPU)||(lconf.fpu==FPU_MEIKO))
      report_lconf_fpu(&lconf_fpu);
    report_lconf_swar(&lconf_swar);
    sysregs_init();
  } while(0);
#endif /* NOHWCONF */

#if defined (PACKED)
    m_print("FFT - SINGLE PRECISION, PACKED\n");
#else
    m_print("FFT - SINGLE PRECISION, NORMAL\n");
#endif

    unsigned i;
    printf("Columns:\nLN2(SZ)\tINSNS");
    for (i = 0; i < NBLSZ; i++)
	printf("\tCC_BLK%d", blocksizes[i]);
    putchar('\n');

#ifdef NOIOTIME
    sysregs_init();
#endif

    unsigned M;
    for (M = 1; M <= TABLE_SIZE; M++) {
	unsigned N = 1 << M;
	printf("%u ", N);
	for (i = 0; i < NBLSZ; i++) {
	    unsigned blocksize = blocksizes[i];
	    
#ifdef NOIOTIME
            sysregs_start();
#endif
	    c1 = dtime(); //mtperf_sample1(MTPERF_CLOCKS);
// 	    i1 = mtperf_sample1(MTPERF_EXECUTED_INSNS);
	    FFT_1(M, y_fft, N/2, sc_table_ptr, blocksize);
	    c2 = dtime(); //mtperf_sample1(MTPERF_CLOCKS);
// 	    i2 = mtperf_sample1(MTPERF_EXECUTED_INSNS);
	    
#ifdef NOIOTIME
            sysregs_stop();
#endif

	    if (i == 0) {
// 		printf("\t%u", delta(i2, i1));
		printf("\t");
	    }
	    printf("\t%u", delta(c2, c1));
	}
	putchar('\n');
    }
    printf("Done!\n");
#ifndef NOHWCONF
    do {
      unsigned ticks_lo, ticks_hi, insns_lo, insns_hi;
      sysregs_stop();
      sysregs_read(&ticks_lo, &ticks_hi, &insns_lo, &insns_hi);
      if (ticks_hi)
        printf("TEST EXECUTED IN (%u * 2^32 + %u) TICKS AND (%u * 2^32 + %u) INSTRUCTIONS\n\n", ticks_hi, ticks_lo, insns_hi, insns_lo);
      else
        printf("TEST EXECUTED IN %u TICKS AND %u INSTRUCTIONS\n\n", ticks_lo, insns_lo);
    } while(0);
#endif /* NOHWCONF */
    m_print("\n\nEND OF TEST\n\n");



    __asm__("ta 1; nop; nop;");
}