summaryrefslogtreecommitdiffstats
path: root/src/runtime/sys_wasm.s
blob: 164dd16ec9ff13a88a0abbf59bbc4e7803d0aca6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
// 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.

#include "textflag.h"

TEXT runtime·wasmMove(SB), NOSPLIT, $0-0
loop:
	Loop
		// *dst = *src
		Get R0
		Get R1
		I64Load $0
		I64Store $0

		// n--
		Get R2
		I32Const $1
		I32Sub
		Tee R2

		// n == 0
		I32Eqz
		If
			Return
		End

		// dst += 8
		Get R0
		I32Const $8
		I32Add
		Set R0

		// src += 8
		Get R1
		I32Const $8
		I32Add
		Set R1

		Br loop
	End
	UNDEF

TEXT runtime·wasmZero(SB), NOSPLIT, $0-0
loop:
	Loop
		// *dst = 0
		Get R0
		I64Const $0
		I64Store $0

		// n--
		Get R1
		I32Const $1
		I32Sub
		Tee R1

		// n == 0
		I32Eqz
		If
			Return
		End

		// dst += 8
		Get R0
		I32Const $8
		I32Add
		Set R0

		Br loop
	End
	UNDEF

TEXT runtime·wasmDiv(SB), NOSPLIT, $0-0
	Get R0
	I64Const $-0x8000000000000000
	I64Eq
	If
		Get R1
		I64Const $-1
		I64Eq
		If
			I64Const $-0x8000000000000000
			Return
		End
	End
	Get R0
	Get R1
	I64DivS
	Return

TEXT runtime·wasmTruncS(SB), NOSPLIT, $0-0
	Get R0
	Get R0
	F64Ne // NaN
	If
		I64Const $0x8000000000000000
		Return
	End

	Get R0
	F64Const $0x7ffffffffffffc00p0 // Maximum truncated representation of 0x7fffffffffffffff
	F64Gt
	If
		I64Const $0x8000000000000000
		Return
	End

	Get R0
	F64Const $-0x7ffffffffffffc00p0 // Minimum truncated representation of -0x8000000000000000
	F64Lt
	If
		I64Const $0x8000000000000000
		Return
	End

	Get R0
	I64TruncF64S
	Return

TEXT runtime·wasmTruncU(SB), NOSPLIT, $0-0
	Get R0
	Get R0
	F64Ne // NaN
	If
		I64Const $0x8000000000000000
		Return
	End

	Get R0
	F64Const $0xfffffffffffff800p0 // Maximum truncated representation of 0xffffffffffffffff
	F64Gt
	If
		I64Const $0x8000000000000000
		Return
	End

	Get R0
	F64Const $0.
	F64Lt
	If
		I64Const $0x8000000000000000
		Return
	End

	Get R0
	I64TruncF64U
	Return

TEXT runtime·exitThread(SB), NOSPLIT, $0-0
	UNDEF

TEXT runtime·osyield(SB), NOSPLIT, $0-0
	UNDEF

TEXT runtime·usleep(SB), NOSPLIT, $0-0
	RET // TODO(neelance): implement usleep

TEXT runtime·currentMemory(SB), NOSPLIT, $0
	Get SP
	CurrentMemory
	I32Store ret+0(FP)
	RET

TEXT runtime·growMemory(SB), NOSPLIT, $0
	Get SP
	I32Load pages+0(FP)
	GrowMemory
	I32Store ret+8(FP)
	RET

TEXT ·resetMemoryDataView(SB), NOSPLIT, $0
	CallImport
	RET

TEXT ·wasmExit(SB), NOSPLIT, $0
	CallImport
	RET

TEXT ·wasmWrite(SB), NOSPLIT, $0
	CallImport
	RET

TEXT ·nanotime1(SB), NOSPLIT, $0
	CallImport
	RET

TEXT ·walltime(SB), NOSPLIT, $0
	CallImport
	RET

TEXT ·scheduleTimeoutEvent(SB), NOSPLIT, $0
	CallImport
	RET

TEXT ·clearTimeoutEvent(SB), NOSPLIT, $0
	CallImport
	RET

TEXT ·getRandomData(SB), NOSPLIT, $0
	CallImport
	RET