111dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt/*
211dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt * Copyright © 2010 Intel Corporation
311dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt *
411dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt * Permission is hereby granted, free of charge, to any person obtaining a
511dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt * copy of this software and associated documentation files (the "Software"),
611dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt * to deal in the Software without restriction, including without limitation
711dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt * the rights to use, copy, modify, merge, publish, distribute, sublicense,
811dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt * and/or sell copies of the Software, and to permit persons to whom the
911dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt * Software is furnished to do so, subject to the following conditions:
1011dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt *
1111dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt * The above copyright notice and this permission notice (including the next
1211dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt * paragraph) shall be included in all copies or substantial portions of the
1311dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt * Software.
1411dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt *
1511dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1611dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1711dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
1811dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1911dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
2011dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
2111dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt * IN THE SOFTWARE.
2211dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt */
2311dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt
2411dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt/** @file brw_fs_emit.cpp
2511dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt *
2611dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt * This file supports emitting code from the FS LIR to the actual
2711dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt * native instructions.
2811dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt */
2911dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt
3011dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholtextern "C" {
3111dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt#include "main/macros.h"
3211dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt#include "brw_context.h"
3311dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt#include "brw_eu.h"
3411dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt} /* extern "C" */
3511dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt
3611dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt#include "brw_fs.h"
37080b125c64b48447a515b1a169f779e62b3de13dEric Anholt#include "brw_fs_cfg.h"
382f0edc60f4bd2ae5999a6afa656e3bb3f181bf0fChad Versace#include "glsl/ir_print_visitor.h"
3911dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt
4011dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholtvoid
4111dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholtfs_visitor::generate_fb_write(fs_inst *inst)
4211dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt{
432e5a1a254ed81b1d3efa6064f48183eefac784d0Kenneth Graunke   bool eot = inst->eot;
4411dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt   struct brw_reg implied_header;
4529362875f2613ad87abe7725ce3c56c36d16cf9bEric Anholt   uint32_t msg_control;
4611dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt
4711dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt   /* Header is 2 regs, g0 and g1 are the contents. g0 will be implied
4811dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt    * move, here's g1.
4911dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt    */
5011dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt   brw_push_insn_state(p);
5111dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt   brw_set_mask_control(p, BRW_MASK_DISABLE);
5211dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt   brw_set_compression_control(p, BRW_COMPRESSION_NONE);
5311dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt
5411dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt   if (inst->header_present) {
5511dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt      if (intel->gen >= 6) {
5611dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	 brw_set_compression_control(p, BRW_COMPRESSION_COMPRESSED);
5711dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	 brw_MOV(p,
5811dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt		 retype(brw_message_reg(inst->base_mrf), BRW_REGISTER_TYPE_UD),
5911dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt		 retype(brw_vec8_grf(0, 0), BRW_REGISTER_TYPE_UD));
6011dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	 brw_set_compression_control(p, BRW_COMPRESSION_NONE);
6111dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt
62e592f7df0361eb8b5c75944f0151c4e6b3f839ddAnuj Phogat         if (inst->target > 0 &&
63e592f7df0361eb8b5c75944f0151c4e6b3f839ddAnuj Phogat	     c->key.nr_color_regions > 1 &&
64e592f7df0361eb8b5c75944f0151c4e6b3f839ddAnuj Phogat	     c->key.sample_alpha_to_coverage) {
65e592f7df0361eb8b5c75944f0151c4e6b3f839ddAnuj Phogat            /* Set "Source0 Alpha Present to RenderTarget" bit in message
66e592f7df0361eb8b5c75944f0151c4e6b3f839ddAnuj Phogat             * header.
67e592f7df0361eb8b5c75944f0151c4e6b3f839ddAnuj Phogat             */
68e592f7df0361eb8b5c75944f0151c4e6b3f839ddAnuj Phogat            brw_OR(p,
69e592f7df0361eb8b5c75944f0151c4e6b3f839ddAnuj Phogat		   vec1(retype(brw_message_reg(inst->base_mrf), BRW_REGISTER_TYPE_UD)),
70e592f7df0361eb8b5c75944f0151c4e6b3f839ddAnuj Phogat		   vec1(retype(brw_vec8_grf(0, 0), BRW_REGISTER_TYPE_UD)),
71e592f7df0361eb8b5c75944f0151c4e6b3f839ddAnuj Phogat		   brw_imm_ud(0x1 << 11));
72e592f7df0361eb8b5c75944f0151c4e6b3f839ddAnuj Phogat         }
73e592f7df0361eb8b5c75944f0151c4e6b3f839ddAnuj Phogat
7411dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	 if (inst->target > 0) {
7511dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	    /* Set the render target index for choosing BLEND_STATE. */
763daa2d97eb13f41de4cbab9301a167be85d48642Eric Anholt	    brw_MOV(p, retype(brw_vec1_reg(BRW_MESSAGE_REGISTER_FILE,
773daa2d97eb13f41de4cbab9301a167be85d48642Eric Anholt					   inst->base_mrf, 2),
7811dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt			      BRW_REGISTER_TYPE_UD),
7911dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt		    brw_imm_ud(inst->target));
8011dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	 }
8111dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt
8211dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	 implied_header = brw_null_reg();
8311dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt      } else {
8411dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	 implied_header = retype(brw_vec8_grf(0, 0), BRW_REGISTER_TYPE_UW);
8511dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt
8611dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	 brw_MOV(p,
8711dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt		 brw_message_reg(inst->base_mrf + 1),
8811dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt		 brw_vec8_grf(1, 0));
8911dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt      }
9011dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt   } else {
9111dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt      implied_header = brw_null_reg();
9211dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt   }
9311dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt
9429362875f2613ad87abe7725ce3c56c36d16cf9bEric Anholt   if (this->dual_src_output.file != BAD_FILE)
9529362875f2613ad87abe7725ce3c56c36d16cf9bEric Anholt      msg_control = BRW_DATAPORT_RENDER_TARGET_WRITE_SIMD8_DUAL_SOURCE_SUBSPAN01;
9629362875f2613ad87abe7725ce3c56c36d16cf9bEric Anholt   else if (c->dispatch_width == 16)
9729362875f2613ad87abe7725ce3c56c36d16cf9bEric Anholt      msg_control = BRW_DATAPORT_RENDER_TARGET_WRITE_SIMD16_SINGLE_SOURCE;
9829362875f2613ad87abe7725ce3c56c36d16cf9bEric Anholt   else
9929362875f2613ad87abe7725ce3c56c36d16cf9bEric Anholt      msg_control = BRW_DATAPORT_RENDER_TARGET_WRITE_SIMD8_SINGLE_SOURCE_SUBSPAN01;
10029362875f2613ad87abe7725ce3c56c36d16cf9bEric Anholt
10111dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt   brw_pop_insn_state(p);
10211dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt
10311dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt   brw_fb_WRITE(p,
10411dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt		c->dispatch_width,
10511dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt		inst->base_mrf,
10611dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt		implied_header,
10729362875f2613ad87abe7725ce3c56c36d16cf9bEric Anholt		msg_control,
10811dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt		inst->target,
10911dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt		inst->mlen,
11011dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt		0,
11111dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt		eot,
11211dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt		inst->header_present);
11311dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt}
11411dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt
11511dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt/* Computes the integer pixel x,y values from the origin.
11611dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt *
11711dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt * This is the basis of gl_FragCoord computation, but is also used
11811dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt * pre-gen6 for computing the deltas from v0 for computing
11911dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt * interpolation.
12011dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt */
12111dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholtvoid
12211dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholtfs_visitor::generate_pixel_xy(struct brw_reg dst, bool is_x)
12311dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt{
12411dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt   struct brw_reg g1_uw = retype(brw_vec1_grf(1, 0), BRW_REGISTER_TYPE_UW);
12511dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt   struct brw_reg src;
12611dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt   struct brw_reg deltas;
12711dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt
12811dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt   if (is_x) {
12911dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt      src = stride(suboffset(g1_uw, 4), 2, 4, 0);
13011dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt      deltas = brw_imm_v(0x10101010);
13111dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt   } else {
13211dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt      src = stride(suboffset(g1_uw, 5), 2, 4, 0);
13311dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt      deltas = brw_imm_v(0x11001100);
13411dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt   }
13511dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt
13611dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt   if (c->dispatch_width == 16) {
13711dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt      dst = vec16(dst);
13811dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt   }
13911dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt
14011dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt   /* We do this 8 or 16-wide, but since the destination is UW we
14111dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt    * don't do compression in the 16-wide case.
14211dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt    */
14311dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt   brw_push_insn_state(p);
14411dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt   brw_set_compression_control(p, BRW_COMPRESSION_NONE);
14511dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt   brw_ADD(p, dst, src, deltas);
14611dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt   brw_pop_insn_state(p);
14711dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt}
14811dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt
14911dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholtvoid
15011dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholtfs_visitor::generate_linterp(fs_inst *inst,
15111dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt			     struct brw_reg dst, struct brw_reg *src)
15211dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt{
15311dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt   struct brw_reg delta_x = src[0];
15411dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt   struct brw_reg delta_y = src[1];
15511dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt   struct brw_reg interp = src[2];
15611dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt
15711dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt   if (brw->has_pln &&
15811dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt       delta_y.nr == delta_x.nr + 1 &&
15911dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt       (intel->gen >= 6 || (delta_x.nr & 1) == 0)) {
16011dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt      brw_PLN(p, dst, interp, delta_x);
16111dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt   } else {
16211dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt      brw_LINE(p, brw_null_reg(), interp, delta_x);
16311dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt      brw_MAC(p, dst, suboffset(interp, 1), delta_y);
16411dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt   }
16511dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt}
16611dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt
16711dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholtvoid
168a73c65c5342bf41fa0dfefe7daa9197ce6a11db4Kenneth Graunkefs_visitor::generate_math1_gen7(fs_inst *inst,
169a73c65c5342bf41fa0dfefe7daa9197ce6a11db4Kenneth Graunke			        struct brw_reg dst,
170a73c65c5342bf41fa0dfefe7daa9197ce6a11db4Kenneth Graunke			        struct brw_reg src0)
171a73c65c5342bf41fa0dfefe7daa9197ce6a11db4Kenneth Graunke{
172a73c65c5342bf41fa0dfefe7daa9197ce6a11db4Kenneth Graunke   assert(inst->mlen == 0);
173a73c65c5342bf41fa0dfefe7daa9197ce6a11db4Kenneth Graunke   brw_math(p, dst,
174a73c65c5342bf41fa0dfefe7daa9197ce6a11db4Kenneth Graunke	    brw_math_function(inst->opcode),
175a73c65c5342bf41fa0dfefe7daa9197ce6a11db4Kenneth Graunke	    0, src0,
176a73c65c5342bf41fa0dfefe7daa9197ce6a11db4Kenneth Graunke	    BRW_MATH_DATA_VECTOR,
177a73c65c5342bf41fa0dfefe7daa9197ce6a11db4Kenneth Graunke	    BRW_MATH_PRECISION_FULL);
178a73c65c5342bf41fa0dfefe7daa9197ce6a11db4Kenneth Graunke}
179a73c65c5342bf41fa0dfefe7daa9197ce6a11db4Kenneth Graunke
180a73c65c5342bf41fa0dfefe7daa9197ce6a11db4Kenneth Graunkevoid
181a73c65c5342bf41fa0dfefe7daa9197ce6a11db4Kenneth Graunkefs_visitor::generate_math2_gen7(fs_inst *inst,
182a73c65c5342bf41fa0dfefe7daa9197ce6a11db4Kenneth Graunke			        struct brw_reg dst,
183a73c65c5342bf41fa0dfefe7daa9197ce6a11db4Kenneth Graunke			        struct brw_reg src0,
184a73c65c5342bf41fa0dfefe7daa9197ce6a11db4Kenneth Graunke			        struct brw_reg src1)
185a73c65c5342bf41fa0dfefe7daa9197ce6a11db4Kenneth Graunke{
186a73c65c5342bf41fa0dfefe7daa9197ce6a11db4Kenneth Graunke   assert(inst->mlen == 0);
187a73c65c5342bf41fa0dfefe7daa9197ce6a11db4Kenneth Graunke   brw_math2(p, dst, brw_math_function(inst->opcode), src0, src1);
188a73c65c5342bf41fa0dfefe7daa9197ce6a11db4Kenneth Graunke}
189a73c65c5342bf41fa0dfefe7daa9197ce6a11db4Kenneth Graunke
190a73c65c5342bf41fa0dfefe7daa9197ce6a11db4Kenneth Graunkevoid
19174e927bcafad0a994be5f88fbda4058bef08bc51Kenneth Graunkefs_visitor::generate_math1_gen6(fs_inst *inst,
19274e927bcafad0a994be5f88fbda4058bef08bc51Kenneth Graunke			        struct brw_reg dst,
19374e927bcafad0a994be5f88fbda4058bef08bc51Kenneth Graunke			        struct brw_reg src0)
19411dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt{
195af3c9803d818fd33139f1247a387d64b967b8992Eric Anholt   int op = brw_math_function(inst->opcode);
19611dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt
19774e927bcafad0a994be5f88fbda4058bef08bc51Kenneth Graunke   assert(inst->mlen == 0);
19811dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt
19974e927bcafad0a994be5f88fbda4058bef08bc51Kenneth Graunke   brw_set_compression_control(p, BRW_COMPRESSION_NONE);
20074e927bcafad0a994be5f88fbda4058bef08bc51Kenneth Graunke   brw_math(p, dst,
20174e927bcafad0a994be5f88fbda4058bef08bc51Kenneth Graunke	    op,
20274e927bcafad0a994be5f88fbda4058bef08bc51Kenneth Graunke	    0, src0,
20374e927bcafad0a994be5f88fbda4058bef08bc51Kenneth Graunke	    BRW_MATH_DATA_VECTOR,
20474e927bcafad0a994be5f88fbda4058bef08bc51Kenneth Graunke	    BRW_MATH_PRECISION_FULL);
20511dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt
20674e927bcafad0a994be5f88fbda4058bef08bc51Kenneth Graunke   if (c->dispatch_width == 16) {
20774e927bcafad0a994be5f88fbda4058bef08bc51Kenneth Graunke      brw_set_compression_control(p, BRW_COMPRESSION_2NDHALF);
20874e927bcafad0a994be5f88fbda4058bef08bc51Kenneth Graunke      brw_math(p, sechalf(dst),
20911dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	       op,
21074e927bcafad0a994be5f88fbda4058bef08bc51Kenneth Graunke	       0, sechalf(src0),
21111dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	       BRW_MATH_DATA_VECTOR,
21211dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	       BRW_MATH_PRECISION_FULL);
21374e927bcafad0a994be5f88fbda4058bef08bc51Kenneth Graunke      brw_set_compression_control(p, BRW_COMPRESSION_COMPRESSED);
21474e927bcafad0a994be5f88fbda4058bef08bc51Kenneth Graunke   }
21574e927bcafad0a994be5f88fbda4058bef08bc51Kenneth Graunke}
21611dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt
21774e927bcafad0a994be5f88fbda4058bef08bc51Kenneth Graunkevoid
21874e927bcafad0a994be5f88fbda4058bef08bc51Kenneth Graunkefs_visitor::generate_math2_gen6(fs_inst *inst,
21974e927bcafad0a994be5f88fbda4058bef08bc51Kenneth Graunke			        struct brw_reg dst,
22074e927bcafad0a994be5f88fbda4058bef08bc51Kenneth Graunke			        struct brw_reg src0,
22174e927bcafad0a994be5f88fbda4058bef08bc51Kenneth Graunke			        struct brw_reg src1)
22274e927bcafad0a994be5f88fbda4058bef08bc51Kenneth Graunke{
22374e927bcafad0a994be5f88fbda4058bef08bc51Kenneth Graunke   int op = brw_math_function(inst->opcode);
22411dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt
22574e927bcafad0a994be5f88fbda4058bef08bc51Kenneth Graunke   assert(inst->mlen == 0);
22674e927bcafad0a994be5f88fbda4058bef08bc51Kenneth Graunke
22774e927bcafad0a994be5f88fbda4058bef08bc51Kenneth Graunke   brw_set_compression_control(p, BRW_COMPRESSION_NONE);
22874e927bcafad0a994be5f88fbda4058bef08bc51Kenneth Graunke   brw_math2(p, dst, op, src0, src1);
22974e927bcafad0a994be5f88fbda4058bef08bc51Kenneth Graunke
23074e927bcafad0a994be5f88fbda4058bef08bc51Kenneth Graunke   if (c->dispatch_width == 16) {
23174e927bcafad0a994be5f88fbda4058bef08bc51Kenneth Graunke      brw_set_compression_control(p, BRW_COMPRESSION_2NDHALF);
23274e927bcafad0a994be5f88fbda4058bef08bc51Kenneth Graunke      brw_math2(p, sechalf(dst), op, sechalf(src0), sechalf(src1));
23374e927bcafad0a994be5f88fbda4058bef08bc51Kenneth Graunke      brw_set_compression_control(p, BRW_COMPRESSION_COMPRESSED);
23474e927bcafad0a994be5f88fbda4058bef08bc51Kenneth Graunke   }
23574e927bcafad0a994be5f88fbda4058bef08bc51Kenneth Graunke}
23674e927bcafad0a994be5f88fbda4058bef08bc51Kenneth Graunke
23774e927bcafad0a994be5f88fbda4058bef08bc51Kenneth Graunkevoid
23874e927bcafad0a994be5f88fbda4058bef08bc51Kenneth Graunkefs_visitor::generate_math_gen4(fs_inst *inst,
23974e927bcafad0a994be5f88fbda4058bef08bc51Kenneth Graunke			       struct brw_reg dst,
24074e927bcafad0a994be5f88fbda4058bef08bc51Kenneth Graunke			       struct brw_reg src)
24174e927bcafad0a994be5f88fbda4058bef08bc51Kenneth Graunke{
24274e927bcafad0a994be5f88fbda4058bef08bc51Kenneth Graunke   int op = brw_math_function(inst->opcode);
24374e927bcafad0a994be5f88fbda4058bef08bc51Kenneth Graunke
24474e927bcafad0a994be5f88fbda4058bef08bc51Kenneth Graunke   assert(inst->mlen >= 1);
24574e927bcafad0a994be5f88fbda4058bef08bc51Kenneth Graunke
24674e927bcafad0a994be5f88fbda4058bef08bc51Kenneth Graunke   brw_set_compression_control(p, BRW_COMPRESSION_NONE);
24774e927bcafad0a994be5f88fbda4058bef08bc51Kenneth Graunke   brw_math(p, dst,
24874e927bcafad0a994be5f88fbda4058bef08bc51Kenneth Graunke	    op,
24974e927bcafad0a994be5f88fbda4058bef08bc51Kenneth Graunke	    inst->base_mrf, src,
25074e927bcafad0a994be5f88fbda4058bef08bc51Kenneth Graunke	    BRW_MATH_DATA_VECTOR,
25174e927bcafad0a994be5f88fbda4058bef08bc51Kenneth Graunke	    BRW_MATH_PRECISION_FULL);
25274e927bcafad0a994be5f88fbda4058bef08bc51Kenneth Graunke
25374e927bcafad0a994be5f88fbda4058bef08bc51Kenneth Graunke   if (c->dispatch_width == 16) {
25474e927bcafad0a994be5f88fbda4058bef08bc51Kenneth Graunke      brw_set_compression_control(p, BRW_COMPRESSION_2NDHALF);
25574e927bcafad0a994be5f88fbda4058bef08bc51Kenneth Graunke      brw_math(p, sechalf(dst),
25674e927bcafad0a994be5f88fbda4058bef08bc51Kenneth Graunke	       op,
25774e927bcafad0a994be5f88fbda4058bef08bc51Kenneth Graunke	       inst->base_mrf + 1, sechalf(src),
25874e927bcafad0a994be5f88fbda4058bef08bc51Kenneth Graunke	       BRW_MATH_DATA_VECTOR,
25974e927bcafad0a994be5f88fbda4058bef08bc51Kenneth Graunke	       BRW_MATH_PRECISION_FULL);
26074e927bcafad0a994be5f88fbda4058bef08bc51Kenneth Graunke
26174e927bcafad0a994be5f88fbda4058bef08bc51Kenneth Graunke      brw_set_compression_control(p, BRW_COMPRESSION_COMPRESSED);
26211dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt   }
26311dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt}
26411dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt
26511dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholtvoid
26611dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholtfs_visitor::generate_tex(fs_inst *inst, struct brw_reg dst, struct brw_reg src)
26711dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt{
26811dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt   int msg_type = -1;
26911dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt   int rlen = 4;
27011dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt   uint32_t simd_mode = BRW_SAMPLER_SIMD_MODE_SIMD8;
2717e84a64dd02794a59586ba58ef0864118534d3c6Eric Anholt   uint32_t return_format;
2727e84a64dd02794a59586ba58ef0864118534d3c6Eric Anholt
2737e84a64dd02794a59586ba58ef0864118534d3c6Eric Anholt   switch (dst.type) {
2747e84a64dd02794a59586ba58ef0864118534d3c6Eric Anholt   case BRW_REGISTER_TYPE_D:
2757e84a64dd02794a59586ba58ef0864118534d3c6Eric Anholt      return_format = BRW_SAMPLER_RETURN_FORMAT_SINT32;
2767e84a64dd02794a59586ba58ef0864118534d3c6Eric Anholt      break;
2777e84a64dd02794a59586ba58ef0864118534d3c6Eric Anholt   case BRW_REGISTER_TYPE_UD:
2787e84a64dd02794a59586ba58ef0864118534d3c6Eric Anholt      return_format = BRW_SAMPLER_RETURN_FORMAT_UINT32;
2797e84a64dd02794a59586ba58ef0864118534d3c6Eric Anholt      break;
2807e84a64dd02794a59586ba58ef0864118534d3c6Eric Anholt   default:
2817e84a64dd02794a59586ba58ef0864118534d3c6Eric Anholt      return_format = BRW_SAMPLER_RETURN_FORMAT_FLOAT32;
2827e84a64dd02794a59586ba58ef0864118534d3c6Eric Anholt      break;
2837e84a64dd02794a59586ba58ef0864118534d3c6Eric Anholt   }
28411dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt
28511dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt   if (c->dispatch_width == 16)
28611dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt      simd_mode = BRW_SAMPLER_SIMD_MODE_SIMD16;
28711dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt
28811dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt   if (intel->gen >= 5) {
28911dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt      switch (inst->opcode) {
290febad1779ae5cb5c85d66c2635baea62da52d2faKenneth Graunke      case SHADER_OPCODE_TEX:
29111dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	 if (inst->shadow_compare) {
29211dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	    msg_type = GEN5_SAMPLER_MESSAGE_SAMPLE_COMPARE;
29311dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	 } else {
29411dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	    msg_type = GEN5_SAMPLER_MESSAGE_SAMPLE;
29511dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	 }
29611dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	 break;
29711dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt      case FS_OPCODE_TXB:
29811dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	 if (inst->shadow_compare) {
29911dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	    msg_type = GEN5_SAMPLER_MESSAGE_SAMPLE_BIAS_COMPARE;
30011dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	 } else {
30111dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	    msg_type = GEN5_SAMPLER_MESSAGE_SAMPLE_BIAS;
30211dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	 }
30311dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	 break;
304febad1779ae5cb5c85d66c2635baea62da52d2faKenneth Graunke      case SHADER_OPCODE_TXL:
30511dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	 if (inst->shadow_compare) {
30611dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	    msg_type = GEN5_SAMPLER_MESSAGE_SAMPLE_LOD_COMPARE;
30711dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	 } else {
30811dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	    msg_type = GEN5_SAMPLER_MESSAGE_SAMPLE_LOD;
30911dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	 }
31011dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	 break;
311febad1779ae5cb5c85d66c2635baea62da52d2faKenneth Graunke      case SHADER_OPCODE_TXS:
312ecf8963754489abfb5097c130a9bcd4cdb76b6bdKenneth Graunke	 msg_type = GEN5_SAMPLER_MESSAGE_SAMPLE_RESINFO;
313ecf8963754489abfb5097c130a9bcd4cdb76b6bdKenneth Graunke	 break;
314febad1779ae5cb5c85d66c2635baea62da52d2faKenneth Graunke      case SHADER_OPCODE_TXD:
315d02343e5016a5795451af3e0315b658b39463a30Kenneth Graunke         if (inst->shadow_compare) {
316d02343e5016a5795451af3e0315b658b39463a30Kenneth Graunke            /* Gen7.5+.  Otherwise, lowered by brw_lower_texture_gradients(). */
317d02343e5016a5795451af3e0315b658b39463a30Kenneth Graunke            assert(intel->is_haswell);
318d02343e5016a5795451af3e0315b658b39463a30Kenneth Graunke            msg_type = HSW_SAMPLER_MESSAGE_SAMPLE_DERIV_COMPARE;
319d02343e5016a5795451af3e0315b658b39463a30Kenneth Graunke         } else {
320d02343e5016a5795451af3e0315b658b39463a30Kenneth Graunke            msg_type = GEN5_SAMPLER_MESSAGE_SAMPLE_DERIVS;
321d02343e5016a5795451af3e0315b658b39463a30Kenneth Graunke         }
32211dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	 break;
323febad1779ae5cb5c85d66c2635baea62da52d2faKenneth Graunke      case SHADER_OPCODE_TXF:
32430be2cc6c7c3378ee17885b5bf41d7ae53bf6fe0Kenneth Graunke	 msg_type = GEN5_SAMPLER_MESSAGE_SAMPLE_LD;
32530be2cc6c7c3378ee17885b5bf41d7ae53bf6fe0Kenneth Graunke	 break;
3266034b9a5124475d300d0678bd2fb6160865fa972Eric Anholt      default:
3276034b9a5124475d300d0678bd2fb6160865fa972Eric Anholt	 assert(!"not reached");
3286034b9a5124475d300d0678bd2fb6160865fa972Eric Anholt	 break;
32911dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt      }
33011dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt   } else {
33111dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt      switch (inst->opcode) {
332febad1779ae5cb5c85d66c2635baea62da52d2faKenneth Graunke      case SHADER_OPCODE_TEX:
33311dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	 /* Note that G45 and older determines shadow compare and dispatch width
33411dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	  * from message length for most messages.
33511dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	  */
33611dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	 assert(c->dispatch_width == 8);
33711dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	 msg_type = BRW_SAMPLER_MESSAGE_SIMD8_SAMPLE;
33811dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	 if (inst->shadow_compare) {
33911dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	    assert(inst->mlen == 6);
34011dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	 } else {
34111dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	    assert(inst->mlen <= 4);
34211dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	 }
34311dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	 break;
34411dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt      case FS_OPCODE_TXB:
34511dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	 if (inst->shadow_compare) {
34611dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	    assert(inst->mlen == 6);
34711dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	    msg_type = BRW_SAMPLER_MESSAGE_SIMD8_SAMPLE_BIAS_COMPARE;
34811dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	 } else {
34911dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	    assert(inst->mlen == 9);
35011dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	    msg_type = BRW_SAMPLER_MESSAGE_SIMD16_SAMPLE_BIAS;
35111dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	    simd_mode = BRW_SAMPLER_SIMD_MODE_SIMD16;
35211dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	 }
35311dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	 break;
354febad1779ae5cb5c85d66c2635baea62da52d2faKenneth Graunke      case SHADER_OPCODE_TXL:
35511dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	 if (inst->shadow_compare) {
35611dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	    assert(inst->mlen == 6);
35711dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	    msg_type = BRW_SAMPLER_MESSAGE_SIMD8_SAMPLE_LOD_COMPARE;
35811dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	 } else {
35911dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	    assert(inst->mlen == 9);
36011dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	    msg_type = BRW_SAMPLER_MESSAGE_SIMD16_SAMPLE_LOD;
36111dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	    simd_mode = BRW_SAMPLER_SIMD_MODE_SIMD16;
36211dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	 }
36311dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	 break;
364febad1779ae5cb5c85d66c2635baea62da52d2faKenneth Graunke      case SHADER_OPCODE_TXD:
3656430df37736d71dd2bd6f1fe447d39f0b68cb567Kenneth Graunke	 /* There is no sample_d_c message; comparisons are done manually */
3666c947cfd1973c3791d54f1406c973357b4a9621aKenneth Graunke	 assert(inst->mlen == 7 || inst->mlen == 10);
3676c947cfd1973c3791d54f1406c973357b4a9621aKenneth Graunke	 msg_type = BRW_SAMPLER_MESSAGE_SIMD8_SAMPLE_GRADIENTS;
36811dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	 break;
369febad1779ae5cb5c85d66c2635baea62da52d2faKenneth Graunke      case SHADER_OPCODE_TXF:
37047b556fbcaea4660b21481e40d89167d883d47f5Kenneth Graunke	 assert(inst->mlen == 9);
37147b556fbcaea4660b21481e40d89167d883d47f5Kenneth Graunke	 msg_type = BRW_SAMPLER_MESSAGE_SIMD16_LD;
37247b556fbcaea4660b21481e40d89167d883d47f5Kenneth Graunke	 simd_mode = BRW_SAMPLER_SIMD_MODE_SIMD16;
37347b556fbcaea4660b21481e40d89167d883d47f5Kenneth Graunke	 break;
374febad1779ae5cb5c85d66c2635baea62da52d2faKenneth Graunke      case SHADER_OPCODE_TXS:
3754eeb4c150598605d1be3ce6674fa63076a720ae9Kenneth Graunke	 assert(inst->mlen == 3);
3764eeb4c150598605d1be3ce6674fa63076a720ae9Kenneth Graunke	 msg_type = BRW_SAMPLER_MESSAGE_SIMD16_RESINFO;
3774eeb4c150598605d1be3ce6674fa63076a720ae9Kenneth Graunke	 simd_mode = BRW_SAMPLER_SIMD_MODE_SIMD16;
3784eeb4c150598605d1be3ce6674fa63076a720ae9Kenneth Graunke	 break;
3796034b9a5124475d300d0678bd2fb6160865fa972Eric Anholt      default:
3806034b9a5124475d300d0678bd2fb6160865fa972Eric Anholt	 assert(!"not reached");
3816034b9a5124475d300d0678bd2fb6160865fa972Eric Anholt	 break;
38211dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt      }
38311dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt   }
38411dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt   assert(msg_type != -1);
38511dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt
38611dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt   if (simd_mode == BRW_SAMPLER_SIMD_MODE_SIMD16) {
38711dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt      rlen = 8;
38811dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt      dst = vec16(dst);
38911dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt   }
39011dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt
39182bfb4b41af7d61aa45e41d62c1842b6a09e9585Kenneth Graunke   /* Load the message header if present.  If there's a texture offset,
39282bfb4b41af7d61aa45e41d62c1842b6a09e9585Kenneth Graunke    * we need to set it up explicitly and load the offset bitfield.
39382bfb4b41af7d61aa45e41d62c1842b6a09e9585Kenneth Graunke    * Otherwise, we can use an implied move from g0 to the first message reg.
39482bfb4b41af7d61aa45e41d62c1842b6a09e9585Kenneth Graunke    */
39582bfb4b41af7d61aa45e41d62c1842b6a09e9585Kenneth Graunke   if (inst->texture_offset) {
39682bfb4b41af7d61aa45e41d62c1842b6a09e9585Kenneth Graunke      brw_push_insn_state(p);
39782bfb4b41af7d61aa45e41d62c1842b6a09e9585Kenneth Graunke      brw_set_compression_control(p, BRW_COMPRESSION_NONE);
39882bfb4b41af7d61aa45e41d62c1842b6a09e9585Kenneth Graunke      /* Explicitly set up the message header by copying g0 to the MRF. */
39982bfb4b41af7d61aa45e41d62c1842b6a09e9585Kenneth Graunke      brw_MOV(p, retype(brw_message_reg(inst->base_mrf), BRW_REGISTER_TYPE_UD),
40082bfb4b41af7d61aa45e41d62c1842b6a09e9585Kenneth Graunke                 retype(brw_vec8_grf(0, 0), BRW_REGISTER_TYPE_UD));
40182bfb4b41af7d61aa45e41d62c1842b6a09e9585Kenneth Graunke
40282bfb4b41af7d61aa45e41d62c1842b6a09e9585Kenneth Graunke      /* Then set the offset bits in DWord 2. */
40382bfb4b41af7d61aa45e41d62c1842b6a09e9585Kenneth Graunke      brw_MOV(p, retype(brw_vec1_reg(BRW_MESSAGE_REGISTER_FILE,
40482bfb4b41af7d61aa45e41d62c1842b6a09e9585Kenneth Graunke                                     inst->base_mrf, 2), BRW_REGISTER_TYPE_UD),
40582bfb4b41af7d61aa45e41d62c1842b6a09e9585Kenneth Graunke                 brw_imm_ud(inst->texture_offset));
40682bfb4b41af7d61aa45e41d62c1842b6a09e9585Kenneth Graunke      brw_pop_insn_state(p);
40782bfb4b41af7d61aa45e41d62c1842b6a09e9585Kenneth Graunke   } else if (inst->header_present) {
40882bfb4b41af7d61aa45e41d62c1842b6a09e9585Kenneth Graunke      /* Set up an implied move from g0 to the MRF. */
40982bfb4b41af7d61aa45e41d62c1842b6a09e9585Kenneth Graunke      src = retype(brw_vec8_grf(0, 0), BRW_REGISTER_TYPE_UW);
41082bfb4b41af7d61aa45e41d62c1842b6a09e9585Kenneth Graunke   }
41182bfb4b41af7d61aa45e41d62c1842b6a09e9585Kenneth Graunke
41211dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt   brw_SAMPLE(p,
41311dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	      retype(dst, BRW_REGISTER_TYPE_UW),
41411dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	      inst->base_mrf,
41511dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	      src,
41611dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt              SURF_INDEX_TEXTURE(inst->sampler),
41711dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	      inst->sampler,
41811dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	      WRITEMASK_XYZW,
41911dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	      msg_type,
42011dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	      rlen,
42111dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	      inst->mlen,
42211dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	      inst->header_present,
4237e84a64dd02794a59586ba58ef0864118534d3c6Eric Anholt	      simd_mode,
4247e84a64dd02794a59586ba58ef0864118534d3c6Eric Anholt	      return_format);
42511dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt}
42611dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt
42711dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt
42811dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt/* For OPCODE_DDX and OPCODE_DDY, per channel of output we've got input
42911dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt * looking like:
43011dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt *
43111dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt * arg0: ss0.tl ss0.tr ss0.bl ss0.br ss1.tl ss1.tr ss1.bl ss1.br
43211dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt *
43311dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt * and we're trying to produce:
43411dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt *
43511dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt *           DDX                     DDY
43611dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt * dst: (ss0.tr - ss0.tl)     (ss0.tl - ss0.bl)
43711dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt *      (ss0.tr - ss0.tl)     (ss0.tr - ss0.br)
43811dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt *      (ss0.br - ss0.bl)     (ss0.tl - ss0.bl)
43911dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt *      (ss0.br - ss0.bl)     (ss0.tr - ss0.br)
44011dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt *      (ss1.tr - ss1.tl)     (ss1.tl - ss1.bl)
44111dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt *      (ss1.tr - ss1.tl)     (ss1.tr - ss1.br)
44211dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt *      (ss1.br - ss1.bl)     (ss1.tl - ss1.bl)
44311dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt *      (ss1.br - ss1.bl)     (ss1.tr - ss1.br)
44411dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt *
44511dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt * and add another set of two more subspans if in 16-pixel dispatch mode.
44611dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt *
44711dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt * For DDX, it ends up being easy: width = 2, horiz=0 gets us the same result
44811dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt * for each pair, and vertstride = 2 jumps us 2 elements after processing a
44911dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt * pair. But for DDY, it's harder, as we want to produce the pairs swizzled
45011dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt * between each other.  We could probably do it like ddx and swizzle the right
45111dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt * order later, but bail for now and just produce
45211dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt * ((ss0.tl - ss0.bl)x4 (ss1.tl - ss1.bl)x4)
45311dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt */
45411dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholtvoid
45511dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholtfs_visitor::generate_ddx(fs_inst *inst, struct brw_reg dst, struct brw_reg src)
45611dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt{
45711dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt   struct brw_reg src0 = brw_reg(src.file, src.nr, 1,
45811dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt				 BRW_REGISTER_TYPE_F,
45911dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt				 BRW_VERTICAL_STRIDE_2,
46011dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt				 BRW_WIDTH_2,
46111dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt				 BRW_HORIZONTAL_STRIDE_0,
46211dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt				 BRW_SWIZZLE_XYZW, WRITEMASK_XYZW);
46311dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt   struct brw_reg src1 = brw_reg(src.file, src.nr, 0,
46411dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt				 BRW_REGISTER_TYPE_F,
46511dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt				 BRW_VERTICAL_STRIDE_2,
46611dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt				 BRW_WIDTH_2,
46711dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt				 BRW_HORIZONTAL_STRIDE_0,
46811dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt				 BRW_SWIZZLE_XYZW, WRITEMASK_XYZW);
46911dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt   brw_ADD(p, dst, src0, negate(src1));
47011dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt}
47111dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt
47282d25963a838cfebdeb9b080169979329ee850eaPaul Berry/* The negate_value boolean is used to negate the derivative computation for
47382d25963a838cfebdeb9b080169979329ee850eaPaul Berry * FBOs, since they place the origin at the upper left instead of the lower
47482d25963a838cfebdeb9b080169979329ee850eaPaul Berry * left.
47582d25963a838cfebdeb9b080169979329ee850eaPaul Berry */
47611dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholtvoid
47782d25963a838cfebdeb9b080169979329ee850eaPaul Berryfs_visitor::generate_ddy(fs_inst *inst, struct brw_reg dst, struct brw_reg src,
47882d25963a838cfebdeb9b080169979329ee850eaPaul Berry                         bool negate_value)
47911dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt{
48011dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt   struct brw_reg src0 = brw_reg(src.file, src.nr, 0,
48111dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt				 BRW_REGISTER_TYPE_F,
48211dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt				 BRW_VERTICAL_STRIDE_4,
48311dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt				 BRW_WIDTH_4,
48411dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt				 BRW_HORIZONTAL_STRIDE_0,
48511dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt				 BRW_SWIZZLE_XYZW, WRITEMASK_XYZW);
48611dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt   struct brw_reg src1 = brw_reg(src.file, src.nr, 2,
48711dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt				 BRW_REGISTER_TYPE_F,
48811dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt				 BRW_VERTICAL_STRIDE_4,
48911dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt				 BRW_WIDTH_4,
49011dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt				 BRW_HORIZONTAL_STRIDE_0,
49111dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt				 BRW_SWIZZLE_XYZW, WRITEMASK_XYZW);
49282d25963a838cfebdeb9b080169979329ee850eaPaul Berry   if (negate_value)
49382d25963a838cfebdeb9b080169979329ee850eaPaul Berry      brw_ADD(p, dst, src1, negate(src0));
49482d25963a838cfebdeb9b080169979329ee850eaPaul Berry   else
49582d25963a838cfebdeb9b080169979329ee850eaPaul Berry      brw_ADD(p, dst, src0, negate(src1));
49611dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt}
49711dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt
49811dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholtvoid
49911dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholtfs_visitor::generate_discard(fs_inst *inst)
50011dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt{
50111dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt   struct brw_reg f0 = brw_flag_reg();
50211dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt
50311dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt   if (intel->gen >= 6) {
50411dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt      struct brw_reg g1 = retype(brw_vec1_grf(1, 7), BRW_REGISTER_TYPE_UW);
50511dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt      struct brw_reg some_register;
50611dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt
50711dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt      /* As of gen6, we no longer have the mask register to look at,
50811dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt       * so life gets a bit more complicated.
50911dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt       */
51011dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt
51111dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt      /* Load the flag register with all ones. */
51211dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt      brw_push_insn_state(p);
51311dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt      brw_set_mask_control(p, BRW_MASK_DISABLE);
51411dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt      brw_MOV(p, f0, brw_imm_uw(0xffff));
51511dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt      brw_pop_insn_state(p);
51611dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt
51711dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt      /* Do a comparison that should always fail, to produce 0s in the flag
51811dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt       * reg where we have active channels.
51911dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt       */
52011dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt      some_register = retype(brw_vec8_grf(0, 0), BRW_REGISTER_TYPE_UW);
52111dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt      brw_CMP(p, retype(brw_null_reg(), BRW_REGISTER_TYPE_UD),
52211dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	      BRW_CONDITIONAL_NZ, some_register, some_register);
52311dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt
52411dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt      /* Undo CMP's whacking of predication*/
52511dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt      brw_set_predicate_control(p, BRW_PREDICATE_NONE);
52611dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt
52711dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt      brw_push_insn_state(p);
52811dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt      brw_set_mask_control(p, BRW_MASK_DISABLE);
52911dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt      brw_AND(p, g1, f0, g1);
53011dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt      brw_pop_insn_state(p);
53111dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt   } else {
53211dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt      struct brw_reg g0 = retype(brw_vec1_grf(0, 0), BRW_REGISTER_TYPE_UW);
53311dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt
53411dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt      brw_push_insn_state(p);
53511dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt      brw_set_mask_control(p, BRW_MASK_DISABLE);
53611dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt      brw_set_compression_control(p, BRW_COMPRESSION_NONE);
53711dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt
53811dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt      /* Unlike the 965, we have the mask reg, so we just need
53911dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt       * somewhere to invert that (containing channels to be disabled)
54011dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt       * so it can be ANDed with the mask of pixels still to be
54111dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt       * written. Use the flag reg for consistency with gen6+.
54211dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt       */
54311dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt      brw_NOT(p, f0, brw_mask_reg(1)); /* IMASK */
54411dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt      brw_AND(p, g0, f0, g0);
54511dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt
54611dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt      brw_pop_insn_state(p);
54711dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt   }
54811dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt}
54911dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt
55011dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholtvoid
55111dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholtfs_visitor::generate_spill(fs_inst *inst, struct brw_reg src)
55211dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt{
55311dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt   assert(inst->mlen != 0);
55411dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt
55511dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt   brw_MOV(p,
55611dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	   retype(brw_message_reg(inst->base_mrf + 1), BRW_REGISTER_TYPE_UD),
55711dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	   retype(src, BRW_REGISTER_TYPE_UD));
55811dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt   brw_oword_block_write_scratch(p, brw_message_reg(inst->base_mrf), 1,
55911dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt				 inst->offset);
56011dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt}
56111dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt
56211dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholtvoid
56311dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholtfs_visitor::generate_unspill(fs_inst *inst, struct brw_reg dst)
56411dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt{
56511dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt   assert(inst->mlen != 0);
56611dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt
56711dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt   /* Clear any post destination dependencies that would be ignored by
56811dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt    * the block read.  See the B-Spec for pre-gen5 send instruction.
56911dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt    *
57011dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt    * This could use a better solution, since texture sampling and
57111dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt    * math reads could potentially run into it as well -- anywhere
57211dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt    * that we have a SEND with a destination that is a register that
57311dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt    * was written but not read within the last N instructions (what's
57411dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt    * N?  unsure).  This is rare because of dead code elimination, but
57511dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt    * not impossible.
57611dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt    */
57711dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt   if (intel->gen == 4 && !intel->is_g4x)
57811dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt      brw_MOV(p, brw_null_reg(), dst);
57911dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt
58011dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt   brw_oword_block_read_scratch(p, dst, brw_message_reg(inst->base_mrf), 1,
58111dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt				inst->offset);
58211dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt
58311dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt   if (intel->gen == 4 && !intel->is_g4x) {
58411dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt      /* gen4 errata: destination from a send can't be used as a
58511dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt       * destination until it's been read.  Just read it so we don't
58611dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt       * have to worry.
58711dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt       */
58811dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt      brw_MOV(p, brw_null_reg(), dst);
58911dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt   }
59011dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt}
59111dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt
59211dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholtvoid
593454dc83f66643e66ea7ee9117368211f0cfe84d7Eric Anholtfs_visitor::generate_pull_constant_load(fs_inst *inst, struct brw_reg dst,
594454dc83f66643e66ea7ee9117368211f0cfe84d7Eric Anholt					struct brw_reg index,
595454dc83f66643e66ea7ee9117368211f0cfe84d7Eric Anholt					struct brw_reg offset)
59611dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt{
59711dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt   assert(inst->mlen != 0);
59811dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt
59911dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt   /* Clear any post destination dependencies that would be ignored by
60011dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt    * the block read.  See the B-Spec for pre-gen5 send instruction.
60111dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt    *
60211dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt    * This could use a better solution, since texture sampling and
60311dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt    * math reads could potentially run into it as well -- anywhere
60411dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt    * that we have a SEND with a destination that is a register that
60511dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt    * was written but not read within the last N instructions (what's
60611dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt    * N?  unsure).  This is rare because of dead code elimination, but
60711dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt    * not impossible.
60811dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt    */
60911dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt   if (intel->gen == 4 && !intel->is_g4x)
61011dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt      brw_MOV(p, brw_null_reg(), dst);
61111dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt
612454dc83f66643e66ea7ee9117368211f0cfe84d7Eric Anholt   assert(index.file == BRW_IMMEDIATE_VALUE &&
613454dc83f66643e66ea7ee9117368211f0cfe84d7Eric Anholt	  index.type == BRW_REGISTER_TYPE_UD);
614454dc83f66643e66ea7ee9117368211f0cfe84d7Eric Anholt   uint32_t surf_index = index.dw1.ud;
615454dc83f66643e66ea7ee9117368211f0cfe84d7Eric Anholt
616454dc83f66643e66ea7ee9117368211f0cfe84d7Eric Anholt   assert(offset.file == BRW_IMMEDIATE_VALUE &&
617454dc83f66643e66ea7ee9117368211f0cfe84d7Eric Anholt	  offset.type == BRW_REGISTER_TYPE_UD);
618454dc83f66643e66ea7ee9117368211f0cfe84d7Eric Anholt   uint32_t read_offset = offset.dw1.ud;
619454dc83f66643e66ea7ee9117368211f0cfe84d7Eric Anholt
62011dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt   brw_oword_block_read(p, dst, brw_message_reg(inst->base_mrf),
621454dc83f66643e66ea7ee9117368211f0cfe84d7Eric Anholt			read_offset, surf_index);
62211dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt
62311dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt   if (intel->gen == 4 && !intel->is_g4x) {
62411dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt      /* gen4 errata: destination from a send can't be used as a
62511dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt       * destination until it's been read.  Just read it so we don't
62611dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt       * have to worry.
62711dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt       */
62811dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt      brw_MOV(p, brw_null_reg(), dst);
62911dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt   }
63011dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt}
63111dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt
6323f929efa2872aa5a4402520ec9fd551392e2413aPaul Berry
6333f929efa2872aa5a4402520ec9fd551392e2413aPaul Berry/**
6343f929efa2872aa5a4402520ec9fd551392e2413aPaul Berry * Cause the current pixel/sample mask (from R1.7 bits 15:0) to be transferred
6353f929efa2872aa5a4402520ec9fd551392e2413aPaul Berry * into the flags register (f0.0).
6363f929efa2872aa5a4402520ec9fd551392e2413aPaul Berry *
6373f929efa2872aa5a4402520ec9fd551392e2413aPaul Berry * Used only on Gen6 and above.
6383f929efa2872aa5a4402520ec9fd551392e2413aPaul Berry */
6393f929efa2872aa5a4402520ec9fd551392e2413aPaul Berryvoid
6403f929efa2872aa5a4402520ec9fd551392e2413aPaul Berryfs_visitor::generate_mov_dispatch_to_flags()
6413f929efa2872aa5a4402520ec9fd551392e2413aPaul Berry{
6423f929efa2872aa5a4402520ec9fd551392e2413aPaul Berry   struct brw_reg f0 = brw_flag_reg();
6433f929efa2872aa5a4402520ec9fd551392e2413aPaul Berry   struct brw_reg g1 = retype(brw_vec1_grf(1, 7), BRW_REGISTER_TYPE_UW);
6443f929efa2872aa5a4402520ec9fd551392e2413aPaul Berry
6453f929efa2872aa5a4402520ec9fd551392e2413aPaul Berry   assert (intel->gen >= 6);
6463f929efa2872aa5a4402520ec9fd551392e2413aPaul Berry   brw_push_insn_state(p);
6473f929efa2872aa5a4402520ec9fd551392e2413aPaul Berry   brw_set_mask_control(p, BRW_MASK_DISABLE);
6483f929efa2872aa5a4402520ec9fd551392e2413aPaul Berry   brw_MOV(p, f0, g1);
6493f929efa2872aa5a4402520ec9fd551392e2413aPaul Berry   brw_pop_insn_state(p);
6503f929efa2872aa5a4402520ec9fd551392e2413aPaul Berry}
6513f929efa2872aa5a4402520ec9fd551392e2413aPaul Berry
6523f929efa2872aa5a4402520ec9fd551392e2413aPaul Berry
653a3b8c5ed5bd591d4ae7d215f71f039d3b19200bbEric Anholtstatic uint32_t brw_file_from_reg(fs_reg *reg)
654a3b8c5ed5bd591d4ae7d215f71f039d3b19200bbEric Anholt{
655a3b8c5ed5bd591d4ae7d215f71f039d3b19200bbEric Anholt   switch (reg->file) {
656a3b8c5ed5bd591d4ae7d215f71f039d3b19200bbEric Anholt   case ARF:
657a3b8c5ed5bd591d4ae7d215f71f039d3b19200bbEric Anholt      return BRW_ARCHITECTURE_REGISTER_FILE;
658a3b8c5ed5bd591d4ae7d215f71f039d3b19200bbEric Anholt   case GRF:
659a3b8c5ed5bd591d4ae7d215f71f039d3b19200bbEric Anholt      return BRW_GENERAL_REGISTER_FILE;
660a3b8c5ed5bd591d4ae7d215f71f039d3b19200bbEric Anholt   case MRF:
661a3b8c5ed5bd591d4ae7d215f71f039d3b19200bbEric Anholt      return BRW_MESSAGE_REGISTER_FILE;
662a3b8c5ed5bd591d4ae7d215f71f039d3b19200bbEric Anholt   case IMM:
663a3b8c5ed5bd591d4ae7d215f71f039d3b19200bbEric Anholt      return BRW_IMMEDIATE_VALUE;
664a3b8c5ed5bd591d4ae7d215f71f039d3b19200bbEric Anholt   default:
665a3b8c5ed5bd591d4ae7d215f71f039d3b19200bbEric Anholt      assert(!"not reached");
666a3b8c5ed5bd591d4ae7d215f71f039d3b19200bbEric Anholt      return BRW_GENERAL_REGISTER_FILE;
667a3b8c5ed5bd591d4ae7d215f71f039d3b19200bbEric Anholt   }
668a3b8c5ed5bd591d4ae7d215f71f039d3b19200bbEric Anholt}
669a3b8c5ed5bd591d4ae7d215f71f039d3b19200bbEric Anholt
67011dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholtstatic struct brw_reg
67111dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholtbrw_reg_from_fs_reg(fs_reg *reg)
67211dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt{
67311dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt   struct brw_reg brw_reg;
67411dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt
67511dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt   switch (reg->file) {
67611dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt   case GRF:
67711dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt   case ARF:
67811dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt   case MRF:
67911dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt      if (reg->smear == -1) {
680a3b8c5ed5bd591d4ae7d215f71f039d3b19200bbEric Anholt	 brw_reg = brw_vec8_reg(brw_file_from_reg(reg), reg->reg, 0);
68111dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt      } else {
682a3b8c5ed5bd591d4ae7d215f71f039d3b19200bbEric Anholt	 brw_reg = brw_vec1_reg(brw_file_from_reg(reg), reg->reg, reg->smear);
68311dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt      }
68411dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt      brw_reg = retype(brw_reg, reg->type);
68511dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt      if (reg->sechalf)
68611dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	 brw_reg = sechalf(brw_reg);
68711dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt      break;
68811dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt   case IMM:
68911dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt      switch (reg->type) {
69011dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt      case BRW_REGISTER_TYPE_F:
69111dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	 brw_reg = brw_imm_f(reg->imm.f);
69211dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	 break;
69311dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt      case BRW_REGISTER_TYPE_D:
69411dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	 brw_reg = brw_imm_d(reg->imm.i);
69511dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	 break;
69611dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt      case BRW_REGISTER_TYPE_UD:
69711dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	 brw_reg = brw_imm_ud(reg->imm.u);
69811dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	 break;
69911dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt      default:
70011dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	 assert(!"not reached");
70111dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	 brw_reg = brw_null_reg();
70211dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	 break;
70311dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt      }
70411dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt      break;
70511dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt   case FIXED_HW_REG:
70611dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt      brw_reg = reg->fixed_hw_reg;
70711dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt      break;
70811dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt   case BAD_FILE:
70911dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt      /* Probably unused. */
71011dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt      brw_reg = brw_null_reg();
71111dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt      break;
71211dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt   case UNIFORM:
71311dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt      assert(!"not reached");
71411dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt      brw_reg = brw_null_reg();
71511dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt      break;
71611dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt   default:
71711dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt      assert(!"not reached");
71811dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt      brw_reg = brw_null_reg();
71911dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt      break;
72011dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt   }
72111dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt   if (reg->abs)
72211dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt      brw_reg = brw_abs(brw_reg);
72311dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt   if (reg->negate)
72411dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt      brw_reg = negate(brw_reg);
72511dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt
72611dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt   return brw_reg;
72711dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt}
72811dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt
72911dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholtvoid
73011dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholtfs_visitor::generate_code()
73111dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt{
73211dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt   int last_native_inst = p->nr_insn;
73311dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt   const char *last_annotation_string = NULL;
73411dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt   ir_instruction *last_annotation_ir = NULL;
73511dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt
73611dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt   if (unlikely(INTEL_DEBUG & DEBUG_WM)) {
73711dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt      printf("Native code for fragment shader %d (%d-wide dispatch):\n",
7380653c450cc8da1212e1123a1cd6635c02f7d6919Eric Anholt	     prog->Name, c->dispatch_width);
73911dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt   }
74011dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt
741080b125c64b48447a515b1a169f779e62b3de13dEric Anholt   fs_cfg *cfg = NULL;
742080b125c64b48447a515b1a169f779e62b3de13dEric Anholt   if (unlikely(INTEL_DEBUG & DEBUG_WM))
743080b125c64b48447a515b1a169f779e62b3de13dEric Anholt      cfg = new(mem_ctx) fs_cfg(this);
744080b125c64b48447a515b1a169f779e62b3de13dEric Anholt
74544ffb4ae207e48f78fae55925601b8708ed09c1dEric Anholt   foreach_list(node, &this->instructions) {
74644ffb4ae207e48f78fae55925601b8708ed09c1dEric Anholt      fs_inst *inst = (fs_inst *)node;
74711dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt      struct brw_reg src[3], dst;
74811dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt
74911dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt      if (unlikely(INTEL_DEBUG & DEBUG_WM)) {
750080b125c64b48447a515b1a169f779e62b3de13dEric Anholt	 foreach_list(node, &cfg->block_list) {
751080b125c64b48447a515b1a169f779e62b3de13dEric Anholt	    fs_bblock_link *link = (fs_bblock_link *)node;
752080b125c64b48447a515b1a169f779e62b3de13dEric Anholt	    fs_bblock *block = link->block;
753080b125c64b48447a515b1a169f779e62b3de13dEric Anholt
754080b125c64b48447a515b1a169f779e62b3de13dEric Anholt	    if (block->start == inst) {
755080b125c64b48447a515b1a169f779e62b3de13dEric Anholt	       printf("   START B%d", block->block_num);
756080b125c64b48447a515b1a169f779e62b3de13dEric Anholt	       foreach_list(predecessor_node, &block->parents) {
757080b125c64b48447a515b1a169f779e62b3de13dEric Anholt		  fs_bblock_link *predecessor_link =
758080b125c64b48447a515b1a169f779e62b3de13dEric Anholt		     (fs_bblock_link *)predecessor_node;
759080b125c64b48447a515b1a169f779e62b3de13dEric Anholt		  fs_bblock *predecessor_block = predecessor_link->block;
760080b125c64b48447a515b1a169f779e62b3de13dEric Anholt		  printf(" <-B%d", predecessor_block->block_num);
761080b125c64b48447a515b1a169f779e62b3de13dEric Anholt	       }
762080b125c64b48447a515b1a169f779e62b3de13dEric Anholt	       printf("\n");
763080b125c64b48447a515b1a169f779e62b3de13dEric Anholt	    }
764080b125c64b48447a515b1a169f779e62b3de13dEric Anholt	 }
765080b125c64b48447a515b1a169f779e62b3de13dEric Anholt
76611dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	 if (last_annotation_ir != inst->ir) {
76711dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	    last_annotation_ir = inst->ir;
76811dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	    if (last_annotation_ir) {
76911dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	       printf("   ");
77011dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	       last_annotation_ir->print();
77111dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	       printf("\n");
77211dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	    }
77311dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	 }
77411dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	 if (last_annotation_string != inst->annotation) {
77511dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	    last_annotation_string = inst->annotation;
77611dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	    if (last_annotation_string)
77711dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	       printf("   %s\n", last_annotation_string);
77811dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	 }
77911dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt      }
78011dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt
78111dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt      for (unsigned int i = 0; i < 3; i++) {
78211dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	 src[i] = brw_reg_from_fs_reg(&inst->src[i]);
78373b0a28ba8b3e2ab917d4c729f34ddbde52c9e88Eric Anholt
78473b0a28ba8b3e2ab917d4c729f34ddbde52c9e88Eric Anholt	 /* The accumulator result appears to get used for the
78573b0a28ba8b3e2ab917d4c729f34ddbde52c9e88Eric Anholt	  * conditional modifier generation.  When negating a UD
78673b0a28ba8b3e2ab917d4c729f34ddbde52c9e88Eric Anholt	  * value, there is a 33rd bit generated for the sign in the
78773b0a28ba8b3e2ab917d4c729f34ddbde52c9e88Eric Anholt	  * accumulator value, so now you can't check, for example,
78873b0a28ba8b3e2ab917d4c729f34ddbde52c9e88Eric Anholt	  * equality with a 32-bit value.  See piglit fs-op-neg-uvec4.
78973b0a28ba8b3e2ab917d4c729f34ddbde52c9e88Eric Anholt	  */
79073b0a28ba8b3e2ab917d4c729f34ddbde52c9e88Eric Anholt	 assert(!inst->conditional_mod ||
79173b0a28ba8b3e2ab917d4c729f34ddbde52c9e88Eric Anholt		inst->src[i].type != BRW_REGISTER_TYPE_UD ||
79273b0a28ba8b3e2ab917d4c729f34ddbde52c9e88Eric Anholt		!inst->src[i].negate);
79311dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt      }
79411dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt      dst = brw_reg_from_fs_reg(&inst->dst);
79511dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt
79611dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt      brw_set_conditionalmod(p, inst->conditional_mod);
79711dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt      brw_set_predicate_control(p, inst->predicated);
79811dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt      brw_set_predicate_inverse(p, inst->predicate_inverse);
79911dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt      brw_set_saturate(p, inst->saturate);
80011dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt
80111dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt      if (inst->force_uncompressed || c->dispatch_width == 8) {
80211dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	 brw_set_compression_control(p, BRW_COMPRESSION_NONE);
80311dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt      } else if (inst->force_sechalf) {
80411dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	 brw_set_compression_control(p, BRW_COMPRESSION_2NDHALF);
80511dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt      } else {
80611dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	 brw_set_compression_control(p, BRW_COMPRESSION_COMPRESSED);
80711dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt      }
80811dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt
80911dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt      switch (inst->opcode) {
81011dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt      case BRW_OPCODE_MOV:
81111dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	 brw_MOV(p, dst, src[0]);
81211dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	 break;
81311dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt      case BRW_OPCODE_ADD:
81411dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	 brw_ADD(p, dst, src[0], src[1]);
81511dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	 break;
81611dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt      case BRW_OPCODE_MUL:
81711dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	 brw_MUL(p, dst, src[0], src[1]);
81811dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	 break;
8193f78f719732b87e6707f94c187ad6e263c6c2ef0Eric Anholt      case BRW_OPCODE_MACH:
8203f78f719732b87e6707f94c187ad6e263c6c2ef0Eric Anholt	 brw_set_acc_write_control(p, 1);
8213f78f719732b87e6707f94c187ad6e263c6c2ef0Eric Anholt	 brw_MACH(p, dst, src[0], src[1]);
8223f78f719732b87e6707f94c187ad6e263c6c2ef0Eric Anholt	 brw_set_acc_write_control(p, 0);
8233f78f719732b87e6707f94c187ad6e263c6c2ef0Eric Anholt	 break;
82411dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt
8257d55f37b0e87db9b3806088797075161a1c9a8bbEric Anholt      case BRW_OPCODE_MAD:
8267d55f37b0e87db9b3806088797075161a1c9a8bbEric Anholt	 brw_set_access_mode(p, BRW_ALIGN_16);
8277d55f37b0e87db9b3806088797075161a1c9a8bbEric Anholt	 if (c->dispatch_width == 16) {
8287d55f37b0e87db9b3806088797075161a1c9a8bbEric Anholt	    brw_set_compression_control(p, BRW_COMPRESSION_NONE);
8297d55f37b0e87db9b3806088797075161a1c9a8bbEric Anholt	    brw_MAD(p, dst, src[0], src[1], src[2]);
8307d55f37b0e87db9b3806088797075161a1c9a8bbEric Anholt	    brw_set_compression_control(p, BRW_COMPRESSION_2NDHALF);
8317d55f37b0e87db9b3806088797075161a1c9a8bbEric Anholt	    brw_MAD(p, sechalf(dst), sechalf(src[0]), sechalf(src[1]), sechalf(src[2]));
8327d55f37b0e87db9b3806088797075161a1c9a8bbEric Anholt	    brw_set_compression_control(p, BRW_COMPRESSION_COMPRESSED);
8337d55f37b0e87db9b3806088797075161a1c9a8bbEric Anholt	 } else {
8347d55f37b0e87db9b3806088797075161a1c9a8bbEric Anholt	    brw_MAD(p, dst, src[0], src[1], src[2]);
8357d55f37b0e87db9b3806088797075161a1c9a8bbEric Anholt	 }
8367d55f37b0e87db9b3806088797075161a1c9a8bbEric Anholt	 brw_set_access_mode(p, BRW_ALIGN_1);
8377d55f37b0e87db9b3806088797075161a1c9a8bbEric Anholt	 break;
8387d55f37b0e87db9b3806088797075161a1c9a8bbEric Anholt
83911dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt      case BRW_OPCODE_FRC:
84011dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	 brw_FRC(p, dst, src[0]);
84111dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	 break;
84211dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt      case BRW_OPCODE_RNDD:
84311dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	 brw_RNDD(p, dst, src[0]);
84411dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	 break;
84511dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt      case BRW_OPCODE_RNDE:
84611dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	 brw_RNDE(p, dst, src[0]);
84711dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	 break;
84811dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt      case BRW_OPCODE_RNDZ:
84911dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	 brw_RNDZ(p, dst, src[0]);
85011dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	 break;
85111dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt
85211dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt      case BRW_OPCODE_AND:
85311dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	 brw_AND(p, dst, src[0], src[1]);
85411dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	 break;
85511dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt      case BRW_OPCODE_OR:
85611dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	 brw_OR(p, dst, src[0], src[1]);
85711dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	 break;
85811dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt      case BRW_OPCODE_XOR:
85911dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	 brw_XOR(p, dst, src[0], src[1]);
86011dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	 break;
86111dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt      case BRW_OPCODE_NOT:
86211dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	 brw_NOT(p, dst, src[0]);
86311dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	 break;
86411dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt      case BRW_OPCODE_ASR:
86511dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	 brw_ASR(p, dst, src[0], src[1]);
86611dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	 break;
86711dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt      case BRW_OPCODE_SHR:
86811dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	 brw_SHR(p, dst, src[0], src[1]);
86911dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	 break;
87011dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt      case BRW_OPCODE_SHL:
87111dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	 brw_SHL(p, dst, src[0], src[1]);
87211dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	 break;
87311dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt
87411dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt      case BRW_OPCODE_CMP:
87511dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	 brw_CMP(p, dst, inst->conditional_mod, src[0], src[1]);
87611dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	 break;
87711dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt      case BRW_OPCODE_SEL:
87811dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	 brw_SEL(p, dst, src[0], src[1]);
87911dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	 break;
88011dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt
88111dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt      case BRW_OPCODE_IF:
88211dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	 if (inst->src[0].file != BAD_FILE) {
88311dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	    /* The instruction has an embedded compare (only allowed on gen6) */
88411dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	    assert(intel->gen == 6);
88511dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	    gen6_IF(p, inst->conditional_mod, src[0], src[1]);
88611dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	 } else {
88711dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	    brw_IF(p, c->dispatch_width == 16 ? BRW_EXECUTE_16 : BRW_EXECUTE_8);
88811dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	 }
88911dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	 break;
89011dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt
89111dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt      case BRW_OPCODE_ELSE:
89211dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	 brw_ELSE(p);
89311dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	 break;
89411dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt      case BRW_OPCODE_ENDIF:
89511dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	 brw_ENDIF(p);
89611dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	 break;
89711dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt
89811dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt      case BRW_OPCODE_DO:
899ce6be334bbf7f44c71ad5d190f9fb075d2f9a38cEric Anholt	 brw_DO(p, BRW_EXECUTE_8);
90011dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	 break;
90111dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt
90211dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt      case BRW_OPCODE_BREAK:
903f1d89638c02afafbf82ef657cd6ba9965dad6738Eric Anholt	 brw_BREAK(p);
90411dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	 brw_set_predicate_control(p, BRW_PREDICATE_NONE);
90511dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	 break;
90611dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt      case BRW_OPCODE_CONTINUE:
90711dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	 /* FINISHME: We need to write the loop instruction support still. */
90811dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	 if (intel->gen >= 6)
9099f8814752f306cb9a26d283f0b7cf876639e10f7Eric Anholt	    gen6_CONT(p);
91011dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	 else
911f1d89638c02afafbf82ef657cd6ba9965dad6738Eric Anholt	    brw_CONT(p);
91211dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	 brw_set_predicate_control(p, BRW_PREDICATE_NONE);
91311dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	 break;
91411dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt
915ce6be334bbf7f44c71ad5d190f9fb075d2f9a38cEric Anholt      case BRW_OPCODE_WHILE:
916ce6be334bbf7f44c71ad5d190f9fb075d2f9a38cEric Anholt	 brw_WHILE(p);
91711dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	 break;
91811dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt
91965b5cbbcf783f6c668ab5b31a0734680dd396794Eric Anholt      case SHADER_OPCODE_RCP:
92065b5cbbcf783f6c668ab5b31a0734680dd396794Eric Anholt      case SHADER_OPCODE_RSQ:
92165b5cbbcf783f6c668ab5b31a0734680dd396794Eric Anholt      case SHADER_OPCODE_SQRT:
92265b5cbbcf783f6c668ab5b31a0734680dd396794Eric Anholt      case SHADER_OPCODE_EXP2:
92365b5cbbcf783f6c668ab5b31a0734680dd396794Eric Anholt      case SHADER_OPCODE_LOG2:
92465b5cbbcf783f6c668ab5b31a0734680dd396794Eric Anholt      case SHADER_OPCODE_SIN:
92565b5cbbcf783f6c668ab5b31a0734680dd396794Eric Anholt      case SHADER_OPCODE_COS:
926a73c65c5342bf41fa0dfefe7daa9197ce6a11db4Kenneth Graunke	 if (intel->gen >= 7) {
927a73c65c5342bf41fa0dfefe7daa9197ce6a11db4Kenneth Graunke	    generate_math1_gen7(inst, dst, src[0]);
928a73c65c5342bf41fa0dfefe7daa9197ce6a11db4Kenneth Graunke	 } else if (intel->gen == 6) {
92974e927bcafad0a994be5f88fbda4058bef08bc51Kenneth Graunke	    generate_math1_gen6(inst, dst, src[0]);
93074e927bcafad0a994be5f88fbda4058bef08bc51Kenneth Graunke	 } else {
93174e927bcafad0a994be5f88fbda4058bef08bc51Kenneth Graunke	    generate_math_gen4(inst, dst, src[0]);
93274e927bcafad0a994be5f88fbda4058bef08bc51Kenneth Graunke	 }
93374e927bcafad0a994be5f88fbda4058bef08bc51Kenneth Graunke	 break;
934ff8f272b0d02b41a0ce34ab6af7119b9e06f4961Kenneth Graunke      case SHADER_OPCODE_INT_QUOTIENT:
935ff8f272b0d02b41a0ce34ab6af7119b9e06f4961Kenneth Graunke      case SHADER_OPCODE_INT_REMAINDER:
93674e927bcafad0a994be5f88fbda4058bef08bc51Kenneth Graunke      case SHADER_OPCODE_POW:
937dceb202297b39220fbbcb41267077fb3ff8d137aKenneth Graunke	 if (intel->gen >= 7) {
938a73c65c5342bf41fa0dfefe7daa9197ce6a11db4Kenneth Graunke	    generate_math2_gen7(inst, dst, src[0], src[1]);
939a73c65c5342bf41fa0dfefe7daa9197ce6a11db4Kenneth Graunke	 } else if (intel->gen == 6) {
94074e927bcafad0a994be5f88fbda4058bef08bc51Kenneth Graunke	    generate_math2_gen6(inst, dst, src[0], src[1]);
94174e927bcafad0a994be5f88fbda4058bef08bc51Kenneth Graunke	 } else {
94274e927bcafad0a994be5f88fbda4058bef08bc51Kenneth Graunke	    generate_math_gen4(inst, dst, src[0]);
94374e927bcafad0a994be5f88fbda4058bef08bc51Kenneth Graunke	 }
94411dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	 break;
94511dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt      case FS_OPCODE_PIXEL_X:
94611dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	 generate_pixel_xy(dst, true);
94711dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	 break;
94811dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt      case FS_OPCODE_PIXEL_Y:
94911dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	 generate_pixel_xy(dst, false);
95011dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	 break;
95111dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt      case FS_OPCODE_CINTERP:
95211dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	 brw_MOV(p, dst, src[0]);
95311dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	 break;
95411dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt      case FS_OPCODE_LINTERP:
95511dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	 generate_linterp(inst, dst, src);
95611dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	 break;
957febad1779ae5cb5c85d66c2635baea62da52d2faKenneth Graunke      case SHADER_OPCODE_TEX:
95811dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt      case FS_OPCODE_TXB:
959febad1779ae5cb5c85d66c2635baea62da52d2faKenneth Graunke      case SHADER_OPCODE_TXD:
960febad1779ae5cb5c85d66c2635baea62da52d2faKenneth Graunke      case SHADER_OPCODE_TXF:
961febad1779ae5cb5c85d66c2635baea62da52d2faKenneth Graunke      case SHADER_OPCODE_TXL:
962febad1779ae5cb5c85d66c2635baea62da52d2faKenneth Graunke      case SHADER_OPCODE_TXS:
96311dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	 generate_tex(inst, dst, src[0]);
96411dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	 break;
96511dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt      case FS_OPCODE_DISCARD:
96611dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	 generate_discard(inst);
96711dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	 break;
96811dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt      case FS_OPCODE_DDX:
96911dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	 generate_ddx(inst, dst, src[0]);
97011dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	 break;
97111dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt      case FS_OPCODE_DDY:
972d08fdacd58dfa6b1926e9df4707dd9e8dd5370c5Paul Berry         /* Make sure fp->UsesDFdy flag got set (otherwise there's no
973d08fdacd58dfa6b1926e9df4707dd9e8dd5370c5Paul Berry          * guarantee that c->key.render_to_fbo is set).
974d08fdacd58dfa6b1926e9df4707dd9e8dd5370c5Paul Berry          */
975d08fdacd58dfa6b1926e9df4707dd9e8dd5370c5Paul Berry         assert(fp->UsesDFdy);
97682d25963a838cfebdeb9b080169979329ee850eaPaul Berry	 generate_ddy(inst, dst, src[0], c->key.render_to_fbo);
97711dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	 break;
97811dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt
97911dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt      case FS_OPCODE_SPILL:
98011dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	 generate_spill(inst, src[0]);
98111dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	 break;
98211dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt
98311dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt      case FS_OPCODE_UNSPILL:
98411dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	 generate_unspill(inst, dst);
98511dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	 break;
98611dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt
98711dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt      case FS_OPCODE_PULL_CONSTANT_LOAD:
988454dc83f66643e66ea7ee9117368211f0cfe84d7Eric Anholt	 generate_pull_constant_load(inst, dst, src[0], src[1]);
98911dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	 break;
99011dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt
99111dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt      case FS_OPCODE_FB_WRITE:
99211dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	 generate_fb_write(inst);
99311dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	 break;
9943f929efa2872aa5a4402520ec9fd551392e2413aPaul Berry
9953f929efa2872aa5a4402520ec9fd551392e2413aPaul Berry      case FS_OPCODE_MOV_DISPATCH_TO_FLAGS:
9963f929efa2872aa5a4402520ec9fd551392e2413aPaul Berry         generate_mov_dispatch_to_flags();
9973f929efa2872aa5a4402520ec9fd551392e2413aPaul Berry         break;
9983f929efa2872aa5a4402520ec9fd551392e2413aPaul Berry
99911dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt      default:
100011dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	 if (inst->opcode < (int)ARRAY_SIZE(brw_opcodes)) {
100111dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	    _mesa_problem(ctx, "Unsupported opcode `%s' in FS",
100211dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt			  brw_opcodes[inst->opcode].name);
100311dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	 } else {
100411dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	    _mesa_problem(ctx, "Unsupported opcode %d in FS", inst->opcode);
100511dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	 }
100611dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	 fail("unsupported opcode in FS\n");
100711dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt      }
100811dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt
100911dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt      if (unlikely(INTEL_DEBUG & DEBUG_WM)) {
101011dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	 for (unsigned int i = last_native_inst; i < p->nr_insn; i++) {
101111dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	    if (0) {
101211dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	       printf("0x%08x 0x%08x 0x%08x 0x%08x ",
101311dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt		      ((uint32_t *)&p->store[i])[3],
101411dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt		      ((uint32_t *)&p->store[i])[2],
101511dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt		      ((uint32_t *)&p->store[i])[1],
101611dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt		      ((uint32_t *)&p->store[i])[0]);
101711dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	    }
101811dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	    brw_disasm(stdout, &p->store[i], intel->gen);
101911dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	 }
1020080b125c64b48447a515b1a169f779e62b3de13dEric Anholt
1021080b125c64b48447a515b1a169f779e62b3de13dEric Anholt	 foreach_list(node, &cfg->block_list) {
1022080b125c64b48447a515b1a169f779e62b3de13dEric Anholt	    fs_bblock_link *link = (fs_bblock_link *)node;
1023080b125c64b48447a515b1a169f779e62b3de13dEric Anholt	    fs_bblock *block = link->block;
1024080b125c64b48447a515b1a169f779e62b3de13dEric Anholt
1025080b125c64b48447a515b1a169f779e62b3de13dEric Anholt	    if (block->end == inst) {
1026080b125c64b48447a515b1a169f779e62b3de13dEric Anholt	       printf("   END B%d", block->block_num);
1027080b125c64b48447a515b1a169f779e62b3de13dEric Anholt	       foreach_list(successor_node, &block->children) {
1028080b125c64b48447a515b1a169f779e62b3de13dEric Anholt		  fs_bblock_link *successor_link =
1029080b125c64b48447a515b1a169f779e62b3de13dEric Anholt		     (fs_bblock_link *)successor_node;
1030080b125c64b48447a515b1a169f779e62b3de13dEric Anholt		  fs_bblock *successor_block = successor_link->block;
1031080b125c64b48447a515b1a169f779e62b3de13dEric Anholt		  printf(" ->B%d", successor_block->block_num);
1032080b125c64b48447a515b1a169f779e62b3de13dEric Anholt	       }
1033080b125c64b48447a515b1a169f779e62b3de13dEric Anholt	       printf("\n");
1034080b125c64b48447a515b1a169f779e62b3de13dEric Anholt	    }
1035080b125c64b48447a515b1a169f779e62b3de13dEric Anholt	 }
103611dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt      }
103711dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt
103811dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt      last_native_inst = p->nr_insn;
103911dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt   }
104011dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt
104111dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt   if (unlikely(INTEL_DEBUG & DEBUG_WM)) {
104211dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt      printf("\n");
104311dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt   }
104411dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt
104511dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt   brw_set_uip_jip(p);
104611dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt
104711dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt   /* OK, while the INTEL_DEBUG=wm above is very nice for debugging FS
104811dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt    * emit issues, it doesn't get the jump distances into the output,
104911dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt    * which is often something we want to debug.  So this is here in
105011dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt    * case you're doing that.
105111dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt    */
105211dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt   if (0) {
105311dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt      if (unlikely(INTEL_DEBUG & DEBUG_WM)) {
105411dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	 for (unsigned int i = 0; i < p->nr_insn; i++) {
105511dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	    printf("0x%08x 0x%08x 0x%08x 0x%08x ",
105611dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt		   ((uint32_t *)&p->store[i])[3],
105711dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt		   ((uint32_t *)&p->store[i])[2],
105811dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt		   ((uint32_t *)&p->store[i])[1],
105911dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt		   ((uint32_t *)&p->store[i])[0]);
106011dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	    brw_disasm(stdout, &p->store[i], intel->gen);
106111dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt	 }
106211dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt      }
106311dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt   }
106411dd9e9c0fcf9985b90ff4b63b2833345fece027Eric Anholt}
1065