Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(621)

Side by Side Diff: src/pkg/runtime/asm_386.s

Issue 12053043: code review 12053043: runtime: reimplement reflect.call to not use stack spli... (Closed)
Patch Set: diff -r 5cdc93018bcf https://khr%40golang.org@code.google.com/p/go/ Created 11 years, 8 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/pkg/reflect/all_test.go ('k') | src/pkg/runtime/asm_amd64.s » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2009 The Go Authors. All rights reserved. 1 // Copyright 2009 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style 2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file. 3 // license that can be found in the LICENSE file.
4 4
5 #include "zasm_GOOS_GOARCH.h" 5 #include "zasm_GOOS_GOARCH.h"
6 #include "funcdata.h" 6 #include "funcdata.h"
7 7
8 TEXT _rt0_go(SB),7,$0 8 TEXT _rt0_go(SB),7,$0
9 // copy arguments forward on an even stack 9 // copy arguments forward on an even stack
10 MOVL argc+0(FP), AX 10 MOVL argc+0(FP), AX
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 // Call newstack on m->g0's stack. 237 // Call newstack on m->g0's stack.
238 MOVL m_g0(BX), BP 238 MOVL m_g0(BX), BP
239 MOVL BP, g(CX) 239 MOVL BP, g(CX)
240 MOVL (g_sched+gobuf_sp)(BP), AX 240 MOVL (g_sched+gobuf_sp)(BP), AX
241 MOVL -4(AX), BX // fault if CALL would, before smashing SP 241 MOVL -4(AX), BX // fault if CALL would, before smashing SP
242 MOVL AX, SP 242 MOVL AX, SP
243 CALL runtime·newstack(SB) 243 CALL runtime·newstack(SB)
244 MOVL $0, 0x1003 // crash if newstack returns 244 MOVL $0, 0x1003 // crash if newstack returns
245 RET 245 RET
246 246
247 // Called from reflection library. Mimics morestack, 247 // Called from panic. Mimics morestack,
248 // reuses stack growth code to create a frame 248 // reuses stack growth code to create a frame
249 // with the desired args running the desired function. 249 // with the desired args running the desired function.
250 // 250 //
251 // func call(fn *byte, arg *byte, argsize uint32). 251 // func call(fn *byte, arg *byte, argsize uint32).
252 TEXT reflect·call(SB), 7, $0-12 252 TEXT runtime·newstackcall(SB), 7, $0-12
253 get_tls(CX) 253 get_tls(CX)
254 MOVL m(CX), BX 254 MOVL m(CX), BX
255 255
256 // Save our caller's state as the PC and SP to 256 // Save our caller's state as the PC and SP to
257 // restore when returning from f. 257 // restore when returning from f.
258 MOVL 0(SP), AX // our caller's PC 258 MOVL 0(SP), AX // our caller's PC
259 MOVL AX, (m_morebuf+gobuf_pc)(BX) 259 MOVL AX, (m_morebuf+gobuf_pc)(BX)
260 LEAL 4(SP), AX // our caller's SP 260 LEAL 4(SP), AX // our caller's SP
261 MOVL AX, (m_morebuf+gobuf_sp)(BX) 261 MOVL AX, (m_morebuf+gobuf_sp)(BX)
262 MOVL g(CX), AX 262 MOVL g(CX), AX
263 MOVL AX, (m_morebuf+gobuf_g)(BX) 263 MOVL AX, (m_morebuf+gobuf_g)(BX)
264 264
265 // Save our own state as the PC and SP to restore 265 // Save our own state as the PC and SP to restore
266 // if this goroutine needs to be restarted. 266 // if this goroutine needs to be restarted.
267 » MOVL» $reflect·call(SB), (g_sched+gobuf_pc)(AX) 267 » MOVL» $runtime·newstackcall(SB), (g_sched+gobuf_pc)(AX)
268 MOVL SP, (g_sched+gobuf_sp)(AX) 268 MOVL SP, (g_sched+gobuf_sp)(AX)
269 269
270 // Set up morestack arguments to call f on a new stack. 270 // Set up morestack arguments to call f on a new stack.
271 // We set f's frame size to 1, as a hint to newstack 271 // We set f's frame size to 1, as a hint to newstack
272 » // that this is a call from reflect·call. 272 » // that this is a call from runtime·newstackcall.
273 // If it turns out that f needs a larger frame than 273 // If it turns out that f needs a larger frame than
274 // the default stack, f's usual stack growth prolog will 274 // the default stack, f's usual stack growth prolog will
275 // allocate a new segment (and recopy the arguments). 275 // allocate a new segment (and recopy the arguments).
276 MOVL 4(SP), AX // fn 276 MOVL 4(SP), AX // fn
277 MOVL 8(SP), DX // arg frame 277 MOVL 8(SP), DX // arg frame
278 MOVL 12(SP), CX // arg size 278 MOVL 12(SP), CX // arg size
279 279
280 MOVL AX, m_cret(BX) // f's PC 280 MOVL AX, m_cret(BX) // f's PC
281 MOVL DX, m_moreargp(BX) // f's argument pointer 281 MOVL DX, m_moreargp(BX) // f's argument pointer
282 MOVL CX, m_moreargsize(BX) // f's argument size 282 MOVL CX, m_moreargsize(BX) // f's argument size
283 MOVL $1, m_moreframesize(BX) // f's frame size 283 MOVL $1, m_moreframesize(BX) // f's frame size
284 284
285 // Call newstack on m->g0's stack. 285 // Call newstack on m->g0's stack.
286 MOVL m_g0(BX), BP 286 MOVL m_g0(BX), BP
287 get_tls(CX) 287 get_tls(CX)
288 MOVL BP, g(CX) 288 MOVL BP, g(CX)
289 MOVL (g_sched+gobuf_sp)(BP), SP 289 MOVL (g_sched+gobuf_sp)(BP), SP
290 CALL runtime·newstack(SB) 290 CALL runtime·newstack(SB)
291 MOVL $0, 0x1103 // crash if newstack returns 291 MOVL $0, 0x1103 // crash if newstack returns
292 RET 292 RET
293 293
294 // reflect·call: call a function with the given argument list
295 // func call(f *FuncVal, arg *byte, argsize uint32).
296 // we don't have variable-sized frames, so we use a small number
297 // of constant-sized-frame functions to encode a few bits of size in the pc.
298 // Caution: ugly multiline assembly macros in your future!
299
300 #define DISPATCH(NAME,MAXSIZE) \
301 CMPL CX, $MAXSIZE; \
302 JA 3(PC); \
303 MOVL $runtime·NAME(SB), AX; \
304 JMP AX
305 // Note: can't just "JMP runtime·NAME(SB)" - bad inlining results.
306
307 TEXT reflect·call(SB), 7, $0-12
308 MOVL argsize+8(FP), CX
309 DISPATCH(call16, 16)
310 DISPATCH(call32, 32)
311 DISPATCH(call64, 64)
312 DISPATCH(call128, 128)
313 DISPATCH(call256, 256)
314 DISPATCH(call512, 512)
315 DISPATCH(call1024, 1024)
316 DISPATCH(call2048, 2048)
317 DISPATCH(call4096, 4096)
318 DISPATCH(call8192, 8192)
319 DISPATCH(call16384, 16384)
320 DISPATCH(call32768, 32768)
321 DISPATCH(call65536, 65536)
322 DISPATCH(call131072, 131072)
323 DISPATCH(call262144, 262144)
324 DISPATCH(call524288, 524288)
325 DISPATCH(call1048576, 1048576)
326 DISPATCH(call2097152, 2097152)
327 DISPATCH(call4194304, 4194304)
328 DISPATCH(call8388608, 8388608)
329 DISPATCH(call16777216, 16777216)
330 DISPATCH(call33554432, 33554432)
331 DISPATCH(call67108864, 67108864)
332 DISPATCH(call134217728, 134217728)
333 DISPATCH(call268435456, 268435456)
334 DISPATCH(call536870912, 536870912)
335 DISPATCH(call1073741824, 1073741824)
336 MOVL $runtime·badreflectcall(SB), AX
337 JMP AX
338
339 #define CALLFN(NAME,MAXSIZE,FLAGS) \
340 TEXT runtime·NAME(SB), FLAGS, $MAXSIZE-12; \
341 /* copy arguments to stack */ \
342 MOVL argptr+4(FP), SI; \
343 MOVL argsize+8(FP), CX; \
344 MOVL SP, DI; \
345 REP;MOVSB; \
346 /* call function */ \
347 MOVL f+0(FP), DX; \
348 CALL (DX); \
349 /* copy return values back */ \
350 MOVL argptr+4(FP), DI; \
351 MOVL argsize+8(FP), CX; \
352 MOVL SP, SI; \
353 REP;MOVSB; \
354 RET
355
356 CALLFN(call16, 16, 7)
357 CALLFN(call32, 32, 7)
358 CALLFN(call64, 64, 7)
359 CALLFN(call128, 128, 0)
360 CALLFN(call256, 256, 0)
361 CALLFN(call512, 512, 0)
362 CALLFN(call1024, 1024, 0)
363 CALLFN(call2048, 2048, 0)
364 CALLFN(call4096, 4096, 0)
365 CALLFN(call8192, 8192, 0)
366 CALLFN(call16384, 16384, 0)
367 CALLFN(call32768, 32768, 0)
368 CALLFN(call65536, 65536, 0)
369 CALLFN(call131072, 131072, 0)
370 CALLFN(call262144, 262144, 0)
371 CALLFN(call524288, 524288, 0)
372 CALLFN(call1048576, 1048576, 0)
373 CALLFN(call2097152, 2097152, 0)
374 CALLFN(call4194304, 4194304, 0)
375 CALLFN(call8388608, 8388608, 0)
376 CALLFN(call16777216, 16777216, 0)
377 CALLFN(call33554432, 33554432, 0)
378 CALLFN(call67108864, 67108864, 0)
379 CALLFN(call134217728, 134217728, 0)
380 CALLFN(call268435456, 268435456, 0)
381 CALLFN(call536870912, 536870912, 0)
382 CALLFN(call1073741824, 1073741824, 0)
294 383
295 // Return point when leaving stack. 384 // Return point when leaving stack.
296 // 385 //
297 // Lessstack can appear in stack traces for the same reason 386 // Lessstack can appear in stack traces for the same reason
298 // as morestack; in that context, it has 0 arguments. 387 // as morestack; in that context, it has 0 arguments.
299 TEXT runtime·lessstack(SB), 7, $0-0 388 TEXT runtime·lessstack(SB), 7, $0-0
300 // Save return value in m->cret 389 // Save return value in m->cret
301 get_tls(CX) 390 get_tls(CX)
302 MOVL m(CX), BX 391 MOVL m(CX), BX
303 MOVL AX, m_cret(BX) 392 MOVL AX, m_cret(BX)
(...skipping 936 matching lines...) Expand 10 before | Expand all | Expand 10 after
1240 // all the bytes in common are the same, so we just need 1329 // all the bytes in common are the same, so we just need
1241 // to compare the lengths. 1330 // to compare the lengths.
1242 cmp_allsame: 1331 cmp_allsame:
1243 XORL AX, AX 1332 XORL AX, AX
1244 XORL CX, CX 1333 XORL CX, CX
1245 CMPL BX, DX 1334 CMPL BX, DX
1246 SETGT AX // 1 if alen > blen 1335 SETGT AX // 1 if alen > blen
1247 SETEQ CX // 1 if alen == blen 1336 SETEQ CX // 1 if alen == blen
1248 LEAL -1(CX)(AX*2), AX // 1,0,-1 result 1337 LEAL -1(CX)(AX*2), AX // 1,0,-1 result
1249 RET 1338 RET
OLDNEW
« no previous file with comments | « src/pkg/reflect/all_test.go ('k') | src/pkg/runtime/asm_amd64.s » ('j') | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b