func NewVirtual(idx Index, k Kind, s Spec) Virtual {
	return virtual{
		idx:  idx,
		kind: k,
		Spec: s,
	}
}
NewVirtual builds a Virtual register.
package reg
import (
	"errors"
	"fmt"
)
type Kind uint8
type Index uint16
type Family struct {
	Kind      Kind
	registers []Physical
}
func (f *Family) define(s Spec, idx Index, name string, flags ...Info) Physical {
	r := newregister(f, s, idx, name, flags...)
	f.add(r)
	return r
}
func (f *Family) add(r Physical) {
	if r.Kind() != f.Kind {
		panic("bad kind")
	}
	f.registers = append(f.registers, r)
}
func (f *Family) Virtual(idx Index, s Spec) Virtual {
	return NewVirtual(idx, f.Kind, s)
}
func (f *Family) Registers() []Physical {
	return append([]Physical(nil), f.registers...)
}
func (f *Family) Lookup(idx Index, s Spec) Physical {
	for _, r := range f.registers {
		if r.PhysicalIndex() == idx && r.Mask() == s.Mask() {
			return r
		}
	}
	return nil
}
type ID uint32
func newid(v uint8, kind Kind, idx Index) ID {
	return ID(v) | (ID(kind) << 8) | (ID(idx) << 16)
}
func (id ID) IsVirtual() bool { return (id & 1) == 1 }
func (id ID) IsPhysical() bool { return !id.IsVirtual() }
func (id ID) Kind() Kind { return Kind(id >> 8) }
func (id ID) Index() Index { return Index(id >> 16) }
type Register interface {
	ID() ID
	Kind() Kind
	Size() uint
	Mask() uint16
	Asm() string
	as(Spec) Register
	spec() Spec
	register()
}
func Equal(a, b Register) bool {
	return (a.ID() == b.ID()) && (a.Mask() == b.Mask())
}
type Virtual interface {
	VirtualIndex() Index
	Register
}
func ToVirtual(r Register) Virtual {
	if v, ok := r.(Virtual); ok {
		return v
	}
	return nil
}
type virtual struct {
	idx  Index
	kind Kind
	Spec
}