Documentation
¶
Overview ¶
Code generated by generate-inlinevm; DO NOT EDIT
Index ¶
- Constants
- Variables
- func BuildSuperscalarInline(p []SuperScalarInstruction) (ops []inlineOp)
- func CalculateCommitment(input []byte, hashIn, hashOut *[RANDOMX_HASH_SIZE]byte)
- func CompileProgramToByteCode(prog []byte, bc *ByteCode)
- func CreateSuperScalarInstruction(sins *SuperScalarInstruction, gen *blake2.Generator, instructionLen int, ...)
- func ExponentMask(entropy uint64) uint64
- func MaskRegisterExponentMantissa(f float64, mode uint64) float64
- func ResetRoundingMode(f *RegisterFile)
- func ScaleNegate(f float64) float64
- func ScheduleMop(mop *MacroOP, portbusy [][]int, cycle int, depcycle int, commit bool) int
- func ScheduleUop(uop ExecutionPort, portbusy [][]int, cycle int, commit bool) int
- func SetRoundingMode(f *RegisterFile, mode uint8)
- func SmallPositiveFloatBits(entropy uint64) float64
- func StaticExponent(entropy uint64) uint64
- func Xor(a, b float64) float64
- type ByteCode
- type ByteCodeInstruction
- type ByteCodeInstructionOp
- type Cache
- type Dataset
- type DecoderType
- type ExecutionPort
- type Flags
- type Instruction
- type MacroOP
- type MemoryBlock
- type Register
- type RegisterFile
- type RegisterLine
- type ScratchPad
- func (pad *ScratchPad) Load32(addr uint32) uint32
- func (pad *ScratchPad) Load32F(addr uint32) (lo, hi float64)
- func (pad *ScratchPad) Load32FA(addr uint32) [2]float64
- func (pad *ScratchPad) Load64(addr uint32) uint64
- func (pad *ScratchPad) Load64x8(addr uint32) *[8 * 8]byte
- func (pad *ScratchPad) Store64(addr uint32, val uint64)
- type SuperScalarCode
- type SuperScalarInstruction
- func (sins *SuperScalarInstruction) FixSrcReg()
- func (sins *SuperScalarInstruction) Reset()
- func (sins *SuperScalarInstruction) SelectDestination(cycle int, allowChainedMul bool, Registers *[8]Register, gen *blake2.Generator) bool
- func (sins *SuperScalarInstruction) SelectSource(cycle int, registers *[8]Register, gen *blake2.Generator) bool
- type SuperScalarOp
- type SuperScalarProgram
- type SuperScalarProgramFunc
- type VM
- func (vm *VM) CalculateHash(input []byte, output *[RANDOMX_HASH_SIZE]byte)
- func (vm *VM) CalculateHashFirst(input []byte)
- func (vm *VM) CalculateHashLast(output *[RANDOMX_HASH_SIZE]byte)
- func (vm *VM) CalculateHashNext(nextInput []byte, output *[RANDOMX_HASH_SIZE]byte)
- func (vm *VM) CalculateHashWithState(s *VMState, input []byte, output *[RANDOMX_HASH_SIZE]byte)
- func (vm *VM) Close() error
- func (vm *VM) SetCache(cache *Cache)
- func (vm *VM) SetDataset(dataset *Dataset)
- type VMProgramFunc
- type VMState
- type VM_Instruction
Constants ¶
const ( // RANDOMX_FLAG_LARGE_PAGES Select large page allocation for dataset RANDOMX_FLAG_LARGE_PAGES = Flags(1 << iota) // RANDOMX_FLAG_HARD_AES Selects between hardware or software AES RANDOMX_FLAG_HARD_AES // RANDOMX_FLAG_FULL_MEM Selects between full or light mode dataset RANDOMX_FLAG_FULL_MEM // RANDOMX_FLAG_JIT Enables JIT features RANDOMX_FLAG_JIT // RANDOMX_FLAG_SECURE Enables W^X for JIT code RANDOMX_FLAG_SECURE RANDOMX_FLAG_ARGON2_SSSE3 RANDOMX_FLAG_ARGON2_AVX2 // RANDOMX_FLAG_V2 Implements RandomX V2 RANDOMX_FLAG_V2 RANDOMX_FLAG_ARGON2 = RANDOMX_FLAG_ARGON2_AVX2 | RANDOMX_FLAG_ARGON2_SSSE3 )
const ( Null ExecutionPort = iota P0 = 1 P1 = 2 P5 = 4 P01 = P0 | P1 P05 = P0 | P5 P015 = P0 | P1 | P5 )
const ( S_INVALID = 0xFF S_NOP = 0xFE S_ISUB_R = 0 S_IXOR_R = 1 S_IADD_RS = 2 S_IMUL_R = 3 S_IROR_C = 4 S_IADD_C7 = 5 S_IXOR_C7 = 6 S_IADD_C8 = 7 S_IXOR_C8 = 8 S_IADD_C9 = 9 S_IXOR_C9 = 10 S_IMULH_R = 11 S_ISMULH_R = 12 S_IMUL_RCP = 13 )
const ( SS_ISUB_R = SuperScalarCode(iota) SS_IXOR_R SS_IADD_R SS_IADD_RS SS_IMUL_R SS_IMULH_R SS_ISMULH_R SS_IROL_C SS_IADD_C SS_IXOR_C SS_IMUL_C )
const ( VM_NOP = ByteCodeInstructionOp(iota) VM_IADD_RS VM_IADD_M VM_IADD_MZ VM_ISUB_R VM_ISUB_I VM_ISUB_M VM_ISUB_MZ VM_IMUL_R VM_IMUL_I VM_IMUL_M VM_IMUL_MZ VM_IMULH_R VM_IMULH_M VM_IMULH_MZ VM_ISMULH_R VM_ISMULH_M VM_ISMULH_MZ VM_INEG_R VM_IXOR_R VM_IXOR_I VM_IXOR_M VM_IXOR_MZ VM_IROR_R VM_IROR_I VM_IROL_R VM_IROL_I VM_ISWAP_R VM_FSWAP_RF VM_FSWAP_RE VM_FADD_R VM_FADD_M VM_FSUB_R VM_FSUB_M VM_FSCAL_R VM_FMUL_R VM_FDIV_M VM_FSQRT_R VM_CFROUND VM_CBRANCH VM_ISTORE )
const ArgonSaltSize uint32 = 8 //sizeof("" RANDOMX_ARGON_SALT) - 1
const CONDITIONMASK = (1 << RANDOMX_JUMP_BITS) - 1
const CONDITIONOFFSET = RANDOMX_JUMP_OFFSET
const CYCLE_MAP_SIZE int = RANDOMX_SUPERSCALAR_LATENCY + 4
const CacheLineAlignMask = (RANDOMX_DATASET_BASE_SIZE - 1) & (^(CacheLineSize - 1))
const CacheLineSize uint64 = RANDOMX_DATASET_ITEM_SIZE
const CacheSize uint64 = RANDOMX_ARGON_MEMORY * uint64(argon2.BlockSize)
const CodeAlign = 4096 //align code size to a multiple of 4 KiB
const DatasetExtraItems = RANDOMX_DATASET_EXTRA_SIZE / RANDOMX_DATASET_ITEM_SIZE
const DatasetItemCount = DatasetSize / CacheLineSize
const DatasetSize = RANDOMX_DATASET_BASE_SIZE + RANDOMX_DATASET_EXTRA_SIZE
const HIGH = 1
const LOOK_FORWARD_CYCLES int = 4
const LOW = 0
const MAX_THROWAWAY_COUNT int = 256
const Mask = CacheSize/CacheLineSize - 1
const MaxRandomXInstrCodeSize = 32 //FDIV_M requires up to 32 bytes of x86 code
const MaxSuperscalarInstrSize = 14 //IMUL_RCP requires 14 bytes of x86 code
const RANDOMX_ARGON_ITERATIONS = 3
Number of Argon2d iterations for Cache initialization.
const RANDOMX_ARGON_LANES = 1
Number of parallel lanes for Cache initialization.
const RANDOMX_ARGON_MEMORY = 262144
see reference configuration.h Cache size in KiB. Must be a power of 2.
const RANDOMX_ARGON_SALT = "RandomX\x03"
Argon2d salt
const RANDOMX_CACHE_ACCESSES = 8
Number of random Cache accesses per Dataset item. Minimum is 2.
const RANDOMX_DATASET_BASE_SIZE = 2147483648
Dataset base size in bytes. Must be a power of 2.
const RANDOMX_DATASET_EXTRA_SIZE = 33554368
Dataset extra size. Must be divisible by 64.
const RANDOMX_DATASET_ITEM_SIZE uint64 = 64
const RANDOMX_HASH_SIZE = 32
const RANDOMX_JUMP_BITS = 8
Jump condition mask size in bits.
const RANDOMX_JUMP_OFFSET = 8
Jump condition mask offset in bits. The sum of RANDOMX_JUMP_BITS and RANDOMX_JUMP_OFFSET must not exceed 16.
const RANDOMX_PROGRAM_COUNT = 8
Number of chained VM executions per hash.
const RANDOMX_PROGRAM_ITERATIONS = 2048
Number of iterations during VM execution.
const RANDOMX_PROGRAM_SIZE = 256
Number of instructions in a RandomX program. Must be divisible by 8.
const RANDOMX_SCRATCHPAD_L1 = 16384
Scratchpad L1 size in bytes. Must be a power of two (minimum 64) and less than or equal to RANDOMX_SCRATCHPAD_L2.
const RANDOMX_SCRATCHPAD_L2 = 262144
Scratchpad L2 size in bytes. Must be a power of two and less than or equal to RANDOMX_SCRATCHPAD_L3.
const RANDOMX_SCRATCHPAD_L3 = 2097152
Scratchpad L3 size in bytes. Must be a power of 2.
const RANDOMX_SUPERSCALAR_LATENCY = 170
Target latency for SuperscalarHash (in cycles of the reference CPU).
const RegisterFileSize = RegistersCount*8 + RegistersCountFloat*2*8*3
const RegisterNeedsDisplacement = 5
RegisterNeedsDisplacement x86 r13 register
const RegisterNeedsSib = 4
RegisterNeedsSib x86 r12 register
const RegistersCount = 8
const RegistersCountFloat = 4
const ReserveCodeSize = CodeAlign //function prologue/epilogue + reserve
const STOREL3CONDITION = 14
const ScratchpadL1 = RANDOMX_SCRATCHPAD_L1 / 8
const ScratchpadL1Mask = (ScratchpadL1 - 1) * 8
const ScratchpadL1Mask16 = (ScratchpadL1/2 - 1) * 16
const ScratchpadL2 = RANDOMX_SCRATCHPAD_L2 / 8
const ScratchpadL2Mask = (ScratchpadL2 - 1) * 8
const ScratchpadL2Mask16 = (ScratchpadL2/2 - 1) * 16
const ScratchpadL3 = RANDOMX_SCRATCHPAD_L3 / 8
const ScratchpadL3Mask = (ScratchpadL3 - 1) * 8
const ScratchpadL3Mask64 = (ScratchpadL3/8 - 1) * 64
const ScratchpadSize uint32 = RANDOMX_SCRATCHPAD_L3
const SuperscalarMaxSize = 3*RANDOMX_SUPERSCALAR_LATENCY + 2
const SuperscalarProgramHeader = 128 //overhead per superscalar program
Variables ¶
var ADD_EBX_I = []byte{0x81, 0xc3}
var ADD_RAX_RCX = []byte{0x48, 0x01, 0xC8}
var ADD_RDX_R = []byte{0x4c, 0x01}
var ADD_R_RAX = []byte{0x4C, 0x03}
var AND_EAX_I byte = 0x25
var AND_ECX_I = []byte{0x81, 0xe1}
var AND_OR_MOV_LDMXCSR = []byte{0x25, 0x00, 0x60, 0x00, 0x00, 0x0D, 0xC0, 0x9F, 0x00, 0x00, 0x50, 0x0F, 0xAE, 0x14, 0x24, 0x58}
var BranchesWithin32B = func() bool { a, b, c, d := asm.Cpuid(0) v := string(valAsString(b, d, c)) if v == "GenuineIntel" { family, model, stepping := familyModel(a) if family == 6 { return ((model == 0x4E) && (stepping == 0x3)) || ((model == 0x55) && ((stepping == 0x4) || (stepping == 0x7))) || ((model == 0x5E) && (stepping == 0x3)) || ((model == 0x8E) && (stepping >= 0x9) && (stepping <= 0xC)) || ((model == 0x9E) && (stepping >= 0x9) && (stepping <= 0xD)) || ((model == 0xA6) && (stepping == 0x0)) || ((model == 0xAE) && (stepping == 0xA)) } } return false }()
var CALL = 0xe8
var CodeSize = uint32(RandomXCodeSize + SuperscalarSize)
var ErrLargePagesNotSupported = errors.New("large pages not supported")
var IADD_C7 = Instruction{Opcode: S_IADD_C7, UOP: M_Add_ri, SrcOP: -1}
var IADD_C8 = Instruction{Opcode: S_IADD_C8, UOP: M_Add_ri, SrcOP: -1}
var IADD_C9 = Instruction{Opcode: S_IADD_C9, UOP: M_Add_ri, SrcOP: -1}
var IADD_RS = Instruction{Opcode: S_IADD_RS, UOP: M_Lea_SIB, SrcOP: 0}
var IMULH_R = Instruction{Opcode: S_IMULH_R, UOP_Array: []MacroOP{M_Mov_rr, M_Mul_r, M_Mov_rr}, ResultOP: 1, DstOP: 0, SrcOP: 1}
var IMUL_R = Instruction{Opcode: S_IMUL_R, UOP: M_Imul_rr, SrcOP: 0}
var IMUL_RCP = Instruction{Opcode: S_IMUL_RCP, UOP_Array: []MacroOP{M_Mov_ri64, M_Imul_r_dependent}, ResultOP: 1, DstOP: 1, SrcOP: -1}
var IROR_C = Instruction{Opcode: S_IROR_C, UOP: M_Ror_ri, SrcOP: -1}
var ISMULH_R = Instruction{Opcode: S_ISMULH_R, UOP_Array: []MacroOP{M_Mov_rr, M_Imul_r, M_Mov_rr}, ResultOP: 1, DstOP: 0, SrcOP: 1}
var ISUB_R = Instruction{Opcode: S_ISUB_R, UOP: M_Sub_rr, SrcOP: 0}
SrcOP/DstOp are used to selected registers
var IXOR_C7 = Instruction{Opcode: S_IXOR_C7, UOP: M_Xor_ri, SrcOP: -1}
var IXOR_C8 = Instruction{Opcode: S_IXOR_C8, UOP: M_Xor_ri, SrcOP: -1}
var IXOR_C9 = Instruction{Opcode: S_IXOR_C9, UOP: M_Xor_ri, SrcOP: -1}
var IXOR_R = Instruction{Opcode: S_IXOR_R, UOP: M_Xor_rr, SrcOP: 0}
var JMP byte = 0xe9
var JMP_ALIGN_PREFIX = [14][]byte{
{},
{0x2E},
{0x2E, 0x2E},
{0x2E, 0x2E, 0x2E},
{0x2E, 0x2E, 0x2E, 0x2E},
{0x2E, 0x2E, 0x2E, 0x2E, 0x2E},
{0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E},
{0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E},
{0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E},
{0x90, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E},
{0x66, 0x90, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E},
{0x66, 0x66, 0x90, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E},
{0x0F, 0x1F, 0x40, 0x00, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E},
{0x0F, 0x1F, 0x44, 0x00, 0x00, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E},
}
var JNZ = []byte{0x0f, 0x85}
var JNZ_SHORT byte = 0x75
var JZ = []byte{0x0f, 0x84}
var JZ_SHORT byte = 0x74
var LEA_32 = []byte{0x41, 0x8d}
var MOVAPD = []byte{0x66, 0x0f, 0x29}
var MOVNTI = []byte{0x4c, 0x0f, 0xc3}
var MOV_EAX_I byte = 0xb8
var MOV_RAX_I = []byte{0x48, 0xb8}
var MOV_RCX_I = []byte{0x48, 0xb9}
var MOV_RCX_RAX_SAR_RCX_63 = []byte{0x48, 0x89, 0xc1, 0x48, 0xc1, 0xf9, 0x3f}
var MUL_RCX = []byte{0x48, 0xf7, 0xe1}
var M_Add_ri = MacroOP{"add r,i", 7, 1, P015, Null, false}
Size: 7 bytes (can be optionally padded with nop to 8 or 9 bytes)
var M_Add_rr = MacroOP{"add r,r", 3, 1, P015, Null, false}
3 byte instructions
var M_Imul_r = MacroOP{"imul r", 3, 4, P1, P5, false}
var M_Imul_r_dependent = MacroOP{"imul r", 3, 3, P1, Null, true} // this is the dependent version where current instruction depends on previous instruction
latency is 1 lower
var M_Imul_rr = MacroOP{"imul r,r", 4, 3, P1, Null, false}
var M_Lea_SIB = MacroOP{"lea r,r+r*s", 4, 1, P01, Null, false}
Size: 4 bytes
var M_Mov_ri64 = MacroOP{"mov rax,i64", 10, 1, P015, Null, false}
Size: 10 bytes
var M_Mov_rr = MacroOP{"mov r,r", 3, 0, Null, Null, false}
var M_Mul_r = MacroOP{"mul r", 3, 4, P1, P5, false}
var M_Ror_ri = MacroOP{"ror r,i", 4, 1, P05, Null, false}
var M_Sub_rr = MacroOP{"sub r,r", 3, 1, P015, Null, false}
var M_Xor_ri = MacroOP{"xor r,i", 7, 1, P015, Null, false}
var M_Xor_rr = MacroOP{"xor r,r", 3, 1, P015, Null, false}
var NEG_RAX = []byte{0x48, 0xF7, 0xD8}
var NOP1 = []byte{0x90}
var NOP2 = []byte{0x66, 0x90}
var NOP3 = []byte{0x66, 0x66, 0x90}
var NOP4 = []byte{0x0F, 0x1F, 0x40, 0x00}
var NOP5 = []byte{0x0F, 0x1F, 0x44, 0x00, 0x00}
var NOP6 = []byte{0x66, 0x0F, 0x1F, 0x44, 0x00, 0x00}
var NOP7 = []byte{0x0F, 0x1F, 0x80, 0x00, 0x00, 0x00, 0x00}
var NOP8 = []byte{0x0F, 0x1F, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00}
var PADD_OPCODES = []byte{0xfc, 0xfd, 0xfe, 0xd4}
var RAX_ADD_SBB_1 = []byte{0x48, 0x83, 0xC0, 0x01, 0x48, 0x83, 0xD8, 0x00}
var RET byte = 0xc3
var REX_81 = []byte{0x49, 0x81}
var REX_ADDPD = []byte{0x66, 0x41, 0x0f, 0x58}
var REX_ADD_I = []byte{0x49, 0x81}
var REX_ADD_RM = []byte{0x4c, 0x03}
var REX_ADD_RR = []byte{0x4d, 0x03}
var REX_ANDPS_XMM12 = []byte{0x45, 0x0F, 0x54, 0xE5, 0x45, 0x0F, 0x56, 0xE6}
var REX_CMP_M32I = []byte{0x81, 0x3c, 0x06}
var REX_CMP_R32I = []byte{0x41, 0x81}
var REX_CVTDQ2PD_XMM12 = []byte{0xf3, 0x44, 0x0f, 0xe6, 0x24, 0x06}
var REX_DIVPD = []byte{0x66, 0x41, 0x0f, 0x5e}
var REX_IMUL_MEM = []byte{0x48, 0xf7, 0x2c, 0x0e}
var REX_IMUL_RM = []byte{0x4c, 0x0f, 0xaf}
var REX_IMUL_RR = []byte{0x4d, 0x0f, 0xaf}
var REX_IMUL_RRI = []byte{0x4d, 0x69}
var REX_LEA = []byte{0x4f, 0x8d}
var REX_MAXPD = []byte{0x66, 0x41, 0x0f, 0x5f}
var REX_MOV_MR = []byte{0x4c, 0x89}
var REX_MOV_R64R = []byte{0x4c, 0x8b}
var REX_MOV_RR = []byte{0x41, 0x8b}
var REX_MOV_RR64 = []byte{0x49, 0x8b}
var REX_MULPD = []byte{0x66, 0x41, 0x0f, 0x59}
var REX_MUL_M = []byte{0x48, 0xf7}
var REX_MUL_MEM = []byte{0x48, 0xf7, 0x24, 0x0e}
var REX_MUL_R = []byte{0x49, 0xf7}
var REX_NEG = []byte{0x49, 0xF7}
var REX_PADD = []byte{0x66, 0x44, 0x0f}
var REX_ROT_CL = []byte{0x49, 0xd3}
var REX_ROT_I8 = []byte{0x49, 0xc1}
var REX_SH = []byte{0x49, 0xc1}
var REX_SHR_RAX = []byte{0x48, 0xc1, 0xe8}
var REX_SHR_RDX = []byte{0x48, 0xc1, 0xea}
var REX_SUBPD = []byte{0x66, 0x41, 0x0f, 0x5c}
var REX_SUB_RM = []byte{0x4c, 0x2b}
var REX_SUB_RR = []byte{0x4d, 0x2b}
var REX_TEST = []byte{0x49, 0xF7}
var REX_XCHG = []byte{0x4d, 0x87}
var REX_XORPS = []byte{0x41, 0x0f, 0x57}
var REX_XOR_EAX = []byte{0x41, 0x33}
var REX_XOR_RAX_R64 = []byte{0x49, 0x33}
var REX_XOR_RI = []byte{0x49, 0x81}
var REX_XOR_RM = []byte{0x4c, 0x33}
var REX_XOR_RR = []byte{0x4D, 0x33}
var ROL_RAX = []byte{0x48, 0xc1, 0xc0}
var RandomXCodeSize = alignSize[uint64](ReserveCodeSize+MaxRandomXInstrCodeSize*RANDOMX_PROGRAM_SIZE, CodeAlign)
var SAR_RAX_I8 = []byte{0x48, 0xC1, 0xF8}
var SAR_RDX_I8 = []byte{0x48, 0xC1, 0xFA}
var SETS_AL_ADD_RDX_RAX = []byte{0x0F, 0x98, 0xC0, 0x48, 0x03, 0xD0}
var SHUFPD = []byte{0x66, 0x0f, 0xc6}
var SQRTPD = []byte{0x66, 0x0f, 0x51}
var SUB_EBX = []byte{0x83, 0xEB, 0x01}
var SUB_RDX_R = []byte{0x4c, 0x29}
var SuperscalarSize = alignSize[uint64](ReserveCodeSize+(SuperscalarProgramHeader+MaxSuperscalarInstrSize*SuperscalarMaxSize)*RANDOMX_CACHE_ACCESSES, CodeAlign)
var TEST_EAX_60SL13 = []byte{0xa9, 0x00, 0x80, 0x07, 0x00}
var TEST_RDX_RDX = []byte{0x48, 0x85, 0xD2}
var XOR_EAX_EAX = []byte{0x33, 0xC0}
var XOR_ECX_ECX = []byte{0x33, 0xC9}
Functions ¶
func BuildSuperscalarInline ¶ added in v4.2.0
func BuildSuperscalarInline(p []SuperScalarInstruction) (ops []inlineOp)
func CalculateCommitment ¶
func CalculateCommitment(input []byte, hashIn, hashOut *[RANDOMX_HASH_SIZE]byte)
CalculateCommitment Calculate a RandomX commitment from a RandomX hash and its input.
func CompileProgramToByteCode ¶
CompileProgramToByteCode this will interpret single vm instruction into executable opcodes reference https://github.com/tevador/RandomX/blob/master/doc/specs.md#52-integer-instructions
func CreateSuperScalarInstruction ¶
func CreateSuperScalarInstruction(sins *SuperScalarInstruction, gen *blake2.Generator, instructionLen int, decoderType DecoderType, last, first bool)
func ExponentMask ¶
func ResetRoundingMode ¶
func ResetRoundingMode(f *RegisterFile)
func ScaleNegate ¶
func ScheduleMop ¶
func ScheduleUop ¶
func ScheduleUop(uop ExecutionPort, portbusy [][]int, cycle int, commit bool) int
ScheduleUop schedule the uop as early as possible
func SetRoundingMode ¶
func SetRoundingMode(f *RegisterFile, mode uint8)
func SmallPositiveFloatBits ¶
func StaticExponent ¶
Types ¶
type ByteCode ¶
type ByteCode [RANDOMX_PROGRAM_SIZE]ByteCodeInstruction
func (*ByteCode) Execute ¶
func (c *ByteCode) Execute(f *RegisterFile, pad *ScratchPad, eMask [2]uint64, v2 bool)
Execute Runs a RandomX program with the given register file and scratchpad Warning: This will call asm.SetRoundingMode directly It is the caller's responsibility to set and restore the mode to RoundingModeToNearest between full executions Additionally, runtime.LockOSThread and defer runtime.UnlockOSThread is recommended to prevent other goroutines sharing these changes
type ByteCodeInstruction ¶
type ByteCodeInstructionOp ¶
type ByteCodeInstructionOp int
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
func NewCache ¶
NewCache Creates a randomx_cache structure and allocates memory for RandomX Cache. * * @param flags is any combination of these 2 flags (each flag can be set or not set): * RANDOMX_FLAG_LARGE_PAGES - allocate memory in large pages * RANDOMX_FLAG_JIT - create cache structure with JIT compilation support; this makes * subsequent Dataset initialization faster * Optionally, one of these two flags may be selected: * RANDOMX_FLAG_ARGON2_SSSE3 - optimized Argon2 for CPUs with the SSSE3 instruction set * makes subsequent cache initialization faster * RANDOMX_FLAG_ARGON2_AVX2 - optimized Argon2 for CPUs with the AVX2 instruction set * makes subsequent cache initialization faster * * @return Pointer to an allocated randomx_cache structure. * Returns NULL if: * (1) memory allocation fails * (2) the RANDOMX_FLAG_JIT is set and JIT compilation is not supported on the current platform * (3) an invalid or unsupported RANDOMX_FLAG_ARGON2 value is set */
func (*Cache) DatasetInit ¶ added in v4.5.0
func (c *Cache) DatasetInit(dataset []RegisterLine, startItem, endItem uint64)
func (*Cache) GetMemory ¶
func (c *Cache) GetMemory() *[RANDOMX_ARGON_MEMORY]MemoryBlock
func (*Cache) Init ¶
Init Initializes the cache memory and SuperscalarHash using the provided key value. Does nothing if called again with the same key value.
func (*Cache) InitDatasetItem ¶ added in v4.5.0
func (c *Cache) InitDatasetItem(rl *RegisterLine, itemNumber uint64)
type Dataset ¶
type Dataset struct {
// contains filtered or unexported fields
}
func NewDataset ¶
NewDataset Creates a randomx_dataset structure and allocates memory for RandomX Dataset. Only one flag is supported (can be set or not set): RANDOMX_FLAG_LARGE_PAGES - allocate memory in large pages Returns nil if allocation fails
func (*Dataset) InitDataset ¶
func (*Dataset) InitDatasetParallel ¶
func (*Dataset) Memory ¶
func (d *Dataset) Memory() []RegisterLine
Memory Returns a pointer to the internal memory buffer of the dataset structure. The size of the internal memory buffer is DatasetItemCount * RANDOMX_DATASET_ITEM_SIZE.
type DecoderType ¶
type DecoderType int
const Decoder3310 DecoderType = 5
const Decoder3733 DecoderType = 2
const Decoder4444 DecoderType = 4
const Decoder484 DecoderType = 0
const Decoder493 DecoderType = 3
const Decoder7333 DecoderType = 1
func FetchNextDecoder ¶
func FetchNextDecoder(ins *Instruction, cycle int, mulcount int, gen *blake2.Generator) DecoderType
func (DecoderType) GetSize ¶
func (d DecoderType) GetSize() int
func (DecoderType) String ¶
func (d DecoderType) String() string
type ExecutionPort ¶
type ExecutionPort byte
type Flags ¶
type Flags uint64
const RANDOMX_FLAG_DEFAULT Flags = 0
func GetFlags ¶
func GetFlags() (flags Flags)
GetFlags The recommended flags to be used on the current machine. Does not include: * RANDOMX_FLAG_LARGE_PAGES * RANDOMX_FLAG_FULL_MEM * RANDOMX_FLAG_SECURE These flags must be added manually if desired.
On OpenBSD RANDOMX_FLAG_SECURE is enabled by default in JIT mode as W^X is enforced by the OS.
type Instruction ¶
type Instruction struct {
Opcode byte
UOP MacroOP
SrcOP int
ResultOP int
DstOP int
UOP_Array []MacroOP
}
func (*Instruction) GetLatency ¶
func (ins *Instruction) GetLatency() int
func (*Instruction) GetSize ¶
func (ins *Instruction) GetSize() int
func (*Instruction) GetUOPCount ¶
func (ins *Instruction) GetUOPCount() int
func (*Instruction) IsSimple ¶
func (ins *Instruction) IsSimple() bool
type MacroOP ¶
type MacroOP struct {
Name string
Size int
Latency int
UOP1 ExecutionPort
UOP2 ExecutionPort
Dependent bool
}
func (*MacroOP) GetLatency ¶
func (*MacroOP) GetUOP1 ¶
func (m *MacroOP) GetUOP1() ExecutionPort
func (*MacroOP) GetUOP2 ¶
func (m *MacroOP) GetUOP2() ExecutionPort
func (*MacroOP) IsDependent ¶
func (*MacroOP) IsEliminated ¶
type MemoryBlock ¶
func (*MemoryBlock) GetLine ¶
func (m *MemoryBlock) GetLine(addr uint64) *RegisterLine
type RegisterFile ¶
type RegisterFile struct {
R RegisterLine
F [RegistersCountFloat][2]float64
E [RegistersCountFloat][2]float64
A [RegistersCountFloat][2]float64
FPRC uint8
}
func (*RegisterFile) Clear ¶
func (rf *RegisterFile) Clear()
func (*RegisterFile) Memory ¶
func (rf *RegisterFile) Memory() *[RegisterFileSize]byte
func (*RegisterFile) MemoryE ¶ added in v4.6.1
func (rf *RegisterFile) MemoryE() *[RegistersCountFloat * 2 * 8]byte
func (*RegisterFile) MemoryF ¶ added in v4.6.1
func (rf *RegisterFile) MemoryF() *[RegistersCountFloat * 2 * 8]byte
func (*RegisterFile) MemoryR ¶ added in v4.6.1
func (rf *RegisterFile) MemoryR() *[RegistersCount * 8]byte
type RegisterLine ¶
type RegisterLine [RegistersCount]uint64
func ExecuteSuperscalarInline ¶ added in v4.2.0
func ExecuteSuperscalarInline(ops []inlineOp, rl RegisterLine) RegisterLine
ExecuteSuperscalarInline execute the superscalar program via inline ops
func (*RegisterLine) Init ¶ added in v4.1.0
func (rl *RegisterLine) Init(itemNumber uint64)
type ScratchPad ¶
type ScratchPad [ScratchpadSize]byte
func (*ScratchPad) Load32 ¶
func (pad *ScratchPad) Load32(addr uint32) uint32
func (*ScratchPad) Load32F ¶
func (pad *ScratchPad) Load32F(addr uint32) (lo, hi float64)
func (*ScratchPad) Load32FA ¶
func (pad *ScratchPad) Load32FA(addr uint32) [2]float64
func (*ScratchPad) Load64 ¶
func (pad *ScratchPad) Load64(addr uint32) uint64
func (*ScratchPad) Load64x8 ¶ added in v4.6.1
func (pad *ScratchPad) Load64x8(addr uint32) *[8 * 8]byte
func (*ScratchPad) Store64 ¶
func (pad *ScratchPad) Store64(addr uint32, val uint64)
type SuperScalarCode ¶ added in v4.1.0
type SuperScalarCode uint8
func (SuperScalarCode) String ¶ added in v4.2.0
func (code SuperScalarCode) String() string
type SuperScalarInstruction ¶
type SuperScalarInstruction struct {
Opcode byte
Dst uint8
Src uint8
Mod byte
Imm32 uint32
Imm64 uint64
OpGroup int
OpGroupPar int
GroupParIsSource int
CanReuse bool
// contains filtered or unexported fields
}
SuperScalarInstruction superscalar program is built with superscalar instructions
func (*SuperScalarInstruction) FixSrcReg ¶
func (sins *SuperScalarInstruction) FixSrcReg()
func (*SuperScalarInstruction) Reset ¶
func (sins *SuperScalarInstruction) Reset()
func (*SuperScalarInstruction) SelectDestination ¶
func (*SuperScalarInstruction) SelectSource ¶
type SuperScalarOp ¶ added in v4.1.0
type SuperScalarOp struct {
Opcode SuperScalarCode
Dst, Src uint8
Imm uint64
}
func (SuperScalarOp) String ¶ added in v4.2.0
func (op SuperScalarOp) String() string
type SuperScalarProgram ¶
type SuperScalarProgram []SuperScalarInstruction
func BuildSuperScalarProgram ¶
func BuildSuperScalarProgram(gen *blake2.Generator) SuperScalarProgram
func (SuperScalarProgram) AddressRegister ¶
func (p SuperScalarProgram) AddressRegister() uint8
func (SuperScalarProgram) Program ¶
func (p SuperScalarProgram) Program() []SuperScalarInstruction
type SuperScalarProgramFunc ¶
type SuperScalarProgramFunc []byte
func (SuperScalarProgramFunc) Close ¶
func (f SuperScalarProgramFunc) Close() error
type VM ¶
type VM struct {
HardAES *aes.HardAES
Cache *Cache
Dataset *Dataset
State *VMState
// contains filtered or unexported fields
}
func NewVM ¶
NewVM Creates and initializes a RandomX virtual machine. * * @param flags is any combination of these 5 flags (each flag can be set or not set): * RANDOMX_FLAG_LARGE_PAGES - allocate scratchpad memory in large pages * RANDOMX_FLAG_HARD_AES - virtual machine will use hardware accelerated AES * RANDOMX_FLAG_FULL_MEM - virtual machine will use the full dataset * RANDOMX_FLAG_JIT - virtual machine will use a JIT compiler * RANDOMX_FLAG_SECURE - when combined with RANDOMX_FLAG_JIT, the JIT pages are never * writable and executable at the same time (W^X policy) * RANDOMX_FLAG_V2 - virtual machine will implement RandomX V2 * The numeric values of the first 4 flags are ordered so that a higher value will provide * faster hash calculation and a lower numeric value will provide higher portability. * Using RANDOMX_FLAG_DEFAULT (all flags not set) works on all platforms, but is the slowest. * @param cache is a pointer to an initialized randomx_cache structure. Can be * NULL if RANDOMX_FLAG_FULL_MEM is set. * @param dataset is a pointer to a randomx_dataset structure. Can be NULL * if RANDOMX_FLAG_FULL_MEM is not set. * * @return Pointer to an initialized randomx_vm structure. * Returns NULL if: * (1) Scratchpad memory allocation fails. * (2) The requested initialization flags are not supported on the current platform. * (3) cache parameter is NULL and RANDOMX_FLAG_FULL_MEM is not set * (4) dataset parameter is NULL and RANDOMX_FLAG_FULL_MEM is set */
func (*VM) CalculateHash ¶
func (vm *VM) CalculateHash(input []byte, output *[RANDOMX_HASH_SIZE]byte)
CalculateHash Calculates a RandomX hash value.
func (*VM) CalculateHashFirst ¶
CalculateHashFirst will begin a hash calculation.
func (*VM) CalculateHashLast ¶
func (vm *VM) CalculateHashLast(output *[RANDOMX_HASH_SIZE]byte)
CalculateHashLast will output the hash value of the previous input.
func (*VM) CalculateHashNext ¶
func (vm *VM) CalculateHashNext(nextInput []byte, output *[RANDOMX_HASH_SIZE]byte)
CalculateHashNext will output the hash value of the previous input and begin the calculation of the next hash.
func (*VM) CalculateHashWithState ¶ added in v4.4.0
func (vm *VM) CalculateHashWithState(s *VMState, input []byte, output *[RANDOMX_HASH_SIZE]byte)
CalculateHashWithState Calculates a RandomX hash value.
func (*VM) SetCache ¶
SetCache Reinitializes a virtual machine with a new Cache. This function should be called anytime the Cache is reinitialized with a new key. Does nothing if called with a Cache containing the same key value as already set. VM must be initialized without RANDOMX_FLAG_FULL_MEM.
func (*VM) SetDataset ¶
SetDataset Reinitializes a virtual machine with a new Dataset. VM must be initialized with RANDOMX_FLAG_FULL_MEM.
type VMProgramFunc ¶
type VMProgramFunc []byte
func (VMProgramFunc) Close ¶
func (f VMProgramFunc) Close() error
func (VMProgramFunc) Execute ¶
func (f VMProgramFunc) Execute(rf *RegisterFile, pad *ScratchPad, eMask [2]uint64)
func (VMProgramFunc) ExecuteFull ¶
func (f VMProgramFunc) ExecuteFull(rf *RegisterFile, pad *ScratchPad, dataset *RegisterLine, iterations uint64, ma, mx uint32, eMask [2]uint64)
type VMState ¶ added in v4.4.0
type VMState struct {
Pad ScratchPad
// Buffer first 128 bytes are entropy below rest are program bytes
Buffer [16*8 + RANDOMX_PROGRAM_SIZE*8]byte
HashState [blake2b.Size]byte
RegisterFile RegisterFile
Program ByteCode
JITProgram VMProgramFunc
}
VMState This whole struct is aligned to 64 bytes, except after RegisterFile
func NewVMState ¶ added in v4.4.0
type VM_Instruction ¶
type VM_Instruction [8]byte // it is hardcode 8 bytes
VM_Instruction since go does not have union, use byte array
func (VM_Instruction) Dst ¶
func (ins VM_Instruction) Dst() byte
func (VM_Instruction) IMM ¶
func (ins VM_Instruction) IMM() uint32
func (VM_Instruction) IMM64 ¶
func (ins VM_Instruction) IMM64() uint64
func (VM_Instruction) Mod ¶
func (ins VM_Instruction) Mod() byte
func (VM_Instruction) Opcode ¶
func (ins VM_Instruction) Opcode() byte
func (VM_Instruction) Src ¶
func (ins VM_Instruction) Src() byte
Source Files
¶
- cache.go
- commitment.go
- config.go
- dataset.go
- exec.go
- flags.go
- flags_generic.go
- jit_amd64.go
- math.go
- randomx.go
- register.go
- runtime.go
- superscalar.go
- superscalar_exec.go
- superscalar_inlinevm.go
- superscalar_instruction.go
- superscalar_jit_amd64.go
- vm.go
- vm_bytecode.go
- vm_bytecode_jit_amd64.go
- vm_bytecode_native.go
- vm_instruction.go
- vm_instruction_native.go
Directories
¶
| Path | Synopsis |
|---|---|
|
internal
|
|
|
aes
Package aes implements AES encryption (formerly Rijndael), as defined in U.S. Federal Information Processing Standards Publication 197.
|
Package aes implements AES encryption (formerly Rijndael), as defined in U.S. Federal Information Processing Standards Publication 197. |
|
generate-inlinevm
command
|
|