Path: utzoo!mnetor!uunet!seismo!sundc!pitstop!sun!decwrl!decvax!yale!cmcl2!brl-adm!brl-smoke!gwyn From: gwyn@brl-smoke.ARPA (Doug Gwyn ) Newsgroups: comp.lang.c Subject: Re: Another way (How not to write a loop) Message-ID: <7285@brl-smoke.ARPA> Date: 18 Feb 88 23:56:35 GMT References: <1988Feb11.200149.25172@sq.uucp> <2550046@hpisod2.HP.COM> <2150@bsu-cs.UUCP> Reply-To: gwyn@brl.arpa (Doug Gwyn (VLD/VMB) ) Organization: Ballistic Research Lab (BRL), APG, MD. Lines: 30 In article <2150@bsu-cs.UUCP> dhesi@bsu-cs.UUCP (Rahul Dhesi) writes: >Floating point numbers should not be used for counting except when such >use gains us a remarkable degree of badly-needed efficiency. In the >Snobol (actually SPITBOL) example, the choice was between the >equivalents of the following: > count -=1; /* integer arithmetic with software test */ > if (count == 0) > abort_program; >and > count +=x; /* fast hardware floating add */ > /* actually AUR SCNT,SINC on IBM 360 */ >Note that the language required one or the other of the above to >be done before every statement executed. So, the Snobol implementor made a stupid decision, then. I don't have an IBM 360 at hand, but I do have a Gould PowerNode 9080, which has a remarkably similar architecture (including floating-point format) to the IBM 360's. I jury-rigged a crt0.o to enable floating- point exception trapping (normally it has to be disabled, to avoid trapping on integer overflow), and ran a large number of iterations (that did nothing but iterate) using floating-point trapping to terminate the loop, then an identical number of iterations testing an integer counter. The floating-point version burned 4.3 seconds of CPU time while the integer counter version's overhead was only 0.5 seconds. Note that the time required to perform the integer counter test against zero is utterly insignificant by comparison with whatever work the "statement execution" would involve, and it is portable besides. This looks like another instance of "misplaced efficiency concerns".