...

Source file src/pkg/cmd/compile/internal/x86/ggen.go

     1	// 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	
     5	package x86
     6	
     7	import (
     8		"cmd/compile/internal/gc"
     9		"cmd/internal/obj"
    10		"cmd/internal/obj/x86"
    11	)
    12	
    13	func zerorange(pp *gc.Progs, p *obj.Prog, off, cnt int64, ax *uint32) *obj.Prog {
    14		if cnt == 0 {
    15			return p
    16		}
    17		if *ax == 0 {
    18			p = pp.Appendpp(p, x86.AMOVL, obj.TYPE_CONST, 0, 0, obj.TYPE_REG, x86.REG_AX, 0)
    19			*ax = 1
    20		}
    21	
    22		if cnt <= int64(4*gc.Widthreg) {
    23			for i := int64(0); i < cnt; i += int64(gc.Widthreg) {
    24				p = pp.Appendpp(p, x86.AMOVL, obj.TYPE_REG, x86.REG_AX, 0, obj.TYPE_MEM, x86.REG_SP, off+i)
    25			}
    26		} else if !gc.Nacl && cnt <= int64(128*gc.Widthreg) {
    27			p = pp.Appendpp(p, x86.ALEAL, obj.TYPE_MEM, x86.REG_SP, off, obj.TYPE_REG, x86.REG_DI, 0)
    28			p = pp.Appendpp(p, obj.ADUFFZERO, obj.TYPE_NONE, 0, 0, obj.TYPE_ADDR, 0, 1*(128-cnt/int64(gc.Widthreg)))
    29			p.To.Sym = gc.Duffzero
    30		} else {
    31			p = pp.Appendpp(p, x86.AMOVL, obj.TYPE_CONST, 0, cnt/int64(gc.Widthreg), obj.TYPE_REG, x86.REG_CX, 0)
    32			p = pp.Appendpp(p, x86.ALEAL, obj.TYPE_MEM, x86.REG_SP, off, obj.TYPE_REG, x86.REG_DI, 0)
    33			p = pp.Appendpp(p, x86.AREP, obj.TYPE_NONE, 0, 0, obj.TYPE_NONE, 0, 0)
    34			p = pp.Appendpp(p, x86.ASTOSL, obj.TYPE_NONE, 0, 0, obj.TYPE_NONE, 0, 0)
    35		}
    36	
    37		return p
    38	}
    39	
    40	func zeroAuto(pp *gc.Progs, n *gc.Node) {
    41		// Note: this code must not clobber any registers.
    42		sym := n.Sym.Linksym()
    43		size := n.Type.Size()
    44		for i := int64(0); i < size; i += 4 {
    45			p := pp.Prog(x86.AMOVL)
    46			p.From.Type = obj.TYPE_CONST
    47			p.From.Offset = 0
    48			p.To.Type = obj.TYPE_MEM
    49			p.To.Name = obj.NAME_AUTO
    50			p.To.Reg = x86.REG_SP
    51			p.To.Offset = n.Xoffset + i
    52			p.To.Sym = sym
    53		}
    54	}
    55	
    56	func ginsnop(pp *gc.Progs) *obj.Prog {
    57		// See comment in ../amd64/ggen.go.
    58		p := pp.Prog(x86.AXCHGL)
    59		p.From.Type = obj.TYPE_REG
    60		p.From.Reg = x86.REG_AX
    61		p.To.Type = obj.TYPE_REG
    62		p.To.Reg = x86.REG_AX
    63		return p
    64	}
    65	

View as plain text