scc

simple c99 compiler
git clone git://git.simple-cc.org/scc
Log | Files | Refs | Submodules | README | LICENSE

commit 2684dd7231882c4fff6b68de3131b816dd456477
parent 22f9af5cb85c1e7cb2e3fd78fd4162b8d0b841ca
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Thu, 22 Sep 2016 09:37:34 +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).

Diffstat:
Mcc2/arch/qbe/arch.h | 9++++++---
Mcc2/arch/qbe/cgen.c | 18+++++++++++++-----
Mcc2/arch/qbe/code.c | 15+++++++++------
3 files changed, 28 insertions(+), 14 deletions(-)

diff --git a/cc2/arch/qbe/arch.h b/cc2/arch/qbe/arch.h @@ -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 @@ -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 @@ -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'},