make runtime compatible with wasm

This commit is contained in:
Li Jie
2025-04-08 16:50:47 +08:00
parent 7c81d9293b
commit be4737461a
183 changed files with 14122 additions and 647 deletions

View File

@@ -22,9 +22,6 @@ import (
"github.com/goplus/llgo/runtime/abi"
)
// llgo:skipall
type _abi struct{}
type InterfaceType = abi.InterfaceType
func NoEscape(p unsafe.Pointer) unsafe.Pointer {

View File

@@ -0,0 +1,185 @@
package chacha8rand
import (
"unsafe"
"github.com/goplus/llgo/runtime/internal/runtime/goarch"
)
func block(seed *[4]uint64, blocks *[32]uint64, counter uint32) {
block_generic(seed, blocks, counter)
}
// setup sets up 4 ChaCha8 blocks in b32 with the counter and seed.
// Note that b32 is [16][4]uint32 not [4][16]uint32: the blocks are interlaced
// the same way they would be in a 4-way SIMD implementations.
func setup(seed *[4]uint64, b32 *[16][4]uint32, counter uint32) {
// Convert to uint64 to do half as many stores to memory.
b := (*[16][2]uint64)(unsafe.Pointer(b32))
// Constants; same as in ChaCha20: "expand 32-byte k"
b[0][0] = 0x61707865_61707865
b[0][1] = 0x61707865_61707865
b[1][0] = 0x3320646e_3320646e
b[1][1] = 0x3320646e_3320646e
b[2][0] = 0x79622d32_79622d32
b[2][1] = 0x79622d32_79622d32
b[3][0] = 0x6b206574_6b206574
b[3][1] = 0x6b206574_6b206574
// Seed values.
var x64 uint64
var x uint32
x = uint32(seed[0])
x64 = uint64(x)<<32 | uint64(x)
b[4][0] = x64
b[4][1] = x64
x = uint32(seed[0] >> 32)
x64 = uint64(x)<<32 | uint64(x)
b[5][0] = x64
b[5][1] = x64
x = uint32(seed[1])
x64 = uint64(x)<<32 | uint64(x)
b[6][0] = x64
b[6][1] = x64
x = uint32(seed[1] >> 32)
x64 = uint64(x)<<32 | uint64(x)
b[7][0] = x64
b[7][1] = x64
x = uint32(seed[2])
x64 = uint64(x)<<32 | uint64(x)
b[8][0] = x64
b[8][1] = x64
x = uint32(seed[2] >> 32)
x64 = uint64(x)<<32 | uint64(x)
b[9][0] = x64
b[9][1] = x64
x = uint32(seed[3])
x64 = uint64(x)<<32 | uint64(x)
b[10][0] = x64
b[10][1] = x64
x = uint32(seed[3] >> 32)
x64 = uint64(x)<<32 | uint64(x)
b[11][0] = x64
b[11][1] = x64
// Counters.
if goarch.BigEndian {
b[12][0] = uint64(counter+0)<<32 | uint64(counter+1)
b[12][1] = uint64(counter+2)<<32 | uint64(counter+3)
} else {
b[12][0] = uint64(counter+0) | uint64(counter+1)<<32
b[12][1] = uint64(counter+2) | uint64(counter+3)<<32
}
// Zeros.
b[13][0] = 0
b[13][1] = 0
b[14][0] = 0
b[14][1] = 0
b[15][0] = 0
b[15][1] = 0
}
// block_generic is the non-assembly block implementation,
// for use on systems without special assembly.
// Even on such systems, it is quite fast: on GOOS=386,
// ChaCha8 using this code generates random values faster than PCG-DXSM.
func block_generic(seed *[4]uint64, buf *[32]uint64, counter uint32) {
b := (*[16][4]uint32)(unsafe.Pointer(buf))
setup(seed, b, counter)
for i := range b[0] {
// Load block i from b[*][i] into local variables.
b0 := b[0][i]
b1 := b[1][i]
b2 := b[2][i]
b3 := b[3][i]
b4 := b[4][i]
b5 := b[5][i]
b6 := b[6][i]
b7 := b[7][i]
b8 := b[8][i]
b9 := b[9][i]
b10 := b[10][i]
b11 := b[11][i]
b12 := b[12][i]
b13 := b[13][i]
b14 := b[14][i]
b15 := b[15][i]
// 4 iterations of eight quarter-rounds each is 8 rounds
for round := 0; round < 4; round++ {
b0, b4, b8, b12 = qr(b0, b4, b8, b12)
b1, b5, b9, b13 = qr(b1, b5, b9, b13)
b2, b6, b10, b14 = qr(b2, b6, b10, b14)
b3, b7, b11, b15 = qr(b3, b7, b11, b15)
b0, b5, b10, b15 = qr(b0, b5, b10, b15)
b1, b6, b11, b12 = qr(b1, b6, b11, b12)
b2, b7, b8, b13 = qr(b2, b7, b8, b13)
b3, b4, b9, b14 = qr(b3, b4, b9, b14)
}
// Store block i back into b[*][i].
// Add b4..b11 back to the original key material,
// like in ChaCha20, to avoid trivial invertibility.
// There is no entropy in b0..b3 and b12..b15
// so we can skip the additions and save some time.
b[0][i] = b0
b[1][i] = b1
b[2][i] = b2
b[3][i] = b3
b[4][i] += b4
b[5][i] += b5
b[6][i] += b6
b[7][i] += b7
b[8][i] += b8
b[9][i] += b9
b[10][i] += b10
b[11][i] += b11
b[12][i] = b12
b[13][i] = b13
b[14][i] = b14
b[15][i] = b15
}
if goarch.BigEndian {
// On a big-endian system, reading the uint32 pairs as uint64s
// will word-swap them compared to little-endian, so we word-swap
// them here first to make the next swap get the right answer.
for i, x := range buf {
buf[i] = x>>32 | x<<32
}
}
}
// qr is the (inlinable) ChaCha8 quarter round.
func qr(a, b, c, d uint32) (_a, _b, _c, _d uint32) {
a += b
d ^= a
d = d<<16 | d>>16
c += d
b ^= c
b = b<<12 | b>>20
a += b
d ^= a
d = d<<8 | d>>24
c += d
b ^= c
b = b<<7 | b>>25
return a, b, c, d
}

View File

@@ -0,0 +1,21 @@
#if defined(__GNUC__) || defined(__clang__)
void llgo_getcpuid(unsigned int eax, unsigned int ecx,
unsigned int *a, unsigned int *b,
unsigned int *c, unsigned int *d)
{
#if defined(__i386__) || defined(__x86_64__)
__asm__ __volatile__(
"pushq %%rbp\n\t"
"movq %%rsp, %%rbp\n\t"
"andq $-16, %%rsp\n\t" // 16-byte align stack
"cpuid\n\t"
"movq %%rbp, %%rsp\n\t"
"popq %%rbp\n\t"
: "=a"(*a), "=b"(*b), "=c"(*c), "=d"(*d)
: "a"(eax), "c"(ecx)
: "memory");
#endif
}
#else
#error This code requires GCC or Clang
#endif

View File

@@ -2,39 +2,28 @@
package cpu
/*
#if defined(__GNUC__) || defined(__clang__)
static void getcpuid(unsigned int eax, unsigned int ecx,
unsigned int *a, unsigned int *b,
unsigned int *c, unsigned int *d) {
#if defined(__i386__) || defined(__x86_64__)
__asm__ __volatile__(
"pushq %%rbp\n\t"
"movq %%rsp, %%rbp\n\t"
"andq $-16, %%rsp\n\t" // 16-byte align stack
"cpuid\n\t"
"movq %%rbp, %%rsp\n\t"
"popq %%rbp\n\t"
: "=a"(*a), "=b"(*b), "=c"(*c), "=d"(*d)
: "a"(eax), "c"(ecx)
: "memory"
);
#endif
}
#else
#error This code requires GCC or Clang
#endif
*/
import "C"
import (
_ "unsafe"
c "github.com/goplus/llgo/runtime/internal/clite"
)
const (
LLGoPackage = "link"
LLGoFiles = "_wrap/cpu_x86.c"
)
//go:linkname c_getcpuid C.llgo_getcpuid
func c_getcpuid(eaxArg, ecxArg uint32, eax, ebx, ecx, edx *c.Uint)
func cpuid(eaxArg, ecxArg uint32) (eax, ebx, ecx, edx uint32) {
C.getcpuid(
C.uint(eaxArg),
C.uint(ecxArg),
(*C.uint)(&eax),
(*C.uint)(&ebx),
(*C.uint)(&ecx),
(*C.uint)(&edx),
c_getcpuid(
c.Uint(eaxArg),
c.Uint(ecxArg),
(*c.Uint)(&eax),
(*c.Uint)(&ebx),
(*c.Uint)(&ecx),
(*c.Uint)(&edx),
)
return
}

View File

@@ -0,0 +1,60 @@
// Copyright 2014 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build ignore
package main
import (
"bytes"
"fmt"
"log"
"os"
"strings"
)
var goarches []string
func main() {
data, err := os.ReadFile("../../internal/syslist/syslist.go")
if err != nil {
log.Fatal(err)
}
const goarchPrefix = `var KnownArch = map[string]bool{`
inGOARCH := false
for _, line := range strings.Split(string(data), "\n") {
if strings.HasPrefix(line, goarchPrefix) {
inGOARCH = true
} else if inGOARCH && strings.HasPrefix(line, "}") {
break
} else if inGOARCH {
goarch := strings.Fields(line)[0]
goarch = strings.TrimPrefix(goarch, `"`)
goarch = strings.TrimSuffix(goarch, `":`)
goarches = append(goarches, goarch)
}
}
for _, target := range goarches {
if target == "amd64p32" {
continue
}
var buf bytes.Buffer
fmt.Fprintf(&buf, "// Code generated by gengoarch.go using 'go generate'. DO NOT EDIT.\n\n")
fmt.Fprintf(&buf, "//go:build %s\n\n", target) // must explicitly include target for bootstrapping purposes
fmt.Fprintf(&buf, "package goarch\n\n")
fmt.Fprintf(&buf, "const GOARCH = `%s`\n\n", target)
for _, goarch := range goarches {
value := 0
if goarch == target {
value = 1
}
fmt.Fprintf(&buf, "const Is%s = %d\n", strings.Title(goarch), value)
}
err := os.WriteFile("zgoarch_"+target+".go", buf.Bytes(), 0666)
if err != nil {
log.Fatal(err)
}
}
}

View File

@@ -0,0 +1,60 @@
// Copyright 2021 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// package goarch contains GOARCH-specific constants.
package goarch
// The next line makes 'go generate' write the zgoarch*.go files with
// per-arch information, including constants named $GOARCH for every
// GOARCH. The constant is 1 on the current system, 0 otherwise; multiplying
// by them is useful for defining GOARCH-specific constants.
//
//go:generate go run gengoarch.go
type ArchFamilyType int
const (
AMD64 ArchFamilyType = iota
ARM
ARM64
I386
LOONG64
MIPS
MIPS64
PPC64
RISCV64
S390X
WASM
)
// PtrSize is the size of a pointer in bytes - unsafe.Sizeof(uintptr(0)) but as an ideal constant.
// It is also the size of the machine's native word size (that is, 4 on 32-bit systems, 8 on 64-bit).
const PtrSize = 4 << (^uintptr(0) >> 63)
// ArchFamily is the architecture family (AMD64, ARM, ...)
const ArchFamily ArchFamilyType = _ArchFamily
// BigEndian reports whether the architecture is big-endian.
const BigEndian = IsArmbe|IsArm64be|IsMips|IsMips64|IsPpc|IsPpc64|IsS390|IsS390x|IsSparc|IsSparc64 == 1
// DefaultPhysPageSize is the default physical page size.
const DefaultPhysPageSize = _DefaultPhysPageSize
// PCQuantum is the minimal unit for a program counter (1 on x86, 4 on most other systems).
// The various PC tables record PC deltas pre-divided by PCQuantum.
const PCQuantum = _PCQuantum
// Int64Align is the required alignment for a 64-bit integer (4 on 32-bit systems, 8 on 64-bit).
const Int64Align = PtrSize
// MinFrameSize is the size of the system-reserved words at the bottom
// of a frame (just above the architectural stack pointer).
// It is zero on x86 and PtrSize on most non-x86 (LR-based) systems.
// On PowerPC it is larger, to cover three more reserved words:
// the compiler word, the link editor word, and the TOC save word.
const MinFrameSize = _MinFrameSize
// StackAlign is the required alignment of the SP register.
// The stack must be at least word aligned, but some architectures require more.
const StackAlign = _StackAlign

View File

@@ -0,0 +1,13 @@
// Copyright 2014 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package goarch
const (
_ArchFamily = I386
_DefaultPhysPageSize = 4096
_PCQuantum = 1
_MinFrameSize = 0
_StackAlign = PtrSize
)

View File

@@ -0,0 +1,13 @@
// Copyright 2014 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package goarch
const (
_ArchFamily = AMD64
_DefaultPhysPageSize = 4096
_PCQuantum = 1
_MinFrameSize = 0
_StackAlign = PtrSize
)

View File

@@ -0,0 +1,13 @@
// Copyright 2014 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package goarch
const (
_ArchFamily = ARM
_DefaultPhysPageSize = 65536
_PCQuantum = 4
_MinFrameSize = 4
_StackAlign = PtrSize
)

View File

@@ -0,0 +1,13 @@
// Copyright 2014 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package goarch
const (
_ArchFamily = ARM64
_DefaultPhysPageSize = 65536
_PCQuantum = 4
_MinFrameSize = 8
_StackAlign = 16
)

View File

@@ -0,0 +1,15 @@
// Copyright 2022 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build loong64
package goarch
const (
_ArchFamily = LOONG64
_DefaultPhysPageSize = 16384
_PCQuantum = 4
_MinFrameSize = 8
_StackAlign = PtrSize
)

View File

@@ -0,0 +1,13 @@
// Copyright 2015 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package goarch
const (
_ArchFamily = MIPS
_DefaultPhysPageSize = 65536
_PCQuantum = 4
_MinFrameSize = 4
_StackAlign = PtrSize
)

View File

@@ -0,0 +1,13 @@
// Copyright 2015 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package goarch
const (
_ArchFamily = MIPS64
_DefaultPhysPageSize = 16384
_PCQuantum = 4
_MinFrameSize = 8
_StackAlign = PtrSize
)

View File

@@ -0,0 +1,13 @@
// Copyright 2015 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package goarch
const (
_ArchFamily = MIPS64
_DefaultPhysPageSize = 16384
_PCQuantum = 4
_MinFrameSize = 8
_StackAlign = PtrSize
)

View File

@@ -0,0 +1,13 @@
// Copyright 2016 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package goarch
const (
_ArchFamily = MIPS
_DefaultPhysPageSize = 65536
_PCQuantum = 4
_MinFrameSize = 4
_StackAlign = PtrSize
)

View File

@@ -0,0 +1,13 @@
// Copyright 2014 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package goarch
const (
_ArchFamily = PPC64
_DefaultPhysPageSize = 65536
_PCQuantum = 4
_MinFrameSize = 32
_StackAlign = 16
)

View File

@@ -0,0 +1,13 @@
// Copyright 2014 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package goarch
const (
_ArchFamily = PPC64
_DefaultPhysPageSize = 65536
_PCQuantum = 4
_MinFrameSize = 32
_StackAlign = 16
)

View File

@@ -0,0 +1,13 @@
// Copyright 2016 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package goarch
const (
_ArchFamily = RISCV64
_DefaultPhysPageSize = 4096
_PCQuantum = 4
_MinFrameSize = 8
_StackAlign = PtrSize
)

View File

@@ -0,0 +1,13 @@
// Copyright 2016 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package goarch
const (
_ArchFamily = S390X
_DefaultPhysPageSize = 4096
_PCQuantum = 2
_MinFrameSize = 8
_StackAlign = PtrSize
)

View File

@@ -0,0 +1,13 @@
// Copyright 2018 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package goarch
const (
_ArchFamily = WASM
_DefaultPhysPageSize = 65536
_PCQuantum = 1
_MinFrameSize = 0
_StackAlign = PtrSize
)

View File

@@ -0,0 +1,32 @@
// Code generated by gengoarch.go using 'go generate'. DO NOT EDIT.
//go:build 386
package goarch
const GOARCH = `386`
const Is386 = 1
const IsAmd64 = 0
const IsAmd64p32 = 0
const IsArm = 0
const IsArmbe = 0
const IsArm64 = 0
const IsArm64be = 0
const IsLoong64 = 0
const IsMips = 0
const IsMipsle = 0
const IsMips64 = 0
const IsMips64le = 0
const IsMips64p32 = 0
const IsMips64p32le = 0
const IsPpc = 0
const IsPpc64 = 0
const IsPpc64le = 0
const IsRiscv = 0
const IsRiscv64 = 0
const IsS390 = 0
const IsS390x = 0
const IsSparc = 0
const IsSparc64 = 0
const IsWasm = 0

View File

@@ -0,0 +1,32 @@
// Code generated by gengoarch.go using 'go generate'. DO NOT EDIT.
//go:build amd64
package goarch
const GOARCH = `amd64`
const Is386 = 0
const IsAmd64 = 1
const IsAmd64p32 = 0
const IsArm = 0
const IsArmbe = 0
const IsArm64 = 0
const IsArm64be = 0
const IsLoong64 = 0
const IsMips = 0
const IsMipsle = 0
const IsMips64 = 0
const IsMips64le = 0
const IsMips64p32 = 0
const IsMips64p32le = 0
const IsPpc = 0
const IsPpc64 = 0
const IsPpc64le = 0
const IsRiscv = 0
const IsRiscv64 = 0
const IsS390 = 0
const IsS390x = 0
const IsSparc = 0
const IsSparc64 = 0
const IsWasm = 0

View File

@@ -0,0 +1,32 @@
// Code generated by gengoarch.go using 'go generate'. DO NOT EDIT.
//go:build arm
package goarch
const GOARCH = `arm`
const Is386 = 0
const IsAmd64 = 0
const IsAmd64p32 = 0
const IsArm = 1
const IsArmbe = 0
const IsArm64 = 0
const IsArm64be = 0
const IsLoong64 = 0
const IsMips = 0
const IsMipsle = 0
const IsMips64 = 0
const IsMips64le = 0
const IsMips64p32 = 0
const IsMips64p32le = 0
const IsPpc = 0
const IsPpc64 = 0
const IsPpc64le = 0
const IsRiscv = 0
const IsRiscv64 = 0
const IsS390 = 0
const IsS390x = 0
const IsSparc = 0
const IsSparc64 = 0
const IsWasm = 0

View File

@@ -0,0 +1,32 @@
// Code generated by gengoarch.go using 'go generate'. DO NOT EDIT.
//go:build arm64
package goarch
const GOARCH = `arm64`
const Is386 = 0
const IsAmd64 = 0
const IsAmd64p32 = 0
const IsArm = 0
const IsArmbe = 0
const IsArm64 = 1
const IsArm64be = 0
const IsLoong64 = 0
const IsMips = 0
const IsMipsle = 0
const IsMips64 = 0
const IsMips64le = 0
const IsMips64p32 = 0
const IsMips64p32le = 0
const IsPpc = 0
const IsPpc64 = 0
const IsPpc64le = 0
const IsRiscv = 0
const IsRiscv64 = 0
const IsS390 = 0
const IsS390x = 0
const IsSparc = 0
const IsSparc64 = 0
const IsWasm = 0

View File

@@ -0,0 +1,32 @@
// Code generated by gengoarch.go using 'go generate'. DO NOT EDIT.
//go:build arm64be
package goarch
const GOARCH = `arm64be`
const Is386 = 0
const IsAmd64 = 0
const IsAmd64p32 = 0
const IsArm = 0
const IsArmbe = 0
const IsArm64 = 0
const IsArm64be = 1
const IsLoong64 = 0
const IsMips = 0
const IsMipsle = 0
const IsMips64 = 0
const IsMips64le = 0
const IsMips64p32 = 0
const IsMips64p32le = 0
const IsPpc = 0
const IsPpc64 = 0
const IsPpc64le = 0
const IsRiscv = 0
const IsRiscv64 = 0
const IsS390 = 0
const IsS390x = 0
const IsSparc = 0
const IsSparc64 = 0
const IsWasm = 0

View File

@@ -0,0 +1,32 @@
// Code generated by gengoarch.go using 'go generate'. DO NOT EDIT.
//go:build armbe
package goarch
const GOARCH = `armbe`
const Is386 = 0
const IsAmd64 = 0
const IsAmd64p32 = 0
const IsArm = 0
const IsArmbe = 1
const IsArm64 = 0
const IsArm64be = 0
const IsLoong64 = 0
const IsMips = 0
const IsMipsle = 0
const IsMips64 = 0
const IsMips64le = 0
const IsMips64p32 = 0
const IsMips64p32le = 0
const IsPpc = 0
const IsPpc64 = 0
const IsPpc64le = 0
const IsRiscv = 0
const IsRiscv64 = 0
const IsS390 = 0
const IsS390x = 0
const IsSparc = 0
const IsSparc64 = 0
const IsWasm = 0

View File

@@ -0,0 +1,32 @@
// Code generated by gengoarch.go using 'go generate'. DO NOT EDIT.
//go:build loong64
package goarch
const GOARCH = `loong64`
const Is386 = 0
const IsAmd64 = 0
const IsAmd64p32 = 0
const IsArm = 0
const IsArmbe = 0
const IsArm64 = 0
const IsArm64be = 0
const IsLoong64 = 1
const IsMips = 0
const IsMipsle = 0
const IsMips64 = 0
const IsMips64le = 0
const IsMips64p32 = 0
const IsMips64p32le = 0
const IsPpc = 0
const IsPpc64 = 0
const IsPpc64le = 0
const IsRiscv = 0
const IsRiscv64 = 0
const IsS390 = 0
const IsS390x = 0
const IsSparc = 0
const IsSparc64 = 0
const IsWasm = 0

View File

@@ -0,0 +1,32 @@
// Code generated by gengoarch.go using 'go generate'. DO NOT EDIT.
//go:build mips
package goarch
const GOARCH = `mips`
const Is386 = 0
const IsAmd64 = 0
const IsAmd64p32 = 0
const IsArm = 0
const IsArmbe = 0
const IsArm64 = 0
const IsArm64be = 0
const IsLoong64 = 0
const IsMips = 1
const IsMipsle = 0
const IsMips64 = 0
const IsMips64le = 0
const IsMips64p32 = 0
const IsMips64p32le = 0
const IsPpc = 0
const IsPpc64 = 0
const IsPpc64le = 0
const IsRiscv = 0
const IsRiscv64 = 0
const IsS390 = 0
const IsS390x = 0
const IsSparc = 0
const IsSparc64 = 0
const IsWasm = 0

View File

@@ -0,0 +1,32 @@
// Code generated by gengoarch.go using 'go generate'. DO NOT EDIT.
//go:build mips64
package goarch
const GOARCH = `mips64`
const Is386 = 0
const IsAmd64 = 0
const IsAmd64p32 = 0
const IsArm = 0
const IsArmbe = 0
const IsArm64 = 0
const IsArm64be = 0
const IsLoong64 = 0
const IsMips = 0
const IsMipsle = 0
const IsMips64 = 1
const IsMips64le = 0
const IsMips64p32 = 0
const IsMips64p32le = 0
const IsPpc = 0
const IsPpc64 = 0
const IsPpc64le = 0
const IsRiscv = 0
const IsRiscv64 = 0
const IsS390 = 0
const IsS390x = 0
const IsSparc = 0
const IsSparc64 = 0
const IsWasm = 0

View File

@@ -0,0 +1,32 @@
// Code generated by gengoarch.go using 'go generate'. DO NOT EDIT.
//go:build mips64le
package goarch
const GOARCH = `mips64le`
const Is386 = 0
const IsAmd64 = 0
const IsAmd64p32 = 0
const IsArm = 0
const IsArmbe = 0
const IsArm64 = 0
const IsArm64be = 0
const IsLoong64 = 0
const IsMips = 0
const IsMipsle = 0
const IsMips64 = 0
const IsMips64le = 1
const IsMips64p32 = 0
const IsMips64p32le = 0
const IsPpc = 0
const IsPpc64 = 0
const IsPpc64le = 0
const IsRiscv = 0
const IsRiscv64 = 0
const IsS390 = 0
const IsS390x = 0
const IsSparc = 0
const IsSparc64 = 0
const IsWasm = 0

View File

@@ -0,0 +1,32 @@
// Code generated by gengoarch.go using 'go generate'. DO NOT EDIT.
//go:build mips64p32
package goarch
const GOARCH = `mips64p32`
const Is386 = 0
const IsAmd64 = 0
const IsAmd64p32 = 0
const IsArm = 0
const IsArmbe = 0
const IsArm64 = 0
const IsArm64be = 0
const IsLoong64 = 0
const IsMips = 0
const IsMipsle = 0
const IsMips64 = 0
const IsMips64le = 0
const IsMips64p32 = 1
const IsMips64p32le = 0
const IsPpc = 0
const IsPpc64 = 0
const IsPpc64le = 0
const IsRiscv = 0
const IsRiscv64 = 0
const IsS390 = 0
const IsS390x = 0
const IsSparc = 0
const IsSparc64 = 0
const IsWasm = 0

View File

@@ -0,0 +1,32 @@
// Code generated by gengoarch.go using 'go generate'. DO NOT EDIT.
//go:build mips64p32le
package goarch
const GOARCH = `mips64p32le`
const Is386 = 0
const IsAmd64 = 0
const IsAmd64p32 = 0
const IsArm = 0
const IsArmbe = 0
const IsArm64 = 0
const IsArm64be = 0
const IsLoong64 = 0
const IsMips = 0
const IsMipsle = 0
const IsMips64 = 0
const IsMips64le = 0
const IsMips64p32 = 0
const IsMips64p32le = 1
const IsPpc = 0
const IsPpc64 = 0
const IsPpc64le = 0
const IsRiscv = 0
const IsRiscv64 = 0
const IsS390 = 0
const IsS390x = 0
const IsSparc = 0
const IsSparc64 = 0
const IsWasm = 0

View File

@@ -0,0 +1,32 @@
// Code generated by gengoarch.go using 'go generate'. DO NOT EDIT.
//go:build mipsle
package goarch
const GOARCH = `mipsle`
const Is386 = 0
const IsAmd64 = 0
const IsAmd64p32 = 0
const IsArm = 0
const IsArmbe = 0
const IsArm64 = 0
const IsArm64be = 0
const IsLoong64 = 0
const IsMips = 0
const IsMipsle = 1
const IsMips64 = 0
const IsMips64le = 0
const IsMips64p32 = 0
const IsMips64p32le = 0
const IsPpc = 0
const IsPpc64 = 0
const IsPpc64le = 0
const IsRiscv = 0
const IsRiscv64 = 0
const IsS390 = 0
const IsS390x = 0
const IsSparc = 0
const IsSparc64 = 0
const IsWasm = 0

View File

@@ -0,0 +1,32 @@
// Code generated by gengoarch.go using 'go generate'. DO NOT EDIT.
//go:build ppc
package goarch
const GOARCH = `ppc`
const Is386 = 0
const IsAmd64 = 0
const IsAmd64p32 = 0
const IsArm = 0
const IsArmbe = 0
const IsArm64 = 0
const IsArm64be = 0
const IsLoong64 = 0
const IsMips = 0
const IsMipsle = 0
const IsMips64 = 0
const IsMips64le = 0
const IsMips64p32 = 0
const IsMips64p32le = 0
const IsPpc = 1
const IsPpc64 = 0
const IsPpc64le = 0
const IsRiscv = 0
const IsRiscv64 = 0
const IsS390 = 0
const IsS390x = 0
const IsSparc = 0
const IsSparc64 = 0
const IsWasm = 0

View File

@@ -0,0 +1,32 @@
// Code generated by gengoarch.go using 'go generate'. DO NOT EDIT.
//go:build ppc64
package goarch
const GOARCH = `ppc64`
const Is386 = 0
const IsAmd64 = 0
const IsAmd64p32 = 0
const IsArm = 0
const IsArmbe = 0
const IsArm64 = 0
const IsArm64be = 0
const IsLoong64 = 0
const IsMips = 0
const IsMipsle = 0
const IsMips64 = 0
const IsMips64le = 0
const IsMips64p32 = 0
const IsMips64p32le = 0
const IsPpc = 0
const IsPpc64 = 1
const IsPpc64le = 0
const IsRiscv = 0
const IsRiscv64 = 0
const IsS390 = 0
const IsS390x = 0
const IsSparc = 0
const IsSparc64 = 0
const IsWasm = 0

View File

@@ -0,0 +1,32 @@
// Code generated by gengoarch.go using 'go generate'. DO NOT EDIT.
//go:build ppc64le
package goarch
const GOARCH = `ppc64le`
const Is386 = 0
const IsAmd64 = 0
const IsAmd64p32 = 0
const IsArm = 0
const IsArmbe = 0
const IsArm64 = 0
const IsArm64be = 0
const IsLoong64 = 0
const IsMips = 0
const IsMipsle = 0
const IsMips64 = 0
const IsMips64le = 0
const IsMips64p32 = 0
const IsMips64p32le = 0
const IsPpc = 0
const IsPpc64 = 0
const IsPpc64le = 1
const IsRiscv = 0
const IsRiscv64 = 0
const IsS390 = 0
const IsS390x = 0
const IsSparc = 0
const IsSparc64 = 0
const IsWasm = 0

View File

@@ -0,0 +1,32 @@
// Code generated by gengoarch.go using 'go generate'. DO NOT EDIT.
//go:build riscv
package goarch
const GOARCH = `riscv`
const Is386 = 0
const IsAmd64 = 0
const IsAmd64p32 = 0
const IsArm = 0
const IsArmbe = 0
const IsArm64 = 0
const IsArm64be = 0
const IsLoong64 = 0
const IsMips = 0
const IsMipsle = 0
const IsMips64 = 0
const IsMips64le = 0
const IsMips64p32 = 0
const IsMips64p32le = 0
const IsPpc = 0
const IsPpc64 = 0
const IsPpc64le = 0
const IsRiscv = 1
const IsRiscv64 = 0
const IsS390 = 0
const IsS390x = 0
const IsSparc = 0
const IsSparc64 = 0
const IsWasm = 0

View File

@@ -0,0 +1,32 @@
// Code generated by gengoarch.go using 'go generate'. DO NOT EDIT.
//go:build riscv64
package goarch
const GOARCH = `riscv64`
const Is386 = 0
const IsAmd64 = 0
const IsAmd64p32 = 0
const IsArm = 0
const IsArmbe = 0
const IsArm64 = 0
const IsArm64be = 0
const IsLoong64 = 0
const IsMips = 0
const IsMipsle = 0
const IsMips64 = 0
const IsMips64le = 0
const IsMips64p32 = 0
const IsMips64p32le = 0
const IsPpc = 0
const IsPpc64 = 0
const IsPpc64le = 0
const IsRiscv = 0
const IsRiscv64 = 1
const IsS390 = 0
const IsS390x = 0
const IsSparc = 0
const IsSparc64 = 0
const IsWasm = 0

View File

@@ -0,0 +1,32 @@
// Code generated by gengoarch.go using 'go generate'. DO NOT EDIT.
//go:build s390
package goarch
const GOARCH = `s390`
const Is386 = 0
const IsAmd64 = 0
const IsAmd64p32 = 0
const IsArm = 0
const IsArmbe = 0
const IsArm64 = 0
const IsArm64be = 0
const IsLoong64 = 0
const IsMips = 0
const IsMipsle = 0
const IsMips64 = 0
const IsMips64le = 0
const IsMips64p32 = 0
const IsMips64p32le = 0
const IsPpc = 0
const IsPpc64 = 0
const IsPpc64le = 0
const IsRiscv = 0
const IsRiscv64 = 0
const IsS390 = 1
const IsS390x = 0
const IsSparc = 0
const IsSparc64 = 0
const IsWasm = 0

View File

@@ -0,0 +1,32 @@
// Code generated by gengoarch.go using 'go generate'. DO NOT EDIT.
//go:build s390x
package goarch
const GOARCH = `s390x`
const Is386 = 0
const IsAmd64 = 0
const IsAmd64p32 = 0
const IsArm = 0
const IsArmbe = 0
const IsArm64 = 0
const IsArm64be = 0
const IsLoong64 = 0
const IsMips = 0
const IsMipsle = 0
const IsMips64 = 0
const IsMips64le = 0
const IsMips64p32 = 0
const IsMips64p32le = 0
const IsPpc = 0
const IsPpc64 = 0
const IsPpc64le = 0
const IsRiscv = 0
const IsRiscv64 = 0
const IsS390 = 0
const IsS390x = 1
const IsSparc = 0
const IsSparc64 = 0
const IsWasm = 0

View File

@@ -0,0 +1,32 @@
// Code generated by gengoarch.go using 'go generate'. DO NOT EDIT.
//go:build sparc
package goarch
const GOARCH = `sparc`
const Is386 = 0
const IsAmd64 = 0
const IsAmd64p32 = 0
const IsArm = 0
const IsArmbe = 0
const IsArm64 = 0
const IsArm64be = 0
const IsLoong64 = 0
const IsMips = 0
const IsMipsle = 0
const IsMips64 = 0
const IsMips64le = 0
const IsMips64p32 = 0
const IsMips64p32le = 0
const IsPpc = 0
const IsPpc64 = 0
const IsPpc64le = 0
const IsRiscv = 0
const IsRiscv64 = 0
const IsS390 = 0
const IsS390x = 0
const IsSparc = 1
const IsSparc64 = 0
const IsWasm = 0

View File

@@ -0,0 +1,32 @@
// Code generated by gengoarch.go using 'go generate'. DO NOT EDIT.
//go:build sparc64
package goarch
const GOARCH = `sparc64`
const Is386 = 0
const IsAmd64 = 0
const IsAmd64p32 = 0
const IsArm = 0
const IsArmbe = 0
const IsArm64 = 0
const IsArm64be = 0
const IsLoong64 = 0
const IsMips = 0
const IsMipsle = 0
const IsMips64 = 0
const IsMips64le = 0
const IsMips64p32 = 0
const IsMips64p32le = 0
const IsPpc = 0
const IsPpc64 = 0
const IsPpc64le = 0
const IsRiscv = 0
const IsRiscv64 = 0
const IsS390 = 0
const IsS390x = 0
const IsSparc = 0
const IsSparc64 = 1
const IsWasm = 0

View File

@@ -0,0 +1,32 @@
// Code generated by gengoarch.go using 'go generate'. DO NOT EDIT.
//go:build wasm
package goarch
const GOARCH = `wasm`
const Is386 = 0
const IsAmd64 = 0
const IsAmd64p32 = 0
const IsArm = 0
const IsArmbe = 0
const IsArm64 = 0
const IsArm64be = 0
const IsLoong64 = 0
const IsMips = 0
const IsMipsle = 0
const IsMips64 = 0
const IsMips64le = 0
const IsMips64p32 = 0
const IsMips64p32le = 0
const IsPpc = 0
const IsPpc64 = 0
const IsPpc64le = 0
const IsRiscv = 0
const IsRiscv64 = 0
const IsS390 = 0
const IsS390x = 0
const IsSparc = 0
const IsSparc64 = 0
const IsWasm = 1

View File

@@ -7,15 +7,17 @@
// These types are defined here to permit the syscall package to reference them.
package oserror
import "errors"
import (
"github.com/goplus/llgo/runtime/internal/clite/syscall"
)
// llgo:skipall
type _oserror struct{}
var (
ErrInvalid = errors.New("invalid argument")
ErrPermission = errors.New("permission denied")
ErrExist = errors.New("file already exists")
ErrNotExist = errors.New("file does not exist")
ErrClosed = errors.New("file already closed")
ErrInvalid = syscall.ErrInvalid
ErrPermission = syscall.ErrPermission
ErrExist = syscall.ErrExist
ErrNotExist = syscall.ErrNotExist
ErrClosed = syscall.ErrClosed
)

View File

@@ -0,0 +1,19 @@
package atomic
import (
"unsafe"
"github.com/goplus/llgo/runtime/internal/lib/sync/atomic"
)
func casPointer(ptr *unsafe.Pointer, old, new unsafe.Pointer) bool {
return atomic.CompareAndSwapPointer(ptr, old, new)
}
func storePointer(ptr *unsafe.Pointer, new unsafe.Pointer) {
atomic.StorePointer(ptr, new)
}
func StorepNoWB(ptr unsafe.Pointer, val unsafe.Pointer) {
atomic.StorePointer((*unsafe.Pointer)(ptr), val)
}

View File

@@ -0,0 +1,50 @@
package maps
import (
"unsafe"
"github.com/goplus/llgo/runtime/abi"
)
func rand() uint64 {
panic("not implemented")
}
func fatal(s string) {
panic("fatal: " + s)
}
type Type = abi.Type
type SwissMapType struct {
Type
Key *Type
Elem *Type
Group *Type // internal type representing a slot group
// function for hashing keys (ptr to key, seed) -> hash
Hasher func(unsafe.Pointer, uintptr) uintptr
GroupSize uintptr // == Group.Size_
SlotSize uintptr // size of key/elem slot
ElemOff uintptr // offset of elem in key/elem slot
Flags uint32
}
func mapKeyError(typ *SwissMapType, p unsafe.Pointer) error {
return nil
}
func typedmemmove(typ *abi.Type, dst, src unsafe.Pointer) {
panic("not implemented")
}
func typedmemclr(typ *abi.Type, ptr unsafe.Pointer) {
panic("not implemented")
}
func newobject(typ *abi.Type) unsafe.Pointer {
panic("not implemented")
}
func newarray(typ *abi.Type, n int) unsafe.Pointer {
panic("not implemented")
}

View File

@@ -0,0 +1,5 @@
package sys
func GetCallerPC() uintptr {
panic("not implemented")
}

View File

@@ -0,0 +1,29 @@
package sync
func runtime_canSpin(i int) bool {
panic("not implemented")
}
func runtime_doSpin() {
panic("not implemented")
}
func throw(string) {
panic("not implemented")
}
func fatal(string) {
panic("not implemented")
}
func runtime_nanotime() int64 {
panic("not implemented")
}
func runtime_SemacquireMutex(s *uint32, lifo bool, skipframes int) {
panic("not implemented")
}
func runtime_Semrelease(s *uint32, handoff bool, skipframes int) {
panic("not implemented")
}

View File

@@ -0,0 +1,21 @@
// Copyright 2018 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build unix
package unix
import "syscall"
func IsNonblock(fd int) (nonblocking bool, err error) {
flag, e1 := Fcntl(fd, syscall.F_GETFL, 0)
if e1 != nil {
return false, e1
}
return flag&syscall.O_NONBLOCK != 0, nil
}
func HasNonblockFlag(flag int) bool {
return flag&syscall.O_NONBLOCK != 0
}

View File

@@ -0,0 +1,17 @@
// Copyright 2023 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package unix
import (
_ "unsafe" // for go:linkname
)
func IsNonblock(fd int) (nonblocking bool, err error) {
panic("not implemented")
}
func HasNonblockFlag(flag int) bool {
panic("not implemented")
}

View File

@@ -17,10 +17,8 @@
package unix
import (
"syscall"
_ "unsafe"
)
func HasNonblockFlag(flag int) bool {
return flag&syscall.O_NONBLOCK != 0
}
// llgo:skip path_filestat_get path_create_directory path_readlink path_unlink_file path_remove_directory Fstatat Mkdirat Readlinkat Unlinkat
type _unix struct{}