Hello all
I was wondering if the log2 function of the math_real package was
synthesizable in generic or constant declaration.
The idea is (obviously) to determine a vector length based on the
highest number it must represent (typically address size based on memory
depth)
I know I can define my own log2 function but I'd rather not define a
package only for this
Thanks in advance
Nicolas
Whether or not math_real.log2 is 'synthesizable' or not would depend
on the tool you are using and whether or not it is smart enough to
support math_real.log2 for purposes of the computation of constants.
You'll have to try it for yourself and see.
For what it's worth, Quartus correctly synthesizes the manipulations
shown in the sample code below which compute an sRGB->RGB lookup
table. This computation requires use of the 'exp' and 'log'
functions.
Having said all that, I still use the commonly available synthesizable
version of log2 for computing vector widths just in case vendor
support of 'math_real.log2' is spotty.
Kevin Jennings
-------- Sample code to compute an sRGB->RGB conversion lookup table
------
constant sRGB_To_RGB_Table: work.pkg_vhd_common.arr_natural(0 to
TABLE_SIZE) :=
work.pkg_Color_Space_Conversions.sRGB_To_RGB_Table(TABLE_SIZE);
where the functions required to do all the dirty work are...
--------------------------------------------------------------------------------
-- sRGB to RGB color conversion function derived from the RGB to sRGB
definition
-- per Wikipedia, 10/15/2007
--
http://en.wikipedia.org/wiki/Srgb#Specification_of_the_transformation
--------------------------------------------------------------------------------
function sRGB_To_RGB(x: real range 0.0 to 1.0 ) return real is
variable RetVal: real;
begin
if (x <= 12.92 * 0.0031308) then
RetVal := x / 12.92;
else
RetVal := exp(log((x + 0.055) / 1.055) * 2.4);
end if;
return(RetVal);
end function sRGB_To_RGB;
-----------------------------------------------------------------------------------
-- Function to return a pre-computed table that performs the sRGB to
RGB conversion
-----------------------------------------------------------------------------------
function sRGB_To_RGB_Table(L: positive) return
work.pkg_VHD_Common.arr_natural is
variable RetVal: work.pkg_VHD_Common.arr_natural(0 to L);
begin
for i in RetVal'range loop
RetVal(i) := natural(round(real(L) * sRGB_To_RGB(real(i) /
real(L))));
end loop;
return(RetVal);
end function sRGB_To_RGB_Table;