home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / sys / mac / programm / 18608 < prev    next >
Encoding:
Text File  |  1992-11-18  |  5.1 KB  |  124 lines

  1. Newsgroups: comp.sys.mac.programmer
  2. Path: sparky!uunet!charon.amdahl.com!pacbell.com!sgiblab!darwin.sura.net!paladin.american.edu!news.univie.ac.at!hp4at!mcsun!news.funet.fi!funic!nntp.hut.fi!vipunen.hut.fi!jmunkki
  3. From: jmunkki@vipunen.hut.fi (Juri Munkki)
  4. Subject: Re: Help! making an assembly routine faster
  5. Message-ID: <1992Nov18.203345.1290@nntp.hut.fi>
  6. Sender: usenet@nntp.hut.fi (Usenet pseudouser id)
  7. Nntp-Posting-Host: vipunen.hut.fi
  8. Reply-To: jmunkki@vipunen.hut.fi (Juri Munkki)
  9. Organization: Helsinki University of Technology
  10. References: <1992Nov16.014850.28678@cs.uoregon.edu> <1992Nov16.190947.9920@nntp.hut.fi> <1992Nov18.010815.6649@cs.uoregon.edu>
  11. Date: Wed, 18 Nov 1992 20:33:45 GMT
  12. Lines: 110
  13.  
  14. In article <1992Nov18.010815.6649@cs.uoregon.edu> mkelly@mystix.cs.uoregon.edu (Michael A. Kelly) writes:
  15. > According to the Motorola manual, you're right.  But in practice this slowed
  16. > things down quite a bit.  I can't figure out why.  I replaced the CMPI with
  17. > an ADDQ #1, then at @hardway I did a SUBQ #1.  My test case is a 32x32 rect
  18. > with a 32x32 filled circle as the mask.  I think it would slow things down
  19. > a lot more with more complicated masks.  But still, I don't know why it's
  20. > slower, since the CMPI takes 8 clock cycles and the ADDQ and SUBQ each
  21. > take 4, so it really should be faster....  Then again, those timings are
  22. > for the 68000 (and 68020 too I think), and I'm using a 68040.
  23.  
  24. On the 040, the instructions can overlap quite a bit. I guess that the
  25. modification of a data register prevented the overlap. I suggest that
  26. you try storing the constant 0xFF in a free data register and doing
  27. the compare with the data register. Register to register compares should
  28. always be faster than immediate to register compares.
  29.  
  30. > >it might be as much as 10%. The only way to go beyond this is to make
  31. > >the move.l commands aligned on long word destinations, as I mentioned
  32. > >in my previous article.
  33. > But as long as I align the source and destination Pixmaps, that isn't an
  34. > issue, right?
  35.  
  36. I thought about this alignment stuff and it occured to me that the mask
  37. bitmap would be a lot harder to use if you aligned your writes to video
  38. RAM. On the Quadras, video RAM is so fast that alignment probably doesn't
  39. matter all that much. On NuBUS, things are usually quite different.
  40.  
  41. > OK, here's the new code.  The first one is the newer, better version of
  42. > Quick8CopyMask, with most of the optimizations suggested by Juri.  It's
  43. > about 5.5 times as fast as QuickDraw's CopyMask, at least with my simple
  44. > circle mask test case.  The second one is a small part of a very large
  45. > Quick8CopyMask that has 256 separate subroutines to handle each mask
  46. > byte, rather than only 16 subroutines to handle a mask nibble (a nibble is
  47. > half a byte, right?).  It's far too long to post here, but if you want a
  48. > copy I'll be happy to email it to you.  It's about 6.5 times as fast as
  49. > CopyMask; about 15% faster than the short version.
  50. > I tested the routines with the mask used in the CalcCMask DTS snippet;
  51. > the short version was 5.7 times as fast as CopyMask and the long version
  52. > was 7 times as fast.
  53.  
  54. It should be quite hard to improve speed from the longer code.  I bet it took
  55. quite a few minutes to write it.  :-)
  56.  
  57. I do have an idea that you could try, if you still feel like the code should
  58. be improved.
  59.  
  60. Snippet from long version:
  61. >     @1:                                ; copy the next row
  62. >         MOVE.W     w, D1
  63. >     @2:                                ; copy the next eight bytes in the row
  64. >         CLR.W      D2                  ; clear the mask register
  65. >         MOVE.B     (A2)+, D2           ; copy the next mask byte
  66. >         BEQ        @nocopy             ; if zero, don't copy anything
  67. >         
  68. >         CMPI.B     #0xFF, D2
  69. >         BNE        @hardway            ; don't copy everything
  70. >         
  71. >         MOVE.L     (A0)+, (A1)+        ; copy all bytes
  72. >         MOVE.L     (A0)+, (A1)+
  73. >         
  74. >         DBF        D1, @2
  75. >         JMP        @endloop
  76. >     
  77. >     @nocopy:                           ; copy no bytes
  78. >         ADDQ.L     #8, A0
  79. >         ADDQ.L     #8, A1
  80. >         
  81. >         DBF        D1, @2
  82. >         JMP        @endloop
  83. >     
  84. >     @hardway:
  85. >         ADD.W      D2, D2              ; double the index
  86. >         ADD.W      @table(D2.W), D2    ; calculate the address
  87. >         JMP        @table(D2.W)        ; plot eight pixels
  88.  
  89. I finally dug up my 020 manual and went through the addressing modes.
  90.  
  91. Instead of having a jump table, you should probably use a table of jumps. :-)
  92.  
  93.         clr.w    D2
  94. @1
  95.         move.w    w,D1
  96.  
  97. @2
  98.         move.b    (A2)+,D2
  99.         jmp    (@jumptable,PC,D2.w*4)
  100.  
  101. @jumptable    bra.w    @mask0
  102.         bra.w    @mask1
  103.         bra.w    @mask2
  104.         bra.w    @mask3
  105.         ...
  106.         bra.w    @mask254
  107.         move.l    (A0)+,(A1)+    ; This is mask 255
  108.         move.l    (A0)+,(A1)+
  109.         dbf    D1,@2
  110.         ...
  111.  
  112. I checked with Think C and at least the above code (or something similar)
  113. to it compiles and the disassembly looks reasonable.
  114.  
  115. Note that i removed the special checks for 0 and 255. I think they are
  116. mostly wasted, but it's possible they speed things with masks with large
  117. solid areas.
  118.  
  119. -- 
  120.   Juri Munkki                           Windsurf: fast sailing
  121.  jmunkki@hut.fi                          Macintosh: fast software
  122.