diff --git a/third_party/swiftshader/src/Reactor/SubzeroReactor.cpp b/third_party/swiftshader/src/Reactor/SubzeroReactor.cpp index 3bc99c6fb87414eecac0ddb305d1f5428a511de1..058f6fe51a6ac36335e5054f0e27507703a663a1 100644 --- a/third_party/swiftshader/src/Reactor/SubzeroReactor.cpp +++ b/third_party/swiftshader/src/Reactor/SubzeroReactor.cpp @@ -46,7 +46,7 @@ # define WIN32_LEAN_AND_MEAN # endif // !WIN32_LEAN_AND_MEAN # ifndef NOMINMAX -third_party/swiftshader/src/Reactor/SubzeroReactor.cpp# define NOMINMAX +# define NOMINMAX # endif // !NOMINMAX # include <Windows.h> #endif @@ -55,6 +55,7 @@ third_party/swiftshader/src/Reactor/SubzeroReactor.cpp# define NOMINMAX #include <iostream> #include <limits> #include <mutex> +//#include <elf.h> // Subzero utility functions // These functions only accept and return Subzero (Ice) types, and do not access any globals. @@ -82,7 +83,7 @@ Ice::Cfg *createFunction(Ice::GlobalContext *context, Ice::Type returnType, cons return function; } -Ice::Type getPointerType(Ice::Type elementType)third_party/swiftshader/src/Reactor/SubzeroReactor.cpp +Ice::Type getPointerType(Ice::Type elementType) { if(sizeof(void *) == 8) { @@ -187,7 +188,6 @@ Ice::Variable *createLoad(Ice::Cfg *function, Ice::CfgNode *basicBlock, Ice::Ope Ice::Variable *result = function->makeVariable(type); auto load = Ice::InstLoad::create(function, result, ptr, align); basicBlock->appendInst(load); - return result; } @@ -315,7 +315,7 @@ private: return true; #elif defined(__i386__) || defined(__x86_64__) return false; -#elif defined(__mips__) +#elif defined(__mips__) || defined(__loongarch__) return false; #else # error "Unknown architecture" @@ -355,7 +355,6 @@ std::string BackendName() { return "Subzero"; } -third_party/swiftshader/src/Reactor/SubzeroReactor.cpp const Capabilities Caps = { true, // CoroutinesSupported }; @@ -412,7 +411,7 @@ std::vector<Ice::Type> T(const std::vector<Type *> &types) Value *V(Ice::Operand *v) { - return reinterpret_cast<Value *>(v);third_party/swiftshader/src/Reactor/SubzeroReactor.cpp + return reinterpret_cast<Value *>(v); } Ice::Operand *V(Value *v) @@ -436,7 +435,7 @@ BasicBlock *B(Ice::CfgNode *b) return reinterpret_cast<BasicBlock *>(b); } -static size_t typeSize(Type *type)third_party/swiftshader/src/Reactor/SubzeroReactor.cpp +static size_t typeSize(Type *type) { if(reinterpret_cast<std::intptr_t>(type) & EmulatedBits) { diff --git a/third_party/swiftshader/third_party/llvm-subzero/include/llvm/Support/ELF.h b/third_party/swiftshader/third_party/llvm-subzero/include/llvm/Support/ELF.h index d951e552f7d01d3ab7a45b6ab1b96da7e4a2f515..075769bbad3b61e06ba6f64f09babb72d1ab9551 100644 --- a/third_party/swiftshader/third_party/llvm-subzero/include/llvm/Support/ELF.h +++ b/third_party/swiftshader/third_party/llvm-subzero/include/llvm/Support/ELF.h @@ -310,6 +310,7 @@ enum { EM_RISCV = 243, // RISC-V EM_LANAI = 244, // Lanai 32-bit processor EM_BPF = 247, // Linux kernel bpf virtual machine + EM_LOONGARCH = 258, // Loongsin Loongarch by Spread haha // A request has been made to the maintainer of the official registry for // such numbers for an official value for WebAssembly. As soon as one is diff --git a/third_party/swiftshader/third_party/marl/src/osfiber_asm.h b/third_party/swiftshader/third_party/marl/src/osfiber_asm.h index e9ce773a8def3d3731d8f8d127973ff2e629e6d5..9b0a9384e062294048ec36e908618eb31cb19841 100644 --- a/third_party/swiftshader/third_party/marl/src/osfiber_asm.h +++ b/third_party/swiftshader/third_party/marl/src/osfiber_asm.h @@ -34,6 +34,8 @@ #include "osfiber_asm_ppc64.h" #elif defined(__mips__) && _MIPS_SIM == _ABI64 #include "osfiber_asm_mips64.h" +#elif defined(__loongarch__) +#include "osfiber_asm_loongarch.h" #elif defined(__riscv) && __riscv_xlen == 64 #include "osfiber_asm_rv64.h" #else diff --git a/third_party/swiftshader/third_party/marl/src/osfiber_asm_loongarch.S b/third_party/swiftshader/third_party/marl/src/osfiber_asm_loongarch.S new file mode 100644 index 0000000000000000000000000000000000000000..264cef57180de9e8a6fd51f767418beec36ee2d5 --- /dev/null +++ b/third_party/swiftshader/third_party/marl/src/osfiber_asm_loongarch.S @@ -0,0 +1,73 @@ +#if defined(__loongarch__) + +#define MARL_BUILD_ASM 1 + +#include "osfiber_asm_loongarch.h" + +.text +.global MARL_ASM_SYMBOL(marl_fiber_swap) +.align 4 + +MARL_ASM_SYMBOL(marl_fiber_swap): + + // Save context 'from' + + // Store callee-preserved registers + st.d $s0, MARL_REG_s0($a0) + st.d $s1, MARL_REG_s1($a0) + st.d $s2, MARL_REG_s2($a0) + st.d $s3, MARL_REG_s3($a0) + st.d $s4, MARL_REG_s4($a0) + st.d $s5, MARL_REG_s5($a0) + st.d $s6, MARL_REG_s6($a0) + st.d $s7, MARL_REG_s7($a0) + + st.d $f24, MARL_REG_f24($a0) + st.d $f25, MARL_REG_f25($a0) + st.d $f26, MARL_REG_f26($a0) + st.d $f27, MARL_REG_f27($a0) + st.d $f28, MARL_REG_f28($a0) + st.d $f29, MARL_REG_f29($a0) + st.d $f31, MARL_REG_f30($a0) + st.d $f31, MARL_REG_f31($a0) + + st.d $gp, MARL_REG_gp($a0) + st.d $sp, MARL_REG_sp($a0) + st.d $fp, MARL_REG_fp($a0) + st.d $ra, MARL_REG_ra($a0) + + move $v0, $a1 + + + ld.d $s0, MARL_REG_s0($v0) + ld.d $s1, MARL_REG_s1($v0) + ld.d $s2, MARL_REG_s2($v0) + ld.d $s3, MARL_REG_s3($v0) + ld.d $s4, MARL_REG_s4($v0) + ld.d $s5, MARL_REG_s5($v0) + ld.d $s6, MARL_REG_s6($v0) + ld.d $s7, MARL_REG_s7($v0) + + + ld.d $f24, MARL_REG_f24($v0) + ld.d $f25, MARL_REG_f25($v0) + ld.d $f26, MARL_REG_f26($v0) + ld.d $f27, MARL_REG_f27($v0) + ld.d $f28, MARL_REG_f28($v0) + ld.d $f29, MARL_REG_f29($v0) + ld.d $f31, MARL_REG_f30($v0) + ld.d $f31, MARL_REG_f31($v0) + + ld.d $gp, MARL_REG_gp($v0) + ld.d $sp, MARL_REG_sp($v0) + ld.d $fp, MARL_REG_fp($v0) + ld.d $ra, MARL_REG_ra($v0) + + // Recover arguments + ld.d $a0, MARL_REG_a0($v0) + ld.d $a1, MARL_REG_a1($v0) + + jirl $ra + +#endif // defined(__loongarch__) + diff --git a/third_party/swiftshader/third_party/marl/src/osfiber_asm_loongarch.h b/third_party/swiftshader/third_party/marl/src/osfiber_asm_loongarch.h new file mode 100644 index 0000000000000000000000000000000000000000..e444e1c78bf4c769454b75ec8217f62c74661ff7 --- /dev/null +++ b/third_party/swiftshader/third_party/marl/src/osfiber_asm_loongarch.h @@ -0,0 +1,126 @@ +// Copyright 2020 The Marl Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#define MARL_REG_a0 0x00 +#define MARL_REG_a1 0x08 +#define MARL_REG_s0 0x10 +#define MARL_REG_s1 0x18 +#define MARL_REG_s2 0x20 +#define MARL_REG_s3 0x28 +#define MARL_REG_s4 0x30 +#define MARL_REG_s5 0x38 +#define MARL_REG_s6 0x40 +#define MARL_REG_s7 0x48 +#define MARL_REG_f24 0x50 +#define MARL_REG_f25 0x58 +#define MARL_REG_f26 0x60 +#define MARL_REG_f27 0x68 +#define MARL_REG_f28 0x70 +#define MARL_REG_f29 0x78 +#define MARL_REG_f30 0x80 +#define MARL_REG_f31 0x88 +#define MARL_REG_gp 0x90 +#define MARL_REG_sp 0x98 +#define MARL_REG_fp 0xa0 +#define MARL_REG_ra 0xa8 + +#if defined(__APPLE__) +#define MARL_ASM_SYMBOL(x) _##x +#else +#define MARL_ASM_SYMBOL(x) x +#endif + +#ifndef MARL_BUILD_ASM + +#include <stdint.h> + +struct marl_fiber_context { + // parameter registers (First two) + uintptr_t a0; + uintptr_t a1; + + // callee-saved registers + uintptr_t s0; + uintptr_t s1; + uintptr_t s2; + uintptr_t s3; + uintptr_t s4; + uintptr_t s5; + uintptr_t s6; + uintptr_t s7; + + uintptr_t f24; + uintptr_t f25; + uintptr_t f26; + uintptr_t f27; + uintptr_t f28; + uintptr_t f29; + uintptr_t f30; + uintptr_t f31; + + uintptr_t gp; + uintptr_t sp; + uintptr_t fp; + uintptr_t ra; +}; + +#ifdef __cplusplus +#include <cstddef> +static_assert(offsetof(marl_fiber_context, a0) == MARL_REG_a0, + "Bad register offset"); +static_assert(offsetof(marl_fiber_context, a1) == MARL_REG_a1, + "Bad register offset"); +static_assert(offsetof(marl_fiber_context, s0) == MARL_REG_s0, + "Bad register offset"); +static_assert(offsetof(marl_fiber_context, s1) == MARL_REG_s1, + "Bad register offset"); +static_assert(offsetof(marl_fiber_context, s2) == MARL_REG_s2, + "Bad register offset"); +static_assert(offsetof(marl_fiber_context, s3) == MARL_REG_s3, + "Bad register offset"); +static_assert(offsetof(marl_fiber_context, s4) == MARL_REG_s4, + "Bad register offset"); +static_assert(offsetof(marl_fiber_context, s5) == MARL_REG_s5, + "Bad register offset"); +static_assert(offsetof(marl_fiber_context, s6) == MARL_REG_s6, + "Bad register offset"); +static_assert(offsetof(marl_fiber_context, s7) == MARL_REG_s7, + "Bad register offset"); +static_assert(offsetof(marl_fiber_context, f24) == MARL_REG_f24, + "Bad register offset"); +static_assert(offsetof(marl_fiber_context, f25) == MARL_REG_f25, + "Bad register offset"); +static_assert(offsetof(marl_fiber_context, f26) == MARL_REG_f26, + "Bad register offset"); +static_assert(offsetof(marl_fiber_context, f27) == MARL_REG_f27, + "Bad register offset"); +static_assert(offsetof(marl_fiber_context, f28) == MARL_REG_f28, + "Bad register offset"); +static_assert(offsetof(marl_fiber_context, f29) == MARL_REG_f29, + "Bad register offset"); +static_assert(offsetof(marl_fiber_context, f30) == MARL_REG_f30, + "Bad register offset"); +static_assert(offsetof(marl_fiber_context, f31) == MARL_REG_f31, + "Bad register offset"); +static_assert(offsetof(marl_fiber_context, gp) == MARL_REG_gp, + "Bad register offset"); +static_assert(offsetof(marl_fiber_context, sp) == MARL_REG_sp, + "Bad register offset"); +static_assert(offsetof(marl_fiber_context, fp) == MARL_REG_fp, + "Bad register offset"); +static_assert(offsetof(marl_fiber_context, ra) == MARL_REG_ra, + "Bad register offset"); +#endif // __cplusplus + +#endif // MARL_BUILD_ASM