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 #include <stdio.h>
00028
00029 #include <conio.h>
00030
00031 #include <stdlib.h>
00032
00033 #include <string.h>
00034 #include "kapi.h"
00035
00036 #include "kapi_debug.h"
00037
00038 #include "kapi_ia64.h"
00039 #include "kapi_save_source_ia64.h"
00040
00041 static void Test_bv128Rtns();
00042 static void Test_bv64Rtns();
00043 static void Test_bv32Rtns();
00044
00045
00046
00047
00048 void dump_instruction_fus(FILE *fp, void *pknobs)
00049
00050 {
00051
00052 int num_of_insts,iid,dummy;
00053 kapi_fu_t fu;
00054
00055 typedef struct {
00056 int x;
00057 int *ix;
00058 char *gogo;
00059 int nx[2];
00060 } xtest;
00061 typedef struct {
00062 int nxs;
00063 xtest *pxtest;
00064 xtest *ppx[2];
00065 char *dx;
00066 xtest x[2];
00067 } ytest;
00068
00069 static int yy[]={5,5};
00070
00071
00072 static xtest xx[]= {{2,yy,"gogo",{0,0}},
00073 {2,yy,"gogo",{0,0}}};
00074 static xtest zz[2]= {{2,yy,"gogo",{0,0}},
00075 {2,yy,"gogo",{0,0}}};
00076
00077 static ytest ylast={2,
00078 &(zz[1]),
00079 {xx,zz},
00080 "gugunza",
00081 };
00082
00083 char *str;
00084 char *cIdx;
00085 char buffer[100];
00086 int idx;
00087 int iVal;
00088
00089 FILE *fpTab=fopen("tryTab.c","w");
00090 int expressions=KAPI_EnumCardinality(pknobs,"expressions");
00091 dummy=KAPI_cportMask4ut(pknobs,0,kapi_utI);
00092 dummy=KAPI_cportMask4ut(pknobs,0,kapi_utM);
00093 dummy=KAPI_cportMask4ut(pknobs,0,kapi_utF);
00094 dummy=KAPI_cportMask4ut(pknobs,0,kapi_utB);
00095
00096
00097 dummy=KAPI_fuCount(pknobs);
00098 num_of_insts=KAPI_iidCount(pknobs);
00099 _strset(buffer,0);
00100 str="#include \"tryhead.h\"\n\ninst_info_tab_t infoTab[] = {\n";
00101 fwrite(str,sizeof(char),strlen(str),fp);
00102 for (iid=0;iid<num_of_insts;iid++)
00103 {
00104 _strset(buffer,0);
00105 str=KAPI_iid2uniqueName(pknobs,iid,dummy);
00106 fwrite(str,sizeof(char),strlen(str),fp);
00107 fwrite(",",sizeof(char),1,fp);
00108 fu=KAPI_iid2fu(pknobs,iid,dummy);
00109 strcat(buffer,"/* ");
00110 strcat(buffer,KAPI_fu2fuName(pknobs,fu,dummy));
00111 strcat(buffer," */");
00112 fwrite(buffer,sizeof(char),strlen(buffer),fp);
00113 *buffer='\0';
00114 _itoa(fu,buffer,10);
00115 fwrite(buffer,sizeof(char),strlen(buffer),fp);
00116 fwrite(",",sizeof(char),1,fp);
00117 fwrite("\n",sizeof(char),1,fp);
00118 }
00119 _strset(buffer,0);
00120 str="0,0\n};\n/*";
00121 fwrite(str,sizeof(char),strlen(str),fp);
00122
00123 for (idx=0;idx<expressions;idx++)
00124 {
00125 *buffer='\0';
00126 cIdx=KAPI_EnumName(pknobs,idx,"expressions");
00127 iVal=KAPI_GetIntegerVariable(pknobs,"expr",idx);
00128 sprintf(buffer,"[%s] = %d\n",cIdx,iVal);
00129 fwrite(buffer,sizeof(char),strlen(buffer),fp);
00130 }
00131 _strset(buffer,0);
00132 str="*/\n\n";
00133 fwrite(str,sizeof(char),strlen(str),fp);
00134 KAPI_save_as_header_all_IA64_info( fp, pknobs , "trying123");
00135 printf("finished try\n");
00136 fclose(fp);
00137 fclose(fpTab);
00138
00139
00140 }
00141
00142
00143 int main( int argc, char *argv[] )
00144 {
00145 void *pvoid1;
00146 FILE *fp1=NULL,*fp2=NULL;
00147 FILE *outp=NULL;
00148 FILE *Ferr=NULL;
00149
00150 char *toolname;
00151
00152
00153
00154 if (( (toolname=strrchr(argv[ 0],'\\')) ==NULL) &&
00155 ( (toolname=strrchr(argv[ 0],'/')) ==NULL) )
00156 toolname=argv[ 0];
00157
00158
00159
00160
00161 if ( argc < 2 ) {
00162 printf("%s knobs toolname [delta knobs]\n", toolname );
00163 exit(1);
00164 }
00165
00166 if ( 5 <= argc )
00167 freopen(argv[4],"w",stderr);
00168 if ( 4 <= argc )
00169 fp2 = fopen( argv[ 3 ], "r" );
00170 fp1 = fopen( argv[ 1 ], "r" );
00171 outp = fopen( "try.c", "w" );
00172 if ((fp1==NULL) && (fp2==NULL))
00173 {
00174 printf("Could not open knobsfiles!\n");
00175 return 2;
00176 }
00177 pvoid1 = KAPI_Initialize( fp2, fp1, argv[ 2 ] );
00178 fclose( fp1 );
00179
00180 if (NULL!=fp2) fclose( fp2 );
00181 if ((5 <=argc ) && (NULL!=Ferr)) fclose( Ferr );
00182
00183 if ( pvoid1 ) {
00184 int fuLD;
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194 fuLD = KAPI_EnumIndex( pvoid1, "fu_t", "fuLD" );
00195 printf( "fuLD has %d ports\n",
00196 KAPI_cportCount4fu( pvoid1, 0, fuLD ) );
00197
00198 #if 0
00199 tmp = KAPI_intra;
00200 #endif
00201
00202 dump_instruction_fus(outp,pvoid1);
00203 KAPI_Finalize( pvoid1 );
00204 } else {
00205 fprintf( stderr, "KAPI_Initialize failed\n" );
00206 }
00207
00208 #if 0
00209 Test_bv128Rtns();
00210 Test_bv64Rtns();
00211 Test_bv32Rtns();
00212 #endif
00213
00214 return 0;
00215 }
00216
00217 static void
00218 Test_bv32Rtns()
00219 {
00220 }
00221
00222 static void
00223 Test_bv64Rtns()
00224 {
00225 bv64_t bv64Tmp, bv64Tmp2;
00226 char mpch[ 200 ];
00227 int i;
00228
00229
00230 for ( i=0; i<=64; i++ ) {
00231 ZERO_bv64( bv64Tmp );
00232 SETBIT_bv64( bv64Tmp, i );
00233 printf("Bit %2d = %s\n", i, bv642pch( bv64Tmp, mpch ) );
00234 }
00235
00236
00237 for ( i=0; i<=64; i++ ) {
00238 ZERO_bv64( bv64Tmp );
00239 ONES_bv64( bv64Tmp, 4 );
00240 SHL_bv64( bv64Tmp2, bv64Tmp, i );
00241 printf("Bit %2d = %s\n", i, bv642pch( bv64Tmp2, mpch ) );
00242 }
00243
00244
00245 for ( i=0; i<=64; i++ ) {
00246 ZERO_bv64( bv64Tmp );
00247 ONES_bv64( bv64Tmp, 20 );
00248 SHL_bv64( bv64Tmp2, bv64Tmp, i );
00249 printf("Bit %2d = %s\n", i, bv642pch( bv64Tmp2, mpch ) );
00250 }
00251
00252
00253 for ( i=0; i<=64; i++ ) {
00254 ZERO_bv64( bv64Tmp );
00255 ONES_bv64( bv64Tmp, 40 );
00256 SHL_bv64( bv64Tmp2, bv64Tmp, i );
00257 printf("Bit %2d = %s\n", i, bv642pch( bv64Tmp2, mpch ) );
00258 }
00259
00260
00261 for ( i=0; i<=64; i++ ) {
00262 ZERO_bv64( bv64Tmp );
00263 ONES_bv64( bv64Tmp, 4 );
00264 SHL_bv64( bv64Tmp2, bv64Tmp, 60 );
00265 SHRL_bv64( bv64Tmp, bv64Tmp2, i );
00266 printf("Bit %2d = %s\n", i, bv642pch( bv64Tmp, mpch ) );
00267 }
00268
00269
00270 for ( i=0; i<=64; i++ ) {
00271 ZERO_bv64( bv64Tmp );
00272 ONES_bv64( bv64Tmp, 20 );
00273 SHL_bv64( bv64Tmp2, bv64Tmp, 44 );
00274 SHRL_bv64( bv64Tmp, bv64Tmp2, i );
00275 printf("Bit %2d = %s\n", i, bv642pch( bv64Tmp, mpch ) );
00276 }
00277
00278
00279 for ( i=0; i<=64; i++ ) {
00280 ZERO_bv64( bv64Tmp );
00281 ONES_bv64( bv64Tmp, 40 );
00282 SHL_bv64( bv64Tmp2, bv64Tmp, 24 );
00283 SHRL_bv64( bv64Tmp, bv64Tmp2, i );
00284 printf("Bit %2d = %s\n", i, bv642pch( bv64Tmp, mpch ) );
00285 }
00286
00287
00288 ZERO_bv64( bv64Tmp );
00289 ONES_bv64( bv64Tmp, 8 );
00290 SHL_bv64( bv64Tmp2, bv64Tmp, 28 );
00291 printf("Initial string %s\n", bv642pch( bv64Tmp2, mpch ) );
00292 for ( i=0; i<=64; i++ ) {
00293 ZERO_bv64( bv64Tmp );
00294 ONES_bv64( bv64Tmp, 8 );
00295 SHL_bv64( bv64Tmp2, bv64Tmp, 28 );
00296 EXTRACTU_bv64( bv64Tmp, bv64Tmp2, 4, i );
00297 printf("Extract len=%d pos %2d = %s\n", 4, i, bv642pch( bv64Tmp, mpch ) );
00298 }
00299 }
00300
00301 static void
00302 Test_bv128Rtns()
00303 {
00304 }