It seems to me that this might eventually get out of hand...could there
possibly be some way to automate the generation of a family of opcodes? For
example:
MANUAL_OP_FAMILY eq_T1_T2 {
if( T1 == T2 ) {
RETURN(P3);
}
else {
RETURN(P4);
}
} OVER(i, ic, n, nc)
Note that I'm not proposing that syntax, just wondering if there is a more
automated way of doing things.
-----Original Message-----
From: Nathan Torkington
To: [EMAIL PROTECTED]
Sent: 9/15/2001 4:56 PM
Subject: Constant comparisons
I wanted to be able to say
eq I1, 15, label1, label2
That is, to compare against a constant. I've implemented versions of
the comparison opcodes that let you compare against constants. This
is my first patch to Parrot. Be merciful :-)
Nat
(also working on test system ... stay tuned)
Index: basic_opcodes.ops
===================================================================
RCS file: /home/perlcvs/parrot/basic_opcodes.ops,v
retrieving revision 1.15
diff -u -d -r1.15 basic_opcodes.ops
--- basic_opcodes.ops 2001/09/14 14:08:00 1.15
+++ basic_opcodes.ops 2001/09/15 21:52:38
@@ -56,6 +56,15 @@
}
}
+/* EQ Ix, CONSTANT, EQ_BRANCH, NE_BRANCH */
+MANUAL_OP eq_ic_ic {
+ if (INT_REG(P1) == P2) {
+ RETURN(P3);
+ } else {
+ RETURN(P4);
+ }
+}
+
/* NE Ix, Iy, NE_BRANCH, EQ_BRANCH */
MANUAL_OP ne_i_ic {
if (INT_REG(P1) != INT_REG(P2)) {
@@ -65,6 +74,15 @@
}
}
+/* NE Ix, CONSTANT, NE_BRANCH, EQ_BRANCH */
+MANUAL_OP ne_ic_ic {
+ if (INT_REG(P1) != P2) {
+ RETURN(P3);
+ } else {
+ RETURN(P4);
+ }
+}
+
/* LT Ix, Iy, LT_BRANCH, GE_BRANCH */
MANUAL_OP lt_i_ic {
if (INT_REG(P1) < INT_REG(P2)) {
@@ -74,6 +92,15 @@
}
}
+/* LT Ix, CONSTANT, LT_BRANCH, GE_BRANCH */
+MANUAL_OP lt_ic_ic {
+ if (INT_REG(P1) < P2) {
+ RETURN(P3);
+ } else {
+ RETURN(P4);
+ }
+}
+
/* LE Ix, Iy, LE_BRANCH, GT_BRANCH */
MANUAL_OP le_i_ic {
if (INT_REG(P1) <= INT_REG(P2)) {
@@ -83,6 +110,15 @@
}
}
+/* LE Ix, CONSTANT, LE_BRANCH, GT_BRANCH */
+MANUAL_OP le_ic_ic {
+ if (INT_REG(P1) <= P2) {
+ RETURN(P3);
+ } else {
+ RETURN(P4);
+ }
+}
+
/* GT Ix, Iy, GT_BRANCH, LE_BRANCH */
MANUAL_OP gt_i_ic {
if (INT_REG(P1) > INT_REG(P2)) {
@@ -92,6 +128,15 @@
}
}
+/* GT Ix, CONSTANT, GT_BRANCH, LE_BRANCH */
+MANUAL_OP gt_ic_ic {
+ if (INT_REG(P1) > P2) {
+ RETURN(P3);
+ } else {
+ RETURN(P4);
+ }
+}
+
/* GE Ix, Iy, GE_BRANCH, LT_BRANCH */
MANUAL_OP ge_i_ic {
if (INT_REG(P1) >= INT_REG(P2)) {
@@ -101,6 +146,15 @@
}
}
+/* GE Ix, CONSTANT, GE_BRANCH, LT_BRANCH */
+MANUAL_OP ge_ic_ic {
+ if (INT_REG(P1) >= P2) {
+ RETURN(P3);
+ } else {
+ RETURN(P4);
+ }
+}
+
/* IF IXx, TRUE_BRANCH, FALSE_BRANCH */
MANUAL_OP if_i_ic {
if (INT_REG(P1)) {
@@ -193,6 +247,15 @@
/* EQ Nx, Ny, EQ_BRANCH, NE_BRANCH */
MANUAL_OP eq_n_ic {
if (NUM_REG(P1) == NUM_REG(P2)) {
+ RETURN(P3);
+ } else {
+ RETURN(P4);
+ }
+}
+
+/* EQ Nx, CONSTANT, EQ_BRANCH, NE_BRANCH */
+MANUAL_OP eq_nc_ic {
+ if (NUM_REG(P1) == P2) {
RETURN(P3);
} else {
RETURN(P4);
Index: opcode_table
===================================================================
RCS file: /home/perlcvs/parrot/opcode_table,v
retrieving revision 1.13
diff -u -d -r1.13 opcode_table
--- opcode_table 2001/09/13 16:16:38 1.13
+++ opcode_table 2001/09/15 21:52:38
@@ -62,12 +62,19 @@
# Comparators
eq_i_ic 4 I I D D
+eq_ic_ic 4 I i D D
eq_n_ic 4 N N D D
+eq_nc_ic 4 N n D D
ne_i_ic 4 I I D D
+ne_ic_ic 4 I i D D
lt_i_ic 4 I I D D
+lt_ic_ic 4 I i D D
le_i_ic 4 I I D D
+le_ic_ic 4 I i D D
gt_i_ic 4 I I D D
+gt_ic_ic 4 I i D D
ge_i_ic 4 I I D D
+ge_ic_ic 4 I i D D
# Flow control