ShortCircuitRule Struct Reference

#include <corenodes_lib.h>

Detailed Description

A set of short circuit rules is used for CoreNodesLib::CreateOptimizer to easily create an Optimizer for common cases. For example to optimize binary multiplication there are four rules:

  1. If input 0 is 0, the result is 0.
  2. If input 1 is 0, the result is 0.
  3. If input 0 is 1, the result is input 1.
  4. If input 1 is 1, the result is input 0.

These can be represented as short circuit rules:

static const ShortCircuitRule g_mulRules[] = {{0, 0, -1, 0}, // if input 0 is 0, return 0
{1, 0, -1, 0}, // if input 1 is 0, return 0
{0, 1, 1, -1}, // if input 0 is 1, return input 1
{1, 1, 0, -1}}; // if input 1 is 1, return input 0

You can only use short circuit rules for nodes with exactly one output port. For other nodes you have to implement the Optimizer yourself.

Public Attributes

Int testInput
 
Int testValue
 
Int resultInput
 
Int resultValue
 

Member Data Documentation

◆ testInput

Int testInput

The index of the input port to test.

◆ testValue

Int testValue

If the value of the input port given by testInput matches testValue, the rule applies. A conversion to the input port type is done before, so e.g. a 0 for testValue matches any zero-valued number or vector.

◆ resultInput

Int resultInput

If this is non-negative, a pass-through is create from the input port given by resultInput to the output port. Otherwise resultValue is used.

◆ resultValue

Int resultValue

If resultInput is negative, resultValue is the compile-time constant value to use for the output port. It will be converted to the correct port type.