Path: utzoo!mnetor!uunet!lll-winken!lll-lcc!pyramid!voder!apple!bcase From: bcase@apple.UUCP (Brian Case) Newsgroups: comp.arch Subject: Re: Why make word size a power of two? (was: > 32 bits needed where?) Message-ID: <7453@apple.UUCP> Date: 22 Feb 88 00:12:35 GMT References: <235@unicom.UUCP> <28200089@ccvaxa> <3104@watcgl.waterloo.edu> <4611@ames.arpa> <1354@vaxb.calgary.UUCP> <3049@bloom-beacon.MIT.EDU> Reply-To: bcase@apple.UUCP (Brian Case) Organization: Apple Computer Inc., Cupertino, USA Lines: 30 In article <3049@bloom-beacon.MIT.EDU> peter@athena.mit.edu (Peter J Desnoyers) writes: >In article <1354@vaxb.calgary.UUCP> radford@calgary.UUCP (Radford Neal) writes: >>In article <4611@ames.arpa>, lamaster@ames.arpa (Hugh LaMaster) writes: >> >>> Word size (or the size of any addressable data) should ALWAYS be a >>> power of two. >> >>Please explain what problems you found in converting data from systems >>with wordsizes that aren't a power of two. Given the big-endian vs. >>little-endian incompatibility, I would think that a general data typing >>scheme would be needed in any case, so odd word sizes would be no >>additional hassle. As for bit-bashing code, a #define for wordsize would >>seem to solve the problem. > >I spent some time at BBN writing code for for the C70, which has a 20 >bit word made up of two 10-bit bytes. The major problem in porting C >code to it was the 10-bit byte, rather than the 20-bit word. > >If you restrict your word size to a multiple of 8 bits, such problems >should go away. (Most 'portable' code seems to realize that word size >can differ, as well as ended-ness, and handles this in a correct >fashion.) Er, well, 8-bit bytes are part of the solution. The next problem comes when you ask the question "What word is the Nth byte in, given that the array starts at this base address?" On a machine with 2^n 8-bit bytes per word, the answer is easy: just shift N down by (little) n and add the result to the base address. Now assume that you have 6 8-bit bytes per word. How do you compute the word offset? It requires a divide by three and a divide by two. Good luck (sure, Burroughs did it, but that doesn't make it right).