-
/* Semantics ops support for CGEN-based simulators.
- Copyright (C) 1996, 1997, 1998, 1999 Free Software Foundation, Inc.
+ Copyright (C) 1996, 1997, 1998, 1999, 2002, 2007, 2008, 2009, 2010
+ Free Software Foundation, Inc.
Contributed by Cygnus Solutions.
This file is part of the GNU Simulators.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2, or (at your option)
-any later version.
+the Free Software Foundation; either version 3 of the License, or
+(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
-You should have received a copy of the GNU General Public License along
-with this program; if not, write to the Free Software Foundation, Inc.,
-59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+You should have received a copy of the GNU General Public License
+along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef CGEN_SEM_OPS_H
#define CGEN_SEM_OPS_H
+#include <assert.h>
+
#if defined (__GNUC__) && ! defined (SEMOPS_DEFINE_INLINE)
#define SEMOPS_DEFINE_INLINE
#define SEMOPS_INLINE extern inline
#define ANDIF(x, y) ((x) && (y))
#define ORIF(x, y) ((x) || (y))
+#define SUBBI(x, y) ((x) - (y))
#define ANDBI(x, y) ((x) & (y))
#define ORBI(x, y) ((x) | (y))
#define XORBI(x, y) ((x) ^ (y))
#define GTUBI(x, y) ((BI) (x) > (BI) (y))
#define GEUBI(x, y) ((BI) (x) >= (BI) (y))
\f
-#define ADDQI(x, y) ((x) + (y))
-#define SUBQI(x, y) ((x) - (y))
-#define MULQI(x, y) ((x) * (y))
+#define ADDQI(x, y) ((QI) ((UQI) (x) + (UQI) (y)))
+#define SUBQI(x, y) ((QI) ((UQI) (x) - (UQI) (y)))
+#define MULQI(x, y) ((QI) ((UQI) (x) * (UQI) (y)))
#define DIVQI(x, y) ((QI) (x) / (QI) (y))
#define UDIVQI(x, y) ((UQI) (x) / (UQI) (y))
#define MODQI(x, y) ((QI) (x) % (QI) (y))
#define ANDQI(x, y) ((x) & (y))
#define ORQI(x, y) ((x) | (y))
#define XORQI(x, y) ((x) ^ (y))
-#define NEGQI(x) (- (x))
+#define NEGQI(x) ((QI) (- (UQI) (x)))
#define NOTQI(x) (! (QI) (x))
#define INVQI(x) (~ (x))
+#define ABSQI(x) ((QI) ((QI) (x) < 0 ? -(UQI) (x) : (UQI) (x)))
#define EQQI(x, y) ((QI) (x) == (QI) (y))
#define NEQI(x, y) ((QI) (x) != (QI) (y))
#define LTQI(x, y) ((QI) (x) < (QI) (y))
#define GTUQI(x, y) ((UQI) (x) > (UQI) (y))
#define GEUQI(x, y) ((UQI) (x) >= (UQI) (y))
\f
-#define ADDHI(x, y) ((x) + (y))
-#define SUBHI(x, y) ((x) - (y))
-#define MULHI(x, y) ((x) * (y))
+#define ADDHI(x, y) ((HI) ((UHI) (x) + (UHI) (y)))
+#define SUBHI(x, y) ((HI) ((UHI) (x) - (UHI) (y)))
+#define MULHI(x, y) ((HI) ((UHI) (x) * (UHI) (y)))
#define DIVHI(x, y) ((HI) (x) / (HI) (y))
#define UDIVHI(x, y) ((UHI) (x) / (UHI) (y))
#define MODHI(x, y) ((HI) (x) % (HI) (y))
#define ANDHI(x, y) ((x) & (y))
#define ORHI(x, y) ((x) | (y))
#define XORHI(x, y) ((x) ^ (y))
-#define NEGHI(x) (- (x))
+#define NEGHI(x) ((HI) (- (UHI) (x)))
#define NOTHI(x) (! (HI) (x))
#define INVHI(x) (~ (x))
+#define ABSHI(x) ((HI) ((HI) (x) < 0 ? -(UHI) (x) : (UHI) (x)))
#define EQHI(x, y) ((HI) (x) == (HI) (y))
#define NEHI(x, y) ((HI) (x) != (HI) (y))
#define LTHI(x, y) ((HI) (x) < (HI) (y))
#define GTUHI(x, y) ((UHI) (x) > (UHI) (y))
#define GEUHI(x, y) ((UHI) (x) >= (UHI) (y))
\f
-#define ADDSI(x, y) ((x) + (y))
-#define SUBSI(x, y) ((x) - (y))
-#define MULSI(x, y) ((x) * (y))
+#define ADDSI(x, y) ((SI) ((USI) (x) + (USI) (y)))
+#define SUBSI(x, y) ((SI) ((USI) (x) - (USI) (y)))
+#define MULSI(x, y) ((SI) ((USI) (x) * (USI) (y)))
#define DIVSI(x, y) ((SI) (x) / (SI) (y))
#define UDIVSI(x, y) ((USI) (x) / (USI) (y))
#define MODSI(x, y) ((SI) (x) % (SI) (y))
#define ANDSI(x, y) ((x) & (y))
#define ORSI(x, y) ((x) | (y))
#define XORSI(x, y) ((x) ^ (y))
-#define NEGSI(x) (- (x))
+#define NEGSI(x) ((SI) (- (USI) (x)))
#define NOTSI(x) (! (SI) (x))
#define INVSI(x) (~ (x))
+#define ABSSI(x) ((SI) ((SI) (x) < 0 ? -(USI) (x) : (USI) (x)))
#define EQSI(x, y) ((SI) (x) == (SI) (y))
#define NESI(x, y) ((SI) (x) != (SI) (y))
#define LTSI(x, y) ((SI) (x) < (SI) (y))
extern int GTUDI (UDI, UDI);
extern int GEUDI (UDI, UDI);
#else /* ! DI_FN_SUPPORT */
-#define ADDDI(x, y) ((x) + (y))
-#define SUBDI(x, y) ((x) - (y))
-#define MULDI(x, y) ((x) * (y))
+#define ADDDI(x, y) ((DI) ((UDI) (x) + (UDI) (y)))
+#define SUBDI(x, y) ((DI) ((UDI) (x) - (UDI) (y)))
+#define MULDI(x, y) ((DI) ((UDI) (x) * (UDI) (y)))
#define DIVDI(x, y) ((DI) (x) / (DI) (y))
#define UDIVDI(x, y) ((UDI) (x) / (UDI) (y))
#define MODDI(x, y) ((DI) (x) % (DI) (y))
#define ANDDI(x, y) ((x) & (y))
#define ORDI(x, y) ((x) | (y))
#define XORDI(x, y) ((x) ^ (y))
-#define NEGDI(x) (- (x))
+#define NEGDI(x) ((DI) (- (UDI) (x)))
#define NOTDI(x) (! (DI) (x))
#define INVDI(x) (~ (x))
+#define ABSDI(x) ((DI) ((DI) (x) < 0 ? -(UDI) (x) : (UDI) (x)))
#define EQDI(x, y) ((DI) (x) == (DI) (y))
#define NEDI(x, y) ((DI) (x) != (DI) (y))
#define LTDI(x, y) ((DI) (x) < (DI) (y))
#else
#define EXTQIDI(x) ((DI) (QI) (x))
#endif
+#define EXTHIHI(x) ((HI) (HI) (x))
#define EXTHISI(x) ((SI) (HI) (x))
+#define EXTSISI(x) ((SI) (SI) (x))
#if defined (DI_FN_SUPPORT)
extern DI EXTHIDI (HI);
#else
#define ZEXTQIDI(x) ((DI) (UQI) (x))
#endif
#define ZEXTHISI(x) ((SI) (UHI) (x))
+#define ZEXTHIHI(x) ((HI) (UHI) (x))
+#define ZEXTSISI(x) ((SI) (USI) (x))
#if defined (DI_FN_SUPPORT)
extern DI ZEXTHIDI (HI);
#else
#define TRUNCSIBI(x) ((BI) (SI) (x))
#define TRUNCSIQI(x) ((QI) (SI) (x))
#define TRUNCSIHI(x) ((HI) (SI) (x))
+#define TRUNCSISI(x) ((SI) (SI) (x))
#if defined (DI_FN_SUPPORT)
extern BI TRUNCDIBI (DI);
#else
#define TRUNCDISI(x) ((SI) (DI) (x))
#endif
\f
-/* Composing/decomposing the various types. */
-
-/* ??? endianness issues undecided */
-/* ??? CURRENT_TARGET_BYTE_ORDER usage wip */
+/* Composing/decomposing the various types.
+ Word ordering is endian-independent. Words are specified most to least
+ significant and word number 0 is the most significant word.
+ ??? May also wish an endian-dependent version. Later. */
#ifdef SEMOPS_DEFINE_INLINE
SEMOPS_INLINE SF
-SUBWORDSISF (SIM_CPU *cpu, SI in)
+SUBWORDSISF (SI in)
{
union { SI in; SF out; } x;
x.in = in;
return x.out;
}
+SEMOPS_INLINE DF
+SUBWORDDIDF (DI in)
+{
+ union { DI in; DF out; } x;
+ x.in = in;
+ return x.out;
+}
+
+SEMOPS_INLINE QI
+SUBWORDSIQI (SI in, int byte)
+{
+ assert (byte >= 0 && byte <= 3);
+ return (UQI) (in >> (8 * (3 - byte))) & 0xFF;
+}
+
+SEMOPS_INLINE UQI
+SUBWORDSIUQI (SI in, int byte)
+{
+ assert (byte >= 0 && byte <= 3);
+ return (UQI) (in >> (8 * (3 - byte))) & 0xFF;
+}
+
+SEMOPS_INLINE QI
+SUBWORDDIQI (DI in, int byte)
+{
+ assert (byte >= 0 && byte <= 7);
+ return (UQI) (in >> (8 * (7 - byte))) & 0xFF;
+}
+
+SEMOPS_INLINE HI
+SUBWORDDIHI (DI in, int word)
+{
+ assert (word >= 0 && word <= 3);
+ return (UHI) (in >> (16 * (3 - word))) & 0xFFFF;
+}
+
+SEMOPS_INLINE HI
+SUBWORDSIHI (SI in, int word)
+{
+ if (word == 0)
+ return (USI) in >> 16;
+ else
+ return in;
+}
+
SEMOPS_INLINE SI
-SUBWORDSFSI (SIM_CPU *cpu, SF in)
+SUBWORDSFSI (SF in)
{
union { SF in; SI out; } x;
x.in = in;
return x.out;
}
+SEMOPS_INLINE DI
+SUBWORDDFDI (DF in)
+{
+ union { DF in; DI out; } x;
+ x.in = in;
+ return x.out;
+}
+
+SEMOPS_INLINE UQI
+SUBWORDDIUQI (DI in, int byte)
+{
+ assert (byte >= 0 && byte <= 7);
+ return (UQI) (in >> (8 * (7 - byte)));
+}
+
SEMOPS_INLINE SI
-SUBWORDDISI (SIM_CPU *cpu, DI in, int word)
+SUBWORDDISI (DI in, int word)
{
- if (CURRENT_TARGET_BYTE_ORDER == BIG_ENDIAN)
- {
- if (word == 0)
- return (UDI) in >> 32;
- else
- return in;
- }
+ if (word == 0)
+ return (UDI) in >> 32;
else
- {
- if (word == 1)
- return (UDI) in >> 32;
- else
- return in;
- }
+ return in;
}
SEMOPS_INLINE SI
-SUBWORDDFSI (SIM_CPU *cpu, DF in, int word)
+SUBWORDDFSI (DF in, int word)
{
- union { DF in; SI out[2]; } x;
- x.in = in;
- if (CURRENT_TARGET_BYTE_ORDER == BIG_ENDIAN)
- return x.out[word];
+ /* Note: typedef UDI DF; */
+ if (word == 0)
+ return (UDI) in >> 32;
else
- return x.out[!word];
+ return in;
}
SEMOPS_INLINE SI
-SUBWORDXFSI (SIM_CPU *cpu, XF in, int word)
+SUBWORDXFSI (XF in, int word)
{
+ /* Note: typedef struct { SI parts[3]; } XF; */
union { XF in; SI out[3]; } x;
x.in = in;
if (CURRENT_TARGET_BYTE_ORDER == BIG_ENDIAN)
}
SEMOPS_INLINE SI
-SUBWORDTFSI (SIM_CPU *cpu, TF in, int word)
+SUBWORDTFSI (TF in, int word)
{
+ /* Note: typedef struct { SI parts[4]; } TF; */
union { TF in; SI out[4]; } x;
x.in = in;
if (CURRENT_TARGET_BYTE_ORDER == BIG_ENDIAN)
}
SEMOPS_INLINE DI
-JOINSIDI (SIM_CPU *cpu, SI x0, SI x1)
+JOINSIDI (SI x0, SI x1)
{
- if (CURRENT_TARGET_BYTE_ORDER == BIG_ENDIAN)
- return MAKEDI (x0, x1);
- else
- return MAKEDI (x1, x0);
+ return MAKEDI (x0, x1);
}
SEMOPS_INLINE DF
-JOINSIDF (SIM_CPU *cpu, SI x0, SI x1)
+JOINSIDF (SI x0, SI x1)
{
union { SI in[2]; DF out; } x;
if (CURRENT_TARGET_BYTE_ORDER == BIG_ENDIAN)
}
SEMOPS_INLINE XF
-JOINSIXF (SIM_CPU *cpu, SI x0, SI x1, SI x2)
+JOINSIXF (SI x0, SI x1, SI x2)
{
union { SI in[3]; XF out; } x;
if (CURRENT_TARGET_BYTE_ORDER == BIG_ENDIAN)
}
SEMOPS_INLINE TF
-JOINSITF (SIM_CPU *cpu, SI x0, SI x1, SI x2, SI x3)
+JOINSITF (SI x0, SI x1, SI x2, SI x3)
{
union { SI in[4]; TF out; } x;
if (CURRENT_TARGET_BYTE_ORDER == BIG_ENDIAN)
#else
-SF SUBWORDSISF (SIM_CPU *, SI);
-SI SUBWORDSFSI (SIM_CPU *, SF);
-SI SUBWORDDISI (SIM_CPU *, DI, int);
-SI SUBWORDDFSI (SIM_CPU *, DF, int);
-SI SUBWORDXFSI (SIM_CPU *, XF, int);
-SI SUBWORDTFSI (SIM_CPU *, TF, int);
-
-DI JOINSIDI (SIM_CPU *, SI, SI);
-DF JOINSIDF (SIM_CPU *, SI, SI);
-XF JOINSIXF (SIM_CPU *, SI, SI, SI);
-TF JOINSITF (SIM_CPU *, SI, SI, SI, SI);
+QI SUBWORDSIQI (SI);
+HI SUBWORDSIHI (HI);
+SI SUBWORDSFSI (SF);
+SF SUBWORDSISF (SI);
+DI SUBWORDDFDI (DF);
+DF SUBWORDDIDF (DI);
+QI SUBWORDDIQI (DI, int);
+HI SUBWORDDIHI (DI, int);
+SI SUBWORDDISI (DI, int);
+SI SUBWORDDFSI (DF, int);
+SI SUBWORDXFSI (XF, int);
+SI SUBWORDTFSI (TF, int);
+
+UQI SUBWORDSIUQI (SI);
+UQI SUBWORDDIUQI (DI);
+
+DI JOINSIDI (SI, SI);
+DF JOINSIDF (SI, SI);
+XF JOINSIXF (SI, SI, SI);
+TF JOINSITF (SI, SI, SI, SI);
#endif /* SUBWORD,JOIN */
\f
return res;
}
+SEMOPS_INLINE HI
+ADDCHI (HI a, HI b, BI c)
+{
+ HI res = ADDHI (a, ADDHI (b, c));
+ return res;
+}
+
+SEMOPS_INLINE BI
+ADDCFHI (HI a, HI b, BI c)
+{
+ HI tmp = ADDHI (a, ADDHI (b, c));
+ BI res = ((UHI) tmp < (UHI) a) || (c && tmp == a);
+ return res;
+}
+
+SEMOPS_INLINE BI
+ADDOFHI (HI a, HI b, BI c)
+{
+ HI tmp = ADDHI (a, ADDHI (b, c));
+ BI res = (((a < 0) == (b < 0))
+ && ((a < 0) != (tmp < 0)));
+ return res;
+}
+
+SEMOPS_INLINE HI
+SUBCHI (HI a, HI b, BI c)
+{
+ HI res = SUBHI (a, ADDHI (b, c));
+ return res;
+}
+
+SEMOPS_INLINE BI
+SUBCFHI (HI a, HI b, BI c)
+{
+ BI res = ((UHI) a < (UHI) b) || (c && a == b);
+ return res;
+}
+
+SEMOPS_INLINE BI
+SUBOFHI (HI a, HI b, BI c)
+{
+ HI tmp = SUBHI (a, ADDHI (b, c));
+ BI res = (((a < 0) != (b < 0))
+ && ((a < 0) != (tmp < 0)));
+ return res;
+}
+
+SEMOPS_INLINE QI
+ADDCQI (QI a, QI b, BI c)
+{
+ QI res = ADDQI (a, ADDQI (b, c));
+ return res;
+}
+
+SEMOPS_INLINE BI
+ADDCFQI (QI a, QI b, BI c)
+{
+ QI tmp = ADDQI (a, ADDQI (b, c));
+ BI res = ((UQI) tmp < (UQI) a) || (c && tmp == a);
+ return res;
+}
+
+SEMOPS_INLINE BI
+ADDOFQI (QI a, QI b, BI c)
+{
+ QI tmp = ADDQI (a, ADDQI (b, c));
+ BI res = (((a < 0) == (b < 0))
+ && ((a < 0) != (tmp < 0)));
+ return res;
+}
+
+SEMOPS_INLINE QI
+SUBCQI (QI a, QI b, BI c)
+{
+ QI res = SUBQI (a, ADDQI (b, c));
+ return res;
+}
+
+SEMOPS_INLINE BI
+SUBCFQI (QI a, QI b, BI c)
+{
+ BI res = ((UQI) a < (UQI) b) || (c && a == b);
+ return res;
+}
+
+SEMOPS_INLINE BI
+SUBOFQI (QI a, QI b, BI c)
+{
+ QI tmp = SUBQI (a, ADDQI (b, c));
+ BI res = (((a < 0) != (b < 0))
+ && ((a < 0) != (tmp < 0)));
+ return res;
+}
+
#else
SI ADDCSI (SI, SI, BI);
SI SUBCSI (SI, SI, BI);
UBI SUBCFSI (SI, SI, BI);
UBI SUBOFSI (SI, SI, BI);
+HI ADDCHI (HI, HI, BI);
+UBI ADDCFHI (HI, HI, BI);
+UBI ADDOFHI (HI, HI, BI);
+HI SUBCHI (HI, HI, BI);
+UBI SUBCFHI (HI, HI, BI);
+UBI SUBOFHI (HI, HI, BI);
+QI ADDCQI (QI, QI, BI);
+UBI ADDCFQI (QI, QI, BI);
+UBI ADDOFQI (QI, QI, BI);
+QI SUBCQI (QI, QI, BI);
+UBI SUBCFQI (QI, QI, BI);
+UBI SUBOFQI (QI, QI, BI);
#endif