mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-20 00:47:28 +01:00
std: add hasher_u32 update!, checksum_u32 methods
This commit is contained in:
1 parent
b5eee6ac4f
commit
80b1988237
7 files changed
+299
-25
No files matched your search
@@ -26,7 +26,7 @@ pub func hasher.set_quirk!(key: base.u32, value: base.u64) base.status {
|
||||
return base."#unsupported option"
|
||||
}
|
||||
|
||||
pub func hasher.update_u32!(x: roslice base.u8) base.u32 {
|
||||
pub func hasher.update!(x: roslice base.u8) {
|
||||
if not this.started {
|
||||
this.started = true
|
||||
this.state = 1
|
||||
@@ -39,6 +39,10 @@ pub func hasher.update_u32!(x: roslice base.u8) base.u32 {
|
||||
up_x86_sse42]
|
||||
}
|
||||
this.up!(x: args.x)
|
||||
}
|
||||
|
||||
pub func hasher.update_u32!(x: roslice base.u8) base.u32 {
|
||||
this.update!(x: args.x)
|
||||
return this.state
|
||||
}
|
||||
|
||||
@@ -74,3 +78,7 @@ pri func hasher.up!(x: roslice base.u8),
|
||||
} endwhile
|
||||
this.state = ((s2 & 0xFFFF) << 16) | (s1 & 0xFFFF)
|
||||
}
|
||||
|
||||
pub func hasher.checksum_u32() base.u32 {
|
||||
return this.state
|
||||
}
|
||||
@@ -28,7 +28,7 @@ pub func ieee_hasher.set_quirk!(key: base.u32, value: base.u64) base.status {
|
||||
// TODO: should it be ? instead of ! because it's public, and might need a way
|
||||
// to signal "initializer not called"? Should the return type, in the generated
|
||||
// C code, be "struct{ uint32_t checksum; wuffs_crc32__status status }"?
|
||||
pub func ieee_hasher.update_u32!(x: roslice base.u8) base.u32 {
|
||||
pub func ieee_hasher.update!(x: roslice base.u8) {
|
||||
if this.state == 0 {
|
||||
choose up = [
|
||||
up_arm_crc32,
|
||||
@@ -36,6 +36,10 @@ pub func ieee_hasher.update_u32!(x: roslice base.u8) base.u32 {
|
||||
up_x86_sse42]
|
||||
}
|
||||
this.up!(x: args.x)
|
||||
}
|
||||
|
||||
pub func ieee_hasher.update_u32!(x: roslice base.u8) base.u32 {
|
||||
this.update!(x: args.x)
|
||||
return this.state
|
||||
}
|
||||
|
||||
@@ -77,6 +81,10 @@ pri func ieee_hasher.up!(x: roslice base.u8),
|
||||
this.state = 0xFFFF_FFFF ^ s
|
||||
}
|
||||
|
||||
pub func ieee_hasher.checksum_u32() base.u32 {
|
||||
return this.state
|
||||
}
|
||||
|
||||
// The table below was created by script/print-crc32-magic-numbers.go.
|
||||
|
||||
pri const IEEE_TABLE : roarray[16] roarray[256] base.u32 = [[
|
||||
|
||||
@@ -47,7 +47,7 @@ pub func hasher.set_quirk!(key: base.u32, value: base.u64) base.status {
|
||||
return base."#unsupported option"
|
||||
}
|
||||
|
||||
pub func hasher.update_u32!(x: roslice base.u8) base.u32 {
|
||||
pub func hasher.update!(x: roslice base.u8) {
|
||||
var remaining : roslice base.u8
|
||||
|
||||
if (this.length_modulo_u32 == 0) and not this.length_overflows_u32 {
|
||||
@@ -68,7 +68,10 @@ pub func hasher.update_u32!(x: roslice base.u8) base.u32 {
|
||||
|
||||
args.x = remaining
|
||||
} endwhile
|
||||
}
|
||||
|
||||
pub func hasher.update_u32!(x: roslice base.u8) base.u32 {
|
||||
this.update!(x: args.x)
|
||||
return this.checksum_u32()
|
||||
}
|
||||
|
||||
@@ -183,7 +186,7 @@ pri func hasher.up!(x: roslice base.u8) {
|
||||
this.v3 = v3
|
||||
}
|
||||
|
||||
pri func hasher.checksum_u32() base.u32 {
|
||||
pub func hasher.checksum_u32() base.u32 {
|
||||
var ret : base.u32
|
||||
var i : base.u32[..= 16]
|
||||
var n : base.u32[..= 16]
|
||||
|
||||
Reference in new issue
Block a user