Subject: Opcode quiz

From: "Michael Zapf" <[email-masked]>
Date: Wed, 25 Apr 2012 14:11:43 -0000

I just did some statistics for the reimplementation of the TMS9900 in MESS (emulating the internal microprogramming), in particular concerning the frequency of certains commands.

I disassembled some assembler language programs here, including SYSTEM/SYS from the Geneve. 

So here's the challenge to our assembly programmers: Who dares to give a guess here?

Order the following 16 commands by their number of occurance in assembly programs:

BLWP

CI

CLR

DEC

INC

INCT

JHE

JNE

JOC

MOV

RTWP

SBO

SETO

SLA

SRA

STWP

I'll give you my numbers some days later. Let's see who is closest.
:-)

Michael

---

From: "Stuart" <[email-masked]>
Date: Thu, 26 Apr 2012 14:33:03 -0000

That's nasty! My guess is below. 

MOV
DEC
JNE
CLR
INCT
INC
CI
SETO
JHE
SLA
SRA
JOC
SBO
RTWP
BLWP
STWP

Stuart.

---

From: "Paolo Bagnaresi" <[email-masked]>
Date: Thu, 26 Apr 2012 21:12:43 +0200

I'm sure Paul Urbanus will know better! Here's my guess:

MOV

DEC

INC

JNE

CI

CLR

JHE

BLWP

RTWP

INCT

SETO

SBO

SLA

SRA

JOC

STWP

Paolo Bagnaresi

>----- Original Message ----- 
>From: "Michael Zapf" <[email-masked]>
>To: <[email-masked]>
>Sent: Wednesday, April 25, 2012 4:11 PM
>Subject: [TI994A] Opcode quiz
>
>
>I just did some statistics for the reimplementation of the TMS9900 in 
>MESS (emulating the internal microprogramming), in particular concerning 
>the frequency of certains commands.
>

---

From: Tony Knerr <[email-masked]>
Date: Sat, 28 Apr 2012 22:22:56 -0400

I was going to make an attempt at ordering these commands, but so many 
more skilled programmers than I have
responded so far that surely my response would be folly. So I suggest 
that only one of the commands listed is of any importance.

That command would be BLWP, and the only time that it would be useful is 
when it was aimed at zero. :-)

So my list would be:

1. BLWP (@nada)

2. ... everything else

Who wants to bet a beer I win?

T

On 4/25/2012 10:11 AM, Michael Zapf wrote:
> MESS (emulating the internal microprogramming), in particular 
> concerning the frequency of certains commands.
>
> _

---

From: "Michael Zapf" <[email-masked]>
Date: Sun, 29 Apr 2012 13:36:02 -0000

In the meantime I repeated my statistic analysis by taking more code into account. The ranking did not change significantly, although there were some interesting movements.

My refined stats rely on the following code base:

Infocom interpreter
TI-Invaders (ROM)
Parsec (ROM)
C99
F9640
TELCO
SYSTEM/SYS (this time I used the complete 128K, not just the first 64K)
FRACTALS! (my own program used to create Mandelbrot graphics)
DSR of the TI DSSD controller
DSR of the BwG floppy controller

One of the interesting changes was that DEC and INC moved closer together. In my selection I tried to pick commands that are at least 3 to 4 positions apart, so with the current ranking I would not have picked both DEC and INC.

Even the most experienced programmers will have little chance to guess the ranking. I can reveal so much to say that MOV/MOVB is clearly position 1, that's correct.

You'll get the list in a couple of days.

Michael

---

From: "Michael Zapf" <[email-masked]>
Date: Sat, 05 May 2012 15:19:19 -0000

So as promised, here are the results of my statistics on opcode usage. This is the complete opcode set; the entries with * are not really meaningful since they also comprise a lot of non-opcode usage (e.g. the words >2020,>2020 may be decoded as COC @>2020,R0 although they may just be four space characters). Also, the appearances of the control operations (like RSET) may rather be due to words coincidentally matching the opcode.

I used the following programs as sources for these numbers:

Infocom interpreter
TI-Invaders (ROM)
Parsec (ROM)
C99
F9640
TELCO
SYSTEM/SYS

The inclusion of SYSTEM/SYS accounted much for the XOP appearance, since MDOS makes use of XOP for OS traps. Also, the CRU operations were increased in frequency by the DSRs.

17649 MOV
6550 DATA*
4638 LI
4226 BL
3813 S*
3769 SZC*
3206 C
3035 JEQ
2811 JNE
2441 JMP
2257 B
2077 CLR
2059 A
1710 BLWP
1659 COC*
1379 AI
1312 CI
1252 DEC
1163 INC
1082 SWPB
1001 SRL
940 ANDI
913 SLA
797 XOP
647 INCT
643 LDCR*
637 SOCB*
615 JL
608 MPY
511 SOC
475 STCR
456 SETO
443 JLT
398 DECT
395 JHE
360 JH
350 DIV
306 ORI
281 JOC
279 JGT
264 LIMI
256 ABS
246 CZC
241 RTWP
240 JLE
236 SRA
227 SBO
184 JNC
169 INV
164 NEG
162 X
144 SBZ
136 LWPI
134 SRC
106 TB
98 LST
45 JOP
43 STWP
31 STST
28 JNO
8 DIVS*
3 RSET*
2 LREX*
2 IDLE*
1 MPYS*
1 CKON*
1 CKOF*
0 LWP
0 XOR

So the correct order of the selected opcodes was:

MOV - used for all memory accesses
JNE - used in loops
CLR - initializing values; also shorter than LI Rx,0
BLWP - Subprogram call (very rare in the TI-99 ROM, though)
CI - most popular compare operation
DEC - used in loops 
INC - obviously used in similar environments
SLA - used for multiplying by powers of 2
INCT - much rarer than INC
SETO - much rarer than CLR
JHE - not effective when comparing to 0 (always true)
JOC - mostly for checking shifted out bits
RTWP - much rarer than BLWP (which is not surprising)
SRA - much rarer than SRL (being used for bit shifting mostly)
SBO - used mainly in DSRs, and usually at few points
STWP - rarely used; BLWP has a similar effect.

Michael

---

From: "Michael Zapf" <[email-masked]>
Date: Sat, 05 May 2012 15:31:39 -0000

One thing to add - what was the purpose of this examination?

I am currently rewriting the TMS99xx emulation in MESS; the TMS9900 is now almost complete and already working nicely. The new implementation now correctly emulates on the microprogramming level, i.e. I have actually set up a complete execution system within the CPU that processes microprograms. Also, the READY pin is now operational: When low, the CPU enters one or more wait states. 

This already had a visible effect: The text-to-speech feature of Terminal Emulator II now works correctly. The problem was that it does not check the FIFO fill level (as suggested by the Editor/Assembler manual) but relies on the speech synthesizer pulling down the READY line. This was not available before, but now it works according to the specification, and voila, here comes the speech output.

And the command list? - I wanted to build a binary search tree inside the CPU to keep the processing time for decoding the instruction as low as possible. The problem is that the two most often appearing opcodes are MOV(B) at C000 and LI at 0200, at both ends of the scale. So I had to find out which commands to push up in the tree, and which ones to keep down.

This will be available in some weeks, maybe. I need to convert the TMS9995 now which is a bit more challenging as it has a more complex processing flow (including the instruction prefetch).

Michael