[hackers] [scc] [cc2-qbe] Use specific load versions || Roberto E. Vargas Caballero

From: <git_AT_suckless.org>
Date: Thu, 22 Sep 2016 09:39:21 +0200 (CEST)

commit 2684dd7231882c4fff6b68de3131b816dd456477
Author: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
AuthorDate: Thu Sep 22 09:37:34 2016 +0200
Commit: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
CommitDate: Thu Sep 22 09:37:34 2016 +0200

    [cc2-qbe] Use specific load versions
    
    There are versions of load for the different sizes and
    with or without sign extension, because load was only
    loading a full word (equivalent to loaduw).

diff --git a/cc2/arch/qbe/arch.h b/cc2/arch/qbe/arch.h
index 16b7835..11cb945 100644
--- a/cc2/arch/qbe/arch.h
+++ b/cc2/arch/qbe/arch.h
_AT_@ -13,9 +13,12 @@ enum asmop {
         ASSTS,
         ASSTD,
 
- ASLDB,
- ASLDH,
- ASLDW,
+ ASLDSB,
+ ASLDUB,
+ ASLDSH,
+ ASLDUH,
+ ASLDSW,
+ ASLDUW,
         ASLDL,
         ASLDS,
         ASLDD,
diff --git a/cc2/arch/qbe/cgen.c b/cc2/arch/qbe/cgen.c
index fb60d1b..015eff7 100644
--- a/cc2/arch/qbe/cgen.c
+++ b/cc2/arch/qbe/cgen.c
_AT_@ -112,27 +112,35 @@ static Node *
 load(Type *tp, Node *np, Node *new)
 {
         int op;
+ int flags = tp->flags;
 
- if (tp->flags & AGGRF) {
+ if (flags & AGGRF) {
                 *new = *np;
                 return new;
         }
         switch (tp->size) {
         case 1:
- op = ASLDB;
+ op = ASLDSB;
                 break;
         case 2:
- op = ASLDH;
+ op = ASLDSH;
                 break;
         case 4:
- op = (tp->flags & FLOATF) ? ASLDS : ASLDW;
+ op = (flags & FLOATF) ? ASLDS : ASLDSW;
                 break;
         case 8:
- op = (tp->flags & FLOATF) ? ASLDD : ASLDL;
+ op = (flags & FLOATF) ? ASLDD : ASLDL;
                 break;
         default:
                 abort();
         }
+ /*
+ * unsigned version of operations are always +1 the
+ * signed version
+ */
+ if ((flags & (INTF|SIGNF)) == INTF && tp->size < 8)
+ ++op;
+
         code(op, tmpnode(new, tp), np, NULL);
 
         return new;
diff --git a/cc2/arch/qbe/code.c b/cc2/arch/qbe/code.c
index bd5fd3d..9823644 100644
--- a/cc2/arch/qbe/code.c
+++ b/cc2/arch/qbe/code.c
_AT_@ -18,12 +18,15 @@ static struct opdata {
         char *txt;
         char letter;
 } optbl [] = {
- [ASLDB] = {.fun = unary, .txt = "load", .letter = 'b'},
- [ASLDH] = {.fun = unary, .txt = "load", .letter = 'h'},
- [ASLDW] = {.fun = unary, .txt = "load", .letter = 'w'},
- [ASLDL] = {.fun = unary, .txt = "load", .letter = 'l'},
- [ASLDS] = {.fun = unary, .txt = "load", .letter = 's'},
- [ASLDD] = {.fun = unary, .txt = "load", .letter = 'd'},
+ [ASLDSB] = {.fun = unary, .txt = "loadsb", .letter = 'w'},
+ [ASLDUB] = {.fun = unary, .txt = "loadub", .letter = 'w'},
+ [ASLDSH] = {.fun = unary, .txt = "loadsh", .letter = 'w'},
+ [ASLDUH] = {.fun = unary, .txt = "loaduh", .letter = 'w'},
+ [ASLDSW] = {.fun = unary, .txt = "loadsw", .letter = 'w'},
+ [ASLDUW] = {.fun = unary, .txt = "loaduw", .letter = 'w'},
+ [ASLDL] = {.fun = unary, .txt = "loadl", .letter = 'l'},
+ [ASLDS] = {.fun = unary, .txt = "loads", .letter = 's'},
+ [ASLDD] = {.fun = unary, .txt = "loadd", .letter = 'd'},
 
         [ASCOPYW] = {.fun = unary, .txt = "copy", .letter = 'w'},
 
Received on Thu Sep 22 2016 - 09:39:21 CEST

This archive was generated by hypermail 2.3.0 : Thu Sep 22 2016 - 09:48:18 CEST