Add base.sse128_i

This commit is contained in:
Nigel Tao committed 2021-01-15 15:47:56 +11:00
1 parent 020b8e6903
commit afc6bb9ec3
9 files changed
+144 -15

No files matched your search

+11
View File
@@ -236,6 +236,10 @@ var Types = []string{
"pixel_swizzler",
"decode_frame_options",
// ----
"sse128_i",
}
var Funcs = []string{
@@ -523,6 +527,13 @@ var Funcs = []string{
"dst: slice u8, dst_palette: slice u8, src: slice u8) u64",
"pixel_swizzler.swizzle_interleaved_transparent_black!(" +
"dst: slice u8, dst_palette: slice u8, num_pixels: u64) u64",
// ---- sse128_i
"sse128_i.load_slice!(a: slice base.u8)",
"sse128_i.load_u32!(a: u32)",
"sse128_i.store_slice!(a: slice base.u8)",
"sse128_i.truncate_u32() u32",
}
var Interfaces = []string{
+1 -1
View File
@@ -681,7 +681,7 @@ func (c *Checker) checkFuncBody(node *a.Node) error {
}
// Fill in the TypeMap with all local variables.
if err := q.tcheckVars(n.Body()); err != nil {
if err := q.tcheckVars(calcCPUArchBits(q.astFunc), n.Body()); err != nil {
return &Error{
Err: err,
Filename: q.errFilename,
+4
View File
@@ -75,6 +75,8 @@ var (
typeExprDecodeFrameOptions = a.NewTypeExpr(0, t.IDBase, t.IDDecodeFrameOptions, nil, nil, nil)
typeExprSSE128I = a.NewTypeExpr(0, t.IDBase, t.IDSSE128I, nil, nil, nil)
typeExprSliceU8 = a.NewTypeExpr(t.IDSlice, 0, 0, nil, nil, typeExprU8)
typeExprTableU8 = a.NewTypeExpr(t.IDTable, 0, 0, nil, nil, typeExprU8)
)
@@ -122,6 +124,8 @@ var builtInTypeMap = typeMap{
t.IDPixelSwizzler: typeExprPixelSwizzler,
t.IDDecodeFrameOptions: typeExprDecodeFrameOptions,
t.IDSSE128I: typeExprSSE128I,
}
func (c *Checker) parseBuiltInFuncs(m map[t.QQID]*a.Func, ss []string) error {
+53 -9
View File
@@ -22,7 +22,41 @@ import (
t "github.com/google/wuffs/lang/token"
)
func (q *checker) tcheckVars(block []*a.Node) error {
type cpuArchBits uint32
const (
cpuArchBitsSSE128 = cpuArchBits(0x00000001)
)
func calcCPUArchBits(n *a.Func) (ret cpuArchBits) {
for _, o := range n.Asserts() {
o := o.AsAssert()
if !o.IsChooseCPUArch() {
continue
}
switch o.Condition().RHS().AsExpr().Ident() {
case t.IDSSE128:
ret |= cpuArchBitsSSE128
}
}
return ret
}
func (q *checker) tcheckCPUArchBits(cab cpuArchBits, typ *a.TypeExpr) error {
if qid := typ.Innermost().QID(); qid[0] == t.IDBase {
need := cpuArchBits(0)
switch qid[1] {
case t.IDSSE128I:
need = cpuArchBitsSSE128
}
if (cab & need) != need {
return fmt.Errorf("check: missing cpu_arch for %q", typ.Innermost().Str(q.tm))
}
}
return nil
}
func (q *checker) tcheckVars(cab cpuArchBits, block []*a.Node) error {
for _, o := range block {
if o.Kind() != a.KVar {
break
@@ -44,6 +78,9 @@ func (q *checker) tcheckVars(block []*a.Node) error {
if err := q.tcheckTypeExpr(o.XType(), 0); err != nil {
return err
}
if err := q.tcheckCPUArchBits(cab, o.XType()); err != nil {
return err
}
q.localVars[name] = o.XType()
}
return nil
@@ -549,15 +586,22 @@ func (q *checker) tcheckExprCall(n *a.Expr, depth uint32) error {
genericType1 := (*a.TypeExpr)(nil)
genericType2 := (*a.TypeExpr)(nil)
switch f.Receiver() {
case t.QID{t.IDBase, t.IDDagger1}:
genericType1 = lhs.MType().Receiver()
case t.QID{t.IDBase, t.IDDagger2}:
genericType2 = lhs.MType().Receiver()
if genericType2.Decorator() != t.IDTable {
return fmt.Errorf("check: internal error: %q is not a generic table", genericType2.Str(q.tm))
if recv := f.Receiver(); recv[0] == t.IDBase {
switch recv[1] {
case t.IDDagger1:
genericType1 = lhs.MType().Receiver()
case t.IDDagger2:
genericType2 = lhs.MType().Receiver()
if genericType2.Decorator() != t.IDTable {
return fmt.Errorf("check: internal error: %q is not a generic table", genericType2.Str(q.tm))
}
genericType1 = a.NewTypeExpr(t.IDSlice, 0, 0, nil, nil, genericType2.Inner())
}
if f.FuncName().IsBuiltInLoad() && (lhs.LHS().AsExpr().Operator() != 0) {
return fmt.Errorf(`check: %q receiver %q must be a local variable`,
f.QQID().Str(q.tm), lhs.LHS().AsExpr().Str(q.tm))
}
genericType1 = a.NewTypeExpr(t.IDSlice, 0, 0, nil, nil, genericType2.Inner())
}
// Check that the func's in type matches the arguments.
+22
View File
@@ -114,6 +114,7 @@ func (x ID) IsTightLeft() bool { return x < ID(len(isTightLeft)) && isTightLeft
func (x ID) IsTightRight() bool { return x < ID(len(isTightRight)) && isTightRight[x] }
func (x ID) IsAssign() bool { return minAssign <= x && x <= maxAssign }
func (x ID) IsBuiltInLoad() bool { return minBuiltInLoad <= x && x <= maxBuiltInLoad }
func (x ID) IsCannotAssignTo() bool { return minCannotAssignTo <= x && x <= maxCannotAssignTo }
func (x ID) IsClose() bool { return minClose <= x && x <= maxClose }
func (x ID) IsKeyword() bool { return minKeyword <= x && x <= maxKeyword }
@@ -646,6 +647,19 @@ const (
IDSSE128I = ID(0x311)
// 0x32? are reserved for AVX256.
// --------
minBuiltInLoad = 0x380
maxBuiltInLoad = 0x387
IDLoadSlice = ID(0x380)
IDLoadU32 = ID(0x381)
IDLoadU64 = ID(0x382)
IDStoreSlice = ID(0x388)
IDTruncateU32 = ID(0x389)
IDTruncateU64 = ID(0x38A)
)
var builtInsByID = [nBuiltInIDs]string{
@@ -1014,6 +1028,14 @@ var builtInsByID = [nBuiltInIDs]string{
IDSSE128: "sse128",
IDSSE128I: "sse128_i",
IDLoadSlice: "load_slice",
IDLoadU32: "load_u32",
IDLoadU64: "load_u64",
IDStoreSlice: "store_slice",
IDTruncateU32: "truncate_u32",
IDTruncateU64: "truncate_u64",
}
var builtInsByName = map[string]ID{}