Newsgroups: comp.arch
Path: utzoo!utgpu!watserv1!watdragon!rose!ccplumb
From: ccplumb@rose.uwaterloo.ca (Colin Plumb)
Subject: Re: bizarre instructions
Message-ID: <1991Feb28.073939.12839@watdragon.waterloo.edu>
Sender: daemon@watdragon.waterloo.edu (Owner of Many System Processes)
Organization: University of Waterloo
References: <1991Feb26.145841.12376@dgbt.doc.ca>
Distribution: na
Date: Thu, 28 Feb 1991 07:39:39 GMT
Lines: 22

don@dgbt.doc.ca (Donald McLachlan) wrote:
>Solution, requires that you write a correlator to count the number of bits in
>error in the sync sequence, and only accept it as a valid sync sequence if
>the distance is less than a predetermined limit.
>
>The distance is simply the number_of_ones(receieved_seq XOR sync_pattern).
>
>I must admit that this is a very specific problem, but one that must be
>performed once every bit time, and it would benefit greatly from having
>such an instruction in hardware.

Just wondering: the usual hack to count bits is a table of, say, 256 entries.
Look up each byte and add the values together.  If you know the sync sequence
ahead of time and can afford one table per byte of the sync sequence, you
can get a matched bits count directly by pre-diddling the table.

Another approach, since what you really want is to know whether there are
fewer than N bits set in the word, is to repeat distance &= (distance-1);
N times, and if the result is zero, you have a match.  For small n, this
is quite fast.
-- 
	-Colin
