Search code examples
v8jit

Do JIT compilers include many instruction sets to compile bytecode/source to machine code?


As far is I understand the JIT compiler can take parts of bytecode/source and convert them into machine code (instructions) for the CPU that it runs on.

Does this mean that JIT compilers must know multiple instruction sets to produce machine code for different CPU models?

I tried to search how this works e.g. for V8, but I found nothing useful.


Solution

  • Your assumption is correct.

    You can see in the Github mirror for V8 that it needs to define the architecture it's running.

    // Copyright 2022 the V8 project authors. All rights reserved.
    // Use of this source code is governed by a BSD-style license that can be
    // found in the LICENSE file.
    
    #ifndef V8_CODEGEN_REGISTER_ARCH_H_
    #define V8_CODEGEN_REGISTER_ARCH_H_
    
    #include "src/codegen/register-base.h"
    
    #if V8_TARGET_ARCH_IA32
    #include "src/codegen/ia32/register-ia32.h"
    #elif V8_TARGET_ARCH_X64
    #include "src/codegen/x64/register-x64.h"
    #elif V8_TARGET_ARCH_ARM64
    #include "src/codegen/arm64/register-arm64.h"
    #elif V8_TARGET_ARCH_ARM
    #include "src/codegen/arm/register-arm.h"
    #elif V8_TARGET_ARCH_PPC || V8_TARGET_ARCH_PPC64
    #include "src/codegen/ppc/register-ppc.h"
    #elif V8_TARGET_ARCH_MIPS64
    #include "src/codegen/mips64/register-mips64.h"
    #elif V8_TARGET_ARCH_LOONG64
    #include "src/codegen/loong64/register-loong64.h"
    #elif V8_TARGET_ARCH_S390
    #include "src/codegen/s390/register-s390.h"
    #elif V8_TARGET_ARCH_RISCV32 || V8_TARGET_ARCH_RISCV64
    #include "src/codegen/riscv/register-riscv.h"
    #else
    #error Unknown architecture.
    #endif
    
    #endif  // V8_CODEGEN_REGISTER_ARCH_H_