5

I want to make power function using vhdl where the power is floating number and the number is integer (will be always "2").

2^ some floating number.

I use ieee library and (fixed_float_types.all, fixed_pkg.all, and float_pkg.all).

I thought of calculating all the possible outputs and save them in ROM, but i don't know the ranges of the power.

How to implement this function and if there is any implemented function like this where to find it?

thanks

user1673892
  • 409
  • 2
  • 5
  • 17

3 Answers3

9

For simulation, you will find suitable power functions in the IEEE.math_real library

library IEEE;
use IEEE.math_real.all;
...
X <= 2 ** Y;
or
X <= 2.0 ** Y;

This is probably not synthesisable. If I needed a similar operation for synthesis, I would use a lookup table of values, slopes and second derivatives, and a quadratic interpolator. I have used this approach for reciprocal and square root functions to single precision accuracy; 2**n over a reasonable range of n is smooth enough that the same approach should work.

  • Though not Synthesisable is useful for declaring the size of Memory or large Array-based components. – ijuneja Oct 30 '18 at 18:20
1

If an approximation would do, I think I would use the integer part of my exponent to determine the integer power of 2, like if the floating point number is 111.011010111 You know that the integer power of 2 part is 0b10000000. Then I would do a left to right conditional add based on the fractional bit, so for 111.011010111 you know you need to add implement 0b10000000 times ( 0*(1/2) + 1*(1/4) + 1*(1/8) + 0*(1/16).....and so on). 1/2, 1/4, 1/8, et cetera are right shifts of 0b10000000. This implements the integer part of the exponentiation, and then approximates the fractional part as multiplication of the integer part.

Jotorious
  • 187
  • 1
  • 11
0

As simple as any, 0.1 in binary is equivalent to 0.5 in decimal and that is equivalent to calculating a square root. I've been working on floating point numbers and it took about 4-5 hours to figure this out for implementation of power function in the most simple and synthesizeable way. Just go on with repeated square roots like for b"0.01" you want to do double square root like sqrt(sqrt(x)) and for b"0.11" sqrt * double sqrt like sqrt(x)*sqrt(sqrt(x)) and so on...

This is a synthesizeable implementation of pow function...

Himanshu Tanwar
  • 198
  • 1
  • 11