Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utgpu!water!watnot!watmath!clyde!rutgers!sri-spam!mordor!lll-lcc!pyramid!prls!mips!earl From: earl@mips.UUCP Newsgroups: comp.arch,comp.lang.c Subject: Re: String Processing Instruction Message-ID: <245@gumby.mips.UUCP> Date: Tue, 31-Mar-87 16:22:37 EST Article-I.D.: gumby.245 Posted: Tue Mar 31 16:22:37 1987 Date-Received: Thu, 2-Apr-87 04:19:51 EST References: <15292@amdcad.UUCP> <978@ames.UUCP> <15304@amdcad.UUCP> <15331@amdcad.UUCP> Distribution: na Lines: 37 Xref: utgpu comp.arch:729 comp.lang.c:1403 Summary: You win! In article <15331@amdcad.UUCP>, tim@amdcad.UUCP (Tim Olson) writes: > > Quiz: what are the magic constants that need to be loaded into t0 and > > t1 to make this work? > Let's see... How about > t0 = 0x7efefeff > t1 = 0x81010100 > Is that right? If so, it appears to work only for 7 bit characters (but > we admit that such a restriction is reasonable in real life)... Yes, you've got it. Congratulations. (Gee, do I owe you lunch or something now?) Actually, it works for 8-bit characters in bytes 0, 1, and 2 and a 7-bit one in byte 3 (I'm using little-endian byte numbers here). Thus it may accept '\200' as a zero in byte 3. But this is easily handled in the follow-on code that has to detect which byte is nonzero by actually testing byte 3 and branching back to the loop if it is nonzero. Actually, here is that code. Note how after the word loop the carries also conveniently let you detect the byte. This part only works for little-endian byte ordering. (Note: my personal convention is to indent instructions in branch delay slots once space): ## search for word with zero byte l1: lw t2,1(a1) # read next word addu a1,4 addu t3,t2,t0 # cause carry out of any nonzero byte xor t3,t2 # xor to find carry bits and t3,t1 # look at carries out of bytes beq t3,t1,l1 # all bytes carried => none zero ## found word with zero byte, now find the byte sll t4,t3,23 # carry out of byte 0? l3: beq t4,0,x0 # if not, go compute length sll t4,t3,15 # carry out of byte 1? bge t4,0,x1 # if not, go compute length sll t4,t3,7 # carry out of byte 2? bge t4,0,x2 # if not, go compute length srl t4,t2,24 # byte 3 zero? bne t4,0,l1 # no, re-enter loop