Skip to content

Commit

Permalink
refactoring, reduce duplicated code
Browse files Browse the repository at this point in the history
  • Loading branch information
emmansun authored Oct 17, 2024
1 parent e88388a commit 219f10d
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 184 deletions.
54 changes: 0 additions & 54 deletions base64_amd64.go

This file was deleted.

12 changes: 6 additions & 6 deletions base64_amd64.s
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,8 @@ GLOBL dec_reshuffle_mask<>(SB), (NOPTR+RODATA), $16
VPSHUFB tmp1, lut, tmp1; \ // get offsets and add offsets to input value.
VPADDB tmp1, in_out, in_out

//func encodeSIMD(dst, src []byte, lut *[16]byte) int
TEXT ·encodeSIMD(SB),NOSPLIT,$0
//func encodeAsm(dst, src []byte, lut *[16]byte) int
TEXT ·encodeAsm(SB),NOSPLIT,$0
MOVQ dst_base+0(FP), AX
MOVQ src_base+24(FP), BX
MOVQ src_len+32(FP), CX
Expand Down Expand Up @@ -387,8 +387,8 @@ avx2_done:
VPMADDWD mask1, in_out, in_out; \ // swap and merge 12-bit words into a 24-bit word
VPSHUFB mask2, in_out, in_out

//func decodeStdSIMD(dst, src []byte) int
TEXT ·decodeStdSIMD(SB),NOSPLIT,$0
//func decodeStdAsm(dst, src []byte) int
TEXT ·decodeStdAsm(SB),NOSPLIT,$0
MOVQ dst_base+0(FP), AX
MOVQ src_base+24(FP), BX
MOVQ src_len+32(FP), CX
Expand Down Expand Up @@ -535,8 +535,8 @@ avx2_done:
VZEROUPPER
RET

//func decodeUrlSIMD(dst, src []byte) int
TEXT ·decodeUrlSIMD(SB),NOSPLIT,$0
//func decodeUrlAsmdst, src []byte) int
TEXT ·decodeUrlAsm(SB),NOSPLIT,$0
MOVQ dst_base+0(FP), AX
MOVQ src_base+24(FP), BX
MOVQ src_len+32(FP), CX
Expand Down
10 changes: 8 additions & 2 deletions base64_ppc64x.go → base64_asm.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,15 @@
// Use of this source code is governed by a BSD 3-Clause-style
// license that can be found in the LICENSE file.

//go:build (ppc64 || ppc64le) && !purego
//go:build (amd64 || ppc64 || ppc64le) && !purego

package base64

import "golang.org/x/sys/cpu"

var useAVX2 = cpu.X86.HasAVX2
var useAVX = cpu.X86.HasAVX

//go:noescape
func encodeAsm(dst, src []byte, lut *[16]byte) int

Expand Down Expand Up @@ -35,8 +40,9 @@ func decode(enc *Encoding, dst, src []byte) (int, error) {
} else if enc.lut == &encodeURLLut {
remain = decodeUrlAsm(dst, src)
}

if remain < srcLen {
// decoded by ASM
// decoded by SIMD
remain = srcLen - remain // remain is decoded length now
src = src[remain:]
dstStart := (remain / 4) * 3
Expand Down
6 changes: 5 additions & 1 deletion base64_amd64_test.go → base64_asm_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
//go:build amd64 && !purego
// Copyright 2024 Sun Yimin. All rights reserved.
// Use of this source code is governed by a BSD 3-Clause-style
// license that can be found in the LICENSE file.

//go:build (amd64 || ppc64 || ppc64le) && !purego

package base64

Expand Down
121 changes: 0 additions & 121 deletions base64_ppc64x_test.go

This file was deleted.

0 comments on commit 219f10d

Please sign in to comment.