Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!sharkey!edsews!uunet!mcvax!dik From: dik@cwi.nl (Dik T. Winter) Newsgroups: comp.arch Subject: Re: Endian wars Message-ID: <7858@boring.cwi.nl> Date: 27 Jan 89 23:28:44 GMT References: <6133@columbia.edu> <5124@aldebaran.UUCP> Organization: CWI, Amsterdam Lines: 22 In article <5124@aldebaran.UUCP> jimp@cognos.UUCP (Jim Patterson) writes: > word-oriented algorithm to be effective here, you need an algorithm > which detects which byte of a word (if any) contains a NUL. > > I contend that there's no simple way to do this with integer > instructions; it's more effective to use byte-oriented instructions. > The only word-oriented approaches I can think of are along these > lines. > > has_NUL = ! (i & 0xff && i & 0xff00 && i & 0xff0000 && i & 0xff000000); > On a ones complement machine (because of end-around carry): has_NUL = (~i ^ (i - 0x01010101)) & 0x01010101 On a twos complement machine you have to look at the carry bit too. However you might also try: j = i - 0x01010101; has_NUL = ((~i ^ j) & 0x01010101) | (~j & i & 0x80000000) modulo some typos of course. -- dik t. winter, cwi, amsterdam, nederland INTERNET : dik@cwi.nl BITNET/EARN: dik@mcvax