MCPcopy Create free account
hub / github.com/devosoft/avida / SingleProcess

Method SingleProcess

avida-core/source/cpu/cHardwareCPU.cc:908–1058  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

906// to be as optimized as possible. This is the heart of avida.
907
908bool cHardwareCPU::SingleProcess(cAvidaContext& ctx, bool speculative)
909{
910 assert(!speculative || (speculative && !m_thread_slicing_parallel));
911
912 int last_IP_pos = getIP().GetPosition();
913
914 // Mark this organism as running...
915 m_organism->SetRunning(true);
916
917 if (!speculative && m_spec_die) {
918 m_organism->Die(ctx);
919 m_organism->SetRunning(false);
920 return false;
921 }
922
923 cPhenotype& phenotype = m_organism->GetPhenotype();
924
925 // First instruction - check whether we should be starting at a promoter, when enabled.
926 if (phenotype.GetCPUCyclesUsed() == 0 && m_promoters_enabled) Inst_Terminate(ctx);
927
928 // Count the cpu cycles used
929 phenotype.IncCPUCyclesUsed();
930 if (!m_world->GetConfig().NO_CPU_CYCLE_TIME.Get()) phenotype.IncTimeUsed();
931
932 int num_threads = m_threads.GetSize();
933
934 // If we have threads turned on and we executed each thread in a single
935 // timestep, adjust the number of instructions executed accordingly.
936 int num_inst_exec = m_thread_slicing_parallel ? num_threads : 1;
937
938 // bool isInterruptEnabled(false);
939 // if (m_world->GetConfig().ACTIVE_MESSAGES_ENABLED.Get() == 1)
940 // isInterruptEnabled = true;
941
942 for (int i = 0; i < num_inst_exec; i++) {
943 // Setup the hardware for the next instruction to be executed.
944 int last_thread = m_cur_thread;
945
946 m_cur_thread++;
947
948 if (m_cur_thread >= num_threads) m_cur_thread = 0;
949
950 m_advance_ip = true;
951 cHeadCPU& ip = m_threads[m_cur_thread].heads[nHardware::HEAD_IP];
952 ip.Adjust();
953
954
955 // Print the status of this CPU at each step...
956 if (m_tracer) m_tracer->TraceHardware(ctx, *this);
957
958 // Find the instruction to be executed
959 const Instruction cur_inst = ip.GetInst();
960
961 if (speculative && (m_spec_die || m_inst_set->ShouldStall(cur_inst))) {
962 // Speculative instruction reject, flush and return
963 m_cur_thread = last_thread;
964 phenotype.DecCPUCyclesUsed();
965 if (!m_no_cpu_cycle_time) phenotype.IncTimeUsed(-1);

Callers

nothing calls this directly

Calls 15

SetRunningMethod · 0.80
GetCPUCyclesUsedMethod · 0.80
IncCPUCyclesUsedMethod · 0.80
GetConfigMethod · 0.80
DecCPUCyclesUsedMethod · 0.80
GetAddlTimeCostMethod · 0.80
GetProbFailMethod · 0.80
GetToDeleteMethod · 0.80
GetOpMethod · 0.80
GetSymbolMethod · 0.80
FaultMethod · 0.80
GetMaxExecutedMethod · 0.80

Tested by

no test coverage detected