Skip to content

Commit af0a69f

Browse files
author
gxw
committed
Add support for LOONGARCH64
1 parent 5a2fe5b commit af0a69f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+24189
-27
lines changed

Makefile.loongarch64

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
ifdef BINARY64
2+
else
3+
endif

Makefile.system

+12
Original file line numberDiff line numberDiff line change
@@ -780,6 +780,11 @@ NO_BINARY_MODE = 1
780780
BINARY_DEFINED = 1
781781
endif
782782

783+
ifeq ($(ARCH), loongarch64)
784+
NO_BINARY_MODE = 1
785+
BINARY_DEFINED = 1
786+
endif
787+
783788

784789
#
785790
# C Compiler dependent settings
@@ -850,6 +855,13 @@ ifeq ($(OSNAME), AIX)
850855
BINARY_DEFINED = 1
851856
endif
852857

858+
ifeq ($(ARCH), loongarch64)
859+
ifeq ($(CORE), LOONGSONG3R5)
860+
CCOMMON_OPT += -march=loongarch64 -mabi=lp64
861+
FCOMMON_OPT += -march=loongarch64 -mabi=lp64
862+
endif
863+
endif
864+
853865
endif
854866

855867
ifndef BINARY_DEFINED

TargetList.txt

+2
Original file line numberDiff line numberDiff line change
@@ -110,3 +110,5 @@ Z14
110110
RISCV64_GENERIC
111111
C910V
112112

113+
11.LOONGARCH64:
114+
LOONGSON3R5

c_check

+30-23
Original file line numberDiff line numberDiff line change
@@ -82,18 +82,19 @@ $os = Interix if ($data =~ /OS_INTERIX/);
8282
$os = Android if ($data =~ /OS_ANDROID/);
8383
$os = Haiku if ($data =~ /OS_HAIKU/);
8484

85-
$architecture = x86 if ($data =~ /ARCH_X86/);
86-
$architecture = x86_64 if ($data =~ /ARCH_X86_64/);
87-
$architecture = power if ($data =~ /ARCH_POWER/);
88-
$architecture = mips if ($data =~ /ARCH_MIPS/);
89-
$architecture = mips64 if ($data =~ /ARCH_MIPS64/);
90-
$architecture = alpha if ($data =~ /ARCH_ALPHA/);
91-
$architecture = sparc if ($data =~ /ARCH_SPARC/);
92-
$architecture = ia64 if ($data =~ /ARCH_IA64/);
93-
$architecture = arm if ($data =~ /ARCH_ARM/);
94-
$architecture = arm64 if ($data =~ /ARCH_ARM64/);
95-
$architecture = zarch if ($data =~ /ARCH_ZARCH/);
96-
$architecture = riscv64 if ($data =~ /ARCH_RISCV64/);
85+
$architecture = x86 if ($data =~ /ARCH_X86/);
86+
$architecture = x86_64 if ($data =~ /ARCH_X86_64/);
87+
$architecture = power if ($data =~ /ARCH_POWER/);
88+
$architecture = mips if ($data =~ /ARCH_MIPS/);
89+
$architecture = mips64 if ($data =~ /ARCH_MIPS64/);
90+
$architecture = alpha if ($data =~ /ARCH_ALPHA/);
91+
$architecture = sparc if ($data =~ /ARCH_SPARC/);
92+
$architecture = ia64 if ($data =~ /ARCH_IA64/);
93+
$architecture = arm if ($data =~ /ARCH_ARM/);
94+
$architecture = arm64 if ($data =~ /ARCH_ARM64/);
95+
$architecture = zarch if ($data =~ /ARCH_ZARCH/);
96+
$architecture = riscv64 if ($data =~ /ARCH_RISCV64/);
97+
$architecture = loongarch64 if ($data =~ /ARCH_LOONGARCH64/);
9798

9899
$defined = 0;
99100

@@ -143,6 +144,11 @@ if ($architecture eq "riscv64") {
143144
$binary = 64;
144145
}
145146

147+
if ($architecture eq "loongarch64") {
148+
$defined = 1;
149+
$binary = 64;
150+
}
151+
146152
if ($compiler eq "PGI") {
147153
$compiler_name .= " -tp p7" if ($binary eq "32");
148154
$compiler_name .= " -tp p7-64" if ($binary eq "64");
@@ -215,17 +221,18 @@ if (($architecture eq "mips") || ($architecture eq "mips64")) {
215221
}
216222
}
217223

218-
$architecture = x86 if ($data =~ /ARCH_X86/);
219-
$architecture = x86_64 if ($data =~ /ARCH_X86_64/);
220-
$architecture = power if ($data =~ /ARCH_POWER/);
221-
$architecture = mips if ($data =~ /ARCH_MIPS/);
222-
$architecture = mips64 if ($data =~ /ARCH_MIPS64/);
223-
$architecture = alpha if ($data =~ /ARCH_ALPHA/);
224-
$architecture = sparc if ($data =~ /ARCH_SPARC/);
225-
$architecture = ia64 if ($data =~ /ARCH_IA64/);
226-
$architecture = arm if ($data =~ /ARCH_ARM/);
227-
$architecture = arm64 if ($data =~ /ARCH_ARM64/);
228-
$architecture = zarch if ($data =~ /ARCH_ZARCH/);
224+
$architecture = x86 if ($data =~ /ARCH_X86/);
225+
$architecture = x86_64 if ($data =~ /ARCH_X86_64/);
226+
$architecture = power if ($data =~ /ARCH_POWER/);
227+
$architecture = mips if ($data =~ /ARCH_MIPS/);
228+
$architecture = mips64 if ($data =~ /ARCH_MIPS64/);
229+
$architecture = alpha if ($data =~ /ARCH_ALPHA/);
230+
$architecture = sparc if ($data =~ /ARCH_SPARC/);
231+
$architecture = ia64 if ($data =~ /ARCH_IA64/);
232+
$architecture = arm if ($data =~ /ARCH_ARM/);
233+
$architecture = arm64 if ($data =~ /ARCH_ARM64/);
234+
$architecture = zarch if ($data =~ /ARCH_ZARCH/);
235+
$architecture = loongarch64 if ($data =~ /ARCH_LOONGARCH64/);
229236

230237
$binformat = bin32;
231238
$binformat = bin64 if ($data =~ /BINARY_64/);

common.h

+5-1
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ please https://github.com/xianyi/OpenBLAS/issues/246
449449
#include "common_mips.h"
450450
#endif
451451

452-
452+
453453
#ifdef ARCH_RISCV64
454454
#include "common_riscv64.h"
455455
#endif
@@ -470,6 +470,10 @@ please https://github.com/xianyi/OpenBLAS/issues/246
470470
#include "common_zarch.h"
471471
#endif
472472

473+
#ifdef ARCH_LOONGARCH64
474+
#include "common_loongarch64.h"
475+
#endif
476+
473477
#ifndef ASSEMBLER
474478
#ifdef OS_WINDOWSSTORE
475479
typedef char env_var_t[MAX_PATH];

common_loongarch64.h

+199
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,199 @@
1+
/*****************************************************************************
2+
Copyright (c) 2011-2020, The OpenBLAS Project
3+
All rights reserved.
4+
5+
Redistribution and use in source and binary forms, with or without
6+
modification, are permitted provided that the following conditions are
7+
met:
8+
9+
1. Redistributions of source code must retain the above copyright
10+
notice, this list of conditions and the following disclaimer.
11+
12+
2. Redistributions in binary form must reproduce the above copyright
13+
notice, this list of conditions and the following disclaimer in
14+
the documentation and/or other materials provided with the
15+
distribution.
16+
3. Neither the name of the OpenBLAS project nor the names of
17+
its contributors may be used to endorse or promote products
18+
derived from this software without specific prior written
19+
permission.
20+
21+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24+
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
25+
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
30+
USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31+
**********************************************************************************/
32+
33+
/*********************************************************************/
34+
/* Copyright 2009, 2010 The University of Texas at Austin. */
35+
/* All rights reserved. */
36+
/* */
37+
/* Redistribution and use in source and binary forms, with or */
38+
/* without modification, are permitted provided that the following */
39+
/* conditions are met: */
40+
/* */
41+
/* 1. Redistributions of source code must retain the above */
42+
/* copyright notice, this list of conditions and the following */
43+
/* disclaimer. */
44+
/* */
45+
/* 2. Redistributions in binary form must reproduce the above */
46+
/* copyright notice, this list of conditions and the following */
47+
/* disclaimer in the documentation and/or other materials */
48+
/* provided with the distribution. */
49+
/* */
50+
/* THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY OF TEXAS AT */
51+
/* AUSTIN ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, */
52+
/* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */
53+
/* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
54+
/* DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OF TEXAS AT */
55+
/* AUSTIN OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, */
56+
/* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES */
57+
/* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE */
58+
/* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR */
59+
/* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF */
60+
/* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT */
61+
/* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT */
62+
/* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE */
63+
/* POSSIBILITY OF SUCH DAMAGE. */
64+
/* */
65+
/* The views and conclusions contained in the software and */
66+
/* documentation are those of the authors and should not be */
67+
/* interpreted as representing official policies, either expressed */
68+
/* or implied, of The University of Texas at Austin. */
69+
/*********************************************************************/
70+
71+
#ifndef COMMON_LOONGARCH64
72+
#define COMMON_LOONGARCH64
73+
74+
#define MB __sync_synchronize()
75+
#define WMB __sync_synchronize()
76+
#define RMB __sync_synchronize()
77+
78+
#define INLINE inline
79+
80+
#ifndef ASSEMBLER
81+
82+
static inline int blas_quickdivide(blasint x, blasint y){
83+
return x / y;
84+
}
85+
86+
#ifdef DOUBLE
87+
#define GET_IMAGE(res) __asm__ __volatile__("fmov.d %0, $f2" : "=f"(res) : : "memory")
88+
#else
89+
#define GET_IMAGE(res) __asm__ __volatile__("fmov.s %0, $f2" : "=f"(res) : : "memory")
90+
#endif
91+
92+
#define GET_IMAGE_CANCEL
93+
94+
#else
95+
96+
#ifdef DOUBLE
97+
#define LD fld.d
98+
#define ST fst.d
99+
#define MADD fmadd.d
100+
#define NMADD fnmadd.d
101+
#define MSUB fmsub.d
102+
#define NMSUB fnmsub.d
103+
#define ADD fadd.d
104+
#define SUB fsub.d
105+
#define MUL fmul.d
106+
#define MOV fmov.d
107+
#define CMOVT fsel
108+
#define MTC movgr2fr.d
109+
#define FABS fabs.d
110+
#define CMPEQ fcmp.ceq.d
111+
#define CMPLE fcmp.cle.d
112+
#define CMPLT fcmp.clt.d
113+
#define NEG fneg.d
114+
#else
115+
#define LD fld.s
116+
#define ST fst.s
117+
#define MADD fmadd.s
118+
#define NMADD fnmadd.s
119+
#define MSUB fmsub.s
120+
#define NMSUB fnmsub.s
121+
#define ADD fadd.s
122+
#define SUB fsub.s
123+
#define MUL fmul.s
124+
#define MOV fmov.s
125+
#define CMOVT fsel
126+
#define MTC movgr2fr.w
127+
#define FABS fabs.s
128+
#define CMPEQ fcmp.ceq.s
129+
#define CMPLE fcmp.cle.s
130+
#define CMPLT fcmp.clt.s
131+
#define NEG fneg.s
132+
#endif /* defined(DOUBLE) */
133+
134+
#if defined(__64BIT__) && defined(USE64BITINT)
135+
#define LDINT ld.d
136+
#define LDARG ld.d
137+
#define SDARG st.d
138+
#elif defined(__64BIT__) && !defined(USE64BITINT)
139+
#define LDINT ld.w
140+
#define LDARG ld.d
141+
#define SDARG st.d
142+
#else
143+
#define LDINT ld.w
144+
#define LDARG ld.w
145+
#define SDARG st.w
146+
#endif
147+
148+
149+
#ifndef F_INTERFACE
150+
#define REALNAME ASMNAME
151+
#else
152+
#define REALNAME ASMFNAME
153+
#endif /* defined(F_INTERFACE) */
154+
155+
#if defined(ASSEMBLER) && !defined(NEEDPARAM)
156+
157+
#define PROLOGUE \
158+
.text ;\
159+
.align 5 ;\
160+
.globl REALNAME ;\
161+
.type REALNAME, @function ;\
162+
REALNAME: ;\
163+
164+
#if defined(__linux__) && defined(__ELF__)
165+
#define GNUSTACK .section .note.GNU-stack,"",@progbits
166+
#else
167+
#define GNUSTACK
168+
#endif /* defined(__linux__) && defined(__ELF__) */
169+
170+
#define EPILOGUE \
171+
.end REALNAME ;\
172+
GNUSTACK
173+
174+
#define PROFCODE
175+
176+
#define MOVT(dst, src, cc) \
177+
bceqz cc, 1f; \
178+
add.d dst, src, $r0; \
179+
1:
180+
181+
#endif /* defined(ASSEMBLER) && !defined(NEEDPARAM) */
182+
183+
#endif /* defined(ASSEMBLER) */
184+
185+
#define SEEK_ADDRESS
186+
187+
#define BUFFER_SIZE ( 32 << 20)
188+
189+
#define PAGESIZE (16UL << 1)
190+
#define FIXED_PAGESIZE (16UL << 10)
191+
#define HUGE_PAGESIZE ( 2 << 20)
192+
193+
#define BASE_ADDRESS (START_ADDRESS - BUFFER_SIZE * MAX_CPU_NUMBER)
194+
195+
#ifndef MAP_ANONYMOUS
196+
#define MAP_ANONYMOUS MAP_ANON
197+
#endif
198+
199+
#endif

common_macro.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -2490,7 +2490,8 @@
24902490
#endif
24912491

24922492
#ifndef ASSEMBLER
2493-
#if defined(ARCH_X86) || defined(ARCH_X86_64) || defined(ARCH_IA64) || defined(ARCH_MIPS64) || defined(ARCH_ARM64)
2493+
#if defined(ARCH_X86) || defined(ARCH_X86_64) || defined(ARCH_IA64) || defined(ARCH_MIPS64) || defined(ARCH_ARM64)\
2494+
|| defined(ARCH_LOONGARCH64)
24942495
extern BLASLONG gemm_offset_a;
24952496
extern BLASLONG gemm_offset_b;
24962497
extern BLASLONG sbgemm_p;

0 commit comments

Comments
 (0)