Esempio n. 1
0
// Attempts to memory-map len bytes of the current file, starting
// at position offset.  Precondition: offset is a multiple of the
// page size.  Postcondition: return value is a null pointer if the
// memory mapping failed.  Otherwise the return value is a pointer to 
// the memory-mapped file and the file position is set to offset.
void* _Filebuf_base::_M_mmap(streamoff offset, streamoff len) {
  void* base;
#if defined (_STLP_UNIX) && !defined(__DJGPP) && !defined(_CRAY)
  base = MMAP(0, len, PROT_READ, MAP_PRIVATE, _M_file_id, offset);
  if (base != (void*)MAP_FAILED) {
    if (LSEEK(_M_file_id, offset + len, SEEK_SET) < 0) {
      this->_M_unmap(base, len);
      base = 0;
    }
  } else
    base =0;

#elif defined (_STLP_USE_WIN32_IO)

  _M_view_id = CreateFileMapping(_M_file_id, (PSECURITY_ATTRIBUTES)0 ,
				 PAGE_READONLY, 0 /* len >> 32 */ , 
				 0 /* len & 0xFFFFFFFF */ ,             // low-order DWORD of size
				 0);

  if (_M_view_id) {
# if 0
    printf("view %x created from file %x, error = %d, size = %d, map_offset = %d map_len = %d\n", 
	   _M_view_id, _M_file_id, GetLastError(), 
	   (int)cur_filesize, ULL(offset) & 0xffffffff, len);
# endif
    
    base = MapViewOfFile(_M_view_id, FILE_MAP_READ, ULL(offset)>>32, 
			 ULL(offset) & 0xffffffff, len);
    // check if mapping succeded and is usable
    if (base ==0  || _M_seek(offset+len, ios_base::beg) < 0) {
      this->_M_unmap(base, len);
      base = 0;
    }
  } else
Esempio n. 2
0
/** print totals */
static void
print_totals(struct inspect_totals* t)
{
	int i, tp;
	printf("*** total num chunks:	%llu\n", ULL t->num_chunks);
	for(i=0; i<=UDB_ALLOC_CHUNKS_MAX; i++) {
		if(t->exp_num[i] != 0 || t->exp_free[i] != 0)
			printf("exp %d chunks: free %llu alloc %llu "
				"total %llu\n", i, ULL t->exp_free[i],
				ULL (t->exp_num[i] - t->exp_free[i]),
				ULL t->exp_num[i]);
	}
	for(tp=0; tp<NUM_UDB_TYPES; tp++) {
		if(t->type_num[tp] == 0)
			continue;
		printf("type %s num chunks:	%llu\n",
			chunk_type2str(tp), ULL t->type_num[tp]);
		for(i=0; i<=UDB_ALLOC_CHUNKS_MAX; i++) {
			if(t->type_exp_num[tp][i] != 0)
				printf("type %s exp %d chunks:	%llu\n",
					chunk_type2str(tp), i,
					ULL t->type_exp_num[tp][i]);
		}
	}
}
Esempio n. 3
0
my_ulonglong find_typeset(char *x, TYPELIB *lib, int *err)
{
  my_ulonglong result;
  int find;
  char *i;
  DBUG_ENTER("find_set");
  DBUG_PRINT("enter",("x: '%s'  lib: 0x%lx", x, (long) lib));

  if (!lib->count)
  {
    DBUG_PRINT("exit",("no count"));
    DBUG_RETURN(0);
  }
  result= 0;
  *err= 0;
  while (*x)
  {
    (*err)++;
    i= x;
    while (*x && !is_field_separator(*x))
      x++;
    if (x[0] && x[1])      /* skip separator if found */
      x++;
    if ((find= find_type(i, lib, FIND_TYPE_COMMA_TERM) - 1) < 0)
      DBUG_RETURN(0);
    result|= (ULL(1) << find);
  }
  *err= 0;
  DBUG_RETURN(result);
} /* find_set */
Esempio n. 4
0
/** inspect alloc global part */
static udb_alloc_d*
inspect_alloc(udb_glob_d* g)
{
	int i;
	udb_alloc_d* a = (udb_alloc_d*)((void*)g + sizeof(*g));
	printf("bytes data allocated:	%llu\n", ULL a->stat_data);
	printf("bytes used for chunks:	%llu\n", ULL a->stat_alloc);
	printf("bytes free in chunks:	%llu\n", ULL a->stat_free);
	printf("  lost space:		%llu\n", ULL
		(a->stat_alloc-a->stat_data));
	printf("next chunk placement:	%llu\n", ULL a->nextgrow);
	printf("  unused space at EOF:	%llu\n", ULL g->fsize-a->nextgrow);

	if(v) {
		for(i=0; i<UDB_ALLOC_CHUNKS_MAX-UDB_ALLOC_CHUNK_MINEXP+1; i++) {
			printf("freelist[%d] (exp %d):	%llu\n",
				i, i+UDB_ALLOC_CHUNK_MINEXP, ULL a->free[i]);
		}
		printf("header size:		%llu\n",
			ULL *(uint64_t*)((void*)a+sizeof(*a)));
		printf("header endmarker exp:	%llu\n",
			ULL *(uint64_t*)((void*)a+sizeof(*a)+sizeof(uint64_t)));
	}
	return a;
}
int test_serialize_compress_press( long count )
{
	AllTypes2	st ;
	char		buf[ DSCSERIALIZE_COMPRESS_BUFSIZE_AllTypes2 + 1 ] ;
	int		len ;
	
	long		c ;
	long		t1 , t2 , dt ;
	
	int		nret = 0 ;
	
	memset( & st , 0x00 , sizeof(AllTypes2) );
	
	st.n4 = -0x11223344 ;
	st.n8 = LL(-0x1122334455667788) ;
	st.u4 = 0x11223344 ;
	st.u8 = ULL(0x1122334455667788) ;
	st.f4 = 100.00 ;
	st.f8 = 10000.00 ;
	strcpy( st.str32 , "calvin" );
	strcpy( st.str1024 , "XXXXXXXXXXXXXXXX" );
	
	DSCLOG_AllTypes2( & st );
	
	printf( "Press begin\n" );
	time( & t1 );
	
	for( c = 0 ; c < count ; c++ )
	{
		memset( buf , 0x00 , sizeof(buf) );
		nret = DSCSERIALIZE_COMPRESS_AllTypes2( & st , buf , & len ) ;
		if( nret )
		{
			printf( "DSCSERIALIZE_COMPRESS_AllTypes2 failed[%d]\n" , nret );
			return nret;
		}
		
		memset( & st , 0x00 , sizeof(AllTypes2) );
		nret = DSCDESERIALIZE_COMPRESS_AllTypes2( buf , & len , & st ) ;
		if( nret )
		{
			printf( "DSCDESERIALIZE_COMPRESS_AllTypes2 failed[%d]\n" , nret );
			return nret;
		}
	}
	
	printf( "Press end\n" );
	time( & t2 );
	dt = t2 - t1 ;
	printf( "data compress size[%d] - compact size[%d]\n" , len , DSCSERIALIZE_COMPACT_BUFSIZE_AllTypes2 );
	printf( "Elapse %ld seconds\n" , dt );
	
	dump( buf , len );
	
	DSCLOG_AllTypes2( & st );
	
	return 0;
}
Esempio n. 6
0
ulonglong TIME_to_ulonglong_datetime(const MYSQL_TIME *my_time)
{
  return ((ulonglong) (my_time->year * 10000UL +
                       my_time->month * 100UL +
                       my_time->day) * ULL(1000000) +
          (ulonglong) (my_time->hour * 10000UL +
                       my_time->minute * 100UL +
                       my_time->second));
}
int test_netorder()
{
	AllTypes	st ;
	int		nret = 0 ;
	
	/* client code */
	memset( & st , 0x00 , sizeof(AllTypes) );
	
	st.n1 = -0x11 ;
	st.n2 = -0x1122 ;
	st.n4 = -0x11223344 ;
	st.n8 = LL(-0x1122334455667788) ;
	st.u1 = 0x11 ;
	st.u2 = 0x1122 ;
	st.u4 = 0x11223344 ;
	st.u8 = ULL(0x1122334455667788) ;
	st.f4 = 100.00 ;
	st.f8 = 10000.00 ;
	st.ch = 'A' ;
	st.uch = 'B' ;
	strcpy( st.str32 , "calvin" );
	strcpy( st.str1024 , "XXXXXXXXXXXXXXXX" );
	
	DSCLOG_AllTypes( & st );
	
	nret = DSCNETORDER_AllTypes( & st ) ;
	if( nret )
	{
		printf( "DSCNETORDER_AllTypes failed[%d]\n" , nret );
		return nret;
	}
	else
	{
		printf( "DSCNETORDER_AllTypes ok\n" );
	}
	
	dump( (char *) & st , sizeof(st) );
	
	/* ... client send communication struct to server ... */
	
	/* server code */
	nret = DSCHOSTORDER_AllTypes( & st ) ;
	if( nret )
	{
		printf( "DSCHOSTORDER_AllTypes failed[%d]\n" , nret );
		return nret;
	}
	else
	{
		printf( "DSCHOSTORDER_AllTypes ok\n" );
	}
	
	DSCLOG_AllTypes( & st );
	
	return 0;
}
Esempio n. 8
0
/** walk through file and inspect contents */
static void
inspect_all_chunks(void* base, udb_glob_d* g, udb_alloc_d* a,
	struct inspect_totals* t)
{
	void* at = base + g->hsize;
	while(at < base+a->nextgrow) {
		t->num_chunks++;
		at = inspect_chunk(base, at, t);
	}
	printf("end of chunks at %llu\n", ULL (uint64_t)(at-base));
}
Esempio n. 9
0
uint mi_get_pointer_length(ulonglong file_length, uint def)
{
  DBUG_ASSERT(def >= 2 && def <= 7);
  if (file_length)				/* If not default */
  {
#ifdef NOT_YET_READY_FOR_8_BYTE_POINTERS
    if (file_length >= ULL(1) << 56)
      def=8;
    else
#endif
    if (file_length >= ULL(1) << 48)
      def=7;
    else if (file_length >= ULL(1) << 40)
      def=6;
    else if (file_length >= ULL(1) << 32)
      def=5;
    else if (file_length >= ULL(1) << 24)
      def=4;
    else if (file_length >= ULL(1) << 16)
      def=3;
    else
      def=2;
  }
  return def;
}
Esempio n. 10
0
void taia_now(struct taia *t)
{
#ifdef __WINDOWS__
  FILETIME ft;
  int64_t cns;				/* 100ns ticks */

  /* Get the current system time */
  GetSystemTimeAsFileTime(&ft);

  /* Convert to longtime_t form */
  cns = ((int64_t)ft.dwHighDateTime << 32) + ft.dwLowDateTime;
  t->sec.x = cns/10000000 - 11644473600 + ULL(4611686018427387914);
  t->nano  = (long)((cns % 10000000))*100;
  t->atto  = 0;
#else
  struct timeval now;
  gettimeofday(&now,(struct timezone *) 0);
  t->sec.x = ULL(4611686018427387914) + (uint64_t) now.tv_sec;
  t->nano = 1000 * now.tv_usec + 500;
  t->atto = 0;
#endif
}
Esempio n. 11
0
void test_init_engine()
{
	printf("chess-test: initializing engine...\n");

// 	this stuff needs to run outside of (before) the Initialize command.
//	in the liaison's initializer, we will run this and then call Initialize().
//	it's from main.c's main() originally.

	/* initialize control flags */
	flags = ULL(0);

	/* output for thinking */
	ofp = stdout;

	Initialize();
	printf("chess-test: engine initialization complete.\n");
}
Esempio n. 12
0
ulonglong TIME_to_ulonglong(const MYSQL_TIME *my_time)
{
  switch (my_time->time_type) {
  case MYSQL_TIMESTAMP_DATETIME:
    return TIME_to_ulonglong_datetime(my_time);
  case MYSQL_TIMESTAMP_DATE:
    return TIME_to_ulonglong_date(my_time);
  case MYSQL_TIMESTAMP_TIME:
    return TIME_to_ulonglong_time(my_time);
  case MYSQL_TIMESTAMP_NONE:
  case MYSQL_TIMESTAMP_ERROR:
    return ULL(0);
  default:
    DBUG_ASSERT(0);
  }
  return 0;
}
// Helper function for input_thread() below
static inline void process_one_message(
        char *data,
        int numberOfPixels)
{
#define UC(value)       ((unsigned char) (value))
#define UI(value)       ((unsigned int) (value))
#define ULL(value)      ((unsigned long long) (value))

    int i;
    for (i = 0; i < numberOfPixels; i++) {
        unsigned char x1 = UC(data[i*7 + 0]);
        unsigned char x2 = UC(data[i*7 + 1]);
        unsigned char y1 = UC(data[i*7 + 2]);
        unsigned char y2 = UC(data[i*7 + 3]);
        unsigned int r   = UI(data[i*7 + 4]);
        unsigned int g   = UI(data[i*7 + 5]);
        unsigned int b   = UI(data[i*7 + 6]);
        int x = (((int)x1)<<8) + ((int)x2);
        int y = (((int)y1)<<8) + ((int)y2);

        if (((frameHeight-y-1)*frameWidth + x)*3 + 2 < frameWidth*frameHeight*3 - 1) {
            int index = (frameHeight-y-1)*frameWidth + x;
            unsigned long long receivedFrames = ULL(receivedFrame[index]);

#define EXTRACT(factor, base, index) \
  UC((ULL(UC(base)) + (factor)*ULL(viewingFrame[index])) / ((factor) + 1))

            viewingFrame[index*3]   = EXTRACT(receivedFrames, r, index*3);
            viewingFrame[index*3+1] = EXTRACT(receivedFrames, g, index*3+1);
            viewingFrame[index*3+2] = EXTRACT(receivedFrames, b, index*3+2);

            //viewingFrame[index*3]   = (unsigned char) r;
            //viewingFrame[index*3+1] = (unsigned char) g;
            //viewingFrame[index*3+2] = (unsigned char) b;

            receivedFrame[index] += 1;
        }
    }
}
Esempio n. 14
0
int main (int argc, char *argv[])
{
  int i;

  /*
   * Parse command line arguments conforming with getopt_long syntax
   * Note: we have to support "xboard" and "post" as bare strings
   * for backward compatibility.
   */
 
  int c;
  int opt_help = 0, opt_version = 0, opt_post = 0, opt_xboard = 0, opt_hash = 0, opt_memory = 0, opt_easy = 0, opt_manual = 0;
  char *endptr;

  progname = argv[0]; /* Save in global for cmd_usage */

  while (1)
  {
    static struct option long_options[] =
    {
        {"hashsize", 1, 0, 's'},
        {"memory", 1, 0, 'M'},
        {"version", 0, 0, 'v'},
        {"help", 0, 0, 'h'},
        {"xboard", 0, 0, 'x'},
        {"post", 0, 0, 'p'},
        {"easy", 0, 0, 'e'},
        {"manual", 0, 0, 'm'},
        {0, 0, 0, 0}
    };
 
    /* getopt_long stores the option index here. */ 

    int option_index = 0;
 
    c = getopt_long (argc, argv, "ehmpvxs:M:",
             long_options, &option_index);
 
    /* Detect the end of the options. */
   if (c == -1)
     break;

   /* 
    * Options with a straight flag, could use getoopt_long
    * flag setting but this is more "obvious" and easier to
    * modify.
    */
   switch (c)
     {
     case 'v':
       opt_version = 1;
       break;
     case 'h':
       opt_help = 1;
       break;
     case 'x':
       opt_xboard = 1;
       break;
     case 'p':
       opt_post = 1;
       break;
     case 'e':
       opt_easy = 1;
       break;
     case 'm':
       opt_manual = 1;
       break;
     case 's':    
       if  ( optarg == NULL ){ /* we have error such as two -s */
         opt_help = 1;
         break;
       }
       errno = 0; /* zero error indicator */
       opt_hash = strtol (optarg, &endptr, 10);
       if ( errno != 0 || *endptr != '\0' ){
         printf("Hashsize out of Range or Invalid\n");
         return(1);
       }
       break;
     case 'M':    
       if  ( optarg == NULL ){ /* we have error such as two -s */
         opt_help = 1;
         break;
       }
       errno = 0; /* zero error indicator */
       opt_memory = strtol (optarg, &endptr, 10);
       if ( errno != 0 || *endptr != '\0' ){
         printf("Memory size invalid\n");
         return(1);
       }
       break;
     case '?': /* On error give help - getopt does a basic message. */
       opt_help = 1;
       break;
     default:
       puts ("Option Processing Failed\n");
       abort();
     }
  } /* end of getopt_long style parsing */

  /* Initialize random number generator */
  srand((unsigned int) time(NULL));
  
  /* initialize control flags */
  flags = ULL(0);

  /* output for thinking */
  ofp = stdout;

  /* Handle old style command line options */
  if (argc > 1) {
    for (i = 0; i < argc; i++) {
      if (strcmp(argv[i],"xboard") == 0) {
	SET (flags, XBOARD);
      } else if (strcmp(argv[i],"post") == 0) {
	SET (flags, POST);
      }
    }
  }
  if (opt_xboard == 1)
	SET (flags, XBOARD);
  if (opt_post == 1)
	SET (flags, POST);	
  if (opt_manual ==1)
	SET (flags, MANUAL);
  cmd_version();
  
  /* If the version option was specified we can exit here */
  if (opt_version == 1)
	return(0);
  
  /* If a usage statement is required output it here */
  if (opt_help == 1){
    cmd_usage();
    return (1); /* Maybe an error if due to bad arguments. */
  }

  if (opt_memory != 0 && opt_hash != 0 ){
    cmd_usage();
    return (1); /* only one or the other */
  }

  HashSize = 0 ; /* Set HashSize zero */
  if ( opt_hash != 0)
    CalcHashSize(opt_hash);

  if ( opt_memory > 0 ){
    int tablesize=(1048576*opt_memory)/(2*sizeof(HashSlot));
    CalcHashSize(tablesize);
  }

  Initialize ();

  if ( opt_easy == 0)
   SET (flags, HARD);

  if (argc > 1) {
    for (i = 0; i < argc; i++) {
      if (strcmp(argv[i],"xboard") == 0) {
	SET (flags, XBOARD);
      } else if (strcmp(argv[i],"post") == 0) {
	SET (flags, POST);
      } 
    }
  }

  bookmode = BOOKPREFER;
  bookfirstlast = 3;

  while (!(flags & QUIT)) {
    wait_for_input();
    parse_input();
    if ((flags & THINK) && !(flags & MANUAL) && !(flags & ENDED)) {
      if (!(flags & XBOARD)) printf("Thinking...\n");
      Iterate ();
      CLEAR (flags, THINK);
    }
    RealGameCnt = GameCnt;
    RealSide = board.side;
    input_wakeup();
    /* Ponder only after first move */
    /* Ponder or (if pondering disabled) just wait for input */
    if ((flags & HARD) && !(flags & QUIT) ) {
      ponder();
    }
  }
  
  CleanupInput();

  /*  Some cleaning up  */
  free (HashTab[0]);
  free (HashTab[1]);

  return (0);
}
Esempio n. 15
0
interval j_exp(interval x)
{
  interval res;
  double x_inf, x_sup;
  double rh_sup, rm_sup, rl_sup, tbl1h_sup, tbl1m_sup, tbl1l_sup;
  double tbl2h_sup, tbl2m_sup, tbl2l_sup;
  double xMultLog2InvMult2L_sup, shiftedXMult_sup, kd_sup;
  double msLog2Div2LMultKh_sup, msLog2Div2LMultKm_sup, msLog2Div2LMultKl_sup;
  double t1_sup, t2_sup, polyTblh_sup, polyTblm_sup, polyTbll_sup;
  db_number shiftedXMultdb_sup, xdb_sup, resdb_sup;
  int k_sup, M_sup, index1_sup, index2_sup, xIntHi_sup, mightBeDenorm_sup, roundable;
  double t8_sup, t9_sup, t10_sup, t11_sup, t12_sup, t13_sup;
  double rhSquare_sup, rhSquareHalf_sup, rhC3_sup, rhFour_sup, monomialCube_sup;
  double highPoly_sup, highPolyWithSquare_sup, monomialFour_sup;
  double tablesh_sup, tablesl_sup;
  double s1_sup, s2_sup, s3_sup, s4_sup, s5_sup;
  double res_sup;

  double rh_inf, rm_inf, rl_inf, tbl1h_inf, tbl1m_inf, tbl1l_inf;
  double tbl2h_inf, tbl2m_inf, tbl2l_inf;
  double xMultLog2InvMult2L_inf, shiftedXMult_inf, kd_inf;
  double msLog2Div2LMultKh_inf, msLog2Div2LMultKm_inf, msLog2Div2LMultKl_inf;
  double t1_inf, t2_inf, polyTblh_inf, polyTblm_inf, polyTbll_inf;
  db_number shiftedXMultdb_inf, xdb_inf, resdb_inf;
  int k_inf, M_inf, index1_inf, index2_inf, xIntHi_inf, mightBeDenorm_inf;
  double t8_inf, t9_inf, t10_inf, t11_inf, t12_inf, t13_inf;
  double rhSquare_inf, rhSquareHalf_inf, rhC3_inf, rhFour_inf, monomialCube_inf;
  double highPoly_inf, highPolyWithSquare_inf, monomialFour_inf;
  double tablesh_inf, tablesl_inf;
  double s1_inf, s2_inf, s3_inf, s4_inf, s5_inf;
  double res_inf;

  double res_simple_inf, res_simple_sup;
  int infDone=0; int supDone=0;

  x_inf=LOW(x);
  x_sup=UP(x);

  /* Argument reduction and filtering for special cases */

  /* Compute k as a double and as an int */
  xdb_sup.d = x_sup;
  xdb_inf.d = x_inf;
  xMultLog2InvMult2L_sup = x_sup * log2InvMult2L;
  xMultLog2InvMult2L_inf = x_inf * log2InvMult2L;
  shiftedXMult_sup = xMultLog2InvMult2L_sup + shiftConst;
  shiftedXMult_inf = xMultLog2InvMult2L_inf + shiftConst;
  kd_sup = shiftedXMult_sup - shiftConst;
  kd_inf = shiftedXMult_inf - shiftConst;
  shiftedXMultdb_sup.d = shiftedXMult_sup;
  shiftedXMultdb_inf.d = shiftedXMult_inf;


  /* Special cases tests */
  xIntHi_sup = xdb_sup.i[HI];
  mightBeDenorm_sup = 0;

  /* Special cases tests */
  xIntHi_inf = xdb_inf.i[HI];
  mightBeDenorm_inf = 0;

  if ( __builtin_expect(
       ((xIntHi_sup & 0x7ff00000) == 0)
    || (((xIntHi_sup & 0x7ff00000) == 0)  && (x_sup == 0.0)) 
    || (((xIntHi_sup & 0x7ff00000) == 0)  && (x_sup < 0.0))
    || (((xIntHi_sup & 0x7fffffff) >= OVRUDRFLWSMPLBOUND) && ((xIntHi_sup & 0x7fffffff) >= 0x7ff00000))
    || (((xIntHi_sup & 0x7fffffff) >= OVRUDRFLWSMPLBOUND) && ((xIntHi_sup & 0x7fffffff) >= 0x7ff00000) && (((xIntHi_sup & 0x000fffff) | xdb_sup.i[LO]) != 0))
    || (((xIntHi_sup & 0x7fffffff) >= OVRUDRFLWSMPLBOUND) && ((xIntHi_sup & 0x7fffffff) >= 0x7ff00000) && ((xIntHi_sup & 0x80000000)==0))
    || (((xIntHi_sup & 0x7fffffff) >= OVRUDRFLWSMPLBOUND) && (x_sup > OVRFLWBOUND))
    || (((xIntHi_sup & 0x7fffffff) >= OVRUDRFLWSMPLBOUND) && (x_sup <= UNDERFLWBOUND))
    || (((xIntHi_sup & 0x7fffffff) >= OVRUDRFLWSMPLBOUND) && (x_sup <= DENORMBOUND))
    || ((xIntHi_inf & 0x7ff00000) == 0)
    || (((xIntHi_inf & 0x7ff00000) == 0) && (x_inf == 0.0))
    || (((xIntHi_inf & 0x7ff00000) == 0) && (x_inf > 0.0))
    || (((xIntHi_inf & 0x7fffffff) >= OVRUDRFLWSMPLBOUND) && ((xIntHi_inf & 0x7fffffff) >= 0x7ff00000))
    || (((xIntHi_inf & 0x7fffffff) >= OVRUDRFLWSMPLBOUND) && ((xIntHi_inf & 0x7fffffff) >= 0x7ff00000) && (((xIntHi_inf & 0x000fffff) | xdb_inf.i[LO]) != 0))
    || (((xIntHi_inf & 0x7fffffff) >= OVRUDRFLWSMPLBOUND) && ((xIntHi_inf & 0x7fffffff) >= 0x7ff00000) && ((xIntHi_inf & 0x80000000)==0))
    || (((xIntHi_inf & 0x7fffffff) >= OVRUDRFLWSMPLBOUND) && (x_inf > OVRFLWBOUND))
    || (((xIntHi_inf & 0x7fffffff) >= OVRUDRFLWSMPLBOUND) && (x_inf <= UNDERFLWBOUND))
    || (((xIntHi_inf & 0x7fffffff) >= OVRUDRFLWSMPLBOUND) && (x_inf <= DENORMBOUND))
     ,FALSE))
  {
    ASSIGN_LOW(res,exp_rd(LOW(x)));
    ASSIGN_UP(res,exp_ru(UP(x)));
    return res;
  }

  /* Test if argument is a denormal or zero */
  /* If we are here, we are sure to be neither +/- Inf nor NaN nor overflowed nor denormalized in the argument
     but we might be denormalized in the result 

     We continue the argument reduction for the quick phase and table reads for both phases
  */

  Mul12(&s1_sup,&s2_sup,msLog2Div2Lh,kd_sup);
  Mul12(&s1_inf,&s2_inf,msLog2Div2Lh,kd_inf);
  s3_sup = kd_sup * msLog2Div2Lm;
  s3_inf = kd_inf * msLog2Div2Lm;
  s4_sup = s2_sup + s3_sup; 
  s4_inf = s2_inf + s3_inf; 
  s5_sup = x_sup + s1_sup;
  s5_inf = x_inf + s1_inf;
  Add12Cond(rh_sup,rm_sup,s5_sup,s4_sup);
  Add12Cond(rh_inf,rm_inf,s5_inf,s4_inf);
  k_sup = shiftedXMultdb_sup.i[LO];
  k_inf = shiftedXMultdb_inf.i[LO];
  M_sup = k_sup >> L;
  M_inf = k_inf >> L;
  index1_sup = k_sup & INDEXMASK1;
  index1_inf = k_inf & INDEXMASK1;
  index2_sup = (k_sup & INDEXMASK2) >> LHALF;
  index2_inf = (k_inf & INDEXMASK2) >> LHALF;

  /* Table reads */
  tbl1h_sup = twoPowerIndex1[index1_sup].hi;
  tbl1h_inf = twoPowerIndex1[index1_inf].hi;
  tbl1m_sup = twoPowerIndex1[index1_sup].mi;
  tbl1m_inf = twoPowerIndex1[index1_inf].mi;
  tbl2h_sup = twoPowerIndex2[index2_sup].hi;
  tbl2h_inf = twoPowerIndex2[index2_inf].hi;
  tbl2m_sup = twoPowerIndex2[index2_sup].mi;
  tbl2m_inf = twoPowerIndex2[index2_inf].mi;




  /* No more underflow nor denormal is possible. There may be the case where
     M is 1024 and the value 2^M is to be multiplied may be less than 1
     So the final result will be normalized and representable by the multiplication must be 
     made in 2 steps
  */

  /* Quick phase starts here */

  rhSquare_sup = rh_sup * rh_sup;
  rhSquare_inf = rh_inf * rh_inf;
  rhC3_sup = c3 * rh_sup;
  rhC3_inf = c3 * rh_inf;
  rhSquareHalf_sup = 0.5 * rhSquare_sup;
  rhSquareHalf_inf = 0.5 * rhSquare_inf;
  monomialCube_sup = rhC3_sup * rhSquare_sup;
  monomialCube_inf = rhC3_inf * rhSquare_inf;
  rhFour_sup = rhSquare_sup * rhSquare_sup;
  rhFour_inf = rhSquare_inf * rhSquare_inf;
  monomialFour_sup = c4 * rhFour_sup;
  monomialFour_inf = c4 * rhFour_inf;
  highPoly_sup = monomialCube_sup + monomialFour_sup;
  highPoly_inf = monomialCube_inf + monomialFour_inf;
  highPolyWithSquare_sup = rhSquareHalf_sup + highPoly_sup;
  highPolyWithSquare_inf = rhSquareHalf_inf + highPoly_inf;
  Mul22(&tablesh_sup,&tablesl_sup,tbl1h_sup,tbl1m_sup,tbl2h_sup,tbl2m_sup);
  Mul22(&tablesh_inf,&tablesl_inf,tbl1h_inf,tbl1m_inf,tbl2h_inf,tbl2m_inf);
  t8_sup = rm_sup + highPolyWithSquare_sup;
  t8_inf = rm_inf + highPolyWithSquare_inf;
  t9_sup = rh_sup + t8_sup;
  t9_inf = rh_inf + t8_inf;
  t10_sup = tablesh_sup * t9_sup;
  t10_inf = tablesh_inf * t9_inf;
  Add12(t11_sup,t12_sup,tablesh_sup,t10_sup);
  Add12(t11_inf,t12_inf,tablesh_inf,t10_inf);
  t13_sup = t12_sup + tablesl_sup;
  t13_inf = t12_inf + tablesl_inf;
  Add12(polyTblh_sup,polyTblm_sup,t11_sup,t13_sup);
  Add12(polyTblh_inf,polyTblm_inf,t11_inf,t13_inf);
  
  /* Rounding test 
     Since we know that the result of the final multiplication with 2^M 
     will always be representable, we can do the rounding test on the 
     factors and multiply only the final result.
     We implement the multiplication in integer computations to overcome
     the problem of the non-representability of 2^1024 if M = 1024
  */

  if (infDone==1) res_inf=res_simple_inf;
  if (supDone==1) res_sup=res_simple_sup;

//  TEST_AND_COPY_RDRU_EXP(roundable,infDone,supDone,res_inf,polyTblh_inf,polyTblm_inf,res_sup,polyTblh_sup,polyTblm_sup,RDROUNDCST);
  db_number yh_inf, yl_inf, u53_inf, yh_sup, yl_sup, u53_sup;
  int yh_inf_neg, yl_inf_neg, yh_sup_neg, yl_sup_neg;
  int rd_ok, ru_ok;
  double save_res_inf=res_inf;
  double save_res_sup=res_sup;
  yh_inf.d = polyTblh_inf;    yl_inf.d = polyTblm_inf;
  yh_inf_neg = (yh_inf.i[HI] & 0x80000000);
  yl_inf_neg = (yl_inf.i[HI] & 0x80000000);
  yh_inf.l = yh_inf.l & 0x7fffffffffffffffLL;  /* compute the absolute value*/
  yl_inf.l = yl_inf.l & 0x7fffffffffffffffLL;  /* compute the absolute value*/
  u53_inf.l     = (yh_inf.l & ULL(7ff0000000000000)) +  ULL(0010000000000000);
  yh_sup.d = polyTblh_sup;    yl_sup.d = polyTblm_sup;
  yh_sup_neg = (yh_sup.i[HI] & 0x80000000);
  yl_sup_neg = (yl_sup.i[HI] & 0x80000000);
  yh_sup.l = yh_sup.l & 0x7fffffffffffffffLL;  /* compute the absolute value*/
  yl_sup.l = yl_sup.l & 0x7fffffffffffffffLL;  /* compute the absolute value*/
  u53_sup.l     = (yh_sup.l & ULL(7ff0000000000000)) +  ULL(0010000000000000);
  roundable = 0;
  rd_ok=(yl_inf.d > RDROUNDCST * u53_inf.d);
  ru_ok=(yl_sup.d > RDROUNDCST * u53_sup.d);
     if(yl_inf_neg) {  /* The case yl==0 is filtered by the above test*/
      /* return next down */
       yh_inf.d = polyTblh_inf;
      if(yh_inf_neg) yh_inf.l++;  else yh_inf.l--; /* Beware: fails for zero */
      res_inf = yh_inf.d;
    }
    else {
      res_inf = polyTblh_inf;
    }
    if(!yl_sup_neg) {  /* The case yl==0 is filtered by the above test*/
      /* return next up */
      yh_sup.d = polyTblh_sup;
      if(yh_sup_neg) yh_sup.l--;  else yh_sup.l++; /* Beware: fails for zero */
      res_sup = yh_sup.d;
    }
    else {
      res_sup = polyTblh_sup;
    }
  if(infDone) res_inf=save_res_inf;
  if(supDone) res_sup=save_res_sup;
  if(rd_ok && ru_ok){
    roundable=3;
  }
  else if (rd_ok){
    roundable=1;
  }
  else if (ru_ok){
     roundable=2;
  }
  resdb_inf.d = res_inf;
  resdb_sup.d = res_sup;

  if (roundable==3)
  {
    if (infDone==0){
      resdb_inf.i[HI] += M_inf << 20;
    }
    ASSIGN_LOW(res,resdb_inf.d);
    if (supDone==0){
      resdb_sup.i[HI] += M_sup << 20;
    }
    ASSIGN_UP(res,resdb_sup.d);
    return res;
  }
  if(roundable==1)
  {
    if(infDone==0){
      resdb_inf.i[HI] += M_inf << 20;
    }
    ASSIGN_LOW(res,resdb_inf.d);
    if(supDone==0){
    /* Rest of argument reduction for accurate phase */
    Mul133(&msLog2Div2LMultKh_sup,&msLog2Div2LMultKm_sup,&msLog2Div2LMultKl_sup,kd_sup,msLog2Div2Lh,msLog2Div2Lm,msLog2Div2Ll);
    t1_sup = x_sup + msLog2Div2LMultKh_sup;
    Add12Cond(rh_sup,t2_sup,t1_sup,msLog2Div2LMultKm_sup);
    Add12Cond(rm_sup,rl_sup,t2_sup,msLog2Div2LMultKl_sup);
    /* Table reads for accurate phase */
    tbl1l_sup = twoPowerIndex1[index1_sup].lo;
    tbl2l_sup = twoPowerIndex2[index2_sup].lo;
    /* Call accurate phase */
    exp_td_accurate(&polyTblh_sup, &polyTblm_sup, &polyTbll_sup, rh_sup, rm_sup, rl_sup, tbl1h_sup, tbl1m_sup, tbl1l_sup, tbl2h_sup, tbl2m_sup, tbl2l_sup); 
    /* Since the final multiplication is exact, we can do the final rounding before multiplying
       We overcome this way also the cases where the final result is not underflowed whereas the
       lower parts of the intermediate final result are.
    */
    RoundUpwards3(&res_sup,polyTblh_sup,polyTblm_sup,polyTbll_sup);
    /* Final multiplication with 2^M 
       We implement the multiplication in integer computations to overcome
       the problem of the non-representability of 2^1024 if M = 1024
    */
    resdb_sup.d = res_sup;
    resdb_sup.i[HI] += M_sup << 20;
    }
    ASSIGN_UP(res,resdb_sup.d);
    return res;
  } /* Accurate phase launched after rounding test*/
    
  if (roundable==2) {
    if (infDone==0){
    /* Rest of argument reduction for accurate phase */
    Mul133(&msLog2Div2LMultKh_inf,&msLog2Div2LMultKm_inf,&msLog2Div2LMultKl_inf,kd_inf,msLog2Div2Lh,msLog2Div2Lm,msLog2Div2Ll);
    t1_inf = x_inf + msLog2Div2LMultKh_inf;
    Add12Cond(rh_inf,t2_inf,t1_inf,msLog2Div2LMultKm_inf);
    Add12Cond(rm_inf,rl_inf,t2_inf,msLog2Div2LMultKl_inf);
    /* Table reads for accurate phase */
    tbl1l_inf = twoPowerIndex1[index1_inf].lo;
    tbl2l_inf = twoPowerIndex2[index2_inf].lo;
    /* Call accurate phase */
    exp_td_accurate(&polyTblh_inf, &polyTblm_inf, &polyTbll_inf, rh_inf, rm_inf, rl_inf, tbl1h_inf, tbl1m_inf, tbl1l_inf, tbl2h_inf, tbl2m_inf, tbl2l_inf); 
    /* Since the final multiplication is exact, we can do the final rounding before multiplying
       We overcome this way also the cases where the final result is not underflowed whereas the
       lower parts of the intermediate final result are.
    */

    RoundDownwards3(&res_inf,polyTblh_inf,polyTblm_inf,polyTbll_inf);
    /* Final multiplication with 2^M 
       We implement the multiplication in integer computations to overcome
       the problem of the non-representability of 2^1024 if M = 1024
    */

    resdb_inf.d = res_inf;
    resdb_inf.i[HI] += M_inf << 20;
    }
    ASSIGN_LOW(res,resdb_inf.d);
    if(supDone==0){
      resdb_sup.i[HI] += M_sup << 20;
    }
    ASSIGN_UP(res,resdb_sup.d);    
    return res;
  } /* Accurate phase launched after rounding test*/
  if(roundable==0)
  {
    if(supDone==0){
    /* Rest of argument reduction for accurate phase */
    Mul133(&msLog2Div2LMultKh_sup,&msLog2Div2LMultKm_sup,&msLog2Div2LMultKl_sup,kd_sup,msLog2Div2Lh,msLog2Div2Lm,msLog2Div2Ll);
    t1_sup = x_sup + msLog2Div2LMultKh_sup;
    Add12Cond(rh_sup,t2_sup,t1_sup,msLog2Div2LMultKm_sup);
    Add12Cond(rm_sup,rl_sup,t2_sup,msLog2Div2LMultKl_sup);
    /* Table reads for accurate phase */
    tbl1l_sup = twoPowerIndex1[index1_sup].lo;
    tbl2l_sup = twoPowerIndex2[index2_sup].lo;
    /* Call accurate phase */
    exp_td_accurate(&polyTblh_sup, &polyTblm_sup, &polyTbll_sup, rh_sup, rm_sup, rl_sup, tbl1h_sup, tbl1m_sup, tbl1l_sup, tbl2h_sup, tbl2m_sup, tbl2l_sup); 
    /* Since the final multiplication is exact, we can do the final rounding before multiplying
       We overcome this way also the cases where the final result is not underflowed whereas the
       lower parts of the intermediate final result are.
    */
    RoundUpwards3(&res_sup,polyTblh_sup,polyTblm_sup,polyTbll_sup);
    /* Final multiplication with 2^M 
       We implement the multiplication in integer computations to overcome
       the problem of the non-representability of 2^1024 if M = 1024
    */
    resdb_sup.d = res_sup;
    resdb_sup.i[HI] += M_sup << 20;
    }
    ASSIGN_UP(res,resdb_sup.d);
    if (infDone==0){
    /* Rest of argument reduction for accurate phase */
    Mul133(&msLog2Div2LMultKh_inf,&msLog2Div2LMultKm_inf,&msLog2Div2LMultKl_inf,kd_inf,msLog2Div2Lh,msLog2Div2Lm,msLog2Div2Ll);
    t1_inf = x_inf + msLog2Div2LMultKh_inf;
    Add12Cond(rh_inf,t2_inf,t1_inf,msLog2Div2LMultKm_inf);
    Add12Cond(rm_inf,rl_inf,t2_inf,msLog2Div2LMultKl_inf);
    /* Table reads for accurate phase */
    tbl1l_inf = twoPowerIndex1[index1_inf].lo;
    tbl2l_inf = twoPowerIndex2[index2_inf].lo;
    /* Call accurate phase */
    exp_td_accurate(&polyTblh_inf, &polyTblm_inf, &polyTbll_inf, rh_inf, rm_inf, rl_inf, tbl1h_inf, tbl1m_inf, tbl1l_inf, tbl2h_inf, tbl2m_inf, tbl2l_inf); 
    /* Since the final multiplication is exact, we can do the final rounding before multiplying
       We overcome this way also the cases where the final result is not underflowed whereas the
       lower parts of the intermediate final result are.
    */

    RoundDownwards3(&res_inf,polyTblh_inf,polyTblm_inf,polyTbll_inf);
    /* Final multiplication with 2^M 
       We implement the multiplication in integer computations to overcome
       the problem of the non-representability of 2^1024 if M = 1024
    */

    resdb_inf.d = res_inf;
    resdb_inf.i[HI] += M_inf << 20;
    }
    ASSIGN_LOW(res,resdb_inf.d);
    return res;
  } /* Accurate phase launched after rounding test*/

  return res;
}
Esempio n. 16
0
 inline void TestSwap64() {
     UNIT_ASSERT_EQUAL(0x1234567890abcdefULL, SwapBytes((ui64)ULL(0xefcdab9078563412)));
 }
Esempio n. 17
0
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA */

#include <my_time.h>
#include <m_string.h>
#include <m_ctype.h>
/* Windows version of localtime_r() is declared in my_ptrhead.h */
#include <my_pthread.h>

ulonglong log_10_int[20]=
{
  1, 10, 100, 1000, 10000UL, 100000UL, 1000000UL, 10000000UL,
  ULL(100000000), ULL(1000000000), ULL(10000000000), ULL(100000000000),
  ULL(1000000000000), ULL(10000000000000), ULL(100000000000000),
  ULL(1000000000000000), ULL(10000000000000000), ULL(100000000000000000),
  ULL(1000000000000000000), ULL(10000000000000000000)
};


/* Position for YYYY-DD-MM HH-MM-DD.FFFFFF AM in default format */

static uchar internal_format_positions[]=
{0, 1, 2, 3, 4, 5, 6, (uchar) 255};

static char time_separator=':';

static ulong const days_at_timestart=719528;	/* daynr at 1970.01.01 */
uchar days_in_month[]= {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 0};
Esempio n. 18
0
/* parse execution range *RSTR to *RANGE */
char * /* error string, or NULL */
range_parse_range(char *rstr, /* execution range string */
struct range_range_t *range) /* range return buffer */
{
	char *pos1, *pos2, *p, buf[512], *errstr;

	/* make a copy of the execution range */
	strcpy(buf, rstr);
	pos1 = buf;

	/* find mid-point */
	p = buf;
	while (*p != ':' && *p != '\0') {
		p++;
	}
	if (*p != ':')
		return "badly formed execution range";
	*p = '\0';

	/* this is where the second position will start */
	pos2 = p + 1;

	/* parse start position */
	if (*pos1 && *pos1 != ':') {
		errstr = range_parse_pos(pos1, &range->start);
		if (errstr)
			return errstr;
	} else {
		/* default start range */
		range->start.ptype = pt_inst;
		range->start.pos = 0;
	}

	/* parse end position */
	if (*pos2) {
		if (*pos2 == '+') {
			int delta;
			char *endp;

			/* get delta value */
			errno = 0;
			delta = strtol(pos2 + 1, &endp, /* parse base */0);
			if (!errno && !*endp) {
				/* good conversion */
				range->end.ptype = range->start.ptype;
				range->end.pos = range->start.pos + delta;
			} else {
				/* bad conversion */
				return "badly formed execution range delta";
			}
		} else {
			errstr = range_parse_pos(pos2, &range->end);
			if (errstr)
				return errstr;
		}
	} else {
		/* default end range */
		range->end.ptype = range->start.ptype;
#ifdef HOST_HAS_QWORD
		range->end.pos = ULL(0x7fffffffffffffff);
#else /* !__GNUC__ */
		range->end.pos = 281474976645120.0;
#endif /* __GNUC__ */
	}

	/* no error */
	return NULL;
}
Esempio n. 19
0
	pRtlLargeIntegerToChar = (void *)GetProcAddress(hntdll, "RtlLargeIntegerToChar");
	pRtlUnicodeStringToAnsiString = (void *)GetProcAddress(hntdll, "RtlUnicodeStringToAnsiString");
    } /* if */
}

#define ULL(a,b) (((ULONGLONG)(a) << 32) | (b))

typedef struct {
    LONGLONG a;
    LONGLONG b;
    INT shift;
    LONGLONG result;
} magic_divide_t;

static const magic_divide_t magic_divide[] = {
    {                          3,  ULL(0x55555555,0x55555555), 0,                   0}, /* 1 */
    {                  333333333,  ULL(0x55555555,0x55555555), 0,           111111110}, /* 111111111 */
    { ULL(0x7fffffff,0xffffffff),  ULL(0x55555555,0x55555555), 0,  ULL(0x2aaaaaaa,0xaaaaaaaa)},
    {                          3,  ULL(0xaaaaaaaa,0xaaaaaaaa), 1,                   0}, /* 1 */
    {                  333333333,  ULL(0xaaaaaaaa,0xaaaaaaaa), 1,           111111110}, /* 111111111 */
    { ULL(0x7fffffff,0xffffffff),  ULL(0xaaaaaaaa,0xaaaaaaaa), 1,  ULL(0x2aaaaaaa,0xaaaaaaaa)},
    {                         -3,  ULL(0x55555555,0x55555555), 0,                   0}, /* -1 */
    {                 -333333333,  ULL(0x55555555,0x55555555), 0,          -111111110}, /* -111111111 */
    {-ULL(0x7fffffff,0xffffffff),  ULL(0x55555555,0x55555555), 0, -ULL(0x2aaaaaaa,0xaaaaaaaa)},
    {                         -3,  ULL(0xaaaaaaaa,0xaaaaaaaa), 1,                   0}, /* -1 */
    {                 -333333333,  ULL(0xaaaaaaaa,0xaaaaaaaa), 1,          -111111110}, /* -111111111 */
    {-ULL(0x7fffffff,0xffffffff),  ULL(0xaaaaaaaa,0xaaaaaaaa), 1, -ULL(0x2aaaaaaa,0xaaaaaaaa)},
    {                         -3, -ULL(0x55555555,0x55555555), 0,                  -2}, /* -1 */
    {                 -333333333, -ULL(0x55555555,0x55555555), 0,          -222222222}, /* -111111111 */
    {-ULL(0x7fffffff,0xffffffff), -ULL(0x55555555,0x55555555), 0, -ULL(0x55555555,0x55555554)},
    {                         -3, -ULL(0xaaaaaaaa,0xaaaaaaaa), 1,                   0}, /* -1 */
Esempio n. 20
0
File: perft.cpp Progetto: pd/benthos
	// smirf1
	{ 5, 6 },
	// smirf2
	{ 6, 8 },
	// smirf3
	{ 7, 8 },
	// smirf4
	{ 6, 8 },
	// smirf5
	{ 6, 7 },
};
// the expected results for each depth of each position.
uint64 expected_results[KNOWN_POSITIONS][9] = {
	// starting
	{
		ULL(20),        ULL(400),         ULL(8902),       ULL(197281),
		ULL(4865609),   ULL(119060324),   ULL(3195901860), ULL(84998978956),
		ULL(2439530234167),
	},
	// mixed
	{
		ULL(48),        ULL(2039),        ULL(97862),      ULL(4085603),
		ULL(193690690), ULL(8031647685),  ULL(0),          ULL(0),
		ULL(0),
	},
	// castle
	{
		ULL(47),        ULL(2409),        ULL(111695),     ULL(5664262),
		ULL(269506799), ULL(13523904666), ULL(0),          ULL(0),
		ULL(0),
	},
Esempio n. 21
0
void tai_now(struct tai *t)
{
  t->x = ULL(4611686018427387914) + (uint64_t) time((time_t *) 0);
}
Esempio n. 22
0
 interval j_log(interval x)
 {
   interval res;
   int roundable;
   int cs_inf=0; int cs_sup=0;
   double x_inf,x_sup;
   x_inf=LOW(x);
   x_sup=UP(x);
   double res_inf, res_sup, res_simple_inf, res_simple_sup;

   db_number xdb_sup;
   double y_sup, ed_sup, ri_sup, logih_sup, logim_sup, yrih_sup, yril_sup, th_sup, zh_sup, zl_sup;
   double polyHorner_sup, zhSquareh_sup, zhSquarel_sup, polyUpper_sup, zhSquareHalfh_sup, zhSquareHalfl_sup;
   double t1h_sup, t1l_sup, t2h_sup, t2l_sup, ph_sup, pl_sup, log2edh_sup, log2edl_sup, logTabPolyh_sup, logTabPolyl_sup, logh_sup, logm_sup, logl_sup, roundcst;
   int E_sup, index_sup;
   

   db_number xdb_inf;
   double y_inf, ed_inf, ri_inf, logih_inf, logim_inf, yrih_inf, yril_inf, th_inf, zh_inf, zl_inf;
   double polyHorner_inf, zhSquareh_inf, zhSquarel_inf, polyUpper_inf, zhSquareHalfh_inf, zhSquareHalfl_inf;
   double t1h_inf, t1l_inf, t2h_inf, t2l_inf, ph_inf, pl_inf, log2edh_inf, log2edl_inf, logTabPolyh_inf, logTabPolyl_inf, logh_inf, logm_inf, logl_inf;
   int E_inf, index_inf;

   E_inf=0;
   xdb_inf.d=x_inf;
   E_sup=0;
   xdb_sup.d=x_sup;

   if (__builtin_expect(
      (x_inf == 1.0) || (!(x_inf<=x_sup)) || (xdb_sup.i[HI] < 0) 
   || (xdb_inf.i[HI] < 0x00100000) || (((xdb_inf.i[HI] & 0x7fffffff)|xdb_inf.i[LO])==0) 
   || (xdb_inf.i[HI] < 0)
   || (xdb_inf.i[HI] >= 0x7ff00000)
   || (x_sup == 1.0)
   || (xdb_sup.i[HI] < 0x00100000)
   || (((xdb_sup.i[HI] & 0x7fffffff)|xdb_sup.i[LO])==0)
   || (xdb_sup.i[HI] < 0)
   || (xdb_sup.i[HI] >= 0x7ff00000)
   || ((xdb_inf.d<00) && (xdb_sup.d>0) )
   ,FALSE))
   {
     if (!(x_inf<=x_sup)) RETURN_EMPTY_INTERVAL;
     if (xdb_sup.i[HI] < 0) RETURN_EMPTY_INTERVAL;
     if ((xdb_inf.d<00) && (xdb_sup.d>0) )
     {
       ASSIGN_LOW(res,-1.0/0.0);
       ASSIGN_UP(res,log_ru(UP(x)));
       return res;
     }
     ASSIGN_LOW(res,log_rd(LOW(x)));
     ASSIGN_UP(res,log_ru(UP(x)));
     return res;
   }
   /* Extract exponent and mantissa 
      Do range reduction,
      yielding to E holding the exponent and
      y the mantissa between sqrt(2)/2 and sqrt(2)
   */
   E_inf += (xdb_inf.i[HI]>>20)-1023;             /* extract the exponent */
   E_sup += (xdb_sup.i[HI]>>20)-1023;             /* extract the exponent */
   index_inf = (xdb_inf.i[HI] & 0x000fffff);
   index_sup = (xdb_sup.i[HI] & 0x000fffff);
   xdb_inf.i[HI] =  index_inf | 0x3ff00000;	/* do exponent = 0 */
   xdb_sup.i[HI] =  index_sup | 0x3ff00000;	/* do exponent = 0 */
   index_inf = (index_inf + (1<<(20-L-1))) >> (20-L);
   index_sup = (index_sup + (1<<(20-L-1))) >> (20-L);
   /* reduce  such that sqrt(2)/2 < xdb.d < sqrt(2) */
   if (index_inf >= MAXINDEX){ /* corresponds to xdb>sqrt(2)*/
     xdb_inf.i[HI] -= 0x00100000; 
     E_inf++;
   }
   /* reduce  such that sqrt(2)/2 < xdb.d < sqrt(2) */
   if (index_sup >= MAXINDEX){ /* corresponds to xdb>sqrt(2)*/
     xdb_sup.i[HI] -= 0x00100000; 
     E_sup++;
   }
   y_inf = xdb_inf.d;
   y_sup = xdb_sup.d;
   index_inf = index_inf & INDEXMASK;
   index_sup = index_sup & INDEXMASK;
   /* Cast integer E into double ed for multiplication later */
   ed_inf = (double) E_inf;
   ed_sup = (double) E_sup;
   /* 
      Read tables:
      Read one float for ri
      Read the first two doubles for -log(r_i) (out of three)
      Organization of the table:
      one struct entry per index, the struct entry containing 
      r, logih, logim and logil in this order
   */
   ri_inf = argredtable[index_inf].ri;
   ri_sup = argredtable[index_sup].ri;
   /* 
      Actually we don't need the logarithm entries now
      Move the following two lines to the eventual reconstruction
      As long as we don't have any if in the following code, we can overlap 
      memory access with calculations 
   */
   logih_inf = argredtable[index_inf].logih;
   logih_sup = argredtable[index_sup].logih;
   logim_inf = argredtable[index_inf].logim;
   logim_sup = argredtable[index_sup].logim;
   /* Do range reduction:
      zh + zl = y * ri - 1.0 correctly
      Correctness is assured by use of Mul12 and Add12
      even if we don't force ri to have its' LSBs set to zero
      Discard zl for higher monome degrees
   */

   Mul12(&yrih_inf, &yril_inf, y_inf, ri_inf);
   Mul12(&yrih_sup, &yril_sup, y_sup, ri_sup);
   th_inf = yrih_inf - 1.0; 
   th_sup = yrih_sup - 1.0; 
   /* Do range reduction:
      zh + zl = y * ri - 1.0 correctly
      Correctness is assured by use of Mul12 and Add12
      even if we don't force ri to have its' LSBs set to zero
      Discard zl for higher monome degrees
   */


   Add12Cond(zh_inf, zl_inf, th_inf, yril_inf); 
   Add12Cond(zh_sup, zl_sup, th_sup, yril_sup); 
   /* 
      Polynomial evaluation
      Use a 7 degree polynomial
      Evaluate the higher 5 terms in double precision (-7 * 3 = -21) using Horner's scheme
      Evaluate the lower 3 terms (the last is 0) in double double precision accounting also for zl
      using an ad hoc method
   */



#if defined(PROCESSOR_HAS_FMA) && !defined(AVOID_FMA)
   polyHorner_inf = FMA(FMA(FMA(FMA(c7,zh_inf,c6),zh_inf,c5),zh_inf,c4),zh_inf,c3);
   polyHorner_sup = FMA(FMA(FMA(FMA(c7,zh_sup,c6),zh_sup,c5),zh_sup,c4),zh_sup,c3);
#else
   polyHorner_inf = c3 + zh_inf * (c4 + zh_inf * (c5 + zh_inf * (c6 + zh_inf * c7)));
   polyHorner_sup = c3 + zh_sup * (c4 + zh_sup * (c5 + zh_sup * (c6 + zh_sup * c7)));
#endif

   Mul12(&zhSquareh_inf, &zhSquarel_inf, zh_inf, zh_inf);
   Mul12(&zhSquareh_sup, &zhSquarel_sup, zh_sup, zh_sup);
   polyUpper_inf = polyHorner_inf * (zh_inf * zhSquareh_inf);
   polyUpper_sup = polyHorner_sup * (zh_sup * zhSquareh_sup);
   zhSquareHalfh_inf = zhSquareh_inf * -0.5;
   zhSquareHalfh_sup = zhSquareh_sup * -0.5;
   zhSquareHalfl_inf = zhSquarel_inf * -0.5;
   zhSquareHalfl_sup = zhSquarel_sup * -0.5;
   Add12(t1h_inf, t1l_inf, polyUpper_inf, -1 * (zh_inf * zl_inf));
   Add12(t1h_sup, t1l_sup, polyUpper_sup, -1 * (zh_sup * zl_sup));
   Add22(&t2h_inf, &t2l_inf, zh_inf, zl_inf, zhSquareHalfh_inf, zhSquareHalfl_inf);
   Add22(&t2h_sup, &t2l_sup, zh_sup, zl_sup, zhSquareHalfh_sup, zhSquareHalfl_sup);
   Add22(&ph_inf, &pl_inf, t2h_inf, t2l_inf, t1h_inf, t1l_inf);
   Add22(&ph_sup, &pl_sup, t2h_sup, t2l_sup, t1h_sup, t1l_sup);
   /* Reconstruction 

      Read logih and logim in the tables (already done)
     
      Compute log(x) = E * log(2) + log(1+z) - log(ri)
      i.e. log(x) = ed * (log2h + log2m) + (ph + pl) + (logih + logim) + delta

      Carry out everything in double double precision

   */
   
   /* 
      We store log2 as log2h + log2m + log2l where log2h and log2m have 12 trailing zeros
      Multiplication of ed (double E) and log2h is thus correct
      The overall accuracy of log2h + log2m + log2l is 53 * 3 - 24 = 135 which
      is enough for the accurate phase
      The accuracy suffices also for the quick phase: 53 * 2 - 24 = 82
      Nevertheless the storage with trailing zeros implies an overlap of the tabulated
      triple double values. We have to take it into account for the accurate phase 
      basic procedures for addition and multiplication
      The condition on the next Add12 is verified as log2m is smaller than log2h 
      and both are scaled by ed
   */

   Add12(log2edh_inf, log2edl_inf, log2h * ed_inf, log2m * ed_inf);

   /* 
      We store log2 as log2h + log2m + log2l where log2h and log2m have 12 trailing zeros
      Multiplication of ed (double E) and log2h is thus correct
      The overall accuracy of log2h + log2m + log2l is 53 * 3 - 24 = 135 which
      is enough for the accurate phase
      The accuracy suffices also for the quick phase: 53 * 2 - 24 = 82
      Nevertheless the storage with trailing zeros implies an overlap of the tabulated
      triple double values. We have to take it into account for the accurate phase 
      basic procedures for addition and multiplication
      The condition on the next Add12 is verified as log2m is smaller than log2h 
      and both are scaled by ed
   */

   Add12(log2edh_sup, log2edl_sup, log2h * ed_sup, log2m * ed_sup);


   /* Add logih and logim to ph and pl 

      We must use conditioned Add22 as logih can move over ph
   */

   Add22Cond(&logTabPolyh_inf, &logTabPolyl_inf, logih_inf, logim_inf, ph_inf, pl_inf);

   /* Add log2edh + log2edl to logTabPolyh + logTabPolyl */
  
   Add22Cond(&logh_inf, &logm_inf, log2edh_inf, log2edl_inf, logTabPolyh_inf, logTabPolyl_inf);

   /* Add logih and logim to ph and pl 

      We must use conditioned Add22 as logih can move over ph
   */

   Add22Cond(&logTabPolyh_sup, &logTabPolyl_sup, logih_sup, logim_sup, ph_sup, pl_sup);

   /* Add log2edh + log2edl to logTabPolyh + logTabPolyl */

   Add22Cond(&logh_sup, &logm_sup, log2edh_sup, log2edl_sup, logTabPolyh_sup, logTabPolyl_sup);


   /* Rounding test and eventual return or call to the accurate function */

   roundcst = RDROUNDCST1;

   if(cs_inf) { res_inf=res_simple_inf; }
   if(cs_sup) { res_sup=res_simple_sup; }
   //TEST_AND_COPY_RDRU_LOG(roundable,res_inf,logh_inf,logm_inf,res_sup,logh_sup,logm_sup,roundcst);

//#define TEST_AND_COPY_RDRU_LOG(__cond__, __res_inf__, __yh_inf__, __yl_inf__, __res_sup__, __yh_sup__, __yl_sup__, __eps__)  
                                                                      
  db_number yh_inf, yl_inf, u53_inf, yh_sup, yl_sup, u53_sup;                    
  int yh_inf_neg, yl_inf_neg, yh_sup_neg, yl_sup_neg;                             
  int rd_ok, ru_ok;                                                        
  double save_res_inf=res_inf;                                              
  yh_inf.d = logh_inf;    yl_inf.d = logm_inf;
  yh_inf_neg = (yh_inf.i[HI] & 0x80000000);                                    
  yl_inf_neg = (yl_inf.i[HI] & 0x80000000);                                    
  yh_inf.l = yh_inf.l & 0x7fffffffffffffffLL;  /* compute the absolute value*/ 
  yl_inf.l = yl_inf.l & 0x7fffffffffffffffLL;  /* compute the absolute value*/ 
  u53_inf.l     = (yh_inf.l & ULL(7ff0000000000000)) +  ULL(0010000000000000); 
  yh_sup.d = logh_sup;    yl_sup.d = logm_sup;
  yh_sup_neg = (yh_sup.i[HI] & 0x80000000);                                    
  yl_sup_neg = (yl_sup.i[HI] & 0x80000000);                                    
  yh_sup.l = yh_sup.l & 0x7fffffffffffffffLL;  /* compute the absolute value*/ 
  yl_sup.l = yl_sup.l & 0x7fffffffffffffffLL;  /* compute the absolute value*/ 
  u53_sup.l     = (yh_sup.l & ULL(7ff0000000000000)) +  ULL(0010000000000000); 
  roundable = 0;
  rd_ok=(yl_inf.d > roundcst * u53_inf.d);
  ru_ok=(yl_sup.d > roundcst * u53_sup.d);
     if(yl_inf_neg) {  /* The case yl==0 is filtered by the above test*/    
      /* return next down */                                           
      yh_inf.d = logh_inf;                                                   
      if(yh_inf_neg) yh_inf.l++;  else yh_inf.l--; /* Beware: fails for zero */
      res_inf = yh_inf.d ;
    }
    else {
      res_inf = logh_inf;
    }
    if(!yl_sup_neg) {  /* The case yl==0 is filtered by the above test*/
      /* return next up */
      yh_sup.d = logh_sup;
      if(yh_sup_neg) yh_sup.l--;  else yh_sup.l++; /* Beware: fails for zero */    
      res_sup = yh_sup.d ;                                                 
    }                                                                  
    else {
      res_sup = logh_sup;
    }
  if(save_res_inf==-1.0/0.0) res_inf=-1.0/0.0;
  if(rd_ok && ru_ok){
    ASSIGN_LOW(res,res_inf);
    ASSIGN_UP(res,res_sup);
    return(res);
  }
  else if (rd_ok){
    roundable=1;
  }
  else if (ru_ok){
     roundable=2;
  }


#if DEBUG
   printf("Going for Accurate Phase for x=%1.50e\n",x);
#endif
   if (roundable==1)
   {
     log_td_accurate(&logh_sup, &logm_sup, &logl_sup, E_sup, ed_sup, index_sup, zh_sup, zl_sup, logih_sup, logim_sup); 
     RoundUpwards3(&res_sup, logh_sup, logm_sup, logl_sup);
   }

   if (roundable==2)
   {
     log_td_accurate(&logh_inf, &logm_inf, &logl_inf, E_inf, ed_inf, index_inf, zh_inf, zl_inf, logih_inf, logim_inf); 
     RoundDownwards3(&res_inf, logh_inf, logm_inf, logl_inf);
   }
   if (roundable==0)
   {
     log_td_accurate(&logh_inf, &logm_inf, &logl_inf, E_inf, ed_inf, index_inf, zh_inf, zl_inf, logih_inf, logim_inf); 
     RoundDownwards3(&res_inf, logh_inf, logm_inf, logl_inf);
     log_td_accurate(&logh_sup, &logm_sup, &logl_sup, E_sup, ed_sup, index_sup, zh_sup, zl_sup, logih_sup, logim_sup); 
     RoundUpwards3(&res_sup, logh_sup, logm_sup, logl_sup);
   }
   ASSIGN_LOW(res,res_inf);
   ASSIGN_UP(res,res_sup);
   return res;
 }
Esempio n. 23
0
//parse execution range *RSTR to *RANGE, returns error string or NULL
const char * range_parse_range(const char *rstr,	//execution range string
	range_range_t *range,				//range return buffer
	mem_t* my_mem)
{
	const char *errstr;

	//make a copy of the execution range
	std::string buf(rstr);

	//find mid-point
	std::size_t findcolon = buf.find(":");
	if(findcolon==std::string::npos)
		return "Badly formed execution range";

	buf[findcolon] = static_cast<char>(NULL);

	//this is where the second position will start
	findcolon++;

	//parse start position
	if((buf[0]!=static_cast<char>(NULL)) && (buf[0]!=':'))
	{
		errstr = range_parse_pos(&buf[0], &range->start, my_mem);
		if(errstr)
			return errstr;
	}
	else
	{
		//default start range
		range->start.ptype = pt_inst;
		range->start.pos = 0;
	}

	//parse end position
	if(buf[findcolon]!=static_cast<char>(NULL))
	{
		if(buf[findcolon] == '+')
		{
			char *endp;

			//get delta value
			errno = 0;
			int delta = strtol(&buf[findcolon+1], &endp, /*parse base*/0);
			if(!errno && !*endp)
			{
				//good conversion
				range->end.ptype = range->start.ptype;
				range->end.pos = range->start.pos + delta;
			}
			else
			{
				//bad conversion
				return "badly formed execution range delta";
			}
		}
		else
		{
			errstr = range_parse_pos(&buf[findcolon], &range->end, my_mem);
			if(errstr)
				return errstr;
		}
	}
	else
	{
		//default end range
		range->end.ptype = range->start.ptype;
		range->end.pos = ULL(0x7fffffffffffffff);
	}

	//no error
	return NULL;
}