Advertisement
Guest User

Untitled

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