blob: 2376ab92ba1635ac364399e3101d667e20b46cd5 [file] [log] [blame]
Russ Cox0d3a0432009-03-30 00:01:07 -07001// Copyright 2009 The Go Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
3// license that can be found in the LICENSE file.
4
Russ Cox55889402011-12-19 15:51:13 -05005#include "zasm_GOOS_GOARCH.h"
Russ Cox9ddfb642013-07-16 16:24:09 -04006#include "funcdata.h"
Russ Coxcb040d52014-09-04 23:05:18 -04007#include "textflag.h"
Russ Cox8522a472009-06-17 15:15:55 -07008
Russ Cox7ba41e92014-09-03 11:11:16 -04009TEXT runtime·rt0_go(SB),NOSPLIT,$0
Russ Cox0d3a0432009-03-30 00:01:07 -070010 // copy arguments forward on an even stack
Russ Coxdfc22e292013-03-07 19:57:10 -080011 MOVL argc+0(FP), AX
12 MOVL argv+4(FP), BX
Russ Cox0d3a0432009-03-30 00:01:07 -070013 SUBL $128, SP // plenty of scratch
Russ Cox133a1582009-10-03 10:37:12 -070014 ANDL $~15, SP
Russ Cox0d3a0432009-03-30 00:01:07 -070015 MOVL AX, 120(SP) // save argc, argv away
16 MOVL BX, 124(SP)
17
Dmitriy Vyukov428062d2011-12-07 16:53:17 +030018 // set default stack bounds.
Russ Coxf8d49b52013-02-28 16:24:38 -050019 // _cgo_init may update stackguard.
Dmitriy Vyukov428062d2011-12-07 16:53:17 +030020 MOVL $runtime·g0(SB), BP
21 LEAL (-64*1024+104)(SP), BX
Dmitriy Vyukovf5becf42013-06-03 12:28:24 +040022 MOVL BX, g_stackguard0(BP)
Russ Cox15b76ad2014-09-09 13:39:57 -040023 MOVL BX, g_stackguard1(BP)
24 MOVL BX, (g_stack+stack_lo)(BP)
25 MOVL SP, (g_stack+stack_hi)(BP)
Dmitriy Vyukov428062d2011-12-07 16:53:17 +030026
Keith Randalla5d40242013-03-12 10:47:44 -070027 // find out information about the processor we're on
28 MOVL $0, AX
29 CPUID
30 CMPL AX, $0
31 JE nocpuinfo
32 MOVL $1, AX
33 CPUID
34 MOVL CX, runtime·cpuid_ecx(SB)
35 MOVL DX, runtime·cpuid_edx(SB)
36nocpuinfo:
37
Russ Coxf8d49b52013-02-28 16:24:38 -050038 // if there is an _cgo_init, call it to let it
Russ Cox133a1582009-10-03 10:37:12 -070039 // initialize and to set up GS. if not,
40 // we set up GS ourselves.
Russ Coxf8d49b52013-02-28 16:24:38 -050041 MOVL _cgo_init(SB), AX
Russ Cox133a1582009-10-03 10:37:12 -070042 TESTL AX, AX
Dmitriy Vyukovfbfed492011-11-09 23:11:48 +030043 JZ needtls
Russ Cox89f185f2014-06-26 11:54:39 -040044 MOVL $setg_gcc<>(SB), BX
Russ Cox6a70f9d2013-03-25 18:14:02 -040045 MOVL BX, 4(SP)
Russ Cox3b85b722013-03-11 00:51:42 -040046 MOVL BP, 0(SP)
Russ Cox133a1582009-10-03 10:37:12 -070047 CALL AX
Russ Cox15b76ad2014-09-09 13:39:57 -040048
Dmitriy Vyukovf5becf42013-06-03 12:28:24 +040049 // update stackguard after _cgo_init
50 MOVL $runtime·g0(SB), CX
Russ Cox15b76ad2014-09-09 13:39:57 -040051 MOVL (g_stack+stack_lo)(CX), AX
52 ADDL $const_StackGuard, AX
53 MOVL AX, g_stackguard0(CX)
54 MOVL AX, g_stackguard1(CX)
55
Russ Coxf8d49b52013-02-28 16:24:38 -050056 // skip runtime·ldt0setup(SB) and tls test after _cgo_init for non-windows
Wei Guangjing1aa2d882011-01-20 10:22:20 -050057 CMPL runtime·iswindows(SB), $0
58 JEQ ok
Dmitriy Vyukovfbfed492011-11-09 23:11:48 +030059needtls:
Yuval Pavel Zholkover2aa2ceb2011-07-25 12:25:41 -040060 // skip runtime·ldt0setup(SB) and tls test on Plan 9 in all cases
61 CMPL runtime·isplan9(SB), $1
62 JEQ ok
63
Russ Cox1b14bdb2009-09-22 16:28:32 -070064 // set up %gs
Russ Cox68b42552010-11-04 14:00:19 -040065 CALL runtime·ldt0setup(SB)
Russ Cox0d3a0432009-03-30 00:01:07 -070066
Russ Cox0d3a0432009-03-30 00:01:07 -070067 // store through it, to make sure it works
Hector Chu6bfe5f52010-01-06 17:58:55 -080068 get_tls(BX)
69 MOVL $0x123, g(BX)
Russ Cox68b42552010-11-04 14:00:19 -040070 MOVL runtime·tls0(SB), AX
Russ Cox0d3a0432009-03-30 00:01:07 -070071 CMPL AX, $0x123
72 JEQ ok
Russ Cox133a1582009-10-03 10:37:12 -070073 MOVL AX, 0 // abort
Russ Cox0d3a0432009-03-30 00:01:07 -070074ok:
Russ Cox0d3a0432009-03-30 00:01:07 -070075 // set up m and g "registers"
Hector Chu6bfe5f52010-01-06 17:58:55 -080076 get_tls(BX)
Russ Cox68b42552010-11-04 14:00:19 -040077 LEAL runtime·g0(SB), CX
Hector Chu6bfe5f52010-01-06 17:58:55 -080078 MOVL CX, g(BX)
Russ Cox68b42552010-11-04 14:00:19 -040079 LEAL runtime·m0(SB), AX
Russ Cox0d3a0432009-03-30 00:01:07 -070080
81 // save m->g0 = g0
Russ Cox8522a472009-06-17 15:15:55 -070082 MOVL CX, m_g0(AX)
Russ Cox89f185f2014-06-26 11:54:39 -040083 // save g0->m = m0
84 MOVL AX, g_m(CX)
Russ Cox0d3a0432009-03-30 00:01:07 -070085
Russ Cox68b42552010-11-04 14:00:19 -040086 CALL runtime·emptyfunc(SB) // fault if stack check is wrong
Russ Cox0d3a0432009-03-30 00:01:07 -070087
88 // convention is D is always cleared
89 CLD
90
Russ Cox68b42552010-11-04 14:00:19 -040091 CALL runtime·check(SB)
Russ Cox0d3a0432009-03-30 00:01:07 -070092
93 // saved argc, argv
94 MOVL 120(SP), AX
95 MOVL AX, 0(SP)
96 MOVL 124(SP), AX
97 MOVL AX, 4(SP)
Russ Cox68b42552010-11-04 14:00:19 -040098 CALL runtime·args(SB)
99 CALL runtime·osinit(SB)
100 CALL runtime·schedinit(SB)
Russ Cox0d3a0432009-03-30 00:01:07 -0700101
102 // create a new goroutine to start program
Russ Cox1903ad72013-02-21 17:01:13 -0500103 PUSHL $runtime·main·f(SB) // entry
Russ Cox8522a472009-06-17 15:15:55 -0700104 PUSHL $0 // arg size
Russ Cox9ddfb642013-07-16 16:24:09 -0400105 ARGSIZE(8)
Russ Cox68b42552010-11-04 14:00:19 -0400106 CALL runtime·newproc(SB)
Russ Cox9ddfb642013-07-16 16:24:09 -0400107 ARGSIZE(-1)
Russ Cox0d3a0432009-03-30 00:01:07 -0700108 POPL AX
109 POPL AX
110
111 // start this M
Russ Cox68b42552010-11-04 14:00:19 -0400112 CALL runtime·mstart(SB)
Russ Cox0d3a0432009-03-30 00:01:07 -0700113
114 INT $3
115 RET
116
Russ Cox1903ad72013-02-21 17:01:13 -0500117DATA runtime·main·f+0(SB)/4,$runtime·main(SB)
Keith Randall5a546962013-08-07 10:23:24 -0700118GLOBL runtime·main·f(SB),RODATA,$4
Russ Cox1903ad72013-02-21 17:01:13 -0500119
Keith Randall5a546962013-08-07 10:23:24 -0700120TEXT runtime·breakpoint(SB),NOSPLIT,$0-0
Russ Cox1b14bdb2009-09-22 16:28:32 -0700121 INT $3
Russ Cox0d3a0432009-03-30 00:01:07 -0700122 RET
123
Keith Randall5a546962013-08-07 10:23:24 -0700124TEXT runtime·asminit(SB),NOSPLIT,$0-0
Carl Shapiro019c8fc2013-04-02 13:45:56 -0700125 // Linux and MinGW start the FPU in extended double precision.
Russ Cox1707a992012-02-14 01:23:15 -0500126 // Other operating systems use double precision.
127 // Change to double precision to match them,
128 // and to match other hardware that only has double.
129 PUSHL $0x27F
130 FLDCW 0(SP)
131 POPL AX
132 RET
133
Russ Cox8522a472009-06-17 15:15:55 -0700134/*
135 * go-routine
136 */
Russ Cox0d3a0432009-03-30 00:01:07 -0700137
Russ Coxf9ca3b52011-03-07 10:37:42 -0500138// void gosave(Gobuf*)
Russ Cox8522a472009-06-17 15:15:55 -0700139// save state in Gobuf; setjmp
Keith Randall5a546962013-08-07 10:23:24 -0700140TEXT runtime·gosave(SB), NOSPLIT, $0-4
Russ Cox25f6b022014-08-27 11:32:17 -0400141 MOVL buf+0(FP), AX // gobuf
142 LEAL buf+0(FP), BX // caller's SP
Russ Cox8522a472009-06-17 15:15:55 -0700143 MOVL BX, gobuf_sp(AX)
144 MOVL 0(SP), BX // caller's PC
145 MOVL BX, gobuf_pc(AX)
Russ Coxd67e7e32013-06-12 15:22:26 -0400146 MOVL $0, gobuf_ret(AX)
147 MOVL $0, gobuf_ctxt(AX)
Hector Chu6bfe5f52010-01-06 17:58:55 -0800148 get_tls(CX)
149 MOVL g(CX), BX
Russ Cox8522a472009-06-17 15:15:55 -0700150 MOVL BX, gobuf_g(AX)
Russ Cox0d3a0432009-03-30 00:01:07 -0700151 RET
152
Ian Lance Taylor06272482013-06-12 15:05:10 -0700153// void gogo(Gobuf*)
Russ Cox8522a472009-06-17 15:15:55 -0700154// restore state from Gobuf; longjmp
Keith Randall5a546962013-08-07 10:23:24 -0700155TEXT runtime·gogo(SB), NOSPLIT, $0-4
Russ Cox25f6b022014-08-27 11:32:17 -0400156 MOVL buf+0(FP), BX // gobuf
Russ Cox8522a472009-06-17 15:15:55 -0700157 MOVL gobuf_g(BX), DX
158 MOVL 0(DX), CX // make sure g != nil
Hector Chu6bfe5f52010-01-06 17:58:55 -0800159 get_tls(CX)
160 MOVL DX, g(CX)
Russ Cox8522a472009-06-17 15:15:55 -0700161 MOVL gobuf_sp(BX), SP // restore SP
Russ Coxd67e7e32013-06-12 15:22:26 -0400162 MOVL gobuf_ret(BX), AX
163 MOVL gobuf_ctxt(BX), DX
164 MOVL $0, gobuf_sp(BX) // clear to help garbage collector
165 MOVL $0, gobuf_ret(BX)
166 MOVL $0, gobuf_ctxt(BX)
Russ Cox8522a472009-06-17 15:15:55 -0700167 MOVL gobuf_pc(BX), BX
Russ Cox0d3a0432009-03-30 00:01:07 -0700168 JMP BX
Russ Cox8522a472009-06-17 15:15:55 -0700169
Russ Cox012ceed2014-09-03 11:35:22 -0400170// func mcall(fn func(*g))
Russ Coxf9ca3b52011-03-07 10:37:42 -0500171// Switch to m->g0's stack, call fn(g).
Russ Cox370276a2011-04-27 23:21:12 -0400172// Fn must never return. It should gogo(&g->sched)
Russ Coxf9ca3b52011-03-07 10:37:42 -0500173// to keep running g.
Keith Randall5a546962013-08-07 10:23:24 -0700174TEXT runtime·mcall(SB), NOSPLIT, $0-4
Russ Coxf9ca3b52011-03-07 10:37:42 -0500175 MOVL fn+0(FP), DI
176
177 get_tls(CX)
Russ Cox528534c2013-06-05 07:16:53 -0400178 MOVL g(CX), AX // save state in g->sched
Russ Coxf9ca3b52011-03-07 10:37:42 -0500179 MOVL 0(SP), BX // caller's PC
180 MOVL BX, (g_sched+gobuf_pc)(AX)
Russ Cox25f6b022014-08-27 11:32:17 -0400181 LEAL fn+0(FP), BX // caller's SP
Russ Coxf9ca3b52011-03-07 10:37:42 -0500182 MOVL BX, (g_sched+gobuf_sp)(AX)
183 MOVL AX, (g_sched+gobuf_g)(AX)
184
185 // switch to m->g0 & its stack, call fn
Russ Cox89f185f2014-06-26 11:54:39 -0400186 MOVL g(CX), BX
187 MOVL g_m(BX), BX
Russ Coxf9ca3b52011-03-07 10:37:42 -0500188 MOVL m_g0(BX), SI
189 CMPL SI, AX // if g == m->g0 call badmcall
Keith Randall32b770b2013-08-29 15:53:34 -0700190 JNE 3(PC)
191 MOVL $runtime·badmcall(SB), AX
192 JMP AX
Russ Coxf9ca3b52011-03-07 10:37:42 -0500193 MOVL SI, g(CX) // g = m->g0
Russ Cox528534c2013-06-05 07:16:53 -0400194 MOVL (g_sched+gobuf_sp)(SI), SP // sp = m->g0->sched.sp
Russ Coxf9ca3b52011-03-07 10:37:42 -0500195 PUSHL AX
Russ Cox012ceed2014-09-03 11:35:22 -0400196 MOVL DI, DX
197 MOVL 0(DI), DI
Russ Coxf9ca3b52011-03-07 10:37:42 -0500198 CALL DI
199 POPL AX
Keith Randall32b770b2013-08-29 15:53:34 -0700200 MOVL $runtime·badmcall2(SB), AX
201 JMP AX
Russ Coxf9ca3b52011-03-07 10:37:42 -0500202 RET
203
Keith Randall4aa50432014-07-30 09:01:52 -0700204// switchtoM is a dummy routine that onM leaves at the bottom
205// of the G stack. We need to distinguish the routine that
206// lives at the bottom of the G stack from the one that lives
207// at the top of the M stack because the one at the top of
208// the M stack terminates the stack walk (see topofstack()).
209TEXT runtime·switchtoM(SB), NOSPLIT, $0-4
210 RET
211
Russ Cox012ceed2014-09-03 11:35:22 -0400212// func onM(fn func())
Keith Randall4aa50432014-07-30 09:01:52 -0700213TEXT runtime·onM(SB), NOSPLIT, $0-4
214 MOVL fn+0(FP), DI // DI = fn
215 get_tls(CX)
216 MOVL g(CX), AX // AX = g
217 MOVL g_m(AX), BX // BX = m
Russ Cox32ecf572014-09-04 00:10:10 -0400218
Keith Randall4aa50432014-07-30 09:01:52 -0700219 MOVL m_g0(BX), DX // DX = g0
220 CMPL AX, DX
221 JEQ onm
222
Russ Cox32ecf572014-09-04 00:10:10 -0400223 MOVL m_curg(BX), BP
224 CMPL AX, BP
225 JEQ oncurg
226
227 // Not g0, not curg. Must be gsignal, but that's not allowed.
228 // Hide call from linker nosplit analysis.
229 MOVL $runtime·badonm(SB), AX
230 CALL AX
231
232oncurg:
Keith Randall4aa50432014-07-30 09:01:52 -0700233 // save our state in g->sched. Pretend to
234 // be switchtoM if the G stack is scanned.
235 MOVL $runtime·switchtoM(SB), (g_sched+gobuf_pc)(AX)
236 MOVL SP, (g_sched+gobuf_sp)(AX)
237 MOVL AX, (g_sched+gobuf_g)(AX)
238
239 // switch to g0
240 MOVL DX, g(CX)
Russ Coxd16a2ad2014-09-04 22:48:08 -0400241 MOVL (g_sched+gobuf_sp)(DX), BX
242 // make it look like mstart called onM on g0, to stop traceback
243 SUBL $4, BX
244 MOVL $runtime·mstart(SB), DX
245 MOVL DX, 0(BX)
246 MOVL BX, SP
Keith Randall4aa50432014-07-30 09:01:52 -0700247
248 // call target function
249 ARGSIZE(0)
Russ Cox012ceed2014-09-03 11:35:22 -0400250 MOVL DI, DX
251 MOVL 0(DI), DI
Keith Randall4aa50432014-07-30 09:01:52 -0700252 CALL DI
253
254 // switch back to g
255 get_tls(CX)
256 MOVL g(CX), AX
257 MOVL g_m(AX), BX
258 MOVL m_curg(BX), AX
259 MOVL AX, g(CX)
260 MOVL (g_sched+gobuf_sp)(AX), SP
261 MOVL $0, (g_sched+gobuf_sp)(AX)
262 RET
263
264onm:
265 // already on m stack, just call directly
Russ Cox012ceed2014-09-03 11:35:22 -0400266 MOVL DI, DX
267 MOVL 0(DI), DI
Keith Randall4aa50432014-07-30 09:01:52 -0700268 CALL DI
269 RET
270
Russ Cox8522a472009-06-17 15:15:55 -0700271/*
272 * support for morestack
273 */
274
275// Called during function prolog when more stack is needed.
Russ Cox58f12ff2013-07-18 16:53:45 -0400276//
277// The traceback routines see morestack on a g0 as being
278// the top of a stack (for example, morestack calling newstack
279// calling the scheduler calling newm calling gc), so we must
280// record an argument size. For that purpose, it has no arguments.
Keith Randall5a546962013-08-07 10:23:24 -0700281TEXT runtime·morestack(SB),NOSPLIT,$0-0
Russ Cox8522a472009-06-17 15:15:55 -0700282 // Cannot grow scheduler stack (m->g0).
Hector Chu6bfe5f52010-01-06 17:58:55 -0800283 get_tls(CX)
Russ Cox89f185f2014-06-26 11:54:39 -0400284 MOVL g(CX), BX
285 MOVL g_m(BX), BX
Russ Cox8522a472009-06-17 15:15:55 -0700286 MOVL m_g0(BX), SI
Hector Chu6bfe5f52010-01-06 17:58:55 -0800287 CMPL g(CX), SI
Russ Cox8522a472009-06-17 15:15:55 -0700288 JNE 2(PC)
289 INT $3
290
Russ Coxf8f630f2014-09-05 16:51:45 -0400291 // Cannot grow signal stack.
292 MOVL m_gsignal(BX), SI
293 CMPL g(CX), SI
294 JNE 2(PC)
295 INT $3
296
Russ Cox8522a472009-06-17 15:15:55 -0700297 // Called from f.
298 // Set m->morebuf to f's caller.
299 MOVL 4(SP), DI // f's caller's PC
300 MOVL DI, (m_morebuf+gobuf_pc)(BX)
301 LEAL 8(SP), CX // f's caller's SP
302 MOVL CX, (m_morebuf+gobuf_sp)(BX)
Hector Chu6bfe5f52010-01-06 17:58:55 -0800303 get_tls(CX)
304 MOVL g(CX), SI
Russ Cox8522a472009-06-17 15:15:55 -0700305 MOVL SI, (m_morebuf+gobuf_g)(BX)
306
Russ Cox6fa3c892013-06-27 11:32:01 -0400307 // Set g->sched to context in f.
308 MOVL 0(SP), AX // f's PC
309 MOVL AX, (g_sched+gobuf_pc)(SI)
310 MOVL SI, (g_sched+gobuf_g)(SI)
311 LEAL 4(SP), AX // f's SP
312 MOVL AX, (g_sched+gobuf_sp)(SI)
313 MOVL DX, (g_sched+gobuf_ctxt)(SI)
Russ Cox8522a472009-06-17 15:15:55 -0700314
Russ Coxf9ca3b52011-03-07 10:37:42 -0500315 // Call newstack on m->g0's stack.
Russ Cox8522a472009-06-17 15:15:55 -0700316 MOVL m_g0(BX), BP
Hector Chu6bfe5f52010-01-06 17:58:55 -0800317 MOVL BP, g(CX)
Russ Coxf9ca3b52011-03-07 10:37:42 -0500318 MOVL (g_sched+gobuf_sp)(BP), AX
Russ Cox7e14bd82010-12-07 17:19:36 -0500319 MOVL -4(AX), BX // fault if CALL would, before smashing SP
320 MOVL AX, SP
Russ Cox68b42552010-11-04 14:00:19 -0400321 CALL runtime·newstack(SB)
Russ Cox8522a472009-06-17 15:15:55 -0700322 MOVL $0, 0x1003 // crash if newstack returns
Russ Cox0d3a0432009-03-30 00:01:07 -0700323 RET
324
Russ Coxc2dd33a2014-03-04 13:53:08 -0500325TEXT runtime·morestack_noctxt(SB),NOSPLIT,$0-0
326 MOVL $0, DX
327 JMP runtime·morestack(SB)
328
Keith Randall52631982014-09-08 10:14:41 -0700329// reflectcall: call a function with the given argument list
Russ Cox84736952014-09-06 13:19:08 -0400330// func call(f *FuncVal, arg *byte, argsize, retoffset uint32).
Keith Randall9cd57062013-08-02 13:03:14 -0700331// we don't have variable-sized frames, so we use a small number
332// of constant-sized-frame functions to encode a few bits of size in the pc.
333// Caution: ugly multiline assembly macros in your future!
334
335#define DISPATCH(NAME,MAXSIZE) \
336 CMPL CX, $MAXSIZE; \
337 JA 3(PC); \
Russ Coxf8f630f2014-09-05 16:51:45 -0400338 MOVL $NAME(SB), AX; \
Keith Randall9cd57062013-08-02 13:03:14 -0700339 JMP AX
Rob Pikeaff78832014-07-30 10:11:44 -0700340// Note: can't just "JMP NAME(SB)" - bad inlining results.
Keith Randall9cd57062013-08-02 13:03:14 -0700341
Keith Randall52631982014-09-08 10:14:41 -0700342TEXT runtime·reflectcall(SB), NOSPLIT, $0-16
Keith Randall9cd57062013-08-02 13:03:14 -0700343 MOVL argsize+8(FP), CX
Rob Pikeaff78832014-07-30 10:11:44 -0700344 DISPATCH(runtime·call16, 16)
345 DISPATCH(runtime·call32, 32)
346 DISPATCH(runtime·call64, 64)
347 DISPATCH(runtime·call128, 128)
348 DISPATCH(runtime·call256, 256)
349 DISPATCH(runtime·call512, 512)
350 DISPATCH(runtime·call1024, 1024)
351 DISPATCH(runtime·call2048, 2048)
352 DISPATCH(runtime·call4096, 4096)
353 DISPATCH(runtime·call8192, 8192)
354 DISPATCH(runtime·call16384, 16384)
355 DISPATCH(runtime·call32768, 32768)
356 DISPATCH(runtime·call65536, 65536)
357 DISPATCH(runtime·call131072, 131072)
358 DISPATCH(runtime·call262144, 262144)
359 DISPATCH(runtime·call524288, 524288)
360 DISPATCH(runtime·call1048576, 1048576)
361 DISPATCH(runtime·call2097152, 2097152)
362 DISPATCH(runtime·call4194304, 4194304)
363 DISPATCH(runtime·call8388608, 8388608)
364 DISPATCH(runtime·call16777216, 16777216)
365 DISPATCH(runtime·call33554432, 33554432)
366 DISPATCH(runtime·call67108864, 67108864)
367 DISPATCH(runtime·call134217728, 134217728)
368 DISPATCH(runtime·call268435456, 268435456)
369 DISPATCH(runtime·call536870912, 536870912)
370 DISPATCH(runtime·call1073741824, 1073741824)
Keith Randall9cd57062013-08-02 13:03:14 -0700371 MOVL $runtime·badreflectcall(SB), AX
372 JMP AX
373
Russ Coxf8f630f2014-09-05 16:51:45 -0400374// Argument map for the callXX frames. Each has one stack map.
Keith Randallcee8bca2014-05-21 14:28:34 -0700375DATA gcargs_reflectcall<>+0x00(SB)/4, $1 // 1 stackmap
Russ Cox84736952014-09-06 13:19:08 -0400376DATA gcargs_reflectcall<>+0x04(SB)/4, $8 // 4 words
Russ Coxf8f630f2014-09-05 16:51:45 -0400377DATA gcargs_reflectcall<>+0x08(SB)/1, $(const_BitsPointer+(const_BitsPointer<<2)+(const_BitsScalar<<4)+(const_BitsScalar<<6))
Keith Randallcee8bca2014-05-21 14:28:34 -0700378GLOBL gcargs_reflectcall<>(SB),RODATA,$12
379
380// callXX frames have no locals
381DATA gclocals_reflectcall<>+0x00(SB)/4, $1 // 1 stackmap
382DATA gclocals_reflectcall<>+0x04(SB)/4, $0 // 0 locals
383GLOBL gclocals_reflectcall<>(SB),RODATA,$8
384
Keith Randall12e46e42013-08-06 14:33:55 -0700385#define CALLFN(NAME,MAXSIZE) \
Russ Cox84736952014-09-06 13:19:08 -0400386TEXT NAME(SB), WRAPPER, $MAXSIZE-16; \
Keith Randallcee8bca2014-05-21 14:28:34 -0700387 FUNCDATA $FUNCDATA_ArgsPointerMaps,gcargs_reflectcall<>(SB); \
388 FUNCDATA $FUNCDATA_LocalsPointerMaps,gclocals_reflectcall<>(SB);\
Keith Randall9cd57062013-08-02 13:03:14 -0700389 /* copy arguments to stack */ \
390 MOVL argptr+4(FP), SI; \
391 MOVL argsize+8(FP), CX; \
392 MOVL SP, DI; \
393 REP;MOVSB; \
394 /* call function */ \
395 MOVL f+0(FP), DX; \
Russ Cox4a000b92014-02-25 17:00:08 -0500396 MOVL (DX), AX; \
Keith Randallcee8bca2014-05-21 14:28:34 -0700397 PCDATA $PCDATA_StackMapIndex, $0; \
Russ Cox4a000b92014-02-25 17:00:08 -0500398 CALL AX; \
Keith Randall9cd57062013-08-02 13:03:14 -0700399 /* copy return values back */ \
400 MOVL argptr+4(FP), DI; \
401 MOVL argsize+8(FP), CX; \
Russ Cox72c5d5e2014-04-08 11:11:35 -0400402 MOVL retoffset+12(FP), BX; \
Keith Randall9cd57062013-08-02 13:03:14 -0700403 MOVL SP, SI; \
Russ Cox72c5d5e2014-04-08 11:11:35 -0400404 ADDL BX, DI; \
405 ADDL BX, SI; \
406 SUBL BX, CX; \
Keith Randall9cd57062013-08-02 13:03:14 -0700407 REP;MOVSB; \
408 RET
409
Rob Pikeaff78832014-07-30 10:11:44 -0700410CALLFN(runtime·call16, 16)
411CALLFN(runtime·call32, 32)
412CALLFN(runtime·call64, 64)
413CALLFN(runtime·call128, 128)
414CALLFN(runtime·call256, 256)
415CALLFN(runtime·call512, 512)
416CALLFN(runtime·call1024, 1024)
417CALLFN(runtime·call2048, 2048)
418CALLFN(runtime·call4096, 4096)
419CALLFN(runtime·call8192, 8192)
420CALLFN(runtime·call16384, 16384)
421CALLFN(runtime·call32768, 32768)
422CALLFN(runtime·call65536, 65536)
423CALLFN(runtime·call131072, 131072)
424CALLFN(runtime·call262144, 262144)
425CALLFN(runtime·call524288, 524288)
426CALLFN(runtime·call1048576, 1048576)
427CALLFN(runtime·call2097152, 2097152)
428CALLFN(runtime·call4194304, 4194304)
429CALLFN(runtime·call8388608, 8388608)
430CALLFN(runtime·call16777216, 16777216)
431CALLFN(runtime·call33554432, 33554432)
432CALLFN(runtime·call67108864, 67108864)
433CALLFN(runtime·call134217728, 134217728)
434CALLFN(runtime·call268435456, 268435456)
435CALLFN(runtime·call536870912, 536870912)
436CALLFN(runtime·call1073741824, 1073741824)
Russ Coxbba278a2009-07-08 18:16:09 -0700437
Russ Cox0d3a0432009-03-30 00:01:07 -0700438// bool cas(int32 *val, int32 old, int32 new)
439// Atomically:
440// if(*val == old){
441// *val = new;
442// return 1;
443// }else
444// return 0;
Russ Cox25f6b022014-08-27 11:32:17 -0400445TEXT runtime·cas(SB), NOSPLIT, $0-13
446 MOVL ptr+0(FP), BX
447 MOVL old+4(FP), AX
448 MOVL new+8(FP), CX
Russ Cox0d3a0432009-03-30 00:01:07 -0700449 LOCK
450 CMPXCHGL CX, 0(BX)
Russ Cox25f6b022014-08-27 11:32:17 -0400451 JZ 4(PC)
Russ Cox0d3a0432009-03-30 00:01:07 -0700452 MOVL $0, AX
Russ Cox25f6b022014-08-27 11:32:17 -0400453 MOVB AX, ret+12(FP)
Russ Cox0d3a0432009-03-30 00:01:07 -0700454 RET
455 MOVL $1, AX
Russ Cox25f6b022014-08-27 11:32:17 -0400456 MOVB AX, ret+12(FP)
Russ Cox0d3a0432009-03-30 00:01:07 -0700457 RET
458
Russ Coxd21638b2014-08-27 21:59:49 -0400459TEXT runtime·casuintptr(SB), NOSPLIT, $0-13
460 JMP runtime·cas(SB)
461
Russ Cox3a7f6642014-08-29 16:20:48 -0400462TEXT runtime·atomicloaduintptr(SB), NOSPLIT, $0-8
463 JMP runtime·atomicload(SB)
464
Keith Randall47d6af22014-08-30 11:03:28 -0700465TEXT runtime·atomicloaduint(SB), NOSPLIT, $0-8
466 JMP runtime·atomicload(SB)
467
Russ Coxf70a19f2013-07-12 00:42:46 -0400468// bool runtime·cas64(uint64 *val, uint64 old, uint64 new)
Dmitriy Vyukov46675712012-04-05 18:47:43 +0400469// Atomically:
470// if(*val == *old){
471// *val = new;
472// return 1;
473// } else {
Dmitriy Vyukov46675712012-04-05 18:47:43 +0400474// return 0;
475// }
Russ Cox25f6b022014-08-27 11:32:17 -0400476TEXT runtime·cas64(SB), NOSPLIT, $0-21
477 MOVL ptr+0(FP), BP
478 MOVL old_lo+4(FP), AX
479 MOVL old_hi+8(FP), DX
480 MOVL new_lo+12(FP), BX
481 MOVL new_hi+16(FP), CX
Dmitriy Vyukov46675712012-04-05 18:47:43 +0400482 LOCK
483 CMPXCHG8B 0(BP)
484 JNZ cas64_fail
485 MOVL $1, AX
Russ Cox25f6b022014-08-27 11:32:17 -0400486 MOVB AX, ret+20(FP)
Dmitriy Vyukov46675712012-04-05 18:47:43 +0400487 RET
488cas64_fail:
Dmitriy Vyukovfd04f052012-04-05 18:59:50 +0400489 MOVL $0, AX
Russ Cox25f6b022014-08-27 11:32:17 -0400490 MOVB AX, ret+20(FP)
Dmitriy Vyukov46675712012-04-05 18:47:43 +0400491 RET
492
Hector Chu6bfe5f52010-01-06 17:58:55 -0800493// bool casp(void **p, void *old, void *new)
494// Atomically:
495// if(*p == old){
496// *p = new;
497// return 1;
498// }else
499// return 0;
Russ Cox25f6b022014-08-27 11:32:17 -0400500TEXT runtime·casp(SB), NOSPLIT, $0-13
501 MOVL ptr+0(FP), BX
502 MOVL old+4(FP), AX
503 MOVL new+8(FP), CX
Hector Chu6bfe5f52010-01-06 17:58:55 -0800504 LOCK
505 CMPXCHGL CX, 0(BX)
Russ Cox25f6b022014-08-27 11:32:17 -0400506 JZ 4(PC)
Hector Chu6bfe5f52010-01-06 17:58:55 -0800507 MOVL $0, AX
Russ Cox25f6b022014-08-27 11:32:17 -0400508 MOVB AX, ret+12(FP)
Hector Chu6bfe5f52010-01-06 17:58:55 -0800509 RET
510 MOVL $1, AX
Russ Cox25f6b022014-08-27 11:32:17 -0400511 MOVB AX, ret+12(FP)
Hector Chu6bfe5f52010-01-06 17:58:55 -0800512 RET
513
Dmitriy Vyukov491aa152011-07-15 11:27:16 -0400514// uint32 xadd(uint32 volatile *val, int32 delta)
515// Atomically:
516// *val += delta;
517// return *val;
Russ Cox25f6b022014-08-27 11:32:17 -0400518TEXT runtime·xadd(SB), NOSPLIT, $0-12
519 MOVL ptr+0(FP), BX
520 MOVL delta+4(FP), AX
Dmitriy Vyukov491aa152011-07-15 11:27:16 -0400521 MOVL AX, CX
522 LOCK
523 XADDL AX, 0(BX)
524 ADDL CX, AX
Russ Cox25f6b022014-08-27 11:32:17 -0400525 MOVL AX, ret+8(FP)
Dmitriy Vyukov491aa152011-07-15 11:27:16 -0400526 RET
527
Russ Cox25f6b022014-08-27 11:32:17 -0400528TEXT runtime·xchg(SB), NOSPLIT, $0-12
529 MOVL ptr+0(FP), BX
530 MOVL new+4(FP), AX
Dmitriy Vyukov4e5086b2011-07-29 12:44:06 -0400531 XCHGL AX, 0(BX)
Russ Cox25f6b022014-08-27 11:32:17 -0400532 MOVL AX, ret+8(FP)
Dmitriy Vyukov4e5086b2011-07-29 12:44:06 -0400533 RET
534
Russ Cox25f6b022014-08-27 11:32:17 -0400535TEXT runtime·xchgp(SB), NOSPLIT, $0-12
536 MOVL ptr+0(FP), BX
537 MOVL new+4(FP), AX
Dmitriy Vyukov9cbd2fb2014-01-22 11:27:16 +0400538 XCHGL AX, 0(BX)
Russ Cox25f6b022014-08-27 11:32:17 -0400539 MOVL AX, ret+8(FP)
Dmitriy Vyukov9cbd2fb2014-01-22 11:27:16 +0400540 RET
541
Dmitriy Vyukov91a670d2014-09-04 10:04:04 +0400542TEXT runtime·xchguintptr(SB), NOSPLIT, $0-12
543 JMP runtime·xchg(SB)
544
Keith Randall5a546962013-08-07 10:23:24 -0700545TEXT runtime·procyield(SB),NOSPLIT,$0-0
Russ Cox25f6b022014-08-27 11:32:17 -0400546 MOVL cycles+0(FP), AX
Dmitriy Vyukov4e5086b2011-07-29 12:44:06 -0400547again:
548 PAUSE
549 SUBL $1, AX
550 JNZ again
551 RET
552
Keith Randall5a546962013-08-07 10:23:24 -0700553TEXT runtime·atomicstorep(SB), NOSPLIT, $0-8
Russ Cox25f6b022014-08-27 11:32:17 -0400554 MOVL ptr+0(FP), BX
555 MOVL val+4(FP), AX
Dmitriy Vyukov86a659c2011-07-13 11:22:41 -0700556 XCHGL AX, 0(BX)
557 RET
558
Keith Randall5a546962013-08-07 10:23:24 -0700559TEXT runtime·atomicstore(SB), NOSPLIT, $0-8
Russ Cox25f6b022014-08-27 11:32:17 -0400560 MOVL ptr+0(FP), BX
561 MOVL val+4(FP), AX
Dmitriy Vyukov91f0f182011-07-29 13:47:24 -0400562 XCHGL AX, 0(BX)
563 RET
564
Dmitriy Vyukov46675712012-04-05 18:47:43 +0400565// uint64 atomicload64(uint64 volatile* addr);
Russ Cox25f6b022014-08-27 11:32:17 -0400566TEXT runtime·atomicload64(SB), NOSPLIT, $0-12
567 MOVL ptr+0(FP), AX
568 LEAL ret_lo+4(FP), BX
Dmitriy Vyukov46675712012-04-05 18:47:43 +0400569 // MOVQ (%EAX), %MM0
570 BYTE $0x0f; BYTE $0x6f; BYTE $0x00
571 // MOVQ %MM0, 0(%EBX)
572 BYTE $0x0f; BYTE $0x7f; BYTE $0x03
573 // EMMS
574 BYTE $0x0F; BYTE $0x77
575 RET
576
577// void runtime·atomicstore64(uint64 volatile* addr, uint64 v);
Keith Randall5a546962013-08-07 10:23:24 -0700578TEXT runtime·atomicstore64(SB), NOSPLIT, $0-12
Russ Cox25f6b022014-08-27 11:32:17 -0400579 MOVL ptr+0(FP), AX
Dmitriy Vyukov46675712012-04-05 18:47:43 +0400580 // MOVQ and EMMS were introduced on the Pentium MMX.
581 // MOVQ 0x8(%ESP), %MM0
582 BYTE $0x0f; BYTE $0x6f; BYTE $0x44; BYTE $0x24; BYTE $0x08
583 // MOVQ %MM0, (%EAX)
584 BYTE $0x0f; BYTE $0x7f; BYTE $0x00
585 // EMMS
586 BYTE $0x0F; BYTE $0x77
587 // This is essentially a no-op, but it provides required memory fencing.
588 // It can be replaced with MFENCE, but MFENCE was introduced only on the Pentium4 (SSE2).
589 MOVL $0, AX
590 LOCK
591 XADDL AX, (SP)
592 RET
593
Dmitriy Vyukovff3fa1b2014-08-19 17:38:00 +0400594// void runtime·atomicor8(byte volatile*, byte);
Russ Cox25f6b022014-08-27 11:32:17 -0400595TEXT runtime·atomicor8(SB), NOSPLIT, $0-5
Dmitriy Vyukovff3fa1b2014-08-19 17:38:00 +0400596 MOVL ptr+0(FP), AX
597 MOVB val+4(FP), BX
598 LOCK
599 ORB BX, (AX)
600 RET
601
Russ Coxaa3222d82009-06-02 23:02:12 -0700602// void jmpdefer(fn, sp);
603// called from deferreturn.
Russ Cox0d3a0432009-03-30 00:01:07 -0700604// 1. pop the caller
605// 2. sub 5 bytes from the callers return
606// 3. jmp to the argument
Keith Randalla97a91d2013-08-07 14:03:50 -0700607TEXT runtime·jmpdefer(SB), NOSPLIT, $0-8
Russ Cox25f6b022014-08-27 11:32:17 -0400608 MOVL fv+0(FP), DX // fn
609 MOVL argp+4(FP), BX // caller sp
Russ Coxaa3222d82009-06-02 23:02:12 -0700610 LEAL -4(BX), SP // caller sp after CALL
611 SUBL $5, (SP) // return to CALL again
Russ Cox6066fdc2013-02-22 10:47:54 -0500612 MOVL 0(DX), BX
Russ Cox1903ad72013-02-21 17:01:13 -0500613 JMP BX // but first run the deferred function
Russ Cox0d3a0432009-03-30 00:01:07 -0700614
Russ Coxd67e7e32013-06-12 15:22:26 -0400615// Save state of caller into g->sched.
Keith Randall5a546962013-08-07 10:23:24 -0700616TEXT gosave<>(SB),NOSPLIT,$0
Russ Coxd67e7e32013-06-12 15:22:26 -0400617 PUSHL AX
618 PUSHL BX
619 get_tls(BX)
620 MOVL g(BX), BX
621 LEAL arg+0(FP), AX
622 MOVL AX, (g_sched+gobuf_sp)(BX)
623 MOVL -4(AX), AX
624 MOVL AX, (g_sched+gobuf_pc)(BX)
625 MOVL $0, (g_sched+gobuf_ret)(BX)
626 MOVL $0, (g_sched+gobuf_ctxt)(BX)
627 POPL BX
628 POPL AX
Russ Coxf9ca3b52011-03-07 10:37:42 -0500629 RET
630
631// asmcgocall(void(*fn)(void*), void *arg)
632// Call fn(arg) on the scheduler stack,
633// aligned appropriately for the gcc ABI.
634// See cgocall.c for more details.
Russ Coxcb767242014-09-04 00:01:55 -0400635TEXT runtime·asmcgocall(SB),NOSPLIT,$0-8
Russ Cox54138e12014-09-03 11:36:14 -0400636 MOVL fn+0(FP), AX
637 MOVL arg+4(FP), BX
Russ Coxcb767242014-09-04 00:01:55 -0400638 CALL asmcgocall<>(SB)
Russ Cox54138e12014-09-03 11:36:14 -0400639 RET
640
641TEXT runtime·asmcgocall_errno(SB),NOSPLIT,$0-12
Russ Coxf9ca3b52011-03-07 10:37:42 -0500642 MOVL fn+0(FP), AX
643 MOVL arg+4(FP), BX
Russ Coxcb767242014-09-04 00:01:55 -0400644 CALL asmcgocall<>(SB)
645 MOVL AX, ret+8(FP)
646 RET
647
648TEXT asmcgocall<>(SB),NOSPLIT,$0-12
649 // fn in AX, arg in BX
Russ Coxf9ca3b52011-03-07 10:37:42 -0500650 MOVL SP, DX
651
652 // Figure out if we need to switch to m->g0 stack.
653 // We get called to create new OS threads too, and those
654 // come in on the m->g0 stack already.
655 get_tls(CX)
Russ Cox89f185f2014-06-26 11:54:39 -0400656 MOVL g(CX), BP
657 MOVL g_m(BP), BP
Russ Coxf9ca3b52011-03-07 10:37:42 -0500658 MOVL m_g0(BP), SI
659 MOVL g(CX), DI
660 CMPL SI, DI
Russ Coxd67e7e32013-06-12 15:22:26 -0400661 JEQ 4(PC)
662 CALL gosave<>(SB)
Russ Coxf9ca3b52011-03-07 10:37:42 -0500663 MOVL SI, g(CX)
664 MOVL (g_sched+gobuf_sp)(SI), SP
665
666 // Now on a scheduling stack (a pthread-created stack).
667 SUBL $32, SP
668 ANDL $~15, SP // alignment, perhaps unnecessary
669 MOVL DI, 8(SP) // save g
670 MOVL DX, 4(SP) // save SP
671 MOVL BX, 0(SP) // first argument in x86-32 ABI
672 CALL AX
673
674 // Restore registers, g, stack pointer.
675 get_tls(CX)
676 MOVL 8(SP), DI
677 MOVL DI, g(CX)
678 MOVL 4(SP), SP
679 RET
680
681// cgocallback(void (*fn)(void*), void *frame, uintptr framesize)
Russ Cox3d2dfc52013-02-22 16:08:56 -0500682// Turn the fn into a Go func (by taking its address) and call
683// cgocallback_gofunc.
Keith Randall5a546962013-08-07 10:23:24 -0700684TEXT runtime·cgocallback(SB),NOSPLIT,$12-12
Russ Cox3d2dfc52013-02-22 16:08:56 -0500685 LEAL fn+0(FP), AX
686 MOVL AX, 0(SP)
687 MOVL frame+4(FP), AX
688 MOVL AX, 4(SP)
689 MOVL framesize+8(FP), AX
690 MOVL AX, 8(SP)
691 MOVL $runtime·cgocallback_gofunc(SB), AX
692 CALL AX
693 RET
694
695// cgocallback_gofunc(FuncVal*, void *frame, uintptr framesize)
696// See cgocall.c for more details.
Keith Randall5a546962013-08-07 10:23:24 -0700697TEXT runtime·cgocallback_gofunc(SB),NOSPLIT,$12-12
Russ Cox89f185f2014-06-26 11:54:39 -0400698 // If g is nil, Go did not create the current thread.
Russ Cox6c976392013-02-20 17:48:23 -0500699 // Call needm to obtain one for temporary use.
700 // In this case, we're running on the thread stack, so there's
701 // lots of space, but the linker doesn't know. Hide the call from
702 // the linker analysis by using an indirect call through AX.
703 get_tls(CX)
704#ifdef GOOS_windows
Russ Coxdba623b2013-07-23 18:40:02 -0400705 MOVL $0, BP
Russ Cox6c976392013-02-20 17:48:23 -0500706 CMPL CX, $0
Russ Cox89f185f2014-06-26 11:54:39 -0400707 JEQ 2(PC) // TODO
Russ Cox6c976392013-02-20 17:48:23 -0500708#endif
Russ Cox89f185f2014-06-26 11:54:39 -0400709 MOVL g(CX), BP
Russ Cox6c976392013-02-20 17:48:23 -0500710 CMPL BP, $0
Russ Cox89f185f2014-06-26 11:54:39 -0400711 JEQ needm
712 MOVL g_m(BP), BP
713 MOVL BP, DX // saved copy of oldm
714 JMP havem
Russ Cox6c976392013-02-20 17:48:23 -0500715needm:
Russ Cox89f185f2014-06-26 11:54:39 -0400716 MOVL $0, 0(SP)
Russ Cox6c976392013-02-20 17:48:23 -0500717 MOVL $runtime·needm(SB), AX
718 CALL AX
Russ Coxf0112822013-07-24 09:01:57 -0400719 MOVL 0(SP), DX
Russ Coxf9ca3b52011-03-07 10:37:42 -0500720 get_tls(CX)
Russ Cox89f185f2014-06-26 11:54:39 -0400721 MOVL g(CX), BP
722 MOVL g_m(BP), BP
Russ Cox9b732382012-03-08 12:12:40 -0500723
Russ Cox6c976392013-02-20 17:48:23 -0500724havem:
725 // Now there's a valid m, and we're running on its m->g0.
726 // Save current m->g0->sched.sp on stack and then set it to SP.
727 // Save current sp in m->g0->sched.sp in preparation for
728 // switch back to m->curg stack.
Russ Coxdba623b2013-07-23 18:40:02 -0400729 // NOTE: unwindm knows that the saved g->sched.sp is at 0(SP).
Russ Coxf9ca3b52011-03-07 10:37:42 -0500730 MOVL m_g0(BP), SI
Russ Coxdba623b2013-07-23 18:40:02 -0400731 MOVL (g_sched+gobuf_sp)(SI), AX
732 MOVL AX, 0(SP)
Russ Coxf9ca3b52011-03-07 10:37:42 -0500733 MOVL SP, (g_sched+gobuf_sp)(SI)
734
Russ Coxdba623b2013-07-23 18:40:02 -0400735 // Switch to m->curg stack and call runtime.cgocallbackg.
736 // Because we are taking over the execution of m->curg
737 // but *not* resuming what had been running, we need to
738 // save that information (m->curg->sched) so we can restore it.
Russ Cox528534c2013-06-05 07:16:53 -0400739 // We can restore m->curg->sched.sp easily, because calling
Alex Brainman72e83482011-08-18 12:17:09 -0400740 // runtime.cgocallbackg leaves SP unchanged upon return.
Russ Cox528534c2013-06-05 07:16:53 -0400741 // To save m->curg->sched.pc, we push it onto the stack.
Russ Coxf9ca3b52011-03-07 10:37:42 -0500742 // This has the added benefit that it looks to the traceback
Alex Brainman72e83482011-08-18 12:17:09 -0400743 // routine like cgocallbackg is going to return to that
Russ Coxdba623b2013-07-23 18:40:02 -0400744 // PC (because the frame we allocate below has the same
745 // size as cgocallback_gofunc's frame declared above)
Russ Coxf9ca3b52011-03-07 10:37:42 -0500746 // so that the traceback will seamlessly trace back into
747 // the earlier calls.
Russ Coxdba623b2013-07-23 18:40:02 -0400748 //
Russ Coxf0112822013-07-24 09:01:57 -0400749 // In the new goroutine, 0(SP) holds the saved oldm (DX) register.
750 // 4(SP) and 8(SP) are unused.
Russ Coxf9ca3b52011-03-07 10:37:42 -0500751 MOVL m_curg(BP), SI
752 MOVL SI, g(CX)
Russ Coxdba623b2013-07-23 18:40:02 -0400753 MOVL (g_sched+gobuf_sp)(SI), DI // prepare stack as DI
Russ Coxf9ca3b52011-03-07 10:37:42 -0500754 MOVL (g_sched+gobuf_pc)(SI), BP
Russ Coxdba623b2013-07-23 18:40:02 -0400755 MOVL BP, -4(DI)
Russ Coxf0112822013-07-24 09:01:57 -0400756 LEAL -(4+12)(DI), SP
757 MOVL DX, 0(SP)
Russ Coxf9ca3b52011-03-07 10:37:42 -0500758 CALL runtime·cgocallbackg(SB)
Russ Coxf0112822013-07-24 09:01:57 -0400759 MOVL 0(SP), DX
Russ Coxf9ca3b52011-03-07 10:37:42 -0500760
Russ Cox528534c2013-06-05 07:16:53 -0400761 // Restore g->sched (== m->curg->sched) from saved values.
Russ Coxf9ca3b52011-03-07 10:37:42 -0500762 get_tls(CX)
763 MOVL g(CX), SI
Russ Coxf0112822013-07-24 09:01:57 -0400764 MOVL 12(SP), BP
Russ Coxf9ca3b52011-03-07 10:37:42 -0500765 MOVL BP, (g_sched+gobuf_pc)(SI)
Russ Coxf0112822013-07-24 09:01:57 -0400766 LEAL (12+4)(SP), DI
Russ Coxf9ca3b52011-03-07 10:37:42 -0500767 MOVL DI, (g_sched+gobuf_sp)(SI)
768
769 // Switch back to m->g0's stack and restore m->g0->sched.sp.
770 // (Unlike m->curg, the g0 goroutine never uses sched.pc,
771 // so we do not have to restore it.)
Russ Cox89f185f2014-06-26 11:54:39 -0400772 MOVL g(CX), BP
773 MOVL g_m(BP), BP
Russ Coxf9ca3b52011-03-07 10:37:42 -0500774 MOVL m_g0(BP), SI
775 MOVL SI, g(CX)
776 MOVL (g_sched+gobuf_sp)(SI), SP
Russ Coxdba623b2013-07-23 18:40:02 -0400777 MOVL 0(SP), AX
778 MOVL AX, (g_sched+gobuf_sp)(SI)
Russ Cox6c976392013-02-20 17:48:23 -0500779
780 // If the m on entry was nil, we called needm above to borrow an m
781 // for the duration of the call. Since the call is over, return it with dropm.
Russ Coxf0112822013-07-24 09:01:57 -0400782 CMPL DX, $0
Russ Cox6c976392013-02-20 17:48:23 -0500783 JNE 3(PC)
784 MOVL $runtime·dropm(SB), AX
785 CALL AX
Russ Coxf9ca3b52011-03-07 10:37:42 -0500786
787 // Done!
788 RET
789
Russ Cox89f185f2014-06-26 11:54:39 -0400790// void setg(G*); set g. for use by needm.
Russ Cox25f6b022014-08-27 11:32:17 -0400791TEXT runtime·setg(SB), NOSPLIT, $0-4
Russ Cox89f185f2014-06-26 11:54:39 -0400792 MOVL gg+0(FP), BX
Russ Cox6c976392013-02-20 17:48:23 -0500793#ifdef GOOS_windows
Russ Cox89f185f2014-06-26 11:54:39 -0400794 CMPL BX, $0
Russ Cox6c976392013-02-20 17:48:23 -0500795 JNE settls
796 MOVL $0, 0x14(FS)
797 RET
798settls:
Russ Cox89f185f2014-06-26 11:54:39 -0400799 MOVL g_m(BX), AX
Russ Cox6c976392013-02-20 17:48:23 -0500800 LEAL m_tls(AX), AX
801 MOVL AX, 0x14(FS)
802#endif
Russ Cox6c976392013-02-20 17:48:23 -0500803 get_tls(CX)
Russ Cox6c976392013-02-20 17:48:23 -0500804 MOVL BX, g(CX)
805 RET
806
Russ Cox89f185f2014-06-26 11:54:39 -0400807// void setg_gcc(G*); set g. for use by gcc
808TEXT setg_gcc<>(SB), NOSPLIT, $0
Russ Cox6a70f9d2013-03-25 18:14:02 -0400809 get_tls(AX)
Russ Cox89f185f2014-06-26 11:54:39 -0400810 MOVL gg+0(FP), DX
811 MOVL DX, g(AX)
Russ Cox6a70f9d2013-03-25 18:14:02 -0400812 RET
813
Russ Cox8ac35be2014-09-09 14:02:37 -0400814// check that SP is in range [g->stack.lo, g->stack.hi)
Keith Randall5a546962013-08-07 10:23:24 -0700815TEXT runtime·stackcheck(SB), NOSPLIT, $0-0
Russ Coxf9ca3b52011-03-07 10:37:42 -0500816 get_tls(CX)
817 MOVL g(CX), AX
Russ Cox15b76ad2014-09-09 13:39:57 -0400818 CMPL (g_stack+stack_hi)(AX), SP
Russ Coxf9ca3b52011-03-07 10:37:42 -0500819 JHI 2(PC)
820 INT $3
Russ Cox15b76ad2014-09-09 13:39:57 -0400821 CMPL SP, (g_stack+stack_lo)(AX)
Russ Coxf9ca3b52011-03-07 10:37:42 -0500822 JHI 2(PC)
823 INT $3
824 RET
825
Russ Cox25f6b022014-08-27 11:32:17 -0400826TEXT runtime·getcallerpc(SB),NOSPLIT,$0-8
827 MOVL argp+0(FP),AX // addr of first arg
Russ Cox0d3a0432009-03-30 00:01:07 -0700828 MOVL -4(AX),AX // get calling pc
Russ Cox25f6b022014-08-27 11:32:17 -0400829 MOVL AX, ret+4(FP)
Russ Cox0d3a0432009-03-30 00:01:07 -0700830 RET
831
Keith Randall61dca942014-06-16 23:03:03 -0700832TEXT runtime·gogetcallerpc(SB),NOSPLIT,$0-8
Keith Randall14c81432014-06-17 21:59:50 -0700833 MOVL p+0(FP),AX // addr of first arg
Keith Randall61dca942014-06-16 23:03:03 -0700834 MOVL -4(AX),AX // get calling pc
Keith Randall14c81432014-06-17 21:59:50 -0700835 MOVL AX, ret+4(FP)
Keith Randall61dca942014-06-16 23:03:03 -0700836 RET
837
Keith Randall5a546962013-08-07 10:23:24 -0700838TEXT runtime·setcallerpc(SB),NOSPLIT,$0-8
Russ Cox25f6b022014-08-27 11:32:17 -0400839 MOVL argp+0(FP),AX // addr of first arg
840 MOVL pc+4(FP), BX
Russ Cox0d3a0432009-03-30 00:01:07 -0700841 MOVL BX, -4(AX) // set calling pc
842 RET
843
Russ Cox25f6b022014-08-27 11:32:17 -0400844TEXT runtime·getcallersp(SB), NOSPLIT, $0-8
845 MOVL argp+0(FP), AX
846 MOVL AX, ret+4(FP)
Russ Cox6c196012010-04-05 12:51:09 -0700847 RET
848
Rémy Oudompheng39ffa8b2014-08-26 08:34:46 +0200849// func gogetcallersp(p unsafe.Pointer) uintptr
850TEXT runtime·gogetcallersp(SB),NOSPLIT,$0-8
851 MOVL p+0(FP),AX // addr of first arg
852 MOVL AX, ret+4(FP)
853 RET
854
Damian Gryski8e765da2012-02-02 14:09:27 -0500855// int64 runtime·cputicks(void), so really
856// void runtime·cputicks(int64 *ticks)
Russ Cox25f6b022014-08-27 11:32:17 -0400857TEXT runtime·cputicks(SB),NOSPLIT,$0-8
Shenghou Ma6392b432012-02-06 12:49:28 -0500858 RDTSC
Russ Cox25f6b022014-08-27 11:32:17 -0400859 MOVL AX, ret_lo+0(FP)
860 MOVL DX, ret_hi+4(FP)
Damian Gryski8e765da2012-02-02 14:09:27 -0500861 RET
862
Dmitriy Vyukov684de042014-08-21 20:41:09 +0400863TEXT runtime·gocputicks(SB),NOSPLIT,$0-8
864 RDTSC
Josh Bleecher Snydere5a06cc2014-08-26 12:38:18 -0700865 MOVL AX, ret_lo+0(FP)
866 MOVL DX, ret_hi+4(FP)
Dmitriy Vyukov684de042014-08-21 20:41:09 +0400867 RET
868
Keith Randall5a546962013-08-07 10:23:24 -0700869TEXT runtime·ldt0setup(SB),NOSPLIT,$16-0
Russ Cox0d3a0432009-03-30 00:01:07 -0700870 // set up ldt 7 to point at tls0
871 // ldt 1 would be fine on Linux, but on OS X, 7 is as low as we can go.
Russ Cox1b14bdb2009-09-22 16:28:32 -0700872 // the entry number is just a hint. setldt will set up GS with what it used.
Russ Cox0d3a0432009-03-30 00:01:07 -0700873 MOVL $7, 0(SP)
Russ Cox68b42552010-11-04 14:00:19 -0400874 LEAL runtime·tls0(SB), AX
Russ Cox0d3a0432009-03-30 00:01:07 -0700875 MOVL AX, 4(SP)
876 MOVL $32, 8(SP) // sizeof(tls array)
Russ Cox68b42552010-11-04 14:00:19 -0400877 CALL runtime·setldt(SB)
Russ Cox0d3a0432009-03-30 00:01:07 -0700878 RET
879
Russ Cox9ddfb642013-07-16 16:24:09 -0400880TEXT runtime·emptyfunc(SB),0,$0-0
Russ Cox0d3a0432009-03-30 00:01:07 -0700881 RET
882
Keith Randall5a546962013-08-07 10:23:24 -0700883TEXT runtime·abort(SB),NOSPLIT,$0-0
Russ Cox0d3a0432009-03-30 00:01:07 -0700884 INT $0x3
Russ Cox133a1582009-10-03 10:37:12 -0700885
Russ Cox68b42552010-11-04 14:00:19 -0400886GLOBL runtime·tls0(SB), $32
Keith Randalla5d40242013-03-12 10:47:44 -0700887
888// hash function using AES hardware instructions
Keith Randalla2a97682014-07-31 15:07:05 -0700889TEXT runtime·aeshash(SB),NOSPLIT,$0-16
890 MOVL p+0(FP), AX // ptr to data
891 MOVL s+4(FP), CX // size
Keith Randalla5d40242013-03-12 10:47:44 -0700892 JMP runtime·aeshashbody(SB)
893
Keith Randalla2a97682014-07-31 15:07:05 -0700894TEXT runtime·aeshashstr(SB),NOSPLIT,$0-16
895 MOVL p+0(FP), AX // ptr to string object
896 // s+4(FP) is ignored, it is always sizeof(String)
Keith Randalla5d40242013-03-12 10:47:44 -0700897 MOVL 4(AX), CX // length of string
898 MOVL (AX), AX // string data
899 JMP runtime·aeshashbody(SB)
900
901// AX: data
902// CX: length
Keith Randalla2a97682014-07-31 15:07:05 -0700903TEXT runtime·aeshashbody(SB),NOSPLIT,$0-16
904 MOVL h+8(FP), X0 // seed to low 32 bits of xmm0
Keith Randalla5d40242013-03-12 10:47:44 -0700905 PINSRD $1, CX, X0 // size to next 32 bits of xmm0
Keith Randalldb53d972013-03-20 14:34:26 -0700906 MOVO runtime·aeskeysched+0(SB), X2
907 MOVO runtime·aeskeysched+16(SB), X3
Keith Randallee669722013-05-15 09:40:14 -0700908 CMPL CX, $16
909 JB aessmall
Keith Randalla5d40242013-03-12 10:47:44 -0700910aesloop:
911 CMPL CX, $16
Keith Randallee669722013-05-15 09:40:14 -0700912 JBE aesloopend
Keith Randalla5d40242013-03-12 10:47:44 -0700913 MOVOU (AX), X1
914 AESENC X2, X0
915 AESENC X1, X0
916 SUBL $16, CX
917 ADDL $16, AX
918 JMP aesloop
Keith Randallee669722013-05-15 09:40:14 -0700919// 1-16 bytes remaining
Keith Randalla5d40242013-03-12 10:47:44 -0700920aesloopend:
Keith Randallee669722013-05-15 09:40:14 -0700921 // This load may overlap with the previous load above.
922 // We'll hash some bytes twice, but that's ok.
923 MOVOU -16(AX)(CX*1), X1
924 JMP partial
925// 0-15 bytes
926aessmall:
Keith Randalla5d40242013-03-12 10:47:44 -0700927 TESTL CX, CX
Keith Randallee669722013-05-15 09:40:14 -0700928 JE finalize // 0 bytes
Keith Randalla5d40242013-03-12 10:47:44 -0700929
Keith Randallee669722013-05-15 09:40:14 -0700930 CMPB AX, $0xf0
931 JA highpartial
Keith Randalla5d40242013-03-12 10:47:44 -0700932
Keith Randallee669722013-05-15 09:40:14 -0700933 // 16 bytes loaded at this address won't cross
934 // a page boundary, so we can load it directly.
Keith Randalla5d40242013-03-12 10:47:44 -0700935 MOVOU (AX), X1
936 ADDL CX, CX
Russ Cox9ddfb642013-07-16 16:24:09 -0400937 PAND masks<>(SB)(CX*8), X1
Keith Randalla5d40242013-03-12 10:47:44 -0700938 JMP partial
939highpartial:
Keith Randallee669722013-05-15 09:40:14 -0700940 // address ends in 1111xxxx. Might be up against
Keith Randalla5d40242013-03-12 10:47:44 -0700941 // a page boundary, so load ending at last byte.
942 // Then shift bytes down using pshufb.
943 MOVOU -16(AX)(CX*1), X1
944 ADDL CX, CX
Russ Cox9ddfb642013-07-16 16:24:09 -0400945 PSHUFB shifts<>(SB)(CX*8), X1
Keith Randalla5d40242013-03-12 10:47:44 -0700946partial:
947 // incorporate partial block into hash
948 AESENC X3, X0
949 AESENC X1, X0
950finalize:
951 // finalize hash
952 AESENC X2, X0
953 AESENC X3, X0
954 AESENC X2, X0
Russ Cox25f6b022014-08-27 11:32:17 -0400955 MOVL X0, ret+12(FP)
Keith Randalla5d40242013-03-12 10:47:44 -0700956 RET
957
Keith Randalla2a97682014-07-31 15:07:05 -0700958TEXT runtime·aeshash32(SB),NOSPLIT,$0-16
959 MOVL p+0(FP), AX // ptr to data
960 // s+4(FP) is ignored, it is always sizeof(int32)
961 MOVL h+8(FP), X0 // seed
Keith Randalla5d40242013-03-12 10:47:44 -0700962 PINSRD $1, (AX), X0 // data
Keith Randalldb53d972013-03-20 14:34:26 -0700963 AESENC runtime·aeskeysched+0(SB), X0
964 AESENC runtime·aeskeysched+16(SB), X0
965 AESENC runtime·aeskeysched+0(SB), X0
Russ Cox25f6b022014-08-27 11:32:17 -0400966 MOVL X0, ret+12(FP)
Keith Randalla5d40242013-03-12 10:47:44 -0700967 RET
968
Keith Randalla2a97682014-07-31 15:07:05 -0700969TEXT runtime·aeshash64(SB),NOSPLIT,$0-16
970 MOVL p+0(FP), AX // ptr to data
971 // s+4(FP) is ignored, it is always sizeof(int64)
Keith Randalla5d40242013-03-12 10:47:44 -0700972 MOVQ (AX), X0 // data
Keith Randalla2a97682014-07-31 15:07:05 -0700973 PINSRD $2, h+8(FP), X0 // seed
Keith Randalldb53d972013-03-20 14:34:26 -0700974 AESENC runtime·aeskeysched+0(SB), X0
975 AESENC runtime·aeskeysched+16(SB), X0
976 AESENC runtime·aeskeysched+0(SB), X0
Russ Cox25f6b022014-08-27 11:32:17 -0400977 MOVL X0, ret+12(FP)
Keith Randalla5d40242013-03-12 10:47:44 -0700978 RET
979
Keith Randalla5d40242013-03-12 10:47:44 -0700980// simple mask to get rid of data in the high part of the register.
Russ Cox9ddfb642013-07-16 16:24:09 -0400981DATA masks<>+0x00(SB)/4, $0x00000000
982DATA masks<>+0x04(SB)/4, $0x00000000
983DATA masks<>+0x08(SB)/4, $0x00000000
984DATA masks<>+0x0c(SB)/4, $0x00000000
Keith Randalla5d40242013-03-12 10:47:44 -0700985
Russ Cox9ddfb642013-07-16 16:24:09 -0400986DATA masks<>+0x10(SB)/4, $0x000000ff
987DATA masks<>+0x14(SB)/4, $0x00000000
988DATA masks<>+0x18(SB)/4, $0x00000000
989DATA masks<>+0x1c(SB)/4, $0x00000000
Keith Randalla5d40242013-03-12 10:47:44 -0700990
Russ Cox9ddfb642013-07-16 16:24:09 -0400991DATA masks<>+0x20(SB)/4, $0x0000ffff
992DATA masks<>+0x24(SB)/4, $0x00000000
993DATA masks<>+0x28(SB)/4, $0x00000000
994DATA masks<>+0x2c(SB)/4, $0x00000000
Keith Randalla5d40242013-03-12 10:47:44 -0700995
Russ Cox9ddfb642013-07-16 16:24:09 -0400996DATA masks<>+0x30(SB)/4, $0x00ffffff
997DATA masks<>+0x34(SB)/4, $0x00000000
998DATA masks<>+0x38(SB)/4, $0x00000000
999DATA masks<>+0x3c(SB)/4, $0x00000000
Keith Randalla5d40242013-03-12 10:47:44 -07001000
Russ Cox9ddfb642013-07-16 16:24:09 -04001001DATA masks<>+0x40(SB)/4, $0xffffffff
1002DATA masks<>+0x44(SB)/4, $0x00000000
1003DATA masks<>+0x48(SB)/4, $0x00000000
1004DATA masks<>+0x4c(SB)/4, $0x00000000
Keith Randalla5d40242013-03-12 10:47:44 -07001005
Russ Cox9ddfb642013-07-16 16:24:09 -04001006DATA masks<>+0x50(SB)/4, $0xffffffff
1007DATA masks<>+0x54(SB)/4, $0x000000ff
1008DATA masks<>+0x58(SB)/4, $0x00000000
1009DATA masks<>+0x5c(SB)/4, $0x00000000
Keith Randalla5d40242013-03-12 10:47:44 -07001010
Russ Cox9ddfb642013-07-16 16:24:09 -04001011DATA masks<>+0x60(SB)/4, $0xffffffff
1012DATA masks<>+0x64(SB)/4, $0x0000ffff
1013DATA masks<>+0x68(SB)/4, $0x00000000
1014DATA masks<>+0x6c(SB)/4, $0x00000000
Keith Randalla5d40242013-03-12 10:47:44 -07001015
Russ Cox9ddfb642013-07-16 16:24:09 -04001016DATA masks<>+0x70(SB)/4, $0xffffffff
1017DATA masks<>+0x74(SB)/4, $0x00ffffff
1018DATA masks<>+0x78(SB)/4, $0x00000000
1019DATA masks<>+0x7c(SB)/4, $0x00000000
Keith Randalla5d40242013-03-12 10:47:44 -07001020
Russ Cox9ddfb642013-07-16 16:24:09 -04001021DATA masks<>+0x80(SB)/4, $0xffffffff
1022DATA masks<>+0x84(SB)/4, $0xffffffff
1023DATA masks<>+0x88(SB)/4, $0x00000000
1024DATA masks<>+0x8c(SB)/4, $0x00000000
Keith Randalla5d40242013-03-12 10:47:44 -07001025
Russ Cox9ddfb642013-07-16 16:24:09 -04001026DATA masks<>+0x90(SB)/4, $0xffffffff
1027DATA masks<>+0x94(SB)/4, $0xffffffff
1028DATA masks<>+0x98(SB)/4, $0x000000ff
1029DATA masks<>+0x9c(SB)/4, $0x00000000
Keith Randalla5d40242013-03-12 10:47:44 -07001030
Russ Cox9ddfb642013-07-16 16:24:09 -04001031DATA masks<>+0xa0(SB)/4, $0xffffffff
1032DATA masks<>+0xa4(SB)/4, $0xffffffff
1033DATA masks<>+0xa8(SB)/4, $0x0000ffff
1034DATA masks<>+0xac(SB)/4, $0x00000000
Keith Randalla5d40242013-03-12 10:47:44 -07001035
Russ Cox9ddfb642013-07-16 16:24:09 -04001036DATA masks<>+0xb0(SB)/4, $0xffffffff
1037DATA masks<>+0xb4(SB)/4, $0xffffffff
1038DATA masks<>+0xb8(SB)/4, $0x00ffffff
1039DATA masks<>+0xbc(SB)/4, $0x00000000
Keith Randalla5d40242013-03-12 10:47:44 -07001040
Russ Cox9ddfb642013-07-16 16:24:09 -04001041DATA masks<>+0xc0(SB)/4, $0xffffffff
1042DATA masks<>+0xc4(SB)/4, $0xffffffff
1043DATA masks<>+0xc8(SB)/4, $0xffffffff
1044DATA masks<>+0xcc(SB)/4, $0x00000000
Keith Randalla5d40242013-03-12 10:47:44 -07001045
Russ Cox9ddfb642013-07-16 16:24:09 -04001046DATA masks<>+0xd0(SB)/4, $0xffffffff
1047DATA masks<>+0xd4(SB)/4, $0xffffffff
1048DATA masks<>+0xd8(SB)/4, $0xffffffff
1049DATA masks<>+0xdc(SB)/4, $0x000000ff
Keith Randalla5d40242013-03-12 10:47:44 -07001050
Russ Cox9ddfb642013-07-16 16:24:09 -04001051DATA masks<>+0xe0(SB)/4, $0xffffffff
1052DATA masks<>+0xe4(SB)/4, $0xffffffff
1053DATA masks<>+0xe8(SB)/4, $0xffffffff
1054DATA masks<>+0xec(SB)/4, $0x0000ffff
Keith Randalla5d40242013-03-12 10:47:44 -07001055
Russ Cox9ddfb642013-07-16 16:24:09 -04001056DATA masks<>+0xf0(SB)/4, $0xffffffff
1057DATA masks<>+0xf4(SB)/4, $0xffffffff
1058DATA masks<>+0xf8(SB)/4, $0xffffffff
1059DATA masks<>+0xfc(SB)/4, $0x00ffffff
Keith Randalla5d40242013-03-12 10:47:44 -07001060
Keith Randall5a546962013-08-07 10:23:24 -07001061GLOBL masks<>(SB),RODATA,$256
Keith Randalla5d40242013-03-12 10:47:44 -07001062
Russ Cox9ddfb642013-07-16 16:24:09 -04001063// these are arguments to pshufb. They move data down from
1064// the high bytes of the register to the low bytes of the register.
1065// index is how many bytes to move.
1066DATA shifts<>+0x00(SB)/4, $0x00000000
1067DATA shifts<>+0x04(SB)/4, $0x00000000
1068DATA shifts<>+0x08(SB)/4, $0x00000000
1069DATA shifts<>+0x0c(SB)/4, $0x00000000
1070
1071DATA shifts<>+0x10(SB)/4, $0xffffff0f
1072DATA shifts<>+0x14(SB)/4, $0xffffffff
1073DATA shifts<>+0x18(SB)/4, $0xffffffff
1074DATA shifts<>+0x1c(SB)/4, $0xffffffff
1075
1076DATA shifts<>+0x20(SB)/4, $0xffff0f0e
1077DATA shifts<>+0x24(SB)/4, $0xffffffff
1078DATA shifts<>+0x28(SB)/4, $0xffffffff
1079DATA shifts<>+0x2c(SB)/4, $0xffffffff
1080
1081DATA shifts<>+0x30(SB)/4, $0xff0f0e0d
1082DATA shifts<>+0x34(SB)/4, $0xffffffff
1083DATA shifts<>+0x38(SB)/4, $0xffffffff
1084DATA shifts<>+0x3c(SB)/4, $0xffffffff
1085
1086DATA shifts<>+0x40(SB)/4, $0x0f0e0d0c
1087DATA shifts<>+0x44(SB)/4, $0xffffffff
1088DATA shifts<>+0x48(SB)/4, $0xffffffff
1089DATA shifts<>+0x4c(SB)/4, $0xffffffff
1090
1091DATA shifts<>+0x50(SB)/4, $0x0e0d0c0b
1092DATA shifts<>+0x54(SB)/4, $0xffffff0f
1093DATA shifts<>+0x58(SB)/4, $0xffffffff
1094DATA shifts<>+0x5c(SB)/4, $0xffffffff
1095
1096DATA shifts<>+0x60(SB)/4, $0x0d0c0b0a
1097DATA shifts<>+0x64(SB)/4, $0xffff0f0e
1098DATA shifts<>+0x68(SB)/4, $0xffffffff
1099DATA shifts<>+0x6c(SB)/4, $0xffffffff
1100
1101DATA shifts<>+0x70(SB)/4, $0x0c0b0a09
1102DATA shifts<>+0x74(SB)/4, $0xff0f0e0d
1103DATA shifts<>+0x78(SB)/4, $0xffffffff
1104DATA shifts<>+0x7c(SB)/4, $0xffffffff
1105
1106DATA shifts<>+0x80(SB)/4, $0x0b0a0908
1107DATA shifts<>+0x84(SB)/4, $0x0f0e0d0c
1108DATA shifts<>+0x88(SB)/4, $0xffffffff
1109DATA shifts<>+0x8c(SB)/4, $0xffffffff
1110
1111DATA shifts<>+0x90(SB)/4, $0x0a090807
1112DATA shifts<>+0x94(SB)/4, $0x0e0d0c0b
1113DATA shifts<>+0x98(SB)/4, $0xffffff0f
1114DATA shifts<>+0x9c(SB)/4, $0xffffffff
1115
1116DATA shifts<>+0xa0(SB)/4, $0x09080706
1117DATA shifts<>+0xa4(SB)/4, $0x0d0c0b0a
1118DATA shifts<>+0xa8(SB)/4, $0xffff0f0e
1119DATA shifts<>+0xac(SB)/4, $0xffffffff
1120
1121DATA shifts<>+0xb0(SB)/4, $0x08070605
1122DATA shifts<>+0xb4(SB)/4, $0x0c0b0a09
1123DATA shifts<>+0xb8(SB)/4, $0xff0f0e0d
1124DATA shifts<>+0xbc(SB)/4, $0xffffffff
1125
1126DATA shifts<>+0xc0(SB)/4, $0x07060504
1127DATA shifts<>+0xc4(SB)/4, $0x0b0a0908
1128DATA shifts<>+0xc8(SB)/4, $0x0f0e0d0c
1129DATA shifts<>+0xcc(SB)/4, $0xffffffff
1130
1131DATA shifts<>+0xd0(SB)/4, $0x06050403
1132DATA shifts<>+0xd4(SB)/4, $0x0a090807
1133DATA shifts<>+0xd8(SB)/4, $0x0e0d0c0b
1134DATA shifts<>+0xdc(SB)/4, $0xffffff0f
1135
1136DATA shifts<>+0xe0(SB)/4, $0x05040302
1137DATA shifts<>+0xe4(SB)/4, $0x09080706
1138DATA shifts<>+0xe8(SB)/4, $0x0d0c0b0a
1139DATA shifts<>+0xec(SB)/4, $0xffff0f0e
1140
1141DATA shifts<>+0xf0(SB)/4, $0x04030201
1142DATA shifts<>+0xf4(SB)/4, $0x08070605
1143DATA shifts<>+0xf8(SB)/4, $0x0c0b0a09
1144DATA shifts<>+0xfc(SB)/4, $0xff0f0e0d
1145
Keith Randall5a546962013-08-07 10:23:24 -07001146GLOBL shifts<>(SB),RODATA,$256
Russ Cox9ddfb642013-07-16 16:24:09 -04001147
Keith Randall7aa4e5a2014-08-07 14:52:55 -07001148TEXT runtime·memeq(SB),NOSPLIT,$0-13
Keith Randall0c6b55e2014-07-16 14:16:19 -07001149 MOVL a+0(FP), SI
1150 MOVL b+4(FP), DI
1151 MOVL size+8(FP), BX
1152 CALL runtime·memeqbody(SB)
1153 MOVB AX, ret+12(FP)
1154 RET
1155
Keith Randallb36ed902014-06-16 21:00:37 -07001156// eqstring tests whether two strings are equal.
1157// See runtime_test.go:eqstring_generic for
Josh Bleecher Snyder339a24d2014-08-19 08:50:35 -07001158// equivalent Go code.
Keith Randallb36ed902014-06-16 21:00:37 -07001159TEXT runtime·eqstring(SB),NOSPLIT,$0-17
1160 MOVL s1len+4(FP), AX
1161 MOVL s2len+12(FP), BX
1162 CMPL AX, BX
1163 JNE different
1164 MOVL s1str+0(FP), SI
1165 MOVL s2str+8(FP), DI
1166 CMPL SI, DI
1167 JEQ same
1168 CALL runtime·memeqbody(SB)
1169 MOVB AX, v+16(FP)
1170 RET
1171same:
1172 MOVB $1, v+16(FP)
1173 RET
1174different:
1175 MOVB $0, v+16(FP)
1176 RET
1177
Keith Randall5a546962013-08-07 10:23:24 -07001178TEXT bytes·Equal(SB),NOSPLIT,$0-25
Keith Randall3d5daa22013-04-02 16:26:15 -07001179 MOVL a_len+4(FP), BX
1180 MOVL b_len+16(FP), CX
1181 XORL AX, AX
1182 CMPL BX, CX
1183 JNE eqret
1184 MOVL a+0(FP), SI
1185 MOVL b+12(FP), DI
1186 CALL runtime·memeqbody(SB)
1187eqret:
1188 MOVB AX, ret+24(FP)
1189 RET
1190
1191// a in SI
1192// b in DI
1193// count in BX
Keith Randall5a546962013-08-07 10:23:24 -07001194TEXT runtime·memeqbody(SB),NOSPLIT,$0-0
Keith Randall3d5daa22013-04-02 16:26:15 -07001195 XORL AX, AX
1196
1197 CMPL BX, $4
1198 JB small
1199
1200 // 64 bytes at a time using xmm registers
1201hugeloop:
1202 CMPL BX, $64
1203 JB bigloop
1204 TESTL $0x4000000, runtime·cpuid_edx(SB) // check for sse2
1205 JE bigloop
1206 MOVOU (SI), X0
1207 MOVOU (DI), X1
1208 MOVOU 16(SI), X2
1209 MOVOU 16(DI), X3
1210 MOVOU 32(SI), X4
1211 MOVOU 32(DI), X5
1212 MOVOU 48(SI), X6
1213 MOVOU 48(DI), X7
1214 PCMPEQB X1, X0
1215 PCMPEQB X3, X2
1216 PCMPEQB X5, X4
1217 PCMPEQB X7, X6
1218 PAND X2, X0
1219 PAND X6, X4
1220 PAND X4, X0
1221 PMOVMSKB X0, DX
1222 ADDL $64, SI
1223 ADDL $64, DI
1224 SUBL $64, BX
1225 CMPL DX, $0xffff
1226 JEQ hugeloop
1227 RET
1228
1229 // 4 bytes at a time using 32-bit register
1230bigloop:
1231 CMPL BX, $4
1232 JBE leftover
1233 MOVL (SI), CX
1234 MOVL (DI), DX
1235 ADDL $4, SI
1236 ADDL $4, DI
1237 SUBL $4, BX
1238 CMPL CX, DX
1239 JEQ bigloop
1240 RET
1241
1242 // remaining 0-4 bytes
1243leftover:
1244 MOVL -4(SI)(BX*1), CX
1245 MOVL -4(DI)(BX*1), DX
1246 CMPL CX, DX
1247 SETEQ AX
1248 RET
1249
1250small:
1251 CMPL BX, $0
1252 JEQ equal
1253
1254 LEAL 0(BX*8), CX
1255 NEGL CX
1256
1257 MOVL SI, DX
1258 CMPB DX, $0xfc
1259 JA si_high
1260
1261 // load at SI won't cross a page boundary.
1262 MOVL (SI), SI
1263 JMP si_finish
1264si_high:
1265 // address ends in 111111xx. Load up to bytes we want, move to correct position.
1266 MOVL -4(SI)(BX*1), SI
1267 SHRL CX, SI
1268si_finish:
1269
1270 // same for DI.
1271 MOVL DI, DX
1272 CMPB DX, $0xfc
1273 JA di_high
1274 MOVL (DI), DI
1275 JMP di_finish
1276di_high:
1277 MOVL -4(DI)(BX*1), DI
1278 SHRL CX, DI
1279di_finish:
1280
1281 SUBL SI, DI
1282 SHLL CX, DI
1283equal:
1284 SETEQ AX
1285 RET
Keith Randallb3946dc2013-05-14 16:05:51 -07001286
Keith Randall5a546962013-08-07 10:23:24 -07001287TEXT runtime·cmpstring(SB),NOSPLIT,$0-20
Russ Cox25f6b022014-08-27 11:32:17 -04001288 MOVL s1_base+0(FP), SI
1289 MOVL s1_len+4(FP), BX
1290 MOVL s2_base+8(FP), DI
1291 MOVL s2_len+12(FP), DX
Keith Randallb3946dc2013-05-14 16:05:51 -07001292 CALL runtime·cmpbody(SB)
Russ Cox25f6b022014-08-27 11:32:17 -04001293 MOVL AX, ret+16(FP)
Keith Randallb3946dc2013-05-14 16:05:51 -07001294 RET
1295
Russ Cox6179aca2014-08-28 10:46:59 -04001296TEXT runtime·cmpbytes(SB),NOSPLIT,$0-28
Keith Randallb3946dc2013-05-14 16:05:51 -07001297 MOVL s1+0(FP), SI
1298 MOVL s1+4(FP), BX
1299 MOVL s2+12(FP), DI
1300 MOVL s2+16(FP), DX
1301 CALL runtime·cmpbody(SB)
Russ Cox25f6b022014-08-27 11:32:17 -04001302 MOVL AX, ret+24(FP)
Keith Randallb3946dc2013-05-14 16:05:51 -07001303 RET
1304
Keith Randall5a546962013-08-07 10:23:24 -07001305TEXT bytes·IndexByte(SB),NOSPLIT,$0
Brad Fitzpatricke2a1bd62013-08-01 16:11:19 -07001306 MOVL s+0(FP), SI
1307 MOVL s_len+4(FP), CX
1308 MOVB c+12(FP), AL
1309 MOVL SI, DI
1310 CLD; REPN; SCASB
1311 JZ 3(PC)
1312 MOVL $-1, ret+16(FP)
1313 RET
1314 SUBL SI, DI
1315 SUBL $1, DI
1316 MOVL DI, ret+16(FP)
1317 RET
1318
Keith Randall5a546962013-08-07 10:23:24 -07001319TEXT strings·IndexByte(SB),NOSPLIT,$0
Brad Fitzpatrick598c7892013-08-05 15:04:05 -07001320 MOVL s+0(FP), SI
1321 MOVL s_len+4(FP), CX
1322 MOVB c+8(FP), AL
1323 MOVL SI, DI
1324 CLD; REPN; SCASB
1325 JZ 3(PC)
1326 MOVL $-1, ret+12(FP)
1327 RET
1328 SUBL SI, DI
1329 SUBL $1, DI
1330 MOVL DI, ret+12(FP)
1331 RET
1332
Keith Randallb3946dc2013-05-14 16:05:51 -07001333// input:
1334// SI = a
1335// DI = b
1336// BX = alen
1337// DX = blen
1338// output:
1339// AX = 1/0/-1
Keith Randall5a546962013-08-07 10:23:24 -07001340TEXT runtime·cmpbody(SB),NOSPLIT,$0-0
Keith Randallb3946dc2013-05-14 16:05:51 -07001341 CMPL SI, DI
1342 JEQ cmp_allsame
1343 CMPL BX, DX
1344 MOVL DX, BP
1345 CMOVLLT BX, BP // BP = min(alen, blen)
1346 CMPL BP, $4
1347 JB cmp_small
1348 TESTL $0x4000000, runtime·cpuid_edx(SB) // check for sse2
1349 JE cmp_mediumloop
1350cmp_largeloop:
1351 CMPL BP, $16
1352 JB cmp_mediumloop
1353 MOVOU (SI), X0
1354 MOVOU (DI), X1
1355 PCMPEQB X0, X1
1356 PMOVMSKB X1, AX
1357 XORL $0xffff, AX // convert EQ to NE
1358 JNE cmp_diff16 // branch if at least one byte is not equal
1359 ADDL $16, SI
1360 ADDL $16, DI
1361 SUBL $16, BP
1362 JMP cmp_largeloop
1363
1364cmp_diff16:
1365 BSFL AX, BX // index of first byte that differs
1366 XORL AX, AX
1367 MOVB (SI)(BX*1), CX
1368 CMPB CX, (DI)(BX*1)
1369 SETHI AX
1370 LEAL -1(AX*2), AX // convert 1/0 to +1/-1
1371 RET
1372
1373cmp_mediumloop:
1374 CMPL BP, $4
1375 JBE cmp_0through4
1376 MOVL (SI), AX
1377 MOVL (DI), CX
1378 CMPL AX, CX
1379 JNE cmp_diff4
1380 ADDL $4, SI
1381 ADDL $4, DI
1382 SUBL $4, BP
1383 JMP cmp_mediumloop
1384
1385cmp_0through4:
1386 MOVL -4(SI)(BP*1), AX
1387 MOVL -4(DI)(BP*1), CX
1388 CMPL AX, CX
1389 JEQ cmp_allsame
1390
1391cmp_diff4:
1392 BSWAPL AX // reverse order of bytes
1393 BSWAPL CX
1394 XORL AX, CX // find bit differences
1395 BSRL CX, CX // index of highest bit difference
1396 SHRL CX, AX // move a's bit to bottom
1397 ANDL $1, AX // mask bit
1398 LEAL -1(AX*2), AX // 1/0 => +1/-1
1399 RET
1400
1401 // 0-3 bytes in common
1402cmp_small:
1403 LEAL (BP*8), CX
1404 NEGL CX
1405 JEQ cmp_allsame
1406
1407 // load si
1408 CMPB SI, $0xfc
1409 JA cmp_si_high
1410 MOVL (SI), SI
1411 JMP cmp_si_finish
1412cmp_si_high:
1413 MOVL -4(SI)(BP*1), SI
1414 SHRL CX, SI
1415cmp_si_finish:
1416 SHLL CX, SI
1417
1418 // same for di
1419 CMPB DI, $0xfc
1420 JA cmp_di_high
1421 MOVL (DI), DI
1422 JMP cmp_di_finish
1423cmp_di_high:
1424 MOVL -4(DI)(BP*1), DI
1425 SHRL CX, DI
1426cmp_di_finish:
1427 SHLL CX, DI
1428
1429 BSWAPL SI // reverse order of bytes
1430 BSWAPL DI
1431 XORL SI, DI // find bit differences
1432 JEQ cmp_allsame
1433 BSRL DI, CX // index of highest bit difference
1434 SHRL CX, SI // move a's bit to bottom
1435 ANDL $1, SI // mask bit
1436 LEAL -1(SI*2), AX // 1/0 => +1/-1
1437 RET
1438
1439 // all the bytes in common are the same, so we just need
1440 // to compare the lengths.
1441cmp_allsame:
1442 XORL AX, AX
1443 XORL CX, CX
1444 CMPL BX, DX
1445 SETGT AX // 1 if alen > blen
1446 SETEQ CX // 1 if alen == blen
1447 LEAL -1(CX)(AX*2), AX // 1,0,-1 result
1448 RET
Keith Randall6c7cbf02014-04-01 12:51:02 -07001449
1450// A Duff's device for zeroing memory.
1451// The compiler jumps to computed addresses within
1452// this routine to zero chunks of memory. Do not
1453// change this code without also changing the code
1454// in ../../cmd/8g/ggen.c:clearfat.
1455// AX: zero
1456// DI: ptr to memory to be zeroed
1457// DI is updated as a side effect.
1458TEXT runtime·duffzero(SB), NOSPLIT, $0-0
1459 STOSL
1460 STOSL
1461 STOSL
1462 STOSL
1463 STOSL
1464 STOSL
1465 STOSL
1466 STOSL
1467 STOSL
1468 STOSL
1469 STOSL
1470 STOSL
1471 STOSL
1472 STOSL
1473 STOSL
1474 STOSL
1475 STOSL
1476 STOSL
1477 STOSL
1478 STOSL
1479 STOSL
1480 STOSL
1481 STOSL
1482 STOSL
1483 STOSL
1484 STOSL
1485 STOSL
1486 STOSL
1487 STOSL
1488 STOSL
1489 STOSL
1490 STOSL
1491 STOSL
1492 STOSL
1493 STOSL
1494 STOSL
1495 STOSL
1496 STOSL
1497 STOSL
1498 STOSL
1499 STOSL
1500 STOSL
1501 STOSL
1502 STOSL
1503 STOSL
1504 STOSL
1505 STOSL
1506 STOSL
1507 STOSL
1508 STOSL
1509 STOSL
1510 STOSL
1511 STOSL
1512 STOSL
1513 STOSL
1514 STOSL
1515 STOSL
1516 STOSL
1517 STOSL
1518 STOSL
1519 STOSL
1520 STOSL
1521 STOSL
1522 STOSL
1523 STOSL
1524 STOSL
1525 STOSL
1526 STOSL
1527 STOSL
1528 STOSL
1529 STOSL
1530 STOSL
1531 STOSL
1532 STOSL
1533 STOSL
1534 STOSL
1535 STOSL
1536 STOSL
1537 STOSL
1538 STOSL
1539 STOSL
1540 STOSL
1541 STOSL
1542 STOSL
1543 STOSL
1544 STOSL
1545 STOSL
1546 STOSL
1547 STOSL
1548 STOSL
1549 STOSL
1550 STOSL
1551 STOSL
1552 STOSL
1553 STOSL
1554 STOSL
1555 STOSL
1556 STOSL
1557 STOSL
1558 STOSL
1559 STOSL
1560 STOSL
1561 STOSL
1562 STOSL
1563 STOSL
1564 STOSL
1565 STOSL
1566 STOSL
1567 STOSL
1568 STOSL
1569 STOSL
1570 STOSL
1571 STOSL
1572 STOSL
1573 STOSL
1574 STOSL
1575 STOSL
1576 STOSL
1577 STOSL
1578 STOSL
1579 STOSL
1580 STOSL
1581 STOSL
1582 STOSL
1583 STOSL
1584 STOSL
1585 STOSL
1586 STOSL
1587 RET
1588
1589// A Duff's device for copying memory.
1590// The compiler jumps to computed addresses within
1591// this routine to copy chunks of memory. Source
1592// and destination must not overlap. Do not
1593// change this code without also changing the code
1594// in ../../cmd/6g/cgen.c:sgen.
1595// SI: ptr to source memory
1596// DI: ptr to destination memory
1597// SI and DI are updated as a side effect.
1598
1599// NOTE: this is equivalent to a sequence of MOVSL but
1600// for some reason MOVSL is really slow.
1601TEXT runtime·duffcopy(SB), NOSPLIT, $0-0
1602 MOVL (SI),CX
1603 ADDL $4,SI
1604 MOVL CX,(DI)
1605 ADDL $4,DI
1606
1607 MOVL (SI),CX
1608 ADDL $4,SI
1609 MOVL CX,(DI)
1610 ADDL $4,DI
1611
1612 MOVL (SI),CX
1613 ADDL $4,SI
1614 MOVL CX,(DI)
1615 ADDL $4,DI
1616
1617 MOVL (SI),CX
1618 ADDL $4,SI
1619 MOVL CX,(DI)
1620 ADDL $4,DI
1621
1622 MOVL (SI),CX
1623 ADDL $4,SI
1624 MOVL CX,(DI)
1625 ADDL $4,DI
1626
1627 MOVL (SI),CX
1628 ADDL $4,SI
1629 MOVL CX,(DI)
1630 ADDL $4,DI
1631
1632 MOVL (SI),CX
1633 ADDL $4,SI
1634 MOVL CX,(DI)
1635 ADDL $4,DI
1636
1637 MOVL (SI),CX
1638 ADDL $4,SI
1639 MOVL CX,(DI)
1640 ADDL $4,DI
1641
1642 MOVL (SI),CX
1643 ADDL $4,SI
1644 MOVL CX,(DI)
1645 ADDL $4,DI
1646
1647 MOVL (SI),CX
1648 ADDL $4,SI
1649 MOVL CX,(DI)
1650 ADDL $4,DI
1651
1652 MOVL (SI),CX
1653 ADDL $4,SI
1654 MOVL CX,(DI)
1655 ADDL $4,DI
1656
1657 MOVL (SI),CX
1658 ADDL $4,SI
1659 MOVL CX,(DI)
1660 ADDL $4,DI
1661
1662 MOVL (SI),CX
1663 ADDL $4,SI
1664 MOVL CX,(DI)
1665 ADDL $4,DI
1666
1667 MOVL (SI),CX
1668 ADDL $4,SI
1669 MOVL CX,(DI)
1670 ADDL $4,DI
1671
1672 MOVL (SI),CX
1673 ADDL $4,SI
1674 MOVL CX,(DI)
1675 ADDL $4,DI
1676
1677 MOVL (SI),CX
1678 ADDL $4,SI
1679 MOVL CX,(DI)
1680 ADDL $4,DI
1681
1682 MOVL (SI),CX
1683 ADDL $4,SI
1684 MOVL CX,(DI)
1685 ADDL $4,DI
1686
1687 MOVL (SI),CX
1688 ADDL $4,SI
1689 MOVL CX,(DI)
1690 ADDL $4,DI
1691
1692 MOVL (SI),CX
1693 ADDL $4,SI
1694 MOVL CX,(DI)
1695 ADDL $4,DI
1696
1697 MOVL (SI),CX
1698 ADDL $4,SI
1699 MOVL CX,(DI)
1700 ADDL $4,DI
1701
1702 MOVL (SI),CX
1703 ADDL $4,SI
1704 MOVL CX,(DI)
1705 ADDL $4,DI
1706
1707 MOVL (SI),CX
1708 ADDL $4,SI
1709 MOVL CX,(DI)
1710 ADDL $4,DI
1711
1712 MOVL (SI),CX
1713 ADDL $4,SI
1714 MOVL CX,(DI)
1715 ADDL $4,DI
1716
1717 MOVL (SI),CX
1718 ADDL $4,SI
1719 MOVL CX,(DI)
1720 ADDL $4,DI
1721
1722 MOVL (SI),CX
1723 ADDL $4,SI
1724 MOVL CX,(DI)
1725 ADDL $4,DI
1726
1727 MOVL (SI),CX
1728 ADDL $4,SI
1729 MOVL CX,(DI)
1730 ADDL $4,DI
1731
1732 MOVL (SI),CX
1733 ADDL $4,SI
1734 MOVL CX,(DI)
1735 ADDL $4,DI
1736
1737 MOVL (SI),CX
1738 ADDL $4,SI
1739 MOVL CX,(DI)
1740 ADDL $4,DI
1741
1742 MOVL (SI),CX
1743 ADDL $4,SI
1744 MOVL CX,(DI)
1745 ADDL $4,DI
1746
1747 MOVL (SI),CX
1748 ADDL $4,SI
1749 MOVL CX,(DI)
1750 ADDL $4,DI
1751
1752 MOVL (SI),CX
1753 ADDL $4,SI
1754 MOVL CX,(DI)
1755 ADDL $4,DI
1756
1757 MOVL (SI),CX
1758 ADDL $4,SI
1759 MOVL CX,(DI)
1760 ADDL $4,DI
1761
1762 MOVL (SI),CX
1763 ADDL $4,SI
1764 MOVL CX,(DI)
1765 ADDL $4,DI
1766
1767 MOVL (SI),CX
1768 ADDL $4,SI
1769 MOVL CX,(DI)
1770 ADDL $4,DI
1771
1772 MOVL (SI),CX
1773 ADDL $4,SI
1774 MOVL CX,(DI)
1775 ADDL $4,DI
1776
1777 MOVL (SI),CX
1778 ADDL $4,SI
1779 MOVL CX,(DI)
1780 ADDL $4,DI
1781
1782 MOVL (SI),CX
1783 ADDL $4,SI
1784 MOVL CX,(DI)
1785 ADDL $4,DI
1786
1787 MOVL (SI),CX
1788 ADDL $4,SI
1789 MOVL CX,(DI)
1790 ADDL $4,DI
1791
1792 MOVL (SI),CX
1793 ADDL $4,SI
1794 MOVL CX,(DI)
1795 ADDL $4,DI
1796
1797 MOVL (SI),CX
1798 ADDL $4,SI
1799 MOVL CX,(DI)
1800 ADDL $4,DI
1801
1802 MOVL (SI),CX
1803 ADDL $4,SI
1804 MOVL CX,(DI)
1805 ADDL $4,DI
1806
1807 MOVL (SI),CX
1808 ADDL $4,SI
1809 MOVL CX,(DI)
1810 ADDL $4,DI
1811
1812 MOVL (SI),CX
1813 ADDL $4,SI
1814 MOVL CX,(DI)
1815 ADDL $4,DI
1816
1817 MOVL (SI),CX
1818 ADDL $4,SI
1819 MOVL CX,(DI)
1820 ADDL $4,DI
1821
1822 MOVL (SI),CX
1823 ADDL $4,SI
1824 MOVL CX,(DI)
1825 ADDL $4,DI
1826
1827 MOVL (SI),CX
1828 ADDL $4,SI
1829 MOVL CX,(DI)
1830 ADDL $4,DI
1831
1832 MOVL (SI),CX
1833 ADDL $4,SI
1834 MOVL CX,(DI)
1835 ADDL $4,DI
1836
1837 MOVL (SI),CX
1838 ADDL $4,SI
1839 MOVL CX,(DI)
1840 ADDL $4,DI
1841
1842 MOVL (SI),CX
1843 ADDL $4,SI
1844 MOVL CX,(DI)
1845 ADDL $4,DI
1846
1847 MOVL (SI),CX
1848 ADDL $4,SI
1849 MOVL CX,(DI)
1850 ADDL $4,DI
1851
1852 MOVL (SI),CX
1853 ADDL $4,SI
1854 MOVL CX,(DI)
1855 ADDL $4,DI
1856
1857 MOVL (SI),CX
1858 ADDL $4,SI
1859 MOVL CX,(DI)
1860 ADDL $4,DI
1861
1862 MOVL (SI),CX
1863 ADDL $4,SI
1864 MOVL CX,(DI)
1865 ADDL $4,DI
1866
1867 MOVL (SI),CX
1868 ADDL $4,SI
1869 MOVL CX,(DI)
1870 ADDL $4,DI
1871
1872 MOVL (SI),CX
1873 ADDL $4,SI
1874 MOVL CX,(DI)
1875 ADDL $4,DI
1876
1877 MOVL (SI),CX
1878 ADDL $4,SI
1879 MOVL CX,(DI)
1880 ADDL $4,DI
1881
1882 MOVL (SI),CX
1883 ADDL $4,SI
1884 MOVL CX,(DI)
1885 ADDL $4,DI
1886
1887 MOVL (SI),CX
1888 ADDL $4,SI
1889 MOVL CX,(DI)
1890 ADDL $4,DI
1891
1892 MOVL (SI),CX
1893 ADDL $4,SI
1894 MOVL CX,(DI)
1895 ADDL $4,DI
1896
1897 MOVL (SI),CX
1898 ADDL $4,SI
1899 MOVL CX,(DI)
1900 ADDL $4,DI
1901
1902 MOVL (SI),CX
1903 ADDL $4,SI
1904 MOVL CX,(DI)
1905 ADDL $4,DI
1906
1907 MOVL (SI),CX
1908 ADDL $4,SI
1909 MOVL CX,(DI)
1910 ADDL $4,DI
1911
1912 MOVL (SI),CX
1913 ADDL $4,SI
1914 MOVL CX,(DI)
1915 ADDL $4,DI
1916
1917 MOVL (SI),CX
1918 ADDL $4,SI
1919 MOVL CX,(DI)
1920 ADDL $4,DI
1921
1922 MOVL (SI),CX
1923 ADDL $4,SI
1924 MOVL CX,(DI)
1925 ADDL $4,DI
1926
1927 MOVL (SI),CX
1928 ADDL $4,SI
1929 MOVL CX,(DI)
1930 ADDL $4,DI
1931
1932 MOVL (SI),CX
1933 ADDL $4,SI
1934 MOVL CX,(DI)
1935 ADDL $4,DI
1936
1937 MOVL (SI),CX
1938 ADDL $4,SI
1939 MOVL CX,(DI)
1940 ADDL $4,DI
1941
1942 MOVL (SI),CX
1943 ADDL $4,SI
1944 MOVL CX,(DI)
1945 ADDL $4,DI
1946
1947 MOVL (SI),CX
1948 ADDL $4,SI
1949 MOVL CX,(DI)
1950 ADDL $4,DI
1951
1952 MOVL (SI),CX
1953 ADDL $4,SI
1954 MOVL CX,(DI)
1955 ADDL $4,DI
1956
1957 MOVL (SI),CX
1958 ADDL $4,SI
1959 MOVL CX,(DI)
1960 ADDL $4,DI
1961
1962 MOVL (SI),CX
1963 ADDL $4,SI
1964 MOVL CX,(DI)
1965 ADDL $4,DI
1966
1967 MOVL (SI),CX
1968 ADDL $4,SI
1969 MOVL CX,(DI)
1970 ADDL $4,DI
1971
1972 MOVL (SI),CX
1973 ADDL $4,SI
1974 MOVL CX,(DI)
1975 ADDL $4,DI
1976
1977 MOVL (SI),CX
1978 ADDL $4,SI
1979 MOVL CX,(DI)
1980 ADDL $4,DI
1981
1982 MOVL (SI),CX
1983 ADDL $4,SI
1984 MOVL CX,(DI)
1985 ADDL $4,DI
1986
1987 MOVL (SI),CX
1988 ADDL $4,SI
1989 MOVL CX,(DI)
1990 ADDL $4,DI
1991
1992 MOVL (SI),CX
1993 ADDL $4,SI
1994 MOVL CX,(DI)
1995 ADDL $4,DI
1996
1997 MOVL (SI),CX
1998 ADDL $4,SI
1999 MOVL CX,(DI)
2000 ADDL $4,DI
2001
2002 MOVL (SI),CX
2003 ADDL $4,SI
2004 MOVL CX,(DI)
2005 ADDL $4,DI
2006
2007 MOVL (SI),CX
2008 ADDL $4,SI
2009 MOVL CX,(DI)
2010 ADDL $4,DI
2011
2012 MOVL (SI),CX
2013 ADDL $4,SI
2014 MOVL CX,(DI)
2015 ADDL $4,DI
2016
2017 MOVL (SI),CX
2018 ADDL $4,SI
2019 MOVL CX,(DI)
2020 ADDL $4,DI
2021
2022 MOVL (SI),CX
2023 ADDL $4,SI
2024 MOVL CX,(DI)
2025 ADDL $4,DI
2026
2027 MOVL (SI),CX
2028 ADDL $4,SI
2029 MOVL CX,(DI)
2030 ADDL $4,DI
2031
2032 MOVL (SI),CX
2033 ADDL $4,SI
2034 MOVL CX,(DI)
2035 ADDL $4,DI
2036
2037 MOVL (SI),CX
2038 ADDL $4,SI
2039 MOVL CX,(DI)
2040 ADDL $4,DI
2041
2042 MOVL (SI),CX
2043 ADDL $4,SI
2044 MOVL CX,(DI)
2045 ADDL $4,DI
2046
2047 MOVL (SI),CX
2048 ADDL $4,SI
2049 MOVL CX,(DI)
2050 ADDL $4,DI
2051
2052 MOVL (SI),CX
2053 ADDL $4,SI
2054 MOVL CX,(DI)
2055 ADDL $4,DI
2056
2057 MOVL (SI),CX
2058 ADDL $4,SI
2059 MOVL CX,(DI)
2060 ADDL $4,DI
2061
2062 MOVL (SI),CX
2063 ADDL $4,SI
2064 MOVL CX,(DI)
2065 ADDL $4,DI
2066
2067 MOVL (SI),CX
2068 ADDL $4,SI
2069 MOVL CX,(DI)
2070 ADDL $4,DI
2071
2072 MOVL (SI),CX
2073 ADDL $4,SI
2074 MOVL CX,(DI)
2075 ADDL $4,DI
2076
2077 MOVL (SI),CX
2078 ADDL $4,SI
2079 MOVL CX,(DI)
2080 ADDL $4,DI
2081
2082 MOVL (SI),CX
2083 ADDL $4,SI
2084 MOVL CX,(DI)
2085 ADDL $4,DI
2086
2087 MOVL (SI),CX
2088 ADDL $4,SI
2089 MOVL CX,(DI)
2090 ADDL $4,DI
2091
2092 MOVL (SI),CX
2093 ADDL $4,SI
2094 MOVL CX,(DI)
2095 ADDL $4,DI
2096
2097 MOVL (SI),CX
2098 ADDL $4,SI
2099 MOVL CX,(DI)
2100 ADDL $4,DI
2101
2102 MOVL (SI),CX
2103 ADDL $4,SI
2104 MOVL CX,(DI)
2105 ADDL $4,DI
2106
2107 MOVL (SI),CX
2108 ADDL $4,SI
2109 MOVL CX,(DI)
2110 ADDL $4,DI
2111
2112 MOVL (SI),CX
2113 ADDL $4,SI
2114 MOVL CX,(DI)
2115 ADDL $4,DI
2116
2117 MOVL (SI),CX
2118 ADDL $4,SI
2119 MOVL CX,(DI)
2120 ADDL $4,DI
2121
2122 MOVL (SI),CX
2123 ADDL $4,SI
2124 MOVL CX,(DI)
2125 ADDL $4,DI
2126
2127 MOVL (SI),CX
2128 ADDL $4,SI
2129 MOVL CX,(DI)
2130 ADDL $4,DI
2131
2132 MOVL (SI),CX
2133 ADDL $4,SI
2134 MOVL CX,(DI)
2135 ADDL $4,DI
2136
2137 MOVL (SI),CX
2138 ADDL $4,SI
2139 MOVL CX,(DI)
2140 ADDL $4,DI
2141
2142 MOVL (SI),CX
2143 ADDL $4,SI
2144 MOVL CX,(DI)
2145 ADDL $4,DI
2146
2147 MOVL (SI),CX
2148 ADDL $4,SI
2149 MOVL CX,(DI)
2150 ADDL $4,DI
2151
2152 MOVL (SI),CX
2153 ADDL $4,SI
2154 MOVL CX,(DI)
2155 ADDL $4,DI
2156
2157 MOVL (SI),CX
2158 ADDL $4,SI
2159 MOVL CX,(DI)
2160 ADDL $4,DI
2161
2162 MOVL (SI),CX
2163 ADDL $4,SI
2164 MOVL CX,(DI)
2165 ADDL $4,DI
2166
2167 MOVL (SI),CX
2168 ADDL $4,SI
2169 MOVL CX,(DI)
2170 ADDL $4,DI
2171
2172 MOVL (SI),CX
2173 ADDL $4,SI
2174 MOVL CX,(DI)
2175 ADDL $4,DI
2176
2177 MOVL (SI),CX
2178 ADDL $4,SI
2179 MOVL CX,(DI)
2180 ADDL $4,DI
2181
2182 MOVL (SI),CX
2183 ADDL $4,SI
2184 MOVL CX,(DI)
2185 ADDL $4,DI
2186
2187 MOVL (SI),CX
2188 ADDL $4,SI
2189 MOVL CX,(DI)
2190 ADDL $4,DI
2191
2192 MOVL (SI),CX
2193 ADDL $4,SI
2194 MOVL CX,(DI)
2195 ADDL $4,DI
2196
2197 MOVL (SI),CX
2198 ADDL $4,SI
2199 MOVL CX,(DI)
2200 ADDL $4,DI
2201
2202 MOVL (SI),CX
2203 ADDL $4,SI
2204 MOVL CX,(DI)
2205 ADDL $4,DI
2206
2207 MOVL (SI),CX
2208 ADDL $4,SI
2209 MOVL CX,(DI)
2210 ADDL $4,DI
2211
2212 MOVL (SI),CX
2213 ADDL $4,SI
2214 MOVL CX,(DI)
2215 ADDL $4,DI
2216
2217 MOVL (SI),CX
2218 ADDL $4,SI
2219 MOVL CX,(DI)
2220 ADDL $4,DI
2221
2222 MOVL (SI),CX
2223 ADDL $4,SI
2224 MOVL CX,(DI)
2225 ADDL $4,DI
2226
2227 MOVL (SI),CX
2228 ADDL $4,SI
2229 MOVL CX,(DI)
2230 ADDL $4,DI
2231
2232 MOVL (SI),CX
2233 ADDL $4,SI
2234 MOVL CX,(DI)
2235 ADDL $4,DI
2236
2237 MOVL (SI),CX
2238 ADDL $4,SI
2239 MOVL CX,(DI)
2240 ADDL $4,DI
2241
2242 RET
Dmitriy Vyukov350a8fc2014-05-02 17:32:42 +01002243
2244TEXT runtime·timenow(SB), NOSPLIT, $0-0
2245 JMP time·now(SB)
Keith Randall0c6b55e2014-07-16 14:16:19 -07002246
Keith Randall3306d112014-09-02 14:33:33 -07002247TEXT runtime·fastrand1(SB), NOSPLIT, $0-4
Keith Randall0c6b55e2014-07-16 14:16:19 -07002248 get_tls(CX)
2249 MOVL g(CX), AX
2250 MOVL g_m(AX), AX
2251 MOVL m_fastrand(AX), DX
2252 ADDL DX, DX
2253 MOVL DX, BX
2254 XORL $0x88888eef, DX
2255 CMOVLMI BX, DX
2256 MOVL DX, m_fastrand(AX)
2257 MOVL DX, ret+0(FP)
2258 RET
Keith Randallf4407372014-09-03 08:49:43 -07002259
2260TEXT runtime·return0(SB), NOSPLIT, $0
2261 MOVL $0, AX
2262 RET