kusano 2b45e8
/*********************************************************************/
kusano 2b45e8
/* Copyright 2009, 2010 The University of Texas at Austin.           */
kusano 2b45e8
/* All rights reserved.                                              */
kusano 2b45e8
/*                                                                   */
kusano 2b45e8
/* Redistribution and use in source and binary forms, with or        */
kusano 2b45e8
/* without modification, are permitted provided that the following   */
kusano 2b45e8
/* conditions are met:                                               */
kusano 2b45e8
/*                                                                   */
kusano 2b45e8
/*   1. Redistributions of source code must retain the above         */
kusano 2b45e8
/*      copyright notice, this list of conditions and the following  */
kusano 2b45e8
/*      disclaimer.                                                  */
kusano 2b45e8
/*                                                                   */
kusano 2b45e8
/*   2. Redistributions in binary form must reproduce the above      */
kusano 2b45e8
/*      copyright notice, this list of conditions and the following  */
kusano 2b45e8
/*      disclaimer in the documentation and/or other materials       */
kusano 2b45e8
/*      provided with the distribution.                              */
kusano 2b45e8
/*                                                                   */
kusano 2b45e8
/*    THIS  SOFTWARE IS PROVIDED  BY THE  UNIVERSITY OF  TEXAS AT    */
kusano 2b45e8
/*    AUSTIN  ``AS IS''  AND ANY  EXPRESS OR  IMPLIED WARRANTIES,    */
kusano 2b45e8
/*    INCLUDING, BUT  NOT LIMITED  TO, THE IMPLIED  WARRANTIES OF    */
kusano 2b45e8
/*    MERCHANTABILITY  AND FITNESS FOR  A PARTICULAR  PURPOSE ARE    */
kusano 2b45e8
/*    DISCLAIMED.  IN  NO EVENT SHALL THE UNIVERSITY  OF TEXAS AT    */
kusano 2b45e8
/*    AUSTIN OR CONTRIBUTORS BE  LIABLE FOR ANY DIRECT, INDIRECT,    */
kusano 2b45e8
/*    INCIDENTAL,  SPECIAL, EXEMPLARY,  OR  CONSEQUENTIAL DAMAGES    */
kusano 2b45e8
/*    (INCLUDING, BUT  NOT LIMITED TO,  PROCUREMENT OF SUBSTITUTE    */
kusano 2b45e8
/*    GOODS  OR  SERVICES; LOSS  OF  USE,  DATA,  OR PROFITS;  OR    */
kusano 2b45e8
/*    BUSINESS INTERRUPTION) HOWEVER CAUSED  AND ON ANY THEORY OF    */
kusano 2b45e8
/*    LIABILITY, WHETHER  IN CONTRACT, STRICT  LIABILITY, OR TORT    */
kusano 2b45e8
/*    (INCLUDING NEGLIGENCE OR OTHERWISE)  ARISING IN ANY WAY OUT    */
kusano 2b45e8
/*    OF  THE  USE OF  THIS  SOFTWARE,  EVEN  IF ADVISED  OF  THE    */
kusano 2b45e8
/*    POSSIBILITY OF SUCH DAMAGE.                                    */
kusano 2b45e8
/*                                                                   */
kusano 2b45e8
/* The views and conclusions contained in the software and           */
kusano 2b45e8
/* documentation are those of the authors and should not be          */
kusano 2b45e8
/* interpreted as representing official policies, either expressed   */
kusano 2b45e8
/* or implied, of The University of Texas at Austin.                 */
kusano 2b45e8
/*********************************************************************/
kusano 2b45e8
kusano 2b45e8
#ifndef COMMON_IA64
kusano 2b45e8
#define COMMON_IA64
kusano 2b45e8
kusano 2b45e8
#ifndef ASSEMBLER
kusano 2b45e8
kusano 2b45e8
#ifndef MAP_WRITECOMBINED
kusano 2b45e8
#define MAP_WRITECOMBINED 0x10000
kusano 2b45e8
#endif
kusano 2b45e8
kusano 2b45e8
#define MB
kusano 2b45e8
#define WMB
kusano 2b45e8
kusano 2b45e8
#ifdef __ECC
kusano 2b45e8
#include <ia64intrin.h></ia64intrin.h>
kusano 2b45e8
#endif
kusano 2b45e8
kusano 2b45e8
#define RPCC64BIT
kusano 2b45e8
kusano 2b45e8
#ifndef __ECC
kusano 2b45e8
static __inline void blas_lock(volatile unsigned long *address){
kusano 2b45e8
kusano 2b45e8
  unsigned long ret;
kusano 2b45e8
  
kusano 2b45e8
  do {
kusano 2b45e8
    while (*address) {YIELDING;};
kusano 2b45e8
    
kusano 2b45e8
    __asm__ __volatile__ ("mov ar.ccv=r0\n;;\n"
kusano 2b45e8
			  "cmpxchg4.acq %0=[%2],%1,ar.ccv\n"
kusano 2b45e8
			  : "=r"(ret) : "r"(1), "r"(address)
kusano 2b45e8
			  : "ar.ccv", "memory");
kusano 2b45e8
  } while (ret);
kusano 2b45e8
}
kusano 2b45e8
kusano 2b45e8
static __inline unsigned long rpcc(void) {
kusano 2b45e8
  unsigned long clocks;
kusano 2b45e8
kusano 2b45e8
  __asm__ __volatile__ ("mov %0=ar.itc" : "=r"(clocks));
kusano 2b45e8
  return clocks;
kusano 2b45e8
}
kusano 2b45e8
kusano 2b45e8
kusano 2b45e8
static __inline unsigned long stmxcsr(void){
kusano 2b45e8
  unsigned long fp;
kusano 2b45e8
kusano 2b45e8
   __asm__ __volatile__ ("mov.m %0=ar.fpsr" : "=r" (fp));
kusano 2b45e8
kusano 2b45e8
   return fp;
kusano 2b45e8
}
kusano 2b45e8
kusano 2b45e8
static __inline void ldmxcsr(unsigned long fp) {
kusano 2b45e8
kusano 2b45e8
   __asm__ __volatile__ ("mov.m ar.fpsr=%0" :: "r" (fp));
kusano 2b45e8
kusano 2b45e8
}
kusano 2b45e8
kusano 2b45e8
#define GET_IMAGE(res) asm __volatile__("mov %0 = f9" : "=f"(res)  : : "memory")
kusano 2b45e8
kusano 2b45e8
#else
kusano 2b45e8
kusano 2b45e8
static __inline void blas_lock(volatile unsigned long *address){
kusano 2b45e8
  while (*address || _InterlockedCompareExchange((volatile int *) address,1,0))
kusano 2b45e8
    ;
kusano 2b45e8
}
kusano 2b45e8
kusano 2b45e8
static __inline unsigned int rpcc(void) {
kusano 2b45e8
  return __getReg(_IA64_REG_AR_ITC);
kusano 2b45e8
}
kusano 2b45e8
kusano 2b45e8
static __inline unsigned int stmxcsr(void) {
kusano 2b45e8
  return __getReg(_IA64_REG_AR_FPSR);
kusano 2b45e8
}
kusano 2b45e8
kusano 2b45e8
static __inline void ldmxcsr(unsigned long fp) {
kusano 2b45e8
kusano 2b45e8
  return __setReg(_IA64_REG_AR_FPSR, fp);
kusano 2b45e8
kusano 2b45e8
}
kusano 2b45e8
kusano 2b45e8
#ifdef DOUBLE
kusano 2b45e8
#define GET_IMAGE(res) __stfd(&res, 9)
kusano 2b45e8
#else
kusano 2b45e8
#define GET_IMAGE(res) __stfs(&res, 9)
kusano 2b45e8
#endif
kusano 2b45e8
kusano 2b45e8
#endif
kusano 2b45e8
kusano 2b45e8
#define GET_IMAGE_CANCEL
kusano 2b45e8
kusano 2b45e8
#ifdef ENABLE_SSE_EXCEPTION
kusano 2b45e8
kusano 2b45e8
#define IDEBUG_START \
kusano 2b45e8
  { \
kusano 2b45e8
    unsigned long fp_sse_mode, new_fp_mode; \
kusano 2b45e8
	fp_sse_mode = stmxcsr();\
kusano 2b45e8
	new_fp_mode = (fp_sse_mode & ~(FE_UNDERFLOW | FE_OVERFLOW | FE_UNNORMAL | FE_INVALID));\
kusano 2b45e8
	ldmxcsr(new_fp_mode);
kusano 2b45e8
kusano 2b45e8
#define IDEBUG_END \
kusano 2b45e8
	ldmxcsr(fp_sse_mode); \
kusano 2b45e8
	}
kusano 2b45e8
kusano 2b45e8
#endif
kusano 2b45e8
kusano 2b45e8
#ifdef SMP
kusano 2b45e8
kusano 2b45e8
#ifdef USE64BITINT
kusano 2b45e8
kusano 2b45e8
/* 64bit version */
kusano 2b45e8
kusano 2b45e8
extern unsigned long blas_quick_divide_table[];
kusano 2b45e8
kusano 2b45e8
#ifndef __ECC
kusano 2b45e8
static __inline long blas_quickdivide(unsigned long int x, unsigned long int y){
kusano 2b45e8
  unsigned long ret;
kusano 2b45e8
kusano 2b45e8
  if (y <= 1) return x;
kusano 2b45e8
kusano 2b45e8
  __asm__ __volatile__("setf.sig f6 = %1\n\t"
kusano 2b45e8
	       "ldf8     f7 = [%2];;\n\t"
kusano 2b45e8
	       "xmpy.hu f6= f6, f7;;\n\t"
kusano 2b45e8
	       "getf.sig %0 = f6;;\n"
kusano 2b45e8
	       : "=r"(ret)
kusano 2b45e8
	       : "r"(x), "r"(&blas_quick_divide_table[y]) : "f6", "f7"
kusano 2b45e8
	       );
kusano 2b45e8
kusano 2b45e8
  return ret;
kusano 2b45e8
}
kusano 2b45e8
#else
kusano 2b45e8
/* Using Intel Compiler */
kusano 2b45e8
static __inline long blas_quickdivide(unsigned long int x, unsigned long int y){
kusano 2b45e8
  if (y <= 1) return x;
kusano 2b45e8
  return _m64_xmahu(x, blas_quick_divide_table[y], 0);
kusano 2b45e8
}
kusano 2b45e8
#endif
kusano 2b45e8
kusano 2b45e8
#else
kusano 2b45e8
 /* 32bit version */
kusano 2b45e8
extern unsigned int  blas_quick_divide_table[];
kusano 2b45e8
kusano 2b45e8
static __inline int blas_quickdivide(unsigned int x, unsigned int y){
kusano 2b45e8
  if (y <= 1) return x;
kusano 2b45e8
  return (int)((x * (unsigned long)blas_quick_divide_table[y]) >> 32);
kusano 2b45e8
}
kusano 2b45e8
#endif
kusano 2b45e8
#endif
kusano 2b45e8
kusano 2b45e8
#endif
kusano 2b45e8
kusano 2b45e8
#if 0
kusano 2b45e8
#ifdef DOUBLE
kusano 2b45e8
#define   GEMM_NCOPY	dgemm_ncopy
kusano 2b45e8
#define   GEMM_TCOPY	dgemm_tcopy
kusano 2b45e8
#define  ZGEMM_NCOPY	zgemm_ncopy
kusano 2b45e8
#define  ZGEMM_TCOPY	zgemm_tcopy
kusano 2b45e8
#define   GEMM_KERNEL	dgemm_kernel
kusano 2b45e8
kusano 2b45e8
#if defined(NN) || defined(NT) || defined(TN) || defined(TT)
kusano 2b45e8
#define ZGEMM_KERNEL zgemm_kernel_n
kusano 2b45e8
#endif
kusano 2b45e8
#if defined(CN) || defined(CT) || defined(RN) || defined(RT)
kusano 2b45e8
#define ZGEMM_KERNEL zgemm_kernel_l
kusano 2b45e8
#endif
kusano 2b45e8
#if defined(NC) || defined(TC) || defined(NR) || defined(TR)
kusano 2b45e8
#define ZGEMM_KERNEL zgemm_kernel_r
kusano 2b45e8
#endif
kusano 2b45e8
#if defined(CC) || defined(CR) || defined(RC) || defined(RR)
kusano 2b45e8
#define ZGEMM_KERNEL zgemm_kernel_b
kusano 2b45e8
#endif
kusano 2b45e8
kusano 2b45e8
#else
kusano 2b45e8
#define   GEMM_NCOPY	sgemm_ncopy
kusano 2b45e8
#define   GEMM_TCOPY	sgemm_tcopy
kusano 2b45e8
#define  ZGEMM_NCOPY	cgemm_ncopy
kusano 2b45e8
#define  ZGEMM_TCOPY	cgemm_tcopy
kusano 2b45e8
#define   GEMM_KERNEL	sgemm_kernel
kusano 2b45e8
kusano 2b45e8
#if defined(NN) || defined(NT) || defined(TN) || defined(TT)
kusano 2b45e8
#define ZGEMM_KERNEL cgemm_kernel_n
kusano 2b45e8
#endif
kusano 2b45e8
#if defined(CN) || defined(CT) || defined(RN) || defined(RT)
kusano 2b45e8
#define ZGEMM_KERNEL cgemm_kernel_l
kusano 2b45e8
#endif
kusano 2b45e8
#if defined(NC) || defined(TC) || defined(NR) || defined(TR)
kusano 2b45e8
#define ZGEMM_KERNEL cgemm_kernel_r
kusano 2b45e8
#endif
kusano 2b45e8
#if defined(CC) || defined(CR) || defined(RC) || defined(RR)
kusano 2b45e8
#define ZGEMM_KERNEL cgemm_kernel_b
kusano 2b45e8
#endif
kusano 2b45e8
kusano 2b45e8
#endif
kusano 2b45e8
#endif
kusano 2b45e8
kusano 2b45e8
#ifdef USE64BITINT
kusano 2b45e8
#define LDINT		ld8
kusano 2b45e8
#define INTSIZE		8
kusano 2b45e8
#define CMP4GE		cmp.ge
kusano 2b45e8
#define CMP4NE		cmp.ge
kusano 2b45e8
#define CMP4EQ		cmp.eq
kusano 2b45e8
#else
kusano 2b45e8
#define LDINT		ld4
kusano 2b45e8
#define INTSIZE		4
kusano 2b45e8
#define CMP4GE		cmp4.ge
kusano 2b45e8
#define CMP4NE		cmp4.ne
kusano 2b45e8
#define CMP4EQ		cmp4.eq
kusano 2b45e8
#endif
kusano 2b45e8
kusano 2b45e8
#define HALT		mov r0 = 0
kusano 2b45e8
kusano 2b45e8
#ifdef XDOUBLE
kusano 2b45e8
#define LD8		ld8
kusano 2b45e8
#define ST8		st8
kusano 2b45e8
#define LDFD		ldfe
kusano 2b45e8
#define LDFPD		ldfpe
kusano 2b45e8
#define LDFD_T1		ldfe.t1
kusano 2b45e8
#define LDFD_NT1	ldfe.nt1
kusano 2b45e8
#define LDFD_NT2	ldfe.nt2
kusano 2b45e8
#define LDFD_NTA	ldfe.nta
kusano 2b45e8
#define LDFPD_NT1	ldfpe.nt1
kusano 2b45e8
#define LDFPD_NT2	ldfpe.nt2
kusano 2b45e8
#define LDFPD_NTA	ldfpe.nta
kusano 2b45e8
#define STFD		stfe
kusano 2b45e8
#define STFD_NTA	stfe.nta
kusano 2b45e8
#define FADD		fadd
kusano 2b45e8
#define FSUB		fsub
kusano 2b45e8
#define FMPY		fmpy
kusano 2b45e8
#define FMA		fma
kusano 2b45e8
#define FMS		fms
kusano 2b45e8
#define FNMA		fnma
kusano 2b45e8
#define FPMA		fpma
kusano 2b45e8
#define SETF		setf.d
kusano 2b45e8
#elif defined(DOUBLE)
kusano 2b45e8
#define LD8		ld8
kusano 2b45e8
#define ST8		st8
kusano 2b45e8
#define LDF8		ldf8
kusano 2b45e8
#define LDF8_NT1	ldf8.nt1
kusano 2b45e8
#define LDF8_NTA	ldf8.nta
kusano 2b45e8
#define STF8		stf8
kusano 2b45e8
#define STF8_NTA	stf8.nta
kusano 2b45e8
#define LDFD		ldfd
kusano 2b45e8
#define LDFPD		ldfpd
kusano 2b45e8
#define LDFD_T1		ldfd.t1
kusano 2b45e8
#define LDFD_NT1	ldfd.nt1
kusano 2b45e8
#define LDFD_NT2	ldfd.nt2
kusano 2b45e8
#define LDFD_NTA	ldfd.nta
kusano 2b45e8
#define LDFPD_NT1	ldfpd.nt1
kusano 2b45e8
#define LDFPD_NT2	ldfpd.nt2
kusano 2b45e8
#define LDFPD_NTA	ldfpd.nta
kusano 2b45e8
#define STFD		stfd
kusano 2b45e8
#define STFD_NTA	stfd.nta
kusano 2b45e8
#define FADD		fadd.d
kusano 2b45e8
#define FSUB		fsub.d
kusano 2b45e8
#define FMPY		fmpy.d
kusano 2b45e8
#define FMA		fma.d
kusano 2b45e8
#define FMS		fms.d
kusano 2b45e8
#define FNMA		fnma.d
kusano 2b45e8
#define FPMA		fpma.d
kusano 2b45e8
#define SETF		setf.d
kusano 2b45e8
#else
kusano 2b45e8
#define LD8		ld4
kusano 2b45e8
#define ST8		st4
kusano 2b45e8
#define LDF8		ldfs
kusano 2b45e8
#define LDF8_NT1	ldfs.nt1
kusano 2b45e8
#define LDF8_NTA	ldfs.nta
kusano 2b45e8
#define STF8		stfs
kusano 2b45e8
#define STF8_NTA	stfs.nta
kusano 2b45e8
#define LDFD		ldfs
kusano 2b45e8
#define LDFPD		ldfps
kusano 2b45e8
#define LDFD_T1		ldfs.t1
kusano 2b45e8
#define LDFD_NT1	ldfs.nt1
kusano 2b45e8
#define LDFD_NT2	ldfs.nt2
kusano 2b45e8
#define LDFD_NTA	ldfs.nta
kusano 2b45e8
#define LDFPD_NT1	ldfps.nt1
kusano 2b45e8
#define LDFPD_NT2	ldfps.nt2
kusano 2b45e8
#define LDFPD_NTA	ldfps.nta
kusano 2b45e8
#define STFD		stfs
kusano 2b45e8
#define STFD_NTA	stfs.nta
kusano 2b45e8
#if 0
kusano 2b45e8
#define FADD		fadd.s
kusano 2b45e8
#define FSUB		fsub.s
kusano 2b45e8
#define FMPY		fmpy.s
kusano 2b45e8
#define FMA		fma.s
kusano 2b45e8
#define FMS		fms.s
kusano 2b45e8
#define FNMA		fnma.s
kusano 2b45e8
#define FPMA		fpma.s
kusano 2b45e8
#else
kusano 2b45e8
#define FADD		fadd
kusano 2b45e8
#define FSUB		fsub
kusano 2b45e8
#define FMPY		fmpy
kusano 2b45e8
#define FMA		fma
kusano 2b45e8
#define FMS		fms
kusano 2b45e8
#define FNMA		fnma
kusano 2b45e8
#define FPMA		fpma
kusano 2b45e8
#endif
kusano 2b45e8
#define SETF		setf.s
kusano 2b45e8
#endif
kusano 2b45e8
kusano 2b45e8
#ifndef F_INTERFACE
kusano 2b45e8
#define REALNAME ASMNAME
kusano 2b45e8
#else
kusano 2b45e8
#define REALNAME ASMFNAME
kusano 2b45e8
#endif
kusano 2b45e8
kusano 2b45e8
#ifdef F_INTERFACE_G77
kusano 2b45e8
#define RETURN_BY_STACK
kusano 2b45e8
#endif
kusano 2b45e8
kusano 2b45e8
#ifdef F_INTERFACE_G95
kusano 2b45e8
#define RETURN_BY_STACK
kusano 2b45e8
#endif
kusano 2b45e8
kusano 2b45e8
#ifdef F_INTERFACE_GFORT
kusano 2b45e8
#define RETURN_BY_REGS
kusano 2b45e8
#endif
kusano 2b45e8
kusano 2b45e8
#ifdef F_INTERFACE_INTEL
kusano 2b45e8
#define RETURN_BY_STACK
kusano 2b45e8
#endif
kusano 2b45e8
kusano 2b45e8
#define PROLOGUE \
kusano 2b45e8
	.explicit; \
kusano 2b45e8
	.text; \
kusano 2b45e8
	.align 128; \
kusano 2b45e8
	.global REALNAME; \
kusano 2b45e8
	.proc REALNAME; \
kusano 2b45e8
REALNAME:
kusano 2b45e8
kusano 2b45e8
kusano 2b45e8
#ifdef PROFILE
kusano 2b45e8
#define PROFCODE \
kusano 2b45e8
	.data; \
kusano 2b45e8
	.align 8; \
kusano 2b45e8
.LP0:; \
kusano 2b45e8
	data8	0; \
kusano 2b45e8
	.text; \
kusano 2b45e8
	alloc	out0 = ar.pfs, 8, 0, 4, 0; \
kusano 2b45e8
	mov	out1 = r1; \
kusano 2b45e8
	mov	out2 = b0; \
kusano 2b45e8
	addl	out3 = @ltoff(.LP0), r1;;; \
kusano 2b45e8
	br.call.sptk.many b0 = _mcount;;
kusano 2b45e8
#else
kusano 2b45e8
#define PROFCODE
kusano 2b45e8
#endif
kusano 2b45e8
kusano 2b45e8
#define EPILOGUE \
kusano 2b45e8
	.endp REALNAME
kusano 2b45e8
kusano 2b45e8
#define START_ADDRESS 0x20000fc800000000UL
kusano 2b45e8
kusano 2b45e8
#undef SEEK_ADDRESS
kusano 2b45e8
kusano 2b45e8
#if 0
kusano 2b45e8
#ifdef CONFIG_IA64_PAGE_SIZE_4KB
kusano 2b45e8
#define SEEK_ADDRESS
kusano 2b45e8
#endif
kusano 2b45e8
kusano 2b45e8
#ifdef CONFIG_IA64_PAGE_SIZE_8KB
kusano 2b45e8
#define SEEK_ADDRESS
kusano 2b45e8
#endif
kusano 2b45e8
#endif
kusano 2b45e8
kusano 2b45e8
#define BUFFER_SIZE	(128 << 20)
kusano 2b45e8
kusano 2b45e8
#ifndef PAGESIZE
kusano 2b45e8
#define PAGESIZE	(16UL << 10)
kusano 2b45e8
#endif
kusano 2b45e8
#define HUGE_PAGESIZE	(  4 << 20)
kusano 2b45e8
kusano 2b45e8
#define BASE_ADDRESS (START_ADDRESS - (BLASULONG)BUFFER_SIZE * MAX_CPU_NUMBER)
kusano 2b45e8
kusano 2b45e8
#endif