Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!think.com!zaphod.mps.ohio-state.edu!uakari.primate.wisc.edu!pikes!aspen.craycos.com!rh From: rh@craycos.com (Robert Herndon) Newsgroups: comp.arch Subject: Re: new instructions Message-ID: <1991May22.001620.751@craycos.com> Date: 22 May 91 00:16:20 GMT Organization: Cray Computer Corporation Lines: 50 In article <1991May21.191034.25980@murdoch.acc.Virginia.EDU>, Clark Coleman writes: > As a compiler writer in this RISCy age, I am inclined to agree with this > statement. If we compiler writers, in our infinite brilliance, cannot > figure out how to use an instruction, it doesn't belong in the instruction > set. Before this becomes a mantra that is chanted mindlessly, let's look > at an example that might make us think a little harder. While I generally agree with his sentiment and his example, I am inclined to believe in at least one major exception. Not to mindlessly encourage H. L. Rubin, but population count and leading zero count on a word value are quite useful, yet (though I'm not a compiler writer) I can't think of easy methods for a (non-vector) compiler to use these instructions often. Yet I think they are undeniably useful. Many simple operations can be built easily and quickly in straight-line code with these instructions, and simple things like dispatching on a bit mask and converting octal mask bit constants to shift counts, etc. are much simplified with them. Examples of functions easily built using population_count(x) and leading_zeroes(x) include signum(x), abs(x), !a, a == b, a < b, a > b, ... trailing_zeroes(x), ceil(log2(x)), and more. At the same time, these operations are not that common in most codes, so I wouldn't expect large performance gains, except in programs that make heavy use of either assembly codes, compiler intrinsics, or library routines written in assembler or with intrinsics. Perhaps I am mistaken here, and you compiler writers can use these instructions to significant advantage. If so, I'd be curious to know how much these instructions typically save. Also, in this one case, I can sympathise with Mr. Rubin, because there isn't any elegant and portable way to express, for instance, leading_zeroes(x) in a language other than (say, in C) to make it a function or #define and define it according to the capabilities of the hardware/compiler at hand. Not terribly difficult, but it does seem to lack elegance, and not all compilers for machines that have these functions have such intrinsics or deal with them well. Still, IMHO that is something to take up with the compiler writers, rather than the language designers. I will note however, that I am very happy to see that many micros are beginning to include these instructions... Robert Herndon -- Robert Herndon -- not speaking officially for Cray Computer. Cray Computer Corporation 719/540-4240 1110 Bayfield Dr. rh@craycos.com Colorado Springs, CO 80906 Ignore these three words.