mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-17 16:32:11 +01:00
Add some adler.update implementation.
This commit is contained in:
1 parent
50369c782c
commit
d770bf7534
3 files changed
+62
-1
No files matched your search
@@ -2422,5 +2422,32 @@ short_read_src:
|
||||
|
||||
uint32_t puffs_flate_adler_update(puffs_flate_adler* self,
|
||||
puffs_base_slice_u8 a_x) {
|
||||
uint32_t v_s1;
|
||||
uint32_t v_s2;
|
||||
puffs_base_slice_u8 v_remaining;
|
||||
uint64_t v_i;
|
||||
|
||||
v_s1 = ((self->private_impl.f_state) & ((1 << (16)) - 1));
|
||||
v_s2 = ((self->private_impl.f_state) >> (32 - (16)));
|
||||
while (((uint64_t)(a_x.len)) > 0) {
|
||||
v_remaining = ((puffs_base_slice_u8){});
|
||||
if (((uint64_t)(a_x.len)) > 5552) {
|
||||
v_remaining = puffs_base_slice_u8_subslice_i(a_x, 5552);
|
||||
a_x = puffs_base_slice_u8_subslice_j(a_x, 5552);
|
||||
if (((uint64_t)(a_x.len)) > 5552) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
v_i = 0;
|
||||
while (v_i < ((uint64_t)(a_x.len))) {
|
||||
v_s1 += 42;
|
||||
v_s2 += v_s1;
|
||||
v_i += 1;
|
||||
}
|
||||
v_s1 %= 65521;
|
||||
v_s2 %= 65521;
|
||||
a_x = v_remaining;
|
||||
}
|
||||
self->private_impl.f_state = (((v_s2 & 65535) << 16) | (v_s1 & 65535));
|
||||
return self->private_impl.f_state;
|
||||
}
|
||||
@@ -338,7 +338,7 @@ func (q *checker) bcheckAssignment(lhs *a.Expr, op t.ID, rhs *a.Expr) error {
|
||||
return err
|
||||
}
|
||||
|
||||
if lhs.Pure() && rhs.Pure() {
|
||||
if lhs.Pure() && rhs.Pure() && lhs.MType().IsNumType() {
|
||||
o := a.NewExpr(a.FlagsTypeChecked, t.IDXBinaryEqEq, 0, lhs.Node(), nil, rhs.Node(), nil)
|
||||
o.SetMType(lhs.MType())
|
||||
q.facts.appendFact(o)
|
||||
|
||||
@@ -48,5 +48,39 @@ pri struct adler?(
|
||||
)
|
||||
|
||||
pri func adler.update(x[] u8)(checksum u32) {
|
||||
// The magic 65521 and 5552 numbers are discussed in RFC 1950.
|
||||
|
||||
var s1 u32 = this.state.low_bits(n:16)
|
||||
var s2 u32 = this.state.high_bits(n:16)
|
||||
|
||||
while in.x.length() > 0 {
|
||||
var remaining[] u8
|
||||
if in.x.length() > 5552 {
|
||||
remaining = in.x[5552:]
|
||||
in.x = in.x[:5552]
|
||||
// TODO: this redundant if should be unnecessary.
|
||||
if in.x.length() > 5552 {
|
||||
return 0 // Unreachable.
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: can u64 be u32? Does it matter?
|
||||
var i u64
|
||||
while i < in.x.length(),
|
||||
inv in.x.length() <= 5552,
|
||||
{
|
||||
assert i < 5552 via "a < b: a < c; c <= b"(c:in.x.length())
|
||||
s1 ~+= 42 // TODO.
|
||||
s2 ~+= s1
|
||||
i += 1
|
||||
}
|
||||
|
||||
s1 %= 65521
|
||||
s2 %= 65521
|
||||
|
||||
in.x = remaining
|
||||
}
|
||||
|
||||
this.state = ((s2 & 0xFFFF) << 16) | (s1 & 0xFFFF)
|
||||
return this.state
|
||||
}
|
||||
Reference in new issue
Block a user