Exemplo n.º 1
0
static NODE *
builtin_bswap32(const struct bitable *bt, NODE *a)
{
    NODE *f, *t1, *t2, *t3, *t4;

    t1 = buildtree(LS, buildtree(AND, ccopy(a), bcon(255)), bcon(24));
    t2 = buildtree(LS, buildtree(AND, ccopy(a), bcon(255 << 8)), bcon(8));
    t3 = buildtree(AND, buildtree(RS, ccopy(a), bcon(8)), bcon(255 << 8));
    t4 = buildtree(AND, buildtree(RS, a, bcon(24)), bcon(255));
    f = buildtree(OR, buildtree(OR, t1, t2), buildtree(OR, t3, t4));
    return f;
}
Exemplo n.º 2
0
Arquivo: xdg.c Projeto: Cloudef/chck
static inline char*
get_home(void)
{
   const char *env;
   if ((env = getenv("HOME")) && env[0] == '/')
      return ccopy(env);

   struct passwd *pwd;
   if (!(pwd = getpwuid(getuid())) || !pwd->pw_dir || pwd->pw_dir[0] != '/')
      return NULL;

   return ccopy(pwd->pw_dir);
}
Exemplo n.º 3
0
Arquivo: code.c Projeto: rheoli/pcc
/*
 * Sort arglist so that register assignments ends up last.
 */
static int
argsort(NODE *p)
{
	NODE *q, *r;
	int rv = 0;

	if (p->n_op != CM) {
		if (p->n_op == ASSIGN && p->n_left->n_op == REG &&
		    coptype(p->n_right->n_op) != LTYPE) {
			q = tempnode(0, p->n_type, p->n_df, p->n_ap);
			r = ccopy(q);
			p->n_right = buildtree(COMOP,
			    buildtree(ASSIGN, q, p->n_right), r);
		}
		return rv;
	}
	if (p->n_right->n_op == CM) {
		/* fixup for small structs in regs */
		q = p->n_right->n_left;
		p->n_right->n_left = p->n_left;
		p->n_left = p->n_right;
		p->n_right = p->n_left->n_right;
		p->n_left->n_right = q;
	}
	if (p->n_right->n_op == ASSIGN && p->n_right->n_left->n_op == REG &&
	    coptype(p->n_right->n_right->n_op) != LTYPE) {
		/* move before everything to avoid reg trashing */
		q = tempnode(0, p->n_right->n_type,
		    p->n_right->n_df, p->n_right->n_ap);
		r = ccopy(q);
		p->n_right->n_right = buildtree(COMOP,
		    buildtree(ASSIGN, q, p->n_right->n_right), r);
	}
	if (p->n_right->n_op == ASSIGN && p->n_right->n_left->n_op == REG) {
		if (p->n_left->n_op == CM &&
		    p->n_left->n_right->n_op == STASG) {
			q = p->n_left->n_right;
			p->n_left->n_right = p->n_right;
			p->n_right = q;
			rv = 1;
		} else if (p->n_left->n_op == STASG) {
			q = p->n_left;
			p->n_left = p->n_right;
			p->n_right = q;
			rv = 1;
		}
	}
	return rv | argsort(p->n_left);
}
Exemplo n.º 4
0
/*
 * The "initial exec" tls model.
 */
static NODE *
tlsinitialexec(NODE *p)
{
	NODE *q, *r, *s;
	char *s1, *s2;

	/*
	 * movq %fs:0,%rax
	 * addq x@GOTTPOFF(%rip),%rax
	 */

	q = bcon(0);
	q->n_type = STRTY;

	s = ccopy(r = tempnode(0, INCREF(p->n_type), p->n_df, p->n_ap));
	r = mkx("=r", r);
	r = block(XASM, r, q, INT, 0, 0);

	s1 = "movq %%fs:0,%0\n\taddq ";
	s2 = "@GOTTPOFF(%%rip),%0";
	if (attr_find(p->n_sp->sap, ATTR_SONAME) == NULL) {
		p->n_sp->sap = attr_add(p->n_sp->sap, attr_new(ATTR_SONAME, 1));
		p->n_sp->sap->sarg(0) = p->n_sp->sname;
	}
	r->n_name = mk3str(s1,
	    attr_find(p->n_sp->sap, ATTR_SONAME)->sarg(0), s2);

	r = block(COMOP, r, s, INCREF(p->n_type), p->n_df, p->n_ap);
	r = buildtree(UMUL, r, NIL);
	tfree(p);
	return r;
}
Exemplo n.º 5
0
static NODE *
builtin_va_arg(const struct bitable *bt, NODE *a)
{
    NODE *p, *q, *r, *rv;
    int sz, nodnum;

    /* create a copy to a temp node of current ap */
    p = ccopy(a->n_left);
    q = tempnode(0, p->n_type, p->n_df, p->n_ap);
    nodnum = regno(q);
    rv = buildtree(ASSIGN, q, p);

    r = a->n_right;
    sz = (int)tsize(r->n_type, r->n_df, r->n_ap)/SZCHAR;
    /* add one to ap */
#ifdef BACKAUTO
    rv = buildtree(COMOP, rv , buildtree(PLUSEQ, a->n_left, bcon(sz)));
#else
#error fix wrong eval order in builtin_va_arg
    ecomp(buildtree(MINUSEQ, a->n_left, bcon(sz)));
#endif

    nfree(a->n_right);
    nfree(a);
    r = tempnode(nodnum, INCREF(r->n_type), r->n_df, r->n_ap);
    return buildtree(COMOP, rv, buildtree(UMUL, r, NIL));

}
Exemplo n.º 6
0
/*
 * The "initial exec" tls model.
 */
static NODE *
tlsinitialexec(NODE *p)
{
	NODE *q, *r, *s;
	char *s1, *s2;

	/*
	 * movq %fs:0,%rax
	 * addq x@GOTTPOFF(%rip),%rax
	 */

	q = bcon(0);
	q->n_type = STRTY;

	s = ccopy(r = tempnode(0, INCREF(p->n_type), p->n_df, p->n_ap));
	r = mkx("=r", r);
	r = block(XASM, r, q, INT, 0, 0);

	s1 = "movq %%fs:0,%0\n\taddq ";
	s2 = "@GOTTPOFF(%%rip),%0";
	if (p->n_sp->soname == NULL)
		p->n_sp->soname = p->n_sp->sname;
	r->n_name = mk3str(s1, p->n_sp->soname, s2);

	r = block(COMOP, r, s, INCREF(p->n_type), p->n_df, p->n_ap);
	r = buildtree(UMUL, r, NIL);
	tfree(p);
	return r;
}
Exemplo n.º 7
0
Arquivo: main.cpp Projeto: nyhu/PCPP
static void testCommuns(FragTrap &ft, ScavTrap &st)
{
    FragTrap copy(ft);
    FragTrap test = copy;

    ft.takeDmg(35);
    ft.takeDmg(35);
    ft.takeDmg(100);

    ft.beRepaired(80);
    ft.beRepaired(80);

    ft.rangeAttack("farfaraway");
    ft.meleeAttack("closeTaget");

    ScavTrap ccopy(st);
    ScavTrap ttest = ccopy;

    st.takeDmg(35);
    st.takeDmg(35);
    st.takeDmg(100);

    st.beRepaired(80);
    st.beRepaired(80);
    st.rangeAttack("farfaraway");
    st.meleeAttack("closeTaget");

}
Exemplo n.º 8
0
Arquivo: xdg.c Projeto: Cloudef/chck
char*
xdg_get_path(const char *xdg_env, const char *default_path)
{
   assert(xdg_env && default_path && default_path[0] != '/');

   if (!xdg_env || !default_path || default_path[0] == '/')
      return NULL;

   const char *xdg_dir;
   if ((xdg_dir = getenv(xdg_env)) && xdg_dir[0] == '/')
      return strip_slash(ccopy(xdg_dir));

   char *home;
   if (!(home = get_home()))
      return NULL; /** fatal! */

   const size_t len = snprintf(NULL, 0, "%s/%s", home, default_path) + 1;

   char *path;
   if (!(path = calloc(1, len))) {
      free(home);
      return NULL; /** fatal! */
   }

   snprintf(path, len, "%s/%s", home, default_path);
   free(home);
   return path;
}
Exemplo n.º 9
0
static NODE *
builtin_isany(NODE *a, TWORD rt, int cmpt)
{
    NODE *p, *q;
    TWORD t;

    if ((t = mtcheck(a)) == 0)
        return bcon(0);
    p = buildtree(OROR, mtisnan(a->n_left), mtisnan(a->n_right));
    p = buildtree(NOT, p, NIL);
    q = buildtree(cmpt, cast(ccopy(a->n_left), t, 0),
                  cast(ccopy(a->n_right), t, 0));
    p = buildtree(ANDAND, p, q);
    tfree(a);
    return p;
}
Exemplo n.º 10
0
/*
 * Handle the builtin macros for the math functions is*
 * To get something that is be somewhat generic assume that 
 * isnan() is a real function and that cast of a NaN type 
 * to double will still be a NaN.
 */
static NODE *
mtisnan(NODE *p)
{
	NODE *q = block(NAME, NIL, NIL, INT, 0, 0);

	return binhelp(q, cast(ccopy(p), DOUBLE, 0), INT, "isnan");
}
Exemplo n.º 11
0
int adsi_download_connect(unsigned char *buf, unsigned char *service,  unsigned char *fdn, unsigned char *sec, int ver)
{
	int bytes=0;
	int x;

	/* Message type */
	buf[bytes++] = ADSI_DOWNLOAD_CONNECT;

	/* Reserve space for length */
	bytes++;

	/* Primary column */
	bytes+= ccopy(buf + bytes, service, 18);

	/* Delimiter */
	buf[bytes++] = 0xff;
	
	for (x=0;x<4;x++) {
		buf[bytes++] = fdn[x];
	}
	for (x=0;x<4;x++)
		buf[bytes++] = sec[x];
	buf[bytes++] = ver & 0xff;

	buf[1] = bytes - 2;

	return bytes;

}
Exemplo n.º 12
0
/* special function to 2D slice of 3D matrix z for "wavelet" element of
the work space.  Result is copied to a fortran like output vector, zwork,
with the individual channel results in the rows of the output matrix.
An offset of ts samples from the beginning is given and nt_used samples
are blindly copied to the output matrix.  No error checking is made in
this function as it just assumes this was done earlier.  Uses sunperf
C interface to BLAS functions.  Note z[][][] is assumed to be indexed
left to right as:  wavelet number, channel, timelag.

This function is a little silly because it is so short, but it is repeatedly
and has some pretty obscure indexing.  I hope this clarifies rather than
confuses the algorithm.

Author:  Gary Pavlis
Written: December 2001
*/
void MWcopy_one_wavelet_matrix(complex ***z,int wavelet,complex *zwork,
			int nchan, int ts, int nt_used)
{
	int i;

	for(i=0;i<nchan;++i)
		ccopy(nt_used,(z[wavelet][i])+ts,1,zwork+i,nchan);
}
Exemplo n.º 13
0
int AST_OPTIONAL_API_NAME(ast_adsi_display)(unsigned char *buf, int page, int line, int just, int wrap,
		 char *col1, char *col2)
{
	int bytes = 0;

	/* Sanity check line number */

	if (page) {
		if (line > 4) return -1;
	} else {
		if (line > 33) return -1;
	}

	if (line < 1) {
		return -1;
	}
	/* Parameter type */
	buf[bytes++] = ADSI_LOAD_VIRTUAL_DISP;

	/* Reserve space for size */
	bytes++;

	/* Page and wrap indicator */
	buf[bytes++] = ((page & 0x1) << 7) | ((wrap & 0x1) << 6) | (line & 0x3f);

	/* Justification */
	buf[bytes++] = (just & 0x3) << 5;

	/* Omit highlight mode definition */
	buf[bytes++] = 0xff;

	/* Primary column */
	bytes+= ccopy(buf + bytes, (unsigned char *)col1, 20);

	/* Delimiter */
	buf[bytes++] = 0xff;

	/* Secondary column */
	bytes += ccopy(buf + bytes, (unsigned char *)col2, 20);

	/* Update length */
	buf[1] = bytes - 2;

	return bytes;

}
Exemplo n.º 14
0
int adsi_input_format(unsigned char *buf, int num, int dir, int wrap, unsigned char *format1, unsigned char *format2)
{
	int bytes = 0;

	if (!strlen(format1))
		return -1;

	buf[bytes++] = ADSI_INPUT_FORMAT;
	bytes++;
	buf[bytes++] = ((dir & 1) << 7) | ((wrap & 1) << 6) | (num & 0x7);
	bytes += ccopy(buf + bytes, format1, 20);
	buf[bytes++] = 0xff;
	if (format2 && strlen(format2)) {
		bytes += ccopy(buf + bytes, format2, 20);
	}
	buf[1] = bytes - 2;
	return bytes;
}
Exemplo n.º 15
0
void Frame::circle (const Circle& circle)
{
    Circle ccopy(circle);
    ccopy.xc += originX;
    ccopy.yc += originY;
    fixFillColor(&ccopy);
    fixStrokeStyle(&ccopy);
    display->circle(ccopy);
}
Exemplo n.º 16
0
void func_cvec_set(func_t *f, int i, func_t *g)
{
  func_t *a=NULL;
  if(f==NULL || func_ptype(f)!=FUNC_P_CVEC || f->p.rvec==NULL || i<0 || i>=f->p.rvec->n){ FUNC_ERROR_ARG2("func_cvec_set",f,g); }
  a=func_evalf(FR(g));
  if(func_is_real(a))        { ccopy_r(func_cvec_at(f,i),func_real_p(a)); }
  else if(func_is_complex(a)){ ccopy  (func_cvec_at(f,i),func_complex_p(a)); }
  else                       { FUNC_ERROR_ARG2("func_cvec_set",f,g); }
  a=func_del(a);
}
Exemplo n.º 17
0
static NODE *
builtin_islessgreater(const struct bitable *bt, NODE *a)
{
    NODE *p, *q, *r;
    TWORD t;

    if ((t = mtcheck(a)) == 0)
        return bcon(0);
    p = buildtree(OROR, mtisnan(a->n_left), mtisnan(a->n_right));
    p = buildtree(NOT, p, NIL);
    q = buildtree(GT, cast(ccopy(a->n_left), t, 0),
                  cast(ccopy(a->n_right), t, 0));
    r = buildtree(LT, cast(ccopy(a->n_left), t, 0),
                  cast(ccopy(a->n_right), t, 0));
    q = buildtree(OROR, q, r);
    p = buildtree(ANDAND, p, q);
    tfree(a);
    return p;
}
Exemplo n.º 18
0
static NODE *
builtin_bswap16(const struct bitable *bt, NODE *a)
{
    NODE *f, *t1, *t2;

    t1 = buildtree(LS, buildtree(AND, ccopy(a), bcon(255)), bcon(8));
    t2 = buildtree(AND, buildtree(RS, a, bcon(8)), bcon(255));
    f = buildtree(OR, t1, t2);
    return f;
}
Exemplo n.º 19
0
int AST_OPTIONAL_API_NAME(ast_adsi_input_format)(unsigned char *buf, int num, int dir, int wrap, char *format1, char *format2)
{
	int bytes = 0;

	if (ast_strlen_zero((char *) format1)) {
		return -1;
	}

	buf[bytes++] = ADSI_INPUT_FORMAT;
	bytes++;
	buf[bytes++] = ((dir & 1) << 7) | ((wrap & 1) << 6) | (num & 0x7);
	bytes += ccopy(buf + bytes, (unsigned char *) format1, 20);
	buf[bytes++] = 0xff;
	if (!ast_strlen_zero(format2)) {
		bytes += ccopy(buf + bytes, (unsigned char *) format2, 20);
	}
	buf[1] = bytes - 2;
	return bytes;
}
Exemplo n.º 20
0
Arquivo: main.cpp Projeto: nyhu/PCPP
static void testCommuns(FragTrap &ft, ScavTrap &st, NinjaTrap &nt, SuperTrap &sut)
{
    std::cout << std::endl << "STD TESTS" << std::endl;

    FragTrap copy(ft);
    FragTrap test = copy;

    ft.takeDmg(35);
    ft.takeDmg(35);
    ft.takeDmg(100);

    ft.beRepaired(80);
    ft.beRepaired(80);

    ft.rangeAttack("farfaraway");
    ft.meleeAttack("closeTaget");

    ScavTrap ccopy(st);
    ScavTrap ttest = ccopy;

    st.takeDmg(35);
    st.takeDmg(35);
    st.takeDmg(100);

    st.beRepaired(80);
    st.beRepaired(80);
    st.rangeAttack("farfaraway");
    st.meleeAttack("closeTaget");

    NinjaTrap cccopy(nt);
    NinjaTrap tttest = cccopy;

    nt.takeDmg(35);
    nt.takeDmg(35);
    nt.takeDmg(100);

    nt.beRepaired(80);
    nt.beRepaired(80);

    nt.rangeAttack("farfaraway");
    nt.meleeAttack("closeTaget");

    SuperTrap ccccopy(sut);
    SuperTrap ttttest = ccccopy;

    sut.takeDmg(35);
    sut.takeDmg(35);
    sut.takeDmg(100);

    sut.beRepaired(80);
    sut.beRepaired(80);

    sut.rangeAttack("farfaraway");
    sut.meleeAttack("closeTaget");
}
Exemplo n.º 21
0
int AST_OPTIONAL_API_NAME(ast_adsi_load_soft_key)(unsigned char *buf, int key, const char *llabel, const char *slabel, char *ret, int data)
{
	int bytes = 0;

	/* Abort if invalid key specified */
	if ((key < 2) || (key > 33)) {
		return -1;
	}

	buf[bytes++] = ADSI_LOAD_SOFTKEY;
	/* Reserve for length */
	bytes++;
	/* Which key */
	buf[bytes++] = key;

	/* Carefully copy long label */
	bytes += ccopy(buf + bytes, (const unsigned char *)llabel, 18);

	/* Place delimiter */
	buf[bytes++] = 0xff;

	/* Short label */
	bytes += ccopy(buf + bytes, (const unsigned char *)slabel, 7);


	/* If specified, copy return string */
	if (ret) {
		/* Place delimiter */
		buf[bytes++] = 0xff;
		if (data) {
			buf[bytes++] = ADSI_SWITCH_TO_DATA2;
		}
		/* Carefully copy return string */
		bytes += ccopy(buf + bytes, (const unsigned char *)ret, 20);

	}
	/* Replace parameter length */
	buf[1] = bytes - 2;
	return bytes;
}
Exemplo n.º 22
0
/*
 * Evaluate AND/OR/ER.  p1 and p2 are pointers to ti struct.
 */
static NODE *
gcc_andorer(int op, NODE *p1, NODE *p2)
{
	char *n = tistack();
	NODE *p, *t1, *t2, *p3;

	t1 = tempnode(0, p1->n_type, p1->n_df, p1->n_ap);
	t2 = tempnode(0, p2->n_type, p2->n_df, p2->n_ap);

	p1 = buildtree(ASSIGN, ccopy(t1), p1);
	p2 = buildtree(ASSIGN, ccopy(t2), p2);
	p = buildtree(COMOP, p1, p2);

	p3 = buildtree(ADDROF, eve(bdty(NAME, n)), NIL);
	p1 = buildtree(ASSIGN, structref(ccopy(p3), STREF, hiti),
	    buildtree(op, structref(ccopy(t1), STREF, hiti),
	    structref(ccopy(t2), STREF, hiti)));
	p = buildtree(COMOP, p, p1);
	p1 = buildtree(ASSIGN, structref(ccopy(p3), STREF, loti),
	    buildtree(op, structref(t1, STREF, loti),
	    structref(t2, STREF, loti)));
	p = buildtree(COMOP, p, p1);
	p = buildtree(COMOP, p, buildtree(UMUL, p3, NIL));
	return p;
}
Exemplo n.º 23
0
Arquivo: code.c Projeto: rheoli/pcc
NODE *
amd64_builtin_stdarg_start(const struct bitable *bt, NODE *a)
{
	NODE *p, *r;

	/* use the values from the function header */
	p = a->n_left;
	r = buildtree(ASSIGN, structref(ccopy(p), STREF, reg_save_area),
	    mkstkref(-rsaoff, VOID));
	r = buildtree(COMOP, r,
	    buildtree(ASSIGN, structref(ccopy(p), STREF, overflow_arg_area),
	    mkstkref(thisrsp, VOID)));
	r = buildtree(COMOP, r,
	    buildtree(ASSIGN, structref(ccopy(p), STREF, gp_offset),
	    bcon(thisgpr*(SZLONG/SZCHAR))));
	r = buildtree(COMOP, r,
	    buildtree(ASSIGN, structref(ccopy(p), STREF, fp_offset),
	    bcon(thissse*(SZDOUBLE*2/SZCHAR)+48)));

	tfree(a);
	return r;
}
Exemplo n.º 24
0
/*
 * Check if we may have to do a cast to/from TI.
 */
NODE *
gcc_eval_ticast(int op, NODE *p1, NODE *p2)
{
	struct attr *a1, *a2;
	int t;

	if ((a1 = isti(p1)) == NULL && (a2 = isti(p2)) == NULL)
		return NIL;

	if (op == RETURN)
		p1 = ccopy(p1);
	if (a1 == NULL) {
		if (a2 == NULL)
			cerror("gcc_eval_ticast error");
		switch (p1->n_type) {
		case LDOUBLE:
			p2 = doacall(floatuntixfsp,
			    nametree(floatuntixfsp), p2);
			tfree(p1);
			break;
		case ULONG:
		case LONG:
			p2 = cast(structref(p2, DOT, loti), p1->n_type, 0);
			tfree(p1);
			break;
		case VOID:
			return NIL;
		default:
			uerror("gcc_eval_ticast: %d", p1->n_type);
		}
		return p2;
	}
	/* p2 can be anything, but we must cast it to p1 */
	t = a1->iarg(1);

	if (p2->n_type == STRTY &&
	    (a2 = attr_find(p2->n_ap, GCC_ATYP_MODE)) &&
	    strcmp(a2->sarg(0), TISTR) == 0) {
		/* Already TI, just add extra mode bits */
		a2 = attr_new(GCC_ATYP_MODE, 3);
		a2->sarg(0) = TISTR;
		a2->iarg(1) = t;
		p2->n_ap = attr_add(p2->n_ap, a2);
	} else  {
		p2 = ticast(p2, t);
	}
	tfree(p1);
	return p2;
}
Exemplo n.º 25
0
Arquivo: string.c Projeto: uzur/chck
bool
chck_string_set_cstr_with_length(struct chck_string *string, const char *data, size_t len, bool is_heap)
{
   assert(string);

   char *copy = (char*)data;
   if (is_heap && data && len > 0 && !(copy = ccopy(data, len)))
      return false;

   chck_string_release(string);
   string->is_heap = is_heap;
   string->data = (len > 0 ? copy : NULL);
   string->size = len;
   return true;
}
Exemplo n.º 26
0
Arquivo: code.c Projeto: Sciumo/pcc
/*
 * Generate the builtin code for FFS.
 */
NODE *
builtin_ffs(const struct bitable *bt, NODE *a)
{
	NODE *p, *q, *r;

	p = tempnode(0, bt->rt, 0, 0);
	r = block(XARG, ccopy(p), NIL, INT, 0, 0);
	r->n_name = "=&r";
	q = block(XARG, a, NIL, INT, 0, 0);
	q->n_name = "g";
	q = block(CM, r, q, INT, 0, 0);
	q = block(XASM, q, block(ICON, 0, 0, STRTY, 0, 0), INT, 0, 0);
	q->n_name = "ffs $0,$32,%1,%0;bneq 1f;mnegl $1,%0;1:;incl %0";
	p = block(COMOP, q, p, bt->rt, 0, 0);
	return p;
}
Exemplo n.º 27
0
/*
  Purpose:
    CFFT2 performs a complex Fast Fourier Transform.
    分布式并行

  Parameters:
    Input, int N, the size of the array to be transformed.
    Input/output, double X[2*N], the data to be transformed. On output, the contents of X have been overwritten by work information.
    Output, double Y[2*N], the forward or backward FFT of X.
    Input, double W[N], a table of sines and cosines.
    Input, double SGN, is +1 for a "forward" FFT and -1 for a "backward" FFT.
*/
void cfft2( int n, double x[], double y[], double w[], double sgn )
{
  int j;
  int m;
  int mj;
  int tgle;

  m = (int) (log((double)n) / log(1.99) );
  mj   = 1;

  //Toggling switch for work array.
  tgle = 1;
  step( n, mj, &x[0*2+0], &x[(n/2)*2+0], &y[0*2+0], &y[mj*2+0], w, sgn );

  if(n == 2)
  {
    return;
  }

  for( j = 0; j < m - 2; j++ )
  {
    mj = mj * 2;
    if( tgle )
    {
      step(n, mj, &y[0*2+0], &y[(n/2)*2+0], &x[0*2+0], &x[mj*2+0], w, sgn);
      tgle = 0;
    }
    else
    {
      step(n, mj, &x[0*2+0], &x[(n/2)*2+0], &y[0*2+0], &y[mj*2+0], w, sgn);
      tgle = 1;
    }
  }

  //Last pass through data: move Y to X if needed.
  if( tgle ) 
  {
    ccopy(n, y, x);
  }

  mj = n / 2;
  step( n, mj, &x[0*2+0], &x[(n/2)*2+0], &y[0*2+0], &y[mj*2+0], w, sgn );

  return;
}
Exemplo n.º 28
0
/*
 * Create a reference for a TLS variable.
 * This is the "General dynamic" version.
 */
static NODE *
tlspic(NODE *p)
{
	NODE *q, *r, *s;
	char *s1, *s2;

	/*
	 * .byte   0x66
	 * leaq x@TLSGD(%rip),%rdi
	 * .word   0x6666
	 * rex64
	 * call __tls_get_addr@PLT
	 */

	/* Need the .byte stuff around.  Why? */
	/* Use inline assembler */
	q = mkx("%rdx", bcon(0));
	q = cmop(q, mkx("%rcx", bcon(0)));
	q = cmop(q, mkx("%rsi", bcon(0)));
	q = cmop(q, mkx("%rdi", bcon(0)));
	q = cmop(q, mkx("%r8", bcon(0)));
	q = cmop(q, mkx("%r9", bcon(0)));
	q = cmop(q, mkx("%r10", bcon(0)));
	q = cmop(q, mkx("%r11", bcon(0)));

	s = ccopy(r = tempnode(0, INCREF(p->n_type), p->n_df, p->n_ap));
	r = mkx("=a", r);
	r = block(XASM, r, q, INT, 0, 0);

	/* Create the magic string */
	s1 = ".byte 0x66\n\tleaq ";
	s2 = "@TLSGD(%%rip),%%rdi\n"
	    "\t.word 0x6666\n\trex64\n\tcall __tls_get_addr@PLT";
	if (attr_find(p->n_sp->sap, ATTR_SONAME) == NULL) {
		p->n_sp->sap = attr_add(p->n_sp->sap, attr_new(ATTR_SONAME, 1));
		p->n_sp->sap->sarg(0) = p->n_sp->sname;
	}
	r->n_name = addstring(mk3str(s1,
	    attr_find(p->n_sp->sap, ATTR_SONAME)->sarg(0), s2));

	r = block(COMOP, r, s, INCREF(p->n_type), p->n_df, p->n_ap);
	r = buildtree(UMUL, r, NIL);
	tfree(p);
	return r;
}
Exemplo n.º 29
0
void
myp2tree(NODE *p)
{
	struct symtab *sp;
	NODE *l, *r;
	int o = p->n_op;

	switch (o) {
	case NAME: /* reading from a name must be done with a subroutine */
		if (p->n_type != CHAR && p->n_type != UCHAR)
			break;
		l = buildtree(ADDROF, ccopy(p), NIL);
		r = block(NAME, NIL, NIL, INT, 0, 0);

		r->n_sp = lookup(addname("__nova_rbyte"), SNORMAL);
		if (r->n_sp->sclass == SNULL) {
			r->n_sp->sclass = EXTERN;
			r->n_sp->stype = INCREF(p->n_type)+(FTN-PTR);
		}
		r->n_type = r->n_sp->stype;
		r = clocal(r);
		r = optim(buildtree(CALL, r, l));
		*p = *r;
		nfree(r);
		break;

	case FCON:
		sp = tmpalloc(sizeof(struct symtab));
		sp->sclass = STATIC;
		sp->sap = 0;
		sp->slevel = 1; /* fake numeric label */
		sp->soffset = getlab();
		sp->sflags = 0;
		sp->stype = p->n_type;
		sp->squal = (CON >> TSHIFT);

		defloc(sp);
		ninval(0, tsize(sp->stype, sp->sdf, sp->sap), p);

		p->n_op = NAME;
		p->n_lval = 0;
		p->n_sp = sp;
	}
}
Exemplo n.º 30
0
/*
 * Find number of beginning 0's in a word of type t.
 * t should be deunsigned.
 */
static NODE *
builtin_ff(NODE *f, NODE *a, TWORD t)
{
	NODE *t101, *t102;
	NODE *rn, *p;
	int l15, l16, l17;
	int sz;

	tfree(f);
	t = ctype(t);
	sz = (int)tsize(t, 0, 0)+1;

	t101 = tempnode(0, INT, 0, 0);
	t102 = tempnode(0, t, 0, 0);
	l15 = getlab();
	l16 = getlab();
	l17 = getlab();
	rn = buildtree(ASSIGN, ccopy(t101), bcon(0));
	rn = cmop(rn, buildtree(ASSIGN, ccopy(t102), a));

	p = buildtree(CBRANCH, buildtree(EQ, ccopy(t102), bcon(0)), bcon(l15));
	rn = cmop(rn, p);

	rn = cmop(rn, buildtree(INCR, ccopy(t101), bcon(1)));

	rn = cmop(rn, lblnod(l16));

	p = buildtree(CBRANCH, buildtree(GE, ccopy(t101), bcon(sz)), bcon(l15));
	rn = cmop(rn, p);

	p = buildtree(CBRANCH,
	    buildtree(EQ, buildtree(AND, ccopy(t102), bcon(1)),
	    bcon(0)), bcon(l17));
	rn = cmop(rn, p);

	rn = cmop(rn, block(GOTO, bcon(l15), NIL, INT, 0, 0));

	rn = cmop(rn, lblnod(l17));
	rn = cmop(rn, buildtree(RSEQ, t102, bcon(1)));

	rn = cmop(rn, buildtree(INCR, ccopy(t101), bcon(1)));

	rn = cmop(rn, block(GOTO, bcon(l16), NIL, INT, 0, 0));
	rn = cmop(rn, lblnod(l15));
	return cmop(rn, t101);
}