
/*******************************************************************************
*
* File Qhat.c
*
* Copyright (C) 2005 Martin Luescher, 2007 Bjoern Leder, 2010 Andrea Nobile
*
* This software is distributed under the terms of the GNU General Public
* License (GPL)
*
* Application of the even-odd preconditioned Wilson-Dirac operator
*
* The externally accessible functions are
*
*   void Qhat(int k,int l)
*     Applies Qhat to the global single-precision field *ps[k][] and assigns
*     the result to *ps[l][]
*
*   void Qoe(int k,int l)
*     Applies the operator Qoe to the even part of the global single-precision
*     field *ps[k][] and assigns the result to *ps[l][]
*
*   void Qeo(int k,int l)
*     Applies the operator Qeo to the odd part of the global single-precision
*     field *ps[k][] and *subtracts* the result from *ps[l][]
*
*   void Qnohat(int k,int l)
*     Applies the full Dirac operator Q to the global single-precision field
*     *ps[k][] and assigns the result to *ps[l][]
*
*   void Qhat_blk(block_t *b,int k,int l)
*     Applies Qhat to the single-precision field b.s[k][] on the block b and
*     assigns the result to b.s[l][]
*
*   void Qoe_blk(block_t *b,int k,int l)
*     Applies the operator Qoe to the even part of the single-precision field
*     b.s[k][] on the block b and assigns the result to b.s[l][]
*
*   void Qeo_blk(block_t *b,int k,int l)
*     Applies the operator Qeo to the odd part of the single-precision field
*     b.s[k][] on the block b and *subtracts* the result from b.s[l][]
*
*   void Qnohat_blk(block_t *b,int k,int l)
*     Applies the full Dirac operator Q to the single-precision field b.s[k][]
*     on the block b and assigns the result to b.s[l][]
*
* Notes:
*
* The notation and normalization conventions are specified in the notes
* "Implementation of the lattice Dirac operator" (file doc/dirac.ps)
*
* In all these programs it is assumed that Qee and Qoo (or 1/Qoo in the
* case of the preconditioned operator) are stored in the appropriate sw
* arrays. Whether the field arrays are in the proper condition can normally
* be determined by querying the flags data base [see flags.c]
*
* All non-block programs in this file act globally and should be called
* from all processes with the same parameters. Communication buffers are
* allocated automatically when needed
*
* The block programs, on the other hand, act locally. Any errors occuring in
* these are recorded by the error_loc [utils.c] function
*
*******************************************************************************/

#define QHAT_BGQ_C

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
//#include "mpi.h"
#include "su3.h"
//#include "flags.h"
//#include "start.h"
//#include "block.h"
//#include "sw_term.h"
//#include "dirac.h"
//#include "global.h"

#include "qpx.h"

static float coe=-0.25,ceo;
static const spinor s0={{{0.0f}}};

#define _vector_mul_assign(r,c) \
   (r).c1.re*=(c); \
   (r).c1.im*=(c); \
   (r).c2.re*=(c); \
   (r).c2.im*=(c); \
   (r).c3.re*=(c); \
   (r).c3.im*=(c)

#if (defined VERBOSE_DEBUG)

#define _print_dir(mu) \
    printf( "\ndir %s\n", mu )

#define _cv_print(a) \
    printf( "vecX = {%f+j%f, %f+j%f, %f+j%f}\n", a.c1.re, a.c1.im, a.c2.re, a.c2.im, a.c3.re, a.c3.im ) 

#define _cv_print2(a,b) \
    printf( "vecA = {%f+j%f, %f+j%f, %f+j%f}\n", a.c1.re, a.c1.im, a.c2.re, a.c2.im, a.c3.re, a.c3.im ); \
    printf( "vecB = {%f+j%f, %f+j%f, %f+j%f}\n", b.c1.re, b.c1.im, b.c2.re, b.c2.im, b.c3.re, b.c3.im ) 

#define _qpx_debug_vectorpair_print(p) \
    _qpx_vectorpair_print(p)

#else

#define _print_dir(mu)
#define _cv_print(a)
#define _cv_print2(a,b)
#define _qpx_debug_vectorpair_print(p)

#endif

//static spinor rs_bgq;
//spinor rs_bgq;

_qpx_vectorpair_static_declare(r12);
_qpx_vectorpair_static_declare(r34);

//static void qoe_bgq(int *piup,int *pidn,su3 *u,spinor *pk)
void qoe_bgq(int *piup,int *pidn,su3 *u,spinor *pk)
{
   spinor *sp,*sm;

#pragma disjoint(*u,*sp,*sm)
   __alignx(16,sp);
   __alignx(16,sm);
   __alignx(16,u);

    _qpx_su3_declare(cm);
    _qpx_vectorpair_declare(p1);
    _qpx_vectorpair_declare(p2);

/******************************* direction +0 *********************************/

      sp=pk+(*(piup++));

      _print_dir("+0");

      //_qpx_vectorpair_au_load(p1,(*sp).c1,(*sp).c2, cm_1_0, cm_1_1 );
      //_qpx_vectorpair_au_load(p2,(*sp).c3,(*sp).c4, cm_1_0, cm_1_1 );
      _qpx_vectorpair_spinor34_load(p1,p2,(*sp),cm_1_0,cm_1_1,cm_1_2 );

      _qpx_debug_vectorpair_print( p1 );
      _qpx_debug_vectorpair_print( p2 );

      _qpx_vectorpair_add( p1, p1, p2 );
      _qpx_debug_vectorpair_print( p1 );

      _qpx_su3_a_load( cm, (*u), p2_0 );
      _qpx_su3_multiply( r12, cm, p1 );
      _qpx_vectorpair_assign( r34, r12 );
      
      _qpx_debug_vectorpair_print( r12 );
      _qpx_debug_vectorpair_print( r34 );

/******************************* direction -0 *********************************/

      sm=pk+(*(pidn++));
      u+=1;

      _print_dir("-0");

      //_qpx_vectorpair_au_load( p1, (*sm).c1, (*sm).c2, cm_1_0, cm_1_1 );
      //_qpx_vectorpair_au_load( p2, (*sm).c3, (*sm).c4, cm_1_0, cm_1_1 );
      _qpx_vectorpair_spinor34_load(p1,p2,(*sm),cm_1_0,cm_1_1,cm_1_2 );

      _qpx_vectorpair_sub( p1, p1, p2 );
      _qpx_debug_vectorpair_print( p1 );

      _qpx_su3_u_load( cm, (*u), p2_0 );
      _qpx_su3_inv_multiply( p2, cm, p1 );
      _qpx_debug_vectorpair_print( p2 );
      _qpx_vectorpair_add( r12, r12, p2 );
      _qpx_vectorpair_sub( r34, r34, p2 );

      _qpx_debug_vectorpair_print( r12 );
      _qpx_debug_vectorpair_print( r34 );

/******************************* direction +1 *********************************/

      sp=pk+(*(piup++));
      u+=1;

      _print_dir("+1");

      //_qpx_vectorpair_au_load( p1, (*sp).c1, (*sp).c2, cm_1_0, cm_1_1 );
      //_qpx_vectorpair_ua_load( p2, (*sp).c4, (*sp).c3, cm_1_0, cm_1_1 );
      _qpx_vectorpair_spinor43_load(p1,p2,(*sp),cm_1_0,cm_1_1,cm_1_2,cm_2_0);

      _qpx_vectorpair_i_add( p1, p1, p2, cm_1_0 );
      _qpx_debug_vectorpair_print( p1 );

      // p2 = U*{ s1+i*s4, s2+i*s3 }
      _qpx_su3_a_load( cm, (*u), p2_0 );
      _qpx_su3_multiply( p2, cm, p1 );
      _qpx_debug_vectorpair_print( p2 );

      // r12 += U*{ s1+i*s4, s2+i*s3 }
      // r34 -= i*U*{ s2+i*s3, s1+i*s4 }
      _qpx_vectorpair_add( r12, r12, p2 );
      _qpx_vectorpair_i_xsub( r34, r34, p2, cm_1, cm_2_0 );

      _qpx_debug_vectorpair_print( r12 );
      _qpx_debug_vectorpair_print( r34 );

/******************************* direction -1 *********************************/

      sm=pk+(*(pidn++));
      u+=1;

      _print_dir("-1");

      //_qpx_vectorpair_au_load( p1, (*sp).c1, (*sp).c2, cm_1_0, cm_1_1 );
      //_qpx_vectorpair_ua_load( p2, (*sp).c4, (*sp).c3, cm_1_0, cm_1_1 );
      _qpx_vectorpair_spinor43_load(p1,p2,(*sm),cm_1_0,cm_1_1,cm_1_2,cm_2_0);

      _qpx_vectorpair_i_sub( p1, p1, p2, cm_1_0 );
      _qpx_debug_vectorpair_print( p1 );

      // p2 = U*{ s1-i*s4, s2-i*s3 }
      _qpx_su3_u_load( cm, (*u), p2_0 );
      _qpx_su3_inv_multiply( p2, cm, p1 );
      _qpx_debug_vectorpair_print( p2 );

      // r12 += U*{ s1-i*s4, s2-i*s3 }
      // r34 += i*U*{ s2-i*s3, s1-i*s4 }
      _qpx_vectorpair_add( r12, r12, p2 );
      _qpx_vectorpair_i_xadd( r34, r34, p2, cm_1, cm_2_0 );

      _qpx_debug_vectorpair_print( r12 );
      _qpx_debug_vectorpair_print( r34 );

/******************************* direction +2 *********************************/

      sp=pk+(*(piup++));
      u+=1;

      _print_dir("+2");

      //_qpx_vectorpair_au_load( p1, (*sp).c1, (*sp).c2, cm_1_0, cm_1_1 );
      //_qpx_vectorpair_ua_load( p2, (*sp).c4, (*sp).c3, cm_1_0, cm_1_1 );
      _qpx_vectorpair_spinor43_load(p1,p2,(*sp),cm_1_0,cm_1_1,cm_1_2,cm_2_0);

      _qpx_vectorpair_1add2sub( p1, p1, p2, cm_1_0 );
      _qpx_debug_vectorpair_print( p1 );

      // p2 = U*{ s1+s4, s2-s3 }
      _qpx_su3_a_load( cm, (*u), p2_0 );
      _qpx_su3_multiply( p2, cm, p1 );
      _qpx_debug_vectorpair_print( p2 );

      // r12 += U*{ s1+s4, s2-s3 }
      // r34 += U*{ -1 * s2-s3, s1+s4 }
      _qpx_vectorpair_add( r12, r12, p2 );
      _qpx_vectorpair_x1sub2add( r34, r34, p2, cm_1, cm_2_0 );

      _qpx_debug_vectorpair_print( r12 );
      _qpx_debug_vectorpair_print( r34 );

/******************************* direction -2 *********************************/

      sm=pk+(*(pidn++));
      u+=1;

      _print_dir("-2");

      //_qpx_vectorpair_au_load( p1, (*sp).c1, (*sp).c2, cm_1_0, cm_1_1 );
      //_qpx_vectorpair_ua_load( p2, (*sp).c4, (*sp).c3, cm_1_0, cm_1_1 );
      _qpx_vectorpair_spinor43_load(p1,p2,(*sm),cm_1_0,cm_1_1,cm_1_2,cm_2_0);

      _qpx_vectorpair_1sub2add( p1, p1, p2, cm_1_0 );
      _qpx_debug_vectorpair_print( p1 );

      // p2 = U*{ s1-s4, s2+s3 }
      _qpx_su3_u_load( cm, (*u), p2_0 );
      _qpx_su3_inv_multiply( p2, cm, p1 );
      _qpx_debug_vectorpair_print( p2 );

      // r12 += U*{ s1-s4, s2+s3 }
      // r34 += U*{ s2+s3, -1 * s1-s4 }
      _qpx_vectorpair_add( r12, r12, p2 );
      _qpx_vectorpair_x1add2sub( r34, r34, p2, cm_1, cm_2_0 );

      _qpx_debug_vectorpair_print( r12 );
      _qpx_debug_vectorpair_print( r34 );

/******************************* direction +3 *********************************/

      sp=pk+(*(piup));
      u+=1;

      _print_dir("+3");

      //_qpx_vectorpair_au_load( p1, (*sp).c1, (*sp).c2, cm_1_0, cm_1_1 );
      //_qpx_vectorpair_au_load( p2, (*sp).c3, (*sp).c4, cm_1_0, cm_1_1 );
      _qpx_vectorpair_spinor34_load(p1,p2,(*sp),cm_1_0,cm_1_1,cm_1_2 );

      _qpx_vectorpair_i_1add2sub( p1, p1, p2, cm_1_0 );
      _qpx_debug_vectorpair_print( p1 );

      // p2 = U*{ s1+i*s3, s2-i*s4 }
      _qpx_su3_a_load( cm, (*u), p2_0 );
      _qpx_su3_multiply( p2, cm, p1 );
      _qpx_debug_vectorpair_print( p2 );

      // r12 += U*{ s1+i*s3, s2-i*s4 }
      // r34 += i*U*{ -1 * s1+i*s3, s2-i*s4 }
      _qpx_vectorpair_add( r12, r12, p2 );
      _qpx_vectorpair_i_1sub2add( r34, r34, p2, cm_1_0 );

      _qpx_debug_vectorpair_print( r12 );
      _qpx_debug_vectorpair_print( r34 );

/******************************* direction -3 *********************************/

      sm=pk+(*(pidn));
      u+=1;

      _print_dir("-3");

      //_qpx_vectorpair_au_load( p1, (*sm).c1, (*sm).c2, cm_1_0, cm_1_1 );
      //_qpx_vectorpair_au_load( p2, (*sm).c3, (*sm).c4, cm_1_0, cm_1_1 );
      _qpx_vectorpair_spinor34_load(p1,p2,(*sm),cm_1_0,cm_1_1,cm_1_2 );

      _qpx_vectorpair_i_1sub2add( p1, p1, p2, cm_1_0 );
      _qpx_debug_vectorpair_print( p1 );

      // p2 = U*{ s1-i*s3, s2+i*s4 }
      _qpx_su3_u_load( cm, (*u), p2_0 );
      _qpx_su3_inv_multiply( p2, cm, p1 );
      _qpx_debug_vectorpair_print( p2 );

      // r12 += U*{ s1-i*s3, s2+i*s4 }
      // r34 += i*U*{ s1-i*s3, -1 * s2+i*s4 }
      _qpx_vectorpair_add( r12, r12, p2 );
      _qpx_vectorpair_i_1add2sub( r34, r34, p2, cm_1_0 );

      _qpx_debug_vectorpair_print( r12 );
      _qpx_debug_vectorpair_print( r34 );

      cm_1_0 = VEC_LOAD_S( 0l, &coe );
      _qpx_vectorpair_mul( r34, r34, cm_1_0 );
      cm_1_0 = vec_neg( cm_1_0 );
      _qpx_vectorpair_mul( r12, r12, cm_1_0 );

      _qpx_debug_vectorpair_print( r12 );
      _qpx_debug_vectorpair_print( r34 );
}


//static void qeo_bgq(int *piup,int *pidn,su3 *u,spinor *pl)
void qeo_bgq(int *piup,int *pidn,su3 *u,spinor *pl)
{
   spinor *sp,*sm;

#pragma disjoint(*u,*sp,*sm)
   __alignx(16,sp);
   __alignx(16,sm);
   __alignx(16,u);

    _qpx_su3_declare(cm);
    _qpx_vectorpair_declare(p1);
    _qpx_vectorpair_declare(p2);

    _qpx_debug_vectorpair_print( r12 );
    _qpx_debug_vectorpair_print( r34 );

/******************************* direction +0 *********************************/

      sp=pl+(*(piup++));

      _print_dir("+0");

      _qpx_vectorpair_sub( p1, r12, r34 );
      _qpx_debug_vectorpair_print( p1 );

      _qpx_su3_a_load( cm, (*u), p2_0 );
      _qpx_su3_inv_multiply( p2, cm, p1 );
      _qpx_debug_vectorpair_print( p2 );

      //_qpx_vectorpair_au_load( cm_0, (*sp).c1, (*sp).c2, cm_1_0, cm_1_1 );
      //_qpx_vectorpair_au_load( p1, (*sp).c3, (*sp).c4, cm_1_0, cm_1_1 );
      _qpx_vectorpair_spinor34_load(cm_0,p1,(*sp),cm_1_0,cm_1_1,cm_1_2 );

      _qpx_vectorpair_sub( cm_0, cm_0, p2 );
      _qpx_vectorpair_sub( p1, p1, p2 );

      //_qpx_vectorpair_au_store( (*sp).c1, (*sp).c2, cm_0, cm_1_0, cm_1_1 );
      //_qpx_vectorpair_au_store( (*sp).c3, (*sp).c4, p1, cm_1_0, cm_1_1 );
      _qpx_vectorpair_spinor34_store( (*sp), cm_0, p1, cm_1_0, cm_1_1, cm_1_2 );

      _cv_print2( (*sp).c1, (*sp).c2 );
      _cv_print2( (*sp).c3, (*sp).c4 );

/******************************* direction -0 *********************************/

      sm=pl+(*(pidn++));
      u+=1;

      _print_dir("-0");

      _qpx_vectorpair_add( p1, r12, r34 );
      _qpx_debug_vectorpair_print( p1 );

      _qpx_su3_u_load( cm, (*u), p2_0 );
      _qpx_su3_multiply( p2, cm, p1 );
      _qpx_debug_vectorpair_print( p2 );

      _cv_print2( (*sm).c1, (*sm).c2 );
      _cv_print2( (*sm).c3, (*sm).c4 );

      //_qpx_vectorpair_au_load( cm_0, (*sm).c1, (*sm).c2, cm_1_0, cm_1_1 );
      //_qpx_vectorpair_au_load( p1, (*sm).c3, (*sm).c4, cm_1_0, cm_1_1 );
      _qpx_vectorpair_spinor34_load(cm_0,p1,(*sm),cm_1_0,cm_1_1,cm_1_2 );

      _qpx_vectorpair_sub( cm_0, cm_0, p2 );
      _qpx_vectorpair_add( p1, p1, p2 );

      //_qpx_vectorpair_au_store( (*sm).c1, (*sm).c2, cm_0, cm_1_0, cm_1_1 );
      //_qpx_vectorpair_au_store( (*sm).c3, (*sm).c4, p1, cm_1_0, cm_1_1 );
      _qpx_vectorpair_spinor34_store( (*sm), cm_0, p1, cm_1_0, cm_1_1, cm_1_2 );

      _cv_print2( (*sm).c1, (*sm).c2 );
      _cv_print2( (*sm).c3, (*sm).c4 );

/******************************* direction +1 *********************************/

      sp=pl+(*(piup++));
      u+=1;

      _print_dir("+1");

      _qpx_vectorpair_i_xsub( p1, r12, r34, cm_1, cm_2_0 );
      _qpx_debug_vectorpair_print( p1 );

      _qpx_su3_a_load( cm, (*u), p2_0 );
      _qpx_su3_inv_multiply( p2, cm, p1 );
      _qpx_debug_vectorpair_print( p2 );

      //_qpx_vectorpair_au_load( cm_0, (*sp).c1, (*sp).c2, cm_1_0, cm_1_1 );
      //_qpx_vectorpair_au_load( p1, (*sp).c3, (*sp).c4, cm_1_0, cm_1_1 );
      _qpx_vectorpair_spinor34_load(cm_0,p1,(*sp),cm_1_0,cm_1_1,cm_1_2 );

      _qpx_vectorpair_sub( cm_0, cm_0, p2 );
      _qpx_vectorpair_i_xadd( p1, p1, p2, cm_1, cm_2_0 );

      //_qpx_vectorpair_au_store( (*sp).c1, (*sp).c2, cm_0, cm_1_0, cm_1_1 );
      //_qpx_vectorpair_au_store( (*sp).c3, (*sp).c4, p1, cm_1_0, cm_1_1 );
      _qpx_vectorpair_spinor34_store( (*sp), cm_0, p1, cm_1_0, cm_1_1, cm_1_2 );

      _cv_print2( (*sp).c1, (*sp).c2 );
      _cv_print2( (*sp).c3, (*sp).c4 );

/******************************* direction -1 *********************************/

      sm=pl+(*(pidn++));
      u+=1;

      _print_dir("-1");

      _qpx_vectorpair_i_xadd( p1, r12, r34, cm_1, cm_2_0 );
      _qpx_debug_vectorpair_print( p1 );

      _qpx_su3_u_load( cm, (*u), p2_0 );
      _qpx_su3_multiply( p2, cm, p1 );
      _qpx_debug_vectorpair_print( p2 );

      //_qpx_vectorpair_au_load( cm_0, (*sm).c1, (*sm).c2, cm_1_0, cm_1_1 );
      //_qpx_vectorpair_au_load( p1, (*sm).c3, (*sm).c4, cm_1_0, cm_1_1 );
      _qpx_vectorpair_spinor34_load(cm_0,p1,(*sm),cm_1_0,cm_1_1,cm_1_2 );

      _qpx_vectorpair_sub( cm_0, cm_0, p2 );
      _qpx_vectorpair_i_xsub( p1, p1, p2, cm_1, cm_2_0 );

      //_qpx_vectorpair_au_store( (*sm).c1, (*sm).c2, cm_0, cm_1_0, cm_1_1 );
      //_qpx_vectorpair_au_store( (*sm).c3, (*sm).c4, p1, cm_1_0, cm_1_1 );
      _qpx_vectorpair_spinor34_store( (*sm), cm_0, p1, cm_1_0, cm_1_1, cm_1_2 );

      _cv_print2( (*sm).c1 , (*sm).c2 );
      _cv_print2( (*sm).c3 , (*sm).c4 );

/******************************* direction +2 *********************************/

      sp=pl+(*(piup++));
      u+=1;

      _print_dir("+2");

      _qpx_vectorpair_x1sub2add( p1, r12, r34, cm_1, cm_2_0 );
      _qpx_debug_vectorpair_print( p1 );

      _qpx_su3_a_load( cm, (*u), p2_0 );
      _qpx_su3_inv_multiply( p2, cm, p1 );
      _qpx_debug_vectorpair_print( p2 );

      //_qpx_vectorpair_au_load( cm_0, (*sp).c1, (*sp).c2, cm_1_0, cm_1_1 );
      //_qpx_vectorpair_au_load( p1, (*sp).c3, (*sp).c4, cm_1_0, cm_1_1 );
      _qpx_vectorpair_spinor34_load(cm_0,p1,(*sp),cm_1_0,cm_1_1,cm_1_2 );

      _qpx_vectorpair_sub( cm_0, cm_0, p2 );
      _qpx_vectorpair_x1add2sub( p1, p1, p2, cm_1, cm_2_0 );

      //_qpx_vectorpair_au_store( (*sp).c1, (*sp).c2, cm_0, cm_1_0, cm_1_1 );
      //_qpx_vectorpair_au_store( (*sp).c3, (*sp).c4, p1, cm_1_0, cm_1_1 );
      _qpx_vectorpair_spinor34_store( (*sp), cm_0, p1, cm_1_0, cm_1_1, cm_1_2 );

      _cv_print2( (*sp).c1, (*sp).c2 );
      _cv_print2( (*sp).c3, (*sp).c4 );

/******************************* direction -2 *********************************/

      sm=pl+(*(pidn++));
      u+=1;

      _print_dir("-2");

      _qpx_vectorpair_x1add2sub( p1, r12, r34, cm_1, cm_2_0 );
      _qpx_debug_vectorpair_print( p1 );

      _qpx_su3_u_load( cm, (*u), p2_0 );
      _qpx_su3_multiply( p2, cm, p1 );
      _qpx_debug_vectorpair_print( p2 );

      //_qpx_vectorpair_au_load( cm_0, (*sm).c1, (*sm).c2, cm_1_0, cm_1_1 );
      //_qpx_vectorpair_au_load( p1, (*sm).c3, (*sm).c4, cm_1_0, cm_1_1 );
      _qpx_vectorpair_spinor34_load(cm_0,p1,(*sm),cm_1_0,cm_1_1,cm_1_2 );

      _qpx_vectorpair_sub( cm_0, cm_0, p2 );
      _qpx_vectorpair_x1sub2add( p1, p1, p2, cm_1, cm_2_0 );

      //_qpx_vectorpair_au_store( (*sm).c1, (*sm).c2, cm_0, cm_1_0, cm_1_1 );
      //_qpx_vectorpair_au_store( (*sm).c3, (*sm).c4, p1, cm_1_0, cm_1_1 );
      _qpx_vectorpair_spinor34_store( (*sm), cm_0, p1, cm_1_0, cm_1_1, cm_1_2 );

      _cv_print2( (*sm).c1, (*sm).c2 );
      _cv_print2( (*sm).c3, (*sm).c4 );

/******************************* direction +3 *********************************/

      sp=pl+(*(piup));
      u+=1;

      _print_dir("+3");

      _qpx_vectorpair_i_1sub2add( p1, r12, r34, p2_0 );
      _qpx_debug_vectorpair_print( p1 );

      _qpx_su3_a_load( cm, (*u), p2_0 );
      _qpx_su3_inv_multiply( p2, cm, p1 );
      _qpx_debug_vectorpair_print( p2 );

      //_qpx_vectorpair_au_load( cm_0, (*sp).c1, (*sp).c2, cm_1_0, cm_1_1 );
      //_qpx_vectorpair_au_load( p1, (*sp).c3, (*sp).c4, cm_1_0, cm_1_1 );
      _qpx_vectorpair_spinor34_load(cm_0,p1,(*sp),cm_1_0,cm_1_1,cm_1_2 );

      _qpx_vectorpair_sub( cm_0, cm_0, p2 );
      _qpx_vectorpair_i_1add2sub( p1, p1, p2, cm_1_0 );

      //_qpx_vectorpair_au_store( (*sp).c1, (*sp).c2, cm_0, cm_1_0, cm_1_1 );
      //_qpx_vectorpair_au_store( (*sp).c3, (*sp).c4, p1, cm_1_0, cm_1_1 );
      _qpx_vectorpair_spinor34_store( (*sp), cm_0, p1, cm_1_0, cm_1_1, cm_1_2 );

      _cv_print2( (*sp).c1, (*sp).c2 );
      _cv_print2( (*sp).c3, (*sp).c4 );

/******************************* direction -3 *********************************/

      sm=pl+(*(pidn));
      u+=1;

      _print_dir("-3");

      _qpx_vectorpair_i_1add2sub( p1, r12, r34, p2_0 );
      _qpx_debug_vectorpair_print( p1 );

      _qpx_su3_u_load( cm, (*u), p2_0 );
      _qpx_su3_multiply( p2, cm, p1 );
      _qpx_debug_vectorpair_print( p2 );

      //_qpx_vectorpair_au_load( cm_0, (*sm).c1, (*sm).c2, cm_1_0, cm_1_1 );
      //_qpx_vectorpair_au_load( p1, (*sm).c3, (*sm).c4, cm_1_0, cm_1_1 );
      _qpx_vectorpair_spinor34_load(cm_0,p1,(*sm),cm_1_0,cm_1_1,cm_1_2 );

      _qpx_vectorpair_sub( cm_0, cm_0, p2 );
      _qpx_vectorpair_i_1sub2add( p1, p1, p2, cm_1_0 );

      //_qpx_vectorpair_au_store( (*sm).c1, (*sm).c2, cm_0, cm_1_0, cm_1_1 );
      //_qpx_vectorpair_au_store( (*sm).c3, (*sm).c4, p1, cm_1_0, cm_1_1 );
      _qpx_vectorpair_spinor34_store( (*sm), cm_0, p1, cm_1_0, cm_1_1, cm_1_2 );

      _cv_print2( (*sm).c1, (*sm).c2 );
      _cv_print2( (*sm).c3, (*sm).c4 );
}

void dummy_Qhat_blk_BGQ(pauli* m, su3 *b, spinor* pk, int iter)
{
      int piup[4];
      int pidown[4];

      for( int mu=0; mu<4; ++mu ) {
          piup[mu] = 2*mu;
          pidown[mu] = 2*mu+1;
      }

      _qpx_pauli_declare(pm);
      _qpx_vectorpair_declare(pm_x);
      _qpx_vector_declare(perm);
      _qpx_vector_declare(work);

   coe=-0.25f;

   for (int i=0;i<iter;++i) {
      qoe(piup,pidown,b,pk);      

       _qpx_pauli_load_all(pm,(*m));
       m+=1;
       _qpx_pauli_multiply_all(pm_x,pm,r12, perm,work, pm_0,pm_1);
       _qpx_vectorpair_assign( r12, pm_x );

       _qpx_pauli_load_all(pm,(*m));
       m-=1;
       _qpx_pauli_multiply_all(pm_x,pm,r34, perm,work, pm_0,pm_1);
       _qpx_vectorpair_assign( r34, pm_x );

      qeo(piup,pidown,b,pk);
   }
}

