Beispiel #1
0
/** 
 * clay_util_statement_insert_inequation function:
 * Insert a new inequation at the end of the scattering
 * The list must have less or equal than 3 arrays
 * Warning: here the output dims are complete
 *          example: if the output dims are : 0 i 0 j 0, you have
 *                   to give all these numbers
 * \param[in,out] statement
 * \param[in] inequ              {(([output, ...],) [param, ..],) [const]}
 */
void clay_util_statement_set_inequation(
                        osl_statement_p statement,
                        clay_list_p inequ) {
  
  osl_relation_p scattering = statement->scattering;
  clay_array_p arr_dims = NULL, arr_params = NULL, arr_const = NULL;
  int row = scattering->nb_rows;
  int i, j;
  int precision = scattering->precision;
  
  // insert the inequation spliting (local dims are not in the inequation)
  // (at the end)
  osl_relation_insert_blank_row(scattering, row);
  osl_int_set_si(precision, &scattering->m[row][0], 1); // type inequation

  if (inequ->size > 3) {
    CLAY_error("list with more than 3 arrays not supported");
  } else if (inequ->size == 3) {
    arr_dims   = inequ->data[0];
    arr_params = inequ->data[1];
    arr_const  = inequ->data[2];
  } else if (inequ->size == 2) {
    arr_params = inequ->data[0];
    arr_const  = inequ->data[1];
  } else {
    arr_const  = inequ->data[0];
  }

  // affects output dims
  if (inequ->size == 3) {
    i = 1;
    for (j = 0 ; j < arr_dims->size ; j++) {
      osl_int_set_si(precision,
                     &scattering->m[row][i],
                     arr_dims->data[j]);
      i++;
    }
  }

  // affects parameters
  if (inequ->size >= 2) {
    i = 1 + scattering->nb_output_dims + scattering->nb_input_dims + 
        scattering->nb_local_dims;
    for (j = 0; j < arr_params->size ; j++) {
      osl_int_set_si(precision,
                     &scattering->m[row][i],
                     arr_params->data[j]);
      i++;
    }
  }

  // set the constant
  if (inequ->size >= 1 && arr_const->size == 1) {
    osl_int_set_si(precision,
                   &scattering->m[row][scattering->nb_columns-1],
                   arr_const->data[0]);
  }
}
Beispiel #2
0
// aware of beta structure
osl_int_t clay_relation_line_gcd(osl_relation_p relation, int line, int column_start, int column_end) {
  osl_int_t gcd, tmp;
  int i;
  int gcd_assigned = 0;

  osl_int_init(relation->precision, &gcd);
  osl_int_init(relation->precision, &tmp);

  if (column_end - column_start < 1 ||
      column_start >= relation->nb_columns ||
      column_end > relation->nb_columns) {
    osl_int_set_si(relation->precision, &gcd, 0);
    return gcd;
  } else if (column_end - column_start == 1) {
    osl_int_assign(relation->precision, &gcd, relation->m[line][column_start]);
    return gcd;
  }

  for (i = column_start; i < column_end; i++) {
    if (i >= 1 && i < relation->nb_output_dims + 1 && (i % 2) == 1) {
      continue; // ignore betas
    }
    if (osl_int_zero(relation->precision, relation->m[line][i])) {
      continue; // ignore zeros
    }
    osl_int_abs(relation->precision, &tmp, relation->m[line][i]);

    if (!gcd_assigned) {
      osl_int_assign(relation->precision, &gcd, tmp);
      gcd_assigned = 1;
    } else {
      osl_int_gcd(relation->precision, &gcd, gcd, tmp);
    }
  }

  if (!gcd_assigned) { // if gcd zero or not found, default to 1.
    osl_int_set_si(relation->precision, &gcd, 1);
  }

  osl_int_clear(relation->precision, &tmp);
  return gcd;
}
Beispiel #3
0
/**
 * clay_util_statement_insert function:
 * Insert `newstatement' before `statement', and set his beta value
 * \param[in,out] statement
 * \param[in,out] newstatement
 * \param[in] column             column on the output dim (where we want to split)
 *                               this is a `alpha column' of the 2*d+1
 * \param[in] order              new beta value
 * \return                       return statement->next (so newtstatement)
 */
osl_statement_p clay_util_statement_insert(osl_statement_p statement,
                                           osl_statement_p newstatement,
                                           int column,
                                           int order) {
  osl_relation_p scattering = statement->scattering;

  // the current statement is after the new statement
  int row = clay_util_relation_get_line(scattering, column);
  osl_int_set_si(scattering->precision,
                 &scattering->m[row][scattering->nb_columns-1],
                 order);

  // the order is not important in the statements list
  newstatement->next = statement->next;
  statement->next = newstatement;
  statement = statement->next;

  return statement;
}
Beispiel #4
0
// assumes beta-structure; depth 1-based
// TODO: do not return, possible leak
osl_int_t clay_relation_gcd(osl_relation_p relation, int depth) {
  osl_int_t gcd;
  int row, col;
  int gcd_assigned = 0;
  int column = 2*depth;

  osl_int_init(relation->precision, &gcd);
  if (depth < -1 || depth == 0 || depth > relation->nb_output_dims / 2) {
  CLAY_debug("Called clay_relation_gcd with column outside bounds");
    osl_int_set_si(relation->precision, &gcd, 0);
    return gcd;
  }

  for (row = 0; row < relation->nb_rows; row++) {
    if (depth != -1 && osl_int_zero(relation->precision, relation->m[row][column])) {
      continue;
    }

    for (col = 2; col < relation->nb_columns; col++) {
      // if beta, ignore
      if (col >= 1 && col < relation->nb_output_dims + 1 && (col % 2) == 1) {
        continue;
      }
      if (col == column) {
        continue;
      }
      if (gcd_assigned) {
        osl_int_gcd(relation->precision, &gcd, gcd, relation->m[row][col]);
      } else {
        if (!osl_int_zero(relation->precision, relation->m[row][col])) {
          osl_int_assign(relation->precision, &gcd, relation->m[row][col]);
          gcd_assigned = 1;
        }
      }
    }
  }
  return gcd;
}
Beispiel #5
0
int main(int argc, char** argv)
{
  if (argc > 1) { printf("argv are ignored\n"); }
  
  unsigned int nb_fail = 0;
  
  #ifdef OSL_GMP_IS_HERE
  
  int i;
  for (i = SCHAR_MIN; i <= SCHAR_MAX; ++i) {
    osl_int_t a_sp; osl_int_init_set_si(OSL_PRECISION_SP, &a_sp, i);
    osl_int_t a_dp; osl_int_init_set_si(OSL_PRECISION_DP, &a_dp, i);
    osl_int_t a_mp; osl_int_init_set_si(OSL_PRECISION_MP, &a_mp, i);
    
    int j;
    for (j = SCHAR_MIN; j <= SCHAR_MAX; ++j) {
      int error = 0;
      
      osl_int_t b_sp; osl_int_init_set_si(OSL_PRECISION_SP, &b_sp, j);
      osl_int_t b_dp; osl_int_init_set_si(OSL_PRECISION_DP, &b_dp, j);
      osl_int_t b_mp; osl_int_init_set_si(OSL_PRECISION_MP, &b_mp, j);
      
      osl_int_t c_sp; osl_int_init(OSL_PRECISION_SP, &c_sp);
      osl_int_t c_dp; osl_int_init(OSL_PRECISION_DP, &c_dp);
      osl_int_t c_mp; osl_int_init(OSL_PRECISION_MP, &c_mp);
      
      int const a_sp_i = osl_int_get_si(OSL_PRECISION_SP, a_sp);
      int const a_dp_i = osl_int_get_si(OSL_PRECISION_DP, a_dp);
      int const a_mp_i = osl_int_get_si(OSL_PRECISION_MP, a_mp);
      
      int const b_sp_i = osl_int_get_si(OSL_PRECISION_SP, b_sp);
      int const b_dp_i = osl_int_get_si(OSL_PRECISION_DP, b_dp);
      int const b_mp_i = osl_int_get_si(OSL_PRECISION_MP, b_mp);
      
      // osl_int_init_set_si & osl_int_init & osl_int_get_si
      if (!error) {
        int c_sp_i = osl_int_get_si(OSL_PRECISION_SP, c_sp);
        int c_dp_i = osl_int_get_si(OSL_PRECISION_DP, c_dp);
        int c_mp_i = osl_int_get_si(OSL_PRECISION_MP, c_mp);
      
        if (a_sp_i != a_dp_i || a_sp_i != a_mp_i) {
          error++; printf("Error osl_int_init_set_si or osl_int_get_si\n");
        }
        if (b_sp_i != b_dp_i || b_sp_i != b_mp_i) {
          error++; printf("Error osl_int_init_set_si or osl_int_get_si\n");
        }
        if (c_sp_i != c_dp_i || c_sp_i != c_mp_i || c_sp_i != 0) {
          error++; printf("Error osl_int_init or osl_int_get_si\n");
        }
      }
      
      // osl_int_assign
      if (!error) {
        osl_int_assign(OSL_PRECISION_SP, &c_sp, b_sp);
        osl_int_assign(OSL_PRECISION_DP, &c_dp, b_dp);
        osl_int_assign(OSL_PRECISION_MP, &c_mp, b_mp);
        
        if (osl_int_ne(OSL_PRECISION_SP, c_sp, b_sp)) {
          error++; printf("Error osl_int_assign\n");
        }
        if (osl_int_ne(OSL_PRECISION_DP, c_dp, b_dp)) {
          error++; printf("Error osl_int_assign\n");
        }
        if (osl_int_ne(OSL_PRECISION_MP, c_mp, b_mp)) {
          error++; printf("Error osl_int_assign\n");
        }
      }
      
      // osl_int_swap
      
      // osl_int_increment
      if (!error) {
        osl_int_increment(OSL_PRECISION_SP, &c_sp, a_sp);
        osl_int_increment(OSL_PRECISION_DP, &c_dp, a_dp);
        osl_int_increment(OSL_PRECISION_MP, &c_mp, a_mp);
        
        int c_sp_i = osl_int_get_si(OSL_PRECISION_SP, c_sp);
        int c_dp_i = osl_int_get_si(OSL_PRECISION_DP, c_dp);
        int c_mp_i = osl_int_get_si(OSL_PRECISION_MP, c_mp);
        
        if (c_sp_i != c_dp_i || c_sp_i != c_mp_i || c_sp_i != a_sp_i + 1) {
          error++; printf("Error osl_int_increment\n");
        }
      }
      
      // osl_int_decrement
      if (!error) {
        osl_int_decrement(OSL_PRECISION_SP, &c_sp, a_sp);
        osl_int_decrement(OSL_PRECISION_DP, &c_dp, a_dp);
        osl_int_decrement(OSL_PRECISION_MP, &c_mp, a_mp);
        
        int c_sp_i = osl_int_get_si(OSL_PRECISION_SP, c_sp);
        int c_dp_i = osl_int_get_si(OSL_PRECISION_DP, c_dp);
        int c_mp_i = osl_int_get_si(OSL_PRECISION_MP, c_mp);
        
        if (c_sp_i != c_dp_i || c_sp_i != c_mp_i || c_sp_i != a_sp_i - 1) {
          error++; printf("Error osl_int_decrement\n");
        }
      }
      
      // osl_int_add
      if (!error) {
        osl_int_add(OSL_PRECISION_SP, &c_sp, a_sp, b_sp);
        osl_int_add(OSL_PRECISION_DP, &c_dp, a_dp, b_dp);
        osl_int_add(OSL_PRECISION_MP, &c_mp, a_mp, b_mp);
        
        int c_sp_i = osl_int_get_si(OSL_PRECISION_SP, c_sp);
        int c_dp_i = osl_int_get_si(OSL_PRECISION_DP, c_dp);
        int c_mp_i = osl_int_get_si(OSL_PRECISION_MP, c_mp);
        
        if (c_sp_i != c_dp_i || c_sp_i != c_mp_i || c_sp_i != a_sp_i + b_sp_i) {
          error++; printf("Error osl_int_add\n");
        }
      }
      
      // osl_int_add_si
      
      // osl_int_sub
      if (!error) {
        osl_int_sub(OSL_PRECISION_SP, &c_sp, a_sp, b_sp);
        osl_int_sub(OSL_PRECISION_DP, &c_dp, a_dp, b_dp);
        osl_int_sub(OSL_PRECISION_MP, &c_mp, a_mp, b_mp);
        
        int c_sp_i = osl_int_get_si(OSL_PRECISION_SP, c_sp);
        int c_dp_i = osl_int_get_si(OSL_PRECISION_DP, c_dp);
        int c_mp_i = osl_int_get_si(OSL_PRECISION_MP, c_mp);
        
        if (c_sp_i != c_dp_i || c_sp_i != c_mp_i || c_sp_i != a_sp_i - b_sp_i) {
          error++; printf("Error osl_int_add\n");
        }
      }
      
      // osl_int_mul
      if (!error) {
        osl_int_mul(OSL_PRECISION_SP, &c_sp, a_sp, b_sp);
        osl_int_mul(OSL_PRECISION_DP, &c_dp, a_dp, b_dp);
        osl_int_mul(OSL_PRECISION_MP, &c_mp, a_mp, b_mp);
        
        int c_sp_i = osl_int_get_si(OSL_PRECISION_SP, c_sp);
        int c_dp_i = osl_int_get_si(OSL_PRECISION_DP, c_dp);
        int c_mp_i = osl_int_get_si(OSL_PRECISION_MP, c_mp);
        
        if (c_sp_i != c_dp_i || c_sp_i != c_mp_i || c_sp_i != a_sp_i * b_sp_i) {
          error++; printf("Error osl_int_mul\n");
        }
      }
      
      // osl_int_mul_si
      if (!error) {
        osl_int_mul_si(OSL_PRECISION_SP, &c_sp, a_sp, b_sp_i);
        osl_int_mul_si(OSL_PRECISION_DP, &c_dp, a_dp, b_dp_i);
        osl_int_mul_si(OSL_PRECISION_MP, &c_mp, a_mp, b_mp_i);
        
        int c_sp_i = osl_int_get_si(OSL_PRECISION_SP, c_sp);
        int c_dp_i = osl_int_get_si(OSL_PRECISION_DP, c_dp);
        int c_mp_i = osl_int_get_si(OSL_PRECISION_MP, c_mp);
        
        if (c_sp_i != c_dp_i || c_sp_i != c_mp_i || c_sp_i != a_sp_i * b_sp_i) {
          error++; printf("Error osl_int_mul_si\n");
        }
      }
      
      // osl_int_div_exact
      if (!error && b_sp_i != 0 && a_sp_i % b_sp_i == 0) {
        osl_int_div_exact(OSL_PRECISION_SP, &c_sp, a_sp, b_sp);
        osl_int_div_exact(OSL_PRECISION_DP, &c_dp, a_dp, b_dp);
        osl_int_div_exact(OSL_PRECISION_MP, &c_mp, a_mp, b_mp);
        
        int c_sp_i = osl_int_get_si(OSL_PRECISION_SP, c_sp);
        int c_dp_i = osl_int_get_si(OSL_PRECISION_DP, c_dp);
        int c_mp_i = osl_int_get_si(OSL_PRECISION_MP, c_mp);
        
        if (c_sp_i != c_dp_i || c_sp_i != c_mp_i || c_sp_i != a_sp_i / b_sp_i) {
          error++; printf("Error osl_int_div_exact\n");
        }
      }
      
      // osl_int_floor_div_q
      if (!error && b_sp_i != 0) {
        osl_int_floor_div_q(OSL_PRECISION_SP, &c_sp, a_sp, b_sp);
        osl_int_floor_div_q(OSL_PRECISION_DP, &c_dp, a_dp, b_dp);
        osl_int_floor_div_q(OSL_PRECISION_MP, &c_mp, a_mp, b_mp);
        
        int c_sp_i = osl_int_get_si(OSL_PRECISION_SP, c_sp);
        int c_dp_i = osl_int_get_si(OSL_PRECISION_DP, c_dp);
        int c_mp_i = osl_int_get_si(OSL_PRECISION_MP, c_mp);
        
        if (c_sp_i != c_dp_i || c_sp_i != c_mp_i) {
          error++; printf("Error osl_int_floor_div_q\n");
        }
      }
      
      // osl_int_floor_div_r
      if (!error && b_sp_i != 0) {
        osl_int_floor_div_r(OSL_PRECISION_SP, &c_sp, a_sp, b_sp);
        osl_int_floor_div_r(OSL_PRECISION_DP, &c_dp, a_dp, b_dp);
        osl_int_floor_div_r(OSL_PRECISION_MP, &c_mp, a_mp, b_mp);
        
        int c_sp_i = osl_int_get_si(OSL_PRECISION_SP, c_sp);
        int c_dp_i = osl_int_get_si(OSL_PRECISION_DP, c_dp);
        int c_mp_i = osl_int_get_si(OSL_PRECISION_MP, c_mp);
        
        if (c_sp_i != c_dp_i || c_sp_i != c_mp_i) {
          error++; printf("Error osl_int_floor_div_r\n");
        }
      }
      
      // osl_int_floor_div_q_r
      if (!error && b_sp_i != 0) {
        osl_int_t q_sp; osl_int_init(OSL_PRECISION_SP, &q_sp);
        osl_int_t q_dp; osl_int_init(OSL_PRECISION_DP, &q_dp);
        osl_int_t q_mp; osl_int_init(OSL_PRECISION_MP, &q_mp);
        
        osl_int_t r_sp; osl_int_init(OSL_PRECISION_SP, &r_sp);
        osl_int_t r_dp; osl_int_init(OSL_PRECISION_DP, &r_dp);
        osl_int_t r_mp; osl_int_init(OSL_PRECISION_MP, &r_mp);
      
        osl_int_floor_div_q_r(OSL_PRECISION_SP, &q_sp, &r_sp, a_sp, b_sp);
        osl_int_floor_div_q_r(OSL_PRECISION_DP, &q_dp, &r_dp, a_dp, b_dp);
        osl_int_floor_div_q_r(OSL_PRECISION_MP, &q_mp, &r_mp, a_mp, b_mp);
        
        int q_sp_i = osl_int_get_si(OSL_PRECISION_SP, q_sp);
        int q_dp_i = osl_int_get_si(OSL_PRECISION_DP, q_dp);
        int q_mp_i = osl_int_get_si(OSL_PRECISION_MP, q_mp);
        
        int r_sp_i = osl_int_get_si(OSL_PRECISION_SP, r_sp);
        int r_dp_i = osl_int_get_si(OSL_PRECISION_DP, r_dp);
        int r_mp_i = osl_int_get_si(OSL_PRECISION_MP, r_mp);
        
        if (q_sp_i != q_dp_i || q_sp_i != q_mp_i) {
          error++; printf("Error osl_int_floor_div_q_r\n");
        }
        if (r_sp_i != r_dp_i || r_sp_i != r_mp_i) {
          error++; printf("Error osl_int_floor_div_q_r\n");
        }
      }
      
      // osl_int_mod
      if (!error && b_sp_i != 0) {
        osl_int_mod(OSL_PRECISION_SP, &c_sp, a_sp, b_sp);
        osl_int_mod(OSL_PRECISION_DP, &c_dp, a_dp, b_dp);
        osl_int_mod(OSL_PRECISION_MP, &c_mp, a_mp, b_mp);
        
        int c_sp_i = osl_int_get_si(OSL_PRECISION_SP, c_sp);
        int c_dp_i = osl_int_get_si(OSL_PRECISION_DP, c_dp);
        int c_mp_i = osl_int_get_si(OSL_PRECISION_MP, c_mp);
        
        if (c_sp_i != c_dp_i || c_sp_i != c_mp_i) {
          error++; printf("Error osl_int_mod\n");
        }
      }
      
      // osl_int_gcd
      if (!error) {
        osl_int_gcd(OSL_PRECISION_SP, &c_sp, a_sp, b_sp);
        osl_int_gcd(OSL_PRECISION_DP, &c_dp, a_dp, b_dp);
        osl_int_gcd(OSL_PRECISION_MP, &c_mp, a_mp, b_mp);
        
        int c_sp_i = osl_int_get_si(OSL_PRECISION_SP, c_sp);
        int c_dp_i = osl_int_get_si(OSL_PRECISION_DP, c_dp);
        int c_mp_i = osl_int_get_si(OSL_PRECISION_MP, c_mp);
        
        if (c_sp_i != c_dp_i || c_sp_i != c_mp_i) {
          error++; printf("Error osl_int_gcd\n");
        }
      }
      
      // osl_int_oppose
      if (!error) {
        osl_int_oppose(OSL_PRECISION_SP, &c_sp, b_sp);
        osl_int_oppose(OSL_PRECISION_DP, &c_dp, b_dp);
        osl_int_oppose(OSL_PRECISION_MP, &c_mp, b_mp);
        
        int c_sp_i = osl_int_get_si(OSL_PRECISION_SP, c_sp);
        int c_dp_i = osl_int_get_si(OSL_PRECISION_DP, c_dp);
        int c_mp_i = osl_int_get_si(OSL_PRECISION_MP, c_mp);
        
        if (c_sp_i != c_dp_i || c_sp_i != c_mp_i) {
          error++; printf("Error osl_int_oppose\n");
        }
      }
      
      // osl_int_abs
      if (!error) {
        osl_int_abs(OSL_PRECISION_SP, &c_sp, b_sp);
        osl_int_abs(OSL_PRECISION_DP, &c_dp, b_dp);
        osl_int_abs(OSL_PRECISION_MP, &c_mp, b_mp);
        
        int c_sp_i = osl_int_get_si(OSL_PRECISION_SP, c_sp);
        int c_dp_i = osl_int_get_si(OSL_PRECISION_DP, c_dp);
        int c_mp_i = osl_int_get_si(OSL_PRECISION_MP, c_mp);
        
        if (c_sp_i != c_dp_i || c_sp_i != c_mp_i) {
          error++; printf("Error osl_int_abs\n");
        }
      }
      
      // osl_int_size_in_base_2
      if (!error) {
        size_t r_sp = osl_int_size_in_base_2(OSL_PRECISION_SP, b_sp);
        size_t r_dp = osl_int_size_in_base_2(OSL_PRECISION_DP, b_dp);
        size_t r_mp = osl_int_size_in_base_2(OSL_PRECISION_MP, b_mp);
        
        osl_int_set_si(OSL_PRECISION_SP, &c_sp, r_sp);
        osl_int_set_si(OSL_PRECISION_DP, &c_dp, r_dp);
        osl_int_set_si(OSL_PRECISION_MP, &c_mp, r_mp);
        
        if (r_sp != r_dp || r_sp != r_mp) {
          error++; printf("Error osl_int_size_in_base_2\n");
        }
      }
      
      // osl_int_size_in_base_10
//       if (!error) {
//         size_t r_sp = osl_int_size_in_base_10(OSL_PRECISION_SP, b_sp);
//         size_t r_dp = osl_int_size_in_base_10(OSL_PRECISION_DP, b_dp);
//         size_t r_mp = osl_int_size_in_base_10(OSL_PRECISION_MP, b_mp);
//         
//         osl_int_set_si(OSL_PRECISION_SP, &c_sp, r_sp);
//         osl_int_set_si(OSL_PRECISION_DP, &c_dp, r_dp);
//         osl_int_set_si(OSL_PRECISION_MP, &c_mp, r_mp);
//         
//         if (r_sp != r_dp || r_sp != r_mp)
//           { error++; printf("Error osl_int_size_in_base_10\n"); }
//       }
      
      // osl_int_eq
      
      // osl_int_ne
      
      // osl_int_pos
      
      // osl_int_neg
      
      // osl_int_zero
      
      // osl_int_one
      
      // osl_int_mone
      
      // osl_int_divisible
      
      if (error) {
        printf("Error with:\n");
        printf("\n");
        
        printf("a_sp = "); osl_int_print(stdout, OSL_PRECISION_SP, a_sp);
        printf("\n");
        printf("a_dp = "); osl_int_print(stdout, OSL_PRECISION_DP, a_dp);
        printf("\n");
        printf("a_mp = "); osl_int_print(stdout, OSL_PRECISION_MP, a_mp);
        printf("\n");
        printf("\n");
        
        printf("b_sp = "); osl_int_print(stdout, OSL_PRECISION_SP, b_sp);
        printf("\n");
        printf("b_dp = "); osl_int_print(stdout, OSL_PRECISION_DP, b_dp);
        printf("\n");
        printf("b_mp = "); osl_int_print(stdout, OSL_PRECISION_MP, b_mp);
        printf("\n");
        printf("\n");
        
        printf("c_sp = "); osl_int_print(stdout, OSL_PRECISION_SP, c_sp);
        printf("\n");
        printf("c_dp = "); osl_int_print(stdout, OSL_PRECISION_DP, c_dp);
        printf("\n");
        printf("c_mp = "); osl_int_print(stdout, OSL_PRECISION_MP, c_mp);
        printf("\n");
        printf("\n");
        
        nb_fail += error;
      }
    }
  }
  
  printf("%s ", argv[0]);
  printf("fails = %d\n", nb_fail);
  
  #else
  
  printf("%s ", argv[0]);
  printf("works only with GMP\n");
  
  #endif
  
  return nb_fail;
}
Beispiel #6
0
/*
 * Converts a PIP quast to a union of polyhedra
 */
osl_relation_p pip_quast_to_polyhedra(PipQuast *quast, int nvar, int npar) {
  // originaly used for lastwriter
  // july 5th 2012 : extracted from dependence.c

  osl_relation_p ep;
  osl_relation_p tp;
  osl_relation_p qp;
  osl_relation_p iter;
  int precision;
  int j;
  if (quast == NULL)
    return NULL;

  #if defined(CANDL_LINEAR_VALUE_IS_INT)
    precision = OSL_PRECISION_SP;
  #elif defined(CANDL_LINEAR_VALUE_IS_LONGLONG)
    precision = OSL_PRECISION_DP;
  #elif defined(CANDL_LINEAR_VALUE_IS_MP)
    precision = OSL_PRECISION_MP;
  #endif

  if (quast->condition != NULL) {
    tp = pip_quast_to_polyhedra(quast->next_then, nvar, npar);
    ep = pip_quast_to_polyhedra(quast->next_else, nvar, npar);
      
    /* Each of the matrices in the then tree needs to be augmented with
     * the condition */
    for (iter = tp ; iter != NULL ; iter = iter->next) {
      int nrows = iter->nb_rows;
      osl_int_set_si(precision, &iter->m[nrows][0], 1);
      for (j = 1; j < 1 + nvar; j++)
        osl_int_set_si(precision, &iter->m[nrows][j], 0);
      for (j = 0; j < npar + 1; j++)
        osl_int_set_si(precision, &iter->m[nrows][1 + nvar + j],
                        CANDL_get_si(quast->condition->the_vector[j]));
      (iter->nb_rows)++;
    }

    /* JP : july 5th 2012:
     * Fix negation of a constraint in adding -1 to the constant
     */

    for (iter = ep; iter != NULL ; iter = iter->next) {
      int nrows = iter->nb_rows;
      /* Inequality */
      osl_int_set_si(precision, &iter->m[nrows][0], 5);
      for (j = 1; j < 1 + nvar; j++)
        osl_int_set_si(precision, &iter->m[nrows][j], 0);
      for (j = 0; j < npar + 1; j++)
        osl_int_set_si(precision, &iter->m[nrows][1 + nvar + j],
                     -CANDL_get_si(quast->condition->the_vector[j]));
      osl_int_decrement(precision, 
                        &iter->m[nrows][iter->nb_columns - 1],
                        iter->m[nrows][iter->nb_columns - 1]);
      (iter->nb_rows)++;
    }

    /* union of tp and ep */
    if (tp) {
      qp = tp;
      for (iter = tp ; iter->next != NULL ; iter = iter->next)
        ;
      iter->next = ep;
    } else {
      qp = ep;
    }

    return qp;

  } else {
    /* quast condition is NULL */
    osl_relation_p lwmatrix = osl_relation_pmalloc(precision, nvar+npar+1,
                                                  nvar+npar+2);
    PipList *vecList = quast->list;

    int count=0;
    while (vecList != NULL) {
      /* Equality */
      osl_int_set_si(precision, &lwmatrix->m[count][0], 0);
      for (j=0; j < nvar; j++)
        if (j == count)
          osl_int_set_si(precision, &lwmatrix->m[count][j + 1], 1);
        else
          osl_int_set_si(precision, &lwmatrix->m[count][j + 1], 0);

      for (j=0; j < npar; j++)
        osl_int_set_si(precision, &lwmatrix->m[count][j + 1 + nvar],
                       -CANDL_get_si(vecList->vector->the_vector[j]));
      /* Constant portion */
      if (quast->newparm != NULL)
        /* Don't handle newparm for now */
        osl_int_set_si(precision, &lwmatrix->m[count][npar + 1 + nvar],
                       -CANDL_get_si(vecList->vector->the_vector[npar+1]));
      else
        osl_int_set_si(precision, &lwmatrix->m[count][npar + 1 + nvar],
                       -CANDL_get_si(vecList->vector->the_vector[npar]));

      count++;

      vecList = vecList->next;
    }
    lwmatrix->nb_rows = count;
    lwmatrix->nb_parameters = npar;

    return lwmatrix;
  }
}
Beispiel #7
0
/*
 * Converts all conditions where the path does not lead to a solution
 * The return is a upip_quast_to_polyhedranion of polyhedra
 * extracted from pip_quast_to_polyhedra
 */
osl_relation_p pip_quast_no_solution_to_polyhedra(PipQuast *quast, int nvar, 
                                                  int npar) {
  osl_relation_p ep;
  osl_relation_p tp;
  osl_relation_p qp;
  osl_relation_p iter;
  int precision;
  int j;
  if (quast == NULL)
    return NULL;

  #if defined(CANDL_LINEAR_VALUE_IS_INT)
    precision = OSL_PRECISION_SP;
  #elif defined(CANDL_LINEAR_VALUE_IS_LONGLONG)
    precision = OSL_PRECISION_DP;
  #elif defined(CANDL_LINEAR_VALUE_IS_MP)
    precision = OSL_PRECISION_MP;
  #endif

  if (quast->condition != NULL) {
    tp = pip_quast_no_solution_to_polyhedra(quast->next_then, nvar, npar);
    ep = pip_quast_no_solution_to_polyhedra(quast->next_else, nvar, npar);
      
    /* Each of the matrices in the then tree needs to be augmented with
     * the condition */
    for (iter = tp ; iter != NULL ; iter = iter->next) {
      int nrows = iter->nb_rows;
      osl_int_set_si(precision, &iter->m[nrows][0], 1);
      for (j = 1; j < 1 + nvar; j++)
        osl_int_set_si(precision, &iter->m[nrows][j], 0);
      for (j = 0; j < npar + 1; j++)
        osl_int_set_si(precision, &iter->m[nrows][1 + nvar + j],
                        CANDL_get_si(quast->condition->the_vector[j]));
      (iter->nb_rows)++;
    }

    for (iter = ep; iter != NULL ; iter = iter->next) {
      int nrows = iter->nb_rows;
      /* Inequality */
      osl_int_set_si(precision, &iter->m[nrows][0], 1);
      for (j = 1; j < 1 + nvar; j++)
        osl_int_set_si(precision, &iter->m[nrows][j], 0);
      for (j = 0; j < npar + 1; j++)
        osl_int_set_si(precision, &iter->m[nrows][1 + nvar + j],
                     -CANDL_get_si(quast->condition->the_vector[j]));
      osl_int_decrement(precision, 
                        &iter->m[nrows][iter->nb_columns - 1],
                        iter->m[nrows][iter->nb_columns - 1]);
      (iter->nb_rows)++;
    }

    /* union of tp and ep */
    if (tp) {
      qp = tp;
      for (iter = tp ; iter->next != NULL ; iter = iter->next)
        ;
      iter->next = ep;
    } else {
      qp = ep;
    }

    return qp;

  }

  if (quast->list != NULL)
    return NULL;

  /* quast condition is NULL */
  osl_relation_p lwmatrix = osl_relation_pmalloc(precision, nvar+npar+1,
                                                nvar+npar+2);
  lwmatrix->nb_rows = 0;
  lwmatrix->nb_parameters = npar;

  return lwmatrix;
}
Beispiel #8
0
Datei: ddv.c Projekt: Ced/candl
/**
 * Creates a ddv of size equal to the maximal loop depth of the source
 * and target of the statement, according to the dependence polyhedron.
 *
 */
static
CandlDDV*
candl_ddv_create_from_dep(osl_dependence_p dep, int loop_id, int ddv_size) {
  osl_relation_p mat = dep->domain;
  osl_statement_p src = dep->stmt_source_ptr;
  candl_statement_usr_p usr = src->usr;
  CandlDDV* dv = candl_ddv_alloc(ddv_size);
  int precision = src->domain->precision;
  int i, j;
  int pos;
  
  dv->loop_id = loop_id;
  dv->deptype = dep->type;

  // Create the template of the system to operate on.
  // Add one dimension at the beginning, and one row for the extra constraint.
  int nb_par = src->domain->nb_parameters;
  osl_relation_p testsyst = osl_relation_pmalloc(precision,
                                                 mat->nb_rows + 1,
                                                 mat->nb_columns + 1);
  for (pos = 0; pos < mat->nb_rows; ++pos) {
    osl_int_assign(precision, &testsyst->m[pos][0], mat->m[pos][0]);
    for (j = 1; j < mat->nb_columns; ++j)
      osl_int_assign(precision, &testsyst->m[pos][j + 1],mat->m[pos][j]);
  }
  
  int has_eq, has_pos, has_neg, has_cst;
  int scal1, scal2;
  for (i = 1; i <= ddv_size; ++i) {
    // Test for '='.
    osl_int_set_si(precision, &testsyst->m[pos][0], 0);
    osl_int_set_si(precision, &testsyst->m[pos][1 + i], 1);
    osl_int_set_si(precision, &testsyst->m[pos][1 + i + usr->depth], -1);
    osl_int_set_si(precision, &testsyst->m[pos][testsyst->nb_columns-1], 0);
    has_eq = pip_has_rational_point(testsyst, NULL, 1);

    // Test for '>'.
    osl_int_set_si(precision, &testsyst->m[pos][0], 1);
    osl_int_set_si(precision, &testsyst->m[pos][1 + i], 1);
    osl_int_set_si(precision, &testsyst->m[pos][1 + i + usr->depth], -1);
    osl_int_set_si(precision, &testsyst->m[pos][testsyst->nb_columns-1], -1);
    has_pos = pip_has_rational_point(testsyst, NULL, 1);

    // Test for '<'.
    osl_int_set_si(precision, &testsyst->m[pos][0], 1);
    osl_int_set_si(precision, &testsyst->m[pos][1 + i], -1);
    osl_int_set_si(precision, &testsyst->m[pos][1 + i + usr->depth], 1);
    osl_int_set_si(precision, &testsyst->m[pos][testsyst->nb_columns-1], -1);
    has_neg = pip_has_rational_point(testsyst, NULL, 1);

    // Test for constant distance.
    // min(x_R^i - x_S^i)
    // max(x_R^i - x_S^i) = - min(- x_R^i + x_S^i)
    osl_int_set_si(precision, &testsyst->m[pos][0], 0);
    osl_int_set_si(precision, &testsyst->m[pos][1], 1);
    osl_int_set_si(precision, &testsyst->m[pos][1 + i], -1);
    osl_int_set_si(precision, &testsyst->m[pos][1 + i + usr->depth], 1);
    osl_int_set_si(precision, &testsyst->m[pos][testsyst->nb_columns-1], 0);
    has_cst = candl_ddv_constant_val(testsyst, &scal1, nb_par);

    if (has_cst) {
      osl_int_set_si(precision, &testsyst->m[pos][1 + i], 1);
      osl_int_set_si(precision, &testsyst->m[pos][1 + i + usr->depth], -1);
      osl_int_set_si(precision, &testsyst->m[pos][1], 1);
      has_cst = candl_ddv_constant_val(testsyst, &scal2, nb_par);
      scal2 *= -1;
      if (has_cst)
        has_cst = (scal1 == scal2);
    }

    if (has_cst && scal1 != 0) {
      candl_ddv_set_type_at(dv, candl_dv_scalar, i - 1);
      candl_ddv_set_value_at(dv, scal1, i - 1);
    }
    else if (has_pos && has_neg)
      candl_ddv_set_type_at(dv, candl_dv_star, i - 1);
    else if (has_pos)
      candl_ddv_set_type_at(dv, candl_dv_plus, i - 1);
    else if (has_neg)
      candl_ddv_set_type_at(dv, candl_dv_minus, i - 1);
    else if (has_eq) {
      candl_ddv_set_type_at(dv, candl_dv_eq, i - 1);
      candl_ddv_set_value_at(dv, 0, i - 1);
    }

    // Reset the constraint.
    osl_int_set_si(precision, &testsyst->m[pos][0], 0);
    osl_int_set_si(precision, &testsyst->m[pos][1], 0);
    osl_int_set_si(precision, &testsyst->m[pos][1 + i], 0);
    osl_int_set_si(precision, &testsyst->m[pos][1 + i + usr->depth], 0);
    osl_int_set_si(precision, &testsyst->m[pos][testsyst->nb_columns-1], 0);
  }

  return dv;
}