SvenP Posted January 15, 2006 Share Posted January 15, 2006 ok my question is how can i create something like this in vops ? float total_opac = 0; float temp_opac = 0; for (int i ; i<100 ; i++) { temp_opac = CalcOpacity(whatever); total_opac += temp_opac; } Thanks in advance Sven Quote Link to comment Share on other sites More sharing options...
edward Posted January 15, 2006 Share Posted January 15, 2006 Yes, use a a For (loop) VOP. Create a Constant VOP and name its variable as total_opac. Wire it into the For loop VOP. Inside the the For loop VOP, Add your computation to the total_opac input and wire the result into the output vop. Outside the For loop VOP, you can then take the result from the total_opac output. Quote Link to comment Share on other sites More sharing options...
lisux Posted January 16, 2006 Share Posted January 16, 2006 Yes, use a a For (loop) VOP. Create a Constant VOP and name its variable as total_opac. Wire it into the For loop VOP. Inside the the For loop VOP, Add your computation to the total_opac input and wire the result into the output vop. Outside the For loop VOP, you can then take the result from the total_opac output. 23721[/snapback] So edward, the Constant VOP is like to declare a variable? Is strange that you can change the value of a constant, or not? Quote Link to comment Share on other sites More sharing options...
edward Posted January 16, 2006 Share Posted January 16, 2006 I suppose but that's how the code is generated. The value coming out of the Constant VOP is certainly a constant. What you do with the constant afterwards is a different story. In the VOP network, you're not really outputting the constant but a particular output from the For loop VOP. Quote Link to comment Share on other sites More sharing options...
lisux Posted January 17, 2006 Share Posted January 17, 2006 I suppose but that's how the code is generated. The value coming out of the Constant VOP is certainly a constant. What you do with the constant afterwards is a different story. In the VOP network, you're not really outputting the constant but a particular output from the For loop VOP. 23738[/snapback] I used to use the Parameter VOP to create variables for the For and IF VOP. Quote Link to comment Share on other sites More sharing options...
FrankFirsching Posted January 17, 2006 Share Posted January 17, 2006 So edward, the Constant VOP is like to declare a variable?Is strange that you can change the value of a constant, or not? 23732[/snapback] Isn't it more like that every outpt of a VOP node can be seen as a new variable? So feeding a constant into an addition VOP doesn't change the constant, but creates a new variable with the summed value. Even newer compilers (C/C++) introduce new variable names when optimizing code (and perhaps so does the vex compiler, too?). This is called SSA (single static assignment) and is for example implemented in gcc4. This optimization step removes all reassignments of a variable with assignments to new variables. So a variable never changes its value. An example will clarify my vague explanations above: You may have a piece of code like the following: int a=b+c; doSomething(a); a += d; doSomeOtherThing(a); It is equivalent with the following code: int a=b+c; doSomething(a); int e = a+d; doSomeOtherThing(e); In the second version a variable never changes it's value and can therefore be seen as a "constant". A compiler might even generate the second version as an intermediate step before generating assembly code. I hope this wasn't too technical and confusing ;-) Quote Link to comment Share on other sites More sharing options...
lisux Posted January 17, 2006 Share Posted January 17, 2006 Isn't it more like that every outpt of a VOP node can be seen as a new variable? So feeding a constant into an addition VOP doesn't change the constant, but creates a new variable with the summed value. Even newer compilers (C/C++) introduce new variable names when optimizing code (and perhaps so does the vex compiler, too?). This is called SSA (single static assignment) and is for example implemented in gcc4. This optimization step removes all reassignments of a variable with assignments to new variables. So a variable never changes its value. An example will clarify my vague explanations above:.... In the second version a variable never changes it's value and can therefore be seen as a "constant". A compiler might even generate the second version as an intermediate step before generating assembly code. I hope this wasn't too technical and confusing ;-) 23777[/snapback] Thanks Frank for clearing it. So for optimization pourposes the code generator treats all the variables like constant, creating new variables for every operation result. Why is better to use a new variable than using an existing variables and reasigning it, in both cases you assing a value to something.? Quote Link to comment Share on other sites More sharing options...
FrankFirsching Posted January 17, 2006 Share Posted January 17, 2006 Well, I don't really know much about this and even less how the vex compiler handles it. For a deeper explanation of SSA you can take a look at the explanation on the wikipedia page: http://en.wikipedia.org/wiki/Static_single_assignment_form There they have a nice example, why this might be usefull. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.