
/*******************************************************************************
*
* File misc.h
*
* Copyright (C) 2005 Martin Luescher
*
* This software is distributed under the terms of the GNU General Public
* License (GPL)
*
*******************************************************************************/

#ifndef MISC_H
#define MISC_H

#include <limits.h>
#include <float.h>

#ifndef SU3_H
#include "su3.h"
#endif

#if ((DBL_MANT_DIG!=53)||(DBL_MIN_EXP!=-1021)||(DBL_MAX_EXP!=1024))
#error : Machine is not compliant with the IEEE-754 standard
#endif

#if (SHRT_MAX==0x7fffffff)
typedef short int stdint_t;
typedef unsigned short int stduint_t;
#elif (INT_MAX==0x7fffffff)
typedef int stdint_t;
typedef unsigned int stduint_t;
#elif (LONG_MAX==0x7fffffff)
typedef long int stdint_t;
typedef unsigned long int stduint_t;
#else
#error : There is no four-byte integer type on this machine 
#endif

#undef UNKNOWN_ENDIAN
#undef LITTLE_ENDIAN
#undef BIG_ENDIAN

#define UNKNOWN_ENDIAN 0
#define LITTLE_ENDIAN 1
#define BIG_ENDIAN 2

#ifndef ARCHIVE_C
extern int copy_file(char *in,char *out);
extern void write_cnfg(char *out);
extern void read_cnfg(char *in);
extern void export_cnfg(char *out);
extern void export_cnfg_sp(char *out);
extern void import_cnfg(char *in);
#endif

#ifndef BG_FCTS_C
extern void write_bglinfo(int my_rank,char *name);
#endif

#ifndef CMATRIX_C
extern void cmat_vec(int n,complex *a,complex *v,complex *w);
extern void cmat_vec_assign(int n,complex *a,complex *v,complex *w);
extern void cmat_add(int n,complex *a,complex *b,complex *c);
extern void cmat_sub(int n,complex *a,complex *b,complex *c);
extern void cmat_mul(int n,complex *a,complex *b,complex *c);
extern void cmat_dag(int n,complex *a,complex *b);
#endif

#ifndef CMATRIX_DBLE_C
extern void cmat_vec_dble(int n,complex_dble *a,complex_dble *v,
                          complex_dble *w);
extern void cmat_vec_assign_dble(int n,complex_dble *a,complex_dble *v,
                                 complex_dble *w);
extern void cmat_add_dble(int n,complex_dble *a,complex_dble *b,
                          complex_dble *c);
extern void cmat_sub_dble(int n,complex_dble *a,complex_dble *b,
                          complex_dble *c);
extern void cmat_mul_dble(int n,complex_dble *a,complex_dble *b,
                          complex_dble *c);
extern void cmat_dag_dble(int n,complex_dble *a,complex_dble *b);
extern int cmat_inv_dble(int n,complex_dble *a,complex_dble *b,double *k);
#endif

#ifndef ENDIAN_C
extern int endianness(void);
extern void bswap_int(int n,stdint_t *a);
extern void bswap_double(int n,double *a);
#endif

#ifndef MUTILS_C
extern int find_opt(int argc,char *argv[],char *opt);
extern void check_dir(char* dir);
extern void check_dir_root(char* dir);
extern int name_size(char *format,...);
extern void read_line(char *tag,char *format,...);
#endif

#ifndef SARCHIVE_C
extern void write_sfld(char *out,int k);
extern void read_sfld(char *in,int k);
extern void export_sfld(char *out,int k);
extern void import_sfld(char *in,int k);
#endif

#ifndef SSE_FCTS_C
#if (defined SSE)
#ifndef SSE_H
#include "sse.h"
#endif
extern void sse_ln1px(sse_float *x,sse_float *lx);
extern void sse_sincos(sse_float *x,sse_float *sx,sse_float *cx);
#endif
#endif

#ifndef SU3_FCTS_C
extern void cross_prod(su3_vector *v1,su3_vector *v2,su3_vector *v3);
extern void cross_prod_dble(su3_vector_dble *v1,su3_vector_dble *v2,
                            su3_vector_dble *v3);
extern void project_to_su3(su3 *u);
extern void project_to_su3_dble(su3_dble *u);
#endif

#ifndef SU3_PRODS_C
extern void su3xsu3(su3_dble *u,su3_dble *v,su3_dble *w);
extern void su3dagxsu3(su3_dble *u,su3_dble *v,su3_dble *w);
extern void su3xsu3dag(su3_dble *u,su3_dble *v,su3_dble *w);
extern void su3dagxsu3dag(su3_dble *u,su3_dble *v,su3_dble *w);
extern void su3xu3alg(su3_dble *u,u3_alg_dble *X,su3_dble *v);
extern void su3dagxu3alg(su3_dble *u,u3_alg_dble *X,su3_dble *v);
extern void u3algxsu3(u3_alg_dble *X,su3_dble *u,su3_dble *v);
extern void u3algxsu3dag(u3_alg_dble *X,su3_dble *u,su3_dble *v);
extern void prod2su3alg(su3_dble *u,su3_dble *v,su3_alg_dble *X);
extern void add_prod2u3alg(su3_dble *u,su3_dble *v,u3_alg_dble *X);
extern void rotate_su3alg(su3_dble *u,su3_alg_dble *X);
#endif

#endif
