native_amd64.go 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. * Copyright 2024 CloudWeGo Authors
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. //go:generate make
  17. package base64x
  18. import (
  19. `unsafe`
  20. `github.com/bytedance/sonic/loader`
  21. )
  22. //go:nosplit
  23. func b64encode(out *[]byte, src *[]byte, mode int) {
  24. __b64encode(noEscape(unsafe.Pointer(out)), noEscape(unsafe.Pointer(src)), mode)
  25. }
  26. //go:nosplit
  27. func b64decode(out *[]byte, src unsafe.Pointer, len int, mode int) (ret int) {
  28. return __b64decode(noEscape(unsafe.Pointer(out)), noEscape(unsafe.Pointer(src)), len, mode)
  29. }
  30. // asm2asm templates
  31. var (
  32. __b64encode func(out unsafe.Pointer, src unsafe.Pointer, mod int)
  33. __b64decode func(out unsafe.Pointer, src unsafe.Pointer, len int, mod int) (ret int)
  34. )
  35. // directly jump PCs
  36. var (
  37. _subr__b64encode uintptr
  38. _subr__b64decode uintptr
  39. )
  40. var stubs = []loader.GoC{
  41. {"_b64encode", &_subr__b64encode, &__b64encode},
  42. {"_b64decode", &_subr__b64decode, &__b64decode},
  43. }
  44. func init() {
  45. if hasAVX2() {
  46. archFlags = _MODE_AVX2
  47. }
  48. loader.WrapGoC(text__native_entry__, funcs, stubs, "base64x", "base64x/native.c")
  49. }