optimized unary() - fix long long signed comparisons

tcc-xref
bellard 2002-11-23 23:12:26 +00:00
parent 0adc5a8921
commit ab9973c843
1 changed files with 191 additions and 136 deletions

109
tcc.c
View File

@ -4572,8 +4572,17 @@ void gen_opl(int op)
#endif
}
}
/* compare low */
gen_op(op);
/* compare low. Always unsigned */
op1 = op;
if (op1 == TOK_LT)
op1 = TOK_ULT;
else if (op1 == TOK_LE)
op1 = TOK_ULE;
else if (op1 == TOK_GT)
op1 = TOK_UGT;
else if (op1 == TOK_GE)
op1 = TOK_UGE;
gen_op(op1);
a = gtst(1, a);
gsym(b);
vseti(VT_JMPI, a);
@ -6109,32 +6118,48 @@ static void unary(void)
GFuncContext gf;
AttributeDef ad;
if (tok == TOK_CINT || tok == TOK_CCHAR || tok == TOK_LCHAR) {
/* XXX: GCC 2.95.3 does not generate a table although it should be
better here */
switch(tok) {
case TOK_CINT:
case TOK_CCHAR:
case TOK_LCHAR:
vpushi(tokc.i);
next();
} else if (tok == TOK_CUINT) {
break;
case TOK_CUINT:
vpush_tokc(VT_INT | VT_UNSIGNED);
next();
} else if (tok == TOK_CLLONG) {
break;
case TOK_CLLONG:
vpush_tokc(VT_LLONG);
next();
} else if (tok == TOK_CULLONG) {
break;
case TOK_CULLONG:
vpush_tokc(VT_LLONG | VT_UNSIGNED);
next();
} else if (tok == TOK_CFLOAT) {
break;
case TOK_CFLOAT:
vpush_tokc(VT_FLOAT);
next();
} else if (tok == TOK_CDOUBLE) {
break;
case TOK_CDOUBLE:
vpush_tokc(VT_DOUBLE);
next();
} else if (tok == TOK_CLDOUBLE) {
break;
case TOK_CLDOUBLE:
vpush_tokc(VT_LDOUBLE);
next();
} else if (tok == TOK___FUNC__ || (tok == TOK___FUNCTION__ && gnu_ext)) {
break;
case TOK___FUNCTION__:
if (!gnu_ext)
goto tok_identifier;
/* fall thru */
case TOK___FUNC__:
{
void *ptr;
int len;
/* special function name identifier */
len = strlen(funcname) + 1;
/* generate char[len] type */
type.t = VT_BYTE;
@ -6145,10 +6170,12 @@ static void unary(void)
ptr = section_ptr_add(data_section, len);
memcpy(ptr, funcname, len);
next();
} else if (tok == TOK_LSTR) {
}
break;
case TOK_LSTR:
t = VT_INT;
goto str_init;
} else if (tok == TOK_STR) {
case TOK_STR:
/* string parsing */
t = VT_BYTE;
str_init:
@ -6157,10 +6184,9 @@ static void unary(void)
type.t |= VT_ARRAY;
memset(&ad, 0, sizeof(AttributeDef));
decl_initializer_alloc(&type, &ad, VT_CONST, 2, 0, 0);
} else {
t = tok;
break;
case '(':
next();
if (t == '(') {
/* cast ? */
if (parse_btype(&type, &ad)) {
type_decl(&type, &ad, &n, TYPE_ABSTRACT);
@ -6185,10 +6211,14 @@ static void unary(void)
gexpr();
skip(')');
}
} else if (t == '*') {
break;
case '*':
next();
unary();
indir();
} else if (t == '&') {
break;
case '&':
next();
unary();
/* functions names must be treated as function pointers,
except for unary '&' and sizeof. Since we consider that
@ -6200,7 +6230,9 @@ static void unary(void)
test_lvalue();
mk_pointer(&vtop->type);
gaddrof();
} else if (t == '!') {
break;
case '!':
next();
unary();
if ((vtop->r & (VT_VALMASK | VT_LVAL | VT_SYM)) == VT_CONST)
vtop->c.i = !vtop->c.i;
@ -6208,18 +6240,26 @@ static void unary(void)
vtop->c.i = vtop->c.i ^ 1;
else
vseti(VT_JMP, gtst(1, 0));
} else if (t == '~') {
break;
case '~':
next();
unary();
vpushi(-1);
gen_op('^');
} else if (t == '+') {
break;
case '+':
next();
/* in order to force cast, we add zero */
unary();
if ((vtop->type.t & VT_BTYPE) == VT_PTR)
error("pointer not accepted for unary plus");
vpushi(0);
gen_op('+');
} else if (t == TOK_SIZEOF || t == TOK_ALIGNOF) {
break;
case TOK_SIZEOF:
case TOK_ALIGNOF:
t = tok;
next();
if (tok == '(') {
parse_expr_type(&type);
} else {
@ -6230,14 +6270,25 @@ static void unary(void)
vpushi(size);
else
vpushi(align);
} else if (t == TOK_INC || t == TOK_DEC) {
break;
case TOK_INC:
case TOK_DEC:
t = tok;
next();
unary();
inc(0, t);
} else if (t == '-') {
break;
case '-':
next();
vpushi(0);
unary();
gen_op('-');
} else if (t == TOK_LAND && gnu_ext) {
break;
case TOK_LAND:
if (!gnu_ext)
goto tok_identifier;
next();
/* allow to take the address of a label */
if (tok < TOK_UIDENT)
expect("label identifier");
@ -6253,7 +6304,11 @@ static void unary(void)
vset(&s->type, VT_CONST | VT_SYM, 0);
vtop->sym = s;
next();
} else {
break;
default:
tok_identifier:
t = tok;
next();
if (t < TOK_UIDENT)
expect("identifier");
s = sym_find(t);
@ -6270,7 +6325,7 @@ static void unary(void)
vtop->sym = s;
vtop->c.ul = 0;
}
}
break;
}
/* post operations */