github.com/gagliardetto/golang-go@v0.0.0-20201020153340-53909ea70814/cmd/compile/internal/x86/ggen.go (about)

     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  	"github.com/gagliardetto/golang-go/cmd/compile/internal/gc"
     9  	"github.com/gagliardetto/golang-go/cmd/internal/obj"
    10  	"github.com/gagliardetto/golang-go/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 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 ginsnop(pp *gc.Progs) *obj.Prog {
    41  	// See comment in ../amd64/ggen.go.
    42  	p := pp.Prog(x86.AXCHGL)
    43  	p.From.Type = obj.TYPE_REG
    44  	p.From.Reg = x86.REG_AX
    45  	p.To.Type = obj.TYPE_REG
    46  	p.To.Reg = x86.REG_AX
    47  	return p
    48  }