Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!sdd.hp.com!spool.mu.edu!uwm.edu!bionet!agate!ucbvax!tut.cis.ohio-state.edu!sei.cmu.edu!fs7.ece.cmu.edu!o.gp.cs.cmu.edu!spot From: spot@CS.CMU.EDU (Scott Draves) Newsgroups: comp.arch Subject: Re: Bitfield instructions--a good idea? Message-ID: Date: 18 Apr 91 16:37:11 GMT Article-I.D.: WOOZLE.SPOT.91Apr18123711 References: <1991Apr15.193425.3436@waikato.ac.nz> <1991Apr18.093804.18183@odin.diku.dk> Sender: netnews@cs.cmu.edu (USENET News Group Software) Organization: School of Computer Science, Carnegie Mellon University Lines: 54 In-Reply-To: torbenm@diku.dk's message of 18 Apr 91 09:38:04 GMT In article <1991Apr18.093804.18183@odin.diku.dk> torbenm@diku.dk (Torben [gidius Mogensen) writes: What is (often?) needed in graphics systems is to convert raster arrays from one number of bits per pixel to another, for example 1 bit per pixel to two bits per pixel. this rarely happens. 1 -> 8 or 1 -> 24 happens on occasion, but i doubt any of these are significant compared to blitting and rendering. With the normal instruction selection on processors, this requires handling each pixel on its own, making the operation quite slow. when it does happen, you can use look up tables. to do your 1 -> 2 bits per pixel example, i would use a table of 256 entries, 16 bits each. It also works for bitmap magnification. A ZIP instructions takes two words abcde..., ABCDE... and merges the bits into a double word aAbBcCdDeE... (or two half words into a word) these can be done with the look up tables in a similar fashion. make a table called halfzip that spaces out the bits of a word: halfzip[abcd] = 0a0b0c0d. then your ZIP(i,j) = halfzip[i] | (halfzip[j] << 1). Or you can use two separate tables to avoid the shift. An UNZIP instruction is the inverse of ZIP, and thus takes a double word aAbBcCdDeE... and produces two words abcde..., ABCDE... (or takes a word and produces two half words). I can't think of a similar game for unzip, but.... to convert from a two-bit-per-pixel double word to a one-bit per pixel you UNZIP it into two words. Specific colour translations can be obtained using logical operations between the two words (and possibly constants). ...this is a very bad way to convert from 2 bit to 1 bit. Dithering should be used if you want the result to look good at all. converting down to 1 bit even less common than converting from 1 bit You could also just implement EXPAND and CONTRACT, and use shifts and logical operations to get the full ZIP and UNZIP functionality. EXPAND ZIPs a word with zero, and CONTRACT is an UNZIP where only one of the outputs is generated. EXPAND = halfzip -- christianity is stupid Scott Draves communism is good spot@cs.cmu.edu give up