github.com/bytedance/sonic@v1.11.7-0.20240517092252-d2edb31b167b/internal/jit/arch_amd64.go (about)

     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 jit
    18  
    19  import (
    20      `github.com/twitchyliquid64/golang-asm/asm/arch`
    21      `github.com/twitchyliquid64/golang-asm/obj`
    22  )
    23  
    24  var (
    25      _AC = arch.Set("amd64")
    26  )
    27  
    28  func As(op string) obj.As {
    29      if ret, ok := _AC.Instructions[op]; ok {
    30          return ret
    31      } else {
    32          panic("invalid instruction: " + op)
    33      }
    34  }
    35  
    36  func Imm(imm int64) obj.Addr {
    37      return obj.Addr {
    38          Type   : obj.TYPE_CONST,
    39          Offset : imm,
    40      }
    41  }
    42  
    43  func Reg(reg string) obj.Addr {
    44      if ret, ok := _AC.Register[reg]; ok {
    45          return obj.Addr{Reg: ret, Type: obj.TYPE_REG}
    46      } else {
    47          panic("invalid register name: " + reg)
    48      }
    49  }
    50  
    51  func Ptr(reg obj.Addr, offs int64) obj.Addr {
    52      return obj.Addr {
    53          Reg    : reg.Reg,
    54          Type   : obj.TYPE_MEM,
    55          Offset : offs,
    56      }
    57  }
    58  
    59  func Sib(reg obj.Addr, idx obj.Addr, scale int16, offs int64) obj.Addr {
    60      return obj.Addr {
    61          Reg    : reg.Reg,
    62          Index  : idx.Reg,
    63          Scale  : scale,
    64          Type   : obj.TYPE_MEM,
    65          Offset : offs,
    66      }
    67  }