def run():
    import nir_algebraic  # pylint: disable=import-error

    print('#include "midgard_nir.h"')
    print(nir_algebraic.AlgebraicPass("midgard_nir_lower_algebraic",
                                      algebraic).render())

    print(nir_algebraic.AlgebraicPass("midgard_nir_scale_trig",
                                      scale_trig).render())
Exemple #2
0
def run():
    import nir_algebraic  # pylint: disable=import-error

    print('#include "dxil_nir.h"')

    print(nir_algebraic.AlgebraicPass("dxil_nir_lower_8bit_conv",
                                      no_8bit_conv).render())
    print(nir_algebraic.AlgebraicPass("dxil_nir_lower_16bit_conv",
                                      no_16bit_conv).render())
    print(nir_algebraic.AlgebraicPass("dxil_nir_lower_x2b",
                                      lower_x2b).render())
Exemple #3
0
def run():
    import nir_algebraic  # pylint: disable=import-error

    print('#include "brw_nir.h"')
    print(
        nir_algebraic.AlgebraicPass("brw_nir_apply_trig_workarounds",
                                    TRIG_WORKAROUNDS).render())
    print(
        nir_algebraic.AlgebraicPass(
            "brw_nir_limit_trig_input_range_workaround",
            LIMIT_TRIG_INPUT_RANGE_WORKAROUND).render())
def run():
    import nir_algebraic  # pylint: disable=import-error

    print('#include "ir/lima_ir.h"')

    print(
        nir_algebraic.AlgebraicPass("lima_nir_scale_trig",
                                    scale_trig).render())
    print(
        nir_algebraic.AlgebraicPass("lima_nir_lower_ftrunc",
                                    lower_ftrunc).render())
def run():
    import nir_algebraic  # pylint: disable=import-error

    print('#include "ir3_nir.h"')
    print(
        nir_algebraic.AlgebraicPass("ir3_nir_lower_imul",
                                    imul_lowering).render())
Exemple #6
0
def run():
    import nir_algebraic  # pylint: disable=import-error

    print('#include "ir3_nir.h"')
    print(
        nir_algebraic.AlgebraicPass("ir3_nir_apply_trig_workarounds",
                                    trig_workarounds).render())
Exemple #7
0
def run():
    import nir_algebraic  # pylint: disable=import-error

    print('#include "midgard_nir.h"')

    print(nir_algebraic.AlgebraicPass("midgard_nir_lower_algebraic_early",
                                      algebraic).render())

    print(nir_algebraic.AlgebraicPass("midgard_nir_lower_algebraic_late",
                                      algebraic_late + converts + constant_switch).render())

    print(nir_algebraic.AlgebraicPass("midgard_nir_scale_trig",
                                      scale_trig).render())

    print(nir_algebraic.AlgebraicPass("midgard_nir_cancel_inot",
                                      cancel_inot).render())
Exemple #8
0
def run():
    import nir_algebraic  # pylint: disable=import-error

    print('#include "bifrost_nir.h"')

    print(nir_algebraic.AlgebraicPass("bifrost_nir_lower_algebraic_late",
                                      algebraic_late + converts).render())
def run():
    import nir_algebraic  # pylint: disable=import-error

    print('#include "nir_to_spirv/nir_to_spirv.h"')

    print(
        nir_algebraic.AlgebraicPass("zink_nir_lower_b2b", lower_b2b).render())
Exemple #10
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('-p', '--import-path', required=True)
    parser.add_argument('output')
    args = parser.parse_args()
    sys.path.insert(0, args.import_path)

    import nir_algebraic  # pylint: disable=import-error

    with open(args.output, 'w') as f:
        f.write('#include "r300_vs.h"')

        f.write(
            nir_algebraic.AlgebraicPass("r300_transform_vs_trig_input",
                                        transform_trig_input_vs_r500).render())

        f.write(
            nir_algebraic.AlgebraicPass("r300_transform_fs_trig_input",
                                        transform_trig_input_fs_r500).render())
Exemple #11
0
late_optimizations = [
   # Most of these optimizations aren't quite safe when you get infinity or
   # Nan involved but the first one should be fine.
   (('flt',          ('fadd', a, b),  0.0), ('flt',          a, ('fneg', b))),
   (('flt', ('fneg', ('fadd', a, b)), 0.0), ('flt', ('fneg', a),         b)),
   (('~fge',          ('fadd', a, b),  0.0), ('fge',          a, ('fneg', b))),
   (('~fge', ('fneg', ('fadd', a, b)), 0.0), ('fge', ('fneg', a),         b)),
   (('~feq', ('fadd', a, b), 0.0), ('feq', a, ('fneg', b))),
   (('~fne', ('fadd', a, b), 0.0), ('fne', a, ('fneg', b))),

   (('~fge', ('fmin(is_used_once)', ('fadd(is_used_once)', a, b), ('fadd', c, d)), 0.0), ('iand', ('fge', a, ('fneg', b)), ('fge', c, ('fneg', d)))),

   (('fdot2', a, b), ('fdot_replicated2', a, b), 'options->fdot_replicates'),
   (('fdot3', a, b), ('fdot_replicated3', a, b), 'options->fdot_replicates'),
   (('fdot4', a, b), ('fdot_replicated4', a, b), 'options->fdot_replicates'),
   (('fdph', a, b), ('fdph_replicated', a, b), 'options->fdot_replicates'),

   (('b2f(is_used_more_than_once)', ('inot', 'a@1')), ('bcsel', a, 0.0, 1.0)),
   (('fneg(is_used_more_than_once)', ('b2f', ('inot', 'a@1'))), ('bcsel', a, -0.0, -1.0)),

   # we do these late so that we don't get in the way of creating ffmas
   (('fmin', ('fadd(is_used_once)', '#c', a), ('fadd(is_used_once)', '#c', b)), ('fadd', c, ('fmin', a, b))),
   (('fmax', ('fadd(is_used_once)', '#c', a), ('fadd(is_used_once)', '#c', b)), ('fadd', c, ('fmax', a, b))),
]

print(nir_algebraic.AlgebraicPass("nir_opt_algebraic", optimizations).render())
print(nir_algebraic.AlgebraicPass("nir_opt_algebraic_before_ffma",
                                  before_ffma_optimizations).render())
print(nir_algebraic.AlgebraicPass("nir_opt_algebraic_late",
                                  late_optimizations).render())
Exemple #12
0
for op in [
        'flt', 'fge', 'feq', 'fne', 'ilt', 'ige', 'ieq', 'ine', 'ult', 'uge'
]:
    optimizations += [
        ((op, ('bcsel', 'a', '#b', '#c'), '#d'), ('bcsel', 'a', (op, 'b', 'd'),
                                                  (op, 'c', 'd'))),
        ((op, '#d', ('bcsel', a, '#b', '#c')), ('bcsel', 'a', (op, 'd', 'b'),
                                                (op, 'd', 'c'))),
    ]

# This section contains "late" optimizations that should be run after the
# regular optimizations have finished.  Optimizations should go here if
# they help code generation but do not necessarily produce code that is
# more easily optimizable.
late_optimizations = [
    # Most of these optimizations aren't quite safe when you get infinity or
    # Nan involved but the first one should be fine.
    (('flt', ('fadd', a, b), 0.0), ('flt', a, ('fneg', b))),
    (('~fge', ('fadd', a, b), 0.0), ('fge', a, ('fneg', b))),
    (('~feq', ('fadd', a, b), 0.0), ('feq', a, ('fneg', b))),
    (('~fne', ('fadd', a, b), 0.0), ('fne', a, ('fneg', b))),
    (('fdot2', a, b), ('fdot_replicated2', a, b), 'options->fdot_replicates'),
    (('fdot3', a, b), ('fdot_replicated3', a, b), 'options->fdot_replicates'),
    (('fdot4', a, b), ('fdot_replicated4', a, b), 'options->fdot_replicates'),
    (('fdph', a, b), ('fdph_replicated', a, b), 'options->fdot_replicates'),
]

print nir_algebraic.AlgebraicPass("nir_opt_algebraic", optimizations).render()
print nir_algebraic.AlgebraicPass("nir_opt_algebraic_late",
                                  late_optimizations).render()
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE.

import nir_algebraic

# Prior to Kaby Lake, The SIN and COS instructions on Intel hardware can
# produce values slightly outside of the [-1.0, 1.0] range for a small set of
# values.  Obviously, this can break everyone's expectations about trig
# functions.  This appears to be fixed in Kaby Lake.
#
# According to an internal presentation, the COS instruction can produce
# a value up to 1.000027 for inputs in the range (0.08296, 0.09888).  One
# suggested workaround is to multiply by 0.99997, scaling down the
# amplitude slightly.  Apparently this also minimizes the error function,
# reducing the maximum error from 0.00006 to about 0.00003.

trig_workarounds = [
    (('fsin', 'x'), ('fmul', ('fsin', 'x'), 0.99997)),
    (('fcos', 'x'), ('fmul', ('fcos', 'x'), 0.99997)),
]

print '#include "brw_nir.h"'
print nir_algebraic.AlgebraicPass("brw_nir_apply_trig_workarounds",
                                  trig_workarounds).render()
def run():
    import nir_algebraic  # pylint: disable=import-error

    print('#include "brw_nir.h"')
    print(nir_algebraic.AlgebraicPass("brw_nir_apply_trig_workarounds",
                                      TRIG_WORKAROUNDS).render())
def run():
    import nir_algebraic  # pylint: disable=import-error

    print('#include "sfn/sfn_nir.h"')

    print(nir_algebraic.AlgebraicPass("r600_lower_alu", lower_alu).render())