Path: utzoo!attcan!uunet!husc6!im4u!ut-sally!nather From: nather@ut-sally.UUCP (Ed Nather) Newsgroups: comp.arch Subject: Re: negative addresses (really unsigned arithmetic) Message-ID: <11647@ut-sally.UUCP> Date: 17 May 88 18:13:15 GMT References: <2393@uvacs.CS.VIRGINIA.EDU> <9485@apple.Apple.Com>, <6575@cit-vax.Caltech.Edu> Organization: U. Texas CS Dept., Austin, Texas Lines: 35 In article <6575@cit-vax.Caltech.Edu>, mangler@cit-vax.Caltech.Edu (Don Speck) writes: > One should use unsigned numbers when mixing arithmetic and logical > operators, e.g. division by shifting right, modulus by masking, etc. > Indeed. Most of the time-critical operations that must be very fast make use of these, and other, "tricks." When time is of the essence even an integer multiply (rarely needed) can be too costly. Shift-and-add operations between two registers can multiply by 10, or 40, or such small integers as special ceses faster than most built-in multiply operations. One obvious problem: the multiplier is not explicit, it is implicit in the actual operations used. Comments help. > There are certain optimizations along those lines that are only safe > if the compiler can be sure that the number cannot be negative > (stemming largely from the convention of rounding towards zero). > > Array indices can be range-checked with a single unsigned compare. > Has anyone considered a method for telling the compiler that numbers can only be positive, to make use of these operations? I thought "unsigned" did that, but maybe I'm wrong. If I promise not to use negative integers anywhere, even as array indices, can you generate faster code for me? If I had that, and C had a way to keep track of the carry bit, I wouldn't need assembly code at all. Well, hardly ever. -- Ed Nather Astronomy Dept, U of Texas @ Austin {allegra,ihnp4}!{noao,ut-sally}!utastro!nather nather@astro.AS.UTEXAS.EDU