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