LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Strange constant folding

Normally I leave the constant folding display turned on for both wires and structures. Today I noticed this:

 

Strange Constant Folding.PNG

 

You'll notice that not only is the case structure marked as  being folded, but so are the wires connected to controls on the front panel. After playing around with it a bit, I discovered that you can make the folding go away in one of a few ways.

 

  1. Put an Always Copy node in the wire between the Check Code input and the border of the case structure.
  2. Put an Always Copy node in the wire between the border of the case structure and the input to the Min/Max function.
  3. Put a single frame sequence structure around everything but the first case structure and its two input controls.

Interestingly, putting a sequence structure around the first case structure does NOT correct the problem. For those of you who like code (I hear you Bob!) the VI is attached.

 

Mike...

 

PS: Oh yes, this is in LV2015sp1


Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
0 Kudos
Message 1 of 16
(3,874 Views)

Wow!  I don't understand anything about this Post, including its title.  I don't even think I could create this by myself from scratch.  What am I supposed to see?  What's wrong?  I am so puzzled ...

 

BS

0 Kudos
Message 2 of 16
(3,843 Views)

Constant Folding is when the compiler can turn part of your code into a constant.  Needless to say, that can greatly increase the performance of you code.  You can have the editor show you when constant folding is happening from a setting in the Options->Block Diagram.  For wires, they will look fuzzy to show constant folding.  Structures show faded stripes in them.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 3 of 16
(3,837 Views)
The problem is that it is showing that a case structure that shouldn't be constant folded, is.

To understand the idea behind constant folding, let's say you have a loop that generates an array of numbers. Let's further say that all the inputs to the loop are constants. Clearly, it doesn't matter how or when it's called, the loop will always generate the same array of numbers.

Constant folding is a kind of optimization that looks for these sorts of situations and performs the a foldable operation once at compile time and in the output object code replaces the operation with the calculated result -- thus saving the time required to perform an operation that will always give the same result.

Back to the code I posted. The first case structure is showing that it is being folded -- which is wrong because it's input values are both coming from controls not constants and so is not foldable.

Mike...

Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
Message 4 of 16
(3,834 Views)

Thank you for the explanation.  I must confess I've never paid much attention to this setting, and had never turned it on.  Doing so, of course, dramatically changed the appearance of Mike's VI (to match the picture in his post -- needless to say, when I opened it in my LabVIEW 2015 SP1, with the options cleared, there were no wavy lines nor filled-in Case structures).

 

Bob "Still Learning" Schor

0 Kudos
Message 5 of 16
(3,825 Views)

We discussed a similar observation elsewhere recently. The important point is the presence of the feedback node, which is anchored to a invisible single iteration loop scaffold surrounding all code (similar to a shift register). This means that the case structure is folded as loop invariant code.

 

I agree this is somewhat confusing.

0 Kudos
Message 6 of 16
(3,810 Views)
Where was that discussion at? I looked on the forum and didn't find anything.

Mike...

Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
0 Kudos
Message 7 of 16
(3,775 Views)

@crossrulz wrote:

Constant Folding is when the compiler can turn part of your code into a constant.  Needless to say, that can greatly increase the performance of you code.  You can have the editor show you when constant folding is happening from a setting in the Options->Block Diagram.  For wires, they will look fuzzy to show constant folding.  Structures show faded stripes in them.


Honestly I was thinking something happened to my LabVIEW which started showing Fades on wires till now.

-----

The best solution is the one you find it by yourself
0 Kudos
Message 8 of 16
(3,757 Views)

Well aside from the fact that the max of 0 and an U32 is a no-op (and therefore can actually be removed by the compiler) Ifind the display of what is constant folded and what not to be, let'sput it politely, hard to decipher.

 

0 Kudos
Message 9 of 16
(3,749 Views)

@mikeporter wrote:
Where was that discussion at? I looked on the forum and didn't find anything.

I am pretty sure that conversation was during the latest beta.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 10 of 16
(3,744 Views)