Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!uupsi!sunic!dkuug!diku!torbenm From: torbenm@diku.dk (Torben [gidius Mogensen) Newsgroups: comp.arch Subject: Re: Bitfield instructions--a good idea? Message-ID: <1991Apr18.093804.18183@odin.diku.dk> Date: 18 Apr 91 09:38:04 GMT References: <1991Apr15.193425.3436@waikato.ac.nz> Sender: torbenm@sleipner.diku.dk Organization: Department of Computer Science, U of Copenhagen Lines: 63 ldo@waikato.ac.nz (Lawrence D'Oliveiro, Waikato University) writes: > What do RISC designers think of bitfield instructions? (A la > the VAX and 680x0 [x >= 2] processors: extract so many bits at > a certain offset, insert so many bits at a certain offset, etc.) > > Do other people find these instructions useful? > As John Bowler pointed out in another article, bit masking instructions can be simulated with a few shift and logical instructions, and you oten don't need the full generality of the masks, as the bitfields tend to be at one end or other of the word. 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. With the normal instruction selection on processors, this requires handling each pixel on its own, making the operation quite slow. If you had bit ZIP and UNZIP instructions as described below, the operations could be done on whole words (or half words), at least if the bits per pixel are powers of two. A ZIP instructions takes two words abcde..., ABCDE... and merges the bits into a double word aAbBcCdDeE... (or two half words into a word) 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). Thus if you want to take a one-bit-per-pixel word and produce a two-bit-per-pixel double word, you ZIP if with 0, -1 or itself, which would yield the following colour translations: X ZIP 0: 0 -> 00, 1 -> 10 0 ZIP X: 0 -> 00, 1 -> 01 X ZIP -1: 0 -> 01, 1 -> 11 -1 ZIP X: 0 -> 10, 1 -> 11 X ZIP X: 0 -> 00, 1 -> 11 other translations can be obtained using logical operations on the result. Conversion of two-bit-per-pixel words to four-bits-per-pixel double words can also be done, but specific colour translation is more tricky. 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). ZIP and UNZIP can be implemented very efficiently (they are just crossing wires), but will take up rather much space (similar to a barrel shifter I would guess), so it would probably only be worthwhile on graphics processors. 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. Does anyone know of any processors (graphics or general purpose) that have such instructions? Torben Mogensen (torbenm@diku.dk)