home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / os / vms / 22001 < prev    next >
Encoding:
Internet Message Format  |  1993-01-27  |  2.2 KB

  1. Path: sparky!uunet!ogicse!uwm.edu!spool.mu.edu!agate!ucbvax!lrw.com!leichter
  2. From: leichter@lrw.com (Jerry Leichter)
  3. Newsgroups: comp.os.vms
  4. Subject: re: Yet another VAX C problem
  5. Message-ID: <9301261255.AA28785@uu3.psi.com>
  6. Date: 26 Jan 93 11:32:38 GMT
  7. Article-I.D.: uu3.9301261255.AA28785
  8. Sender: daemon@ucbvax.BERKELEY.EDU
  9. Distribution: world
  10. Organization: The Internet
  11. Lines: 45
  12.  
  13.  
  14.     [Responding to all the people who told him that his previous report
  15.     of VAX C generating 10 instructions for an integer divide, Mr. Dick
  16.     finally gets the message and posts some real code:]
  17.  
  18.     void test(unsigned int *ip)
  19.     {
  20.        *ip = (*ip + 511) / 512;
  21.     }
  22.  
  23.     In VAX C 3.2, it generates:
  24.  
  25.  
  26.                                           0000    test:
  27.                                     000C  0000        .entry    test,^m<r2,r3>
  28.                               5E 04 C2    0002        subl2    #4,sp
  29.  
  30.                            53 04 AC D0    0005        movl    4(ap),r3
  31.                   52 63 000001FF 8F C1    0009        addl3    #511,(r3),r2
  32.                                  51 D4    0011        clrl    r1
  33.                               50 52 D0    0013        movl    r2,r0
  34.                      52 00000200 8F D0    0016        movl    #512,r2
  35.                                  09 18    001D        bgeq    vcg.1
  36.                               50 52 D1    001F        cmpl    r2,r0
  37.                                  09 1A    0022        bgtru    vcg.2
  38.                                  51 D6    0024        incl    r1
  39.                                  05 11    0026        brb    vcg.2
  40.                                           0028    vcg.1:
  41.                         50 51 50 52 7B    0028        ediv    r2,r0,r1,r0
  42.                                           002D    vcg.2:
  43.                               63 51 D0    002D        movl    r1,(r3)
  44.  
  45.                                     04    0030        ret    
  46.     Why is the question?
  47.  
  48. Because it's the correct code (gives the right answers), whereas doing a DIVL
  49. would NOT be the correct code (would give the wrong answers).
  50.  
  51. DIVL does SIGNED integer division.  *ip is an UNSIGNED integer.  If you don't
  52. understand the difference, and what effect it has on correct code generation,
  53. don't waste your time looking at generated code.
  54.  
  55. (Admittedly the "unsigned divide" template is being applied VERY stupidly and
  56. blindly.)
  57.                             -- Jerry
  58.