Example #1
0
void speed()
{
	for (int k = 0; k < 5; k++) {
		UNPACK(9)(input, output);
		clock_t begin = clock();
		for (int i = 0; i < 10000 * 10000 * 10; i++) {
			for (int v = 0; v < 1/*BLOCKCOUNT / minimums[11]*/; v++) {
				UNPACK(9)(input, output);
			}
		}
		clock_t end = clock();
		printf("%f\n", (double)(end - begin) / CLOCKS_PER_SEC);
		sleep(1);
	}
}
Example #2
0
File: ht.c Project: taysom/tau
STATIC Key_t get_key(Node_s *node, unint i)
{
	Key_t	key;
	unint	x;
	u8	*start;

	aver(i < node->numrecs);
	x = node->rec[i];
	aver(x < BLOCK_SIZE);
	start = &((u8 *)node)[x];
	UNPACK(start, key);
	return key;
}
Example #3
0
File: ht.c Project: taysom/tau
STATIC Hrec_s get_rec(Node_s *node, unint i)
{
	Hrec_s	rec;
	unint	x;
	u8	*start;

	aver(i < node->numrecs);
	x = node->rec[i];
	aver(x < BLOCK_SIZE);
	start = &((u8 *)node)[x];

	UNPACK(start, rec.key);
	start += sizeof(Key_t);
	rec.val.size = *start++;
	rec.val.size |= (*start++) << 8;
	rec.val.d = start;
	return rec;
}
Example #4
0
size_t put_fread(const char * const path) {
	/*
	Opens the file.
	*/
	FILE * const stream = fopen(path, "rb");
	if (stream == NULL) {
		probno = log_error(INPUT_OPEN_PROBLEM);
		return 0;
	}

	/*
	Reads the header.
	*/
	unsigned char header[1024];
	size_t result = 0;
	if (fread(&header[0], sizeof header, 1, stream) != 1) {
		probno = log_error(INPUT_READ_PROBLEM);
	}

	unsigned char * position = &header[0];
	if (strcmp((char * )position, &record_type[0]) != 0) {
		probno = log_error(INPUT_FORMAT_PROBLEM);
		goto hell;
	}
	position += (ptrdiff_t )sizeof record_type;
	strcpy(record.author, (char * )position);
	position += (ptrdiff_t )sizeof record.author;
	strcpy(record.executable, (char * )position);
	position += (ptrdiff_t )sizeof record.executable;
	strcpy(record.comments, (char * )position);
	position += (ptrdiff_t )sizeof record.comments;
	UNPACK(record.category, position);
	position += (ptrdiff_t )sizeof record.category;
	UNPACK(record.frames, position);
	position += (ptrdiff_t )sizeof record.frames;
	UNPACK(record.time, position);
	position += (ptrdiff_t )sizeof record.time;
	UNPACK(record.turns, position);
	position += (ptrdiff_t )sizeof record.turns;
	result++;

	/*
	Reads the chunks.
	*/
	frame_d frame;
	unsigned char chunk[sizeof frame.duration + sizeof frame.value];
	do {
		if (fread(&chunk[0], sizeof chunk, 1, stream) != 1) {
			if (feof(stream) == 0) {
				probno = log_error(INPUT_READ_PROBLEM);
				goto hell;
			}
			else {
				break;
			}
		}
		else {
			unsigned char * position = &chunk[0];
			UNPACK(frame.duration, position);
			position += (ptrdiff_t )sizeof frame.duration;
			UNPACK(frame.value, position);
			position += (ptrdiff_t )sizeof frame.value;
			if (rec_add_frame(frame.duration, frame.value) == NULL) {
				probno = log_error(INPUT_FRAME_PROBLEM);
				goto hell;
			}
			else {
				result++;
			}
		}
	} while (TRUE);

	/*
	Closes the file.
	*/
	hell: if (fclose(stream) == EOF) {
		probno = log_error(INPUT_CLOSE_PROBLEM);
	}

	return result;
}
Example #5
0
static void
to_float(void *data, int num_chan, GLenum type, float *out)
{
	int i;

	switch (type) {
	case GL_UNSIGNED_BYTE_3_3_2:
		assert(num_chan == 3);
		out[0] = un_to_float(3, UNPACK(*(GLubyte *)data, 3, 5));
		out[1] = un_to_float(3, UNPACK(*(GLubyte *)data, 3, 2));
		out[2] = un_to_float(2, UNPACK(*(GLubyte *)data, 2, 0));
		break;
	case GL_UNSIGNED_BYTE_2_3_3_REV:
		assert(num_chan == 3);
		out[0] = un_to_float(3, UNPACK(*(GLubyte *)data, 3, 0));
		out[1] = un_to_float(3, UNPACK(*(GLubyte *)data, 3, 3));
		out[2] = un_to_float(2, UNPACK(*(GLubyte *)data, 2, 6));
		break;
	case GL_UNSIGNED_SHORT_5_6_5:
		assert(num_chan == 3);
		out[0] = un_to_float(5, UNPACK(*(GLushort *)data, 5, 11));
		out[1] = un_to_float(6, UNPACK(*(GLushort *)data, 6, 5));
		out[2] = un_to_float(5, UNPACK(*(GLushort *)data, 5, 0));
		break;
	case GL_UNSIGNED_SHORT_5_6_5_REV:
		assert(num_chan == 3);
		out[0] = un_to_float(5, UNPACK(*(GLushort *)data, 5, 0));
		out[1] = un_to_float(6, UNPACK(*(GLushort *)data, 6, 5));
		out[2] = un_to_float(5, UNPACK(*(GLushort *)data, 5, 11));
		break;
	case GL_UNSIGNED_SHORT_4_4_4_4:
		assert(num_chan == 4);
		out[0] = un_to_float(4, UNPACK(*(GLushort *)data, 4, 12));
		out[1] = un_to_float(4, UNPACK(*(GLushort *)data, 4, 8));
		out[2] = un_to_float(4, UNPACK(*(GLushort *)data, 4, 4));
		out[3] = un_to_float(4, UNPACK(*(GLushort *)data, 4, 0));
		break;
	case GL_UNSIGNED_SHORT_4_4_4_4_REV:
		assert(num_chan == 4);
		out[0] = un_to_float(4, UNPACK(*(GLushort *)data, 4, 0));
		out[1] = un_to_float(4, UNPACK(*(GLushort *)data, 4, 4));
		out[2] = un_to_float(4, UNPACK(*(GLushort *)data, 4, 8));
		out[3] = un_to_float(4, UNPACK(*(GLushort *)data, 4, 12));
		break;
	case GL_UNSIGNED_SHORT_5_5_5_1:
		assert(num_chan == 4);
		out[0] = un_to_float(5, UNPACK(*(GLushort *)data, 5, 11));
		out[1] = un_to_float(5, UNPACK(*(GLushort *)data, 5, 6));
		out[2] = un_to_float(5, UNPACK(*(GLushort *)data, 5, 1));
		out[3] = un_to_float(1, UNPACK(*(GLushort *)data, 1, 0));
		break;
	case GL_UNSIGNED_SHORT_1_5_5_5_REV:
		assert(num_chan == 4);
		out[0] = un_to_float(5, UNPACK(*(GLushort *)data, 5, 0));
		out[1] = un_to_float(5, UNPACK(*(GLushort *)data, 5, 5));
		out[2] = un_to_float(5, UNPACK(*(GLushort *)data, 5, 10));
		out[3] = un_to_float(1, UNPACK(*(GLushort *)data, 1, 15));
		break;
	case GL_UNSIGNED_INT_10_10_10_2:
		assert(num_chan == 4);
		out[0] = un_to_float(10, UNPACK(*(GLuint *)data, 10, 22));
		out[1] = un_to_float(10, UNPACK(*(GLuint *)data, 10, 12));
		out[2] = un_to_float(10, UNPACK(*(GLuint *)data, 10, 2));
		out[3] = un_to_float(2, UNPACK(*(GLuint *)data, 2, 0));
		break;
	case GL_UNSIGNED_INT_2_10_10_10_REV:
		assert(num_chan == 4);
		out[0] = un_to_float(10, UNPACK(*(GLuint *)data, 10, 0));
		out[1] = un_to_float(10, UNPACK(*(GLuint *)data, 10, 10));
		out[2] = un_to_float(10, UNPACK(*(GLuint *)data, 10, 20));
		out[3] = un_to_float(2, UNPACK(*(GLuint *)data, 2, 30));
		break;
	case GL_UNSIGNED_INT_8_8_8_8:
		assert(num_chan == 4);
		out[0] = un_to_float(8, UNPACK(*(GLuint *)data, 8, 24));
		out[1] = un_to_float(8, UNPACK(*(GLuint *)data, 8, 16));
		out[2] = un_to_float(8, UNPACK(*(GLuint *)data, 8, 8));
		out[3] = un_to_float(8, UNPACK(*(GLuint *)data, 8, 0));
		break;
	case GL_UNSIGNED_INT_8_8_8_8_REV:
		assert(num_chan == 4);
		out[0] = un_to_float(8, UNPACK(*(GLuint *)data, 8, 0));
		out[1] = un_to_float(8, UNPACK(*(GLuint *)data, 8, 8));
		out[2] = un_to_float(8, UNPACK(*(GLuint *)data, 8, 16));
		out[3] = un_to_float(8, UNPACK(*(GLuint *)data, 8, 24));
		break;
	case GL_BYTE:
		for (i = 0; i < num_chan; ++i)
			out[i] = sn_to_float(8, ((GLbyte *)data)[i]);
		break;
	case GL_UNSIGNED_BYTE:
		for (i = 0; i < num_chan; ++i)
			out[i] = un_to_float(8, ((GLubyte *)data)[i]);
		break;
	case GL_SHORT:
		for (i = 0; i < num_chan; ++i)
			out[i] = sn_to_float(16, ((GLshort *)data)[i]);
		break;
	case GL_UNSIGNED_SHORT:
		for (i = 0; i < num_chan; ++i)
			out[i] = un_to_float(16, ((GLushort *)data)[i]);
		break;
	case GL_FLOAT:
		for (i = 0; i < num_chan; ++i)
			out[i] = ((float *)data)[i];
		break;
	case GL_INT:
		for (i = 0; i < num_chan; ++i)
			out[i] = sn_to_float(32, ((GLint *)data)[i]);
		break;
	case GL_UNSIGNED_INT:
		for (i = 0; i < num_chan; ++i)
			out[i] = un_to_float(32, ((GLuint *)data)[i]);
		break;
	default:
		assert(!"Invalid type");
	}
}
Example #6
0
File: pack.c Project: UIKit0/gnet
/**
 *  gnet_vunpack
 *  @format: unpack data format
 *  @buffer: buffer to unpack from
 *  @length: length of @buffer
 *  @args: var args
 *
 *  Var arg interface to gnet_unpack().  See gnet_unpack() for more
 *  information.
 *
 *  Returns: number of bytes packed; -1 on error.
 *
 **/
gint 
gnet_vunpack (const gchar * format, const gchar * buffer, gint length,
    va_list args)
{
  gint n = 0;
  gchar* p = (gchar*) format;
  guint mult = 0;
  gint sizemode = 0;	/* 1 = little, 2 = big */

  g_return_val_if_fail (format, -1);
  g_return_val_if_fail (buffer, -1);

  switch (*p)
    {
    case '@':					++p;	break;
    case '<':	sizemode = 1;			++p;	break;
    case '>':	
    case '!':	sizemode = 2;			++p;	break;
    }

  for (; *p; ++p)
    {
      switch (*p)
	{
	case 'x': 
	  {	
	    mult = mult? mult:1;
	    g_return_val_if_fail (n + mult <= length, FALSE);

	    buffer += mult;
	    n += mult;

	    mult = 0;
	    break; 
	  }

	case 'b':  { UNPACK(gint8); 			break;	}
	case 'B':  { UNPACK(guint8);			break;	}

	case 'h':  { UNPACK2(short, gint16); 		break;  }
	case 'H':  { UNPACK2(unsigned short, guint16);	break;  }

	case 'i':  { UNPACK2(int, gint32); 		break;  }
	case 'I':  { UNPACK2(unsigned int, guint32); 	break;  }

	case 'l':  { UNPACK2(long, gint32); 		break;  }
	case 'L':  { UNPACK2(unsigned long, guint32);	break;  }

	case 'f':  { UNPACK(float);			break;  }
	case 'd':  { UNPACK(double);			break;  }

	case 'v':  { UNPACK2(void*, void*); 		break;	}

	case 's':
	  { 
	    for (mult=(mult?mult:1); mult; --mult)
	      {
		gchar** sp; 
		gsize slen;

		sp = va_arg (args, gchar**);
		g_return_val_if_fail (sp, -1);

		slen = strlenn(buffer, length - n);
		g_return_val_if_fail (n + slen <= length, FALSE);

		*sp = g_new(gchar, slen + 1);
		memcpy (*sp, buffer, slen);
		(*sp)[slen] = 0;
		buffer += slen + 1;
		n += slen + 1;
	      }

	    mult = 0; 
	    break;
	  }

	case 'S':
	  { 
	    gchar** sp; 
	    gsize slen;

	    g_return_val_if_fail (mult, -1);

	    sp = va_arg (args, gchar**);
	    g_return_val_if_fail (sp, -1);

	    slen = MIN(mult, strlenn(buffer, length - n));
	    g_return_val_if_fail ((n + slen) <= length, -1);

	    *sp = g_new(gchar, mult + 1);

	    memcpy (*sp, buffer, slen);
	    while (slen < (mult + 1)) (*sp)[slen++] = '\0';
	    buffer += mult;
	    n += mult;

	    mult = 0; break;
	  }

	case 'r':  /* r is the same as s, in this case. */
	  { 
	    for (mult=(mult?mult:1); mult; --mult)
	      {
		gchar** sp; 
		guint ln;

		sp = va_arg (args, gchar**);
		ln = va_arg (args, guint);

		g_return_val_if_fail (sp, -1);
		g_return_val_if_fail (n + ln <= length, FALSE);

		*sp = g_new(char, ln);
		memcpy(*sp, buffer, ln);
		buffer += ln;
		n += ln;
	      }

	    mult = 0; break;
	  }

	case 'R':  
	  { 
	    gchar** sp; 

	    sp = va_arg (args, gchar**);
	    g_return_val_if_fail (sp, -1);

	    g_return_val_if_fail (mult, -1);
	    g_return_val_if_fail (n + mult <= length, -1);

	    *sp = g_new(char, mult);
	    memcpy(*sp, buffer, mult);
	    buffer += mult;
	    n += mult;
	    mult = 0; 
	    break;
	  }

	case 'p':  
	  { 
	    for (mult=(mult?mult:1); mult; --mult)
	      {
		gchar** sp;
		guint slen;

		sp = va_arg (args, gchar**);
		g_return_val_if_fail (sp, -1);
		g_return_val_if_fail (n + 1 <= length, FALSE);

		slen = *buffer++; 
		++n;
		g_return_val_if_fail (n + slen <= length, FALSE);

		*sp = g_new(gchar, slen + 1);
		memcpy (*sp, buffer, slen); 
		(*sp)[slen] = 0;
		buffer += slen;
		n += slen;
	      }

	    mult = 0;
	    break;
	  }

	case '0':  case '1': case '2': case '3': case '4':
	case '5':  case '6': case '7': case '8': case '9':
	  {
	    mult *= 10;
	    mult += (*p - '0');
	    break;
	  }

	case ' ': case '\t': case '\n': break;

	default: g_return_val_if_fail (FALSE, -1);
	}
    }

  return n;
}
Example #7
0
int PeTable :: UnpackAndInsertAll(void *in, int npes, int *pelist) {
  char *junk;
  char *t =(char *)in /*+CmiReservedHeaderSize*/;
  int i,  
    ufield,   // user field or ths stage of the iteration 
    nmsgs,    // number of messages in combo message
    refno,    // reference number
    dummy;    // alignment dummy
  
  comID id;

  /*
    UNPACK(int, refno);      
    UNPACK(comID, id);
    
    UNPACK(int, ufield);
    UNPACK(int, nmsgs);
    //UNPACK(int, dummy);
    int header_size = sizeof(comID) + CmiReservedHeaderSize + 3 *sizeof(int);
    if(header_size % 8 != 0)
    t+= 8 - header_size % 8;
  */

  AllToAllHdr ahdr;
  UNPACK(AllToAllHdr, ahdr);

  if((sizeof(AllToAllHdr) & 7) != 0)
    t += 8 - (sizeof(AllToAllHdr) & 7);

  refno = ahdr.refno;
  id = ahdr.id;
  nmsgs = ahdr.nmsgs;
  ufield = ahdr.ufield;

  ComlibPrintf("[%d] unpack and insert all %d, %d\n", CkMyPe(), ufield, nmsgs);
  
  //Inserting a memory foot print may, change later
  CmiChunkHeader *chdr= (CmiChunkHeader*)((char*)in - sizeof(CmiChunkHeader));

  int *ref;
  int size;
  char *msg;
  for(int count = 0; count < nmsgs; count++){

    t += sizeof(CmiChunkHeader);
    msg = t;

    // Get the size of the message, and set the ref field correctly for CmiFree
    size = SIZEFIELD(msg);
    REFFIELD(msg) = (int)((char *)in - (char *)msg);

    t += ALIGN8(size);

    // Do CmiReference(msg), this is done bypassing converse!
    chdr->ref++;

    /*
      UNPACK(int, size);
      ref = (int *)t;
      t += sizeof(int);
    
      *ref = (int)((char *)(&chdr->ref) - (char *)ref);
      chdr->ref ++;

      ComlibPrintf("ref = %d, global_ref = %d\n", *ref, chdr->ref);
    
      msg = t;
      t += ALIGN8(size);
    */
    InsertMsgs(npes, pelist, size, msg);
  }  

  CmiFree(in);
  return ufield;
}
Example #8
0
int PeTable :: UnpackAndInsert(void *in) {
  char *junk;
  char *t =(char *)in + CmiReservedHeaderSize;
  int i, ufield, npe, pe, nummsgs, ptrlistindex=0;
  char *msgend, *msgcur;
  comID id;
  int refno = 0;
  int msgsize;

  register int offset;

  UNPACK(int, refno);
  ComlibPrintf("%d UnPackAndInsert\n", CkMyPe());
  UNPACK(comID, id);
  UNPACK(int, msgsize);
  UNPACK(int, ufield);
  UNPACK(int, nummsgs);
  UNPACK(int, npe);

  // unpack all messages into an array
  msgend = (char*)in + msgsize;
  msgcur = (char*)in + ALIGN8(sizeof(struct AllToAllHdr) + (npe+nummsgs+1)*sizeof(int));
  while (msgcur < msgend) {
    CmiChunkHeader *ch = (CmiChunkHeader *)msgcur;

    PTinfo *temp;
    PTALLOC(temp);
    temp->msgsize=ch->size;
    temp->msg=(void*)&ch[1];
    temp->refCount=0;
    temp->magic=0;
    temp->offset=0;

    ptrvec.insert(++ptrlistindex, temp);

    // fix the ref field of the message
    ch->ref = (int)((char*)in - (char*)temp->msg);
    msgcur += ALIGN8(ch->size) + sizeof(CmiChunkHeader);
  }

  pe = -1;
  //for (i=0;i<npe;i++) {
  for (i=0; i<nummsgs; ++i) {
    //UNPACK(int, pe);
    //pe *= -1;

    UNPACK(int, offset);
    if (offset <= 0) {
      pe = -1 * offset;
      --i;
      continue;
    }

    if (msgnum[pe] >= MaxSize[pe]) {
      REALLOC(PeList[pe], MaxSize[pe]);
      MaxSize[pe] *= 2;
    }
    PeList[pe][msgnum[pe]] = ptrvec[offset];
    (ptrvec[offset])->refCount++;
    msgnum[pe]++;

    /*
      while (offset > 0) {
      int tempmsgsize;
      UNPACKMSG(&(tempmsgsize), (char *)in+offset, sizeof(int));
      int ptr;
      UNPACKMSG(&ptr, (char *)in+offset, sizeof(int));

      if (ptr >=0 )  {
      if (msgnum[pe] >= MaxSize[pe]) {
      REALLOC(PeList[pe], MaxSize[pe]);
      MaxSize[pe] *= 2;
      }
      PeList[pe][msgnum[pe]]=ptrvec[ptr];
      (ptrvec[ptr])->refCount++;
      msgnum[pe]++;

      UNPACK(int, offset);
      continue;
      }
            
      PTinfo *temp;
      PTALLOC(temp);
      temp->msgsize=tempmsgsize;
      temp->refCount=1;
      temp->magic=0;
      temp->offset=0;

      ptrvec.insert(ptrlistindex, temp);
      memcpy((char *)in+offset-sizeof(int), &ptrlistindex, sizeof(int));

      ptrlistindex++;
      temp->msg=(void *)((char *)in+offset);
      if (msgnum[pe] >= MaxSize[pe]) {

      REALLOC(PeList[pe], MaxSize[pe]);
      MaxSize[pe] *= 2;
      }
      PeList[pe][msgnum[pe]]=temp;
      msgnum[pe]++;
      UNPACK(int, offset);
      //}
      //t -=sizeof(int);
      }
      *(int *)((char *)in -sizeof(int))=ptrlistindex; 
      */
  }

  REFFIELD(in) = ptrlistindex;
  if (ptrlistindex==0) {
    REFFIELD(in) = 1;
    CmiFree(in);
  }

  /*  
      for (i=0;i<ptrlistindex;i++) {
      char * actualmsg=(char *)(ptrvec[i]->msg);
      int *rc=(int *)(actualmsg-sizeof(int));
      *rc=(int)((char *)in-actualmsg);
      //ComlibPrintf("I am inserting %d\n", *rc);
      }
  */

  ptrvec.removeAll();
  
  return(ufield);
}
#endif

/* ------------------------------------------------------------------------------------ */
#if GASNETE_BUILD_AMREF_GET_HANDLERS

GASNETI_INLINE(gasnete_amref_get_reqh_inner)
void gasnete_amref_get_reqh_inner(gasnet_token_t token, 
  gasnet_handlerarg_t nbytes, void *dest, void *src, void *done) {
  gasneti_assert(nbytes <= gasnet_AMMaxMedium());
  GASNETI_SAFE(
    MEDIUM_REP(2,4,(token, gasneti_handleridx(gasnete_amref_get_reph),
                  src, nbytes, 
                  PACK(dest), PACK(done))));
}
SHORT_HANDLER(gasnete_amref_get_reqh,4,7, 
              (token, a0, UNPACK(a1),      UNPACK(a2),      UNPACK(a3)     ),
              (token, a0, UNPACK2(a1, a2), UNPACK2(a3, a4), UNPACK2(a5, a6)));

GASNETI_INLINE(gasnete_amref_get_reph_inner)
void gasnete_amref_get_reph_inner(gasnet_token_t token, 
  void *addr, size_t nbytes,
  void *dest, void *done) {
  GASNETE_FAST_UNALIGNED_MEMCPY(dest, addr, nbytes);
  MARK_DONE(done,1);
}
MEDIUM_HANDLER(gasnete_amref_get_reph,2,4,
              (token,addr,nbytes, UNPACK(a0),      UNPACK(a1)    ),
              (token,addr,nbytes, UNPACK2(a0, a1), UNPACK2(a2, a3)));

GASNETI_INLINE(gasnete_amref_getlong_reqh_inner)
void gasnete_amref_getlong_reqh_inner(gasnet_token_t token, 
Example #10
0
X_X_PROTO(F_ENTRY_NAME, packed_result, packed_argument)
    {
    WORD fp_class;
    UX_SIGN_TYPE  sign;
    UX_EXPONENT_TYPE exponent;
    UX_FRACTION_DIGIT_TYPE  f_hi;
    UX_FLOAT unpacked_argument, unpacked_result, tmp;
    EXCEPTION_INFO_DECL
    DECLARE_X_FLOAT(packed_result)

    INIT_EXCEPTION_INFO;
    fp_class  = UNPACK(
        PASS_ARG_X_FLOAT(packed_argument),
        & unpacked_argument,
        ASINH_CLASS_TO_ACTION_MAP,
        PASS_RET_X_FLOAT(packed_result)
        OPT_EXCEPTION_INFO);

    if (0 >= fp_class)
       RETURN_X_FLOAT(packed_result);

    /* Get |x| */

    sign = G_UX_SIGN(&unpacked_argument);
    P_UX_SIGN(&unpacked_argument, 0);

    /* Compute sqrt(x^2+1) */

    SQUARE(&unpacked_argument, &tmp);
    ADDSUB(&tmp, UX_ONE, ADD, &tmp);
    NORMALIZE(&tmp);
    UX_SQRT(&tmp, &tmp);

    /* Check for small arguments */

    exponent = G_UX_EXPONENT(&unpacked_argument);
    f_hi     = G_UX_MSD(&unpacked_argument);
    if ((exponent < -1) || ((exponent == -1) && (f_hi <= SQRT_2_OV_4)))
        { /* Argument is small, evaluate directly */

        ADDSUB(&tmp, UX_ONE, ADD, &tmp);
        DIVIDE(&unpacked_argument, &tmp, FULL_PRECISION, &tmp);
        UX_LOG_POLY(&tmp, &unpacked_result);
        }
    else
        { /* Argument is not small, use log function */
        ADDSUB(&tmp, &unpacked_argument, ADD, &tmp);
        NORMALIZE(&tmp);
        UX_LOG( &tmp, UX_LN2, &unpacked_result);
        }

    /* Set sign of result and pack */

    P_UX_SIGN(&unpacked_result,  sign);
    PACK(
        &unpacked_result,
        PASS_RET_X_FLOAT(packed_result),
        NOT_USED,
        NOT_USED
        OPT_EXCEPTION_INFO);

    RETURN_X_FLOAT(packed_result);

    }
Example #11
0
X_X_PROTO(F_ENTRY_NAME, packed_result, packed_argument)
    {
    WORD fp_class, underflow_error;
    UX_SIGN_TYPE sign;
    UX_EXPONENT_TYPE exponent;
    UX_FRACTION_DIGIT_TYPE f_hi;
    UX_FLOAT * unpacked_argument, * unpacked_result, tmp[3];
    EXCEPTION_INFO_DECL
    DECLARE_X_FLOAT(packed_result)

    unpacked_argument = &tmp[2];
    unpacked_result = &tmp[0];
    INIT_EXCEPTION_INFO;
    fp_class  = UNPACK(
        PASS_ARG_X_FLOAT(packed_argument),
        unpacked_argument,
        ATANH_CLASS_TO_ACTION_MAP,
        PASS_RET_X_FLOAT(packed_result)
        OPT_EXCEPTION_INFO);

    if (0 > fp_class)
       RETURN_X_FLOAT(packed_result);

    /* Get |x| */

    sign = G_UX_SIGN(unpacked_argument);
    P_UX_SIGN(unpacked_argument, 0);

    /* Check for |arg| >= 1 */

    exponent = G_UX_EXPONENT(unpacked_argument);
    f_hi     = G_UX_MSD(unpacked_argument);
    if (exponent >= 1)
        { /* |x| >= 1,  split out |x| == 1 and |x| > 1 */

        P_UX_MSD(unpacked_result, UX_MSB);

        if ((exponent > 1) ||
          !UX_FRACTION_IS_ONE_HALF(unpacked_argument))

            /* |x| > 1, return error by forcing overflow */
            P_UX_EXPONENT(unpacked_result, UX_OVERFLOW_EXPONENT);

        else
            { /* |x| = 1, return error by forcing "underflow" */
            P_UX_EXPONENT(unpacked_result, UX_UNDERFLOW_EXPONENT);
            underflow_error = (sign) ?
               ATANH_OF_NEG_ONE : ATANH_OF_ONE;
            }
        }

    /* Check for x small */

    else if ((exponent < -2) ||
      ((exponent == -2) && (f_hi <= SQRT_2_M1_SQR)))
        { /* Argument is small, evaluate directly */
        UX_LOG_POLY( unpacked_argument, unpacked_result);
        }
    else
        { /* Argument is not small, use log function */
        ADDSUB(unpacked_argument,  UX_ONE, ADD_SUB, unpacked_result);
        DIVIDE(unpacked_result + 1, unpacked_result, FULL_PRECISION,
           unpacked_result);
        NORMALIZE(unpacked_result);
        UX_LOG(unpacked_result, UX_LN2, unpacked_result);
        }

    /* Set sign of result, multiply by 1/2 and pack */

    P_UX_SIGN(unpacked_result, sign);
    UX_DECR_EXPONENT(unpacked_result, 1);
    PACK(
        unpacked_result,
        PASS_RET_X_FLOAT(packed_result),
        underflow_error,
        ATANH_ABS_ARG_GT_ONE
        OPT_EXCEPTION_INFO);

    RETURN_X_FLOAT(packed_result);

    }
Example #12
0
X_X_PROTO(F_ENTRY_NAME, packed_result, packed_argument)
    {
    WORD fp_class;
    UX_SIGN_TYPE  sign;
    UX_EXPONENT_TYPE exponent;
    UX_FRACTION_DIGIT_TYPE f_hi;
    UX_FLOAT *unpacked_argument, *unpacked_result, tmp[3];
    EXCEPTION_INFO_DECL
    DECLARE_X_FLOAT(packed_result)

    unpacked_argument = &tmp[2];
    unpacked_result   = &tmp[0];

    INIT_EXCEPTION_INFO;
    fp_class  = UNPACK(
        PASS_ARG_X_FLOAT(packed_argument),
        unpacked_argument,
        ACOSH_CLASS_TO_ACTION_MAP,
        PASS_RET_X_FLOAT(packed_result)
        OPT_EXCEPTION_INFO);

    if (0 > fp_class)
       RETURN_X_FLOAT(packed_result);

    /* Only positive arguments get here */ 

    exponent = G_UX_EXPONENT(unpacked_argument);
    f_hi     = G_UX_MSD(unpacked_argument);

    /* Compute x - 1 and x + 1 */

    ADDSUB(unpacked_argument, UX_ONE, ADD_SUB, unpacked_result);

    /* Check for arguments less than one */

    if (G_UX_SIGN(&unpacked_result[1]))
        { /* Arg was less than 1, force "overflow" */
        P_UX_EXPONENT(unpacked_result, UX_OVERFLOW_EXPONENT);
        goto pack_it;
        }

    /* Check for small arguments */

    else if ((exponent == 1) && (f_hi <= THREE_SQRT_2_OV_4))
        { /* Argument is small, evaluate directly */

        DIVIDE(unpacked_result + 1, unpacked_result, FULL_PRECISION,
          unpacked_result);
        UX_SQRT(unpacked_result, unpacked_result + 1);
        UX_LOG_POLY(unpacked_result + 1, unpacked_result);
        }
    else
        { /* Argument is not small, use log function */
        MULTIPLY(unpacked_result + 1, unpacked_result, unpacked_result);
        NORMALIZE(unpacked_result);
        UX_SQRT(unpacked_result, unpacked_result);
        ADDSUB(unpacked_result, unpacked_argument, ADD, unpacked_result);
        UX_LOG(unpacked_result, UX_LN2, unpacked_result);
        }

pack_it:

    PACK(
        unpacked_result,
        PASS_RET_X_FLOAT(packed_result),
        NOT_USED,
        ACOSH_ARG_LT_ONE
        OPT_EXCEPTION_INFO);

    RETURN_X_FLOAT(packed_result);

    }
Example #13
0
size_t pt_type_unpack_frame(pt_frame_t *frame, char *buf)
{
    int i;
    size_t len;
    char *ori = buf;

    UNPACK(buf, uint8_t, frame->type);
    UNPACK(buf, uint8_t, frame->functype);
    UNPACK(buf, uint32_t, frame->lineno);

    UNPACK_SDS(buf, frame->filename);
    UNPACK_SDS(buf, frame->class);
    UNPACK_SDS(buf, frame->function);

    UNPACK(buf, uint32_t, frame->level);

    UNPACK(buf, uint32_t, frame->arg_count);
    if (frame->arg_count > 0) {
        frame->args = calloc(frame->arg_count, sizeof(sds));
    } else {
        frame->args = NULL;
    }
    for (i = 0; i < frame->arg_count; i++) {
        UNPACK_SDS(buf, frame->args[i]);
    }
    UNPACK_SDS(buf, frame->retval);

    UNPACK(buf, int64_t, frame->entry.wall_time);
    UNPACK(buf, int64_t, frame->entry.cpu_time);
    UNPACK(buf, int64_t,  frame->entry.mem);
    UNPACK(buf, int64_t,  frame->entry.mempeak);

    UNPACK(buf, int64_t, frame->exit.wall_time);
    UNPACK(buf, int64_t, frame->exit.cpu_time);
    UNPACK(buf, int64_t,  frame->exit.mem);
    UNPACK(buf, int64_t,  frame->exit.mempeak);

    return buf - ori;
}
Example #14
0
#include "ssedef.h"
#include "bitpack.h"

#define sleep(sec)	Sleep(sec * 1000)

const Pack packs[] = {
	PACK(1), PACK(2), PACK(3), PACK(4),
	PACK(5), PACK(6), PACK(7), PACK(8),
	PACK(9), PACK(10), PACK(11), PACK(12),
	PACK(13), PACK(14), PACK(15), PACK(16),
	PACK(17), PACK(18), PACK(19), PACK(20),
	PACK(21), PACK(22), PACK(23), PACK(24),
};

const Unpack unpacks[] = {
	UNPACK(1), UNPACK(2), UNPACK(3), UNPACK(4),
	UNPACK(5), UNPACK(6), UNPACK(7), UNPACK(8),
	UNPACK(9), UNPACK(10), UNPACK(11), UNPACK(12),
	UNPACK(13), UNPACK(14), UNPACK(15), UNPACK(16),
	UNPACK(17), UNPACK(18), UNPACK(19), UNPACK(20),
	UNPACK(21), UNPACK(22), UNPACK(23), UNPACK(24),
};

const int minimums[] = {
	BLOCKCOUNT, BLOCKCOUNT / 2, BLOCKCOUNT, BLOCKCOUNT / 4,
	BLOCKCOUNT, BLOCKCOUNT / 2, BLOCKCOUNT, BLOCKCOUNT / 8,
	BLOCKCOUNT, BLOCKCOUNT / 2, BLOCKCOUNT, BLOCKCOUNT / 4,
	BLOCKCOUNT, BLOCKCOUNT / 2, BLOCKCOUNT, BLOCKCOUNT / 8,
	BLOCKCOUNT, BLOCKCOUNT / 2, BLOCKCOUNT, BLOCKCOUNT / 4,
	BLOCKCOUNT, BLOCKCOUNT / 2, BLOCKCOUNT, BLOCKCOUNT / 8,
};