prog8/examples/bench8/crc32.p8

43 lines
1.1 KiB
Plaintext
Raw Normal View History

2022-08-12 20:02:44 +00:00
%import textio
main {
sub crc32(uword data, uword length) {
; because prog8 doesn't have 32 bits integers, we have to split up the calucation over 2 words.
; result in cx16.r0 (high word) and cx1.r1 (low word).
cx16.r0 = 0
cx16.r1 = 0
repeat length {
cx16.r0 ^= @(data) << $0008
repeat 8 {
if cx16.r0 & $8000 {
sys.clear_carry()
rol(cx16.r1)
rol(cx16.r0)
cx16.r0 ^= $04c1
cx16.r1 ^= $1db7
}
else {
sys.clear_carry()
rol(cx16.r1)
rol(cx16.r0)
}
}
data++
}
cx16.r0 ^= $ffff
cx16.r1 ^= $ffff
}
sub start() {
txt.print("calculating...")
cbm.SETTIM(0,0,0)
2022-08-12 20:02:44 +00:00
crc32($e000, $2000)
txt.print_uwhex(cx16.r0, true)
txt.print_uwhex(cx16.r1, false)
txt.nl()
txt.print_uw(cbm.RDTIM16())
2022-08-12 20:02:44 +00:00
txt.print(" jiffies")
sys.wait(100)
}
}