Path: utzoo!utgpu!water!watmath!clyde!bellcore!rutgers!mit-eddie!uw-beaver!teknowledge-vaxc!sri-unix!garth!smryan From: smryan@garth.UUCP (Steven Ryan) Newsgroups: comp.arch Subject: Re: Vectorising conditional code. Message-ID: <916@garth.UUCP> Date: 10 Jul 88 23:56:59 GMT References: <893@garth.UUCP> <11855@agate.BERKELEY.EDU> Reply-To: smryan@garth.UUCP (Steven Ryan) Organization: INTERGRAPH (APD) -- Palo Alto, CA Lines: 50 >I once played with the Mandelbrot set on a Cray-1. The relevant code frag- >ment is (with complex arithmetic): > > for c in [set of pixels] > { for(z=i=0; |z|<2 && iz=z*z+c; > count[c]=i; > } > >Version 3 was written in assembly, and vectorized by hand. I don't know what version 3 is but version 1 is recursive. I don't if the Cray can generate a geometric progression in one swoop. If it can, fine. Otherwise, I would have changed this to bit in_range[] := all true z[] := 0 i := 1; while some bit set in in_range and i<=max_iter for c in pixel set if in_range[c] z[c] := z[c]*z[c] + c in_range[c] := in_range[c] and abs z[c] <2 i+:=1 The inner loop is not recursive and it has single entry/single exit body. Such loops are vectorisable, in principle anyway. I'm not sure what this has to do with early exits. >Now back to your example and my promised comments. > >> for i >> a[i] := ... >> exit if p[i] >> b[i] := ... > >What I did, then, was to vectorize the a[i] calculation. Sorry, don't understand. >More fun happens if you replace the "exit" with "continue" Then it very easy. "continue if p[i]" becomes for i a[i] := ... if not p[i] b[i] := ... Again, a single entry/single exit body.