Xref: utzoo comp.lang.c:32454 comp.arch:18365 Path: utzoo!attcan!uunet!wuarchive!zaphod.mps.ohio-state.edu!rpi!sci.ccny.cuny.edu!phri!roy From: roy@phri.nyu.edu (Roy Smith) Newsgroups: comp.lang.c,comp.arch Subject: Re: a style question Message-ID: <1990Oct2.151644.1581@phri.nyu.edu> Date: 2 Oct 90 15:16:44 GMT References: <7341@darkstar.ucsc.edu> <1990Sep30.050655.13212@zoo.toronto.edu> <1990Sep30.172917.2951@Neon.Stanford.EDU> Sender: news@phri.nyu.edu (News System) Organization: Public Health Research Institute, New York City Lines: 26 davis@pacific.mps.ohio-state.edu (John E. Davis) writes: > Which ['x != 100' or 'x < 100' RHS] generates faster code? It seems to > me that it is easier to tell if two values are unequal than to tell if > one is greater than the other. I'd rather save the machine a few > micro-seconds than myself since I only do the comparison once whereas the > machine must do it many times. Are there actually any machines in which a compare-and-branch for inequality is any faster or slower than a compare-and-branch for less-than? It seems to me that either should take one pass through the ALU to do the comparison and set some flags, so they should both take the same amount of time. I'm basing my assumption on experience with pdp-11 type machines, but I find it hard to imagine any other machine being significantly different. Maybe if you had an asynchronous ALU? The only scenario I could think of would be a RISC machine which has only two branches; branch-on-equal, and branch-on-less-than. The compiler could generate an appropriate stream of instructions to simulate any possible branch condition from just those two, and some streams might end up being longer than others, but that sounds pretty strange, and very un-orthogonal. -- Roy Smith, Public Health Research Institute 455 First Avenue, New York, NY 10016 roy@alanine.phri.nyu.edu -OR- {att,cmcl2,rutgers,hombre}!phri!roy "Arcane? Did you say arcane? It wouldn't be Unix if it wasn't arcane!"