Author Topic: How to force all code to be compiled?  (Read 5002 times)

0 Members and 1 Guest are viewing this topic.

Offline sci4meTopic starter

  • Regular Contributor
  • *
  • Posts: 139
  • Country: us
    • sci4me.com
How to force all code to be compiled?
« on: July 31, 2013, 09:31:27 am »
Hi guys. So, I am working on a processor and at the moment, since I haven't implemented a proper way to program it, i am just putting to code into the ram before i compile and program the processor. The issue is that, I think the compiler is actually looking at my program and only compiling the parts of the processor that are needed to run the program. Is there some way I can disable this?
 

Offline mrflibble

  • Super Contributor
  • ***
  • Posts: 2051
  • Country: nl
Re: How to force all code to be compiled?
« Reply #1 on: July 31, 2013, 09:38:51 am »
I'm guessing an fpga implementation of a cpu... But you'll have to be a wee bit more specific. Without more specifics you can read up on using the KEEP and SAVE constraints if you use Xilinx or the equivalent constraints on Altera.
 

Offline mrflibble

  • Super Contributor
  • ***
  • Posts: 2051
  • Country: nl
Re: How to force all code to be compiled?
« Reply #2 on: July 31, 2013, 09:40:15 am »
Doh! Just noticed your n00b fpga thread ... Try to keep it to one thread please. :P
 

Offline sci4meTopic starter

  • Regular Contributor
  • *
  • Posts: 139
  • Country: us
    • sci4me.com
Re: How to force all code to be compiled?
« Reply #3 on: July 31, 2013, 09:43:09 am »
Sorry, its just that its a slightly different topic which is why I decided on a new one. As far as using the KEEP/SAVE, I assume that means it will compile the code even if its not needed? I am writing this for an Altera Cyclone IV E on the DE0 Nano board. You said that those are for xilinx though? Ill look into the altera ones.
 

Offline mrflibble

  • Super Contributor
  • ***
  • Posts: 2051
  • Country: nl
Re: How to force all code to be compiled?
« Reply #4 on: July 31, 2013, 09:47:30 am »
KEEP/SAVE are for xilinx yes. You'll have to check the altera docs for the equivalent. Basically these constraints are to make sure the synthesizer doesn't try to optimize away certain logic you would like to keep.
 

Offline sci4meTopic starter

  • Regular Contributor
  • *
  • Posts: 139
  • Country: us
    • sci4me.com
Re: How to force all code to be compiled?
« Reply #5 on: July 31, 2013, 09:49:16 am »
Will I need to put the keyword on EVERY line? or can I just encapsulate what I want to keep?
 

Offline mrflibble

  • Super Contributor
  • ***
  • Posts: 2051
  • Country: nl
Re: How to force all code to be compiled?
« Reply #6 on: July 31, 2013, 09:55:28 am »
You will need to put it wherever you need to put it, which shall all become clear after you read the fine manual. :P

But you can start by making sure that the flip-flops for your RAM are not optimized away. Because currently they are probably interpreted as constants, which is nice for the optimizer. :P

Quick way: INIT value for ram is whatever your program is. Then make sure you attach a clock to those registers and simply feed back the flip-flop outputs back to the inputs. That should be good enough to keep those constant valued RAMs around.

And pre-empting your next question: did you RTFM yet?
 

Offline sci4meTopic starter

  • Regular Contributor
  • *
  • Posts: 139
  • Country: us
    • sci4me.com
Re: How to force all code to be compiled?
« Reply #7 on: July 31, 2013, 10:15:03 am »
Okay, bearing in mind that im still a beginner who is trying to learn, this is what my RAM looks like:
Code: [Select]
module ram
(
input [31:0] data,
input [11:0] addr,
input we, clk,
output [31:0] q
);

reg [31:0] ram[2**11:0];

reg [11:0] addr_reg;

initial
begin : INIT
integer i;
for(i = 0; i < 2**11; i = i + 1)
ram[i] = {32{1'b0}};

ram[0] = 47;
ram[1] = 512;

ram[513] = 3;
ram[514] = 512;
ram[515] = 18; //stack pointer 512

ram[516] = 74; //BIO
   ram[517] = 0; //PIN0
ram[518] = 523; //addr
ram[519] = 72; //SIO
ram[520] = 0; //PIN0
ram[521] = 47; //JMP
ram[522] = 516; //addr
ram[523] = 70; //CIO
ram[524] = 0; //PIN0
ram[525] = 47; //JMP
ram[526] = 516; //addr
end

always @ (posedge clk)
begin
if (we)
ram[addr] <= data;

addr_reg <= addr;
end

assign q = ram[addr_reg];
endmodule

As far as did i RTFM, I read the manual for the development board I got, and ive looked at some verilog information, but thats basically it. Ive learned quite a bit just by looking at simple examples online.
 

Offline mrflibble

  • Super Contributor
  • ***
  • Posts: 2051
  • Country: nl
Re: How to force all code to be compiled?
« Reply #8 on: July 31, 2013, 10:48:45 am »
Well, the fine manual I refer to is the constraints guide from Altera. That will tell you what constraints will make the synthesizer (quartus in this case) leave your RAM unmolested.

Just google on "altera constraints guide", the first several hits are relevant.
 

Offline sci4meTopic starter

  • Regular Contributor
  • *
  • Posts: 139
  • Country: us
    • sci4me.com
Re: How to force all code to be compiled?
« Reply #9 on: July 31, 2013, 11:08:39 am »
Well the ram isnt being changed.. like, the program I put in is working, but if I dont use all parts of the processor in the program, the unused parts of the processor arent compiled...
 

Offline mrflibble

  • Super Contributor
  • ***
  • Posts: 2051
  • Country: nl
Re: How to force all code to be compiled?
« Reply #10 on: July 31, 2013, 11:12:06 am »
...  the unused parts of the processor arent compiled...

See previous statements about stuff being optimized away.
 

Offline sci4meTopic starter

  • Regular Contributor
  • *
  • Posts: 139
  • Country: us
    • sci4me.com
Re: How to force all code to be compiled?
« Reply #11 on: July 31, 2013, 11:14:38 am »
Okay, but my question is why would I need to worry about the ram if the processor is whats being optimized away?
 

Offline mrflibble

  • Super Contributor
  • ***
  • Posts: 2051
  • Country: nl
Re: How to force all code to be compiled?
« Reply #12 on: July 31, 2013, 01:44:34 pm »
If a module (any module) doesn't have a load connected to it's drivers then the synthesizer concludes that apparently this module is not needed.

Also, if a module only has constant outputs and the synthesizer is able to detect this then it will use those constant values, NOT the logic or whatever that generated those constant outputs. Because a line pulled high/low is a lot cheaper than a collection of convoluted logic that apparently resulted in a constant result.

All that to say that sometimes module B is optimized away because module A is optimized away because it's outputs are static.

So while you may focus on module B (because OMG module B optimized away), the root cause can be module A.
 

Offline sci4meTopic starter

  • Regular Contributor
  • *
  • Posts: 139
  • Country: us
    • sci4me.com
Re: How to force all code to be compiled?
« Reply #13 on: July 31, 2013, 06:04:28 pm »
Right, so since the ram values are constant... its optimizing things away, but ... the ram values can change... or should be able to...
 

Offline jahonen

  • Super Contributor
  • ***
  • Posts: 1054
  • Country: fi
Re: How to force all code to be compiled?
« Reply #14 on: July 31, 2013, 07:44:52 pm »
You are likely after preserve synthesis attribute:

http://quartushelp.altera.com/13.0/mergedProjects/hdl/vlog/vlog_file_dir_preserve.htm

So try

Code: [Select]
reg [31:0] ram[2**11:0] /* synthesis preserve */;

there. But this might not work if there are no-fanout registers, in which case you'd need to add noprune attribute too.

Regards,
Janne
 

Offline mrflibble

  • Super Contributor
  • ***
  • Posts: 2051
  • Country: nl
Re: How to force all code to be compiled?
« Reply #15 on: July 31, 2013, 10:34:27 pm »
but ... the ram values can change... or should be able to...

Well, which is it? Do the ram values change in reality (where the synthesizer lives) or just in your intentions? If you have verified that ram values really do change then this is unlikely to be the culprit...

 

Offline sci4meTopic starter

  • Regular Contributor
  • *
  • Posts: 139
  • Country: us
    • sci4me.com
Re: How to force all code to be compiled?
« Reply #16 on: August 01, 2013, 07:48:36 am »
Well they can change if I program the device to change them...
 

Offline mrflibble

  • Super Contributor
  • ***
  • Posts: 2051
  • Country: nl
Re: How to force all code to be compiled?
« Reply #17 on: August 01, 2013, 08:26:14 am »
That doesn't really tell me all that much. But no matter, in the meantime you no doubt worked out how to apply constraints where needed so problem solved.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf