Path: news.mathworks.com!not-for-mail
From: "Michael Hui" <myhui@yahoo.com>
Newsgroups: comp.soft-sys.matlab
Subject: FPT : bitsra function and CORDIC
Date: Tue, 19 Aug 2008 17:27:02 +0000 (UTC)
Organization: Broadcom Corp
Lines: 49
Message-ID: <g8evp6$4dp$1@fred.mathworks.com>
Reply-To: "Michael Hui" <myhui@yahoo.com>
NNTP-Posting-Host: webapp-05-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1219166822 4537 172.30.248.35 (19 Aug 2008 17:27:02 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Tue, 19 Aug 2008 17:27:02 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1388863
Xref: news.mathworks.com comp.soft-sys.matlab:486274



This should be a follow-up on an active thread but I can't
find it now ... I apologize.

I converted the inner loop of my CORDIC from integer-only
implementation:

   x(i+1) = x(i) + sgn(y(i))*floor(y(i)*pow2(1-i));

   y(i+1) = y(i) - sgn(y(i))*floor(x(i)*pow2(1-i));

To FPT implementation:

   switch sgn(y(i))
       case -1 , x(i+1) = x(i) - bitsra(y(i),i-1);
       case  0 , x(i+1) = 0;
       case  1 , x(i+1) = x(i) + bitsra(y(i),i-1);
   end

   switch sgn(y(i))
       case -1 , y(i+1) = y(i) + bitsra(x(i),i-1);
       case  0 , y(i+1) = 0;
       case  1 , y(i+1) = y(i) - bitsra(x(i),i-1);
   end

I noticed two problems, when running 7.6.0 on Linux:

1) the underflow messages do appear when bitsra is used,
contrary to what the other thread just claimed.

2) the execution speed, at least in interpreted mode, slowed
way down, by more than factor of 20.

The integer-only implementation was written for speed,
admittedly, so it avoids the needless left and right shifts
during rounding just to maintain the binary point.

So the question is: is this the best way to do this simple
operation? I'm looking for something both easy to read and fast.

I'm using

   x(i+1) = x(i) + sgn(y(i))*floor(y(i)*pow2(1-i));

instead of

   x = x + sgn(y) * floor( y * pow2(1-i) );

just to keep track of what happens after each iteration.
It's not a required part of the algorithm.