Found unsupported division expression for HDL code generation; Signed input data type is not supported for division with Floor RoundMode, at Function 'mod'
17 次查看(过去 30 天)
显示 更早的评论
Hi,
I am trying to use HDLcoder(NOT SIMULINK) for my code to generate some HDL out of it. I have a sin function that I am replacing within the hdl flow with a lookup table. In the HDL conformance report I get this error : Found unsupported division expression for HDL code generation; Signed input data type is not supported for division with Floor RoundMode, at Function 'mod'. The 'mod' in question is generated by matlab in the replacement_sin function, within the fixed point generated code.
Now, I have tried:
- Changing the round mode. That did not lead to any changes in the error message, which makes me think, the data type used there is independent of what I can change.
- Changing the input data type to unsigned. In my original code, I added an 'abs' before calling the sin function(just for funsies, since the functionality changes). Still no improvement, which brings me back to the conclusion of point 1.
- I ran the fix point generated code with my testbench, and checked the data type and seems to be fine. So the question is, what can I change in my datatype or my code or anything to satisfy the great matlab hdl coder.
- I tried hdlfimath. No improvement.
Don't suggest me to use cordic because it does not work in my case.
Here is the entire error message :

Here is the code snippet generated by matlab that is throwing the error:
% calculate replacement_sin via lookup table between extents x = fi([-0.999790219693613,6.26444371189643]),
% interpolation degree = 1, number of points = 1000
function y = replacement_sin( x )
persistent LUT
if ( isempty(LUT) )
LUT = fi([-0.841357621509828, -0.837405318273412, -0.833408737600639, ...
-0.829368090808947, -0.825283591545749, -0.821155455777142, ... % long list of values that I did not include for readibility
-0.0187404981463422, ], ...
numerictype(true, 32, 30), ...
fimath(x));
end
x = fi( mod( x, fi(6.28318530717959) ), fimath(x) ); % this is the line with the error
x_idx = fi((x - -0.999790219693613)*137.523104212769,1,16,5,fimath(x));
idx_bot = floor(x_idx) + 1;
x_idx(:) = x_idx + 1;
if ( idx_bot >= fi(1000,numerictype(idx_bot),fimath(x)) )
idx_bot = fi((999),numerictype(idx_bot),fimath(x));
elseif ( idx_bot < fi(1,numerictype(idx_bot),fimath(x)) )
idx_bot = fi(1,numerictype(idx_bot),fimath(x));
end
idx_top = fi(idx_bot+1,numerictype(idx_bot),fimath(x));
x_bot = idx_bot;
x_top = idx_top;
y_bot = LUT(idx_bot);
y_top = LUT(idx_top);
y = y_top*(x_idx-x_bot) + ...
y_bot*(x_top - x_idx);
end
function fm = get_fimath()
fm = fimath('RoundingMethod', 'Floor',...
'OverflowAction', 'Saturate',...
'ProductMode', 'KeepMSB',...
'ProductWordLength', 32,...
'SumMode', 'KeepMSB',...
'SumWordLength', 32,...
'CastBeforeSum', true);
end
Help
0 个评论
回答(1 个)
Walter Roberson
2025-6-20
You should be doing range reduction. sin(x) for negative x is -sin(-x). You could do something akin to
if x < 0
x = 2*pi - mod(-x,2*pi);
end
except fancied up to reflect fi()
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!