gtsocial-umbx

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

dispatch_amd64.go (5293B)


      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 
     17 package native
     18 
     19 import (
     20     `unsafe`
     21 
     22     `github.com/bytedance/sonic/internal/cpu`
     23     `github.com/bytedance/sonic/internal/native/avx`
     24     `github.com/bytedance/sonic/internal/native/avx2`
     25     `github.com/bytedance/sonic/internal/native/sse`
     26     `github.com/bytedance/sonic/internal/native/types`
     27 )
     28 
     29 const (
     30     MaxFrameSize   uintptr = 400
     31     BufPaddingSize int     = 64
     32 )
     33 
     34 var (
     35     S_f64toa uintptr
     36     S_f32toa uintptr
     37     S_i64toa uintptr
     38     S_u64toa uintptr
     39     S_lspace uintptr
     40 )
     41 
     42 var (
     43     S_quote   uintptr
     44     S_unquote uintptr
     45 )
     46 
     47 var (
     48     S_value     uintptr
     49     S_vstring   uintptr
     50     S_vnumber   uintptr
     51     S_vsigned   uintptr
     52     S_vunsigned uintptr
     53 )
     54 
     55 var (
     56     S_skip_one    uintptr
     57     S_skip_one_fast    uintptr
     58     S_get_by_path    uintptr
     59     S_skip_array  uintptr
     60     S_skip_object uintptr
     61     S_skip_number uintptr
     62 )
     63 
     64 //go:nosplit
     65 //go:noescape
     66 //goland:noinspection GoUnusedParameter
     67 func Quote(s unsafe.Pointer, nb int, dp unsafe.Pointer, dn *int, flags uint64) int
     68 
     69 //go:nosplit
     70 //go:noescape
     71 //goland:noinspection GoUnusedParameter
     72 func Unquote(s unsafe.Pointer, nb int, dp unsafe.Pointer, ep *int, flags uint64) int
     73 
     74 //go:nosplit
     75 //go:noescape
     76 //goland:noinspection GoUnusedParameter
     77 func HTMLEscape(s unsafe.Pointer, nb int, dp unsafe.Pointer, dn *int) int
     78 
     79 //go:nosplit
     80 //go:noescape
     81 //goland:noinspection GoUnusedParameter
     82 func Value(s unsafe.Pointer, n int, p int, v *types.JsonState, flags uint64) int
     83 
     84 //go:nosplit
     85 //go:noescape
     86 //goland:noinspection GoUnusedParameter
     87 func SkipOne(s *string, p *int, m *types.StateMachine, flags uint64) int
     88 
     89 //go:nosplit
     90 //go:noescape
     91 //goland:noinspection GoUnusedParameter
     92 func SkipOneFast(s *string, p *int) int
     93 
     94 //go:nosplit
     95 //go:noescape
     96 //goland:noinspection GoUnusedParameter
     97 func GetByPath(s *string, p *int, path *[]interface{}, m *types.StateMachine) int
     98 
     99 //go:nosplit
    100 //go:noescape
    101 //goland:noinspection GoUnusedParameter
    102 func ValidateOne(s *string, p *int, m *types.StateMachine) int
    103 
    104 //go:nosplit
    105 //go:noescape
    106 //goland:noinspection GoUnusedParameter
    107 func I64toa(out *byte, val int64) (ret int)
    108 
    109 //go:nosplit
    110 //go:noescape
    111 //goland:noinspection GoUnusedParameter
    112 func U64toa(out *byte, val uint64) (ret int)
    113 
    114 //go:nosplit
    115 //go:noescape
    116 //goland:noinspection GoUnusedParameter
    117 func F64toa(out *byte, val float64) (ret int)
    118 
    119 //go:nosplit
    120 //go:noescape
    121 //goland:noinspection GoUnusedParameter
    122 func ValidateUTF8(s *string, p *int, m *types.StateMachine) (ret int)
    123 
    124 //go:nosplit
    125 //go:noescape
    126 //goland:noinspection GoUnusedParameter
    127 func ValidateUTF8Fast(s *string) (ret int)
    128 
    129 func useAVX() {
    130     S_f64toa      = avx.S_f64toa
    131     S_f32toa      = avx.S_f32toa
    132     S_i64toa      = avx.S_i64toa
    133     S_u64toa      = avx.S_u64toa
    134     S_lspace      = avx.S_lspace
    135     S_quote       = avx.S_quote
    136     S_unquote     = avx.S_unquote
    137     S_value       = avx.S_value
    138     S_vstring     = avx.S_vstring
    139     S_vnumber     = avx.S_vnumber
    140     S_vsigned     = avx.S_vsigned
    141     S_vunsigned   = avx.S_vunsigned
    142     S_skip_one    = avx.S_skip_one
    143     S_skip_one_fast = avx.S_skip_one_fast
    144     S_skip_array  = avx.S_skip_array
    145     S_skip_object = avx.S_skip_object
    146     S_skip_number = avx.S_skip_number
    147     S_get_by_path = avx.S_get_by_path
    148 }
    149 
    150 func useAVX2() {
    151     S_f64toa      = avx2.S_f64toa
    152     S_f32toa      = avx2.S_f32toa
    153     S_i64toa      = avx2.S_i64toa
    154     S_u64toa      = avx2.S_u64toa
    155     S_lspace      = avx2.S_lspace
    156     S_quote       = avx2.S_quote
    157     S_unquote     = avx2.S_unquote
    158     S_value       = avx2.S_value
    159     S_vstring     = avx2.S_vstring
    160     S_vnumber     = avx2.S_vnumber
    161     S_vsigned     = avx2.S_vsigned
    162     S_vunsigned   = avx2.S_vunsigned
    163     S_skip_one    = avx2.S_skip_one
    164     S_skip_one_fast = avx2.S_skip_one_fast
    165     S_skip_array  = avx2.S_skip_array
    166     S_skip_object = avx2.S_skip_object
    167     S_skip_number = avx2.S_skip_number
    168     S_get_by_path = avx2.S_get_by_path
    169 }
    170 
    171 func useSSE() {
    172     S_f64toa = sse.S_f64toa
    173     S_f32toa = sse.S_f32toa
    174     S_i64toa = sse.S_i64toa
    175     S_u64toa = sse.S_u64toa
    176     S_lspace = sse.S_lspace
    177     S_quote = sse.S_quote
    178     S_unquote = sse.S_unquote
    179     S_value = sse.S_value
    180     S_vstring = sse.S_vstring
    181     S_vnumber = sse.S_vnumber
    182     S_vsigned = sse.S_vsigned
    183     S_vunsigned = sse.S_vunsigned
    184     S_skip_one = sse.S_skip_one
    185     S_skip_one_fast = sse.S_skip_one_fast
    186     S_skip_array = sse.S_skip_array
    187     S_skip_object = sse.S_skip_object
    188     S_skip_number = sse.S_skip_number
    189     S_get_by_path = sse.S_get_by_path
    190 }
    191 
    192 func init() {
    193     if cpu.HasAVX2 {
    194         useAVX2()
    195     } else if cpu.HasAVX {
    196         useAVX()
    197     } else if cpu.HasSSE {
    198         useSSE()
    199     } else {
    200         panic("Unsupported CPU, maybe it's too old to run Sonic.")
    201     }
    202 }