/*
*===============================================================================
*
* d/wilson_d501/neighb.h 
*
*-------------------------------------------------------------------------------
*
* Copyright (C) 2006 Thomas Streuer 
*
* This file is part of BQCD -- Berlin Quantum ChromoDynamics program
*
* BQCD is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* BQCD is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with BQCD.  If not, see <http:*www.gnu.org/licenses/>.
*
*-------------------------------------------------------------------------------
*/
// changes here must be reflected in cr_asm.cc and gs.S!!!

typedef struct
{
  short int* neighb_offs;                  // changes here must be reflected in cr_asm.cc and gs.S, bgl_comm.S !!!
  short int* neighb_offs_even;             //
  short int* neighb_offs_odd;
  short int* neighb_offs_rm;
  short int* neighb_offs_rm_even;
  short int* neighb_offs_rm_odd;
  int  volume;
  int  volh_tot;
  int gpr[32];
  double fpr[64];
  int ctr;
  int cr;
  int lr;
  int dummy;
  int fifo_stat_orig[16];
  short int* neighb_offs_l;
  short int* neighb_offs_l_even;
  short int* neighb_offs_l_odd;
  unsigned char t_position[4];
  unsigned char t_size[4];
  unsigned char phys_dir[4];
  int pe, n_pe; 
} w_data;

extern int* neighb;

extern w_data wilson_data;

extern int  torus_dir[4];
extern int  logical_dir[4];
extern int  boundary[4];
extern int  position[4];
extern int  t_position[4];
extern int  my_rank;
extern int  num_procs;
extern int  grid_nb[2][4];
extern int tot_bnd_size;
extern int  which_cpu;  /*  0/1 */
extern int grid[4];
extern int lattice[4];
extern int  bnd_size[4];
extern int  bnd_offs[4];
extern char* send_fifo_addr[2][3];
extern char* recv_fifo_addr[2][3];
extern char* send_stat_addr[2][3];
extern char* recv_stat_addr[2][3];

extern char* send_fifo4_addr;
extern char* recv_fifo4_addr;

extern void* stat_addr;

typedef struct 
{ 
  unsigned int type          : 8;
  unsigned int hintXPlus     : 1;
  unsigned int hintXMinus    : 1;
  unsigned int hintYPlus     : 1;
  unsigned int hintYMinus    : 1;
  unsigned int hintZPlus     : 1;
  unsigned int hintZMinus    : 1;
  unsigned int deposit       : 1;
  unsigned int fifoID        : 1;
  unsigned int size          : 3;
  unsigned int avail         : 2;
  unsigned int dynamicRoute  : 1;
  unsigned int vc            : 2;
  unsigned int destX         : 8;
  unsigned int destY         : 8;
  unsigned int destZ         : 8;
  unsigned int seqno         : 8;
  unsigned int chksum        : 8;
} hard_header;

typedef struct 
{
  unsigned int val1;
  unsigned int val2;
} soft_header;


typedef struct 
{
  hard_header hh;
  soft_header sh;
} header;

extern header send_header[2][3];
extern header recv_header[2][3];


extern const int fifo4_size;
extern const int fifo4_mask;

extern const int send_stat_byte_offs[2][3];
extern const int recv_stat_byte_offs[2][3];


void wilson_init_bqcd(int* l, int* g, int* vh, int* nn);
void wilson_init_test(int* l, int* g);
int sort(int i, int fw);
