|
kusano |
2b45e8 |
/*****************************************************************************
|
|
kusano |
2b45e8 |
Copyright (c) 2011, Lab of Parallel Software and Computational Science,ICSAS
|
|
kusano |
2b45e8 |
All rights reserved.
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
Redistribution and use in source and binary forms, with or without
|
|
kusano |
2b45e8 |
modification, are permitted provided that the following conditions are
|
|
kusano |
2b45e8 |
met:
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
1. Redistributions of source code must retain the above copyright
|
|
kusano |
2b45e8 |
notice, this list of conditions and the following disclaimer.
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
2. Redistributions in binary form must reproduce the above copyright
|
|
kusano |
2b45e8 |
notice, this list of conditions and the following disclaimer in
|
|
kusano |
2b45e8 |
the documentation and/or other materials provided with the
|
|
kusano |
2b45e8 |
distribution.
|
|
kusano |
2b45e8 |
3. Neither the name of the ISCAS nor the names of its contributors may
|
|
kusano |
2b45e8 |
be used to endorse or promote products derived from this software
|
|
kusano |
2b45e8 |
without specific prior written permission.
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
kusano |
2b45e8 |
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
kusano |
2b45e8 |
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
kusano |
2b45e8 |
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
|
kusano |
2b45e8 |
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
kusano |
2b45e8 |
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
kusano |
2b45e8 |
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
kusano |
2b45e8 |
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
kusano |
2b45e8 |
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
|
|
kusano |
2b45e8 |
USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
**********************************************************************************/
|
|
kusano |
2b45e8 |
|
|
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_MIPS64
|
|
kusano |
2b45e8 |
#define COMMON_MIPS64
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
#define MB
|
|
kusano |
2b45e8 |
#define WMB
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
#define INLINE inline
|
|
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, val = 1;
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
do {
|
|
kusano |
2b45e8 |
while (*address) {YIELDING;};
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
__asm__ __volatile__(
|
|
kusano |
2b45e8 |
"1: ll %0, %3\n"
|
|
kusano |
2b45e8 |
" ori %2, %0, 1\n"
|
|
kusano |
2b45e8 |
" sc %2, %1\n"
|
|
kusano |
2b45e8 |
" beqz %2, 1b\n"
|
|
kusano |
2b45e8 |
" andi %2, %0, 1\n"
|
|
kusano |
2b45e8 |
" sync\n"
|
|
kusano |
2b45e8 |
: "=&r" (val), "=m" (address), "=&r" (ret)
|
|
kusano |
2b45e8 |
: "m" (address)
|
|
kusano |
2b45e8 |
: "memory");
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
} while (ret);
|
|
kusano |
2b45e8 |
}
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
static inline unsigned int rpcc(void){
|
|
kusano |
2b45e8 |
unsigned long ret;
|
|
kusano |
2b45e8 |
#if defined(LOONGSON3A) || defined(LOONGSON3B)
|
|
kusano |
2b45e8 |
// unsigned long long tmp;
|
|
kusano |
2b45e8 |
//__asm__ __volatile__("dmfc0 %0, $25, 1": "=r"(tmp):: "memory");
|
|
kusano |
2b45e8 |
//ret=tmp;
|
|
kusano |
2b45e8 |
__asm__ __volatile__(".set push \n"
|
|
kusano |
2b45e8 |
".set mips32r2\n"
|
|
kusano |
2b45e8 |
"rdhwr %0, $2\n"
|
|
kusano |
2b45e8 |
".set pop": "=r"(ret):: "memory");
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
#else
|
|
kusano |
2b45e8 |
__asm__ __volatile__(".set push \n"
|
|
kusano |
2b45e8 |
".set mips32r2\n"
|
|
kusano |
2b45e8 |
"rdhwr %0, $30 \n"
|
|
kusano |
2b45e8 |
".set pop" : "=r"(ret) : : "memory");
|
|
kusano |
2b45e8 |
#endif
|
|
kusano |
2b45e8 |
return ret;
|
|
kusano |
2b45e8 |
}
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
#if defined(LOONGSON3A) || defined(LOONGSON3B)
|
|
kusano |
2b45e8 |
#ifndef NO_AFFINITY
|
|
kusano |
2b45e8 |
#define WHEREAMI
|
|
kusano |
2b45e8 |
static inline int WhereAmI(void){
|
|
kusano |
2b45e8 |
int ret=0;
|
|
kusano |
2b45e8 |
__asm__ __volatile__(".set push \n"
|
|
kusano |
2b45e8 |
".set mips32r2\n"
|
|
kusano |
2b45e8 |
"rdhwr %0, $0\n"
|
|
kusano |
2b45e8 |
".set pop": "=r"(ret):: "memory");
|
|
kusano |
2b45e8 |
return ret;
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
}
|
|
kusano |
2b45e8 |
#endif
|
|
kusano |
2b45e8 |
#endif
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
static inline int blas_quickdivide(blasint x, blasint y){
|
|
kusano |
2b45e8 |
return x / y;
|
|
kusano |
2b45e8 |
}
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
#ifdef DOUBLE
|
|
kusano |
2b45e8 |
#define GET_IMAGE(res) __asm__ __volatile__("mov.d %0, $f2" : "=f"(res) : : "memory")
|
|
kusano |
2b45e8 |
#else
|
|
kusano |
2b45e8 |
#define GET_IMAGE(res) __asm__ __volatile__("mov.s %0, $f2" : "=f"(res) : : "memory")
|
|
kusano |
2b45e8 |
#endif
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
#define GET_IMAGE_CANCEL
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
#endif
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
#ifdef ASSEMBLER
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
#define HALT teq $0, $0
|
|
kusano |
2b45e8 |
#define NOP move $0, $0
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
#ifdef DOUBLE
|
|
kusano |
2b45e8 |
#define LD ldc1
|
|
kusano |
2b45e8 |
#define ST sdc1
|
|
kusano |
2b45e8 |
#define MADD madd.d
|
|
kusano |
2b45e8 |
#define NMADD nmadd.d
|
|
kusano |
2b45e8 |
#define MSUB msub.d
|
|
kusano |
2b45e8 |
#define NMSUB nmsub.d
|
|
kusano |
2b45e8 |
#define ADD add.d
|
|
kusano |
2b45e8 |
#define SUB sub.d
|
|
kusano |
2b45e8 |
#define MUL mul.d
|
|
kusano |
2b45e8 |
#define MOV mov.d
|
|
kusano |
2b45e8 |
#define CMOVF movf.d
|
|
kusano |
2b45e8 |
#define CMOVT movt.d
|
|
kusano |
2b45e8 |
#define MTC dmtc1
|
|
kusano |
2b45e8 |
#define FABS abs.d
|
|
kusano |
2b45e8 |
#define CMPEQ c.eq.d
|
|
kusano |
2b45e8 |
#define CMPLE c.le.d
|
|
kusano |
2b45e8 |
#define CMPLT c.lt.d
|
|
kusano |
2b45e8 |
#define NEG neg.d
|
|
kusano |
2b45e8 |
#else
|
|
kusano |
2b45e8 |
#define LD lwc1
|
|
kusano |
2b45e8 |
#define ST swc1
|
|
kusano |
2b45e8 |
#define MADD madd.s
|
|
kusano |
2b45e8 |
#define NMADD nmadd.s
|
|
kusano |
2b45e8 |
#define MSUB msub.s
|
|
kusano |
2b45e8 |
#define NMSUB nmsub.s
|
|
kusano |
2b45e8 |
#define ADD add.s
|
|
kusano |
2b45e8 |
#define SUB sub.s
|
|
kusano |
2b45e8 |
#define MUL mul.s
|
|
kusano |
2b45e8 |
#define MOV mov.s
|
|
kusano |
2b45e8 |
#define CMOVF movf.s
|
|
kusano |
2b45e8 |
#define CMOVT movt.s
|
|
kusano |
2b45e8 |
#define MTC mtc1
|
|
kusano |
2b45e8 |
#define FABS abs.s
|
|
kusano |
2b45e8 |
#define CMPEQ c.eq.s
|
|
kusano |
2b45e8 |
#define CMPLE c.le.s
|
|
kusano |
2b45e8 |
#define CMPLT c.lt.s
|
|
kusano |
2b45e8 |
#define PLU plu.ps
|
|
kusano |
2b45e8 |
#define PLL pll.ps
|
|
kusano |
2b45e8 |
#define PUU puu.ps
|
|
kusano |
2b45e8 |
#define PUL pul.ps
|
|
kusano |
2b45e8 |
#define MADPS madd.ps
|
|
kusano |
2b45e8 |
#define CVTU cvt.s.pu
|
|
kusano |
2b45e8 |
#define CVTL cvt.s.pl
|
|
kusano |
2b45e8 |
#define NEG neg.s
|
|
kusano |
2b45e8 |
#endif
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
#if defined(__64BIT__) && defined(USE64BITINT)
|
|
kusano |
2b45e8 |
#define LDINT ld
|
|
kusano |
2b45e8 |
#define LDARG ld
|
|
kusano |
2b45e8 |
#define SDARG sd
|
|
kusano |
2b45e8 |
#elif defined(__64BIT__) && !defined(USE64BITINT)
|
|
kusano |
2b45e8 |
#define LDINT lw
|
|
kusano |
2b45e8 |
#define LDARG ld
|
|
kusano |
2b45e8 |
#define SDARG sd
|
|
kusano |
2b45e8 |
#else
|
|
kusano |
2b45e8 |
#define LDINT lw
|
|
kusano |
2b45e8 |
#define LDARG lw
|
|
kusano |
2b45e8 |
#define SDARG sw
|
|
kusano |
2b45e8 |
#endif
|
|
kusano |
2b45e8 |
|
|
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 |
#if defined(ASSEMBLER) && !defined(NEEDPARAM)
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
#define PROLOGUE \
|
|
kusano |
2b45e8 |
.text ;\
|
|
kusano |
2b45e8 |
.set mips64 ;\
|
|
kusano |
2b45e8 |
.align 5 ;\
|
|
kusano |
2b45e8 |
.globl REALNAME ;\
|
|
kusano |
2b45e8 |
.ent REALNAME ;\
|
|
kusano |
2b45e8 |
.type REALNAME, @function ;\
|
|
kusano |
2b45e8 |
REALNAME: ;\
|
|
kusano |
2b45e8 |
.set noreorder ;\
|
|
kusano |
2b45e8 |
.set nomacro
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
#define EPILOGUE \
|
|
kusano |
2b45e8 |
.set macro ;\
|
|
kusano |
2b45e8 |
.set reorder ;\
|
|
kusano |
2b45e8 |
.end REALNAME
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
#define PROFCODE
|
|
kusano |
2b45e8 |
#endif
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
#endif
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
#define SEEK_ADDRESS
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
#define BUFFER_SIZE ( 32 << 20)
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
#if defined(LOONGSON3A)
|
|
kusano |
2b45e8 |
#define PAGESIZE (16UL << 10)
|
|
kusano |
2b45e8 |
#define FIXED_PAGESIZE (16UL << 10)
|
|
kusano |
2b45e8 |
#endif
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
#if defined(LOONGSON3B)
|
|
kusano |
2b45e8 |
#define PAGESIZE (32UL << 10)
|
|
kusano |
2b45e8 |
#define FIXED_PAGESIZE (32UL << 10)
|
|
kusano |
2b45e8 |
#endif
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
#ifndef PAGESIZE
|
|
kusano |
2b45e8 |
#define PAGESIZE (64UL << 10)
|
|
kusano |
2b45e8 |
#endif
|
|
kusano |
2b45e8 |
#define HUGE_PAGESIZE ( 2 << 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 |
|
|
kusano |
2b45e8 |
#if defined(LOONGSON3A) || defined(LOONGSON3B)
|
|
kusano |
2b45e8 |
#define PREFETCHD_(x) ld $0, x
|
|
kusano |
2b45e8 |
#define PREFETCHD(x) PREFETCHD_(x)
|
|
kusano |
2b45e8 |
#else
|
|
kusano |
2b45e8 |
#define PREFETCHD(x)
|
|
kusano |
2b45e8 |
#endif
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
#endif
|