intel/tools: New i965 instruction assembler tool

Tool is inspired from igt's assembler tool. Thanks to Matt Turner, who
mentored me through out this project.

v2: Fix memory leaks and naming convention (Caio)
v3: Fix meson changes (Dylan Baker)
v4: Fix usage options (Matt Turner)

Signed-off-by: Sagar Ghuge <sagar.ghuge@intel.com>
Reviewed-by: Dylan Baker <dylan@pnwbakers.com>
Reviewed-by: Matt Turner <mattst88@gmail.com>
Closes: https://gitlab.freedesktop.org/mesa/mesa/merge_requests/141
This commit is contained in:
Sagar Ghuge 2018-12-10 16:12:07 -08:00 committed by Matt Turner
parent a232aa5c50
commit 70308a5a8a
No known key found for this signature in database
GPG key ID: 9C825A6605D40BBE
5 changed files with 3040 additions and 0 deletions

255
src/intel/tools/i965_asm.c Normal file
View file

@ -0,0 +1,255 @@
/*
* Copyright © 2018 Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*/
#include <stdio.h>
#include <getopt.h>
#include "i965_asm.h"
extern FILE *yyin;
struct brw_codegen *p;
static int c_literal_output = 0;
char *input_filename;
int errors;
static void
print_help(const char *progname, FILE *file)
{
fprintf(file,
"Usage: %s [OPTION] inputfile\n"
"Assemble i965 instructions from input file.\n\n"
" -h, --help display this help and exit\n"
" -l, --c-literal C literal\n"
" -o, --output specify output file\n"
" --compact print compacted instructions\n"
" -g, --gen=platform assemble instructions for given \n"
" platform (3 letter platform name)\n"
"Example:\n"
" i965_asm -g kbl input.asm -o output\n",
progname);
}
static void
print_instruction(FILE *output, bool compact, const brw_inst *instruction)
{
int byte_limit;
byte_limit = (compact == true) ? 8 : 16;
if (c_literal_output) {
fprintf(output, "\t0x%02x,", ((unsigned char *)instruction)[0]);
for (unsigned i = 1; i < byte_limit; i++)
fprintf(output, " 0x%02x,", ((unsigned char *)instruction)[i]);
} else {
fprintf(output, "%02x", ((unsigned char *)instruction)[0]);
for (unsigned i = 1; i < byte_limit; i++)
fprintf(output, " %02x", ((unsigned char *)instruction)[i]);
}
fprintf(output, "\n");
}
static struct gen_device_info *
i965_disasm_init(uint16_t pci_id)
{
struct gen_device_info *devinfo;
devinfo = malloc(sizeof *devinfo);
if (devinfo == NULL)
return NULL;
if (!gen_get_device_info(pci_id, devinfo)) {
fprintf(stderr, "can't find device information: pci_id=0x%x\n",
pci_id);
return NULL;
}
brw_init_compaction_tables(devinfo);
return devinfo;
}
int main(int argc, char **argv)
{
char *output_file = NULL;
char c;
FILE *output = stdout;
bool help = false, compact = false;
void *store;
uint64_t pci_id = 0;
int offset, err;
int start_offset = 0;
struct disasm_info *disasm_info;
struct gen_device_info *devinfo;
int result = EXIT_FAILURE;
const struct option i965_asm_opts[] = {
{ "help", no_argument, (int *) &help, true },
{ "c-literal", no_argument, NULL, 'c' },
{ "gen", required_argument, NULL, 'g' },
{ "output", required_argument, NULL, 'o' },
{ "compact", no_argument, (int *) &compact, true },
{ NULL, 0, NULL, 0 }
};
while ((c = getopt_long(argc, argv, ":g:o:lh", i965_asm_opts, NULL)) != -1) {
switch (c) {
case 'g': {
const int id = gen_device_name_to_pci_device_id(optarg);
if (id < 0) {
fprintf(stderr, "can't parse gen: '%s', expected 3 letter "
"platform name\n", optarg);
goto end;
} else {
pci_id = id;
}
break;
}
case 'h':
help = true;
print_help(argv[0], stderr);
goto end;
case 'l':
c_literal_output = 1;
break;
case 'o':
output_file = strdup(optarg);
break;
case 0:
break;
case ':':
fprintf(stderr, "%s: option `-%c' requires an argument\n",
argv[0], optopt);
goto end;
case '?':
default:
fprintf(stderr, "%s: option `-%c' is invalid: ignored\n",
argv[0], optopt);
goto end;
}
}
if (help || !pci_id) {
print_help(argv[0], stderr);
goto end;
}
if (!argv[optind]) {
fprintf(stderr, "Please specify input file\n");
goto end;
}
input_filename = strdup(argv[optind]);
yyin = fopen(input_filename, "r");
if (!yyin) {
fprintf(stderr, "Unable to read input file : %s\n",
input_filename);
goto end;
}
if (output_file) {
output = fopen(output_file, "w");
if (!output) {
fprintf(stderr, "Couldn't open output file\n");
goto end;
}
}
devinfo = i965_disasm_init(pci_id);
if (!devinfo) {
fprintf(stderr, "Unable to allocate memory for "
"gen_device_info struct instance.\n");
goto end;
}
p = rzalloc(NULL, struct brw_codegen);
brw_init_codegen(devinfo, p, p);
p->automatic_exec_sizes = false;
err = yyparse();
if (err || errors)
goto end;
store = p->store;
disasm_info = disasm_initialize(p->devinfo, NULL);
if (!disasm_info) {
fprintf(stderr, "Unable to initialize disasm_info struct instance\n");
goto end;
}
if (c_literal_output)
fprintf(output, "static const char gen_eu_bytes[] = {\n");
brw_validate_instructions(p->devinfo, p->store, 0,
p->next_insn_offset, disasm_info);
int nr_insn = (p->next_insn_offset - start_offset) / 16;
if (compact)
brw_compact_instructions(p, start_offset, disasm_info);
ralloc_free(disasm_info);
for (int i = 0; i < nr_insn; i++) {
const brw_inst *insn = store + offset;
bool compacted = false;
if (compact && brw_inst_cmpt_control(p->devinfo, insn)) {
offset += 8;
compacted = true;
} else {
offset += 16;
}
print_instruction(output, compacted, insn);
}
if (c_literal_output)
fprintf(output, "}");
result = EXIT_SUCCESS;
goto end;
end:
if (input_filename)
free(input_filename);
if (output_file)
free(output_file);
if (yyin)
fclose(yyin);
if (output)
fclose(output);
if (p)
ralloc_free(p);
if (devinfo)
free(devinfo);
exit(result);
}

View file

@ -0,0 +1,77 @@
/*
* Copyright © 2018 Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*/
#ifndef __I965_ASM_H__
#define __I965_ASM_H__
#include <inttypes.h>
#include <stdbool.h>
#include <assert.h>
#include "compiler/brw_reg.h"
#include "compiler/brw_reg_type.h"
#include "compiler/brw_eu_defines.h"
#include "compiler/brw_inst.h"
#include "compiler/brw_eu.h"
#include "dev/gen_device_info.h"
void yyerror (char *);
int yyparse(void);
int yylex(void);
char *lex_text(void);
extern struct brw_codegen *p;
extern int errors;
extern char *input_filename;
struct condition {
unsigned cond_modifier:4;
unsigned flag_reg_nr:1;
unsigned flag_subreg_nr:1;
};
struct predicate {
unsigned pred_control:4;
unsigned pred_inv:1;
unsigned flag_reg_nr:1;
unsigned flag_subreg_nr:1;
};
struct options {
unsigned access_mode:1;
unsigned compression_control:2;
unsigned thread_control:2;
unsigned no_dd_check:1; // Dependency control
unsigned no_dd_clear:1; // Dependency control
unsigned mask_control:1;
unsigned debug_control:1;
unsigned acc_wr_control:1;
unsigned end_of_thread:1;
unsigned compaction:1;
unsigned qtr_ctrl:2;
unsigned nib_ctrl:1;
unsigned is_compr:1;
};
#endif /* __I965_ASM_H__ */

2278
src/intel/tools/i965_gram.y Normal file

File diff suppressed because it is too large Load diff

404
src/intel/tools/i965_lex.l Normal file
View file

@ -0,0 +1,404 @@
%option yylineno
%option nounput
%{
#include <string.h>
#include "i965_asm.h"
#include "i965_gram.tab.h"
/* Locations */
int yycolumn = 1;
int saved_state = 0;
extern char *input_filename;
#define YY_NO_INPUT
#define YY_USER_ACTION \
yylloc.first_line = yylloc.last_line = yylineno; \
yylloc.first_column = yycolumn; \
yylloc.last_column = yycolumn + yyleng - 1; \
yycolumn += yyleng;
%}
%x BLOCK_COMMENT
%x FILENAME
%x CHANNEL
%x REG
%x DOTSEL
%%
/* eat up single line comment */
\/\/.*[\r\n] { yycolumn = 1; }
/* eat up multiline comment */
\/\* { saved_state = YYSTATE; BEGIN(BLOCK_COMMENT); }
<BLOCK_COMMENT>\*\/ { BEGIN(saved_state); }
<BLOCK_COMMENT>. { }
<BLOCK_COMMENT>[\r\n] { }
<FILENAME>\"[^\"]+\" {
char *name = malloc(yyleng - 1);
memmove(name, yytext + 1, yyleng - 2);
name[yyleng-1] = '\0';
input_filename = name;
}
/* null register */
null { BEGIN(REG); return NULL_TOKEN; }
/* Opcodes */
add { yylval.integer = BRW_OPCODE_ADD; return ADD; }
addc { yylval.integer = BRW_OPCODE_ADDC; return ADDC; }
and { yylval.integer = BRW_OPCODE_AND; return AND; }
asr { yylval.integer = BRW_OPCODE_ASR; return ASR; }
avg { yylval.integer = BRW_OPCODE_AVG; return AVG; }
bfe { yylval.integer = BRW_OPCODE_BFE; return BFE; }
bfi1 { yylval.integer = BRW_OPCODE_BFI1; return BFI1; }
bfi2 { yylval.integer = BRW_OPCODE_BFI2; return BFI2; }
bfrev { yylval.integer = BRW_OPCODE_BFREV; return BFREV; }
brc { yylval.integer = BRW_OPCODE_BRC; return BRC; }
brd { yylval.integer = BRW_OPCODE_BRD; return BRD; }
break { yylval.integer = BRW_OPCODE_BREAK; return BREAK; }
call { yylval.integer = BRW_OPCODE_CALL; return CALL; }
calla { yylval.integer = BRW_OPCODE_CALLA; return CALLA; }
case { yylval.integer = BRW_OPCODE_CASE; return CASE; }
cbit { yylval.integer = BRW_OPCODE_CBIT; return CBIT; }
cmp { yylval.integer = BRW_OPCODE_CMP; return CMP; }
cmpn { yylval.integer = BRW_OPCODE_CMPN; return CMPN; }
cont { yylval.integer = BRW_OPCODE_CONTINUE; return CONT; }
csel { yylval.integer = BRW_OPCODE_CSEL; return CSEL; }
dim { yylval.integer = BRW_OPCODE_DIM; return DIM; }
do { yylval.integer = BRW_OPCODE_DO; return DO; }
dp2 { yylval.integer = BRW_OPCODE_DP2; return DP2; }
dp3 { yylval.integer = BRW_OPCODE_DP3; return DP3; }
dp4 { yylval.integer = BRW_OPCODE_DP4; return DP4; }
dph { yylval.integer = BRW_OPCODE_DPH; return DPH; }
else { yylval.integer = BRW_OPCODE_ELSE; return ELSE; }
endif { yylval.integer = BRW_OPCODE_ENDIF; return ENDIF; }
f16to32 { yylval.integer = BRW_OPCODE_F16TO32; return F16TO32; }
f32to16 { yylval.integer = BRW_OPCODE_F32TO16; return F32TO16; }
fbh { yylval.integer = BRW_OPCODE_FBH; return FBH; }
fbl { yylval.integer = BRW_OPCODE_FBL; return FBL; }
fork { yylval.integer = BRW_OPCODE_FORK; return FORK; }
frc { yylval.integer = BRW_OPCODE_FRC; return FRC; }
goto { yylval.integer = BRW_OPCODE_GOTO; return GOTO; }
halt { yylval.integer = BRW_OPCODE_HALT; return HALT; }
if { yylval.integer = BRW_OPCODE_IF; return IF; }
iff { yylval.integer = BRW_OPCODE_IFF; return IFF; }
illegal { yylval.integer = BRW_OPCODE_ILLEGAL; return ILLEGAL; }
jmpi { yylval.integer = BRW_OPCODE_JMPI; return JMPI; }
line { yylval.integer = BRW_OPCODE_LINE; return LINE; }
lrp { yylval.integer = BRW_OPCODE_LRP; return LRP; }
lzd { yylval.integer = BRW_OPCODE_LZD; return LZD; }
mac { yylval.integer = BRW_OPCODE_MAC; return MAC; }
mach { yylval.integer = BRW_OPCODE_MACH; return MACH; }
mad { yylval.integer = BRW_OPCODE_MAD; return MAD; }
madm { yylval.integer = BRW_OPCODE_MADM; return MADM; }
mov { yylval.integer = BRW_OPCODE_MOV; return MOV; }
movi { yylval.integer = BRW_OPCODE_MOVI; return MOVI; }
mul { yylval.integer = BRW_OPCODE_MUL; return MUL; }
mrest { yylval.integer = BRW_OPCODE_MREST; return MREST; }
msave { yylval.integer = BRW_OPCODE_MSAVE; return MSAVE; }
nenop { yylval.integer = BRW_OPCODE_NENOP; return NENOP; }
nop { yylval.integer = BRW_OPCODE_NOP; return NOP; }
not { yylval.integer = BRW_OPCODE_NOT; return NOT; }
or { yylval.integer = BRW_OPCODE_OR; return OR; }
pln { yylval.integer = BRW_OPCODE_PLN; return PLN; }
pop { yylval.integer = BRW_OPCODE_POP; return POP; }
push { yylval.integer = BRW_OPCODE_PUSH; return PUSH; }
ret { yylval.integer = BRW_OPCODE_RET; return RET; }
rndd { yylval.integer = BRW_OPCODE_RNDD; return RNDD; }
rnde { yylval.integer = BRW_OPCODE_RNDE; return RNDE; }
rndu { yylval.integer = BRW_OPCODE_RNDU; return RNDU; }
rndz { yylval.integer = BRW_OPCODE_RNDZ; return RNDZ; }
sad2 { yylval.integer = BRW_OPCODE_SAD2; return SAD2; }
sada2 { yylval.integer = BRW_OPCODE_SADA2; return SADA2; }
sel { yylval.integer = BRW_OPCODE_SEL; return SEL; }
send { yylval.integer = BRW_OPCODE_SEND; return SEND; }
sendc { yylval.integer = BRW_OPCODE_SENDC; return SENDC; }
sends { yylval.integer = BRW_OPCODE_SENDS; return SENDS; }
sendsc { yylval.integer = BRW_OPCODE_SENDSC; return SENDSC; }
shl { yylval.integer = BRW_OPCODE_SHL; return SHL; }
shr { yylval.integer = BRW_OPCODE_SHR; return SHR; }
smov { yylval.integer = BRW_OPCODE_SMOV; return SMOV; }
subb { yylval.integer = BRW_OPCODE_SUBB; return SUBB; }
wait { yylval.integer = BRW_OPCODE_WAIT; return WAIT; }
while { yylval.integer = BRW_OPCODE_WHILE; return WHILE; }
xor { yylval.integer = BRW_OPCODE_XOR; return XOR; }
/* extended math functions */
cos { yylval.integer = BRW_MATH_FUNCTION_COS; return COS; }
exp { yylval.integer = BRW_MATH_FUNCTION_EXP; return EXP; }
fdiv { yylval.integer = BRW_MATH_FUNCTION_FDIV; return FDIV; }
inv { yylval.integer = BRW_MATH_FUNCTION_INV; return INV; }
invm { yylval.integer = GEN8_MATH_FUNCTION_INVM; return INVM; }
intdiv {
yylval.integer = BRW_MATH_FUNCTION_INT_DIV_QUOTIENT;
return INTDIV;
}
intdivmod {
yylval.integer =
BRW_MATH_FUNCTION_INT_DIV_QUOTIENT_AND_REMAINDER;
return INTDIVMOD;
}
intmod {
yylval.integer = BRW_MATH_FUNCTION_INT_DIV_REMAINDER;
return INTMOD;
}
log { yylval.integer = BRW_MATH_FUNCTION_LOG; return LOG; }
pow { yylval.integer = BRW_MATH_FUNCTION_POW; return POW; }
rsq { yylval.integer = BRW_MATH_FUNCTION_RSQ; return RSQ; }
rsqrtm { yylval.integer = GEN8_MATH_FUNCTION_RSQRTM; return RSQRTM; }
sin { yylval.integer = BRW_MATH_FUNCTION_SIN; return SIN; }
sqrt { yylval.integer = BRW_MATH_FUNCTION_SQRT; return SQRT; }
sincos { yylval.integer = BRW_MATH_FUNCTION_SINCOS; return SINCOS; }
/* shared functions for send instruction */
sampler { return SAMPLER; }
dp_sampler { return DP_SAMPLER; }
gateway { return GATEWAY; }
urb { return URB; }
thread_spawner { return THREAD_SPAWNER; }
render { return RENDER; }
const { return CONST; }
data { return DATA; }
cre { return CRE; }
math { return MATH; }
read { return READ; }
write { return WRITE; }
vme { return VME; }
"pixel interp" { return PIXEL_INTERP; }
"dp data 1" { return DP_DATA_1; }
";" { return SEMICOLON; }
":" { return COLON; }
"(" { return LPAREN; }
")" { return RPAREN; }
"{" { return LCURLY; }
"}" { return RCURLY; }
"[" { return LSQUARE; }
"]" { return RSQUARE; }
"<" { return LANGLE; }
">" { return RANGLE; }
"," { return COMMA; }
"." { return DOT; }
"+" { return PLUS; }
"-" { return MINUS; }
"~" { return MINUS; }
"(abs)" { return ABS; }
"VxH" { return VxH; }
<REG>"<" { return LANGLE; }
<REG>[0-9][0-9]* {
yylval.integer = strtoul(yytext, NULL, 10);
return INTEGER;
}
<REG>">" { return RANGLE; }
<REG>"," { return COMMA; }
<REG>"." { BEGIN(DOTSEL); return DOT; }
<REG>";" { return SEMICOLON; }
<DOTSEL>"x" { yylval.integer = BRW_CHANNEL_X; return X; }
<DOTSEL>"y" { yylval.integer = BRW_CHANNEL_Y; return Y; }
<DOTSEL>"z" { yylval.integer = BRW_CHANNEL_Z; return Z; }
<DOTSEL>"w" { yylval.integer = BRW_CHANNEL_W; return W; }
<DOTSEL>[0-9][0-9]* {
yylval.integer = strtoul(yytext, NULL, 10);
BEGIN(REG);
return INTEGER;
}
<DOTSEL>. { yyless(0); BEGIN(INITIAL); }
<REG>. { yyless(0); BEGIN(INITIAL); }
/* Access mode */
"align1" { return ALIGN1; }
"align16" { return ALIGN16; }
/* Accumulator write control */
AccWrEnable { return ACCWREN; }
/* Mask control (formerly WECtrl/Write Enable Control) */
"WE_all" { return WECTRL; }
/* Compaction control */
compacted { return CMPTCTRL; }
/* Debug control */
breakpoint { return BREAKPOINT; }
/* Dependency control */
NoDDClr { return NODDCLR; }
NoDDChk { return NODDCHK; }
/* End of thread */
EOT { return EOT; }
/* Mask control */
nomask { return MASK_DISABLE; }
/* Channel */
<CHANNEL>"x" { yylval.integer = BRW_CHANNEL_X; return X; }
<CHANNEL>"y" { yylval.integer = BRW_CHANNEL_Y; return Y; }
<CHANNEL>"z" { yylval.integer = BRW_CHANNEL_Z; return Z; }
<CHANNEL>"w" { yylval.integer = BRW_CHANNEL_W; return W; }
<CHANNEL>[0-9][0-9]* {
yylval.integer = strtoul(yytext, NULL, 10);
return INTEGER;
}
<CHANNEL>"." { return DOT; }
<CHANNEL>. { yyless(0); BEGIN(INITIAL); }
/* Predicate Control */
<CHANNEL>".anyv" { yylval.integer = BRW_PREDICATE_ALIGN1_ANYV; return ANYV; }
<CHANNEL>".allv" { yylval.integer = BRW_PREDICATE_ALIGN1_ALLV; return ALLV; }
<CHANNEL>".any2h" { yylval.integer = BRW_PREDICATE_ALIGN1_ANY2H; return ANY2H; }
<CHANNEL>".all2h" { yylval.integer = BRW_PREDICATE_ALIGN1_ALL2H; return ALL2H; }
<CHANNEL>".any4h" { yylval.integer = BRW_PREDICATE_ALIGN16_ANY4H; return ANY4H; }
<CHANNEL>".all4h" { yylval.integer = BRW_PREDICATE_ALIGN16_ALL4H; return ALL4H; }
<CHANNEL>".any8h" { yylval.integer = BRW_PREDICATE_ALIGN1_ANY8H; return ANY8H; }
<CHANNEL>".all8h" { yylval.integer = BRW_PREDICATE_ALIGN1_ALL8H; return ALL8H; }
<CHANNEL>".any16h" { yylval.integer = BRW_PREDICATE_ALIGN1_ANY16H; return ANY16H; }
<CHANNEL>".all16h" { yylval.integer = BRW_PREDICATE_ALIGN1_ALL16H; return ALL16H; }
<CHANNEL>".any32h" { yylval.integer = BRW_PREDICATE_ALIGN1_ANY32H; return ANY32H; }
<CHANNEL>".all32h" { yylval.integer = BRW_PREDICATE_ALIGN1_ALL32H; return ALL32H; }
/* Saturation */
".sat" { return SATURATE; }
/* Thread control */
atomic { return ATOMIC; }
switch { return SWITCH; }
/* compression control */
compr { return COMPR; }
compr4 { return COMPR4; }
sechalf { return SECHALF; }
/* Quarter Control */
1[HNQ] { }
"2Q" { return QTR_2Q; }
"3Q" { return QTR_3Q; }
"4Q" { return QTR_4Q; }
"2H" { return QTR_2H; }
"2N" { return QTR_2N; }
"3N" { return QTR_3N; }
"4N" { return QTR_4N; }
"5N" { return QTR_5N; }
"6N" { return QTR_6N; }
"7N" { return QTR_7N; }
"8N" { return QTR_8N; }
/* data types */
:?B { return TYPE_B; }
:?D { return TYPE_D; }
:?DF { return TYPE_DF; }
:?F { return TYPE_F; }
:?HF { return TYPE_HF; }
:?NF { return TYPE_NF; }
:?Q { return TYPE_Q; }
:?UB { return TYPE_UB; }
:?UD { return TYPE_UD; }
:?UW { return TYPE_UW; }
:?UQ { return TYPE_UQ; }
:?UV { return TYPE_UV; }
:?V { return TYPE_V; }
:?VF { return TYPE_VF; }
:?W { return TYPE_W; }
/* Address registers */
"a0" { yylval.integer = atoi(yytext + 1); BEGIN(REG); return ADDRREG; }
/* accumulator registers */
"acc"[0-9]+ { yylval.integer = atoi(yytext + 3); return ACCREG; }
/* channel enable registers */
"ce0" { return CHANNELENABLEREG; }
/* control registers */
"cr0" { return CONTROLREG; }
/* flag registers */
"f"[0|1] { BEGIN(CHANNEL); yylval.integer = atoi(yytext + 1); return FLAGREG; }
/* message control registers */
"m" { return MSGREGFILE; }
m[0-9]+ { yylval.integer = atoi(yytext + 1); BEGIN(REG); return MSGREG; }
/* state register */
sr[0-9]+ { yylval.integer = atoi(yytext + 2); return STATEREG; }
/* notification registers */
"n"[0-2]+ { yylval.integer = atoi(yytext + 1); BEGIN(REG); return NOTIFYREG; }
/* IP register */
"ip" { return IPREG; }
/* Thread control register */
"tdr0" { return THREADREG; }
/* performance register */
"tm0" { BEGIN(REG); return PERFORMANCEREG; }
[gr][0-9]+ {
yylval.integer = atoi(yytext + 1);
BEGIN(REG); return GENREG;
}
[gr] { return GENREGFILE; }
"mask"[0-9]+ { yylval.integer = atoi(yytext + 4); return MASKREG; }
/* Conditional modifiers */
".e" { yylval.integer = BRW_CONDITIONAL_Z; return EQUAL; }
".g" { yylval.integer = BRW_CONDITIONAL_G; return GREATER; }
".ge" { yylval.integer = BRW_CONDITIONAL_GE; return GREATER_EQUAL; }
".l" { yylval.integer = BRW_CONDITIONAL_L; return LESS; }
".le" { yylval.integer = BRW_CONDITIONAL_LE; return LESS_EQUAL; }
".ne" { yylval.integer = BRW_CONDITIONAL_NZ; return NOT_EQUAL; }
".nz" { yylval.integer = BRW_CONDITIONAL_NZ; return NOT_ZERO; }
".o" { yylval.integer = BRW_CONDITIONAL_O; return OVERFLOW; }
".r" { yylval.integer = BRW_CONDITIONAL_R; return ROUND_INCREMENT; }
".u" { yylval.integer = BRW_CONDITIONAL_U; return UNORDERED; }
".z" { yylval.integer = BRW_CONDITIONAL_Z; return ZERO; }
/* Eat up JIP and UIP token, their values will be parsed
* in numeric section
*/
"JIP: " { }
"UIP: " { }
"Jump: " { }
"Pop: " { }
[ \t]+ { }
"MsgDesc:"[^{]* { }
"0x"[0-9a-f][0-9a-f]* {
yylval.llint = strtoull(yytext + 2, NULL, 16);
return LONG;
}
[0-9][0-9]* {
yylval.llint = strtoll(yytext, NULL, 10);
return LONG;
}
\n { yycolumn = 1; }
. {
fprintf(stderr, "%s: %d: %s: at \"%s\"\n",
input_filename, yylineno,
"unexpected token", lex_text());
}
%%
char *
lex_text(void)
{
return yytext;
}
#ifndef yywrap
int yywrap()
{
return -1;
}
#endif

View file

@ -127,3 +127,29 @@ if with_tools.contains('intel-ui')
install : true install : true
) )
endif endif
i965_gram_tab = custom_target(
'i965_gram.tab.[ch]',
input : 'i965_gram.y',
output : ['i965_gram.tab.c', 'i965_gram.tab.h'],
command : [
prog_bison, '@INPUT@', '--defines=@OUTPUT1@',
'--output=@OUTPUT0@'
]
)
i965_lex_yy_c = custom_target(
'i965_lex.yy.c',
input : 'i965_lex.l',
output : 'i965_lex.yy.c',
command : [prog_flex, '-o', '@OUTPUT@', '@INPUT@']
)
i965_asm = executable(
'i965_asm',
['i965_asm.c', i965_gram_tab[0], i965_gram_tab[1], i965_lex_yy_c],
include_directories : [inc_common, inc_intel],
link_with : [libintel_common, libintel_compiler, libintel_dev, libmesa_util],
c_args : [c_vis_args, no_override_init_args],
install : true
)