[hackers] [scc] [cc2-qbe] Fix equality operators || Roberto E. Vargas Caballero

From: <git_AT_suckless.org>
Date: Wed, 20 Apr 2016 22:57:26 +0200 (CEST)

commit 6b9a0f241f50fce7e358ac90508d5be9a8a4cb61
Author: Roberto E. Vargas Caballero <Roberto E. Vargas Caballero>
AuthorDate: Wed Apr 20 03:44:11 2016 +0200
Commit: Roberto E. Vargas Caballero <Roberto E. Vargas Caballero>
CommitDate: Wed Apr 20 03:44:11 2016 +0200

    [cc2-qbe] Fix equality operators
    
    These operators have different form depending of the size of the
    operands, so we have to use different opcodes based in the size
    of the operands.

diff --git a/cc2/arch/qbe/arch.h b/cc2/arch/qbe/arch.h
index 7ee9af4..225cd0a 100644
--- a/cc2/arch/qbe/arch.h
+++ b/cc2/arch/qbe/arch.h
_AT_@ -18,7 +18,9 @@ enum asmop {
         ASLE,
         ASGE,
         ASEQ,
+ ASEQL,
         ASNE,
+ ASNEL,
         ASBAND,
         ASBOR,
         ASBXOR,
diff --git a/cc2/arch/qbe/cgen.c b/cc2/arch/qbe/cgen.c
index 23045c2..ff4f9fc 100644
--- a/cc2/arch/qbe/cgen.c
+++ b/cc2/arch/qbe/cgen.c
_AT_@ -61,6 +61,7 @@ cgen(Node *np)
 {
         Node *l, *r;
         Symbol *sym;
+ Type *tp;
         int op;
 
         if (!np)
_AT_@ -68,8 +69,9 @@ cgen(Node *np)
 
         l = cgen(np->left);
         r = cgen(np->right);
+ tp = &np->type;
 
- switch (op = np->op) {
+ switch (np->op) {
         case OREG:
         case OSTRING:
                 abort();
_AT_@ -79,6 +81,10 @@ cgen(Node *np)
         case OMEM:
         case OAUTO:
                 return np;
+ case OEQ:
+ case ONE:
+ op = opasm[np->op] + (tp->size == 8);
+ goto binary;
         case OADD:
         case OSUB:
         case OMUL:
_AT_@ -90,18 +96,18 @@ cgen(Node *np)
         case OGT:
         case OLE:
         case OGE:
- case OEQ:
- case ONE:
         case OBAND:
         case OBOR:
         case OBXOR:
         case OCPL:
+ op = opasm[np->op];
+ binary:
                 if ((l->flags & (ISTMP|ISCONS)) == 0)
                         l = np->left = load(l);
                 if ((r->flags & (ISTMP|ISCONS)) == 0)
                         r = np->right = load(r);
                 tmpnode(np);
- code(opasm[op], np, l, r);
+ code(op, np, l, r);
                 return np;
         case ONOP:
         case OBLOOP:
diff --git a/cc2/arch/qbe/code.c b/cc2/arch/qbe/code.c
index 3f4dc07..7db856f 100644
--- a/cc2/arch/qbe/code.c
+++ b/cc2/arch/qbe/code.c
_AT_@ -11,25 +11,28 @@ static void binary(void), load(void), store(void);
 static struct opdata {
         void (*fun)(void);
         char *txt;
+ char letter;
 } optbl [] = {
- [ASADD] = {.fun = binary, .txt = "add"},
- [ASSUB] = {.fun = binary, .txt = "sub"},
- [ASMUL] = {.fun = binary, .txt = "mul"},
- [ASMOD] = {.fun = binary, .txt = "rem"},
- [ASDIV] = {.fun = binary, .txt = "div"},
- [ASSHL] = {.fun = binary, .txt = "shl"},
- [ASSHR] = {.fun = binary, .txt = "shr"},
- [ASLT] = {.fun = binary, .txt = "clt"},
- [ASGT] = {.fun = binary, .txt = "cgt"},
- [ASLE] = {.fun = binary, .txt = "cle"},
- [ASGE] = {.fun = binary, .txt = "cge"},
- [ASEQ] = {.fun = binary, .txt = "ceq"},
- [ASNE] = {.fun = binary, .txt = "cne"},
- [ASBAND] = {.fun = binary, .txt = "and"},
- [ASBOR] = {.fun = binary, .txt = "or"},
- [ASBXOR] = {.fun = binary, .txt = "xor"},
- [ASLOAD] = {.fun = load, .txt = "load"},
- [ASASSIG] = {.fun = store, .txt = "store"}
+ [ASADD] = {.fun = binary, .txt = "add", .letter = 'w'},
+ [ASSUB] = {.fun = binary, .txt = "sub", .letter = 'w'},
+ [ASMUL] = {.fun = binary, .txt = "mul", .letter = 'w'},
+ [ASMOD] = {.fun = binary, .txt = "rem", .letter = 'w'},
+ [ASDIV] = {.fun = binary, .txt = "div", .letter = 'w'},
+ [ASSHL] = {.fun = binary, .txt = "shl", .letter = 'w'},
+ [ASSHR] = {.fun = binary, .txt = "shr", .letter = 'w'},
+ [ASLT] = {.fun = binary, .txt = "clt", .letter = 'w'},
+ [ASGT] = {.fun = binary, .txt = "cgt", .letter = 'w'},
+ [ASLE] = {.fun = binary, .txt = "cle", .letter = 'w'},
+ [ASGE] = {.fun = binary, .txt = "cge", .letter = 'w'},
+ [ASEQ] = {.fun = binary, .txt = "ceqw", .letter = 'w'},
+ [ASEQL] = {.fun = binary, .txt = "ceql", .letter = 'w'},
+ [ASNE] = {.fun = binary, .txt = "cnew", .letter = 'w'},
+ [ASNEL] = {.fun = binary, .txt = "cnel", .letter = 'w'},
+ [ASBAND] = {.fun = binary, .txt = "and", .letter = 'w'},
+ [ASBOR] = {.fun = binary, .txt = "or", .letter = 'w'},
+ [ASBXOR] = {.fun = binary, .txt = "xor", .letter = 'w'},
+ [ASLOAD] = {.fun = load, .txt = "load", .letter = 'w'},
+ [ASASSIG] = {.fun = store, .txt = "store", .letter = 'w'}
 };
 
 /*
_AT_@ -241,8 +244,10 @@ addr2txt(Addr *a)
 static void
 binary(void)
 {
+ struct opdata *p = &optbl[pc->op];
+
         printf("\t%s %c=\t%s\t",
- addr2txt(&pc->to), 'w', optbl[pc->op].txt);
+ addr2txt(&pc->to), p->letter, p->txt);
         fputs(addr2txt(&pc->from1), stdout);
         putchar(',');
         fputs(addr2txt(&pc->from2), stdout);
Received on Wed Apr 20 2016 - 22:57:26 CEST

This archive was generated by hypermail 2.3.0 : Wed Apr 20 2016 - 23:00:22 CEST