Skip to content

Commit ddfbc64

Browse files
authored
Merge pull request #5676 from martin-frbg/wasm_arch
Move the WebAssembly/Emscripten support to its own architecture and target
2 parents 450af57 + f2a8988 commit ddfbc64

File tree

18 files changed

+542
-32
lines changed

18 files changed

+542
-32
lines changed

Makefile.wasm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
CCOMMON_OPT += -msimd128

TargetList.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,3 +153,7 @@ EV6
153153
14.CSKY
154154
CSKY
155155
CK860FV
156+
157+
15. WebAssembly/Emscripten:
158+
WASM128_GENERIC
159+

c_check

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ case "$data" in
9797
*ARCH_RISCV64*) architecture=riscv64 ;;
9898
*ARCH_LOONGARCH64*) architecture=loongarch64 ;;
9999
*ARCH_CSKY*) architecture=csky ;;
100+
*ARCH_WASM*) architecture=wasm ;;
100101
esac
101102

102103
defined=0
@@ -130,7 +131,7 @@ case "$architecture" in
130131
defined=1
131132
;;
132133
arm|arm64) defined=1 ;;
133-
zarch|e2k|alpha|ia64|riscv64|loonarch64)
134+
zarch|e2k|alpha|ia64|riscv64|loonarch64|wasm)
134135
defined=1
135136
BINARY=64
136137
;;
@@ -254,6 +255,7 @@ case "$data" in
254255
*ARCH_ZARCH*) architecture=zarch ;;
255256
*ARCH_LOONGARCH64*) architecture=loongarch64 ;;
256257
*ARCH_CSKY*) architecture=csky ;;
258+
*ARCH_WASM*) architecture=wasm ;;
257259
esac
258260

259261
binformat='bin32'

cmake/prebuild.cmake

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,10 @@ if (${COMPILER_ID} STREQUAL "GNU")
9898
set(COMPILER_ID "GCC")
9999
endif ()
100100

101+
if (HOST_OS STREQUAL "EMSCRIPTEN")
102+
set (ARCH wasm)
103+
endif()
104+
101105
string(TOUPPER ${ARCH} UC_ARCH)
102106
file(WRITE ${TARGET_CONF_TEMP}
103107
"#define OS_${HOST_OS}\t1\n"
@@ -1500,6 +1504,15 @@ endif ()
15001504
"#define DTB_DEFAULT_ENTRIES 128\n"
15011505
"#define DTB_SIZE 4096\n"
15021506
"#define L2_ASSOCIATIVE 4\n")
1507+
elseif ("${TCORE}" STREQUAL "WASM128_GENERIC")
1508+
file(APPEND ${TARGET_CONF_TEMP}
1509+
"#define L1_DATA_SIZE 32768\n"
1510+
"#define L1_DATA_LINESIZE 32\n"
1511+
"#define L2_SIZE 1048576\n"
1512+
"#define L2_LINESIZE 32 \n"
1513+
"#define DTB_DEFAULT_ENTRIES 128\n"
1514+
"#define DTB_SIZE 4096\n"
1515+
"#define L2_ASSOCIATIVE 4\n")
15031516
elseif ("${TCORE}" STREQUAL "LA64_GENERIC")
15041517
file(APPEND ${TARGET_CONF_TEMP}
15051518
"#define DTB_DEFAULT_ENTRIES 64\n")

cmake/system.cmake

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -879,6 +879,10 @@ if (DEFINED ARCH)
879879
set(USE_GEMM3M 1)
880880
endif ()
881881

882+
if (EMSCRIPTEN)
883+
set(USE_GEMM3M 0)
884+
endif ()
885+
882886
if (${CORE} STREQUAL "generic")
883887
set(USE_GEMM3M 0)
884888
endif ()

cmake/system_check.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ if(CMAKE_CL_64 OR MINGW64)
4040
else()
4141
set(X86_64 1)
4242
endif()
43+
elseif(OS_EMSCRIPTEN)
44+
set(WASM 1)
4345
elseif(MINGW OR (MSVC AND NOT CMAKE_CROSSCOMPILING))
4446
set(X86 1)
4547
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "ppc.*|power.*|Power.*" OR (CMAKE_SYSTEM_NAME MATCHES "Darwin" AND CMAKE_OSX_ARCHITECTURES MATCHES "ppc.*"))

cmake/utils.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ macro(ParseMakefileVars MAKEFILE_IN)
5151
if (${OSNAME} STREQUAL Windows)
5252
set (OSNAME WINNT)
5353
endif ()
54-
message(STATUS OS ${OSNAME} COMPILER ${C_COMPILER})
54+
#message(STATUS OS ${OSNAME} COMPILER ${C_COMPILER})
5555
set (IfElse 0)
5656
set (ElseSeen 0)
5757
set (SkipIfs 0)

common.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,9 +386,11 @@ typedef int blasint;
386386
#endif
387387
#endif
388388

389-
#ifdef __EMSCRIPTEN__
389+
#if defined(ARCH_WASM)
390+
#ifndef YIELDING
390391
#define YIELDING
391392
#endif
393+
#endif
392394

393395
#if defined(_MSC_VER) && !defined(__clang__)
394396
#undef YIELDING // MSVC doesn't support assembly code
@@ -498,6 +500,10 @@ please https://github.com/xianyi/OpenBLAS/issues/246
498500
#include "common_csky.h"
499501
#endif
500502

503+
#ifdef ARCH_WASM
504+
#include "common_wasm.h"
505+
#endif
506+
501507
#ifndef ASSEMBLER
502508
#ifdef OS_WINDOWSSTORE
503509
typedef char env_var_t[MAX_PATH];

common_wasm.h

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
/*****************************************************************************
2+
Copyright (c) 2011-2014, 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_WASM
72+
#define COMMON_WASM
73+
74+
#define MB __sync_synchronize()
75+
#define WMB __sync_synchronize()
76+
#define RMB __sync_synchronize()
77+
78+
#ifndef ASSEMBLER
79+
80+
81+
static inline int blas_quickdivide(blasint x, blasint y){
82+
return x / y;
83+
}
84+
85+
#endif
86+
87+
#define BUFFER_SIZE ( 16 << 20)
88+
#define SEEK_ADDRESS
89+
90+
#endif
91+

ctest.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ ARCH_CSKY
178178
#endif
179179

180180
#if defined(__EMSCRIPTEN__)
181-
ARCH_RISCV64
181+
ARCH_WASM
182182
OS_WINDOWS
183183
#endif
184184

0 commit comments

Comments
 (0)