S
sanborne
Hello,
I am posting to this group because I am seeing some non-intuitive
behavior for one of my synthesized designs, and I would really like
understand what is going on. I hope that someone will have some
insight that they would be willing to share with me.
I spent quite a lot of time building an HDL design that I thought
would be a very efficient in hardware. Essentially, I need to have a
fixed point lookup table. I am approximating a fixed point natural
logarithm and some other unusual functions. I am using a spline
approximation to generate a set of "breaks" over a given interval
where I want these functions defined. An important part of my solution
is that I need to find the appropriate "break" for a given input
value. For clarification, see the following pseudo-code:
--begin code (assuming x is the input value and y is the output, and a
first order polynomial approximation):
if x<B0 then
A <= to_sfixed(...);
B <= to_sfixed(...);
elsif x<B1 then
A <= to_sfixed(...);
B <= to_sfixed(...);
elsif
....
elsif x<B9
A <= to_sfixed(...);
B <= to_sfixed(...);
else
....
end if;
y <= A*x + B;
--end code (note that my actual code is slightly different...this is
only here to illustrate my question)
I assumed from my schooling that a binary search for the correct
coefficients A and B would be better than a linear search (as is
illustrated in my code above). But strangely enough, when I synthesize
both a design that is implemented using linear and a binary search,
the linear search has a shorter combinational delay and therefore can
actually be clocked faster! I think there is some kind of optimization
that is happening in the synthesis tool (I am using Mentor Graphics
Precision, but have seen similar behavior in Quartus II). But this
result seems to render unnecessary a ton of work that I did to write
binary search code instead of linear search.
Here is an example of how my binary search would look (note that I
have simulated both approaches and get identical results):
--begin pseudo-code
if x<B4
if x<B1
if x<B0
A <= to_sfixed(...);
B <= to_sfixed(...);
else
A <=...
B <=...
end if;
elsif x>B2
A <=...
B <=...
else
...
...
end if;
elsif x>B4
....
--etc
--end code
Is there something wrong with my thinking here? Why would a linear
search have a shorter delay than a binary search? Is the synthesis
tool automatically pipelining my design? Has anyone else seen results
like this? Do you believe the results, or do you suspect I am doing
something wrong in my code?
Note that I could post more code details, but I am using MATLAB and
the Simulink HDL Coder, and it would be difficult for me to remove the
dependency of my code on these tools. I have a hand written design,
but it is old, and I would probably need permission from my company to
post specifics anyway. I understand that I may need to put together a
"toy" example that can be used to more clearly characterize this
question, but I wonder first if anyone has any general insight.
I would be very interested and appreciative of any comments.
Sean Little
I am posting to this group because I am seeing some non-intuitive
behavior for one of my synthesized designs, and I would really like
understand what is going on. I hope that someone will have some
insight that they would be willing to share with me.
I spent quite a lot of time building an HDL design that I thought
would be a very efficient in hardware. Essentially, I need to have a
fixed point lookup table. I am approximating a fixed point natural
logarithm and some other unusual functions. I am using a spline
approximation to generate a set of "breaks" over a given interval
where I want these functions defined. An important part of my solution
is that I need to find the appropriate "break" for a given input
value. For clarification, see the following pseudo-code:
--begin code (assuming x is the input value and y is the output, and a
first order polynomial approximation):
if x<B0 then
A <= to_sfixed(...);
B <= to_sfixed(...);
elsif x<B1 then
A <= to_sfixed(...);
B <= to_sfixed(...);
elsif
....
elsif x<B9
A <= to_sfixed(...);
B <= to_sfixed(...);
else
....
end if;
y <= A*x + B;
--end code (note that my actual code is slightly different...this is
only here to illustrate my question)
I assumed from my schooling that a binary search for the correct
coefficients A and B would be better than a linear search (as is
illustrated in my code above). But strangely enough, when I synthesize
both a design that is implemented using linear and a binary search,
the linear search has a shorter combinational delay and therefore can
actually be clocked faster! I think there is some kind of optimization
that is happening in the synthesis tool (I am using Mentor Graphics
Precision, but have seen similar behavior in Quartus II). But this
result seems to render unnecessary a ton of work that I did to write
binary search code instead of linear search.
Here is an example of how my binary search would look (note that I
have simulated both approaches and get identical results):
--begin pseudo-code
if x<B4
if x<B1
if x<B0
A <= to_sfixed(...);
B <= to_sfixed(...);
else
A <=...
B <=...
end if;
elsif x>B2
A <=...
B <=...
else
...
...
end if;
elsif x>B4
....
--etc
--end code
Is there something wrong with my thinking here? Why would a linear
search have a shorter delay than a binary search? Is the synthesis
tool automatically pipelining my design? Has anyone else seen results
like this? Do you believe the results, or do you suspect I am doing
something wrong in my code?
Note that I could post more code details, but I am using MATLAB and
the Simulink HDL Coder, and it would be difficult for me to remove the
dependency of my code on these tools. I have a hand written design,
but it is old, and I would probably need permission from my company to
post specifics anyway. I understand that I may need to put together a
"toy" example that can be used to more clearly characterize this
question, but I wonder first if anyone has any general insight.
I would be very interested and appreciative of any comments.
Sean Little