2 powerof (x) - where x fixed point value

M

MariuszK

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
 
M

MariuszK

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
 
D

David Ashley

MariuszK said:
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
 
D

David Bishop

MariuszK said:
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.
 
M

MariuszK

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
 
D

David Bishop

MariuszK said:
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.
 
M

Mike Treseler

David said:
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
 
M

MariuszK

David Bishop napisal(a):
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.


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


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?


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


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.


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.
 
W

wallge

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
 
M

MariuszK

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

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
 
W

wallge

i dont think i can give you the paper (copyright etc), and if you're a
student you should be able to access the paper through your school
library, or if it's for your work, have your boss buy it for you.
I'll tell you how to do the calculation though. It will help if you do
it in C or matlab first.

you want to do 2^(x.y) first find
2^x and 2^(x+1) through bit shifting 1 to the left by x and (x + 1)
places

now you do linear interpolation by drawing a line through these two
points
2^x, 2^(x+1), then use f = m*x+b.
the slope, m = rise over run = (2(x+1) - 2^x)/((x+1) - (x)) = 2^(x) *
(2 - 1) / 1 = 2^(x)
b = 2^x, so to linearly interpolate do
f = x^(x) * (y) + 2^x
where y is the fractional part.
if you plot this in matlab it will look like 2^x with lines drawn
between the parts of the curve
where x is integer valued.
 
W

wallge

that last bit was a typo, should say
f = 2^(x) * (y) + 2^x = 2^x * (y + 1)
where x is integer part, y is fractional part
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top