scc

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

commit dbb8b774527a030a3b83b8a422234755fc928ed3
parent 89ce7731fc48c5e3d374ef3082da7958a0e4bc49
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Thu, 31 Mar 2022 13:57:49 +0200

cc2/qbe: Add support for sign in float casts

Float casts were missing the unsigned version of the operators.

Diffstat:
Msrc/cmd/cc/cc2/target/qbe/arch.h | 8++++++++
Msrc/cmd/cc/cc2/target/qbe/cgen.c | 12++++++++++--
Msrc/cmd/cc/cc2/target/qbe/code.c | 8++++++++
3 files changed, 26 insertions(+), 2 deletions(-)

diff --git a/src/cmd/cc/cc2/target/qbe/arch.h b/src/cmd/cc/cc2/target/qbe/arch.h @@ -100,14 +100,22 @@ enum asmop { ASUEXTWL, ASSTOL, + ASSTOUL, ASSTOW, + ASSTOUW, ASDTOL, + ASDTOUL, ASDTOW, + ASDTOUW, ASSWTOD, + ASUWTOD, ASSWTOS, + ASUWTOS, ASSLTOD, + ASULTOD, ASSLTOS, + ASULTOS, ASEXTS, ASTRUNCD, diff --git a/src/cmd/cc/cc2/target/qbe/cgen.c b/src/cmd/cc/cc2/target/qbe/cgen.c @@ -258,7 +258,11 @@ cast(Type *td, Node *np) default: abort(); } - /* TODO: Add signess */ + /* + * unsigned version of operations are always +1 the + * signed version + */ + op += (td->flags & SIGNF) == 0; } else if (s_isint) { /* conversion from int to float */ switch (ts->size) { @@ -275,7 +279,11 @@ cast(Type *td, Node *np) default: abort(); } - /* TODO: Add signess */ + /* + * unsigned version of operations are always +1 the + * signed version + */ + op += (ts->flags & SIGNF) == 0; } else { /* conversion from float to float */ op = (td->size == 4) ? ASEXTS : ASTRUNCD; diff --git a/src/cmd/cc/cc2/target/qbe/code.c b/src/cmd/cc/cc2/target/qbe/code.c @@ -125,14 +125,22 @@ static struct opdata { [ASUEXTWL]= {.fun = unary, .txt = "extuw", .letter = 'l'}, [ASSTOL] = {.fun = unary, .txt = "stosi", .letter = 'l'}, + [ASSTOUL] = {.fun = unary, .txt = "stoui", .letter = 'l'}, [ASSTOW] = {.fun = unary, .txt = "stosi", .letter = 'w'}, + [ASSTOUW] = {.fun = unary, .txt = "stoui", .letter = 'w'}, [ASDTOL] = {.fun = unary, .txt = "dtosi", .letter = 'l'}, + [ASDTOUL] = {.fun = unary, .txt = "dtoui", .letter = 'l'}, [ASDTOW] = {.fun = unary, .txt = "dtosi", .letter = 'w'}, + [ASDTOUW] = {.fun = unary, .txt = "dtoui", .letter = 'w'}, [ASSWTOD] = {.fun = unary, .txt = "swtof", .letter = 'd'}, + [ASUWTOD] = {.fun = unary, .txt = "uwtof", .letter = 'd'}, [ASSWTOS] = {.fun = unary, .txt = "swtof", .letter = 's'}, + [ASUWTOS] = {.fun = unary, .txt = "uwtof", .letter = 's'}, [ASSLTOD] = {.fun = unary, .txt = "sltof", .letter = 'd'}, + [ASULTOD] = {.fun = unary, .txt = "ultof", .letter = 'd'}, [ASSLTOS] = {.fun = unary, .txt = "sltof", .letter = 's'}, + [ASULTOS] = {.fun = unary, .txt = "ultof", .letter = 's'}, [ASEXTS] = {.fun = unary, .txt = "exts", .letter = 'd'}, [ASTRUNCD] = {.fun = unary, .txt = "truncd", .letter = 's'},