pools_amd64.go 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*
  2. * Copyright 2021 ByteDance Inc.
  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. package encoder
  17. import (
  18. "reflect"
  19. "unsafe"
  20. "github.com/bytedance/sonic/internal/encoder/vars"
  21. "github.com/bytedance/sonic/internal/encoder/x86"
  22. "github.com/bytedance/sonic/internal/rt"
  23. "github.com/bytedance/sonic/option"
  24. )
  25. func ForceUseJit() {
  26. x86.SetCompiler(makeEncoderX86)
  27. pretouchType = pretouchTypeX86
  28. encodeTypedPointer = x86.EncodeTypedPointer
  29. vars.UseVM = false
  30. }
  31. func init() {
  32. if vars.UseVM {
  33. ForceUseVM()
  34. } else {
  35. ForceUseJit()
  36. }
  37. }
  38. var _KeepAlive struct {
  39. rb *[]byte
  40. vp unsafe.Pointer
  41. sb *vars.Stack
  42. fv uint64
  43. err error
  44. frame [x86.FP_offs]byte
  45. }
  46. func makeEncoderX86(vt *rt.GoType, ex ...interface{}) (interface{}, error) {
  47. pp, err := NewCompiler().Compile(vt.Pack(), ex[0].(bool))
  48. if err != nil {
  49. return nil, err
  50. }
  51. as := x86.NewAssembler(pp)
  52. as.Name = vt.String()
  53. return as.Load(), nil
  54. }
  55. func pretouchTypeX86(_vt reflect.Type, opts option.CompileOptions, v uint8) (map[reflect.Type]uint8, error) {
  56. /* compile function */
  57. compiler := NewCompiler().apply(opts)
  58. /* find or compile */
  59. vt := rt.UnpackType(_vt)
  60. if val := vars.GetProgram(vt); val != nil {
  61. return nil, nil
  62. } else if _, err := vars.ComputeProgram(vt, makeEncoderX86, v == 1); err == nil {
  63. return compiler.rec, nil
  64. } else {
  65. return nil, err
  66. }
  67. }