Add sse128_i.load_slice128

This commit is contained in:
Nigel Tao committed 2021-01-23 22:58:21 +11:00
1 parent 2f78804e62
commit d1b741338b
5 files changed
+118 -25

No files matched your search

+58 -8
View File
@@ -446,8 +446,7 @@ func (g *gen) writeBuiltinTokenWriter(b *buffer, recv *a.Expr, method t.ID, args
func (g *gen) writeBuiltinCPUArch(b *buffer, recv *a.Expr, method t.ID, args []*a.Node, sideEffectsOnly bool, depth uint32) error {
switch method {
case t.IDLoadU32:
// TODO: ensure that the receiver is a variable, not an arbitrary expression.
case t.IDLoadU32, t.IDLoadU64, t.IDLoadSlice128:
if !sideEffectsOnly {
// Generate a two part expression using the comma operator: "(etc,
// return_empty_struct call)". The final part is a function call
@@ -458,22 +457,66 @@ func (g *gen) writeBuiltinCPUArch(b *buffer, recv *a.Expr, method t.ID, args []*
if err := g.writeExpr(b, recv, false, depth); err != nil {
return err
}
b.writes(" = _mm_cvtsi32_si128((int)(")
switch method {
case t.IDLoadU32:
b.writes(" = _mm_cvtsi32_si128((int)(")
case t.IDLoadU64:
b.writes(" = _mm_cvtsi64_si128((int64_t)(")
case t.IDLoadSlice128:
b.writes(" = _mm_lddqu_si128((const __m128i*)(const void*)(")
}
if err := g.writeExpr(b, args[0].AsArg().Value(), false, depth); err != nil {
return err
}
b.writes("))")
switch method {
case t.IDLoadSlice128:
b.writes(".ptr))")
default:
b.writes("))")
}
if !sideEffectsOnly {
b.writes(", wuffs_base__make_empty_struct())")
}
return nil
case t.IDTruncateU32:
b.writes("((uint32_t)(_mm_cvtsi128_si32(")
case t.IDTruncateU32, t.IDTruncateU64, t.IDStoreSlice128:
switch method {
case t.IDTruncateU32:
b.writes("((uint32_t)(_mm_cvtsi128_si32(")
case t.IDTruncateU64:
b.writes("((uint64_t)(_mm_cvtsi128_si64(")
case t.IDStoreSlice128:
if !sideEffectsOnly {
// Generate a two part expression using the comma operator: "(etc,
// return_empty_struct call)". The final part is a function call
// (to a static inline function) instead of a struct literal, to
// avoid a "expression result unused" compiler error.
b.writes("(")
}
b.writes("_mm_storeu_si128((__m128i*)(void*)(")
if err := g.writeExpr(b, args[0].AsArg().Value(), false, depth); err != nil {
return err
}
b.writes(".ptr), ")
}
if err := g.writeExpr(b, recv, false, depth); err != nil {
return err
}
b.writes(")))")
switch method {
case t.IDStoreSlice128:
b.writes(")")
if !sideEffectsOnly {
b.writes(", wuffs_base__make_empty_struct())")
}
default:
b.writes(")))")
}
return nil
}
@@ -503,9 +546,16 @@ func (g *gen) writeBuiltinCPUArch(b *buffer, recv *a.Expr, method t.ID, args []*
}
for _, o := range args {
b.writes(", ")
if err := g.writeExpr(b, o.AsArg().Value(), false, depth); err != nil {
after := ""
v := o.AsArg().Value()
if !v.MType().IsCPUArchType() {
b.writes("(int32_t)(")
after = ")"
}
if err := g.writeExpr(b, v, false, depth); err != nil {
return err
}
b.writes(after)
}
}
b.writes(")")
+4
View File
@@ -797,6 +797,10 @@ func (n *TypeExpr) IsBool() bool {
return n.id0 == 0 && n.id1 == t.IDBase && n.id2 == t.IDBool
}
func (n *TypeExpr) IsCPUArchType() bool {
return n.id0 == 0 && n.id1 == t.IDBase && n.id2.IsBuiltInCPUArch()
}
func (n *TypeExpr) IsIdeal() bool {
return n.id0 == 0 && n.id1 == t.IDBase && n.id2 == t.IDQIdeal
}
+6 -2
View File
@@ -534,10 +534,12 @@ var Funcs = []string{
// ---- 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.load_u64!(a: u64)",
"sse128_i.load_slice128!(a: slice base.u8)",
"sse128_i.truncate_u32() u32",
"sse128_i.truncate_u64() u64",
"sse128_i.store_slice128!(a: slice base.u8)",
// TODO: generate these methods automatically?
@@ -552,6 +554,8 @@ var Funcs = []string{
"sse128_i._mm_cmpeq_epi16(b: sse128_i) sse128_i",
"sse128_i._mm_min_epi16(b: sse128_i) sse128_i",
"sse128_i._mm_packus_epi16(b: sse128_i) sse128_i",
"sse128_i._mm_slli_si128(imm8: u32) sse128_i",
"sse128_i._mm_srli_si128(imm8: u32) sse128_i",
"sse128_i._mm_sub_epi16(b: sse128_i) sse128_i",
"sse128_i._mm_sub_epi8(b: sse128_i) sse128_i",
"sse128_i._mm_unpacklo_epi8(b: sse128_i) sse128_i",
+26 -3
View File
@@ -1153,10 +1153,21 @@ func (q *checker) bcheckExprCallSpecialCases(n *a.Expr, depth uint32) (bounds, e
advance, update = au.advance, au.update
}
}
} else if recvTyp.IsCPUArchType() {
if method >= t.IDLoadSlice128 {
if m := method - t.IDLoadSlice128; m < t.ID(len(lsMethodAdvances)) {
advance, update = lsMethodAdvances[m], false
}
}
}
if (advance != nil) || (advanceExpr != nil) {
if ok, err := q.optimizeIOMethodAdvance(recv, advance, advanceExpr, update); err != nil {
subject := recv
if recv.MType().IsCPUArchType() {
subject = n.Args()[0].AsArg().Value()
}
if ok, err := q.optimizeIOMethodAdvance(subject, advance, advanceExpr, update); err != nil {
return bounds{}, err
} else if !ok {
adv := ""
@@ -1166,9 +1177,9 @@ func (q *checker) bcheckExprCallSpecialCases(n *a.Expr, depth uint32) (bounds, e
adv = advanceExpr.Str(q.tm)
}
return bounds{}, fmt.Errorf("check: could not prove %s pre-condition: %s.length() >= %s",
method.Str(q.tm), recv.Str(q.tm), adv)
method.Str(q.tm), subject.Str(q.tm), adv)
}
// TODO: drop other recv-related facts?
// TODO: drop other subject-related facts?
}
return bounds{}, errNotASpecialCase
@@ -1363,6 +1374,18 @@ var ioMethodAdvances = [...]struct {
t.IDWriteExtendedTokenFast - t.IDPeekU8: {one, true},
}
var lsMethodAdvances = [...]*big.Int{
// 128 bits is 16 bytes. 256 bits is 32 bytes. 512 bits is 64 bytes.
t.IDLoadSlice128 - t.IDLoadSlice128: sixteen,
t.IDLoadSlice256 - t.IDLoadSlice128: thirtyTwo,
t.IDLoadSlice512 - t.IDLoadSlice128: sixtyFour,
t.IDStoreSlice128 - t.IDLoadSlice128: sixteen,
t.IDStoreSlice256 - t.IDLoadSlice128: thirtyTwo,
t.IDStoreSlice512 - t.IDLoadSlice128: sixtyFour,
}
func makeConstValueExpr(tm *t.Map, cv *big.Int) (*a.Expr, error) {
id, err := tm.Insert(cv.String())
if err != nil {
+24 -12
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) IsBuiltInCPUArch() bool { return minBuiltInCPUArch <= x && x <= maxBuiltInCPUArch }
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 }
@@ -659,6 +660,9 @@ const (
// -------- 0x300 block.
minBuiltInCPUArch = 0x300
maxBuiltInCPUArch = 0x32F
// 0x30? are reserved for NEON.
IDSSE128 = ID(0x310)
@@ -671,13 +675,17 @@ const (
minBuiltInLoad = 0x380
maxBuiltInLoad = 0x387
IDLoadSlice = ID(0x380)
IDLoadU32 = ID(0x381)
IDLoadU64 = ID(0x382)
IDLoadU32 = ID(0x380)
IDLoadU64 = ID(0x381)
IDLoadSlice128 = ID(0x382)
IDLoadSlice256 = ID(0x383)
IDLoadSlice512 = ID(0x384)
IDStoreSlice = ID(0x388)
IDTruncateU32 = ID(0x389)
IDTruncateU64 = ID(0x38A)
IDTruncateU32 = ID(0x388)
IDTruncateU64 = ID(0x389)
IDStoreSlice128 = ID(0x38A)
IDStoreSlice256 = ID(0x38B)
IDStoreSlice512 = ID(0x38C)
IDCreateMMSet1EPI8 = ID(0x390)
)
@@ -1067,13 +1075,17 @@ var builtInsByID = [nBuiltInIDs]string{
IDSSE128: "sse128",
IDSSE128I: "sse128_i",
IDLoadSlice: "load_slice",
IDLoadU32: "load_u32",
IDLoadU64: "load_u64",
IDLoadU32: "load_u32",
IDLoadU64: "load_u64",
IDLoadSlice128: "load_slice128",
IDLoadSlice256: "load_slice256",
IDLoadSlice512: "load_slice512",
IDStoreSlice: "store_slice",
IDTruncateU32: "truncate_u32",
IDTruncateU64: "truncate_u64",
IDTruncateU32: "truncate_u32",
IDTruncateU64: "truncate_u64",
IDStoreSlice128: "store_slice128",
IDStoreSlice256: "store_slice256",
IDStoreSlice512: "store_slice512",
IDCreateMMSet1EPI8: "create_mm_set1_epi8",
}