Prepare to add cpu_arch_utility types

This commit is contained in:
Nigel Tao committed 2021-02-18 16:16:48 +11:00
1 parent 869be76fae
commit 492068f3dc
8 files changed
+77 -29

No files matched your search

+2 -3
View File
@@ -47,7 +47,6 @@ var (
typeExprARMNeon64 = a.NewTypeExpr(0, t.IDBase, t.IDARMNeon64, nil, nil, nil)
typeExprARMNeon128 = a.NewTypeExpr(0, t.IDBase, t.IDARMNeon128, nil, nil, nil)
typeExprPixelSwizzler = a.NewTypeExpr(0, t.IDBase, t.IDPixelSwizzler, nil, nil, nil)
typeExprUtility = a.NewTypeExpr(0, t.IDBase, t.IDUtility, nil, nil, nil)
)
// Prefixes are prepended to names to form a namespace and to avoid e.g.
@@ -1075,7 +1074,7 @@ func (g *gen) writeStructPrivateImpl(b *buffer, n *a.Struct) error {
for _, o := range n.Fields() {
o := o.AsField()
if o.PrivateData() || o.XType().Eq(typeExprUtility) {
if o.PrivateData() || o.XType().IsEtcUtilityType() {
continue
}
if err := g.writeCTypeName(b, o.XType(), fPrefix, o.Name().Str(g.tm)); err != nil {
@@ -1128,7 +1127,7 @@ func (g *gen) writeStructPrivateImpl(b *buffer, n *a.Struct) error {
for _, o := range n.Fields() {
o := o.AsField()
if !o.PrivateData() || o.XType().Eq(typeExprUtility) {
if !o.PrivateData() || o.XType().IsEtcUtilityType() {
continue
}
if err := g.writeCTypeName(b, o.XType(), fPrefix, o.Name().Str(g.tm)); err != nil {
+1 -1
View File
@@ -434,7 +434,7 @@ func (g *gen) writeExprUserDefinedCall(b *buffer, n *a.Expr, depth uint32) error
}
qid := recvTyp.QID()
b.printf("%s%s__%s(", g.packagePrefix(qid), qid[1].Str(g.tm), method.Ident().Str(g.tm))
if !recvTyp.Eq(typeExprUtility) {
if !recvTyp.IsEtcUtilityType() {
b.writes(addr)
if err := g.writeExpr(b, recv, false, depth); err != nil {
return err
+6 -5
View File
@@ -238,7 +238,7 @@ func (g *gen) couldHaveDerivedVar(n *a.Expr) bool {
case t.IDOpenParen:
switch n.LHS().AsExpr().Ident() {
case t.IDEmptyIOReader, t.IDEmptyIOWriter:
if n.LHS().AsExpr().LHS().AsExpr().MType().Eq(typeExprUtility) {
if n.LHS().AsExpr().LHS().AsExpr().MType().IsEtcUtilityType() {
return false
}
}
@@ -324,10 +324,11 @@ func (g *gen) writeResumeSuspend(b *buffer, f *funk, suspend bool) error {
func (g *gen) writeVars(b *buffer, f *funk, inStructDecl bool) error {
for _, n := range f.varList {
typ := n.XType()
if inStructDecl {
if typ.HasPointers() || f.varResumables == nil || !f.varResumables[n.Name()] {
continue
}
if typ.Innermost().IsEtcUtilityType() {
continue
} else if inStructDecl &&
(typ.HasPointers() || f.varResumables == nil || !f.varResumables[n.Name()]) {
continue
}
name := n.Name().Str(g.tm)
+4
View File
@@ -801,6 +801,10 @@ func (n *TypeExpr) IsCPUArchType() bool {
return n.id0 == 0 && n.id1 == t.IDBase && n.id2.IsBuiltInCPUArch()
}
func (n *TypeExpr) IsEtcUtilityType() bool {
return n.id0 == 0 && n.id1 == t.IDBase && n.id2.IsEtcUtility()
}
func (n *TypeExpr) IsIdeal() bool {
return n.id0 == 0 && n.id1 == t.IDBase && n.id2 == t.IDQIdeal
}
+11
View File
@@ -245,9 +245,14 @@ var Types = []string{
// ----
"arm_crc32_utility",
"arm_crc32_u32",
"arm_neon_utility",
"arm_neon_64",
"arm_neon_128",
"x86_sse42_utility",
"x86_m128i",
}
@@ -534,6 +539,8 @@ var Funcs = []string{
"pixel_swizzler.swizzle_interleaved_transparent_black!(" +
"dst: slice u8, dst_palette: slice u8, num_pixels: u64) u64",
// ---- arm_crc32_utility
// ---- arm_crc32_u32
"arm_crc32_u32.create(a: u32) arm_crc32_u32",
@@ -544,6 +551,8 @@ var Funcs = []string{
"arm_crc32_u32._crc32w(b: u32) arm_crc32_u32",
"arm_crc32_u32._crc32d(b: u64) arm_crc32_u32",
// ---- arm_neon_utility
// ---- arm_neon_64
// TODO: generate these methods automatically?
@@ -648,6 +657,8 @@ var Funcs = []string{
"arm_neon_128.vshlq_n_u64(b: u32) arm_neon_128",
"arm_neon_128.vshlq_n_u8(b: u32) arm_neon_128",
// ---- x86_sse42_utility
// ---- x86_m128i
"x86_m128i.load_u32!(a: u32)",
+18 -8
View File
@@ -75,10 +75,15 @@ var (
typeExprDecodeFrameOptions = a.NewTypeExpr(0, t.IDBase, t.IDDecodeFrameOptions, nil, nil, nil)
typeExprARMCRC32U32 = a.NewTypeExpr(0, t.IDBase, t.IDARMCRC32U32, nil, nil, nil)
typeExprARMNeon64 = a.NewTypeExpr(0, t.IDBase, t.IDARMNeon64, nil, nil, nil)
typeExprARMNeon128 = a.NewTypeExpr(0, t.IDBase, t.IDARMNeon128, nil, nil, nil)
typeExprX86M128I = a.NewTypeExpr(0, t.IDBase, t.IDX86M128I, nil, nil, nil)
typeExprARMCRC32Utility = a.NewTypeExpr(0, t.IDBase, t.IDARMCRC32Utility, nil, nil, nil)
typeExprARMCRC32U32 = a.NewTypeExpr(0, t.IDBase, t.IDARMCRC32U32, nil, nil, nil)
typeExprARMNeonUtility = a.NewTypeExpr(0, t.IDBase, t.IDARMNeonUtility, nil, nil, nil)
typeExprARMNeon64 = a.NewTypeExpr(0, t.IDBase, t.IDARMNeon64, nil, nil, nil)
typeExprARMNeon128 = a.NewTypeExpr(0, t.IDBase, t.IDARMNeon128, nil, nil, nil)
typeExprX86SSE42Utility = a.NewTypeExpr(0, t.IDBase, t.IDX86SSE42Utility, nil, nil, nil)
typeExprX86M128I = a.NewTypeExpr(0, t.IDBase, t.IDX86M128I, nil, nil, nil)
typeExprSliceU8 = a.NewTypeExpr(t.IDSlice, 0, 0, nil, nil, typeExprU8)
typeExprTableU8 = a.NewTypeExpr(t.IDTable, 0, 0, nil, nil, typeExprU8)
@@ -128,10 +133,15 @@ var builtInTypeMap = typeMap{
t.IDDecodeFrameOptions: typeExprDecodeFrameOptions,
t.IDARMCRC32U32: typeExprARMCRC32U32,
t.IDARMNeon64: typeExprARMNeon64,
t.IDARMNeon128: typeExprARMNeon128,
t.IDX86M128I: typeExprX86M128I,
t.IDARMCRC32Utility: typeExprARMCRC32Utility,
t.IDARMCRC32U32: typeExprARMCRC32U32,
t.IDARMNeonUtility: typeExprARMNeonUtility,
t.IDARMNeon64: typeExprARMNeon64,
t.IDARMNeon128: typeExprARMNeon128,
t.IDX86SSE42Utility: typeExprX86SSE42Utility,
t.IDX86M128I: typeExprX86M128I,
}
func (c *Checker) parseBuiltInFuncs(m map[t.QQID]*a.Func, ss []string) error {
+4 -4
View File
@@ -49,14 +49,14 @@ func calcCPUArchBits(n *a.Func) (ret cpuArchBits) {
}
func (q *checker) tcheckCPUArchBits(cab cpuArchBits, typ *a.TypeExpr) error {
if qid := typ.Innermost().QID(); qid[0] == t.IDBase {
if qid := typ.Innermost().QID(); (qid[0] == t.IDBase) && qid[1].IsBuiltInCPUArch() {
need := cpuArchBits(0)
switch qid[1] {
case t.IDARMCRC32U32:
case t.IDARMCRC32Utility, t.IDARMCRC32U32:
need = cpuArchBitsARMCRC32
case t.IDARMNeon64, t.IDARMNeon128:
case t.IDARMNeonUtility, t.IDARMNeon64, t.IDARMNeon128:
need = cpuArchBitsARMNeon
case t.IDX86M128I:
case t.IDX86SSE42Utility, t.IDX86M128I:
need = cpuArchBitsX86SSE42
}
if (cab & need) != need {
+31 -8
View File
@@ -132,6 +132,19 @@ func (x ID) IsXUnaryOp() bool { return minXOp <= x && x <= maxXOp && unary
func (x ID) IsXBinaryOp() bool { return minXOp <= x && x <= maxXOp && binaryForms[x] != 0 }
func (x ID) IsXAssociativeOp() bool { return minXOp <= x && x <= maxXOp && associativeForms[x] != 0 }
func (x ID) IsEtcUtility() bool {
if (minBuiltInCPUArch <= x) && (x <= maxBuiltInCPUArch) {
switch x {
case IDARMCRC32Utility,
IDARMNeonUtility,
IDX86SSE42Utility,
IDX86AVX2Utility:
return true
}
}
return x == IDUtility
}
// QID is a qualified ID, such as "foo.bar". QID[0] is "foo"'s ID and QID[1] is
// "bar"'s. QID[0] may be 0 for a plain "bar".
type QID [2]ID
@@ -665,16 +678,22 @@ const (
minBuiltInCPUArch = 0x300
maxBuiltInCPUArch = 0x33F
IDARMCRC32 = ID(0x300)
IDARMNeon = ID(0x301)
// If adding more CPUArch utility types, also update IsEtcUtility.
IDARMCRC32 = ID(0x300)
IDARMCRC32Utility = ID(0x301)
IDARMNeon = ID(0x302)
IDARMNeonUtility = ID(0x303)
IDARMCRC32U32 = ID(0x308)
IDARMNeon64 = ID(0x310) // 64-bit D (double-word) register
IDARMNeon128 = ID(0x311) // 128-bit Q ( quad-word) register
IDX86SSE42 = ID(0x320)
IDX86AVX2 = ID(0x321)
IDX86SSE42 = ID(0x320)
IDX86SSE42Utility = ID(0x321)
IDX86AVX2 = ID(0x322)
IDX86AVX2Utility = ID(0x323)
IDX86M128I = ID(0x330)
@@ -1092,16 +1111,20 @@ var builtInsByID = [nBuiltInIDs]string{
// -------- 0x300 block.
IDARMCRC32: "arm_crc32",
IDARMNeon: "arm_neon",
IDARMCRC32: "arm_crc32",
IDARMCRC32Utility: "arm_crc32_utility",
IDARMNeon: "arm_neon",
IDARMNeonUtility: "arm_neon_utility",
IDARMCRC32U32: "arm_crc32_u32",
IDARMNeon64: "arm_neon_64",
IDARMNeon128: "arm_neon_128",
IDX86SSE42: "x86_sse42",
IDX86AVX2: "x86_avx2",
IDX86SSE42: "x86_sse42",
IDX86SSE42Utility: "x86_sse42_utility",
IDX86AVX2: "x86_avx2",
IDX86AVX2Utility: "x86_avx2_utility",
IDX86M128I: "x86_m128i",