From cc18d535a5171e250994425325a300ebe84665ed Mon Sep 17 00:00:00 2001 From: Andrew Ekstedt Date: Fri, 23 Aug 2024 23:14:51 -0700 Subject: [PATCH] crc32: add notw macro instead of materializing a constant 0xffffffff, do a NOT and then zero-extend the result. my qemu doesn't support the zext.w instruction, so we have to do two shifts instead. these can potentially be fused into a single instruction by the processor. --- crc32.s | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/crc32.s b/crc32.s index 8192223..de1c3ed 100644 --- a/crc32.s +++ b/crc32.s @@ -127,6 +127,14 @@ iloop2: #............................................ +.macro notw rd, rs + not \rd, \rs + #zext.w \rd, \rd + #add.uw \rd, \rs, 0 + slli \rd, \rd, 32 + srli \rd, \rd, 32 +.endm + # inputs: # a0: crc # a1: buf @@ -142,9 +150,7 @@ crc_update: mv t2, s1 mv t3, s2 # invert crc - li t0, -1 - srli t0, t0, 32 - xor a0, a0, t0 + notw a0, a0 mv s0, a0 # crc mv s1, a1 # buffer @@ -174,6 +180,5 @@ udone: # invert crc #li t0, -1 #srli t0, t0, 32 - li t0, 0xFFFFFFFF - xor a0, a0, t0 + notw a0, a0 ret