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