Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | RSS feed

  1. /*
  2.  * Copyright © 2008 Keith Packard
  3.  *
  4.  * Permission to use, copy, modify, distribute, and sell this software and its
  5.  * documentation for any purpose is hereby granted without fee, provided that
  6.  * the above copyright notice appear in all copies and that both that copyright
  7.  * notice and this permission notice appear in supporting documentation, and
  8.  * that the name of the copyright holders not be used in advertising or
  9.  * publicity pertaining to distribution of the software without specific,
  10.  * written prior permission.  The copyright holders make no representations
  11.  * about the suitability of this software for any purpose.  It is provided "as
  12.  * is" without express or implied warranty.
  13.  *
  14.  * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  15.  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  16.  * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  17.  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  18.  * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  19.  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
  20.  * OF THIS SOFTWARE.
  21.  */
  22.  
  23. #include <stdio.h>
  24. #include <stdlib.h>
  25. #include <string.h>
  26. #include <getopt.h>
  27. #include <unistd.h>
  28. #include <stdarg.h>
  29.  
  30. #include "main/mtypes.h"
  31.  
  32. #include "brw_context.h"
  33. #include "brw_defines.h"
  34.  
  35. const struct opcode_desc opcode_descs[128] = {
  36.     [BRW_OPCODE_MOV] = { .name = "mov", .nsrc = 1, .ndst = 1 },
  37.     [BRW_OPCODE_FRC] = { .name = "frc", .nsrc = 1, .ndst = 1 },
  38.     [BRW_OPCODE_RNDU] = { .name = "rndu", .nsrc = 1, .ndst = 1 },
  39.     [BRW_OPCODE_RNDD] = { .name = "rndd", .nsrc = 1, .ndst = 1 },
  40.     [BRW_OPCODE_RNDE] = { .name = "rnde", .nsrc = 1, .ndst = 1 },
  41.     [BRW_OPCODE_RNDZ] = { .name = "rndz", .nsrc = 1, .ndst = 1 },
  42.     [BRW_OPCODE_NOT] = { .name = "not", .nsrc = 1, .ndst = 1 },
  43.     [BRW_OPCODE_LZD] = { .name = "lzd", .nsrc = 1, .ndst = 1 },
  44.     [BRW_OPCODE_F32TO16] = { .name = "f32to16", .nsrc = 1, .ndst = 1 },
  45.     [BRW_OPCODE_F16TO32] = { .name = "f16to32", .nsrc = 1, .ndst = 1 },
  46.     [BRW_OPCODE_BFREV] = { .name = "bfrev", .nsrc = 1, .ndst = 1},
  47.     [BRW_OPCODE_FBH] = { .name = "fbh", .nsrc = 1, .ndst = 1},
  48.     [BRW_OPCODE_FBL] = { .name = "fbl", .nsrc = 1, .ndst = 1},
  49.     [BRW_OPCODE_CBIT] = { .name = "cbit", .nsrc = 1, .ndst = 1},
  50.  
  51.     [BRW_OPCODE_MUL] = { .name = "mul", .nsrc = 2, .ndst = 1 },
  52.     [BRW_OPCODE_MAC] = { .name = "mac", .nsrc = 2, .ndst = 1 },
  53.     [BRW_OPCODE_MACH] = { .name = "mach", .nsrc = 2, .ndst = 1 },
  54.     [BRW_OPCODE_LINE] = { .name = "line", .nsrc = 2, .ndst = 1 },
  55.     [BRW_OPCODE_PLN] = { .name = "pln", .nsrc = 2, .ndst = 1 },
  56.     [BRW_OPCODE_MAD] = { .name = "mad", .nsrc = 3, .ndst = 1 },
  57.     [BRW_OPCODE_LRP] = { .name = "lrp", .nsrc = 3, .ndst = 1 },
  58.     [BRW_OPCODE_SAD2] = { .name = "sad2", .nsrc = 2, .ndst = 1 },
  59.     [BRW_OPCODE_SADA2] = { .name = "sada2", .nsrc = 2, .ndst = 1 },
  60.     [BRW_OPCODE_DP4] = { .name = "dp4", .nsrc = 2, .ndst = 1 },
  61.     [BRW_OPCODE_DPH] = { .name = "dph", .nsrc = 2, .ndst = 1 },
  62.     [BRW_OPCODE_DP3] = { .name = "dp3", .nsrc = 2, .ndst = 1 },
  63.     [BRW_OPCODE_DP2] = { .name = "dp2", .nsrc = 2, .ndst = 1 },
  64.     [BRW_OPCODE_MATH] = { .name = "math", .nsrc = 2, .ndst = 1 },
  65.  
  66.     [BRW_OPCODE_AVG] = { .name = "avg", .nsrc = 2, .ndst = 1 },
  67.     [BRW_OPCODE_ADD] = { .name = "add", .nsrc = 2, .ndst = 1 },
  68.     [BRW_OPCODE_SEL] = { .name = "sel", .nsrc = 2, .ndst = 1 },
  69.     [BRW_OPCODE_AND] = { .name = "and", .nsrc = 2, .ndst = 1 },
  70.     [BRW_OPCODE_OR] = { .name = "or", .nsrc = 2, .ndst = 1 },
  71.     [BRW_OPCODE_XOR] = { .name = "xor", .nsrc = 2, .ndst = 1 },
  72.     [BRW_OPCODE_SHR] = { .name = "shr", .nsrc = 2, .ndst = 1 },
  73.     [BRW_OPCODE_SHL] = { .name = "shl", .nsrc = 2, .ndst = 1 },
  74.     [BRW_OPCODE_ASR] = { .name = "asr", .nsrc = 2, .ndst = 1 },
  75.     [BRW_OPCODE_CMP] = { .name = "cmp", .nsrc = 2, .ndst = 1 },
  76.     [BRW_OPCODE_CMPN] = { .name = "cmpn", .nsrc = 2, .ndst = 1 },
  77.     [BRW_OPCODE_BFE] = { .name = "bfe", .nsrc = 3, .ndst = 1},
  78.     [BRW_OPCODE_BFI1] = { .name = "bfe1", .nsrc = 2, .ndst = 1},
  79.     [BRW_OPCODE_BFI2] = { .name = "bfe2", .nsrc = 3, .ndst = 1},
  80.  
  81.     [BRW_OPCODE_SEND] = { .name = "send", .nsrc = 1, .ndst = 1 },
  82.     [BRW_OPCODE_SENDC] = { .name = "sendc", .nsrc = 1, .ndst = 1 },
  83.     [BRW_OPCODE_NOP] = { .name = "nop", .nsrc = 0, .ndst = 0 },
  84.     [BRW_OPCODE_JMPI] = { .name = "jmpi", .nsrc = 0, .ndst = 0 },
  85.     [BRW_OPCODE_IF] = { .name = "if", .nsrc = 2, .ndst = 0 },
  86.     [BRW_OPCODE_IFF] = { .name = "iff", .nsrc = 2, .ndst = 1 },
  87.     [BRW_OPCODE_WHILE] = { .name = "while", .nsrc = 2, .ndst = 0 },
  88.     [BRW_OPCODE_ELSE] = { .name = "else", .nsrc = 2, .ndst = 0 },
  89.     [BRW_OPCODE_BREAK] = { .name = "break", .nsrc = 2, .ndst = 0 },
  90.     [BRW_OPCODE_CONTINUE] = { .name = "cont", .nsrc = 1, .ndst = 0 },
  91.     [BRW_OPCODE_HALT] = { .name = "halt", .nsrc = 1, .ndst = 0 },
  92.     [BRW_OPCODE_MSAVE] = { .name = "msave", .nsrc = 1, .ndst = 1 },
  93.     [BRW_OPCODE_PUSH] = { .name = "push", .nsrc = 1, .ndst = 1 },
  94.     [BRW_OPCODE_MRESTORE] = { .name = "mrest", .nsrc = 1, .ndst = 1 },
  95.     [BRW_OPCODE_POP] = { .name = "pop", .nsrc = 2, .ndst = 0 },
  96.     [BRW_OPCODE_WAIT] = { .name = "wait", .nsrc = 1, .ndst = 0 },
  97.     [BRW_OPCODE_DO] = { .name = "do", .nsrc = 0, .ndst = 0 },
  98.     [BRW_OPCODE_ENDIF] = { .name = "endif", .nsrc = 2, .ndst = 0 },
  99. };
  100. static const struct opcode_desc *opcode = opcode_descs;
  101.  
  102. static const char * const conditional_modifier[16] = {
  103.     [BRW_CONDITIONAL_NONE] = "",
  104.     [BRW_CONDITIONAL_Z] = ".e",
  105.     [BRW_CONDITIONAL_NZ] = ".ne",
  106.     [BRW_CONDITIONAL_G] = ".g",
  107.     [BRW_CONDITIONAL_GE] = ".ge",
  108.     [BRW_CONDITIONAL_L] = ".l",
  109.     [BRW_CONDITIONAL_LE] = ".le",
  110.     [BRW_CONDITIONAL_R] = ".r",
  111.     [BRW_CONDITIONAL_O] = ".o",
  112.     [BRW_CONDITIONAL_U] = ".u",
  113. };
  114.  
  115. static const char * const negate[2] = {
  116.     [0] = "",
  117.     [1] = "-",
  118. };
  119.  
  120. static const char * const _abs[2] = {
  121.     [0] = "",
  122.     [1] = "(abs)",
  123. };
  124.  
  125. static const char * const vert_stride[16] = {
  126.     [0] = "0",
  127.     [1] = "1",
  128.     [2] = "2",
  129.     [3] = "4",
  130.     [4] = "8",
  131.     [5] = "16",
  132.     [6] = "32",
  133.     [15] = "VxH",
  134. };
  135.  
  136. static const char * const width[8] = {
  137.     [0] = "1",
  138.     [1] = "2",
  139.     [2] = "4",
  140.     [3] = "8",
  141.     [4] = "16",
  142. };
  143.  
  144. static const char * const horiz_stride[4] = {
  145.     [0] = "0",
  146.     [1] = "1",
  147.     [2] = "2",
  148.     [3] = "4"
  149. };
  150.  
  151. static const char * const chan_sel[4] = {
  152.     [0] = "x",
  153.     [1] = "y",
  154.     [2] = "z",
  155.     [3] = "w",
  156. };
  157.  
  158. static const char * const debug_ctrl[2] = {
  159.     [0] = "",
  160.     [1] = ".breakpoint"
  161. };
  162.  
  163. static const char * const saturate[2] = {
  164.     [0] = "",
  165.     [1] = ".sat"
  166. };
  167.  
  168. static const char * const accwr[2] = {
  169.     [0] = "",
  170.     [1] = "AccWrEnable"
  171. };
  172.  
  173. static const char * const wectrl[2] = {
  174.     [0] = "WE_normal",
  175.     [1] = "WE_all"
  176. };
  177.  
  178. static const char * const exec_size[8] = {
  179.     [0] = "1",
  180.     [1] = "2",
  181.     [2] = "4",
  182.     [3] = "8",
  183.     [4] = "16",
  184.     [5] = "32"
  185. };
  186.  
  187. static const char * const pred_inv[2] = {
  188.     [0] = "+",
  189.     [1] = "-"
  190. };
  191.  
  192. static const char * const pred_ctrl_align16[16] = {
  193.     [1] = "",
  194.     [2] = ".x",
  195.     [3] = ".y",
  196.     [4] = ".z",
  197.     [5] = ".w",
  198.     [6] = ".any4h",
  199.     [7] = ".all4h",
  200. };
  201.  
  202. static const char * const pred_ctrl_align1[16] = {
  203.     [1] = "",
  204.     [2] = ".anyv",
  205.     [3] = ".allv",
  206.     [4] = ".any2h",
  207.     [5] = ".all2h",
  208.     [6] = ".any4h",
  209.     [7] = ".all4h",
  210.     [8] = ".any8h",
  211.     [9] = ".all8h",
  212.     [10] = ".any16h",
  213.     [11] = ".all16h",
  214. };
  215.  
  216. static const char * const thread_ctrl[4] = {
  217.     [0] = "",
  218.     [2] = "switch"
  219. };
  220.  
  221. static const char * const compr_ctrl[4] = {
  222.     [0] = "",
  223.     [1] = "sechalf",
  224.     [2] = "compr",
  225.     [3] = "compr4",
  226. };
  227.  
  228. static const char * const dep_ctrl[4] = {
  229.     [0] = "",
  230.     [1] = "NoDDClr",
  231.     [2] = "NoDDChk",
  232.     [3] = "NoDDClr,NoDDChk",
  233. };
  234.  
  235. static const char * const mask_ctrl[4] = {
  236.     [0] = "",
  237.     [1] = "nomask",
  238. };
  239.  
  240. static const char * const access_mode[2] = {
  241.     [0] = "align1",
  242.     [1] = "align16",
  243. };
  244.  
  245. static const char * const reg_encoding[8] = {
  246.     [0] = "UD",
  247.     [1] = "D",
  248.     [2] = "UW",
  249.     [3] = "W",
  250.     [4] = "UB",
  251.     [5] = "B",
  252.     [7] = "F"
  253. };
  254.  
  255. const int reg_type_size[8] = {
  256.     [0] = 4,
  257.     [1] = 4,
  258.     [2] = 2,
  259.     [3] = 2,
  260.     [4] = 1,
  261.     [5] = 1,
  262.     [7] = 4
  263. };
  264.  
  265. static const char * const reg_file[4] = {
  266.     [0] = "A",
  267.     [1] = "g",
  268.     [2] = "m",
  269.     [3] = "imm",
  270. };
  271.  
  272. static const char * const writemask[16] = {
  273.     [0x0] = ".",
  274.     [0x1] = ".x",
  275.     [0x2] = ".y",
  276.     [0x3] = ".xy",
  277.     [0x4] = ".z",
  278.     [0x5] = ".xz",
  279.     [0x6] = ".yz",
  280.     [0x7] = ".xyz",
  281.     [0x8] = ".w",
  282.     [0x9] = ".xw",
  283.     [0xa] = ".yw",
  284.     [0xb] = ".xyw",
  285.     [0xc] = ".zw",
  286.     [0xd] = ".xzw",
  287.     [0xe] = ".yzw",
  288.     [0xf] = "",
  289. };
  290.  
  291. static const char * const end_of_thread[2] = {
  292.     [0] = "",
  293.     [1] = "EOT"
  294. };
  295.  
  296. static const char * const target_function[16] = {
  297.     [BRW_SFID_NULL] = "null",
  298.     [BRW_SFID_MATH] = "math",
  299.     [BRW_SFID_SAMPLER] = "sampler",
  300.     [BRW_SFID_MESSAGE_GATEWAY] = "gateway",
  301.     [BRW_SFID_DATAPORT_READ] = "read",
  302.     [BRW_SFID_DATAPORT_WRITE] = "write",
  303.     [BRW_SFID_URB] = "urb",
  304.     [BRW_SFID_THREAD_SPAWNER] = "thread_spawner"
  305. };
  306.  
  307. static const char * const target_function_gen6[16] = {
  308.     [BRW_SFID_NULL] = "null",
  309.     [BRW_SFID_MATH] = "math",
  310.     [BRW_SFID_SAMPLER] = "sampler",
  311.     [BRW_SFID_MESSAGE_GATEWAY] = "gateway",
  312.     [BRW_SFID_URB] = "urb",
  313.     [BRW_SFID_THREAD_SPAWNER] = "thread_spawner",
  314.     [GEN6_SFID_DATAPORT_SAMPLER_CACHE] = "sampler",
  315.     [GEN6_SFID_DATAPORT_RENDER_CACHE] = "render",
  316.     [GEN6_SFID_DATAPORT_CONSTANT_CACHE] = "const",
  317.     [GEN7_SFID_DATAPORT_DATA_CACHE] = "data"
  318. };
  319.  
  320. static const char * const dp_rc_msg_type_gen6[16] = {
  321.     [BRW_DATAPORT_READ_MESSAGE_OWORD_BLOCK_READ] = "OWORD block read",
  322.     [GEN6_DATAPORT_READ_MESSAGE_RENDER_UNORM_READ] = "RT UNORM read",
  323.     [GEN6_DATAPORT_READ_MESSAGE_OWORD_DUAL_BLOCK_READ] = "OWORD dual block read",
  324.     [GEN6_DATAPORT_READ_MESSAGE_MEDIA_BLOCK_READ] = "media block read",
  325.     [GEN6_DATAPORT_READ_MESSAGE_OWORD_UNALIGN_BLOCK_READ] = "OWORD unaligned block read",
  326.     [GEN6_DATAPORT_READ_MESSAGE_DWORD_SCATTERED_READ] = "DWORD scattered read",
  327.     [GEN6_DATAPORT_WRITE_MESSAGE_DWORD_ATOMIC_WRITE] = "DWORD atomic write",
  328.     [GEN6_DATAPORT_WRITE_MESSAGE_OWORD_BLOCK_WRITE] = "OWORD block write",
  329.     [GEN6_DATAPORT_WRITE_MESSAGE_OWORD_DUAL_BLOCK_WRITE] = "OWORD dual block write",
  330.     [GEN6_DATAPORT_WRITE_MESSAGE_MEDIA_BLOCK_WRITE] = "media block write",
  331.     [GEN6_DATAPORT_WRITE_MESSAGE_DWORD_SCATTERED_WRITE] = "DWORD scattered write",
  332.     [GEN6_DATAPORT_WRITE_MESSAGE_RENDER_TARGET_WRITE] = "RT write",
  333.     [GEN6_DATAPORT_WRITE_MESSAGE_STREAMED_VB_WRITE] = "streamed VB write",
  334.     [GEN6_DATAPORT_WRITE_MESSAGE_RENDER_TARGET_UNORM_WRITE] = "RT UNORMc write",
  335. };
  336.  
  337. static const char * const math_function[16] = {
  338.     [BRW_MATH_FUNCTION_INV] = "inv",
  339.     [BRW_MATH_FUNCTION_LOG] = "log",
  340.     [BRW_MATH_FUNCTION_EXP] = "exp",
  341.     [BRW_MATH_FUNCTION_SQRT] = "sqrt",
  342.     [BRW_MATH_FUNCTION_RSQ] = "rsq",
  343.     [BRW_MATH_FUNCTION_SIN] = "sin",
  344.     [BRW_MATH_FUNCTION_COS] = "cos",
  345.     [BRW_MATH_FUNCTION_SINCOS] = "sincos",
  346.     [BRW_MATH_FUNCTION_FDIV] = "fdiv",
  347.     [BRW_MATH_FUNCTION_POW] = "pow",
  348.     [BRW_MATH_FUNCTION_INT_DIV_QUOTIENT_AND_REMAINDER] = "intdivmod",
  349.     [BRW_MATH_FUNCTION_INT_DIV_QUOTIENT] = "intdiv",
  350.     [BRW_MATH_FUNCTION_INT_DIV_REMAINDER] = "intmod",
  351. };
  352.  
  353. static const char * const math_saturate[2] = {
  354.     [0] = "",
  355.     [1] = "sat"
  356. };
  357.  
  358. static const char * const math_signed[2] = {
  359.     [0] = "",
  360.     [1] = "signed"
  361. };
  362.  
  363. static const char * const math_scalar[2] = {
  364.     [0] = "",
  365.     [1] = "scalar"
  366. };
  367.  
  368. static const char * const math_precision[2] = {
  369.     [0] = "",
  370.     [1] = "partial_precision"
  371. };
  372.  
  373. static const char * const urb_opcode[2] = {
  374.     [0] = "urb_write",
  375.     [1] = "ff_sync",
  376. };
  377.  
  378. static const char * const urb_swizzle[4] = {
  379.     [BRW_URB_SWIZZLE_NONE] = "",
  380.     [BRW_URB_SWIZZLE_INTERLEAVE] = "interleave",
  381.     [BRW_URB_SWIZZLE_TRANSPOSE] = "transpose",
  382. };
  383.  
  384. static const char * const urb_allocate[2] = {
  385.     [0] = "",
  386.     [1] = "allocate"
  387. };
  388.  
  389. static const char * const urb_used[2] = {
  390.     [0] = "",
  391.     [1] = "used"
  392. };
  393.  
  394. static const char * const urb_complete[2] = {
  395.     [0] = "",
  396.     [1] = "complete"
  397. };
  398.  
  399. static const char * const sampler_target_format[4] = {
  400.     [0] = "F",
  401.     [2] = "UD",
  402.     [3] = "D"
  403. };
  404.  
  405.  
  406. static int column;
  407.  
  408. static int string (FILE *file, const char *string)
  409. {
  410.     fputs (string, file);
  411.     column += strlen (string);
  412.     return 0;
  413. }
  414.  
  415. static int format (FILE *f, const char *format, ...)
  416. {
  417.     char    buf[1024];
  418.     va_list     args;
  419.     va_start (args, format);
  420.  
  421.     vsnprintf (buf, sizeof (buf) - 1, format, args);
  422.     va_end (args);
  423.     string (f, buf);
  424.     return 0;
  425. }
  426.  
  427. static int newline (FILE *f)
  428. {
  429.     putc ('\n', f);
  430.     column = 0;
  431.     return 0;
  432. }
  433.  
  434. static int pad (FILE *f, int c)
  435. {
  436.     do
  437.         string (f, " ");
  438.     while (column < c);
  439.     return 0;
  440. }
  441.  
  442. static int control (FILE *file, const char *name, const char * const ctrl[],
  443.                     GLuint id, int *space)
  444. {
  445.     if (!ctrl[id]) {
  446.         fprintf (file, "*** invalid %s value %d ",
  447.                  name, id);
  448.         return 1;
  449.     }
  450.     if (ctrl[id][0])
  451.     {
  452.         if (space && *space)
  453.             string (file, " ");
  454.         string (file, ctrl[id]);
  455.         if (space)
  456.             *space = 1;
  457.     }
  458.     return 0;
  459. }
  460.  
  461. static int print_opcode (FILE *file, int id)
  462. {
  463.     if (!opcode[id].name) {
  464.         format (file, "*** invalid opcode value %d ", id);
  465.         return 1;
  466.     }
  467.     string (file, opcode[id].name);
  468.     return 0;
  469. }
  470.  
  471. static int three_source_type_to_reg_type(int three_source_type)
  472. {
  473.    switch (three_source_type) {
  474.    case BRW_3SRC_TYPE_F:
  475.       return BRW_REGISTER_TYPE_F;
  476.    case BRW_3SRC_TYPE_D:
  477.       return BRW_REGISTER_TYPE_D;
  478.    case BRW_3SRC_TYPE_UD:
  479.       return BRW_REGISTER_TYPE_UD;
  480.    }
  481.    return -1;
  482. }
  483.  
  484. static int reg (FILE *file, GLuint _reg_file, GLuint _reg_nr)
  485. {
  486.     int err = 0;
  487.  
  488.     /* Clear the Compr4 instruction compression bit. */
  489.     if (_reg_file == BRW_MESSAGE_REGISTER_FILE)
  490.        _reg_nr &= ~(1 << 7);
  491.  
  492.     if (_reg_file == BRW_ARCHITECTURE_REGISTER_FILE) {
  493.         switch (_reg_nr & 0xf0) {
  494.         case BRW_ARF_NULL:
  495.             string (file, "null");
  496.             return -1;
  497.         case BRW_ARF_ADDRESS:
  498.             format (file, "a%d", _reg_nr & 0x0f);
  499.             break;
  500.         case BRW_ARF_ACCUMULATOR:
  501.             format (file, "acc%d", _reg_nr & 0x0f);
  502.             break;
  503.         case BRW_ARF_FLAG:
  504.             format (file, "f%d", _reg_nr & 0x0f);
  505.             break;
  506.         case BRW_ARF_MASK:
  507.             format (file, "mask%d", _reg_nr & 0x0f);
  508.             break;
  509.         case BRW_ARF_MASK_STACK:
  510.             format (file, "msd%d", _reg_nr & 0x0f);
  511.             break;
  512.         case BRW_ARF_STATE:
  513.             format (file, "sr%d", _reg_nr & 0x0f);
  514.             break;
  515.         case BRW_ARF_CONTROL:
  516.             format (file, "cr%d", _reg_nr & 0x0f);
  517.             break;
  518.         case BRW_ARF_NOTIFICATION_COUNT:
  519.             format (file, "n%d", _reg_nr & 0x0f);
  520.             break;
  521.         case BRW_ARF_IP:
  522.             string (file, "ip");
  523.             return -1;
  524.             break;
  525.         default:
  526.             format (file, "ARF%d", _reg_nr);
  527.             break;
  528.         }
  529.     } else {
  530.         err  |= control (file, "src reg file", reg_file, _reg_file, NULL);
  531.         format (file, "%d", _reg_nr);
  532.     }
  533.     return err;
  534. }
  535.  
  536. static int dest (FILE *file, struct brw_instruction *inst)
  537. {
  538.     int err = 0;
  539.  
  540.     if (inst->header.access_mode == BRW_ALIGN_1)
  541.     {
  542.         if (inst->bits1.da1.dest_address_mode == BRW_ADDRESS_DIRECT)
  543.         {
  544.             err |= reg (file, inst->bits1.da1.dest_reg_file, inst->bits1.da1.dest_reg_nr);
  545.             if (err == -1)
  546.                 return 0;
  547.             if (inst->bits1.da1.dest_subreg_nr)
  548.                 format (file, ".%d", inst->bits1.da1.dest_subreg_nr /
  549.                                      reg_type_size[inst->bits1.da1.dest_reg_type]);
  550.             string (file, "<");
  551.             err |= control (file, "horiz stride", horiz_stride, inst->bits1.da1.dest_horiz_stride, NULL);
  552.             string (file, ">");
  553.             err |= control (file, "dest reg encoding", reg_encoding, inst->bits1.da1.dest_reg_type, NULL);
  554.         }
  555.         else
  556.         {
  557.             string (file, "g[a0");
  558.             if (inst->bits1.ia1.dest_subreg_nr)
  559.                 format (file, ".%d", inst->bits1.ia1.dest_subreg_nr /
  560.                                         reg_type_size[inst->bits1.ia1.dest_reg_type]);
  561.             if (inst->bits1.ia1.dest_indirect_offset)
  562.                 format (file, " %d", inst->bits1.ia1.dest_indirect_offset);
  563.             string (file, "]<");
  564.             err |= control (file, "horiz stride", horiz_stride, inst->bits1.ia1.dest_horiz_stride, NULL);
  565.             string (file, ">");
  566.             err |= control (file, "dest reg encoding", reg_encoding, inst->bits1.ia1.dest_reg_type, NULL);
  567.         }
  568.     }
  569.     else
  570.     {
  571.         if (inst->bits1.da16.dest_address_mode == BRW_ADDRESS_DIRECT)
  572.         {
  573.             err |= reg (file, inst->bits1.da16.dest_reg_file, inst->bits1.da16.dest_reg_nr);
  574.             if (err == -1)
  575.                 return 0;
  576.             if (inst->bits1.da16.dest_subreg_nr)
  577.                 format (file, ".%d", inst->bits1.da16.dest_subreg_nr /
  578.                                      reg_type_size[inst->bits1.da16.dest_reg_type]);
  579.             string (file, "<1>");
  580.             err |= control (file, "writemask", writemask, inst->bits1.da16.dest_writemask, NULL);
  581.             err |= control (file, "dest reg encoding", reg_encoding, inst->bits1.da16.dest_reg_type, NULL);
  582.         }
  583.         else
  584.         {
  585.             err = 1;
  586.             string (file, "Indirect align16 address mode not supported");
  587.         }
  588.     }
  589.  
  590.     return 0;
  591. }
  592.  
  593. static int dest_3src (FILE *file, struct brw_instruction *inst)
  594. {
  595.     int err = 0;
  596.     uint32_t reg_file;
  597.  
  598.     if (inst->bits1.da3src.dest_reg_file)
  599.        reg_file = BRW_MESSAGE_REGISTER_FILE;
  600.     else
  601.        reg_file = BRW_GENERAL_REGISTER_FILE;
  602.  
  603.     err |= reg (file, reg_file, inst->bits1.da3src.dest_reg_nr);
  604.     if (err == -1)
  605.        return 0;
  606.     if (inst->bits1.da3src.dest_subreg_nr)
  607.        format (file, ".%d", inst->bits1.da3src.dest_subreg_nr);
  608.     string (file, "<1>");
  609.     err |= control (file, "writemask", writemask, inst->bits1.da3src.dest_writemask, NULL);
  610.     err |= control (file, "dest reg encoding", reg_encoding,
  611.                     three_source_type_to_reg_type(inst->bits1.da3src.dst_type),
  612.                     NULL);
  613.  
  614.     return 0;
  615. }
  616.  
  617. static int src_align1_region (FILE *file,
  618.                               GLuint _vert_stride, GLuint _width, GLuint _horiz_stride)
  619. {
  620.     int err = 0;
  621.     string (file, "<");
  622.     err |= control (file, "vert stride", vert_stride, _vert_stride, NULL);
  623.     string (file, ",");
  624.     err |= control (file, "width", width, _width, NULL);
  625.     string (file, ",");
  626.     err |= control (file, "horiz_stride", horiz_stride, _horiz_stride, NULL);
  627.     string (file, ">");
  628.     return err;
  629. }
  630.  
  631. static int src_da1 (FILE *file, GLuint type, GLuint _reg_file,
  632.                     GLuint _vert_stride, GLuint _width, GLuint _horiz_stride,
  633.                     GLuint reg_num, GLuint sub_reg_num, GLuint __abs, GLuint _negate)
  634. {
  635.     int err = 0;
  636.     err |= control (file, "negate", negate, _negate, NULL);
  637.     err |= control (file, "abs", _abs, __abs, NULL);
  638.  
  639.     err |= reg (file, _reg_file, reg_num);
  640.     if (err == -1)
  641.         return 0;
  642.     if (sub_reg_num)
  643.         format (file, ".%d", sub_reg_num / reg_type_size[type]); /* use formal style like spec */
  644.     src_align1_region (file, _vert_stride, _width, _horiz_stride);
  645.     err |= control (file, "src reg encoding", reg_encoding, type, NULL);
  646.     return err;
  647. }
  648.  
  649. static int src_ia1 (FILE *file,
  650.                     GLuint type,
  651.                     GLuint _reg_file,
  652.                     GLint _addr_imm,
  653.                     GLuint _addr_subreg_nr,
  654.                     GLuint _negate,
  655.                     GLuint __abs,
  656.                     GLuint _addr_mode,
  657.                     GLuint _horiz_stride,
  658.                     GLuint _width,
  659.                     GLuint _vert_stride)
  660. {
  661.     int err = 0;
  662.     err |= control (file, "negate", negate, _negate, NULL);
  663.     err |= control (file, "abs", _abs, __abs, NULL);
  664.  
  665.     string (file, "g[a0");
  666.     if (_addr_subreg_nr)
  667.         format (file, ".%d", _addr_subreg_nr);
  668.     if (_addr_imm)
  669.         format (file, " %d", _addr_imm);
  670.     string (file, "]");
  671.     src_align1_region (file, _vert_stride, _width, _horiz_stride);
  672.     err |= control (file, "src reg encoding", reg_encoding, type, NULL);
  673.     return err;
  674. }
  675.  
  676. static int src_da16 (FILE *file,
  677.                      GLuint _reg_type,
  678.                      GLuint _reg_file,
  679.                      GLuint _vert_stride,
  680.                      GLuint _reg_nr,
  681.                      GLuint _subreg_nr,
  682.                      GLuint __abs,
  683.                      GLuint _negate,
  684.                      GLuint swz_x,
  685.                      GLuint swz_y,
  686.                      GLuint swz_z,
  687.                      GLuint swz_w)
  688. {
  689.     int err = 0;
  690.     err |= control (file, "negate", negate, _negate, NULL);
  691.     err |= control (file, "abs", _abs, __abs, NULL);
  692.  
  693.     err |= reg (file, _reg_file, _reg_nr);
  694.     if (err == -1)
  695.         return 0;
  696.     if (_subreg_nr)
  697.         /* bit4 for subreg number byte addressing. Make this same meaning as
  698.            in da1 case, so output looks consistent. */
  699.         format (file, ".%d", 16 / reg_type_size[_reg_type]);
  700.     string (file, "<");
  701.     err |= control (file, "vert stride", vert_stride, _vert_stride, NULL);
  702.     string (file, ",4,1>");
  703.     /*
  704.      * Three kinds of swizzle display:
  705.      *  identity - nothing printed
  706.      *  1->all   - print the single channel
  707.      *  1->1     - print the mapping
  708.      */
  709.     if (swz_x == BRW_CHANNEL_X &&
  710.         swz_y == BRW_CHANNEL_Y &&
  711.         swz_z == BRW_CHANNEL_Z &&
  712.         swz_w == BRW_CHANNEL_W)
  713.     {
  714.         ;
  715.     }
  716.     else if (swz_x == swz_y && swz_x == swz_z && swz_x == swz_w)
  717.     {
  718.         string (file, ".");
  719.         err |= control (file, "channel select", chan_sel, swz_x, NULL);
  720.     }
  721.     else
  722.     {
  723.         string (file, ".");
  724.         err |= control (file, "channel select", chan_sel, swz_x, NULL);
  725.         err |= control (file, "channel select", chan_sel, swz_y, NULL);
  726.         err |= control (file, "channel select", chan_sel, swz_z, NULL);
  727.         err |= control (file, "channel select", chan_sel, swz_w, NULL);
  728.     }
  729.     err |= control (file, "src da16 reg type", reg_encoding, _reg_type, NULL);
  730.     return err;
  731. }
  732.  
  733. static int src0_3src (FILE *file, struct brw_instruction *inst)
  734. {
  735.     int err = 0;
  736.     GLuint swz_x = (inst->bits2.da3src.src0_swizzle >> 0) & 0x3;
  737.     GLuint swz_y = (inst->bits2.da3src.src0_swizzle >> 2) & 0x3;
  738.     GLuint swz_z = (inst->bits2.da3src.src0_swizzle >> 4) & 0x3;
  739.     GLuint swz_w = (inst->bits2.da3src.src0_swizzle >> 6) & 0x3;
  740.  
  741.     err |= control (file, "negate", negate, inst->bits1.da3src.src0_negate, NULL);
  742.     err |= control (file, "abs", _abs, inst->bits1.da3src.src0_abs, NULL);
  743.  
  744.     err |= reg (file, BRW_GENERAL_REGISTER_FILE, inst->bits2.da3src.src0_reg_nr);
  745.     if (err == -1)
  746.         return 0;
  747.     if (inst->bits2.da3src.src0_subreg_nr)
  748.         format (file, ".%d", inst->bits2.da3src.src0_subreg_nr);
  749.     string (file, "<4,1,1>");
  750.     err |= control (file, "src da16 reg type", reg_encoding,
  751.                     three_source_type_to_reg_type(inst->bits1.da3src.src_type),
  752.                     NULL);
  753.     /*
  754.      * Three kinds of swizzle display:
  755.      *  identity - nothing printed
  756.      *  1->all   - print the single channel
  757.      *  1->1     - print the mapping
  758.      */
  759.     if (swz_x == BRW_CHANNEL_X &&
  760.         swz_y == BRW_CHANNEL_Y &&
  761.         swz_z == BRW_CHANNEL_Z &&
  762.         swz_w == BRW_CHANNEL_W)
  763.     {
  764.         ;
  765.     }
  766.     else if (swz_x == swz_y && swz_x == swz_z && swz_x == swz_w)
  767.     {
  768.         string (file, ".");
  769.         err |= control (file, "channel select", chan_sel, swz_x, NULL);
  770.     }
  771.     else
  772.     {
  773.         string (file, ".");
  774.         err |= control (file, "channel select", chan_sel, swz_x, NULL);
  775.         err |= control (file, "channel select", chan_sel, swz_y, NULL);
  776.         err |= control (file, "channel select", chan_sel, swz_z, NULL);
  777.         err |= control (file, "channel select", chan_sel, swz_w, NULL);
  778.     }
  779.     return err;
  780. }
  781.  
  782. static int src1_3src (FILE *file, struct brw_instruction *inst)
  783. {
  784.     int err = 0;
  785.     GLuint swz_x = (inst->bits2.da3src.src1_swizzle >> 0) & 0x3;
  786.     GLuint swz_y = (inst->bits2.da3src.src1_swizzle >> 2) & 0x3;
  787.     GLuint swz_z = (inst->bits2.da3src.src1_swizzle >> 4) & 0x3;
  788.     GLuint swz_w = (inst->bits2.da3src.src1_swizzle >> 6) & 0x3;
  789.     GLuint src1_subreg_nr = (inst->bits2.da3src.src1_subreg_nr_low |
  790.                              (inst->bits3.da3src.src1_subreg_nr_high << 2));
  791.  
  792.     err |= control (file, "negate", negate, inst->bits1.da3src.src1_negate,
  793.                     NULL);
  794.     err |= control (file, "abs", _abs, inst->bits1.da3src.src1_abs, NULL);
  795.  
  796.     err |= reg (file, BRW_GENERAL_REGISTER_FILE,
  797.                 inst->bits3.da3src.src1_reg_nr);
  798.     if (err == -1)
  799.         return 0;
  800.     if (src1_subreg_nr)
  801.         format (file, ".%d", src1_subreg_nr);
  802.     string (file, "<4,1,1>");
  803.     err |= control (file, "src da16 reg type", reg_encoding,
  804.                     three_source_type_to_reg_type(inst->bits1.da3src.src_type),
  805.                     NULL);
  806.     /*
  807.      * Three kinds of swizzle display:
  808.      *  identity - nothing printed
  809.      *  1->all   - print the single channel
  810.      *  1->1     - print the mapping
  811.      */
  812.     if (swz_x == BRW_CHANNEL_X &&
  813.         swz_y == BRW_CHANNEL_Y &&
  814.         swz_z == BRW_CHANNEL_Z &&
  815.         swz_w == BRW_CHANNEL_W)
  816.     {
  817.         ;
  818.     }
  819.     else if (swz_x == swz_y && swz_x == swz_z && swz_x == swz_w)
  820.     {
  821.         string (file, ".");
  822.         err |= control (file, "channel select", chan_sel, swz_x, NULL);
  823.     }
  824.     else
  825.     {
  826.         string (file, ".");
  827.         err |= control (file, "channel select", chan_sel, swz_x, NULL);
  828.         err |= control (file, "channel select", chan_sel, swz_y, NULL);
  829.         err |= control (file, "channel select", chan_sel, swz_z, NULL);
  830.         err |= control (file, "channel select", chan_sel, swz_w, NULL);
  831.     }
  832.     return err;
  833. }
  834.  
  835.  
  836. static int src2_3src (FILE *file, struct brw_instruction *inst)
  837. {
  838.     int err = 0;
  839.     GLuint swz_x = (inst->bits3.da3src.src2_swizzle >> 0) & 0x3;
  840.     GLuint swz_y = (inst->bits3.da3src.src2_swizzle >> 2) & 0x3;
  841.     GLuint swz_z = (inst->bits3.da3src.src2_swizzle >> 4) & 0x3;
  842.     GLuint swz_w = (inst->bits3.da3src.src2_swizzle >> 6) & 0x3;
  843.  
  844.     err |= control (file, "negate", negate, inst->bits1.da3src.src2_negate,
  845.                     NULL);
  846.     err |= control (file, "abs", _abs, inst->bits1.da3src.src2_abs, NULL);
  847.  
  848.     err |= reg (file, BRW_GENERAL_REGISTER_FILE,
  849.                 inst->bits3.da3src.src2_reg_nr);
  850.     if (err == -1)
  851.         return 0;
  852.     if (inst->bits3.da3src.src2_subreg_nr)
  853.         format (file, ".%d", inst->bits3.da3src.src2_subreg_nr);
  854.     string (file, "<4,1,1>");
  855.     err |= control (file, "src da16 reg type", reg_encoding,
  856.                     three_source_type_to_reg_type(inst->bits1.da3src.src_type),
  857.                     NULL);
  858.     /*
  859.      * Three kinds of swizzle display:
  860.      *  identity - nothing printed
  861.      *  1->all   - print the single channel
  862.      *  1->1     - print the mapping
  863.      */
  864.     if (swz_x == BRW_CHANNEL_X &&
  865.         swz_y == BRW_CHANNEL_Y &&
  866.         swz_z == BRW_CHANNEL_Z &&
  867.         swz_w == BRW_CHANNEL_W)
  868.     {
  869.         ;
  870.     }
  871.     else if (swz_x == swz_y && swz_x == swz_z && swz_x == swz_w)
  872.     {
  873.         string (file, ".");
  874.         err |= control (file, "channel select", chan_sel, swz_x, NULL);
  875.     }
  876.     else
  877.     {
  878.         string (file, ".");
  879.         err |= control (file, "channel select", chan_sel, swz_x, NULL);
  880.         err |= control (file, "channel select", chan_sel, swz_y, NULL);
  881.         err |= control (file, "channel select", chan_sel, swz_z, NULL);
  882.         err |= control (file, "channel select", chan_sel, swz_w, NULL);
  883.     }
  884.     return err;
  885. }
  886.  
  887. static int imm (FILE *file, GLuint type, struct brw_instruction *inst) {
  888.     switch (type) {
  889.     case BRW_REGISTER_TYPE_UD:
  890.         format (file, "0x%08xUD", inst->bits3.ud);
  891.         break;
  892.     case BRW_REGISTER_TYPE_D:
  893.         format (file, "%dD", inst->bits3.d);
  894.         break;
  895.     case BRW_REGISTER_TYPE_UW:
  896.         format (file, "0x%04xUW", (uint16_t) inst->bits3.ud);
  897.         break;
  898.     case BRW_REGISTER_TYPE_W:
  899.         format (file, "%dW", (int16_t) inst->bits3.d);
  900.         break;
  901.     case BRW_REGISTER_TYPE_UB:
  902.         format (file, "0x%02xUB", (int8_t) inst->bits3.ud);
  903.         break;
  904.     case BRW_REGISTER_TYPE_VF:
  905.         format (file, "Vector Float");
  906.         break;
  907.     case BRW_REGISTER_TYPE_V:
  908.         format (file, "0x%08xV", inst->bits3.ud);
  909.         break;
  910.     case BRW_REGISTER_TYPE_F:
  911.         format (file, "%-gF", inst->bits3.f);
  912.     }
  913.     return 0;
  914. }
  915.  
  916. static int src0 (FILE *file, struct brw_instruction *inst)
  917. {
  918.     if (inst->bits1.da1.src0_reg_file == BRW_IMMEDIATE_VALUE)
  919.         return imm (file, inst->bits1.da1.src0_reg_type,
  920.                     inst);
  921.     else if (inst->header.access_mode == BRW_ALIGN_1)
  922.     {
  923.         if (inst->bits2.da1.src0_address_mode == BRW_ADDRESS_DIRECT)
  924.         {
  925.             return src_da1 (file,
  926.                             inst->bits1.da1.src0_reg_type,
  927.                             inst->bits1.da1.src0_reg_file,
  928.                             inst->bits2.da1.src0_vert_stride,
  929.                             inst->bits2.da1.src0_width,
  930.                             inst->bits2.da1.src0_horiz_stride,
  931.                             inst->bits2.da1.src0_reg_nr,
  932.                             inst->bits2.da1.src0_subreg_nr,
  933.                             inst->bits2.da1.src0_abs,
  934.                             inst->bits2.da1.src0_negate);
  935.         }
  936.         else
  937.         {
  938.             return src_ia1 (file,
  939.                             inst->bits1.ia1.src0_reg_type,
  940.                             inst->bits1.ia1.src0_reg_file,
  941.                             inst->bits2.ia1.src0_indirect_offset,
  942.                             inst->bits2.ia1.src0_subreg_nr,
  943.                             inst->bits2.ia1.src0_negate,
  944.                             inst->bits2.ia1.src0_abs,
  945.                             inst->bits2.ia1.src0_address_mode,
  946.                             inst->bits2.ia1.src0_horiz_stride,
  947.                             inst->bits2.ia1.src0_width,
  948.                             inst->bits2.ia1.src0_vert_stride);
  949.         }
  950.     }
  951.     else
  952.     {
  953.         if (inst->bits2.da16.src0_address_mode == BRW_ADDRESS_DIRECT)
  954.         {
  955.             return src_da16 (file,
  956.                              inst->bits1.da16.src0_reg_type,
  957.                              inst->bits1.da16.src0_reg_file,
  958.                              inst->bits2.da16.src0_vert_stride,
  959.                              inst->bits2.da16.src0_reg_nr,
  960.                              inst->bits2.da16.src0_subreg_nr,
  961.                              inst->bits2.da16.src0_abs,
  962.                              inst->bits2.da16.src0_negate,
  963.                              inst->bits2.da16.src0_swz_x,
  964.                              inst->bits2.da16.src0_swz_y,
  965.                              inst->bits2.da16.src0_swz_z,
  966.                              inst->bits2.da16.src0_swz_w);
  967.         }
  968.         else
  969.         {
  970.             string (file, "Indirect align16 address mode not supported");
  971.             return 1;
  972.         }
  973.     }
  974. }
  975.  
  976. static int src1 (FILE *file, struct brw_instruction *inst)
  977. {
  978.     if (inst->bits1.da1.src1_reg_file == BRW_IMMEDIATE_VALUE)
  979.         return imm (file, inst->bits1.da1.src1_reg_type,
  980.                     inst);
  981.     else if (inst->header.access_mode == BRW_ALIGN_1)
  982.     {
  983.         if (inst->bits3.da1.src1_address_mode == BRW_ADDRESS_DIRECT)
  984.         {
  985.             return src_da1 (file,
  986.                             inst->bits1.da1.src1_reg_type,
  987.                             inst->bits1.da1.src1_reg_file,
  988.                             inst->bits3.da1.src1_vert_stride,
  989.                             inst->bits3.da1.src1_width,
  990.                             inst->bits3.da1.src1_horiz_stride,
  991.                             inst->bits3.da1.src1_reg_nr,
  992.                             inst->bits3.da1.src1_subreg_nr,
  993.                             inst->bits3.da1.src1_abs,
  994.                             inst->bits3.da1.src1_negate);
  995.         }
  996.         else
  997.         {
  998.             return src_ia1 (file,
  999.                             inst->bits1.ia1.src1_reg_type,
  1000.                             inst->bits1.ia1.src1_reg_file,
  1001.                             inst->bits3.ia1.src1_indirect_offset,
  1002.                             inst->bits3.ia1.src1_subreg_nr,
  1003.                             inst->bits3.ia1.src1_negate,
  1004.                             inst->bits3.ia1.src1_abs,
  1005.                             inst->bits3.ia1.src1_address_mode,
  1006.                             inst->bits3.ia1.src1_horiz_stride,
  1007.                             inst->bits3.ia1.src1_width,
  1008.                             inst->bits3.ia1.src1_vert_stride);
  1009.         }
  1010.     }
  1011.     else
  1012.     {
  1013.         if (inst->bits3.da16.src1_address_mode == BRW_ADDRESS_DIRECT)
  1014.         {
  1015.             return src_da16 (file,
  1016.                              inst->bits1.da16.src1_reg_type,
  1017.                              inst->bits1.da16.src1_reg_file,
  1018.                              inst->bits3.da16.src1_vert_stride,
  1019.                              inst->bits3.da16.src1_reg_nr,
  1020.                              inst->bits3.da16.src1_subreg_nr,
  1021.                              inst->bits3.da16.src1_abs,
  1022.                              inst->bits3.da16.src1_negate,
  1023.                              inst->bits3.da16.src1_swz_x,
  1024.                              inst->bits3.da16.src1_swz_y,
  1025.                              inst->bits3.da16.src1_swz_z,
  1026.                              inst->bits3.da16.src1_swz_w);
  1027.         }
  1028.         else
  1029.         {
  1030.             string (file, "Indirect align16 address mode not supported");
  1031.             return 1;
  1032.         }
  1033.     }
  1034. }
  1035.  
  1036. int esize[6] = {
  1037.         [0] = 1,
  1038.         [1] = 2,
  1039.         [2] = 4,
  1040.         [3] = 8,
  1041.         [4] = 16,
  1042.         [5] = 32,
  1043. };
  1044.  
  1045. static int qtr_ctrl(FILE *file, struct brw_instruction *inst)
  1046. {
  1047.     int qtr_ctl = inst->header.compression_control;
  1048.     int exec_size = esize[inst->header.execution_size];
  1049.  
  1050.     if (exec_size == 8) {
  1051.         switch (qtr_ctl) {
  1052.         case 0:
  1053.             string (file, " 1Q");
  1054.             break;
  1055.         case 1:
  1056.             string (file, " 2Q");
  1057.             break;
  1058.         case 2:
  1059.             string (file, " 3Q");
  1060.             break;
  1061.         case 3:
  1062.             string (file, " 4Q");
  1063.             break;
  1064.         }
  1065.     } else if (exec_size == 16){
  1066.         if (qtr_ctl < 2)
  1067.             string (file, " 1H");
  1068.         else
  1069.             string (file, " 2H");
  1070.     }
  1071.     return 0;
  1072. }
  1073.  
  1074. int brw_disasm (FILE *file, struct brw_instruction *inst, int gen)
  1075. {
  1076.     int err = 0;
  1077.     int space = 0;
  1078.  
  1079.     if (inst->header.predicate_control) {
  1080.         string (file, "(");
  1081.         err |= control (file, "predicate inverse", pred_inv, inst->header.predicate_inverse, NULL);
  1082.         format (file, "f%d", gen >= 7 ? inst->bits2.da1.flag_reg_nr : 0);
  1083.         if (inst->bits2.da1.flag_subreg_nr)
  1084.             format (file, ".%d", inst->bits2.da1.flag_subreg_nr);
  1085.         if (inst->header.access_mode == BRW_ALIGN_1)
  1086.             err |= control (file, "predicate control align1", pred_ctrl_align1,
  1087.                             inst->header.predicate_control, NULL);
  1088.         else
  1089.             err |= control (file, "predicate control align16", pred_ctrl_align16,
  1090.                             inst->header.predicate_control, NULL);
  1091.         string (file, ") ");
  1092.     }
  1093.  
  1094.     err |= print_opcode (file, inst->header.opcode);
  1095.     err |= control (file, "saturate", saturate, inst->header.saturate, NULL);
  1096.     err |= control (file, "debug control", debug_ctrl, inst->header.debug_control, NULL);
  1097.  
  1098.     if (inst->header.opcode == BRW_OPCODE_MATH) {
  1099.         string (file, " ");
  1100.         err |= control (file, "function", math_function,
  1101.                         inst->header.destreg__conditionalmod, NULL);
  1102.     } else if (inst->header.opcode != BRW_OPCODE_SEND &&
  1103.                inst->header.opcode != BRW_OPCODE_SENDC) {
  1104.         err |= control (file, "conditional modifier", conditional_modifier,
  1105.                         inst->header.destreg__conditionalmod, NULL);
  1106.  
  1107.         /* If we're using the conditional modifier, print which flags reg is
  1108.          * used for it.  Note that on gen6+, the embedded-condition SEL and
  1109.          * control flow doesn't update flags.
  1110.          */
  1111.         if (inst->header.destreg__conditionalmod &&
  1112.             (gen < 6 || (inst->header.opcode != BRW_OPCODE_SEL &&
  1113.                          inst->header.opcode != BRW_OPCODE_IF &&
  1114.                          inst->header.opcode != BRW_OPCODE_WHILE))) {
  1115.             format (file, ".f%d", gen >= 7 ? inst->bits2.da1.flag_reg_nr : 0);
  1116.             if (inst->bits2.da1.flag_subreg_nr)
  1117.                 format (file, ".%d", inst->bits2.da1.flag_subreg_nr);
  1118.         }
  1119.     }
  1120.  
  1121.     if (inst->header.opcode != BRW_OPCODE_NOP) {
  1122.         string (file, "(");
  1123.         err |= control (file, "execution size", exec_size, inst->header.execution_size, NULL);
  1124.         string (file, ")");
  1125.     }
  1126.  
  1127.     if (inst->header.opcode == BRW_OPCODE_SEND && gen < 6)
  1128.         format (file, " %d", inst->header.destreg__conditionalmod);
  1129.  
  1130.     if (opcode[inst->header.opcode].nsrc == 3) {
  1131.        pad (file, 16);
  1132.        err |= dest_3src (file, inst);
  1133.  
  1134.        pad (file, 32);
  1135.        err |= src0_3src (file, inst);
  1136.  
  1137.        pad (file, 48);
  1138.        err |= src1_3src (file, inst);
  1139.  
  1140.        pad (file, 64);
  1141.        err |= src2_3src (file, inst);
  1142.     } else {
  1143.        if (opcode[inst->header.opcode].ndst > 0) {
  1144.           pad (file, 16);
  1145.           err |= dest (file, inst);
  1146.        } else if (gen == 7 && (inst->header.opcode == BRW_OPCODE_ELSE ||
  1147.                                inst->header.opcode == BRW_OPCODE_ENDIF ||
  1148.                                inst->header.opcode == BRW_OPCODE_WHILE)) {
  1149.           format (file, " %d", inst->bits3.break_cont.jip);
  1150.        } else if (gen == 6 && (inst->header.opcode == BRW_OPCODE_IF ||
  1151.                                inst->header.opcode == BRW_OPCODE_ELSE ||
  1152.                                inst->header.opcode == BRW_OPCODE_ENDIF ||
  1153.                                inst->header.opcode == BRW_OPCODE_WHILE)) {
  1154.           format (file, " %d", inst->bits1.branch_gen6.jump_count);
  1155.        } else if ((gen >= 6 && (inst->header.opcode == BRW_OPCODE_BREAK ||
  1156.                                 inst->header.opcode == BRW_OPCODE_CONTINUE ||
  1157.                                 inst->header.opcode == BRW_OPCODE_HALT)) ||
  1158.                   (gen == 7 && inst->header.opcode == BRW_OPCODE_IF)) {
  1159.           format (file, " %d %d", inst->bits3.break_cont.uip, inst->bits3.break_cont.jip);
  1160.        } else if (inst->header.opcode == BRW_OPCODE_JMPI) {
  1161.           format (file, " %d", inst->bits3.d);
  1162.        }
  1163.  
  1164.        if (opcode[inst->header.opcode].nsrc > 0) {
  1165.           pad (file, 32);
  1166.           err |= src0 (file, inst);
  1167.        }
  1168.        if (opcode[inst->header.opcode].nsrc > 1) {
  1169.           pad (file, 48);
  1170.           err |= src1 (file, inst);
  1171.        }
  1172.     }
  1173.  
  1174.     if (inst->header.opcode == BRW_OPCODE_SEND ||
  1175.         inst->header.opcode == BRW_OPCODE_SENDC) {
  1176.         enum brw_message_target target;
  1177.  
  1178.         if (gen >= 6)
  1179.             target = inst->header.destreg__conditionalmod;
  1180.         else if (gen == 5)
  1181.             target = inst->bits2.send_gen5.sfid;
  1182.         else
  1183.             target = inst->bits3.generic.msg_target;
  1184.  
  1185.         newline (file);
  1186.         pad (file, 16);
  1187.         space = 0;
  1188.  
  1189.         if (gen >= 6) {
  1190.            err |= control (file, "target function", target_function_gen6,
  1191.                            target, &space);
  1192.         } else {
  1193.            err |= control (file, "target function", target_function,
  1194.                            target, &space);
  1195.         }
  1196.  
  1197.         switch (target) {
  1198.         case BRW_SFID_MATH:
  1199.             err |= control (file, "math function", math_function,
  1200.                             inst->bits3.math.function, &space);
  1201.             err |= control (file, "math saturate", math_saturate,
  1202.                             inst->bits3.math.saturate, &space);
  1203.             err |= control (file, "math signed", math_signed,
  1204.                             inst->bits3.math.int_type, &space);
  1205.             err |= control (file, "math scalar", math_scalar,
  1206.                             inst->bits3.math.data_type, &space);
  1207.             err |= control (file, "math precision", math_precision,
  1208.                             inst->bits3.math.precision, &space);
  1209.             break;
  1210.         case BRW_SFID_SAMPLER:
  1211.             if (gen >= 7) {
  1212.                 format (file, " (%d, %d, %d, %d)",
  1213.                         inst->bits3.sampler_gen7.binding_table_index,
  1214.                         inst->bits3.sampler_gen7.sampler,
  1215.                         inst->bits3.sampler_gen7.msg_type,
  1216.                         inst->bits3.sampler_gen7.simd_mode);
  1217.             } else if (gen >= 5) {
  1218.                 format (file, " (%d, %d, %d, %d)",
  1219.                         inst->bits3.sampler_gen5.binding_table_index,
  1220.                         inst->bits3.sampler_gen5.sampler,
  1221.                         inst->bits3.sampler_gen5.msg_type,
  1222.                         inst->bits3.sampler_gen5.simd_mode);
  1223.             } else if (0 /* FINISHME: is_g4x */) {
  1224.                 format (file, " (%d, %d)",
  1225.                         inst->bits3.sampler_g4x.binding_table_index,
  1226.                         inst->bits3.sampler_g4x.sampler);
  1227.             } else {
  1228.                 format (file, " (%d, %d, ",
  1229.                         inst->bits3.sampler.binding_table_index,
  1230.                         inst->bits3.sampler.sampler);
  1231.                 err |= control (file, "sampler target format",
  1232.                                 sampler_target_format,
  1233.                                 inst->bits3.sampler.return_format, NULL);
  1234.                 string (file, ")");
  1235.             }
  1236.             break;
  1237.         case BRW_SFID_DATAPORT_READ:
  1238.             if (gen >= 6) {
  1239.                 format (file, " (%d, %d, %d, %d)",
  1240.                         inst->bits3.gen6_dp.binding_table_index,
  1241.                         inst->bits3.gen6_dp.msg_control,
  1242.                         inst->bits3.gen6_dp.msg_type,
  1243.                         inst->bits3.gen6_dp.send_commit_msg);
  1244.             } else if (gen >= 5 /* FINISHME: || is_g4x */) {
  1245.                 format (file, " (%d, %d, %d)",
  1246.                         inst->bits3.dp_read_gen5.binding_table_index,
  1247.                         inst->bits3.dp_read_gen5.msg_control,
  1248.                         inst->bits3.dp_read_gen5.msg_type);
  1249.             } else {
  1250.                 format (file, " (%d, %d, %d)",
  1251.                         inst->bits3.dp_read.binding_table_index,
  1252.                         inst->bits3.dp_read.msg_control,
  1253.                         inst->bits3.dp_read.msg_type);
  1254.             }
  1255.             break;
  1256.  
  1257.         case BRW_SFID_DATAPORT_WRITE:
  1258.             if (gen >= 7) {
  1259.                 format (file, " (");
  1260.  
  1261.                 err |= control (file, "DP rc message type",
  1262.                                 dp_rc_msg_type_gen6,
  1263.                                 inst->bits3.gen7_dp.msg_type, &space);
  1264.  
  1265.                 format (file, ", %d, %d, %d)",
  1266.                         inst->bits3.gen7_dp.binding_table_index,
  1267.                         inst->bits3.gen7_dp.msg_control,
  1268.                         inst->bits3.gen7_dp.msg_type);
  1269.             } else if (gen == 6) {
  1270.                 format (file, " (");
  1271.  
  1272.                 err |= control (file, "DP rc message type",
  1273.                                 dp_rc_msg_type_gen6,
  1274.                                 inst->bits3.gen6_dp.msg_type, &space);
  1275.  
  1276.                 format (file, ", %d, %d, %d, %d)",
  1277.                         inst->bits3.gen6_dp.binding_table_index,
  1278.                         inst->bits3.gen6_dp.msg_control,
  1279.                         inst->bits3.gen6_dp.msg_type,
  1280.                         inst->bits3.gen6_dp.send_commit_msg);
  1281.             } else {
  1282.                 format (file, " (%d, %d, %d, %d)",
  1283.                         inst->bits3.dp_write.binding_table_index,
  1284.                         (inst->bits3.dp_write.last_render_target << 3) |
  1285.                         inst->bits3.dp_write.msg_control,
  1286.                         inst->bits3.dp_write.msg_type,
  1287.                         inst->bits3.dp_write.send_commit_msg);
  1288.             }
  1289.             break;
  1290.  
  1291.         case BRW_SFID_URB:
  1292.             if (gen >= 5) {
  1293.                 format (file, " %d", inst->bits3.urb_gen5.offset);
  1294.             } else {
  1295.                 format (file, " %d", inst->bits3.urb.offset);
  1296.             }
  1297.  
  1298.             space = 1;
  1299.             if (gen >= 5) {
  1300.                 err |= control (file, "urb opcode", urb_opcode,
  1301.                                 inst->bits3.urb_gen5.opcode, &space);
  1302.             }
  1303.             err |= control (file, "urb swizzle", urb_swizzle,
  1304.                             inst->bits3.urb.swizzle_control, &space);
  1305.             err |= control (file, "urb allocate", urb_allocate,
  1306.                             inst->bits3.urb.allocate, &space);
  1307.             err |= control (file, "urb used", urb_used,
  1308.                             inst->bits3.urb.used, &space);
  1309.             err |= control (file, "urb complete", urb_complete,
  1310.                             inst->bits3.urb.complete, &space);
  1311.             break;
  1312.         case BRW_SFID_THREAD_SPAWNER:
  1313.             break;
  1314.         case GEN7_SFID_DATAPORT_DATA_CACHE:
  1315.             format (file, " (%d, %d, %d)",
  1316.                     inst->bits3.gen7_dp.binding_table_index,
  1317.                     inst->bits3.gen7_dp.msg_control,
  1318.                     inst->bits3.gen7_dp.msg_type);
  1319.             break;
  1320.  
  1321.  
  1322.         default:
  1323.             format (file, "unsupported target %d", target);
  1324.             break;
  1325.         }
  1326.         if (space)
  1327.             string (file, " ");
  1328.         if (gen >= 5) {
  1329.            format (file, "mlen %d",
  1330.                    inst->bits3.generic_gen5.msg_length);
  1331.            format (file, " rlen %d",
  1332.                    inst->bits3.generic_gen5.response_length);
  1333.         } else {
  1334.            format (file, "mlen %d",
  1335.                    inst->bits3.generic.msg_length);
  1336.            format (file, " rlen %d",
  1337.                    inst->bits3.generic.response_length);
  1338.         }
  1339.     }
  1340.     pad (file, 64);
  1341.     if (inst->header.opcode != BRW_OPCODE_NOP) {
  1342.         string (file, "{");
  1343.         space = 1;
  1344.         err |= control(file, "access mode", access_mode, inst->header.access_mode, &space);
  1345.         if (gen >= 6)
  1346.             err |= control (file, "write enable control", wectrl, inst->header.mask_control, &space);
  1347.         else
  1348.             err |= control (file, "mask control", mask_ctrl, inst->header.mask_control, &space);
  1349.         err |= control (file, "dependency control", dep_ctrl, inst->header.dependency_control, &space);
  1350.  
  1351.         if (gen >= 6)
  1352.             err |= qtr_ctrl (file, inst);
  1353.         else {
  1354.             if (inst->header.compression_control == BRW_COMPRESSION_COMPRESSED &&
  1355.                 opcode[inst->header.opcode].ndst > 0 &&
  1356.                 inst->bits1.da1.dest_reg_file == BRW_MESSAGE_REGISTER_FILE &&
  1357.                 inst->bits1.da1.dest_reg_nr & (1 << 7)) {
  1358.                 format (file, " compr4");
  1359.             } else {
  1360.                 err |= control (file, "compression control", compr_ctrl,
  1361.                                 inst->header.compression_control, &space);
  1362.             }
  1363.         }
  1364.  
  1365.         err |= control (file, "thread control", thread_ctrl, inst->header.thread_control, &space);
  1366.         if (gen >= 6)
  1367.             err |= control (file, "acc write control", accwr, inst->header.acc_wr_control, &space);
  1368.         if (inst->header.opcode == BRW_OPCODE_SEND ||
  1369.             inst->header.opcode == BRW_OPCODE_SENDC)
  1370.             err |= control (file, "end of thread", end_of_thread,
  1371.                             inst->bits3.generic.end_of_thread, &space);
  1372.         if (space)
  1373.             string (file, " ");
  1374.         string (file, "}");
  1375.     }
  1376.     string (file, ";");
  1377.     newline (file);
  1378.     return err;
  1379. }
  1380.