00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00041
00042
00043
00044
00045
00046 #include <stdio.h>
00047 #include "issue_port_gen.h"
00048 #include "ekapi_ia64.h"
00049 #include "assert.h"
00050
00051 static const char * const description[] = {"\
00052 /* ====================================================================\n\
00053 * ====================================================================\n\
00054 *\n\
00055 * Description:\n\
00056 */", NULL};
00057
00058 void Issue_Port_Generator(void *pknobs, GEN_MODE mode, MACHINE_TYPE type)
00059 {
00060 FILE *fpc, *fph, *fp_export;
00061 char fname[512] = "targ_issue_port";
00062 char bufname[512];
00063 char *buf;
00064 int i,j,k,count;
00065 int ipcount;
00066 int value=0;
00067 kapi_fu_t fu;
00068
00069 if (type == MCK_TYPE)
00070 Init_Module_Files(mode, "targ_issue_port_mck", &fpc, &fph, &fp_export, 1);
00071 else
00072 Init_Module_Files(mode, "targ_issue_port", &fpc, &fph, &fp_export, 1);
00073 Emit_Header(fph, "targ_issue_port", description, 1);
00074
00075 fprintf(fph, "#include \"topcode.h\" \n");
00076 fprintf(fph, "#define ISA_MAX_ISSUE_BUNDLES (%d) "
00077 "// Machine width in bunldes\n",
00078 KAPI_BundleIssueWidth(pknobs,0));
00079 fprintf(fpc, "#include \"stdio.h\" \n");
00080 fprintf(fpc, "#include \"%s.h\" \n", fname);
00081
00082 fprintf(fph, "typedef INT ISSUE_PORT;\n");
00083 fprintf(fph, "extern ISSUE_PORT ");
00084
00085 for (i=0 ; i< KAPI_EnumCardinality(pknobs, "ut_t"); i++)
00086 {
00087 buf = KAPI_EnumName(pknobs, i, "ut_t");
00088 buf += strlen("ut") ;
00089 for (j=0; j< KAPI_cportCount4ut( pknobs, 0, (kapi_ut_t)i ); j++)
00090 {
00091
00092 fprintf(fpc, "ISSUE_PORT ip_%s%d = %d;\n", buf, j, value);
00093 fprintf(fph, "ip_%s%d, ", buf, j);
00094 value++;
00095 }
00096 }
00097 fprintf(fpc, "ISSUE_PORT ip_invalid = %d; \n ISSUE_PORT ip_number = %d;\n", value, value);
00098 fprintf(fph, "ip_invalid, ip_number;\n");
00099
00100 fprintf(fpc, "char *issue_port_name[] = {\n");
00101 for (i=0 ; i< KAPI_EnumCardinality(pknobs, "ut_t"); i++)
00102 {
00103 buf = KAPI_EnumName(pknobs, i, "ut_t");
00104 buf += strlen("ut") ;
00105 for (j=0; j< KAPI_cportCount4ut( pknobs, 0, (kapi_ut_t)i ); j++)
00106 {
00107 fprintf(fpc, " \"%s%d\",\n", buf, j);
00108 value++;
00109 }
00110 }
00111 fprintf(fpc, " \"invalid\" \n};\n\n");
00112
00113 fprintf(fph, "extern char *issue_port_name[];\n");
00114 fprintf(fph, "inline char *Issue_Port_Name( const ISSUE_PORT ip)\n"
00115 "{ return issue_port_name[ip];}\n\n");
00116
00117 fprintf(fph, "extern ISSUE_PORT issue_port_seq[];\n\n");
00118 fprintf(fpc, "ISSUE_PORT issue_port_seq[]={\n");
00119
00120 int m_idx = -1;
00121 int i_idx = -1;
00122 for (i=0 ; i< KAPI_EnumCardinality(pknobs, "ut_t"); i++)
00123 {
00124 buf = KAPI_EnumName(pknobs, i, "ut_t");
00125 buf += strlen("ut") ;
00126
00127
00128 if (type == MCK_TYPE && *buf == 'M' && i_idx == -1) {
00129 m_idx = i;
00130 continue;
00131 }
00132 for (j=0; j< KAPI_cportCount4ut( pknobs, 0, (kapi_ut_t)i ); j++)
00133 {
00134 int k = j;
00135 if (*buf=='B'){
00136 k = KAPI_cportCount4ut( pknobs, 0, (kapi_ut_t)i ) - j - 1;
00137 }
00138 fprintf(fpc, " ip_%s%d,\n", buf, k);
00139 }
00140
00141 if (type == MCK_TYPE && *buf == 'I' ) {
00142 i_idx = i;
00143 if ( m_idx != -1) {
00144 *buf = 'M';
00145 for (j=0; j< KAPI_cportCount4ut( pknobs, 0, (kapi_ut_t)m_idx ); j++)
00146 fprintf(fpc, " ip_%s%d,\n", buf, j);
00147 }
00148 }
00149 }
00150 fprintf(fpc, " ip_invalid\n};\n");
00151
00152 fprintf(fph, "class PORT_SET{\n"
00153 " INT body;\n\n"
00154 "public:\n"
00155 " PORT_SET() : body(0) {}\n"
00156 " PORT_SET(INT b): body(b) {}\n"
00157 " PORT_SET(const PORT_SET& p): body(p.body) {}\n\n"
00158 " PORT_SET& operator=(PORT_SET p){ body=p.body; return *this; }\n\n"
00159 " PORT_SET operator+(PORT_SET p) const\n"
00160 " { return PORT_SET(body|p.body); }\n"
00161 " PORT_SET operator&(PORT_SET p) const\n"
00162 " { return PORT_SET(body&p.body); }\n"
00163 " PORT_SET operator+(ISSUE_PORT p) const\n"
00164 " { return PORT_SET(body|(1<<p)); }\n\n"
00165 " PORT_SET operator-(PORT_SET p) const\n"
00166 " { return PORT_SET(body&~(p.body)); }\n"
00167 " PORT_SET operator-(ISSUE_PORT p) const\n"
00168 " { return PORT_SET(body&~(1<<p));}\n\n"
00169 " operator INT() const{return body; }"
00170 " INT Body() const{ return body; }\n"
00171 " BOOL In(ISSUE_PORT p) const { return ((1<<p)&body)!=0;}\n"
00172 " BOOL Is_Subset_Of(PORT_SET p) const { return (~body)|(p.body);}\n"
00173 " void Print(FILE *fp, char *str);\n"
00174 " ISSUE_PORT First_IP();\n"
00175 " ISSUE_PORT Last_IP();\n"
00176 " INT Count();\n"
00177 "};\n\n" );
00178
00179
00180 fprintf(fph, "extern PORT_SET ");
00181 fprintf(fpc,
00182 "void PORT_SET::Print(FILE *fp, char *str) {\n"
00183 " BOOL first=true;\n"
00184 " for (INT i=0; i<ip_invalid; i++)\n"
00185 " if (body & 1<<i) {\n"
00186 " if (!first) fprintf(fp, str); /* print string to seperate*/\n"
00187 " fprintf(fp, Issue_Port_Name((ISSUE_PORT)i));\n"
00188 " first = false;\n"
00189 " }\n"
00190 "}\n"
00191 "ISSUE_PORT PORT_SET::First_IP() {\n"
00192 " for (INT i=0; i<ip_invalid; i++)\n"
00193 " if (body & 1<<i) return (ISSUE_PORT)i;\n"
00194 " return ip_invalid;\n"
00195 "}\n"
00196 "ISSUE_PORT PORT_SET::Last_IP() {\n"
00197 " for (INT i=ip_invalid; i>=0; i--)\n"
00198 " if (body & 1<<i) return (ISSUE_PORT)i;\n"
00199 " return ip_invalid;\n"
00200 "}\n"
00201 "INT PORT_SET::Count() {\n"
00202 " INT count = 0;\n"
00203 " for (INT i=ip_invalid; i>=0; i--)\n"
00204 " if (body & 1<<i) count++;\n"
00205 " return count;\n"
00206 "}\n");
00207 j = 0;
00208 for (i=0 ; i< KAPI_EnumCardinality(pknobs, "ut_t"); i++)
00209 {
00210 buf = KAPI_EnumName(pknobs, i, "ut_t");
00211 buf += strlen("ut") ;
00212 fprintf(fph, "%s_PORTS", buf);
00213 int sum = KAPI_cportCount4ut( pknobs, 0, (kapi_ut_t)i );
00214 long ports_set = ((1 << sum) - 1) << j;
00215 fprintf(fpc, "PORT_SET %s_PORTS(%ld);\n", buf, ports_set);
00216 j += sum;
00217 if (i != KAPI_EnumCardinality(pknobs, "ut_t")-1) {
00218 fprintf(fph, ", ");
00219 }
00220 else {
00221 fprintf(fph, ";\n");
00222 }
00223 }
00224
00225 fprintf(fph, "extern const INT op_issue_port[];\n"
00226 "inline const PORT_SET TSI_Issue_Ports(TOP top)\n"
00227 "{\n"
00228 " switch(top){\n"
00229 " case TOP_mov_t_ar_r:\n"
00230 " return (PORT_SET)( op_issue_port[TOP_mov_t_ar_r_i]\n"
00231 " | op_issue_port[TOP_mov_t_ar_r_m] );\n"
00232 " case TOP_mov_t_ar_i:\n"
00233 " return (PORT_SET)( op_issue_port[TOP_mov_t_ar_i_i]\n"
00234 " | op_issue_port[TOP_mov_t_ar_i_m] );\n"
00235 " case TOP_mov_f_ar:\n"
00236 " return (PORT_SET)( op_issue_port[TOP_mov_f_ar_i]\n"
00237 " | op_issue_port[TOP_mov_f_ar_m] );\n"
00238 " case TOP_break:\n"
00239 " return (PORT_SET)( op_issue_port[TOP_break_i]\n"
00240 " | op_issue_port[TOP_break_m]\n"
00241 " | op_issue_port[TOP_break_b]\n"
00242 " | op_issue_port[TOP_break_f] );\n"
00243 " case TOP_chk_s:\n"
00244 " return (PORT_SET)( op_issue_port[TOP_chk_s_i]\n"
00245 " | op_issue_port[TOP_chk_s_m] );\n"
00246 " default:\n"
00247 " return (PORT_SET)(op_issue_port[top]);\n"
00248 " }\n"
00249 "}\n\n");
00250
00251 count = EKAPI_OpCount(pknobs);
00252 fprintf(fpc, "\nconst INT op_issue_port[%d] = {\n", count);
00253 for(i=0; i<count; i++)
00254 {
00255 buf = EKAPI_Op2Fu(pknobs, i);
00256
00257 if ( (strcmp(buf, "fuUNKNOWN") == 0) ||
00258 (strcmp(buf, "fuDUMMY") ==0) )
00259 {
00260 fu = -2;
00261 }
00262 else
00263 {
00264
00265 fu = KAPI_EnumIndex(pknobs, "fu_t", buf);
00266 }
00267 switch (fu)
00268 {
00269 case -1: printf("UNKNOWN fu [%s] line %d\n", buf, i); break;
00270 case -2: fprintf(fpc, " %3d", 0); break;
00271 default:
00272 {
00273 fprintf(fpc, " %3ld", (long)KAPI_cportMask4fu(pknobs, 0, fu));
00274 break;
00275 }
00276 }
00277 if (i != count-1) {
00278 fprintf(fpc, ", /* %-20s", EKAPI_OpName4id(pknobs, i));
00279 ipcount = 0;
00280
00281
00282 for (j=0 ; j< KAPI_EnumCardinality(pknobs, "ut_t"); j++)
00283 {
00284 buf = KAPI_EnumName(pknobs, j, "ut_t");
00285 buf += strlen("ut") ;
00286 for (k=0; k< KAPI_cportCount4ut( pknobs, 0, (kapi_ut_t)j );k++)
00287 {
00288 value = 1ULL << ipcount;
00289 ipcount++;
00290
00291 if (value & KAPI_cportMask4fu(pknobs, 0, fu)) {
00292 fprintf(fpc, " ip_%s%d ", buf, k );
00293 }
00294 }
00295 }
00296 fprintf(fpc, "*/\n");
00297 }
00298 }
00299
00300 fprintf(fpc, "\n};\n");
00301
00302 if (type == MCK_TYPE)
00303 fprintf(fpc, "INT PROCESSOR_Version=2;\n");
00304 else
00305 fprintf(fpc, "INT PROCESSOR_Version=1;\n");
00306 fprintf(fph, "extern INT PROCESSOR_Version;\n");
00307 Emit_Tailer(fph, 1);
00308 Close_Module_Files(mode, &fpc, &fph, &fp_export);
00309 }
00310
00311