Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Power function in vhdl

Tags:

vhdl

modelsim

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

like image 205
user1673892 Avatar asked Apr 28 '13 19:04

user1673892


2 Answers

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.

like image 197
user_1818839 Avatar answered Nov 15 '22 11:11

user_1818839


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.

like image 35
Jotorious Avatar answered Nov 15 '22 11:11

Jotorious