1
0
mirror of https://github.com/golang/go synced 2024-11-25 04:37:56 -07:00

added bitclear operators &^ and &^=

R=r
OCL=26152
CL=26152
This commit is contained in:
Ken Thompson 2009-03-11 19:59:35 -07:00
parent 767845b6fa
commit bb02e481d2
7 changed files with 72 additions and 4 deletions

View File

@ -314,6 +314,9 @@ evconst(Node *n)
case TUP(OAND, Wlitint):
mpandfixfix(xval, nr->val.u.xval);
break;
case TUP(OANDNOT, Wlitint):
mpandnotfixfix(xval, nr->val.u.xval);
break;
case TUP(OXOR, Wlitint):
mpxorfixfix(xval, nr->val.u.xval);
break;

View File

@ -314,7 +314,7 @@ enum
OANDAND,
OEQ, ONE, OLT, OLE, OGE, OGT,
OADD, OSUB, OOR, OXOR,
OMUL, ODIV, OMOD, OLSH, ORSH, OAND,
OMUL, ODIV, OMOD, OLSH, ORSH, OAND, OANDNOT,
OINC, ODEC, // placeholders - not used
OFUNC,
OLABEL,
@ -610,6 +610,7 @@ void mpdivmodfixfix(Mpint *q, Mpint *r, Mpint *n, Mpint *d);
void mpdivfract(Mpint *a, Mpint *b);
void mpnegfix(Mpint *a);
void mpandfixfix(Mpint *a, Mpint *b);
void mpnotandfixfix(Mpint *a, Mpint *b);
void mplshfixfix(Mpint *a, Mpint *b);
void mporfixfix(Mpint *a, Mpint *b);
void mprshfixfix(Mpint *a, Mpint *b);

View File

@ -25,7 +25,7 @@
%token <sym> LNIL LTRUE LFALSE LIOTA
%token LOROR LANDAND LEQ LNE LLE LLT LGE LGT
%token LLSH LRSH LINC LDEC LCOMM
%token LLSH LRSH LINC LDEC LCOMM LANDNOT
%token LIGNORE
/*
@ -87,7 +87,7 @@
%left LCOMM
%left LEQ LNE LLE LGE LLT LGT
%left '+' '-' '|' '^'
%left '*' '/' '%' '&' LLSH LRSH
%left '*' '/' '%' '&' LLSH LRSH LANDNOT
/*
* resolve { vs condition in favor of condition
@ -766,6 +766,10 @@ expr:
{
$$ = nod(OAND, $1, $3);
}
| expr LANDNOT expr
{
$$ = nod(OANDNOT, $1, $3);
}
| expr LLSH expr
{
$$ = nod(OLSH, $1, $3);

View File

@ -654,6 +654,15 @@ l0:
c = LANDAND;
goto lx;
}
if(c1 == '^') {
c = LANDNOT;
c1 = getc();
if(c1 == '=') {
c = OANDNOT;
goto asop;
}
break;
}
if(c1 == '=') {
c = OAND;
goto asop;

View File

@ -406,6 +406,40 @@ mpandfixfix(Mpint *a, Mpint *b)
}
}
void
mpandnotfixfix(Mpint *a, Mpint *b)
{
int i;
long x, *a1, *b1;
if(a->ovf || b->ovf) {
warn("ovf in mpandnotfixfix");
mpmovecfix(a, 0);
a->ovf = 1;
return;
}
if(a->neg) {
a->neg = 0;
mpneg(a);
}
if(b->neg)
mpneg(b);
a1 = &a->a[0];
b1 = &b->a[0];
for(i=0; i<Mpprec; i++) {
x = *a1 & ~*b1++;
*a1++ = x;
}
if(b->neg)
mpneg(b);
if(x & Mpsign) {
a->neg = 1;
mpneg(a);
}
}
void
mpxorfixfix(Mpint *a, Mpint *b)
{

View File

@ -643,6 +643,7 @@ opnames[] =
[OADDR] = "ADDR",
[OADD] = "ADD",
[OANDAND] = "ANDAND",
[OANDNOT] = "ANDNOT",
[OAND] = "AND",
[OARRAY] = "ARRAY",
[OASOP] = "ASOP",

View File

@ -667,6 +667,7 @@ loop:
case OMOD:
case OAND:
case OANDNOT:
case OOR:
case OXOR:
case OANDAND:
@ -700,6 +701,20 @@ loop:
goto badt;
switch(n->op) {
case OANDNOT:
n->op = OAND;
n->right = nod(OCOM, n->right, N);
n->right->type = n->right->left->type;
break;
case OASOP:
if(n->etype == OANDNOT) {
n->etype = OAND;
n->right = nod(OCOM, n->right, N);
n->right->type = n->right->left->type;
break;
}
case OEQ:
case ONE:
case OLT:
@ -707,11 +722,11 @@ loop:
case OGE:
case OGT:
case OADD:
case OASOP:
if(istype(n->left->type, TSTRING)) {
indir(n, stringop(n, top));
goto ret;
}
break;
}
break;
@ -1070,6 +1085,7 @@ loop:
case OLSH:
case ORSH:
case OAND:
case OANDNOT:
case OOR:
case OXOR:
case OMOD: