Advertisement
Guest User

Untitled

a guest
Jun 25th, 2017
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 19.37 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3. #include <stdint.h>
  4. #include <assert.h>
  5. #include <time.h>
  6.  
  7. static uint8_t levels[64];
  8.  
  9. #define ZIG(i,y,x) levels[i] = x*8+y;
  10.  
  11. void init_levels()
  12. {
  13.     ZIG( 0,0,0) ZIG( 1,0,1) ZIG( 2,1,0) ZIG( 3,2,0)
  14.     ZIG( 4,1,1) ZIG( 5,0,2) ZIG( 6,0,3) ZIG( 7,1,2)
  15.     ZIG( 8,2,1) ZIG( 9,3,0) ZIG(10,4,0) ZIG(11,3,1)
  16.     ZIG(12,2,2) ZIG(13,1,3) ZIG(14,0,4) ZIG(15,0,5)
  17.     ZIG(16,1,4) ZIG(17,2,3) ZIG(18,3,2) ZIG(19,4,1)
  18.     ZIG(20,5,0) ZIG(21,6,0) ZIG(22,5,1) ZIG(23,4,2)
  19.     ZIG(24,3,3) ZIG(25,2,4) ZIG(26,1,5) ZIG(27,0,6)
  20.     ZIG(28,0,7) ZIG(29,1,6) ZIG(30,2,5) ZIG(31,3,4)
  21.     ZIG(32,4,3) ZIG(33,5,2) ZIG(34,6,1) ZIG(35,7,0)
  22.     ZIG(36,7,1) ZIG(37,6,2) ZIG(38,5,3) ZIG(39,4,4)
  23.     ZIG(40,3,5) ZIG(41,2,6) ZIG(42,1,7) ZIG(43,2,7)
  24.     ZIG(44,3,6) ZIG(45,4,5) ZIG(46,5,4) ZIG(47,6,3)
  25.     ZIG(48,7,2) ZIG(49,7,3) ZIG(50,6,4) ZIG(51,5,5)
  26.     ZIG(52,4,6) ZIG(53,3,7) ZIG(54,4,7) ZIG(55,5,6)
  27.     ZIG(56,6,5) ZIG(57,7,4) ZIG(58,7,5) ZIG(59,6,6)
  28.     ZIG(60,5,7) ZIG(61,6,7) ZIG(62,7,6) ZIG(63,7,7)
  29. }
  30.  
  31. #define NUMREGS 16
  32. #define MAX_INSTR 500
  33.  
  34. static uint8_t srcregisters[NUMREGS][8];
  35. static uint8_t resultregisters[8][8];
  36. static uint8_t registers[NUMREGS][8];
  37. static uint8_t counter[65];
  38.  
  39. enum instructions
  40. {
  41.     PUNPCKLWD   = 0,
  42.     PUNPCKHWD   = 1,
  43.     PUNCPKLDQ   = 2,
  44.     PUNPCKHDQ   = 3,
  45.     PUNPCKLQDQ  = 4,
  46.     PUNPCKHQDQ  = 5,
  47.     PSLLDQ      = 6,
  48.     PSRLDQ      = 7,
  49.     PSLLQ       = 8,
  50.     PSRLQ       = 9,
  51.     PSLLD       = 10,
  52.     PSRLD       = 11,
  53.     PSHUFLW     = 12,
  54.     PSHUFHW     = 13,
  55.     NUM_INSTR   = 14
  56. };
  57.  
  58. void print_instructions( uint8_t (*instructions)[4], int num_instructions )
  59. {
  60.     int i;
  61.     for( i = 0; i < num_instructions; i++ )
  62.     {
  63.         uint8_t *instr = instructions[i];
  64.         if( instr[0] != PSHUFLW && instr[0] != PSHUFHW && instr[1] != instr[3] ) printf("movdqa m%d, m%d\n", instr[3], instr[1] );
  65.         switch( instr[0] )
  66.         {
  67.             case PUNPCKLWD:
  68.                 printf( "punpcklwd" );
  69.                 break;
  70.             case PUNPCKHWD:
  71.                 printf( "punpckhwd" );
  72.                 break;
  73.             case PUNCPKLDQ:
  74.                 printf( "punpckldq" );
  75.                 break;
  76.             case PUNPCKHDQ:
  77.                 printf( "punpckhdq" );
  78.                 break;
  79.             case PUNPCKLQDQ:
  80.                 printf( "punpcklqdq" );
  81.                 break;
  82.             case PUNPCKHQDQ:
  83.                 printf( "punpckhqdq" );
  84.                 break;
  85.             case PSLLDQ:
  86.                 printf( "pslldq" );
  87.                 break;
  88.             case PSRLDQ:
  89.                 printf( "psrldq" );
  90.                 break;
  91.             case PSLLQ:
  92.                 printf( "psllq" );
  93.                 break;
  94.             case PSRLQ:
  95.                 printf( "psrlq" );
  96.                 break;
  97.             case PSLLD:
  98.                 printf( "pslld" );
  99.                 break;
  100.             case PSRLD:
  101.                 printf( "psrld" );
  102.                 break;
  103.             case PSHUFLW:
  104.                 printf( "pshuflw" );
  105.                 break;
  106.             case PSHUFHW:
  107.                 printf( "pshufhw" );
  108.                 break;
  109.             default:
  110.                 fprintf( stderr, "Error: unsupported instruction!\n");
  111.                 assert(0);
  112.         }
  113.         if(instr[0] < PSLLDQ ) printf(" m%d, m%d\n", instr[3], instr[2] );
  114.         else if(instr[0] < PSHUFLW )  printf(" m%d, %d\n", instr[3], instr[2]*(instr[0] < PSLLQ ? 2 : 16) );
  115.         else                    printf(" m%d, m%d, 0x%x\n", instr[3], instr[1], instr[2] );
  116.     }
  117. }
  118.  
  119. void execute_instruction( uint8_t *instr )
  120. {
  121.     uint8_t *input1 = registers[instr[1]];
  122.     uint8_t *input2 = registers[instr[2]];
  123.     uint8_t *output = registers[instr[3]];
  124.     uint8_t temp[8];
  125.     int i;
  126.     int imm = instr[2];
  127.  
  128.     switch( instr[0] )
  129.     {
  130.         case PUNPCKLWD:
  131.             temp[0] = input1[0];
  132.             temp[2] = input1[1];
  133.             temp[4] = input1[2];
  134.             temp[6] = input1[3];
  135.             temp[1] = input2[0];
  136.             temp[3] = input2[1];
  137.             temp[5] = input2[2];
  138.             temp[7] = input2[3];
  139.             break;
  140.         case PUNPCKHWD:
  141.             temp[0] = input1[4];
  142.             temp[2] = input1[5];
  143.             temp[4] = input1[6];
  144.             temp[6] = input1[7];
  145.             temp[1] = input2[4];
  146.             temp[3] = input2[5];
  147.             temp[5] = input2[6];
  148.             temp[7] = input2[7];
  149.             break;
  150.         case PUNCPKLDQ:
  151.             temp[0] = input1[0];
  152.             temp[1] = input1[1];
  153.             temp[4] = input1[2];
  154.             temp[5] = input1[3];
  155.             temp[2] = input2[0];
  156.             temp[3] = input2[1];
  157.             temp[6] = input2[2];
  158.             temp[7] = input2[3];
  159.             break;
  160.         case PUNPCKHDQ:
  161.             temp[0] = input1[4];
  162.             temp[1] = input1[5];
  163.             temp[4] = input1[6];
  164.             temp[5] = input1[7];
  165.             temp[2] = input2[4];
  166.             temp[3] = input2[5];
  167.             temp[6] = input2[6];
  168.             temp[7] = input2[7];
  169.             break;
  170.         case PUNPCKLQDQ:
  171.             temp[0] = input1[0];
  172.             temp[1] = input1[1];
  173.             temp[2] = input1[2];
  174.             temp[3] = input1[3];
  175.             temp[4] = input2[0];
  176.             temp[5] = input2[1];
  177.             temp[6] = input2[2];
  178.             temp[7] = input2[3];
  179.             break;
  180.         case PUNPCKHQDQ:
  181.             temp[0] = input1[4];
  182.             temp[1] = input1[5];
  183.             temp[2] = input1[6];
  184.             temp[3] = input1[7];
  185.             temp[4] = input2[4];
  186.             temp[5] = input2[5];
  187.             temp[6] = input2[6];
  188.             temp[7] = input2[7];
  189.             break;
  190.         case PSLLDQ:
  191.             for( i = 0; i < imm; i++ )
  192.                 temp[i] = input1[i+imm];
  193.             for( i = imm; i < 8; i++ )
  194.                 temp[i] = 64;
  195.             break;
  196.         case PSRLDQ:
  197.             for( i = 0; i < imm; i++ )
  198.                 temp[i] = 64;
  199.             for( i = imm; i < 8; i++ )
  200.                 temp[i] = input1[i-imm];
  201.             break;
  202.         case PSLLQ:
  203.             if( imm == 1 )
  204.             {
  205.                 temp[0] = input1[1];
  206.                 temp[1] = input1[2];
  207.                 temp[2] = input1[3];
  208.                 temp[3] = 64;
  209.                 temp[4] = input1[5];
  210.                 temp[5] = input1[6];
  211.                 temp[6] = input1[7];
  212.                 temp[7] = 64;
  213.             }
  214.             else if( imm == 2 )
  215.             {
  216.                 temp[0] = input1[2];
  217.                 temp[1] = input1[3];
  218.                 temp[2] = 64;
  219.                 temp[3] = 64;
  220.                 temp[4] = input1[6];
  221.                 temp[5] = input1[7];
  222.                 temp[6] = 64;
  223.                 temp[7] = 64;
  224.             }
  225.             else if( imm == 3 )
  226.             {
  227.                 temp[0] = input1[3];
  228.                 temp[1] = 64;
  229.                 temp[2] = 64;
  230.                 temp[3] = 64;
  231.                 temp[4] = input1[7];
  232.                 temp[5] = 64;
  233.                 temp[6] = 64;
  234.                 temp[7] = 64;
  235.             }
  236.             else
  237.                 assert(0);
  238.             break;
  239.         case PSRLQ:
  240.             if( imm == 1 )
  241.             {
  242.                 temp[0] = 64;
  243.                 temp[1] = input1[0];
  244.                 temp[2] = input1[1];
  245.                 temp[3] = input1[2];
  246.                 temp[4] = 64;
  247.                 temp[5] = input1[4];
  248.                 temp[6] = input1[5];
  249.                 temp[7] = input1[6];
  250.             }
  251.             else if( imm == 2 )
  252.             {
  253.                 temp[0] = 64;
  254.                 temp[1] = 64;
  255.                 temp[2] = input1[0];
  256.                 temp[3] = input1[1];
  257.                 temp[4] = 64;
  258.                 temp[5] = 64;
  259.                 temp[6] = input1[0];
  260.                 temp[7] = input1[1];
  261.             }
  262.             else if( imm == 3 )
  263.             {
  264.                 temp[0] = 64;
  265.                 temp[1] = 64;
  266.                 temp[2] = 64;
  267.                 temp[3] = input1[0];
  268.                 temp[4] = 64;
  269.                 temp[5] = 64;
  270.                 temp[6] = 64;
  271.                 temp[7] = input1[0];
  272.             }
  273.             else
  274.                 assert(0);
  275.             break;
  276.         case PSLLD:
  277.             assert( imm == 1 );
  278.             temp[0] = input1[1];
  279.             temp[1] = 64;
  280.             temp[2] = input1[3];
  281.             temp[3] = 64;
  282.             temp[4] = input1[5];
  283.             temp[5] = 64;
  284.             temp[6] = input1[7];
  285.             temp[7] = 64;
  286.             break;
  287.         case PSRLD:
  288.             assert( imm == 1 );
  289.             temp[0] = 64;
  290.             temp[1] = input1[0];
  291.             temp[2] = 64;
  292.             temp[3] = input1[2];
  293.             temp[4] = 64;
  294.             temp[5] = input2[4];
  295.             temp[6] = 64;
  296.             temp[7] = input2[6];
  297.             break;
  298.         case PSHUFLW:
  299.             temp[0] = input1[imm&0x3]; imm >>= 2;
  300.             temp[1] = input1[imm&0x3]; imm >>= 2;
  301.             temp[2] = input1[imm&0x3]; imm >>= 2;
  302.             temp[3] = input1[imm&0x3];
  303.             for( i = 4; i < 8; i++ )
  304.                 temp[i] = input1[i];
  305.             break;
  306.         case PSHUFHW:
  307.             temp[4] = input1[4+(imm&0x3)]; imm >>= 2;
  308.             temp[5] = input1[4+(imm&0x3)]; imm >>= 2;
  309.             temp[6] = input1[4+(imm&0x3)]; imm >>= 2;
  310.             temp[7] = input1[4+(imm&0x3)];
  311.             for( i = 0; i < 4; i++ )
  312.                 temp[i] = input1[i];
  313.             break;
  314.         default:
  315.             fprintf( stderr, "Error: unsupported instruction %d %d %d %d!\n", instr[0], instr[1], instr[2], instr[3]);
  316.             assert(0);
  317.     }
  318.     for( i = 0; i < 8; i++ )
  319.     {
  320.         counter[output[i]]--;
  321.         counter[temp[i]]++;
  322.     }
  323.     memcpy( output, temp, 8*sizeof(uint8_t) );
  324. }
  325.  
  326. void init_resultregisters()
  327. {
  328.     int r, i;
  329.     for(r=0;r<8;r++)
  330.         for(i=0;i<8;i++)
  331.             resultregisters[r][i] = levels[i+r*8];
  332. }
  333.  
  334. void init_srcregisters()
  335. {
  336.     int r, i;
  337.     for(r=0;r<8;r++)
  338.         for(i=0;i<8;i++)
  339.             srcregisters[r][i] = i+r*8;
  340.     for(r=8;r<NUMREGS;r++)
  341.         for(i=0;i<8;i++)
  342.             srcregisters[r][i] = 64;
  343. }
  344.  
  345. void init_registers()
  346. {
  347.     memcpy( registers, srcregisters, sizeof(srcregisters) );
  348. }
  349.  
  350. int run_program( uint8_t (*instructions)[4], int num_instructions, int debug )
  351. {
  352.     int i,r,j;
  353.     init_registers();
  354.     memset( counter, 1, sizeof( counter ) );
  355.     if( debug )
  356.     {
  357.         printf("targetregs: \n");
  358.         for(r=0;r<8;r++)
  359.         {
  360.             for(j=0;j<8;j++)
  361.                 printf("%d ",resultregisters[r][j]);
  362.             printf("\n");
  363.         }
  364.     }
  365.     for( i = 0; i < num_instructions; i++ )
  366.     {
  367.         if(debug)
  368.         {
  369.             printf("regs: \n");
  370.             for(r=0;r<NUMREGS;r++)
  371.             {
  372.                 for(j=0;j<8;j++)
  373.                     printf("%d ",registers[r][j]);
  374.                 printf("\n");
  375.             }
  376.         }
  377.         execute_instruction( instructions[i] );
  378.         //for( i = 0; i < 64; i++ )
  379.           //  if( !counter[i] ) return 0;
  380.     }
  381.     return 1;
  382. }
  383.  
  384. //#define CHECK_LOC if( i >= 2 && i <= 5 ) continue;
  385. #define CHECK_LOC if( 0 ) continue;
  386.  
  387. int result_cost( int *correct )
  388. {
  389.     //static const int errorcosts[9] = { 0, 7, 14, 21, 27, 32, 36, 39, 40 };
  390.     static const int errorcosts[9] = { 0, 80, 110, 121, 127, 132, 136, 139, 140 };
  391.     static const int weight[8] = { 2, 3, 4, 5, 5, 4, 3, 2 };
  392.     int sumerror = 0;
  393.     int ssderror = 0;
  394.     int i,j;
  395.     for( i = 0; i < 8; i++ )
  396.     {
  397.         CHECK_LOC
  398.         int regerror = 0;
  399.         for( j = 0; j < 8; j++ )
  400.             regerror += registers[i][j] != resultregisters[i][j];
  401.         sumerror += regerror;
  402.         //ssderror += regerror*regerror;
  403.         ssderror += errorcosts[regerror] * weight[i];
  404.     }
  405.     *correct = 64 - sumerror;
  406.     return ssderror;
  407. }
  408.  
  409. void result_cost_breakdown()
  410. {
  411.     int sumerror = 0;
  412.     int i,j;
  413.     printf("Regerror breakdown: ");
  414.     for( i = 0; i < 8; i++ )
  415.     {
  416.         CHECK_LOC
  417.         int regerror = 0;
  418.         for( j = 0; j < 8; j++ )
  419.             regerror += registers[i][j] != resultregisters[i][j];
  420.         printf("%d ",regerror);
  421.     }
  422.     printf("\n");
  423. }
  424.  
  425. void instruction_delete( uint8_t (*instructions)[4], int loc, int numinstructions )
  426. {
  427.     int i;
  428.     for( i = loc; i < numinstructions-1; i++ )
  429.     {
  430.         instructions[i][0] = instructions[i+1][0];
  431.         instructions[i][1] = instructions[i+1][1];
  432.         instructions[i][2] = instructions[i+1][2];
  433.         instructions[i][3] = instructions[i+1][3];
  434.     }
  435. }
  436.  
  437. void instruction_shift( uint8_t (*instructions)[4], int loc, int numinstructions )
  438. {
  439.     int i;
  440.     for( i = numinstructions; i > loc; i-- )
  441.     {
  442.         instructions[i][0] = instructions[i-1][0];
  443.         instructions[i][1] = instructions[i-1][1];
  444.         instructions[i][2] = instructions[i-1][2];
  445.         instructions[i][3] = instructions[i-1][3];
  446.     }
  447. }
  448.  
  449. #define MAXCHANGES 16
  450.  
  451. int generate_algorithm( uint8_t (*instructions)[4], uint8_t (*srcinstructions)[4], int numinstructions )
  452. {
  453.     static const int allowedshuf[24] = { (0<<6)+(1<<4)+(2<<2)+(3<<0),
  454.                                          (0<<6)+(1<<4)+(3<<2)+(2<<0),
  455.                                          (0<<6)+(2<<4)+(3<<2)+(1<<0),
  456.                                          (0<<6)+(2<<4)+(1<<2)+(3<<0),
  457.                                          (0<<6)+(3<<4)+(2<<2)+(1<<0),
  458.                                          (0<<6)+(3<<4)+(1<<2)+(2<<0),
  459.  
  460.                                          (1<<6)+(0<<4)+(2<<2)+(3<<0),
  461.                                          (1<<6)+(0<<4)+(3<<2)+(2<<0),
  462.                                          (1<<6)+(2<<4)+(3<<2)+(0<<0),
  463.                                          (1<<6)+(2<<4)+(0<<2)+(3<<0),
  464.                                          (1<<6)+(3<<4)+(2<<2)+(0<<0),
  465.                                          (1<<6)+(3<<4)+(0<<2)+(2<<0),
  466.                                          
  467.                                          (2<<6)+(1<<4)+(0<<2)+(3<<0),
  468.                                          (2<<6)+(1<<4)+(3<<2)+(0<<0),
  469.                                          (2<<6)+(0<<4)+(3<<2)+(1<<0),
  470.                                          (2<<6)+(0<<4)+(1<<2)+(3<<0),
  471.                                          (2<<6)+(3<<4)+(0<<2)+(1<<0),
  472.                                          (2<<6)+(3<<4)+(1<<2)+(0<<0),
  473.  
  474.                                          (3<<6)+(1<<4)+(2<<2)+(0<<0),
  475.                                          (3<<6)+(1<<4)+(0<<2)+(2<<0),
  476.                                          (3<<6)+(2<<4)+(0<<2)+(1<<0),
  477.                                          (3<<6)+(2<<4)+(1<<2)+(0<<0),
  478.                                          (3<<6)+(0<<4)+(2<<2)+(1<<0),
  479.                                          (3<<6)+(0<<4)+(1<<2)+(2<<0)};
  480.     memcpy( instructions, srcinstructions, numinstructions * sizeof(uint8_t) * 4 );
  481.     int numchanges = rand() % MAXCHANGES;
  482.     int i;
  483.     for( i = 0; i < numchanges; i++ )
  484.     {
  485.         int change = rand() % 4;
  486.         int instr = rand() % NUM_INSTR;
  487.         int input1 = rand() % NUMREGS;
  488.         int input2;
  489.         if( instr < PSLLDQ )
  490.             input2 = rand() % NUMREGS;
  491.         else if( instr < PSLLQ )
  492.             input2 = (rand() % 7) + 1;
  493.         else if( instr < PSLLD )
  494.             input2 = (rand() % 3) + 1;
  495.         else if( instr < PSHUFLW )
  496.             input2 = 1;
  497.         else
  498.             input2 = allowedshuf[rand() % 24];
  499.        
  500.         int output = rand() % NUMREGS;
  501.         int loc = rand() & 1 ? rand() % (numinstructions+1) : numinstructions;
  502.         if(loc == numinstructions) change=1;
  503.         switch( change )
  504.         {
  505.             case 0: //delete instruction
  506.             if( numinstructions == 0 ) continue;
  507.             instruction_delete( instructions, loc, numinstructions );
  508.             numinstructions--;
  509.             break;
  510.             case 1:
  511.             case 2: //add instruction
  512.             if( numinstructions == MAX_INSTR ) continue;
  513.             instruction_shift( instructions, loc, numinstructions );
  514.             numinstructions++;
  515.             instructions[loc][0] = instr;
  516.             instructions[loc][1] = input1;
  517.             instructions[loc][2] = input2;
  518.             instructions[loc][3] = output;
  519.             break;
  520.             case 3: //change instruction
  521.             instructions[loc][0] = instr;
  522.             instructions[loc][1] = input1;
  523.             instructions[loc][2] = input2;
  524.             instructions[loc][3] = output;
  525.             break;
  526.         }
  527.     }
  528. }
  529.  
  530. int instruction_cost( uint8_t (*instructions)[4], int numinstructions )
  531. {
  532.     int i;
  533.     int cost = 0;
  534.     for( i = 0; i < numinstructions; i++ )
  535.     {
  536.         cost++;
  537.         if( instructions[i][0] != PSHUFLW && instructions[i][0] != PSHUFHW && instructions[i][1] != instructions[i][3] ) cost++;
  538.     }
  539.     return cost;
  540. }
  541.  
  542. #define TRIES 1000000
  543. #define ITERATIONS 1000000
  544. #define WEIGHT 20
  545. #define STARTTEMP 100
  546.  
  547. int main()
  548. {
  549.     static uint8_t instructions[MAX_INSTR][4];
  550.     static uint8_t binstructions[MAX_INSTR][4] = {0};
  551.     int num_instructions = 0;
  552.     int num_binstructions = 0;
  553.     int bcost = 1<<30;
  554.     int binstruction_cost = 0;
  555.     int bcorrect = 0;
  556.     init_levels();
  557.     init_srcregisters();
  558.     init_resultregisters();
  559.     int t, i;
  560.    
  561.     int ltime;
  562.     int temperature = STARTTEMP;
  563.     int gototemp = STARTTEMP;
  564.  
  565.     /* get the current calendar time */
  566.     ltime = time(NULL);
  567.     srand(ltime);
  568.     int iterations_since_change = 0;
  569.     int oldbestbcost = 1<<30;
  570.     int bestbcost = 1<<30;
  571.     for( i = 0; i < ITERATIONS; i++ )
  572.     {
  573.         int prevcost = bcost;
  574.         for( t = 0; t < TRIES; t++ )
  575.         {
  576.             num_instructions = generate_algorithm( instructions, binstructions, num_binstructions );
  577.             int success = run_program( instructions, num_instructions, 0 );
  578.             if( !success ) continue;
  579.             int correct;
  580.             int output_cost = result_cost( &correct );
  581.             //if( output_cost > bcost ) continue;
  582.             int icost = instruction_cost( instructions, num_instructions );
  583.             int cost = output_cost * WEIGHT + icost;
  584.             int weight = temperature ? rand() % temperature : 0;
  585.             if( cost < bcost + weight )
  586.             {
  587.                 bcost = cost;
  588.                 bcorrect = correct;
  589.                 binstruction_cost = icost;
  590.                 memcpy( binstructions, instructions, num_instructions * sizeof(uint8_t) * 4 );
  591.                 num_binstructions = num_instructions;
  592.                 if( cost < bestbcost ) bestbcost = cost;
  593.             }
  594.         }
  595.         printf("Correct Outputs: %d, Instructions: %d\n",bcorrect,binstruction_cost);
  596.         printf("Temperature: %d Iterations Since Change: %d Gototemp: %d\n",temperature,iterations_since_change, gototemp);
  597.         run_program( binstructions, num_binstructions, 0 );
  598.         result_cost_breakdown();
  599.         print_instructions( binstructions, num_binstructions );
  600.         if( temperature ) temperature--;
  601.         if( !temperature && prevcost == bcost ) iterations_since_change++;
  602.         else iterations_since_change = 0;
  603.         if( iterations_since_change == 100 )
  604.         {
  605.             temperature = gototemp;
  606.             if( bestbcost == oldbestbcost ) gototemp += 100;
  607.             else if( gototemp > 100 ) gototemp -= 100;
  608.             oldbestbcost = bestbcost;
  609.         }
  610.     }
  611.     return 0;
  612. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement