package base64
import (
"encoding/base64"
"github.com/segmentio/asm/cpu"
"github.com/segmentio/asm/cpu/x86"
)
const (
encLutSize = 32
decLutSize = 48
minEncodeLen = 28
minDecodeLen = 45
)
func newEncoding (encoder string ) *Encoding {
e := &Encoding {base : base64 .NewEncoding (encoder )}
if cpu .X86 .Has (x86 .AVX2 ) {
e .enableEncodeAVX2 (encoder )
e .enableDecodeAVX2 (encoder )
}
return e
}
func (e *Encoding ) enableEncodeAVX2 (encoder string ) {
tab := [encLutSize ]int8 {int8 (encoder [0 ]), int8 (encoder [letterRange ]) - letterRange }
for i , ch := range encoder [2 *letterRange :] {
tab [2 +i ] = int8 (ch ) - 2 *letterRange - int8 (i )
}
e .enc = encodeAVX2
e .enclut = tab
}
func (e *Encoding ) enableDecodeAVX2 (encoder string ) {
c62 , c63 := int8 (encoder [62 ]), int8 (encoder [63 ])
url := c63 == '_'
if url {
c63 = '/'
}
tab := [decLutSize ]int8 {
0 , 63 - c63 , 62 - c62 , 4 , -65 , -65 , -71 , -71 ,
0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
0x15 , 0x11 , 0x11 , 0x11 , 0x11 , 0x11 , 0x11 , 0x11 ,
0x11 , 0x11 , 0x13 , 0x1B , 0x1B , 0x1B , 0x1B , 0x1B ,
}
tab [(c62 &15 )+16 ] = 0x1A
tab [(c63 &15 )+16 ] = 0x1A
if url {
e .dec = decodeAVX2URI
} else {
e .dec = decodeAVX2
}
e .declut = tab
}
The pages are generated with Golds v0.6.7 . (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu .
PR and bug reports are welcome and can be submitted to the issue list .
Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds .