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

#include <stdint.h>
#include <stdio.h>

#if !defined(__riscv) && (USEDBSP==BSP_RTEMS)
  #define USE_RTEMS 1
#endif

#if USE_RTEMS

#include <stdio.h>      /* standard I/O                */
#include <stdlib.h>     /* for exit   - 1 occurrence   */
#include <math.h>

#include <rtems.h>
#include <sys/timespec.h>
#include <sys/unistd.h>

#else

#include "../common_sys_header.inc"

#endif


#define counter_t long unsigned 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]))

#if USE_RTEMS
  #define dtime clock
#else
  unsigned dtime(void)
  {
    return get_usec();
  }
#endif

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

#if USE_RTEMS
rtems_task Init(
  rtems_task_argument ignored
)
#else
int main(void)
#endif
{
#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;

  system_init();

#if defined (PACKED)
  printf("FFT - SINGLE PRECISION, PACKED\n");
#else
  printf("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]);
  printf("\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));
    }
    printf("\n");
  }
  printf("Done!\n");
//#ifndef NOHWCONF
  do {
    unsigned ticks_lo, ticks_hi, insns_lo, insns_hi, fpop_lo, fpop_hi, fpld_lo, fpld_hi, fpst_lo, fpst_hi;
    sysregs_stop();
    sysregs_read_ext(&ticks_lo, &ticks_hi, &insns_lo, &insns_hi, &fpop_lo, &fpop_hi, &fpld_lo, &fpld_hi, &fpst_lo, &fpst_hi);
    if (ticks_hi)
      printf("TEST EXECUTED IN (%u * 2^32 + %u) TICKS AND (%u * 2^32 + %u) INSTRUCTIONS, FPU: FPOP (%u * 2^32 + %u) FPLD (%u * 2^32 + %u) FPST (%u * 2^32 + %u) \n\n", ticks_hi, ticks_lo, insns_hi, insns_lo, fpop_hi, fpop_lo, fpld_hi, fpld_lo, fpst_hi, fpst_lo);
    else
      printf("TEST EXECUTED IN %u TICKS AND %u INSTRUCTIONS, FPU: FPOP %u FPLD %u FPST %u \n\n", ticks_lo, insns_lo, fpop_lo, fpld_lo, fpst_lo);
  } while(0);
//#endif /* NOHWCONF */
  printf("\n\nEND OF TEST\n\n");

  system_done();

  return 0;
}

#if USE_RTEMS
/* configuration information */

#include <bsp.h>

/* NOTICE: the clock driver is explicitly disabled */
#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
#if 0
#define CONFIGURE_USE_DEVFS_AS_BASE_FILESYSTEM
#endif

#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
#define CONFIGURE_MAXIMUM_TASKS 1

#define CONFIGURE_INIT
#define CONFIGURE_INIT_TASK_ATTRIBUTES RTEMS_FLOATING_POINT

#include <rtems/confdefs.h>

#endif