koreth@ssyx.ucsc.edu (Steven Grimm) (09/07/88)
Submitted-by: uunet!mcvax!philmds!leo (Leo de Wit) Posting-number: Volume 2, Issue 59 Archive-name: timecode The following program, timecode, is mainly meant for the programmer crowd. It lets you time a series of 68000 instructions (entered as short hex numbers) which of course should constitute valid (and sensible) code; the result is displayed as a number of clock ticks. The posting consists of a uuencoded program and a manual page. The corresponding source has been sent to the moderator of comp.sources.atari.st. Compiled with the Lattice C compiler; I used a different startup.bin to obtain a smaller program (not included). For correspondence conceirning this program (bugs, questions etc.) try L. J. M. de Wit Nachtegaallaan 7 5731XP Mierlo Holland e-mail: ..!mcvax!philmds!leo (or perhaps ..!hp4nl!philmds!leo) The manual page: ------------------------- S t a r t s h e r e ------------------------------ ****************************************************************************** * * * timecode.c version 1.0 of 27 August 1988 (C) L.J.M. de Wit 1988 * * * * This software may be used and distributed freely if not used commercially * * and the originator (me) is mentioned. * * * ****************************************************************************** NAME timecode - time execution of MC68000 code SYNTAX timecode [-repeat] <shorthex1> <shorthex2> ... DESCRIPTION Timecode times the time needed to execute a series of MC68K instructions. The time taken is expressed in clock ticks. The repeat flag is optional; it is a number indicating how many times the series will be repeated (default 100000) so that timing can be accurate; a lower repeat count will fasten the execution but leads to less accuracy. One of the advantages of timecode is that timings can be calculated online. RESTRICTIONS 1) Up to 32 codes can be timed at once. This is generally no objection, since most of the time one times only one instruction at a time. 2) When using opcodes that read from or write to memory the pointers used will have to be prepared correctly. A convenient way is to time the instruction to load the address register, then time both the address register load and the instruction that references memory via that pointer. Subtract the first from the second to obtain the actual number of ticks for the 'mem-ref' instruction. This whole story applies to whatever code needs proper initialization. A safe place for memory references is the screen memory. 3) Take care when using branches and stuff like jsr, rts etc. Your code should handle that one way or another. 4) All registers may be used except the stack pointer. SP may be used if it restored also. The items currently on the stack must be left undisturbed; if you need to access (SP), first lower SP, and increment it afterwards. DERIVATION OF TIMING FORMULA. The formula used for the calculation of the number of ticks is (using integer division): ticks = (7791*total + (repeat / 2))/repeat - 32; where ticks : # of ticks one execution of the series takes total : # of milliseconds the complete test takes repeat: # of repetitions of the series This has been derived as follows: total # of effective ticks for the test = (total - call) * eff * 8000 = repeat * (ticks + extra) where call : # of milliseconds lost by calling the test function and saving registers. This is negligable. eff : a coefficient (max. 1) that indicates how many ticks of the processor are really used - the others are lost in interrupt handling. Measuring gave 0.9739 as value; if the vbl semaphore was set it increased to 0.9863. The former value has been used. extra : # of ticks needed to handle each repetition. For this program its value is 32. The 8000 is in fact due to the processor's clock frequency (8Mhz); a factor 1000 can be found in the number total, which is expressed in milliseconds instead of seconds. Filling in eff and extra and adding (repeat / 2) to the nominator to achieve rounding of the integer division rather than truncating yields the formula used. Because stdio and memory allocation were not needed, the module was linked with a different startup.bin that does not load unnecessary code. In this way the program size has decreased from 12666 to 3391. ------------------------- E n d s h e r e ------------------------------ The binary: ------------------------- S t a r t s h e r e ------------------------------ begin 640 timecode.ttp M8!H SJ $Y6__P@;@ (("@ # : ! M -"H !30J <!H !$ +4#__"(Y +VK* ;Q9#[O_\( F0K@ (+4#__+* M; 0M0?_\+R[__"\N A"IW!*+P!.N0 !\I/[P 00?D H.(FX "-/N__PO M"4Z06(\O+@ (8098CTY>3G5.5OWF(&X "")H "PM2?WPL_P 9@9"+OWT M8"!![OWT+4C]["!N_>Q2KOWL(F[]\! 1$(!2KOWP2@!FZ"!N @O2 T/P M@")O "QZ0 @9@ _D'N_W23R2U)_W1"+OWK< $M0/_\+4C_]"U)__@,K@ M "#__&P )P@;@ ($"@ @$B 2, B+O_XLH!D "&!H$ "!T<$0$$H 9R0, M @9QX, )9Q@@+O_X!H "!(&X "-' $! , *9B!*+OWK9T1P "(N M__@&@0 ($@;@ (T<$0@!U _>M@*DHN_>MF)!U\ ']ZR N__SE@%*N__Q! M[O]TT< B;@ (TOP @=/N__@@B5*N__A@ /]<("[_^ : @2!N C1P$(0 M#*X @__QF2$AY *%G )+P!.N0 !\I0CW !+P!A $,6(]@*B!N @M M: @__1"KO_\(&[_]$J09PI2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! 0$! 0$! M 1 0$! 0$(*"@H*"@@(" @(" @(" @(" @(" @(" @("$! 0$" M "8N"@%6"K@*%# @0#88& H*'.0L2CP2$A86$A0*$ X*$ @*$! 4 0$F(44B8Z1@9 " 9 " 9 end ------------------------- E n d s h e r e ------------------------------