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_POWER
kusano 2b45e8
#define COMMON_POWER
kusano 2b45e8
kusano 2b45e8
#define MB	__asm__ __volatile__ ("nop")
kusano 2b45e8
#define WMB	__asm__ __volatile__ ("nop")
kusano 2b45e8
kusano 2b45e8
#ifndef ASSEMBLER
kusano 2b45e8
kusano 2b45e8
static void __inline blas_lock(volatile unsigned long *address){
kusano 2b45e8
kusano 2b45e8
  long int ret = 1;
kusano 2b45e8
kusano 2b45e8
  do {
kusano 2b45e8
    while (*address) {YIELDING;};
kusano 2b45e8
kusano 2b45e8
    __asm__ __volatile__(
kusano 2b45e8
			 "ldstub [%1], %0"
kusano 2b45e8
			 : "=&r"(ret)
kusano 2b45e8
			 : "r" (address)
kusano 2b45e8
			 : "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__ ("rd %%tick, %0" : "=r" (clocks));
kusano 2b45e8
kusano 2b45e8
  return clocks;
kusano 2b45e8
};
kusano 2b45e8
kusano 2b45e8
#ifdef __64BIT__
kusano 2b45e8
#define RPCC64BIT
kusano 2b45e8
#endif
kusano 2b45e8
kusano 2b45e8
#ifndef __BIG_ENDIAN__
kusano 2b45e8
#define __BIG_ENDIAN__
kusano 2b45e8
#endif
kusano 2b45e8
kusano 2b45e8
#ifdef DOUBLE
kusano 2b45e8
#define GET_IMAGE(res)  __asm__ __volatile__("fmovd %%f2, %0" : "=f"(res)  : : "memory")
kusano 2b45e8
#else
kusano 2b45e8
#define GET_IMAGE(res)  __asm__ __volatile__("fmovs %%f1, %0" : "=f"(res)  : : "memory")
kusano 2b45e8
#endif
kusano 2b45e8
kusano 2b45e8
#define GET_IMAGE_CANCEL
kusano 2b45e8
kusano 2b45e8
#ifdef SMP
kusano 2b45e8
static __inline int blas_quickdivide(blasint x, blasint y){
kusano 2b45e8
  return x / y;
kusano 2b45e8
}
kusano 2b45e8
#endif
kusano 2b45e8
#endif
kusano 2b45e8
kusano 2b45e8
kusano 2b45e8
#ifdef ASSEMBLER
kusano 2b45e8
kusano 2b45e8
#ifndef __64BIT__
kusano 2b45e8
#define STACK_START 128
kusano 2b45e8
#define SAVESP		save	%sp,  -64, %sp
kusano 2b45e8
#else
kusano 2b45e8
#define STACK_START 2423
kusano 2b45e8
#define SAVESP		save	%sp, -256, %sp
kusano 2b45e8
#endif
kusano 2b45e8
kusano 2b45e8
#define NOP	or %g1, %g1, %g1
kusano 2b45e8
kusano 2b45e8
#ifdef DOUBLE
kusano 2b45e8
#define LDF	ldd
kusano 2b45e8
#define STF	std
kusano 2b45e8
#define FADD	faddd
kusano 2b45e8
#define FMUL	fmuld
kusano 2b45e8
#define FMOV	fmovd
kusano 2b45e8
#define FABS	fabsd
kusano 2b45e8
#define FSUB	fsubd
kusano 2b45e8
#define FCMP	fcmpd
kusano 2b45e8
#define FMOVG	fmovdg
kusano 2b45e8
#define FMOVL	fmovdl
kusano 2b45e8
#define FSQRT	fsqrtd
kusano 2b45e8
#define FDIV	fdivd
kusano 2b45e8
#else
kusano 2b45e8
#define LDF	ld
kusano 2b45e8
#define STF	st
kusano 2b45e8
#define FADD	fadds
kusano 2b45e8
#define FMUL	fmuls
kusano 2b45e8
#define FMOV	fmovs
kusano 2b45e8
#define FABS	fabss
kusano 2b45e8
#define FSUB	fsubs
kusano 2b45e8
#define FCMP	fcmps
kusano 2b45e8
#define FMOVG	fmovsg
kusano 2b45e8
#define FMOVL	fmovsl
kusano 2b45e8
#define FSQRT	fsqrts
kusano 2b45e8
#define FDIV	fdivs
kusano 2b45e8
#endif
kusano 2b45e8
	
kusano 2b45e8
#define HALT prefetch [%g0], 5
kusano 2b45e8
kusano 2b45e8
#define FMADDS(rs1, rs2, rs3, rd) \
kusano 2b45e8
        .word	((2 << 30) | ((rd) << 25) | ( 0x37 << 19) | ((rs1) << 14) | ((rs3) << 9) | ( 1 << 5) | (rs2))
kusano 2b45e8
kusano 2b45e8
#define FMADDD(rs1, rs2, rs3, rd) \
kusano 2b45e8
        .word	((2 << 30) | ((rd) << 25) | ( 0x37 << 19) | ((rs1) << 14) | ((rs3) << 9) | ( 2 << 5) | (rs2))
kusano 2b45e8
kusano 2b45e8
#define FMSUBS(rs1, rs2, rs3, rd) \
kusano 2b45e8
        .word	((2 << 30) | ((rd) << 25) | ( 0x37 << 19) | ((rs1) << 14) | ((rs3) << 9) | ( 5 << 5) | (rs2))
kusano 2b45e8
kusano 2b45e8
#define FMSUBD(rs1, rs2, rs3, rd) \
kusano 2b45e8
        .word	((2 << 30) | ((rd) << 25) | ( 0x37 << 19) | ((rs1) << 14) | ((rs3) << 9) | ( 6 << 5) | (rs2))
kusano 2b45e8
kusano 2b45e8
#define FNMSUBS(rs1, rs2, rs3, rd) \
kusano 2b45e8
        .word	((2 << 30) | ((rd) << 25) | ( 0x37 << 19) | ((rs1) << 14) | ((rs3) << 9) | ( 9 << 5) | (rs2))
kusano 2b45e8
kusano 2b45e8
#define FNMSUBD(rs1, rs2, rs3, rd) \
kusano 2b45e8
        .word	((2 << 30) | ((rd) << 25) | ( 0x37 << 19) | ((rs1) << 14) | ((rs3) << 9) | (10 << 5) | (rs2))
kusano 2b45e8
kusano 2b45e8
#define FNMADDS(rs1, rs2, rs3, rd) \
kusano 2b45e8
        .word	((2 << 30) | ((rd) << 25) | ( 0x37 << 19) | ((rs1) << 14) | ((rs3) << 9) | (13 << 5) | (rs2))
kusano 2b45e8
kusano 2b45e8
#define FNMADDD(rs1, rs2, rs3, rd) \
kusano 2b45e8
        .word	((2 << 30) | ((rd) << 25) | ( 0x37 << 19) | ((rs1) << 14) | ((rs3) << 9) | (14 << 5) | (rs2))
kusano 2b45e8
kusano 2b45e8
#define FCLRS(rd) \
kusano 2b45e8
        .word	((2 << 30) | ((rd) << 25) | ( 0x36 << 19) | ( 0x61 << 5))
kusano 2b45e8
kusano 2b45e8
#define FCLRD(rd) \
kusano 2b45e8
        .word	((2 << 30) | ((rd) << 25) | ( 0x36 << 19) | ( 0x60 << 5))
kusano 2b45e8
kusano 2b45e8
#define FONES(rd) \
kusano 2b45e8
        .word	((2 << 30) | ((rd) << 25) | ( 0x36 << 19) | ( 0x7f << 5))
kusano 2b45e8
kusano 2b45e8
#define FONED(rd) \
kusano 2b45e8
        .word	((2 << 30) | ((rd) << 25) | ( 0x36 << 19) | ( 0x7e << 5))
kusano 2b45e8
kusano 2b45e8
#ifndef DOUBLE
kusano 2b45e8
#define	FCLR(a)			FCLRS(a) 
kusano 2b45e8
#define	FONE(a)			FONES(a) 
kusano 2b45e8
#define	FMADD(a, b, c, d)	FMADDS(a, b, c, d) 
kusano 2b45e8
#define	FMSUB(a, b, c, d)	FMSUBS(a, b, c, d) 
kusano 2b45e8
#define	FNMADD(a, b, c, d)	FNMADDS(a, b, c, d) 
kusano 2b45e8
#define	FNMSUB(a, b, c, d)	FNMSUBS(a, b, c, d) 
kusano 2b45e8
#else
kusano 2b45e8
#define	FCLR(a)			FCLRD(a) 
kusano 2b45e8
#define	FONE(a)			FONED(a) 
kusano 2b45e8
#define	FMADD(a, b, c, d)	FMADDD(a, b, c, d) 
kusano 2b45e8
#define	FMSUB(a, b, c, d)	FMSUBD(a, b, c, d) 
kusano 2b45e8
#define	FNMADD(a, b, c, d)	FNMADDD(a, b, c, d) 
kusano 2b45e8
#define	FNMSUB(a, b, c, d)	FNMSUBD(a, b, c, d) 
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 sparc
kusano 2b45e8
#define PROLOGUE \
kusano 2b45e8
	.section	".text"; \
kusano 2b45e8
	.align 32; \
kusano 2b45e8
	.global REALNAME;\
kusano 2b45e8
	.type	REALNAME, #function; \
kusano 2b45e8
	.proc	07; \
kusano 2b45e8
REALNAME:;
kusano 2b45e8
#define EPILOGUE \
kusano 2b45e8
	.size	 REALNAME, .-REALNAME
kusano 2b45e8
#endif
kusano 2b45e8
kusano 2b45e8
#endif
kusano 2b45e8
kusano 2b45e8
#ifdef sparc
kusano 2b45e8
#define SEEK_ADDRESS
kusano 2b45e8
#endif
kusano 2b45e8
kusano 2b45e8
#define BUFFER_SIZE	(32 << 20)
kusano 2b45e8
kusano 2b45e8
#ifndef PAGESIZE
kusano 2b45e8
#define PAGESIZE	( 8 << 10)
kusano 2b45e8
#endif
kusano 2b45e8
#define HUGE_PAGESIZE	( 4 << 20)
kusano 2b45e8
kusano 2b45e8
#define BASE_ADDRESS (START_ADDRESS - BUFFER_SIZE * MAX_CPU_NUMBER)
kusano 2b45e8
kusano 2b45e8
#ifndef MAP_ANONYMOUS
kusano 2b45e8
#define MAP_ANONYMOUS MAP_ANON
kusano 2b45e8
#endif
kusano 2b45e8
#endif