func (this *ReservationStation) dispatchOperation(entryIndex EntryIndex, op *operation.Operation) {

	// Lock a slot in max quantity of instructions dispatcher per cycle
	this.AddInstructionsFetchedStack()
	// Release reservation station entry
	this.Entries()[entryIndex].Busy = true

	go func() {
		// Release one entry and send operation to execution, when output channel (execution unit) is free
		logger.Collect(" => [RS%d][%03d]: Sending entry %d to %s queue...", this.Index(), op.Id(), entryIndex, op.Instruction().Info.Category)
		// Wait dispatch cycles
		startCycles := this.Processor().Cycles()
		this.Processor().Wait(consts.DISPATCH_CYCLES)
		// Log completion
		this.Processor().LogEvent(consts.DISPATCH_EVENT, this.Index(), op.Id(), startCycles)
		// Send data to execution unit in a go routine, when execution unit is available
		go this.Output()[op.Instruction().Info.Category].Add(op)
	}()
}
Esempio n. 2
0
func (this *Executor) executeOperation(unit IExecutor, event string, op *operation.Operation) (*operation.Operation, error) {
	startCycles := this.Processor().Cycles()

	// Do decode once a data instruction is received
	var err error
	op, err = unit.Process(op)
	if err != nil {
		return op, errors.New(fmt.Sprintf("Failed executing instruction. %s]", err.Error()))
	}
	// Wait cycles of a execution stage
	logger.Collect(" => [%s%d][%03d]: Executing %s, %s", event, this.Index(), op.Id(), op.Instruction().Info.ToString(), op.Instruction().Data.ToString())
	for i := uint8(0); i < op.Instruction().Info.Cycles; i++ {
		this.Processor().Wait(1)
	}
	// Log completion
	if this.IsActive() {
		this.Processor().LogEvent(event, this.Index(), op.Id(), startCycles)
	}
	return op, nil
}
Esempio n. 3
0
func (this *Fpu) Process(operation *operation.Operation) (*operation.Operation, error) {
	instruction := operation.Instruction()
	outputAddress, err := this.compute(operation, instruction.Info, instruction.Data)
	if err != nil {
		return operation, err
	}
	logger.Collect(" => [FPU][%03d]: [R%d(%#02X) = %#08X]", operation.Id(), outputAddress, outputAddress*consts.BYTES_PER_WORD, this.Result())

	// Persist output data
	this.Bus().StoreRegister(operation, outputAddress, this.Result())
	return operation, nil
}
Esempio n. 4
0
func (this *Alu) Process(operation *operation.Operation) (*operation.Operation, error) {
	instruction := operation.Instruction()

	// Clean Status
	this.CleanStatus()

	outputAddress, err := this.compute(operation, instruction.Info, instruction.Data)
	if err != nil {
		return operation, err
	}
	logger.Collect(" => [ALU][%03d]: [R%d(%#02X) = %#08X]", operation.Id(), outputAddress, outputAddress*consts.BYTES_PER_WORD, this.Result())

	// Set status flags
	this.SetStatusFlag(this.Result()%2 == 0, consts.FLAG_PARITY)
	this.SetStatusFlag(this.Result() == 0, consts.FLAG_ZERO)
	this.SetStatusFlag(getSign(this.Result()), consts.FLAG_SIGN)

	// Persist output data
	this.Bus().StoreRegister(operation, outputAddress, this.Result())
	return operation, nil
}
Esempio n. 5
0
func (this *Branch) Process(operation *operation.Operation) (*operation.Operation, error) {
	instruction := operation.Instruction()
	info := instruction.Info
	operands := instruction.Data

	switch info.Type {
	case data.TypeI:
		registerD := operands.(*data.DataI).RegisterD.ToUint32()
		op1 := this.Bus().LoadRegister(operation, registerD)
		registerS := operands.(*data.DataI).RegisterS.ToUint32()
		op2 := this.Bus().LoadRegister(operation, registerS)
		logger.Collect(" => [BR][%03d]: [R%d(%#02X) = %#08X ? R%d(%#02X) = %#08X]",
			operation.Id(), registerD, registerD*consts.BYTES_PER_WORD, op1, registerS, registerS*consts.BYTES_PER_WORD, op2)

		taken, err := processOperation(op1, op2, info.Opcode)
		if err != nil {
			return operation, nil
		}
		operation.SetBranchResult(taken)

		if taken {
			offsetAddress := ComputeOffsetTypeI(operands)
			this.Bus().IncrementProgramCounter(operation, offsetAddress)
			logger.Collect(" => [BR][%03d]: [PC(offset) = 0x%06X", operation.Id(), offsetAddress)
		} else {
			// Notify ROB
			this.Bus().IncrementProgramCounter(operation, 0)
		}
	case data.TypeJ:
		address := ComputeAddressTypeJ(operands)
		this.Bus().SetProgramCounter(operation, uint32(address-consts.BYTES_PER_WORD))
		logger.Collect(" => [BR][%03d]: [Address = %06X]", operation.Id(), address)
	default:
		return operation, errors.New(fmt.Sprintf("Invalid data type to process by Branch unit. Type: %d", info.Type))
	}
	return operation, nil
}
func (this *LoadStore) Process(operation *operation.Operation) (*operation.Operation, error) {

	instruction := operation.Instruction()
	rdAddress := instruction.Data.(*data.DataI).RegisterD.ToUint32()
	rsAddress := instruction.Data.(*data.DataI).RegisterS.ToUint32()
	immediate := instruction.Data.(*data.DataI).Immediate.ToUint32()

	switch instruction.Info.Opcode {
	case set.OP_LW:
		rsValue := this.Bus().LoadRegister(operation, rsAddress)
		value := this.Bus().LoadData(operation, rsValue+immediate)
		this.Bus().StoreRegister(operation, rdAddress, value)
		logger.Collect(" => [LS][%03d]: [R%d(%#02X) = MEM(%#02X) = %#08X]", operation.Id(), rdAddress, rdAddress*consts.BYTES_PER_WORD, rsValue+immediate, value)
	case set.OP_SW:
		rdValue := this.Bus().LoadRegister(operation, rdAddress)
		rsValue := this.Bus().LoadRegister(operation, rsAddress)
		this.Bus().StoreData(operation, rdValue+immediate, rsValue)
		logger.Collect(" => [LS][%03d]: [MEM(%#02X) = %#08X]", operation.Id(), rdValue+immediate, rsValue)
	case set.OP_LLI:
		this.Bus().StoreRegister(operation, rdAddress, immediate)
		logger.Collect(" => [LS][%03d]: [R%d(%#02X) = %#08X]", operation.Id(), rdAddress, rdAddress*consts.BYTES_PER_WORD, immediate)
	case set.OP_SLI:
		rdValue := this.Bus().LoadRegister(operation, rdAddress)
		this.Bus().StoreData(operation, rdValue, immediate)
		logger.Collect(" => [LS][%03d]: [MEM(%#02X) = %#08X]", operation.Id(), rdValue, immediate)
	case set.OP_LUI:
		this.Bus().StoreRegister(operation, rdAddress, immediate<<16)
		logger.Collect(" => [LS][%03d]: [R%d(%#02X) = %#08X]", operation.Id(), rdAddress, rdAddress*consts.BYTES_PER_WORD, immediate<<16)
	case set.OP_SUI:
		rdValue := this.Bus().LoadRegister(operation, rdAddress)
		this.Bus().StoreData(operation, rdValue, immediate<<16)
		logger.Collect(" => [LS][%03d]: [MEM(%#02X) = %#08X]", operation.Id(), rdValue, immediate<<16)
	default:
		return operation, errors.New(fmt.Sprintf("Invalid operation to process by Data unit. Opcode: %d", instruction.Info.Opcode))
	}
	return operation, nil
}
func (this *Dispatcher) renameRegisters(operationId uint32, op *operation.Operation, rat *registeraliastable.RegisterAliasTable) {

	if op.Instruction().Info.Type == data.TypeI {
		data := op.Instruction().Data.(*data.DataI)
		if !op.Instruction().Info.IsBranch() {
			opcode := op.Instruction().Info.Opcode
			if opcode != set.OP_SW && opcode != set.OP_SLI && opcode != set.OP_SUI {
				reg, _ := rat.GetPhysicalRegister(operationId, data.RegisterD.ToUint32())
				op.SetRenamedDestRegister(reg)
			}
		}
		op.Instruction().Data = data
	} else if op.Instruction().Info.Type == data.TypeR {
		data := op.Instruction().Data.(*data.DataR)
		reg, _ := rat.GetPhysicalRegister(operationId, data.RegisterD.ToUint32())
		op.SetRenamedDestRegister(reg)
	}
}