Article View: comp.arch
Article #21539Re: Divide by three?
From: Robert Firth
Date: Fri, 02 Jun 1989 18:22
Date: Fri, 02 Jun 1989 18:22
18 lines
1195 bytes
1195 bytes
In article <d33P02nM30sj01@amdahl.uts.amdahl.com> shs@uts.amdahl.com (Steve Schoettler) writes: > What's the fastest way to divide an 11 bit number by three, > on a processor that doesn't have any multiply or divide instructions? > > There is not enough room in memory for a table lookup. Sorry if this is a dense answer, but what's wrong with multiplying by 1/3? In binary, that's 0.010101..., so the algorithm looks like temp := number>>2; quot := temp while temp>=4 do temp := temp>>2; quot := quot+temp end For an 11-bit number, worst case is 5 shifts and 4 adds. If I expected a logarithmic distribution of input values, I'd probably unroll the loop and branch out after iterations 2 and 3.
Technical Details
Message-ID:
<3440@bd.sei.cmu.edu>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!gatech!udel!rochester!pt.cs.cmu.edu!sei!firthReferences:
<d33P02nM30sj01@amdahl.uts.amdahl.com>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!gatech!udel!rochester!pt.cs.cmu.edu!sei!firth From: firth@sei.cmu.edu (Robert Firth) Newsgroups: comp.arch,sci.math,rec.puzzles Subject: Re: Divide by three? Message-ID: <3440@bd.sei.cmu.edu> Date: 2 Jun 89 18:22:03 GMT References: <d33P02nM30sj01@amdahl.uts.amdahl.com> Reply-To: firth@sei.cmu.edu (Robert Firth) Followup-To: comp.arch Organization: Software Engineering Institute, Pittsburgh, PA Lines: 18