ref: cac397206b8e30c33919c15fe9fc93cedb9758dc
parent: 15e86f6ab34475a0be35a4acaa04c0f29716297b
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Fri Dec 29 08:41:30 EST 2017
[as-z80] Remove class functions It is better to have a function that returns a flag field with the different different classes of the register. It makes the code shorter and faster.
--- a/as/target/x80/ins.c
+++ b/as/target/x80/ins.c
@@ -8,125 +8,54 @@
#include "proc.h"
int
-rclass(int reg)
+getclass(Node *np)
{
- switch (reg) {
- case AREG_B:
- case AREG_C:
- case AREG_D:
- case AREG_E:
- case AREG_H:
- case AREG_L:
- case AREG_A:
- return 1;
- default:
+ if (np->addr != AREG)
return 0;
- }
-}
-int
-pclass(int reg)
-{
- switch (reg) {
- case AREG_B:
+ switch (np->sym->value) {
case AREG_C:
- case AREG_D:
- case AREG_E:
- case AREG_IXH:
- case AREG_IXL:
+ return RCLASS | PCLASS | QCLASS | CCCLASS;
case AREG_A:
- return 1;
- default:
- return 0;
- }
-}
-
-int
-qclass(int reg)
-{
- switch (reg) {
case AREG_B:
- case AREG_C:
case AREG_D:
case AREG_E:
- case AREG_IYH:
+ return RCLASS | PCLASS | QCLASS;
+ case AREG_H:
+ case AREG_L:
+ return RCLASS;
+ break;
+ case AREG_IXL:
+ case AREG_IXH:
+ return PCLASS;
case AREG_IYL:
- case AREG_A:
- return 1;
- default:
- return 0;
- }
-}
-
-int
-ddclass(int reg)
-{
- switch (reg) {
- case AREG_BC:
- case AREG_DE:
+ case AREG_IYH:
+ return QCLASS;
case AREG_HL:
- case AREG_SP:
- return 1;
- default:
- return 0;
- }
-}
-
-int
-qqclass(int reg)
-{
- switch (reg) {
+ return DDCLASS | QQCLASS;
+ break;
case AREG_BC:
case AREG_DE:
- case AREG_HL:
+ return DDCLASS | QQCLASS | PPCLASS | RRCLASS;
+ break;
+ case AREG_SP:
+ return DDCLASS | PPCLASS | RRCLASS;
+ break;
case AREG_AF:
- return 1;
- default:
- return 0;
- }
-}
-
-int
-ppclass(int reg)
-{
- switch (reg) {
- case AREG_BC:
- case AREG_DE:
+ return QQCLASS;
case AREG_IX:
- case AREG_SP:
- return 1;
- default:
- return 0;
- }
-}
-
-int
-rrclass(int reg)
-{
- switch (reg) {
- case AREG_BC:
- case AREG_DE:
+ return PPCLASS;
+ break;
case AREG_IY:
- case AREG_SP:
- return 1;
- default:
- return 0;
- }
-}
-
-int
-ccclass(int reg)
-{
- switch (reg) {
+ return RRCLASS;
case AREG_NZ:
case AREG_Z:
case AREG_NC:
- case AREG_C:
case AREG_PO:
case AREG_PE:
case AREG_P:
case AREG_M:
- return 1;
+ return CCCLASS;
default:
return 0;
}
--- a/as/target/x80/proc.h
+++ b/as/target/x80/proc.h
@@ -63,11 +63,15 @@
ARST, /* 0h, 08h, 10h, 18h, 20h, 28h, 30h, 38h */
};
-extern int rclass(int reg);
-extern int pclass(int reg);
-extern int qclass(int reg);
-extern int ddclass(int reg);
-extern int qqclass(int reg);
-extern int ppclass(int reg);
-extern int rrclass(int reg);
-extern int ccclass(int reg);
+enum {
+ RCLASS = 1 << 0,
+ PCLASS = 1 << 1,
+ QCLASS = 1 << 2,
+ DDCLASS = 1 << 3,
+ QQCLASS = 1 << 4,
+ PPCLASS = 1 << 5,
+ RRCLASS = 1 << 6,
+ CCCLASS = 1 << 7,
+};
+
+extern int getclass(Node *np);
--- a/as/target/z80/proc.c
+++ b/as/target/z80/proc.c
@@ -64,9 +64,8 @@
match(Op *op, Node **args)
{
unsigned char *p;
- int arg;
+ int arg, class;
Node *np;
- int (*class)(int);
if (!op->args)
return args == NULL;
@@ -76,6 +75,7 @@
--p;
if ((np = *args++) == NULL)
return (arg & (AREP|AOPT)) != 0;
+ class = getclass(np);
arg &= ~(AREP|AOPT);
switch (arg) {
@@ -119,32 +119,35 @@
return 0;
break;
case AREG_RCLASS:
- class = rclass;
- goto register_class;
+ if ((class & RCLASS) == 0)
+ return 0;
+ break;
case AREG_PCLASS:
- class = pclass;
- goto register_class;
+ if ((class & PCLASS) == 0)
+ return 0;
+ break;
case AREG_QCLASS:
- class = qclass;
- goto register_class;
+ if ((class & QCLASS) == 0)
+ return 0;
+ break;
case AREG_QQCLASS:
- class = qqclass;
- goto register_class;
+ if ((class & QQCLASS) == 0)
+ return 0;
+ break;
case AREG_PPCLASS:
- class = ppclass;
- goto register_class;
+ if ((class & PPCLASS) == 0)
+ return 0;
+ break;
case AREG_RRCLASS:
- class = rrclass;
- goto register_class;
+ if ((class & RRCLASS) == 0)
+ return 0;
+ break;
case AREG_CCCLASS:
- class = ccclass;
- goto register_class;
- case AREG_DDCLASS:
- class = ddclass;
- register_class:
- if (np->addr != AREG)
+ if ((class & CCCLASS) == 0)
return 0;
- if (!(*class)(np->sym->value))
+ break;
+ case AREG_DDCLASS:
+ if ((class & DDCLASS) == 0)
return 0;
break;
case AINDEX_IY: