Change iterate variable types from ptr to slice

This commit is contained in:
Nigel Tao committed 2018-05-04 13:20:34 +10:00
1 parent d85a94360e
commit 96a549814d
8 files changed
+54 -52

No files matched your search

+7 -5
View File
@@ -238,29 +238,31 @@ func (g *gen) writeStatement(b *buffer, n *a.Node, depth uint32) error {
return err
}
b.writes(";\n")
b.printf("uint8_t* %s%s = %sslice_%s.ptr;\n", vPrefix, name, iPrefix, name)
b.printf("wuffs_base__slice_u8 %s%s = %sslice_%s;\n", vPrefix, name, iPrefix, name)
// TODO: look at n.HasContinue() and n.HasBreak().
unroll := n.Unroll().SmallPowerOf2Value()
step := n.Step().SmallPowerOf2Value()
if uStep := unroll * step; uStep != 1 {
b.printf("%s%s.len = %d;\n", vPrefix, name, step)
b.printf("uint8_t* %send0_%s = %sslice_%s.ptr + (%sslice_%s.len / %d) * %d;\n",
iPrefix, name, iPrefix, name, iPrefix, name, uStep, uStep)
b.printf("while (%s%s < %send0_%s) {\n", vPrefix, name, iPrefix, name)
b.printf("while (%s%s.ptr < %send0_%s) {\n", vPrefix, name, iPrefix, name)
for i := 0; i < unroll; i++ {
for _, o := range n.Body() {
if err := g.writeStatement(b, o, depth); err != nil {
return err
}
}
b.printf("%s%s += %d;\n", vPrefix, name, step)
b.printf("%s%s.ptr += %d;\n", vPrefix, name, step)
}
b.writes("}\n")
}
b.printf("%s%s.len = %d;\n", vPrefix, name, 1)
b.printf("uint8_t* %send1_%s = %sslice_%s.ptr + %sslice_%s.len;\n",
iPrefix, name, iPrefix, name, iPrefix, name)
b.printf("while (%s%s < %send1_%s) {\n", vPrefix, name, iPrefix, name)
b.printf("while (%s%s.ptr < %send1_%s) {\n", vPrefix, name, iPrefix, name)
tail := n.Tail()
if step == 1 {
tail = n.Body()
@@ -270,7 +272,7 @@ func (g *gen) writeStatement(b *buffer, n *a.Node, depth uint32) error {
return err
}
}
b.printf("%s%s++;\n", vPrefix, name)
b.printf("%s%s.ptr++;\n", vPrefix, name)
b.writes("}\n")
b.writes("}\n")
+1
View File
@@ -16,6 +16,7 @@
- Removed `&^`.
- Renamed `[N] T` and `[] T` types to `array[N] T` and `slice T`.
- Renamed `iterate.U` to `iterate (step:S, unroll:U)`.
- Changed iterate variable types from ptr T to slice T.
- Renamed `buf1`, `reader1`, etc to `io_buffer`, `io_reader`, etc.
- Renamed `u32`, `io_reader`, etc to `base.u32`, `base.io_reader`, etc.
- Added a `base.image_config` type.
+23 -21
View File
@@ -1663,39 +1663,41 @@ uint32_t wuffs_adler32__hasher__update(wuffs_adler32__hasher* self,
}
{
wuffs_base__slice_u8 i_slice_p = a_x;
uint8_t* v_p = i_slice_p.ptr;
wuffs_base__slice_u8 v_p = i_slice_p;
v_p.len = 1;
uint8_t* i_end0_p = i_slice_p.ptr + (i_slice_p.len / 8) * 8;
while (v_p < i_end0_p) {
v_s1 += ((uint32_t)(v_p[0]));
while (v_p.ptr < i_end0_p) {
v_s1 += ((uint32_t)(v_p.ptr[0]));
v_s2 += v_s1;
v_p += 1;
v_s1 += ((uint32_t)(v_p[0]));
v_p.ptr += 1;
v_s1 += ((uint32_t)(v_p.ptr[0]));
v_s2 += v_s1;
v_p += 1;
v_s1 += ((uint32_t)(v_p[0]));
v_p.ptr += 1;
v_s1 += ((uint32_t)(v_p.ptr[0]));
v_s2 += v_s1;
v_p += 1;
v_s1 += ((uint32_t)(v_p[0]));
v_p.ptr += 1;
v_s1 += ((uint32_t)(v_p.ptr[0]));
v_s2 += v_s1;
v_p += 1;
v_s1 += ((uint32_t)(v_p[0]));
v_p.ptr += 1;
v_s1 += ((uint32_t)(v_p.ptr[0]));
v_s2 += v_s1;
v_p += 1;
v_s1 += ((uint32_t)(v_p[0]));
v_p.ptr += 1;
v_s1 += ((uint32_t)(v_p.ptr[0]));
v_s2 += v_s1;
v_p += 1;
v_s1 += ((uint32_t)(v_p[0]));
v_p.ptr += 1;
v_s1 += ((uint32_t)(v_p.ptr[0]));
v_s2 += v_s1;
v_p += 1;
v_s1 += ((uint32_t)(v_p[0]));
v_p.ptr += 1;
v_s1 += ((uint32_t)(v_p.ptr[0]));
v_s2 += v_s1;
v_p += 1;
v_p.ptr += 1;
}
v_p.len = 1;
uint8_t* i_end1_p = i_slice_p.ptr + i_slice_p.len;
while (v_p < i_end1_p) {
v_s1 += ((uint32_t)(v_p[0]));
while (v_p.ptr < i_end1_p) {
v_s1 += ((uint32_t)(v_p.ptr[0]));
v_s2 += v_s1;
v_p++;
v_p.ptr++;
}
}
v_s1 %= 65521;
+15 -12
View File
@@ -2015,26 +2015,29 @@ uint32_t wuffs_crc32__ieee_hasher__update(wuffs_crc32__ieee_hasher* self,
v_s = (4294967295 ^ self->private_impl.f_state);
{
wuffs_base__slice_u8 i_slice_p = a_x;
uint8_t* v_p = i_slice_p.ptr;
wuffs_base__slice_u8 v_p = i_slice_p;
v_p.len = 8;
uint8_t* i_end0_p = i_slice_p.ptr + (i_slice_p.len / 8) * 8;
while (v_p < i_end0_p) {
v_s ^= ((((uint32_t)(v_p[0])) << 0) | (((uint32_t)(v_p[1])) << 8) |
(((uint32_t)(v_p[2])) << 16) | (((uint32_t)(v_p[3])) << 24));
v_s = (wuffs_crc32__ieee_table[0][v_p[7]] ^
wuffs_crc32__ieee_table[1][v_p[6]] ^
wuffs_crc32__ieee_table[2][v_p[5]] ^
wuffs_crc32__ieee_table[3][v_p[4]] ^
while (v_p.ptr < i_end0_p) {
v_s ^=
((((uint32_t)(v_p.ptr[0])) << 0) | (((uint32_t)(v_p.ptr[1])) << 8) |
(((uint32_t)(v_p.ptr[2])) << 16) | (((uint32_t)(v_p.ptr[3])) << 24));
v_s = (wuffs_crc32__ieee_table[0][v_p.ptr[7]] ^
wuffs_crc32__ieee_table[1][v_p.ptr[6]] ^
wuffs_crc32__ieee_table[2][v_p.ptr[5]] ^
wuffs_crc32__ieee_table[3][v_p.ptr[4]] ^
wuffs_crc32__ieee_table[4][255 & (v_s >> 24)] ^
wuffs_crc32__ieee_table[5][255 & (v_s >> 16)] ^
wuffs_crc32__ieee_table[6][255 & (v_s >> 8)] ^
wuffs_crc32__ieee_table[7][255 & (v_s >> 0)]);
v_p += 8;
v_p.ptr += 8;
}
v_p.len = 1;
uint8_t* i_end1_p = i_slice_p.ptr + i_slice_p.len;
while (v_p < i_end1_p) {
v_s = (wuffs_crc32__ieee_table[0][((uint8_t)((v_s & 255))) ^ v_p[0]] ^
while (v_p.ptr < i_end1_p) {
v_s = (wuffs_crc32__ieee_table[0][((uint8_t)((v_s & 255))) ^ v_p.ptr[0]] ^
(v_s >> 8));
v_p++;
v_p.ptr++;
}
}
self->private_impl.f_state = (4294967295 ^ v_s);
+2 -4
View File
@@ -304,8 +304,7 @@ func (q *checker) bcheckStatement(n *a.Node) error {
q.facts = q.facts[:0]
for _, o := range n.Variables() {
v := o.Var()
// TODO: use the XType(), not the Value().MType().
q.facts = append(q.facts, makeSliceLengthEqEq(v.Name(), v.Value().MType(), n.Step()))
q.facts = append(q.facts, makeSliceLengthEqEq(v.Name(), v.XType(), n.Step()))
}
for _, o := range n.Body() {
if err := q.bcheckStatement(o); err != nil {
@@ -319,8 +318,7 @@ func (q *checker) bcheckStatement(n *a.Node) error {
q.facts = q.facts[:0]
for _, o := range n.Variables() {
v := o.Var()
// TODO: use the XType(), not the Value().MType().
q.facts = append(q.facts, makeSliceLengthEqEq(v.Name(), v.Value().MType(), t.ID1))
q.facts = append(q.facts, makeSliceLengthEqEq(v.Name(), v.XType(), t.ID1))
}
for _, o := range n.Tail() {
if err := q.bcheckStatement(o); err != nil {
+4 -8
View File
@@ -206,17 +206,13 @@ func (q *checker) tcheckStatement(n *a.Node) error {
lTyp := n.XType()
rTyp := value.MType()
if n.IterateVariable() {
if lTyp.Decorator() != t.IDPtr {
return fmt.Errorf("check: iterate variable %q, of type %q, does not have a pointer type",
if !lTyp.IsSliceType() {
return fmt.Errorf("check: iterate variable %q, of type %q, does not have a slice type",
n.Name().Str(q.tm), lTyp.Str(q.tm))
}
if !rTyp.IsSliceType() {
return fmt.Errorf("check: iterate range %q, of type %q, does not have a slice type",
value.Str(q.tm), rTyp.Str(q.tm))
}
if !lTyp.Inner().Eq(rTyp.Inner()) {
if !lTyp.Eq(rTyp) {
return fmt.Errorf("check: cannot iterate %q of type %q over %q of type %q "+
"as their inner types don't match",
"as their types don't match",
n.Name().Str(q.tm), lTyp.Str(q.tm), value.Str(q.tm), rTyp.Str(q.tm))
}
} else if err := q.tcheckEq(n.Name(), nil, lTyp, value, rTyp); err != nil {
+1 -1
View File
@@ -34,7 +34,7 @@ pub func hasher.update(x slice base.u8)(checksum base.u32) {
in.x = in.x[:5552]
}
iterate (step:1, unroll:8)(p ptr base.u8:in.x) {
iterate (step:1, unroll:8)(p slice base.u8:in.x) {
s1 ~mod+= p[0] as base.u32
s2 ~mod+= s1
}
+1 -1
View File
@@ -27,7 +27,7 @@ pub struct ieee_hasher?(
pub func ieee_hasher.update(x slice base.u8)(checksum base.u32) {
var s base.u32 = 0xFFFFFFFF ^ this.state
iterate (step:8, unroll:1)(p ptr base.u8:in.x) {
iterate (step:8, unroll:1)(p slice base.u8:in.x) {
// TODO: explain the slicing-by-8 algorithm.
//
// TODO: bounds checking for the index expressions "p[7]" etc.