⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.c

📁 nios中自定义指令集实现三角函数的软件部分。
💻 C
📖 第 1 页 / 共 5 页
字号:
        }
        else
        {
          *(my_long_ptr_to_float_operand_a) = my_single_specials_array[j] & 0xFF800000;
        }
        
        if(my_single_specials_array[i] & 0x7f800000)
        {
          *(my_long_ptr_to_float_operand_b) = my_single_specials_array[i];
        }
        else
        {
          *(my_long_ptr_to_float_operand_b) = my_single_specials_array[i] & 0xFF800000;
        }

        float_result = float_operand_a * float_operand_b;
        calc_result_array[i] = *(my_long_ptr_to_float_result);
        
        *(my_long_ptr_to_float_operand_a) = my_single_specials_array[j];
        *(my_long_ptr_to_float_operand_b) = my_single_specials_array[i];

        float_result = spfp_hw_multiplication(float_operand_a, float_operand_b);
        
        cusp_result_array[i] = *(my_long_ptr_to_float_result);

        if((cusp_result_array[i] == calc_result_array[i]))
        {
        }
        else if(
                ((cusp_result_array[i] & 0x7F800000) == 0x7F800000) &&
                ((calc_result_array[i] & 0x7F800000) == 0x7F800000) &&
                ((cusp_result_array[i] & 0x007FFFFF) != 0x0) &&
                ((calc_result_array[i] & 0x007FFFFF) != 0x0)
               )
        {
          if(((cusp_result_array[i] & 0x80000000) == (calc_result_array[i] & 0x80000000)))
          {
            printf("Different NAN signs PASSED...");
          }
          else
          {
              printf("Different NAN results PASSED...  ");
          }
          printf("\n");
        }
        else
        {
          printf("%d - 0x%08lX  -  %08lX I\n", i, cusp_result_array[i], calc_result_array[i]);
          printf("operation is % .20E * % .20E\n", float_operand_a, float_operand_b);
          printf("operation is 0x%08lX * 0x%08lX\n", *(my_long_ptr_to_float_operand_a), *(my_long_ptr_to_float_operand_b));
          printf("float_result = % .20E\n", float_result);
          printf("float_result = 0x%08lX\n\n", *(my_long_ptr_to_float_result));
        }
      }
    }
#endif //MUL_TEST
#ifdef DIV_TEST
    // Division
    printf("\nSingle Precision Division...\n");
    
    for(j = 0 ; j < SINGLE_SPECIALS_ARRAY_SIZE_IN_FLOATS ; j++)
    {
      printf("\n----------------------- %d\n\n", j);
      for(i = 0 ; i < SINGLE_SPECIALS_ARRAY_SIZE_IN_FLOATS ; i++)
      {
        if(my_single_specials_array[j] & 0x7f800000)
        {
          *(my_long_ptr_to_float_operand_a) = my_single_specials_array[j];
        }
        else
        {
          *(my_long_ptr_to_float_operand_a) = my_single_specials_array[j] & 0xFF800000;
        }
        
        if(my_single_specials_array[i] & 0x7f800000)
        {
          *(my_long_ptr_to_float_operand_b) = my_single_specials_array[i];
        }
        else
        {
          *(my_long_ptr_to_float_operand_b) = my_single_specials_array[i] & 0xFF800000;
        }

        float_result = float_operand_a / float_operand_b;
        calc_result_array[i] = *(my_long_ptr_to_float_result);
        
        *(my_long_ptr_to_float_operand_a) = my_single_specials_array[j];
        *(my_long_ptr_to_float_operand_b) = my_single_specials_array[i];

        float_result = spfp_hw_division(float_operand_a, float_operand_b);
        
        cusp_result_array[i] = *(my_long_ptr_to_float_result);

        if((cusp_result_array[i] == calc_result_array[i]))
        {
        }
        else if(
                ((cusp_result_array[i] & 0x7F800000) == 0x7F800000) &&
                ((calc_result_array[i] & 0x7F800000) == 0x7F800000) &&
                ((cusp_result_array[i] & 0x007FFFFF) != 0x0) &&
                ((calc_result_array[i] & 0x007FFFFF) != 0x0)
               )
        {
          if(((cusp_result_array[i] & 0x80000000) == (calc_result_array[i] & 0x80000000)))
          {
            printf("Different NAN signs PASSED...");
          }
          else
          {
              printf("Different NAN results PASSED...  ");
          }
          printf("\n");
        }
        else
        {
          printf("%d - 0x%08lX  -  %08lX I\n", i, cusp_result_array[i], calc_result_array[i]);
          printf("operation is % .20E / % .20E\n", float_operand_a, float_operand_b);
          printf("operation is 0x%08lX / 0x%08lX\n", *(my_long_ptr_to_float_operand_a), *(my_long_ptr_to_float_operand_b));
          printf("float_result = % .20E\n", float_result);
          printf("float_result = 0x%08lX\n\n", *(my_long_ptr_to_float_result));
        }
      }
    }
#endif //DIV_TEST
#endif //SPECIAL_NUMBERS_TEST
#endif //SINGLE_TESTS

#ifdef DOUBLE_TESTS
#ifdef EXPONENT_SWEEP_TEST
// exponent sweep tests
#ifdef ADD_TEST
    // addition
    mantissa_a_lo = 0;
    mantissa_a_hi = 0;
    exponent_a = 0;
    sign_a = 0;
    
    mantissa_b_lo = 0;
    mantissa_b_hi = 0;
    exponent_b = 0;
    sign_b = 0;
    
    count_correct = 0;
    count_incorrect = 0;
    denormal_result = 0;
    round_off_by_one = 0;

    printf("\nDouble Precision Exponent Sweep Addition Test...\n\n");
    
    for( i = 1 ; i < 0x7FF ; i++)
    {
      exponent_a = i;
      
      for( j = 1 ; j < 0x7FF ; j++)
      {
        exponent_b = j;
        
        *(my_long_ptr_to_double_operand_a) = mantissa_a_lo;
        *(my_long_ptr_to_double_operand_a + 1) = (mantissa_a_hi & 0x000FFFFF)|((exponent_a & 0x7FF)<<20)|(sign_a<<31);
        *(my_long_ptr_to_double_operand_b) = mantissa_b_lo;
        *(my_long_ptr_to_double_operand_b + 1) = (mantissa_b_hi & 0x000FFFFF)|((exponent_b & 0x7FF)<<20)|(sign_b<<31);
        
        double_result = double_operand_a + double_operand_b;
  
        calc_result_lo = *(my_long_ptr_to_double_result);
        calc_result_hi = *(my_long_ptr_to_double_result + 1);
        
        double_result = dpfp_hw_addition(double_operand_a, double_operand_b);
        
        cusp_result_lo = *(my_long_ptr_to_double_result);
        cusp_result_hi = *(my_long_ptr_to_double_result + 1);
    
        if((cusp_result_lo == calc_result_lo) && (cusp_result_hi == calc_result_hi))
        {
          //printf("j=%d i=%d - 0x%08lX %08lX - 0x%08lX %08lX C\n", j, i, cusp_result_array[(i*2) + 1], cusp_result_array[(i*2)], calc_result_array[(i*2) + 1], calc_result_array[(i*2)]);
          count_correct++;
        }
        else
        {
          if(((cusp_result_hi & 0xFFF00000) == (calc_result_hi & 0xFFF00000)) && ((cusp_result_hi & 0x7FF00000) == 0x0))
          {
            //printf("denormal j=%d i=%d - 0x%08lX %08lX - 0x%08lX %08lX I\n", j, i, cusp_result_array[(i*2) + 1], cusp_result_array[(i*2)], calc_result_array[(i*2) + 1], calc_result_array[(i*2)]);
            denormal_result++;
            count_correct++;
          }
          else if((((cusp_result_lo - calc_result_lo) == 1) || ((calc_result_lo - cusp_result_lo) == 1)) && (cusp_result_hi == calc_result_hi))
          {
            //printf("lsb only j=%d i=%d - 0x%08lX %08lX - 0x%08lX %08lX I\n", j, i, cusp_result_array[(i*2) + 1], cusp_result_array[(i*2)], calc_result_array[(i*2) + 1], calc_result_array[(i*2)]);
            round_off_by_one++;
            count_correct++;
          }
          else
          {
            printf("swp_a=%d swp_b=%d ex_a=%ld ex_b=%ld - 0x%08lX %08lX - 0x%08lX %08lX I\n", i, j, exponent_a, exponent_b, cusp_result_hi, cusp_result_lo, calc_result_hi, calc_result_lo);
            count_incorrect++;
          }
        }
      }
    }

    printf("Correct = %d\n", count_correct);
    printf("Incorrect = %d\n", count_incorrect);
    printf("Denormal Result = %d\n", denormal_result);
    printf("Round off by one = %d\n", round_off_by_one);
#endif //ADD_TEST
#ifdef SUB_TEST
    // Subtraction
    mantissa_a_lo = 0;
    mantissa_a_hi = 0;
    exponent_a = 0;
    sign_a = 0;
    
    mantissa_b_lo = 0;
    mantissa_b_hi = 0;
    exponent_b = 0;
    sign_b = 0;
    
    count_correct = 0;
    count_incorrect = 0;
    denormal_result = 0;
    round_off_by_one = 0;

    printf("\nDouble Precision Exponent Sweep Subtraction Test...\n\n");
    
    for( i = 1 ; i < 0x7FF ; i++)
    {
      exponent_a = i;
      
      for( j = 1 ; j < 0x7FF ; j++)
      {
        exponent_b = j;
        
        *(my_long_ptr_to_double_operand_a) = mantissa_a_lo;
        *(my_long_ptr_to_double_operand_a + 1) = (mantissa_a_hi & 0x000FFFFF)|((exponent_a & 0x7FF)<<20)|(sign_a<<31);
        *(my_long_ptr_to_double_operand_b) = mantissa_b_lo;
        *(my_long_ptr_to_double_operand_b + 1) = (mantissa_b_hi & 0x000FFFFF)|((exponent_b & 0x7FF)<<20)|(sign_b<<31);
        
        double_result = double_operand_a - double_operand_b;
  
        calc_result_lo = *(my_long_ptr_to_double_result);
        calc_result_hi = *(my_long_ptr_to_double_result + 1);
        
        double_result = dpfp_hw_subtraction(double_operand_a, double_operand_b);
        
        cusp_result_lo = *(my_long_ptr_to_double_result);
        cusp_result_hi = *(my_long_ptr_to_double_result + 1);
    
        if((cusp_result_lo == calc_result_lo) && (cusp_result_hi == calc_result_hi))
        {
          //printf("j=%d i=%d - 0x%08lX %08lX - 0x%08lX %08lX C\n", j, i, cusp_result_array[(i*2) + 1], cusp_result_array[(i*2)], calc_result_array[(i*2) + 1], calc_result_array[(i*2)]);
          count_correct++;
        }
        else
        {
          if(((cusp_result_hi & 0xFFF00000) == (calc_result_hi & 0xFFF00000)) && ((cusp_result_hi & 0x7FF00000) == 0x0))
          {
            //printf("denormal j=%d i=%d - 0x%08lX %08lX - 0x%08lX %08lX I\n", j, i, cusp_result_array[(i*2) + 1], cusp_result_array[(i*2)], calc_result_array[(i*2) + 1], calc_result_array[(i*2)]);
            denormal_result++;
            count_correct++;
          }
          else if((((cusp_result_lo - calc_result_lo) == 1) || ((calc_result_lo - cusp_result_lo) == 1)) && (cusp_result_hi == calc_result_hi))
          {
            //printf("lsb only j=%d i=%d - 0x%08lX %08lX - 0x%08lX %08lX I\n", j, i, cusp_result_array[(i*2) + 1], cusp_result_array[(i*2)], calc_result_array[(i*2) + 1], calc_result_array[(i*2)]);
            round_off_by_one++;
            count_correct++;
          }
          else
          {
            printf("swp_a=%d swp_b=%d ex_a=%ld ex_b=%ld - 0x%08lX %08lX - 0x%08lX %08lX I\n", i, j, exponent_a, exponent_b, cusp_result_hi, cusp_result_lo, calc_result_hi, calc_result_lo);
            count_incorrect++;
          }
        }
      }
    }

    printf("Correct = %d\n", count_correct);
    printf("Incorrect = %d\n", count_incorrect);
    printf("Denormal Result = %d\n", denormal_result);
    printf("Round off by one = %d\n", round_off_by_one);
#endif //SUB_TEST
#ifdef MUL_TEST
    // Multiplication
    mantissa_a_lo = 0;
    mantissa_a_hi = 0;
    exponent_a = 0;
    sign_a = 0;
    
    mantissa_b_lo = 0;
    mantissa_b_hi = 0;
    exponent_b = 0;
    sign_b = 0;
    
    count_correct = 0;
    count_incorrect = 0;
    denormal_result = 0;
    round_off_by_one = 0;

    printf("\nDouble Precision Exponent Sweep Multiplication Test...\n\n");
    
    for( i = 1 ; i < 0x7FF ; i++)
    {
      exponent_a = i;
      
      for( j = 1 ; j < 0x7FF ; j++)
      {
        exponent_b = j;
                
        *(my_long_ptr_to_double_operand_a) = mantissa_a_lo;
        *(my_long_ptr_to_double_operand_a + 1) = (mantissa_a_hi & 0x000FFFFF)|((exponent_a & 0x7FF)<<20)|(sign_a<<31);
        *(my_long_ptr_to_double_operand_b) = mantissa_b_lo;
        *(my_long_ptr_to_double_operand_b + 1) = (mantissa_b_hi & 0x000FFFFF)|((exponent_b & 0x7FF)<<20)|(sign_b<<31);
        
        double_result = double_operand_a * double_operand_b;
  
        calc_result_lo = *(my_long_ptr_to_double_result);
        calc_result_hi = *(my_long_ptr_to_double_result + 1);
        
        double_result = dpfp_hw_multiplication(double_operand_a, double_operand_b);
        
        cusp_result_lo = *(my_long_ptr_to_double_result);
        cusp_result_hi = *(my_long_ptr_to_double_result + 1);
    
        if((cusp_result_lo == calc_result_lo) && (cusp_result_hi == calc_result_hi))

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -