- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello folks,
I'm stuck at the idea how to optimize my code. Hope to get any help from you. My code is to make a generic sum y = a(1) + a(2) + a(3); I would like to make it like: n <= 3; process(y) begin ---for i in 1 to 3 loop ------y <= y + a(i); ---end loop; end process; Of course it will cause combinational loop :( I dont know how to do that sum without rewrite the program. I meant when I need to change the length of a. Need your help, ThanksLink Copied
7 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
--- Quote Start --- Hello folks, I'm stuck at the idea how to optimize my code. Hope to get any help from you. My code is to make a generic sum y = a(1) + a(2) + a(3); I would like to make it like: n <= 3; process(y) begin ---for i in 1 to 3 loop ------y <= y + a(i); ---end loop; end process; Of course it will cause combinational loop :( I dont know how to do that sum without rewrite the program. I meant when I need to change the length of a. Need your help, Thanks --- Quote End --- Assuming you mean (n) will vary as "generic" per compile then one way is to declare a a large adder to accommodate max (n) then wire up per compile. e.g. sum <= A(1) + A(2) +A(3) +A(4) +A(5) + A(6) + A(7); -- 7 is max n then for a given compile with n set to 3: for i in 1 to 3 loop A(i) <= a(i); end loop; That way the compiler will optimise off inputs A(4) ~ A(7)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
--- Quote Start --- Assuming you mean (n) will vary as "generic" per compile then one way is to declare a a large adder to accommodate max (n) then wire up per compile. e.g. sum <= A(1) + A(2) +A(3) +A(4) +A(5) + A(6) + A(7); -- 7 is max n then for a given compile with n set to 3: for i in 1 to 3 loop A(i) <= a(i); end loop; That way the compiler will optimise off inputs A(4) ~ A(7) --- Quote End --- Thanks a lot! :)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
To work as expected, the loop must use a variable instead of a signal. Otherwise only the last iteration will be performed.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
--- Quote Start --- To work as expected, the loop must use a variable instead of a signal. Otherwise only the last iteration will be performed. --- Quote End --- Thanks. I realize that a very good way to do it is to use structural. Then, I just connect them together. It's also for obviously programming I'll build a library for a adder.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
--- Quote Start --- Thanks. I realize that a very good way to do it is to use structural. Then, I just connect them together. It's also for obviously programming I'll build a library for a adder. --- Quote End --- No need to create an adder entity and use a generic. Its a lot more cumbersome. THe for loop will work best.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
--- Quote Start --- No need to create an adder entity and use a generic. Its a lot more cumbersome. THe for loop will work best. --- Quote End --- Yeah, that's right. Thanks :D P.S: I'm working on DSP applications, so in case of those sums are multipliers, it would be great for later optimization to use structural, isn't it? Thanks again you 2
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
it really depends, mainly on your clock speed. normal VHDL:
a <= b*c; will work perfectly well at infering multipliers at slower speeds (like up to 250MHz). But if you need to push the multiplier to the limits, you need to be using the megawizard multiplier as inference wont take into account all optimisations. Also remember you should only do 1 mult per clock.
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page