Re: [hatari-devel] Prefetch issue on 68000?

[ Thread Index | Date Index | More lists.tuxfamily.org/hatari-devel Archives ]


Hi,

On tiistai 19 helmikuu 2013, Nicolas Pomarède wrote:
> Le 19/02/2013 10:32, Eero Tamminen a écrit :
> > On tiistai 19 helmikuu 2013, Nicolas Pomarède wrote:
> >>> Currently I wouldn't count so much on WinUAE core as its "cycle
> >>> exact" cycles returned by Cycles_GetCounter(CYCLES_COUNTER_CPU) are
> >>> more bogus (often there's zero diff from previous instruction) than
> >>> the old UAE core provided ones.  :-/
> >> 
> >> WinUAE's 68000 cycle exact mode is correct ; the fact that
> >> Cycles_GetCounter (which is Hatari specific, not WinUAE) doesn't
> >> return correct values sometimes is a problem in the Falcon's mode
> >> implementation, not in WinUAE.
> > 
> > What increments the CPU counter?  Any idea why it wouldn't be
> > incremented on Falcon emulation for WinUAE core?
> 
> the cpu counter is "local" to each instruction and is reset when the
> instruction has been fully processed.
> I know Laurent added some calls to get/set counter at some points to
> handle the number of cycles for the dsp, so it's probably related, but I
> don't know this part that much.

There's just zeroing of the counter at start of CPU loop and getting
the value at the end of the loop, but those seem the same for
old and new CPU cores:

------- WinUAE core m68k_run_2ce() --------
        for (;;) {
                /* clear add_cycles for instructions like movem */
                regs.ce030_instr_addcycles = 0;

                if (bDspEnabled)
                        Cycles_SetCounter(CYCLES_COUNTER_CPU, 0); 

                BusErrorPC = m68k_getpc();

                uae_u32 opcode = x_prefetch (0);
                (*cpufunctbl[opcode])(opcode);

/* Laurent : if 68030 instr cache is on, not frozen and nohitcache miss,
 * cycles are computed with head / tail / and cache_cycles else, cycles
 * are equal to non cache cycles. */
                falcon_instr_cycle = regs.ce030_instr_cycles;

                if ((currprefs.cpu_model == 68030) && ((r->cacr & 3) == 1) 
&& (CpuInstruction.iCacheMisses == 0)) { // not frozen and enabled
                        if (falcon_instr_cycle.head < 
CpuInstruction.iSave_instr_tail)
                                curr_cycles = 
(falcon_instr_cycle.cache_cycles - falcon_instr_cycle.head);
                        else
                                curr_cycles = 
(falcon_instr_cycle.cache_cycles - CpuInstruction.iSave_instr_tail);

                        CpuInstruction.iSave_instr_tail = 
falcon_instr_cycle.tail;
                }
                else {
                        curr_cycles = falcon_instr_cycle.noncache_cycles;
                }

                curr_cycles += regs.ce030_instr_addcycles;

                M68000_AddCycles(curr_cycles);

                if (regs.spcflags & SPCFLAG_EXTRA_CYCLES) {
                        unset_special(SPCFLAG_EXTRA_CYCLES);
                        M68000_AddCycles(nWaitStateCycles);
                        nWaitStateCycles = 0;
                }

                while ( ( PendingInterruptCount <= 0 ) && ( 
PendingInterruptFunction ) && ( ( regs.spcflags & SPCFLAG_STOP ) == 0 ) ) {
                        CALL_VAR(PendingInterruptFunction);
                        do_specialties_interrupt(false);
                }

                if (r->spcflags) {
                        if (do_specialties (0))
                                return;
                }

                if (bDspEnabled) {
                        DSP_Run(Cycles_GetCounter(CYCLES_COUNTER_CPU) * 2);
                }
        }
------ Old UAE core m68k_run_1() --------
    for (;;) {
        int cycles;
        uae_u32 opcode = get_iword_prefetch (0);

#if COUNT_INSTRS == 2
        if (table68k[opcode].handler != -1)
            instrcount[table68k[opcode].handler]++;
#elif COUNT_INSTRS == 1
        instrcount[opcode]++;
#endif

        BusErrorPC = m68k_getpc();

        if (bDspEnabled)
            Cycles_SetCounter(CYCLES_COUNTER_CPU, 0);

        cycles = (*cpufunctbl[opcode])(opcode);

        M68000_AddCycles(cycles);
        if (regs.spcflags & SPCFLAG_EXTRA_CYCLES) {
          unset_special(SPCFLAG_EXTRA_CYCLES);
          M68000_AddCycles(nWaitStateCycles);
          nWaitStateCycles = 0;
        }

        while ( ( PendingInterruptCount <= 0 ) && ( PendingInterruptFunction 
) && ( ( regs.spcflags & SPCFLAG_STOP ) == 0 ) )
          {
            CALL_VAR(PendingInterruptFunction);
            do_specialties_interrupt(false);
          }

        while (PendingInterruptCount <= 0 && PendingInterruptFunction)
          CALL_VAR(PendingInterruptFunction);

        if (regs.spcflags) {
            if (do_specialties ())
                return;
        }
        if (bDspEnabled) {
            DSP_Run( Cycles_GetCounter(CYCLES_COUNTER_CPU) );
        }
    }
----------------------------

(I removed commented & ifdeffed-out stuff and TRACE lines
to shorten it a bit.)


Do you see in above anything that could cause zero cycles
at the end of the loop?  Debugger/profiler is called in
do_specialties().


Btw. In WinUAE core I see usage of CYCLE_UNIT define usage on
some M68000_AddCycles() calls, but not on all.  That define
in't used at all in old UAE CPU core.


	 - Eero



Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/