home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / sys / atari / st / 16809 < prev    next >
Encoding:
Text File  |  1992-11-18  |  6.0 KB  |  117 lines

  1. Newsgroups: comp.sys.atari.st
  2. Path: sparky!uunet!microsoft!hexnut!darekm
  3. From: darekm@microsoft.com (Darek Mihocka)
  4. Subject: Re: New TOS versions?
  5. Message-ID: <1992Nov19.024438.22369@microsoft.com>
  6. Date: 19 Nov 92 02:44:38 GMT
  7. Organization: Microsoft Corporation
  8. References: <1992Nov17.122627.16049@crc.ac.uk>
  9. Lines: 103
  10.  
  11. In article <1992Nov17.122627.16049@crc.ac.uk> naffara@crc.ac.uk (Dr. N.A. Affara) writes:
  12. >As I understand it, things like NVDI and Warp 9 replace parts of TOS which
  13. >was written in C, with bits written in assembler, which is faster.
  14. >
  15. >Would it be possible to rewrite the whole of TOS in assembler, and would this
  16. >make it faster than NVDI etc?
  17.  
  18.  
  19. Since I spent several years working on Quick ST / Warp 9, here is my
  20. _extremely biased_ two cents worth:
  21.  
  22. There are several different issues here. One is C vs. assembler. The other is
  23. the efficiency of the algorithms used by TOS.
  24.  
  25. What I did when I wrote Quick ST was to replace a large number of the text and
  26. graphics routines in the BIOS, GEMDOS and VDI portions of TOS with my own very
  27. fast assembly language code.
  28.  
  29. In the case of BIOS (the VT52 text functions), those were already written in
  30. assembler, or at least the code didn't look like it was compiled. You can
  31. easily spot compiled C code by looking at the VDI code, because it is of such
  32. poor quality. So why were the routines in TOS slower than the ones Quick ST?
  33.  
  34. The problem with the VT52 routines wasn't that they were slow, but that
  35. they did some stupid things, like each time you print a character, it also
  36. redraws the cursor which can almost double the time it takes to print a
  37. character to the screen. If your program is using the Cconws() function in
  38. GEMDOS to print an entire string of characters to the screen, what do you
  39. think that TOS does? It does the slowest thing possible: it sits in a loop,
  40. fetches a character from the string and does a TRAP #13 call to the BIOS
  41. to print the one character. BIOS prints the character, redraws the cursor,
  42. and returns to GEMDOS. Then it does all this again for the next character.
  43.  
  44. This is stupid code. What Quick ST / Warp 9 does is draw all the characters
  45. at once in a very tight loop, then just draws the cursor once. This eliminates
  46. much of the overhead of repeated TRAP #13 calls and eliminates a lot of
  47. redundant cursor redraws. It is no wonder that you can get Quick ST giving
  48. you 1200% to 2000% speed increases in the speed of VT52 text. Gemulator
  49. uses the same trick to speed up the VT52 output speed by making such a patch
  50. directly in the TOS ROMs (because in an emulator, you can! <grin>)
  51.  
  52. Another example of inefficiency is in VDI. VDI has about 100 graphics
  53. operations, such as line drawing, rectangles, circles, text, setting colors,
  54. setting clipping regions, etc. When a dialog box is being drawn, only a
  55. handful of operations eat up most of the CPU time - text drawing using v_gtext,
  56. rectangle fills (for buttons, scroll bars, window title bars, etc) using
  57. v_rectfl, and v_pline (for drawing outlines, zoom boxes, etc). But about 30%
  58. of the CPU time is eaten up in little helper functions, like setting the color
  59. of text, setting the clipping region, setting the fill pattern etc. These
  60. are very simple operations and should be very fast, but TOS's TRAP #2
  61. handler which dispatches the VDI operations has an incredible amount of
  62. overhead, hundreds of instructions in fact, just to do ANY operation.
  63. By comparison, on the Mac you simply write a value through a pointer to
  64. accomplish the same thing.
  65.  
  66. By checking for these helper functions and handling them very quickly in
  67. Quick ST / Warp 9, I was able to get about a 20% speed up in GEM operations
  68. without even touching the big 3 (text, lines, rectangles)!
  69.  
  70. Now, the second issue is C vs. assembler. Most of GEM (AES and VDI) is written
  71. in C. Unfortunately, Atari seems to be using a really brain dead compiler
  72. that generated the worst possible compiled code you could imagine. It uses
  73. 32-bit addresses where 16-bit addresses will work, it doesn't use MOVEQ
  74. when it could, it copies variables to other variables then copies them
  75. back (which is redundant), and it doesn't actually seem to do much register 
  76. optimizing at all.
  77.  
  78. So when I rewrote the major VDI calls like v_gtext, v_pline, v_rectfl, etc
  79. in assembler, all I did was use similar algorithms as what TOS used, but
  80. used registers instead of memory locations and other things that a smart
  81. C compiler could have easily done. The result of simply writing efficient
  82. is a 2 or 3 times speed increase. Anyone who's ever played around with 
  83. optimizing C compilers on the PC like Watcom or MS C knows that there is
  84. a huge difference in the quality of code produced when you compile with
  85. /Ox or with /Od optiomization options.
  86.  
  87. Looking at code that is generated by newer compilers like Laser C and
  88. Turbo C, and comparing it against the brain dead code of Alcyon C that
  89. I believe that Atari used to compile the TOS ROMs, I am convinced that
  90. a simple recompile of the TOS ROMs would easily bring the size of TOS
  91. down to below 192K again, and at the same time double the speed of most
  92. TOS operations. Easily.
  93.  
  94. Remember in 1985 when TOS 1.0 was released on floppy disk it was about
  95. 210K in size. To get it down to 192K, what did Atari do - use a better
  96. compiler? NOT! They came up with this line F mechanism that shrinks
  97. the code but at the same time slows it down about 20%. They also used
  98. that as an excuse for not implementing the full font functionality of
  99. the PC version of GEM, so instead they came out with the hack GDOS which
  100. slowed down the system even more.
  101.  
  102. So in my opinion, trying to rewrite all of TOS in assembler would be
  103. a bigger waste of time than simply having Atari recompile TOS using an
  104. optimizing 68000 compiler instead of relying on a 1985 compiler. Sure,
  105. the hand coded assembly language version might be a little smaller and
  106. a little faster, but you'd be surprised at what a good C compiler could do.
  107.  
  108. My two cents worth.
  109.  
  110. - Darek
  111.  
  112. -- 
  113. /--------------------------------------\
  114. | Darek Mihocka. net: darekm@microsoft |
  115. | Views expressed are my own, I think. |
  116. \--------------------------------------/
  117.