Example #1
0
lv_val *lv_get_num_inx(sbs_blk *root, mval *key, sbs_search_status *status)
{
       	sbs_blk	       	*blk, *nxt, *prev;
       	sbs_flt_struct 	*p, *top;
	mval		tmp ;
	int4		x ;

	assert(root);
       	prev = root;
       	for (blk = root; ; prev = blk, blk = nxt)
       	{      	if (!(nxt = blk->nxt))
		{	break;
	 	}
		MV_ASGN_FLT2MVAL(tmp,nxt->ptr.sbs_flt[0].flt) ;
		if (key->mvtype & MV_INT & tmp.mvtype)
			x = key->m[1] - tmp.m[1];
		else
	       	       	x = numcmp(key,&tmp) ;
		if (x < 0)
		{	break;
		}
       	       	if (x == 0)
       	       	{      	status->blk = nxt;
			status->prev = blk;
			status->ptr = (char*)&nxt->ptr.sbs_str[0];
       	       	      	return(nxt->ptr.sbs_flt[0].lv);
		}
	}
	status->blk = blk;
	status->prev = prev;
       	for (p = (sbs_flt_struct*)&blk->ptr.sbs_flt[0], top =  (sbs_flt_struct*)&blk->ptr.sbs_flt[blk->cnt]; p < top; p++)
       	{
		MV_ASGN_FLT2MVAL(tmp,p->flt);
		if (key->mvtype & MV_INT & tmp.mvtype)
			x = key->m[1] - tmp.m[1];
		else
	       	       	x = numcmp(key,&tmp) ;
	 	if (x < 0)
	 	{	break;
	 	}
	 	if (x == 0)
       	       	{      	status->ptr = (char*)p;
	 		return(p->lv);
	 	}
	}
	status->ptr = (char*)p;
	return(0);
}
static int lat_cmp(const void *a, const void *b) {
    const struct latency_entry *pa, *pb;

    pa = (*((struct latency_entry **)a));
    pb = (*((struct latency_entry **)b));

    return numcmp(pb->max, pa->max);
}
Example #3
0
static int proc_thr_cmp(const void *a, const void *b) {
    struct proc_info *pa, *pb;

    pa = *((struct proc_info **)a); pb = *((struct proc_info **)b);

    if (!pa && !pb) return 0;
    if (!pa) return 1;
    if (!pb) return -1;

    return -numcmp(pa->num_threads, pb->num_threads);
}
Example #4
0
static int proc_cpu_cmp(const void *a, const void *b) {
    struct proc_info *pa, *pb;

    pa = *((struct proc_info **)a); pb = *((struct proc_info **)b);

    if (!pa && !pb) return 0;
    if (!pa) return 1;
    if (!pb) return -1;

    return -numcmp(pa->delta_time, pb->delta_time);
}
Example #5
0
/*
 *	sort symbol table by address
 */
void a_sort_sym(int len)
{
	register int gap, i, j;
	register struct sym *temp;

	for (gap = len/2; gap > 0; gap /= 2)
		for (i = gap; i < len; i++)
			for (j = i-gap; j >= 0; j -= gap) {
				if (numcmp(symarray[j]->sym_val,
				    symarray[j+gap]->sym_val) <= 0)
					break;
				temp = symarray[j];
				symarray[j] = symarray[j+gap];
				symarray[j+gap] = temp;
			}
}
Example #6
0
int numcmpr(const char* str1, const char* str2) {
    return -1 * numcmp(str1, str2);
}
Example #7
0
void bx_boollit_tail(triple *t, boolean_t jmp_type_one, boolean_t jmp_to_next, boolean_t sense, oprtype *addr)
/* search the Boolean in t (recursively) for literal leaves; the logic is similar to bx_tail
 * the rest of the arguments parallel those in bx_boolop and used primarily handling basic Boolean operations (ON, NOR, AND, NAND)
 * to get the jump target and sense right for the left-hand operand of the operation
 * jmp_type_one gives the sense of the jump associated with the first operand
 * jmp_to_next gives whether we need a second jump to complete the operation
 * sense gives the sense of the requested operation
 * *addr points the operand for the jump and is eventually used by logic back in the invocation stack to fill in a target location
 */
{
	boolean_t	sin[ARRAYSIZE(t->operand)], tv[ARRAYSIZE(t->operand)];
	int		com, comval, dummy, j, neg, num, tvr;
	mval		*mv, *v[ARRAYSIZE(t->operand)];
	opctype		c;
	oprtype		*i, *p;
	triple		*cob[ARRAYSIZE(t->operand)], *ref0, *tl[ARRAYSIZE(t->operand)];

	assert(OCT_BOOL & oc_tab[t->opcode].octype);
	assert(TRIP_REF == t->operand[0].oprclass);
	assert((OC_COBOOL != t->opcode) && (OC_COM != t->opcode) || (TRIP_REF == t->operand[1].oprclass));
	for (i = t->operand, j = 0; i < ARRAYTOP(t->operand); i++, j++)
	{	/* checkout an operand to see if we can simplify it */
		p = i;
		com = 0;
		for (tl[j] = i->oprval.tref; OCT_UNARY & oc_tab[(c = tl[j]->opcode)].octype; tl[j] = p->oprval.tref)
		{	/* find the real object of affection; WARNING assignment above */
			assert((TRIP_REF == tl[j]->operand[0].oprclass) && (NO_REF == tl[j]->operand[1].oprclass));
			com ^= (OC_COM == c);	/* if we make a recursive call below, COM matters, but NEG and FORCENUM don't */
			p = &tl[j]->operand[0];
		}
		if (OCT_ARITH & oc_tab[c].octype)
			ex_tail(p);								/* chained arithmetic */
		else if (OCT_BOOL & oc_tab[c].octype)
		{	/* recursively check an operand */
			sin[j] = sense;
			p = addr;
			if (!j && !(OCT_REL & oc_tab[t->opcode].octype))
			{	/* left hand operand of parent */
				sin[j] = jmp_type_one;
				if (jmp_to_next)
				{	/* left operands need extra attention to decide between jump next or to the end */
					p = (oprtype *)mcalloc(SIZEOF(oprtype));
					*p = put_tjmp(t);
				}
			}
			bx_boollit(tl[j], sin[j] ^ com, p);
		}
		if ((OC_JMPTRUE != tl[j]->opcode) && (OC_JMPFALSE != tl[j]->opcode) && (OC_LIT != tl[j]->opcode))
			return;									/* this operation doesn't qualify */
		com = comval = neg = num = 0;
		cob[j] = NULL;
		for (ref0 = i->oprval.tref; OCT_UNARY & oc_tab[(c = ref0->opcode)].octype; ref0 = ref0->operand[0].oprval.tref)
		{       /* we may be able to clean up this operand; WARNING assignment above */
			assert((TRIP_REF == ref0->operand[0].oprclass) && (NO_REF == ref0->operand[1].oprclass));
			num += (OC_FORCENUM == c);
			com += (OC_COM == c);
			if (!com)								/* "outside" com renders neg mute */
				neg ^= (OC_NEG == c);
			if (!comval && (NULL == cob[j]))
			{
				if (comval = (OC_COMVAL == c))					/* WARNING assignment */
				{
					if (ref0 != t->operand[j].oprval.tref)
						dqdel(t->operand[j].oprval.tref, exorder);
					t->operand[j].oprval.tref = tl[j];			/* need mval: no COBOOL needed */
				}
				else if (OC_COBOOL == c)
				{	/* the operand needs a COBOOL in case its operator remains unresolved */
					cob[j] = t->operand[j].oprval.tref;
					if (ref0 == cob[j])
						continue;					/* already where it belongs */
					cob[j]->opcode = OC_COBOOL;
					cob[j]->operand[0].oprval.tref = tl[j];
				} else if (ref0 == t->operand[j].oprval.tref)
					continue;
			}
			dqdel(ref0, exorder);
		}
		assert(ref0 == tl[j]);
		if (!comval && (NULL == cob[j]) && (tl[j] != t->operand[j].oprval.tref))
		{	/* left room for a COBOOL, but there's no need */
			dqdel(t->operand[j].oprval.tref, exorder);
			t->operand[j].oprval.tref = tl[j];
		}
		if ((OC_JMPTRUE == ref0->opcode) || (OC_JMPFALSE == ref0->opcode))
		{	/* switch to a literal representation of TRUE / FALSE */
			assert(INDR_REF == ref0->operand[0].oprclass);
			ref0->operand[1] = ref0->operand[0];					/* track info as we switch opcode */
			PUT_LITERAL_TRUTH((sin[j] ? OC_JMPFALSE : OC_JMPTRUE) == ref0->opcode, ref0);
			ref0->opcode = OC_LIT;
			com = 0;								/* already accounted for by sin */
		}
		assert((OC_LIT == ref0->opcode) && (MLIT_REF == ref0->operand[0].oprclass));
		v[j] = &ref0->operand[0].oprval.mlit->v;
		if (com)
		{       /* any complement reduces the literal value to [unsigned] 1 or 0 */
			unuse_literal(v[j]);
			tv[j] = (0 == v[j]->m[1]);
			assert(ref0 == tl[j]);
			PUT_LITERAL_TRUTH(tv[j], ref0);
			v[j] = &ref0->operand[0].oprval.mlit->v;
			num = 0;								/* any complement trumps num */
		}
		if (neg || num)
		{	/* get literal into uniform state */
			unuse_literal(v[j]);
			mv = (mval *)mcalloc(SIZEOF(mval));
			*mv = *v[j];
			if (neg)
			{
				if (MV_INT & mv->mvtype)
				{
					if (0 != mv->m[1])
						mv->m[1] = -mv->m[1];
					else
						mv->sgn = 0;
				} else if (MV_NM & mv->mvtype)
					mv->sgn = !mv->sgn;
			} else
				s2n(mv);
			n2s(mv);
			v[j] = mv;
			assert(ref0 == tl[j]);
			put_lit_s(v[j], ref0);
		}
	}
	assert(tl[0] != tl[1]);									/* start processing a live one */
	for (tvr = j, j = 0;  j < tvr; j++)
	{	/* both arguments are literals, so do the operation at compile time */
		if (NULL != cob[j])
			dqdel(cob[j], exorder);
		v[j] = &tl[j]->operand[0].oprval.mlit->v;
		tv[j] = (0 != v[j]->m[1]);
		unuse_literal(v[j]);
		tl[j]->opcode = OC_NOOP;
		tl[j]->operand[0].oprclass = NO_REF;
	}
	t->operand[1].oprclass = NO_REF;
	switch (c = t->opcode)									/* WARNING assignment */
	{	/* optimize the Boolean operations here */
		case OC_NAND:
		case OC_AND:
			tvr = (tv[0] && tv[1]);
			break;
		case OC_NOR:
		case OC_OR:
			tvr = (tv[0] || tv[1]);
			break;
		case OC_NCONTAIN:
		case OC_CONTAIN:
			tvr = 1;
			(void)matchc(v[1]->str.len, (unsigned char *)v[1]->str.addr, v[0]->str.len,
				(unsigned char *)v[0]->str.addr, &dummy, &tvr);
			tvr ^= 1;
			break;
		case OC_NEQU:
		case OC_EQU:
			tvr = is_equ(v[0], v[1]);
			break;
		case OC_NFOLLOW:
		case OC_FOLLOW:
			tvr = 0 < memvcmp(v[0]->str.addr, v[0]->str.len, v[1]->str.addr, v[1]->str.len);
			break;
		case OC_NGT:
		case OC_GT:
			tvr = 0 < numcmp(v[0], v[1]);
			break;
		case OC_NLT:
		case OC_LT:
			tvr = 0 > numcmp(v[0], v[1]);
			break;
		case OC_NPATTERN:
		case OC_PATTERN:
			tvr = !(*(uint4 *)v[1]->str.addr) ? do_pattern(v[0], v[1]) : do_patfixed(v[0], v[1]);
			break;
		case OC_NSORTS_AFTER:
		case OC_SORTS_AFTER:
			tvr = 0 < sorts_after(v[0], v[1]);
			break;
		default:
			assertpro(FALSE);
	}
	tvr ^= !sense;
	t->operand[0] = put_indr(addr);
	t->opcode = tvr ? OC_JMPFALSE : OC_JMPTRUE;
	return;
}
Example #8
0
int numfieldcmp( char * aline, char * bline)
{
	char * a = get_field(aline, IS_NUMERIC_FIELD);
	char * b = get_field(bline, IS_NUMERIC_FIELD);
	return numcmp(a,b);
}
int rnumcmp(char *s1, char *s2)
{
    return -numcmp(s1, s2);

}
Example #10
0
static int licmp(const void *a, const void *b) {
    return order * numcmp(
        (*((struct library_info**)a))->total_usage.pss,
        (*((struct library_info**)b))->total_usage.pss
    );
}
Example #11
0
int numcmp_reverse(char *s1, char *s2)
{
	return (-1)*numcmp(s1, s2);
}
Example #12
0
void op_fnorder(lv_val *src, mval *key, mval *dst)
{
	int			cur_subscr;
	mval			tmp_sbs;
	int             	length;
	sbs_blk			*num, *str;
	boolean_t		found, is_neg;
	int4			i;
	lv_val			**lv;
	lv_sbs_tbl		*tbl;
	sbs_search_status	status;
	boolean_t		is_fnnext;

	is_fnnext = in_op_fnnext;
	in_op_fnnext = FALSE;
	found = FALSE;
	if (src)
	{
		if (tbl = src->ptrs.val_ent.children)
		{
			MV_FORCE_DEFINED(key);
			num = tbl->num;
			str = tbl->str;
			assert(tbl->ident == MV_SBS);
			if ((MV_IS_STRING(key) && key->str.len == 0) || (is_fnnext && MV_IS_INT(key) && key->m[1] == MINUS_ONE))
			{ /* With GT.M collation , if last subscript is null, $o returns the first subscript in that level */
				if (tbl->int_flag)
				{
					assert(num);
					for (i = 0, lv = &num->ptr.lv[0]; i < SBS_NUM_INT_ELE; i++, lv++)
					{
						if (*lv)
						{
							MV_FORCE_MVAL(dst,i);
							found = TRUE;
							break;
						}
					}
				} else if (num)
				{
					assert(num->cnt);
					MV_ASGN_FLT2MVAL((*dst),num->ptr.sbs_flt[0].flt);
					found = TRUE;
				}
			} else
			{
				if (MV_IS_CANONICAL(key))
				{
					MV_FORCE_NUM(key);
					if (tbl->int_flag)
					{
						assert(num);
						is_neg = (key->mvtype & MV_INT) ? key->m[1] < 0 : key->sgn;
						if (is_neg)
							i = 0;
						else
						{
							if (!is_fnnext && (1 == numcmp(key, (mval *)&SBS_MVAL_INT_ELE)))
								i = SBS_NUM_INT_ELE;
							else
							{
								i =  MV_FORCE_INT(key);
								i++;
							}
						}
						for (lv = &num->ptr.lv[i]; i < SBS_NUM_INT_ELE; i++, lv++)
						{
							if (*lv)
							{
								MV_FORCE_MVAL(dst,i);
								found = TRUE;
								break;
							}
						}
					} else if (num && lv_nxt_num_inx(num, key, &status))
					{
						MV_ASGN_FLT2MVAL((*dst),((sbs_flt_struct*)status.ptr)->flt);
						found = TRUE;
					}
				} else
				{
					if (local_collseq)
					{
						ALLOC_XFORM_BUFF(&key->str);
						tmp_sbs.mvtype = MV_STR;
						tmp_sbs.str.len = max_lcl_coll_xform_bufsiz;
						assert(NULL != lcl_coll_xform_buff);
						tmp_sbs.str.addr = lcl_coll_xform_buff;
						do_xform(local_collseq, XFORM, &key->str,
								&tmp_sbs.str, &length);
						tmp_sbs.str.len = length;
						s2pool(&(tmp_sbs.str));
						key = &tmp_sbs;
					}
					if (str && lv_nxt_str_inx(str, &key->str, &status))
					{
						dst->mvtype = MV_STR;
						dst->str = ((sbs_str_struct *)status.ptr)->str;
					} else
					{
						if (!is_fnnext)
						{
							dst->mvtype = MV_STR;
							dst->str.len = 0;
						} else
							MV_FORCE_MVAL(dst, -1);
					}
					found = TRUE;
				}
			}
			if (!found && str)
			{	/* We are here because
				 * a. key is "" and there is no numeric subscript, OR
				 * b. key is numeric and it is >= the largest numeric subscript at this level implying a switch from
				 *    numeric to string subscripts
				 * Either case, return the first string subscript. However, for STDNULLCOLL, skip to the next
				 * subscript should the first subscript be ""
				 */
				assert(str->cnt);
				dst->mvtype = MV_STR;
				dst->str = str->ptr.sbs_str[0].str;
				found = TRUE;
				if (local_collseq_stdnull && 0 == dst->str.len)
				{
					assert(lv_null_subs);
					if (lv_nxt_str_inx(str, &dst->str, &status))
					{
						dst->str = ((sbs_str_struct*)status.ptr)->str;
					} else
						found = FALSE;
				}
			}
		}
	}
	if (!found)
	{
		if (!is_fnnext)
		{
			dst->mvtype = MV_STR;
			dst->str.len = 0;
		} else
			MV_FORCE_MVAL(dst, -1);
	} else if (dst->mvtype == MV_STR && local_collseq)
	{
		ALLOC_XFORM_BUFF(&dst->str);
		assert(NULL != lcl_coll_xform_buff);
		tmp_sbs.str.addr = lcl_coll_xform_buff;
		tmp_sbs.str.len = max_lcl_coll_xform_bufsiz;
		do_xform(local_collseq, XBACK,
				&dst->str, &tmp_sbs.str, &length);
		tmp_sbs.str.len = length;
		s2pool(&(tmp_sbs.str));
		dst->str = tmp_sbs.str;
	}
}
Example #13
0
int numcmp_r(char *s1, char *s2) {
    return -1 * numcmp(s1, s2);
}
Example #14
0
/// @brief Manual test of glibc printf vs ours
/// We test for a worst case error of 1 LSB error at 15digits
/// @param[in] format: printf format string
/// @param[in] ...: list of arguments
/// @return void
MEMSPACE
void tp(const char *format, ...)
{
    char str0[1024];
    char fmt[1024];
    char str1[1024];
    char str2[1024];
    int f;
    int find, ind, len;
    int matched;
    long long error;
    va_list va;
    int digits;

    memset(str0,sizeof(str0)-1,0);
    memset(str1,sizeof(str1)-1,0);
    memset(str2,sizeof(str2)-1,0);
    memset(fmt,sizeof(fmt)-1,0);

    // We want to save only type and type size specifiers)
    find = 0;
    fmt[find++] = '%';

    len = strlen(format);
    if(len > 0)
    {
        ind = len - 1;
    }
    else 
    {
        printf("ERROR: empty format\n");
        printf("    G[%s]\n", str1);
        printf("    B[%s]\n", str2);
        printf("\n");
        ++tp_fmt;
        return;
    }
    
    // We may have a size adjustment specifier
    //FIXME add more as printf gains more type size conversion specifiers
    if(ind >= 2)
    {
        f = format[ind-2];
        if(f == 'l')    
            fmt[find++] = f;
    }
    f = format[ind-1];
    if(f == 'l' || f == 'h')    
        fmt[find++] = f;
    
    // This should be the primary conversion type specifier
    if(ind)
    {
        f = format[ind];
        fmt[find++] = f;
    }
    fmt[find++] = 0;

    // GLIBC printf in str0 without extra specifiers
    va_start(va, format);
    len = vsnprintf(str0, sizeof(str0)-1, fmt, va);
    va_end(va);
    fflush(stdout);
        
    // GLIBC printf in str1
    va_start(va, format);
    len = vsnprintf(str1, sizeof(str1)-1, format, va);
    va_end(va);
    fflush(stdout);

    // Our Printf in str2
    va_start(va, format);
    len = t_vsnprintf(str2, sizeof(str2)-1, format, va);
    va_end(va);
    fflush(stdout);



    //FIXME add more as printf gains more conversion functions
    if(f == 'g' || f == 'G' || f == 'e' || f == 'E' || f == 'f' || f == 'F')
    {
        /*
         * Single mantissa 24bits   base10 digits   7.22     
         *      exponent 8bits   base10 exponent 37
         * Double mantissa 53bits   base10 digits   15.95   
         *      exponent 11bits  base10 exponent 307
        */
        if(sizeof(double) == 8)
            digits = 16;
        else if(sizeof(double) == 4)
            digits = 7;
        else
        {
            fprintf(stderr,"Unexpected size of double:%d\n", (int)sizeof(double));
            exit(1);
        }

        // Compare results to N digit window
        error = numcmp(str1,str2,digits);

        // A double 1 LSB error would be 10LL
        // Remember the numbers may be rounded so we use less then 15LL
        if(error < 0 || error > 14LL)
        {
            printf("ERROR: [%s], [%s]\n", format, str0);
            printf("    G[%s]\n", str1);
            printf("    B[%s]\n", str2);
            printf("    error:%lld\n", error);
            ++tp_bad;
        }
        else
        {
            ++tp_good;
            if(display_good)
            {
                printf("OK:    [%s], [%s]\n", format, str0);
                printf("    G[%s]\n", str1);
            }
        }
    }
    else 
    {
        if(strcmp(str1,str2) != 0)
        {
            printf("ERROR: [%s], [%s]\n", format, str0);
            printf("    G[%s]\n", str1);
            printf("    B[%s]\n", str2);
            ++tp_bad;
        }
        else
        {
            ++tp_good;
            if(display_good)
            {
                printf("OK:    [%s], [%s]\n", format, str0);
                printf("    G[%s]\n", str1);
            }
        }
    }
    fflush(stdout); 
        return;
    fflush(stdout);
}