inp014.c 6.39 KB
/*
 *  inp014.c
 */

#include <stdio.h>
#include <stdlib.h>
#include <math.h>


#include "ints.h"

#define SIGN_EXTEND_16(x)       (((x) & 0x8000) ? ((x) | ~0xffff) : (x))


/*
 *  Globals
 */
static int MaxX = 0;
static int MaxY = 0;
static int TileNumber = 0;

/*  input signals */
static int  st_span;
static int  ncyc;
static int  l;
static int  s;
static int  t;
static int  w;
static int  min_level;
static int  detail_en;
static int  sharp_en;
static int  lod_en;
static int  persp_en;
static int  copy;
static int  samp_type;
static int  tlut_en;
static int  tlut_type;
static int  max_level;
static int  prim_tile;
static int  load;
static int  shift_coord;
static int  tile_adrs;
static int64 tile_data;
static int  we_tile_size;
static int  we_tile_attr;
static int  vm_in;
static int  vm_dv;
static int  load_dv;
static int  dv;
static int  exit1;
static int  xo;
static int  yo;
static int64 copy_bus;


/*
 *  print_header, tabular format header file
 */
static void
  print_header( void )
{
  printf("#\n");
  printf("#  tc_div logical verification (continued)\n");
  printf("#\n");
  printf("gclk                    @C\n");
  printf("st_span                 @I\n");
  printf("ncyc                    @I\n");
  printf("l[15:0]                 @I\n");
  printf("s[15:0]                 @I\n");
  printf("t[15:0]                 @I\n");
  printf("w[15:0]                 @I\n");
  printf("min_level[4:0]          @I\n");
  printf("detail_en               @I\n");
  printf("sharp_en                @I\n");
  printf("lod_en                  @I\n");
  printf("persp_en                @I\n");
  printf("copy                    @I\n");
  printf("samp_type               @I\n");
  printf("tlut_en                 @I\n");
  printf("tlut_type               @I\n");
  printf("max_level[2:0]          @I\n");
  printf("prim_tile[2:0]          @I\n");
  printf("load                    @I\n");
  printf("shift_coord             @I\n");
  printf("tile_adrs[2:0]          @I\n");
  printf("tile_data[47:0]         @I\n");
  printf("we_tile_size            @I\n");
  printf("we_tile_attr            @I\n");
  printf("vm_in[7:0]              @I\n");
  printf("vm_dv                   @I\n");
  printf("copy_load[63:0]         @B\n");
  printf("load_dv                 @I\n");
  printf("dv_0                    @I\n");
  printf("exit1                   @I\n");
  printf("x[9:0]                  @I\n");
  printf("y[9:0]                  @I\n");
  printf("\n");  /* required blank line before vectors */
}


/*
 *  print_vector, tabular file format vector
 */
static void
  print_vector( void )
{
  printf("%01x ", st_span);
  printf("%01x   ", ncyc);
  printf("0x%04x ", l & 0xffff);
  printf("0x%04x ", s & 0xffff);
  printf("0x%04x ", t & 0xffff);
  printf("0x%04x   ", w & 0xffff);
  printf("0x%02x ", min_level & 0x1f);
  printf("%01x ", detail_en & 1);
  printf("%01x ", sharp_en & 1);
  printf("%01x ", lod_en & 1);
  printf("%01x ", persp_en & 1);
  printf("%01x ", copy & 1);
  printf("%01x ", samp_type & 1);
  printf("%01x ", tlut_en & 1);
  printf("%01x ", tlut_type & 1);
  printf("0x%01x ", max_level & 0x7);
  printf("0x%01x ", prim_tile & 0x7);
  printf("%01x ",load & 1);
  printf("%01x   ",shift_coord & 1);
  printf("0x%01x ",tile_adrs & 0x7);
  printf("0x%04x%08x ",tile_data.word1 & 0xffff, tile_data.word0);
  printf("%01x ",we_tile_size & 1);
  printf("%01x   ",we_tile_attr & 1);
  printf("0x%02x ",vm_in & 0xff);
  printf("%01x   ",vm_dv & 1);
  printf("0x%08x%08x ", copy_bus.word1, copy_bus.word0);
  printf("%01x   ",load_dv & 1);
  printf("%01x ",dv & 1);
  printf("%01x ",exit1 & 1);
  printf("0x%03x ", xo & 0x3ff);
  printf("0x%03x ", yo & 0x3ff);
  printf("\n");
}


/*
 *  walk_coord()
 */

static void
  walk_coord( int tile, int sl, int sh, int tl, int th, int step)
{
  /* set all inputs to zero */

  float s_flt, t_flt, w_flt, recip, s_prod, t_prod;
  int cnt;

  st_span = 0;
  ncyc = 0;
  l = 0;
  s = 0;
  t = 0;
  w = 0;
  min_level = 0;
  detail_en = 0;
  sharp_en = 0;
  lod_en = 0;
  persp_en = 0;
  copy = 0;
  samp_type = 0;
  tlut_en = 0;
  tlut_type = 0;
  max_level = 0;
  prim_tile = 0;
  load = 0;
  shift_coord = 0;
  tile_adrs = 0;
  tile_data.word0 = 0;
  tile_data.word1 = 0;
  we_tile_size = 0;
  we_tile_attr = 0;
  vm_in = 0;
  vm_dv = 0;
  load_dv = 0;
  dv = 0;
  exit1 = 0;
  xo = 0;
  yo = 0;
  copy_bus.word0 = 0;
  copy_bus.word1 = 0;

  dv = 1;
  persp_en = 1;

  cnt = 0;

  while (cnt < 5120)
  {
    s = (random() >> 15) & 0xffff;
    s = SIGN_EXTEND_16(s);
    t = (random() >> 15) & 0xffff;
    t = SIGN_EXTEND_16(t);
    w = (random() >> 16) & 0x7fff;

    s_flt = (float) s / pow(2.0, 5.0);
    t_flt = (float) t / pow(2.0, 5.0);
    w_flt = (float) w / pow(2.0, 15.0);
    recip = 1 / w_flt;
    s_prod = recip * s_flt;
    t_prod = recip * t_flt;

    if (((s_prod < 1024.0) && (s_prod >= -1024.0)) || 
       ((t_prod < 1024.0) && (t_prod >= -1024.0)))
    {
      s &= 0xffff;
      t &= 0xffff;
      print_vector();
      cnt++;
    }
  }
}


/*
 *   main()
 */

int
  main(int argc, char **argv)
{

  int cnt, seed;

  print_header();

  /* set all inputs to zero */

  st_span = 0;
  ncyc = 0;
  l = 0;
  s = 0;
  t = 0;
  w = 0;
  min_level = 0;
  detail_en = 0;
  sharp_en = 0;
  lod_en = 0;
  persp_en = 0;
  copy = 0;
  samp_type = 0;
  tlut_en = 0;
  tlut_type = 0;
  max_level = 0;
  prim_tile = 0;
  load = 0;
  shift_coord = 0;
  tile_data.word0 = 0;
  tile_data.word1 = 0;
  we_tile_size = 0;
  we_tile_attr = 0;
  vm_in = 0;
  vm_dv = 0;
  load_dv = 0;
  dv = 0;
  exit1 = 0;
  xo = 0;
  yo = 0;
  copy_bus.word0 = 0;
  copy_bus.word1 = 0;

  /* seed random number gen */
  seed = 0x76543210;
  srandom(seed);


  /* print 5 dead lines */
  for (cnt = 0; cnt < 5; cnt++)
    print_vector();

  /* read entire tmem as 16-bit RGBA */

  printf("# verify output multiplier of divider\n");

  walk_coord(0x2, 0, 1023, 0, 1, 4);


  /* set all inputs to zero */

  st_span = 0;
  ncyc = 0;
  l = 0;
  s = 0;
  t = 0;
  w = 0;
  min_level = 0;
  detail_en = 0;
  sharp_en = 0;
  lod_en = 0;
  persp_en = 0;
  copy = 0;
  samp_type = 0;
  tlut_en = 0;
  tlut_type = 0;
  max_level = 0;
  prim_tile = 0;
  load = 0;
  shift_coord = 0;
  tile_data.word0 = 0;
  tile_data.word1 = 0;
  we_tile_size = 0;
  we_tile_attr = 0;
  vm_in = 0;
  vm_dv = 0;
  load_dv = 0;
  dv = 0;
  exit1 = 0;
  xo = 0;
  yo = 0;
  copy_bus.word0 = 0;
  copy_bus.word1 = 0;

  /* print 15 dead lines */
  printf("#\n");
  for (cnt = 0; cnt < 15; cnt++)
    print_vector();


  return(0);
}