Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > VHDL > 2 powerof (x) - where x fixed point value

Reply
Thread Tools

2 powerof (x) - where x fixed point value

 
 
MariuszK
Guest
Posts: n/a
 
      10-06-2006
Hello,

How can I calculate (optimal) 2 power of x ( 2^x)?

Where x is signed fixed point value ( for example 1.5 or -1.75 etc...).


Best regards
Mariusz

 
Reply With Quote
 
 
 
 
MariuszK
Guest
Posts: n/a
 
      10-06-2006
Hello,

Actually I found next solution, but it is not precise:

2^x ~ 2^INT(x)*(1+FRAC(x))
Where:
INT(X) - integer part of x
FRAC(X) - fraction part of x

example x= 43.125
INT(43.125) = 43
FRAC(43.125)= 0.125

Any other idea?

Mariusz

 
Reply With Quote
 
 
 
 
David Ashley
Guest
Posts: n/a
 
      10-07-2006
MariuszK wrote:
> Hello,
>
> Actually I found next solution, but it is not precise:
>
> 2^x ~ 2^INT(x)*(1+FRAC(x))
> Where:
> INT(X) - integer part of x
> FRAC(X) - fraction part of x
>
> example x= 43.125
> INT(43.125) = 43
> FRAC(43.125)= 0.125
>
> Any other idea?
>
> Mariusz
>


I think you can use the fact that
2^(a+b) = 2^a * 2^b

You only have to deal with the fractional part
by subtracting out the integer part of the
exponent, and that's how many places you shift
the result left.

To produce the effect of the fractional part,
you could use an array of multipliers, each bit
in the fractional part either multiplying by 1 or
by a factor.
So in binary fractions:
..1 = 2 raised to the power of 1/2.
..01 = 2 raised to the power of 1/4
..001 = 2 raised to the power of 1/8
You have a fixed point representation of 2^.5, 2^.25,
2^.125, etc. If the bit in the exponent is 1, you
multiply by the appropriate constant, otherwise
you multiply by 1, and feed the result forward.

so in binary: 10^.1001
is in decimal 2^.5 * 2^.0625


This is similiar to a multiplier circuit itself,
where it's a serial array of optional adders,
only it's a serial array of optional multipliers.
You're helped because each multiply has one
side always a constant value.

IIRC, in one of these newsgroups, someone else
recently suggested something very similiar, but
if I read his suggestion correctly his approach was
to do additions for each fractional bit. This wouldn't
work.

Hope this is useful.

-Dave

--
David Ashley http://www.xdr.com/dash
Embedded linux, device drivers, system architecture
 
Reply With Quote
 
David Bishop
Guest
Posts: n/a
 
      10-11-2006
MariuszK wrote:
> Hello,
>
> How can I calculate (optimal) 2 power of x ( 2^x)?
>
> Where x is signed fixed point value ( for example 1.5 or -1.75 etc...).


Go to:
http://www.vhdl.org/vhdl-200x/vhdl-200x-ft/packages/
you will need
math_utility_pkg.vhdl
fixed_pkg_c.vhdl

Then you can say:

use ieee_proposed.fixed_pkg.all;
....
signal xfixed : sfixed (3 downto -3);
signal xpower : integer;

xfixed <= to_sfixed (1.5, 3, -3);

xpower <= find_msb (abs(xfixed));

All synthesizable, and it should give you what you want.
 
Reply With Quote
 
MariuszK
Guest
Posts: n/a
 
      10-11-2006

>
> use ieee_proposed.fixed_pkg.all;
> ...
> signal xfixed : sfixed (3 downto -3);
> signal xpower : integer;
>
> xfixed <= to_sfixed (1.5, 3, -3);
>
> xpower <= find_msb (abs(xfixed));
>
> All synthesizable, and it should give you what you want.


Thank you David for answer.
Currently I use your fixed_pkg package.
It is the best fixed package which I have ever seen

but...

I want calculate 2^x with use vhdl
for example:
2^1.5 = 2.828427....
2^(-1.75) = 0.2973017.....
etc.....
2 - is constant
x- signed fixed point value

find_msb return 0 for your example.
====================================
by the way.......
I started my implementation with use version 16 fixed_pkg few months
ago.
I have few question about your package. Especially I am interested in
vhdl-93 compatibility fixed point version.

1. Can I use your package without any restriction?
2. Where can I find the latest version of your package?
Only here?: http://www.vhdl.org/vhdl-200x/vhdl-200x-ft/packages/

3. Is any change log between versions (What was changed etc....) any
source.
4. What tools (version etc) are used or recommended to synthesis,
implementation vhdl-93 compatibility version of package? (I have some
problem with synthesis version with use ISE WebPack 8.2)
5. The latest version 17 has not implemented find_msb function.

Best regards
Mariusz

 
Reply With Quote
 
David Bishop
Guest
Posts: n/a
 
      10-15-2006
MariuszK wrote:

> I want calculate 2^x with use vhdl
> for example:
> 2^1.5 = 2.828427....
> 2^(-1.75) = 0.2973017.....
> etc.....
> 2 - is constant
> x- signed fixed point value
>
> find_msb return 0 for your example.


I see. Different from what I thought. A few thoughts here. You could
do a modified X^Y algorithm. However, considering the bit width I'd do
a lookup table.

> ====================================
> by the way.......
> I started my implementation with use version 16 fixed_pkg few months
> ago.
> I have few question about your package. Especially I am interested in
> vhdl-93 compatibility fixed point version.
>
> 1. Can I use your package without any restriction?


Yes. That was the whole idea of giving it to the IEEE.

> 2. Where can I find the latest version of your package?
> Only here?: http://www.vhdl.org/vhdl-200x/vhdl-200x-ft/packages/


Yes. At some time (once the package is fully published) I will probably
put up another page with more algorithms I have been working on. Useful?

> 3. Is any change log between versions (What was changed etc....) any
> source.


Everything is under RCS control. I can publish the logs if you like.

> 4. What tools (version etc) are used or recommended to synthesis,
> implementation vhdl-93 compatibility version of package? (I have some
> problem with synthesis version with use ISE WebPack 8.2)


I've tested these packages with Xilinx, Altera, Synplicity, Precision,
Synopsys, and Cadence RC with varying success. I have "modified"
versions of the packages which I got to work with all of these packages.
I could put these on a web page if necessary.

> 5. The latest version 17 has not implemented find_msb function.


The IEEE committee renamed it to be "find_leftmost". They do things
like that to me.... Sorry forgot to put that in the last e-mail.
 
Reply With Quote
 
Mike Treseler
Guest
Posts: n/a
 
      10-16-2006
David Bishop wrote:

> Yes. At some time (once the package is fully published) I will probably
> put up another page with more algorithms I have been working on. Useful?


Absolutely. Thanks. Excellent work.

> Everything is under RCS control. I can publish the logs if you like.
>


That would be useful to the readers of this newsgroup.


-- Mike Treseler
 
Reply With Quote
 
MariuszK
Guest
Posts: n/a
 
      10-20-2006

David Bishop napisal(a):
> MariuszK wrote:
>
> > I want calculate 2^x with use vhdl
> > for example:
> > 2^1.5 = 2.828427....
> > 2^(-1.75) = 0.2973017.....
> > etc.....
> > 2 - is constant
> > x- signed fixed point value
> >
> > find_msb return 0 for your example.

>
> I see. Different from what I thought. A few thoughts here. You could
> do a modified X^Y algorithm. However, considering the bit width I'd do
> a lookup table.
>
> > ====================================
> > by the way.......
> > I started my implementation with use version 16 fixed_pkg few months
> > ago.
> > I have few question about your package. Especially I am interested in
> > vhdl-93 compatibility fixed point version.
> >
> > 1. Can I use your package without any restriction?

>
> Yes. That was the whole idea of giving it to the IEEE.
>
> > 2. Where can I find the latest version of your package?
> > Only here?: http://www.vhdl.org/vhdl-200x/vhdl-200x-ft/packages/

>
> Yes. At some time (once the package is fully published) I will probably
> put up another page with more algorithms I have been working on. Useful?
>
> > 3. Is any change log between versions (What was changed etc....) any
> > source.

>
> Everything is under RCS control. I can publish the logs if you like.
>
> > 4. What tools (version etc) are used or recommended to synthesis,
> > implementation vhdl-93 compatibility version of package? (I have some
> > problem with synthesis version with use ISE WebPack 8.2)

>
> I've tested these packages with Xilinx, Altera, Synplicity, Precision,
> Synopsys, and Cadence RC with varying success. I have "modified"
> versions of the packages which I got to work with all of these packages.
> I could put these on a web page if necessary.
>
> > 5. The latest version 17 has not implemented find_msb function.

>
> The IEEE committee renamed it to be "find_leftmost". They do things
> like that to me.... Sorry forgot to put that in the last e-mail.


David,
I will be grateful to you for:
1. publish change log
2. publish modified version of package with information of synthesis
tool (with version)

Please, give sign where I can find that information. (if it possible of
course)

Best regards
Mariusz.

 
Reply With Quote
 
wallge
Guest
Posts: n/a
 
      10-22-2006
Read this paper:
A Nonlinear Technique for Enhancement of Color Images:
An Architectural Perspective for Real-Time Applications
you can find it in IEEE xplore.

They implement a linear interpolation of log2 and log2_inv.
where if you want to find log2_inv(x.y),
you just find 2^x and 2^(x + 1) through bit shifting and then linearly
interpolate
between the two using y



MariuszK wrote:
> Hello,
>
> How can I calculate (optimal) 2 power of x ( 2^x)?
>
> Where x is signed fixed point value ( for example 1.5 or -1.75 etc...).
>
>
> Best regards
> Mariusz


 
Reply With Quote
 
MariuszK
Guest
Posts: n/a
 
      10-23-2006

wallge napisal(a):
> Read this paper:
> A Nonlinear Technique for Enhancement of Color Images:
> An Architectural Perspective for Real-Time Applications
> you can find it in IEEE xplore.
>
> They implement a linear interpolation of log2 and log2_inv.
> where if you want to find log2_inv(x.y),
> you just find 2^x and 2^(x + 1) through bit shifting and then linearly
> interpolate
> between the two using y
>
>
>
> MariuszK wrote:
> > Hello,
> >
> > How can I calculate (optimal) 2 power of x ( 2^x)?
> >
> > Where x is signed fixed point value ( for example 1.5 or -1.75 etc...).
> >
> >
> > Best regards
> > Mariusz


Wallge,
Thank you for your answer. It is look intersting. Unfortunately, I can
download that document. Could you send me that document on email?

Mariusz

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Share-Point-2010 ,Share-Point -2010 Training , Share-point-2010Hyderabad , Share-point-2010 Institute Saraswati lakki ASP .Net 0 01-06-2012 06:39 AM
Scenario 5: IS-IS routing on Frame Relay Multi-point and Point-to-Point David Sudjiman Cisco 0 06-08-2006 09:11 AM
converting floating point to fixed point H aka N VHDL 15 03-02-2006 02:26 PM
floating point to fixed point conversion riya1012@gmail.com C Programming 4 02-22-2006 05:56 PM
Fixed-point format for floating-point numbers Motaz Saad Java 7 11-05-2005 05:33 PM



Advertisments