Commit 76536237 authored by Nicolas Pitre's avatar Nicolas Pitre Committed by Russell King

[ARM PATCH] 1110/1: fixes to the ARM checksum code

The current code is, well, broken, for both little and big endian.  The 
corner cases are not all right, and the person to blame is myself.

This patch fixes all bugs.  The resulting code was tested with all alignment 
and length combinations to test all code paths.
parent d797ebd3
...@@ -137,19 +137,19 @@ FN_ENTRY ...@@ -137,19 +137,19 @@ FN_ENTRY
4: ands len, len, #3 4: ands len, len, #3
beq .done beq .done
load1l r5 load1l r4
tst len, #2 tst len, #2
mov r4, r5, lsr #byte(0) mov r5, r4, lsr #byte(0)
beq .exit beq .exit
adcs sum, sum, r5, push #16 adcs sum, sum, r4, push #16
strb r4, [dst], #1 strb r5, [dst], #1
mov r4, r5, lsr #byte(1) mov r5, r4, lsr #byte(1)
strb r4, [dst], #1 strb r5, [dst], #1
mov r4, r5, lsr #byte(2) mov r5, r4, lsr #byte(2)
.exit: tst len, #1 .exit: tst len, #1
strneb r4, [dst], #1 strneb r5, [dst], #1
andne r4, r4, #255 andne r5, r5, #255
adcnes sum, sum, r4, lsl #byte(0) adcnes sum, sum, r5, lsl #byte(0)
/* /*
* If the dst pointer was not 16-bit aligned, we * If the dst pointer was not 16-bit aligned, we
...@@ -210,17 +210,17 @@ FN_ENTRY ...@@ -210,17 +210,17 @@ FN_ENTRY
orr r4, r4, r5, push #24 orr r4, r4, r5, push #24
str r4, [dst], #4 str r4, [dst], #4
adcs sum, sum, r4 adcs sum, sum, r4
mov r4, r5, pull #8
4: ands len, len, #3 4: ands len, len, #3
beq .done beq .done
mov r4, r5, lsr #byte(1) mov r5, r4, lsr #byte(0)
tst len, #2 tst len, #2
beq .exit beq .exit
bic r5, r5, #0xff << byte(0) adcs sum, sum, r4, push #16
adcs sum, sum, r5, push #8 strb r5, [dst], #1
strb r4, [dst], #1 mov r5, r4, lsr #byte(1)
mov r4, r5, lsr #byte(2) strb r5, [dst], #1
strb r4, [dst], #1 mov r5, r4, lsr #byte(2)
mov r4, r5, lsr #byte(3)
b .exit b .exit
.src2_aligned: mov r4, r5, pull #16 .src2_aligned: mov r4, r5, pull #16
...@@ -262,18 +262,19 @@ FN_ENTRY ...@@ -262,18 +262,19 @@ FN_ENTRY
orr r4, r4, r5, push #16 orr r4, r4, r5, push #16
str r4, [dst], #4 str r4, [dst], #4
adcs sum, sum, r4 adcs sum, sum, r4
mov r4, r5, pull #16
4: ands len, len, #3 4: ands len, len, #3
beq .done beq .done
mov r4, r5, lsr #byte(2) mov r5, r4, lsr #byte(0)
tst len, #2 tst len, #2
beq .exit beq .exit
adcs sum, sum, r5, pull #16 adcs sum, sum, r4
strb r4, [dst], #1 strb r5, [dst], #1
mov r4, r5, lsr #byte(3) mov r5, r4, lsr #byte(1)
strb r4, [dst], #1 strb r5, [dst], #1
tst len, #1 tst len, #1
beq .done beq .done
load1b r4 load1b r5
b .exit b .exit
.src3_aligned: mov r4, r5, pull #24 .src3_aligned: mov r4, r5, pull #24
...@@ -315,16 +316,17 @@ FN_ENTRY ...@@ -315,16 +316,17 @@ FN_ENTRY
orr r4, r4, r5, push #8 orr r4, r4, r5, push #8
str r4, [dst], #4 str r4, [dst], #4
adcs sum, sum, r4 adcs sum, sum, r4
mov r4, r5, pull #24
4: ands len, len, #3 4: ands len, len, #3
beq .done beq .done
mov r4, r5, lsr #byte(3) mov r5, r4, lsr #byte(0)
tst len, #2 tst len, #2
beq .exit beq .exit
adcs sum, sum, r5, pull #24 strb r5, [dst], #1
strb r4, [dst], #1 adcs sum, sum, r4
load1l r5 load1l r4
mov r4, r5, lsr #byte(0) mov r5, r4, lsr #byte(0)
strb r4, [dst], #1 strb r5, [dst], #1
adcs sum, sum, r4, push #24 adcs sum, sum, r4, push #24
mov r4, r5, lsr #byte(1) mov r5, r4, lsr #byte(1)
b .exit b .exit
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment