Skip to content

Commit

Permalink
add decode failure test case
Browse files Browse the repository at this point in the history
  • Loading branch information
emmansun authored Oct 17, 2024
1 parent 29e1504 commit 1ef3be3
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 24 deletions.
18 changes: 18 additions & 0 deletions base64_asm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,15 @@ func TestStdDecodeAsm(t *testing.T) {
}
}

func TestStdDecodeAsmWithError(t *testing.T) {
dst := make([]byte, 16)
src := []byte("-YWJjZGVmZ2hpamtsYWJjZGVmZ2hpamtsYWJjZGVmZ2hpamtsYWJjZGVmZ2hpamts")
ret := decodeStdAsm(dst, src)
if ret != len(src) {
t.Errorf("should return original length")
}
}

func TestURLEncodeAsm(t *testing.T) {
pairs := []testpair{
{"!?$*&()'-=@~0000", "IT8kKiYoKSctPUB-"},
Expand Down Expand Up @@ -100,6 +109,15 @@ func TestUrlDecodeAsm(t *testing.T) {
}
}

func TestUrlDecodeAsmWithError(t *testing.T) {
dst := make([]byte, 16)
src := []byte("IT8kKiYoKSctPUB/IT8kKiYoKSctPUB/")
ret := decodeUrlAsm(dst, src)
if ret != len(src) {
t.Errorf("should return original length")
}
}

func BenchmarkEncode(b *testing.B) {
data := make([]byte, 8192)
dst := make([]byte, StdEncoding.EncodedLen(8192))
Expand Down
48 changes: 24 additions & 24 deletions base64_s390x.s
Original file line number Diff line number Diff line change
Expand Up @@ -80,30 +80,30 @@ TEXT ·encodeAsm(SB),NOSPLIT,$0

MOVD $0, R4
loop:
VL (R2), X0
VPERM X0, X0, RESHUFFLE_MASK, X0
VN X0, MULHI_MASK, X1
VMLHH X1, MULHI_CONST, X1
VN X0, MULLO_MASK, X2
VMLHW X2, MULLO_CONST, X2
VO X1, X2, X0

VSB RANGE1_END, X0, X1
VMXB ZERO, X1, X1

VCGTB(X0, RANGE0_END, X2) // mask is 0xFF (-1) for range #[1..4] and 0x00 for range #0.
VSB X2, X1, X1

VPERM LUT, LUT, X1, X2
VAB X2, X0, X0

VPERM X0, X0, REV_BYTES, X0
VST X0, 0(R1)(R4*1)

ADD $16, R4
LAY 12(R2), R2
SUB $12, R3
CMPBGE R3, $16, loop
VL (R2), X0
VPERM X0, X0, RESHUFFLE_MASK, X0
VN X0, MULHI_MASK, X1
VMLHH X1, MULHI_CONST, X1
VN X0, MULLO_MASK, X2
VMLHW X2, MULLO_CONST, X2
VO X1, X2, X0

VSB RANGE1_END, X0, X1
VMXB ZERO, X1, X1

VCGTB(X0, RANGE0_END, X2) // mask is 0xFF (-1) for range #[1..4] and 0x00 for range #0.
VSB X2, X1, X1

VPERM LUT, LUT, X1, X2
VAB X2, X0, X0

VPERM X0, X0, REV_BYTES, X0
VST X0, 0(R1)(R4*1)

ADD $16, R4
LAY 12(R2), R2
SUB $12, R3
CMPBGE R3, $16, loop

done:
MOVD R4, ret+56(FP)
Expand Down

0 comments on commit 1ef3be3

Please sign in to comment.