Whitespace changes --flo
[libfirm] / ir / tv / tv.c
index 8b0a428..a69f45d 100644 (file)
@@ -1,6 +1,8 @@
 /* TV --- Target Values, aka Constant Table.
    Copyright (C) 1995, 1996 Christian von Roques */
 
+/* $Id$ */
+
 /* This implementation assumes:
    * target characters/strings can be represented as type `char'/`char *',
    * host's type `long'/`unsigned long' can hold values of mode `l'/`L',
    values is cheaper than the extra obstack_alloc()/free() for
    discarded ones.  */
 
+/* Defining this causes inclusions of functions renamed with new gmp.h */
+#define _TARVAL_GMP_ 0
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
 #endif
 
+# include "xprintf.h"
 #include <assert.h>
 #include <limits.h>
+#include <errno.h>
 #include <math.h>
 #include <stdlib.h>
 #include <string.h>
 #include "obst.h"
 #include "ieee754.h"
 #include "tune.h"
-#include "ident.h"
-#include "tv.h"
+#include "ident_t.h"
+#include "tv_t.h"
+#include "entity_t.h"
+#include "irmode.h"
 
 static struct obstack tv_obst; /* obstack for all the target values */
 static pset *tarvals;          /* pset containing pointers to _all_ tarvals */
@@ -135,9 +143,10 @@ tv_val_s (tarval *tv)
 static inline bool
 chil_overflow (tarval_chil chil, ir_mode *mode)
 {
-  assert (is_chilCHIL(mode->code));
-  return (mode->min && mode->max  /* only valid after firm initialization */
-         && (chil < tv_val_chil (mode->min) || tv_val_chil (mode->max) < chil));
+  assert (is_chilCHIL(get_mode_modecode(mode)));
+  return (get_mode_min(mode) && get_mode_max(mode)  /* only valid after firm initialization */
+         && (chil < tv_val_chil (get_mode_min(mode))
+             || tv_val_chil (get_mode_max(mode)) < chil));
 }
 
 
@@ -145,9 +154,9 @@ chil_overflow (tarval_chil chil, ir_mode *mode)
 static inline bool
 CHIL_overflow (tarval_CHIL CHIL, ir_mode *mode)
 {
-  assert (is_chilCHIL(mode->code));
-  return (mode->max   /* only valid after firm initialization */
-         && tv_val_CHIL (mode->max) < CHIL);
+  assert (is_chilCHIL(get_mode_modecode(mode)));
+  return (get_mode_max(mode)   /* only valid after firm initialization */
+         && tv_val_CHIL (get_mode_max(mode)) < CHIL);
 }
 
 
@@ -156,7 +165,7 @@ void
 _tarval_vrfy (const tarval *val)
 {
   assert (val);
-  switch (val->mode->code) {
+  switch (get_mode_modecode(val->mode)) {
     /* floating */
   case irm_f:
   case irm_d:
@@ -229,9 +238,10 @@ tarval_cmp (const void *p, const void *q)
   TARVAL_VRFY (b);
 
   if (a == b) return 0;
-  if (a->mode - b->mode) return a->mode - b->mode;
+  if ((void *)a->mode - (void *)b->mode)
+    return (void *)a->mode - (void *)b->mode;
 
-  switch (a->mode->code) {
+  switch (get_mode_modecode(a->mode)) {
     /* floating */
   case irm_f:
     return memcmp (&a->u.f, &b->u.f, sizeof (a->u.f));
@@ -250,7 +260,11 @@ tarval_cmp (const void *p, const void *q)
     }
     return a->u.chil != b->u.chil;
   case irm_Z:
+#if _TARVAL_GMP_
     return mpz_cmp (&a->u.Z, &b->u.Z);
+#else
+    return 99; /* ?? */
+#endif
     /* strange */
   case irm_p:
     if (a->u.p.ent || b->u.p.ent)
@@ -278,8 +292,8 @@ tarval_hash (tarval *tv)
 {
   unsigned h;
 
-  h = tv->mode->code * 0x421u;
-  switch (tv->mode->code) {
+  h = get_mode_modecode(tv->mode) * 0x421u;
+  switch (get_mode_modecode(tv->mode)) {
   case irm_T:
     h = 0x94b527ce; break;
   case irm_f:
@@ -303,7 +317,11 @@ tarval_hash (tarval *tv)
   case irm_c: case irm_h: case irm_i: case irm_l:
     h ^= tv->u.chil; break;
   case irm_Z:
+#if _TARVAL_GMP_
     h ^= mpz_get_ui (&tv->u.Z); break;
+#else
+    h ^= (unsigned int) tv; break; /* tut das? */
+#endif
   case irm_p:
     if (tv->u.p.ent) {
       /* @@@ lower bits not random, watch for collisions; perhaps
@@ -333,7 +351,7 @@ tarval_hash (tarval *tv)
 
 
 \f
-/******************** Initialization ****************************************/
+/*** ***************** Initialization ************************************* ***/
 
 void
 tarval_init_1 (void)
@@ -374,7 +392,6 @@ tarval_init_2 (void)
 
   tv = (tarval *)obstack_alloc (&tv_obst, sizeof (tarval));
   tv->mode = mode_T;
-  tv->lab = 0;
   tarval_bad = tarval_identify (tv);
 
   tarval_b_false = tarval_from_long (mode_b, 0);
@@ -383,7 +400,6 @@ tarval_init_2 (void)
   /* IsInf <-> exponent == 0x7ff && ! (bits | fraction_low) */
   tv = (tarval *)obstack_alloc (&tv_obst, sizeof (tarval));
   tv->mode = mode_d;
-  tv->lab = 0;
   x.ieee.negative = 0;
   x.ieee.exponent = 0x7ff;
   x.ieee.mantissa0 = 0;
@@ -394,7 +410,6 @@ tarval_init_2 (void)
   /* IsNaN <-> exponent==0x7ff  && (qnan_bit | bits | fraction_low) */
   tv = (tarval *)obstack_alloc (&tv_obst, sizeof (tarval));
   tv->mode = mode_d;
-  tv->lab = 0;
   x.ieee_nan.negative = 0;
   x.ieee_nan.exponent = 0x7ff;
   x.ieee_nan.quiet_nan = 1;    /* @@@ quiet or signalling? */
@@ -406,7 +421,6 @@ tarval_init_2 (void)
 
   tv = (tarval *)obstack_alloc (&tv_obst, sizeof (tarval));
   tv->mode = mode_p;
-  tv->lab = 0;
   tv->u.p.xname = NULL;
   tv->u.p.ent = NULL;
   tv->u.p.tv = NULL;
@@ -431,7 +445,7 @@ tarval_init_2 (void)
 
 
 \f
-/************************* Constructors for tarvals *************************/
+/*** ********************** Constructors for tarvals ********************** ***/
 
 /* copy from src to dst len chars omitting '_'. */
 static char *
@@ -462,8 +476,11 @@ tarval_Z_from_str (const char *s, size_t len, int base)
 
   tv = (tarval *)obstack_alloc (&tv_obst, sizeof (tarval));
   tv->mode = mode_Z;
-  tv->lab = 0;
+#if _TARVAL_GMP_
   if (mpz_init_set_str (&tv->u.Z, buf, base)) assert (0);
+#else
+  assert(0 && "no support for Z in tv!");
+#endif
 
   return tarval_identify (tv);
 }
@@ -484,7 +501,6 @@ tarval_B_from_str (const char *s, size_t len)
 
   tv = (tarval *)obstack_alloc (&tv_obst, sizeof (tarval));
   tv->mode = mode_B;
-  tv->lab = 0;
 
   assert (s[0] == '0');
   switch (s[1]) {
@@ -541,6 +557,27 @@ tarval_B_from_str (const char *s, size_t len)
 }
 
 
+tarval *
+tarval_f_from_str (const char *s, size_t len)
+{
+  tarval *tv;
+  char *buf;
+  char *eptr;
+
+  assert (!BUILDING);
+
+  buf = alloca (len+1);
+  stripcpy (buf, s, len);
+
+  tv = (tarval *)obstack_alloc (&tv_obst, sizeof (tarval));
+  tv->mode = mode_f;
+  tv->u.f = (float)strtod (buf, &eptr);
+  assert (eptr == buf+strlen(buf));
+
+  return tarval_identify (tv);
+}
+
+
 tarval *
 tarval_d_from_str (const char *s, size_t len)
 {
@@ -555,7 +592,6 @@ tarval_d_from_str (const char *s, size_t len)
 
   tv = (tarval *)obstack_alloc (&tv_obst, sizeof (tarval));
   tv->mode = mode_d;
-  tv->lab = 0;
   tv->u.d = strtod (buf, &eptr);
   assert (eptr == buf+strlen(buf));
 
@@ -573,7 +609,6 @@ tarval_s_from_str (const char *s, size_t len)
   tv = (tarval *)obstack_alloc (&tv_obst, sizeof (tarval));
 
   tv->mode = mode_s;
-  tv->lab = 0;
   tv->u.s.n = len;
   tv->u.s.p = obstack_copy (&tv_obst, s, len);
 
@@ -590,13 +625,34 @@ tarval_S_from_str (const char *s, size_t len)
   tv = (tarval *)obstack_alloc (&tv_obst, sizeof (tarval));
 
   tv->mode = mode_S;
-  tv->lab = 0;
   tv->u.s.n = len;
   tv->u.s.p = obstack_copy (&tv_obst, s, len);
 
   return tarval_identify (tv);
 }
 
+tarval *tarval_int_from_str (const char *s, size_t len, int base, ir_mode *m) {
+  long val;
+  char *eptr;
+  char *buf;
+
+  assert (mode_is_int(m));
+  assert (!BUILDING);
+
+  buf = alloca (len+1);
+  stripcpy (buf, s, len);
+
+  errno = 0;
+  val = strtol(buf, &eptr, base);    /* strtoll */
+  assert (eptr == buf+strlen(buf));
+  if ((errno == ERANGE)               &&
+      ((m == mode_l) || (m == mode_L))  ) {
+    printf("WARNING: Constant %s not representable. Continuing with %ld.\n",
+          s, val);
+  }
+
+  return tarval_from_long(m, val);
+}
 
 /* Create a tarval with mode `m' and value `i' casted to the type that
    represents such tarvals on host.  The resulting value must be legal
@@ -613,8 +669,7 @@ tarval_from_long (ir_mode *m, long val)
   tv = (tarval *)obstack_alloc (&tv_obst, sizeof (tarval));
 
   tv->mode = m;
-  tv->lab = 0;
-  switch (m->code) {
+  switch (get_mode_modecode(m)) {
     /* floating */
   case irm_f:
     tv->u.f = val; break;
@@ -627,7 +682,11 @@ tarval_from_long (ir_mode *m, long val)
   case irm_c: case irm_h: case irm_i: case irm_l:
     tv->u.chil = val; break;
   case irm_Z:
+#if _TARVAL_GMP_
     mpz_init_set_si (&tv->u.Z, val);
+#else
+    assert(0 && "no support for Z in tv!");
+#endif
     break;
     /* strange */
   case irm_p:
@@ -655,7 +714,6 @@ tarval_p_from_str (const char *xname)
   tv = (tarval *)obstack_alloc (&tv_obst, sizeof (tarval));
 
   tv->mode = mode_p;
-  tv->lab = 0;
   tv->u.p.xname = obstack_copy0 (&tv_obst, xname, strlen (xname));
   tv->u.p.ent = NULL;
   tv->u.p.tv = NULL;
@@ -673,7 +731,6 @@ tarval_p_from_entity (entity *ent)
   tv = (tarval *)obstack_alloc (&tv_obst, sizeof (tarval));
 
   tv->mode = mode_p;
-  tv->lab = 0;
   tv->u.p.xname = NULL;
   tv->u.p.ent = ent;
   tv->u.p.tv = NULL;
@@ -736,9 +793,8 @@ tarval_finish_as (ir_mode *m)
   tv = obstack_finish (&tv_obst);
   p = (unsigned char *)tv + sizeof (tarval);
   tv->mode = m;
-  tv->lab = 0;
 
-  switch (m->code) {
+  switch (get_mode_modecode(m)) {
   case irm_C:
     tv->u.CHIL = ch;
     break;
@@ -773,7 +829,7 @@ tarval_cancel (void)
 
 
 \f
-/********************* Arithmethic operations on tarvals ********************/
+/*** ****************** Arithmethic operations on tarvals ***************** ***/
 
 /* Return `src' converted to mode `m' if representable, else NULL.
    @@@ lots of conversions missing */
@@ -786,9 +842,8 @@ tarval_convert_to (tarval *src, ir_mode *m)
 
   tv = (tarval *)obstack_alloc (&tv_obst, sizeof (tarval));
   tv->mode = m;
-  tv->lab = 0;
 
-  switch (src->mode->code) {
+  switch (get_mode_modecode(src->mode)) {
 
   case irm_d:
     if (m != mode_f) goto fail;
@@ -796,7 +851,8 @@ tarval_convert_to (tarval *src, ir_mode *m)
     break;
 
   case irm_Z:
-    switch (m->code) {
+#if _TARVAL_GMP_
+    switch (get_mode_modecode(m)) {
 
     case irm_C: case irm_H: case irm_I: case irm_L:
       if (mpz_cmp_si (&src->u.Z, 0) < 0) goto fail;
@@ -821,10 +877,13 @@ tarval_convert_to (tarval *src, ir_mode *m)
 
     default: goto fail;
     }
+#else
+    goto fail;
+#endif
     break;
 
   case irm_c: case irm_h: case irm_i: case irm_l:
-    switch (m->code) {
+    switch (get_mode_modecode(m)) {
     case irm_c: case irm_h: case irm_i: case irm_l:
       tv->u.chil = src->u.chil;
       if (chil_overflow (tv->u.chil, m)) goto fail;
@@ -836,7 +895,11 @@ tarval_convert_to (tarval *src, ir_mode *m)
       break;
 
     case irm_Z:
+#if _TARVAL_GMP_
       mpz_init_set_si (&tv->u.Z, src->u.chil);
+#else
+      goto fail;
+#endif
       break;
 
     case irm_b:
@@ -847,7 +910,7 @@ tarval_convert_to (tarval *src, ir_mode *m)
     }
 
   case irm_C: case irm_H: case irm_I: case irm_L:
-    switch (m->code) {
+    switch (get_mode_modecode(m)) {
     case irm_c: case irm_h: case irm_i: case irm_l:
       tv->u.chil = src->u.CHIL;
       if (chil_overflow (tv->u.chil, m)) goto fail;
@@ -859,7 +922,11 @@ tarval_convert_to (tarval *src, ir_mode *m)
       break;
 
     case irm_Z:
+#if _TARVAL_GMP_
       mpz_init_set_ui (&tv->u.Z, src->u.CHIL);
+#else
+      goto fail;
+#endif
       break;
 
     case irm_b:
@@ -871,7 +938,7 @@ tarval_convert_to (tarval *src, ir_mode *m)
     break;
 
   case irm_b:
-    switch (m->code) {
+    switch (get_mode_modecode(m)) {
     case irm_c: case irm_h: case irm_i: case irm_l:
       tv->u.chil = src->u.b;
       break;
@@ -893,6 +960,7 @@ tarval_convert_to (tarval *src, ir_mode *m)
 }
 
 
+/* GL Why are there no ArmRoq comments, why is this not used? */
 tarval *
 tarval_neg (tarval *a)
 {
@@ -903,15 +971,14 @@ tarval_neg (tarval *a)
   tv = (tarval *)obstack_alloc (&tv_obst, sizeof (tarval));
 
   tv->mode = a->mode;
-  tv->lab = 0;
 
-  switch (a->mode->code) {
+  switch (get_mode_modecode(a->mode)) {
     /* floating */
   case irm_f: tv->u.f = -a->u.f; break;
   case irm_d: tv->u.d = -a->u.d; break;
     /* unsigned */
   case irm_C: case irm_H: case irm_I: case irm_L:
-    tv->u.CHIL = -a->u.CHIL & tv_val_CHIL (a->mode->max);
+    tv->u.CHIL = -a->u.CHIL & tv_val_CHIL (get_mode_max(a->mode));
     break;
     /* signed */
   case irm_c: case irm_h: case irm_i: case irm_l:
@@ -923,8 +990,14 @@ tarval_neg (tarval *a)
     }
     break;
   case irm_Z:
+#if _TARVAL_GMP_
     mpz_init (&tv->u.Z);
     mpz_neg (&tv->u.Z, &a->u.Z);
+#else
+    obstack_free (&tv_obst, tv);
+    tv = a;
+    printf("\nWrong negation\n\n");
+#endif
     break;
     /* strange */
   case irm_b: tv->u.b = !a->u.b; break;
@@ -947,7 +1020,7 @@ tarval_comp (tarval *a, tarval *b)
 
   assert (a->mode == b->mode);
 
-  switch (a->mode->code) {
+  switch (get_mode_modecode(a->mode)) {
     /* floating */
   case irm_f: return (  a->u.f == b->u.f ? irpn_Eq
                      : a->u.f > b->u.f ? irpn_Gt
@@ -968,10 +1041,15 @@ tarval_comp (tarval *a, tarval *b)
            : a->u.chil > b->u.chil ? irpn_Gt
            : irpn_Lt);
   case irm_Z:
-    { int cmp = mpz_cmp (&a->u.Z, &b->u.Z);
+    {
+#if _TARVAL_GMP_
+      int cmp = mpz_cmp (&a->u.Z, &b->u.Z);
       return (  cmp == 0 ? irpn_Eq
              : cmp > 0 ? irpn_Gt
              : irpn_Lt);
+#else
+      return irpn_False;
+#endif
     }
     /* strange */
   case irm_b: return (  a->u.b == b->u.b ? irpn_Eq
@@ -1000,15 +1078,14 @@ tarval_add (tarval *a, tarval *b)
   tv = (tarval *)obstack_alloc (&tv_obst, sizeof (tarval));
 
   tv->mode = a->mode;
-  tv->lab = 0;
 
-  switch (a->mode->code) {
+  switch (get_mode_modecode(a->mode)) {
     /* floating */
   case irm_f: tv->u.f = a->u.f + b->u.f; break;        /* @@@ overflow etc */
   case irm_d: tv->u.d = a->u.d + b->u.d; break; /* @@@ dto. */
     /* unsigned */
   case irm_C: case irm_H: case irm_I: case irm_L:
-    tv->u.CHIL = (a->u.CHIL + b->u.CHIL) & tv_val_CHIL (a->mode->max);
+    tv->u.CHIL = (a->u.CHIL + b->u.CHIL) & tv_val_CHIL (get_mode_max(a->mode));
     break;
     /* signed */
   case irm_c: case irm_h: case irm_i: case irm_l:
@@ -1020,8 +1097,13 @@ tarval_add (tarval *a, tarval *b)
     }
     break;
   case irm_Z:
+#if _TARVAL_GMP_
     mpz_init (&tv->u.Z);
     mpz_add (&tv->u.Z, &a->u.Z, &b->u.Z);
+#else
+    obstack_free (&tv_obst, tv);
+    return NULL;
+#endif
     break;
     /* strange */
   case irm_b: tv->u.b = a->u.b | b->u.b; break;        /* u.b is in canonical form */
@@ -1044,15 +1126,14 @@ tarval_sub (tarval *a, tarval *b)
   tv = (tarval *)obstack_alloc (&tv_obst, sizeof (tarval));
 
   tv->mode = a->mode;
-  tv->lab = 0;
 
-  switch (a->mode->code) {
+  switch (get_mode_modecode(a->mode)) {
     /* floating */
   case irm_f: tv->u.f = a->u.f - b->u.f; break;        /* @@@ overflow etc */
   case irm_d: tv->u.d = a->u.d - b->u.d; break; /* @@@ dto. */
     /* unsigned */
   case irm_C: case irm_H: case irm_I: case irm_L:
-    tv->u.CHIL = (a->u.CHIL - b->u.CHIL) & tv_val_CHIL (a->mode->max);
+    tv->u.CHIL = (a->u.CHIL - b->u.CHIL) & tv_val_CHIL (get_mode_max(a->mode));
     break;
     /* signed */
   case irm_c: case irm_h: case irm_i: case irm_l:
@@ -1064,8 +1145,13 @@ tarval_sub (tarval *a, tarval *b)
     }
     break;
   case irm_Z:
+#if _TARVAL_GMP_
     mpz_init (&tv->u.Z);
     mpz_sub (&tv->u.Z, &a->u.Z, &b->u.Z);
+#else
+    obstack_free (&tv_obst, tv);
+    return NULL;
+#endif
     break;
     /* strange */
   case irm_b: tv->u.b = a->u.b & ~b->u.b; break; /* u.b is in canonical form */
@@ -1075,7 +1161,6 @@ tarval_sub (tarval *a, tarval *b)
   return tarval_identify (tv);
 }
 
-
 /* Return `a*b' if computable, else NULL.  Modes must be equal.  */
 tarval *
 tarval_mul (tarval *a, tarval *b)
@@ -1088,15 +1173,14 @@ tarval_mul (tarval *a, tarval *b)
   tv = (tarval *)obstack_alloc (&tv_obst, sizeof (tarval));
 
   tv->mode = a->mode;
-  tv->lab = 0;
 
-  switch (a->mode->code) {
+  switch (get_mode_modecode(a->mode)) {
     /* floating */
   case irm_f: tv->u.f = a->u.f * b->u.f; break;        /* @@@ overflow etc */
   case irm_d: tv->u.d = a->u.d * b->u.d; break; /* @@@ dto. */
     /* unsigned */
   case irm_C: case irm_H: case irm_I: case irm_L:
-    tv->u.CHIL = (a->u.CHIL * b->u.CHIL) & tv_val_CHIL (a->mode->max);
+    tv->u.CHIL = (a->u.CHIL * b->u.CHIL) & tv_val_CHIL (get_mode_max(a->mode));
     break;
     /* signed */
   case irm_c: case irm_h: case irm_i: case irm_l:
@@ -1108,8 +1192,13 @@ tarval_mul (tarval *a, tarval *b)
     }
     break;
   case irm_Z:
+#if _TARVAL_GMP_
     mpz_init (&tv->u.Z);
     mpz_mul (&tv->u.Z, &a->u.Z, &b->u.Z);
+#else
+    obstack_free (&tv_obst, tv);
+    return NULL;
+#endif
     break;
     /* strange */
   case irm_b: tv->u.b = a->u.b & b->u.b; break;        /* u.b is in canonical form */
@@ -1130,18 +1219,16 @@ tarval_quo (tarval *a, tarval *b)
   TARVAL_VRFY (a); TARVAL_VRFY (b);
   assert (a->mode == b->mode);
 
-  switch (a->mode->code) {
+  switch (get_mode_modecode(a->mode)) {
     /* floating */
   case irm_f:
     tv = (tarval *)obstack_alloc (&tv_obst, sizeof (tarval));
     tv->mode = mode_f;
-    tv->lab = 0;
     tv->u.f = a->u.f / b->u.f; /* @@@ overflow etc */
     break;
   case irm_d:
     tv = (tarval *)obstack_alloc (&tv_obst, sizeof (tarval));
     tv->mode = mode_d;
-    tv->lab = 0;
     tv->u.d = a->u.d / b->u.d; /* @@@ overflow etc */
     break;
   default:
@@ -1166,9 +1253,8 @@ tarval_div (tarval *a, tarval *b)
   tv = (tarval *)obstack_alloc (&tv_obst, sizeof (tarval));
 
   tv->mode = a->mode;
-  tv->lab = 0;
 
-  switch (a->mode->code) {
+  switch (get_mode_modecode(a->mode)) {
     /* floating */
   case irm_f: tv->u.f = floor (a->u.f / b->u.f); break; /* @@@ overflow etc */
   case irm_d: tv->u.d = floor (a->u.d / b->u.d); break; /* @@@ dto. */
@@ -1180,7 +1266,7 @@ tarval_div (tarval *a, tarval *b)
     /* signed */
   case irm_c: case irm_h: case irm_i: case irm_l:
     if (   !b->u.chil
-       || ((b->u.chil == -1) && (a->u.chil == tv_val_chil (a->mode->max) ))) {
+       || ((b->u.chil == -1) && (a->u.chil == tv_val_chil (get_mode_max(a->mode)) ))) {
     fail:
       obstack_free (&tv_obst, tv);
       return NULL;
@@ -1188,9 +1274,13 @@ tarval_div (tarval *a, tarval *b)
     tv->u.chil = a->u.chil / b->u.chil;
     break;
   case irm_Z:
+#if _TARVAL_GMP_
     if (!mpz_cmp_ui (&b->u.Z, 0)) goto fail;
     mpz_init (&tv->u.Z);
     mpz_div (&tv->u.Z, &a->u.Z, &b->u.Z);
+#else
+    goto fail;
+#endif
     break;
     /* strange */
   case irm_b: tv->u.b = a->u.b ^ b->u.b; break;        /* u.b is in canonical form */
@@ -1213,9 +1303,8 @@ tarval_mod (tarval *a, tarval *b)
   tv = (tarval *)obstack_alloc (&tv_obst, sizeof (tarval));
 
   tv->mode = a->mode;
-  tv->lab = 0;
 
-  switch (a->mode->code) {
+  switch (get_mode_modecode(a->mode)) {
     /* floating */
   case irm_f: tv->u.f = fmod (a->u.f, b->u.f); break; /* @@@ overflow etc */
   case irm_d: tv->u.d = fmod (a->u.d, b->u.d); break; /* @@@ dto */
@@ -1234,9 +1323,13 @@ tarval_mod (tarval *a, tarval *b)
     tv->u.chil = a->u.chil % b->u.chil;
     break;
   case irm_Z:
+#if _TARVAL_GMP_
     if (!mpz_cmp_ui (&b->u.Z, 0)) goto fail;
     mpz_init (&tv->u.Z);
     mpz_mod (&tv->u.Z, &a->u.Z, &b->u.Z);
+#else
+    goto fail;
+#endif
     break;
     /* strange */
   case irm_b: tv->u.b = a->u.b ^ b->u.b; break;        /* u.b is in canonical form */
@@ -1246,6 +1339,39 @@ tarval_mod (tarval *a, tarval *b)
   return tarval_identify (tv);
 }
 
+/* Return |a| if computable, else Null. */
+/*  is -max == min?? */
+tarval *
+tarval_abs (tarval *a) {
+  TARVAL_VRFY (a);
+  if (tv_is_negative(a)) return tarval_neg(a);
+  return a;
+}
+
+int
+tv_is_negative(tarval *a) {
+  TARVAL_VRFY (a);
+  switch (get_mode_modecode(a->mode)) {
+    /* floating */
+  case irm_f: return (a->u.f<0); break;
+  case irm_d: return (a->u.d<0); break;
+    /* unsigned */
+  case irm_C: case irm_H: case irm_I: case irm_L:
+    return 0;
+    break;
+    /* signed */
+  case irm_c: case irm_h: case irm_i: case irm_l:
+    return (a->u.chil < 0);
+    break;
+  case irm_Z:
+    break;
+  case irm_b: break;
+  default: assert(0);
+  }
+
+  return 0;
+}
+
 
 /* Return `a&b'.  Modes must be equal.  */
 tarval *
@@ -1259,9 +1385,8 @@ tarval_and (tarval *a, tarval *b)
   tv = (tarval *)obstack_alloc (&tv_obst, sizeof (tarval));
 
   tv->mode = a->mode;
-  tv->lab = 0;
 
-  switch (a->mode->code) {
+  switch (get_mode_modecode(a->mode)) {
     /* unsigned */
   case irm_C: case irm_H: case irm_I: case irm_L:
     tv->u.CHIL = a->u.CHIL & b->u.CHIL; break;
@@ -1269,8 +1394,12 @@ tarval_and (tarval *a, tarval *b)
   case irm_c: case irm_h: case irm_i: case irm_l:
     tv->u.chil = a->u.chil & b->u.chil; break;
   case irm_Z:
+#if _TARVAL_GMP_
     mpz_init (&tv->u.Z);
     mpz_and (&tv->u.Z, &a->u.Z, &b->u.Z);
+#else
+    assert(0);
+#endif
     break;
     /* strange */
   case irm_b: tv->u.b = a->u.b & b->u.b; break;        /* u.b is in canonical form */
@@ -1293,9 +1422,8 @@ tarval_or (tarval *a, tarval *b)
   tv = (tarval *)obstack_alloc (&tv_obst, sizeof (tarval));
 
   tv->mode = a->mode;
-  tv->lab = 0;
 
-  switch (a->mode->code) {
+  switch (get_mode_modecode(a->mode)) {
     /* unsigned */
   case irm_C: case irm_H: case irm_I: case irm_L:
     tv->u.CHIL = a->u.CHIL | b->u.CHIL; break;
@@ -1303,8 +1431,12 @@ tarval_or (tarval *a, tarval *b)
   case irm_c: case irm_h: case irm_i: case irm_l:
     tv->u.chil = a->u.chil | b->u.chil; break;
   case irm_Z:
+#if _TARVAL_GMP_
     mpz_init (&tv->u.Z);
     mpz_ior (&tv->u.Z, &a->u.Z, &b->u.Z);
+#else
+    assert(0);
+#endif
     break;
     /* strange */
   case irm_b: tv->u.b = a->u.b | b->u.b; break;        /* u.b is in canonical form */
@@ -1331,9 +1463,8 @@ tarval_eor (tarval *a, tarval *b)
   tv = (tarval *)obstack_alloc (&tv_obst, sizeof (tarval));
 
   tv->mode = a->mode;
-  tv->lab = 0;
 
-  switch (a->mode->code) {
+  switch (get_mode_modecode(a->mode)) {
     /* unsigned */
   case irm_C: case irm_H: case irm_I: case irm_L:
     tv->u.CHIL = a->u.CHIL ^ b->u.CHIL; break;
@@ -1341,7 +1472,8 @@ tarval_eor (tarval *a, tarval *b)
   case irm_c: case irm_h: case irm_i: case irm_l:
     tv->u.chil = a->u.chil ^ b->u.chil; break;
   case irm_Z:
-#if 0 /* gmp-1.3.2 declares but does not define mpz_xor() */
+#if 0
+    /* gmp-1.3.2 declares but does not define mpz_xor() */
     mpz_init (&tv->u.Z);
     mpz_xor (&tv->u.Z, &a->u.Z, &b->u.Z);
 #endif
@@ -1368,15 +1500,14 @@ tarval_shl (tarval *a, tarval *b)
   shift = tarval_ord (b, &b_is_huge);
   if (   b_is_huge
       || (shift < 0)
-      || ((shift >= mode_l->size*target_bits) && (a->mode != mode_Z))) {
+      || ((shift >= get_mode_size(mode_l)*target_bits) && (a->mode != mode_Z))) {
     return NULL;
   }
 
   tv = (tarval *)obstack_alloc (&tv_obst, sizeof (tarval));
   tv->mode = a->mode;
-  tv->lab = 0;
 
-  switch (a->mode->code) {
+  switch (get_mode_modecode(a->mode)) {
     /* unsigned */
   case irm_C: case irm_H: case irm_I: case irm_L:
     tv->u.CHIL = a->u.CHIL << shift;
@@ -1386,8 +1517,12 @@ tarval_shl (tarval *a, tarval *b)
     tv->u.chil = a->u.chil << shift;
     break;
   case irm_Z:
+#if _TARVAL_GMP_
     mpz_init (&tv->u.Z);
     mpz_mul_2exp (&tv->u.Z, &a->u.Z, shift);
+#else
+    assert(0);
+#endif
     break;
   default: assert (0);
   }
@@ -1396,7 +1531,9 @@ tarval_shl (tarval *a, tarval *b)
 }
 
 
-/* Return `a>>b' if computable, else NULL.  */
+/* Return `a>>b' if computable, else NULL.
+   The interpretation of >> (sign extended or not) is implementaion
+   dependent, i.e. this is neither shr nor shrs!! */
 tarval *
 tarval_shr (tarval *a, tarval *b)
 {
@@ -1409,15 +1546,14 @@ tarval_shr (tarval *a, tarval *b)
   shift = tarval_ord (b, &b_is_huge);
   if (   b_is_huge
       || (shift < 0)
-      || ((shift >= mode_l->size*target_bits) && (a->mode != mode_Z))) {
+      || ((shift >= get_mode_size(mode_l)*target_bits) && (a->mode != mode_Z))) {
     return NULL;
   }
 
   tv = (tarval *)obstack_alloc (&tv_obst, sizeof (tarval));
   tv->mode = a->mode;
-  tv->lab = 0;
 
-  switch (a->mode->code) {
+  switch (get_mode_modecode(a->mode)) {
     /* unsigned */
   case irm_C: case irm_H: case irm_I: case irm_L:
     tv->u.CHIL = a->u.CHIL >> shift;
@@ -1427,8 +1563,12 @@ tarval_shr (tarval *a, tarval *b)
     tv->u.chil = a->u.chil >> shift;
     break;
   case irm_Z:
+#if _TARVAL_GMP_
     mpz_init (&tv->u.Z);
     mpz_div_2exp (&tv->u.Z, &a->u.Z, shift);
+#else
+    assert(0);
+#endif
     break;
   default: assert (0);
   }
@@ -1448,26 +1588,28 @@ tarval_classify (tarval *tv)
 
   TARVAL_VRFY (tv);
 
-  switch (tv->mode->code) {
+  switch (get_mode_modecode(tv->mode)) {
     /* floating */
   case irm_f: case irm_d:
     return 2;
     /* unsigned */
   case irm_C:
-    return (long)((tv->u.CHIL+1) & tv_val_CHIL (mode_C->max)) - 1;
+    return (long)((tv->u.CHIL+1) & tv_val_CHIL (get_mode_max(mode_C))) - 1;
   case irm_H:
-    return (long)((tv->u.CHIL+1) & tv_val_CHIL (mode_H->max)) - 1;
+    return (long)((tv->u.CHIL+1) & tv_val_CHIL (get_mode_max(mode_H))) - 1;
   case irm_I:
-    return (long)((tv->u.CHIL+1) & tv_val_CHIL (mode_I->max)) - 1;
+    return (long)((tv->u.CHIL+1) & tv_val_CHIL (get_mode_max(mode_I))) - 1;
   case irm_L:
-    return (long)((tv->u.CHIL+1) & tv_val_CHIL (mode_L->max)) - 1;
+    return (long)((tv->u.CHIL+1) & tv_val_CHIL (get_mode_max(mode_L))) - 1;
     /* signed */
   case irm_c: case irm_h: case irm_i: case irm_l:
     return tv->u.chil;
   case irm_Z:
+#if _TARVAL_GMP_
     if      (mpz_cmp_si (&tv->u.Z, 0)) return 0;
     else if (mpz_cmp_si (&tv->u.Z, 1)) return 1;
     else if (mpz_cmp_si (&tv->u.Z,-1)) return -1;
+#endif
     return 2;
     /* strange */
   case irm_b:
@@ -1478,6 +1620,7 @@ tarval_classify (tarval *tv)
 }
 
 
+#if _TARVAL_GMP_
 bool
 tarval_s_fits (tarval *tv, long min, long max) {
   return ((  mpz_cmp_si (&tv->u.Z, min) >= 0)
@@ -1489,7 +1632,7 @@ tarval_u_fits (tarval *tv, unsigned long max) {
   return ((  mpz_sgn (&tv->u.Z) >= 0)
          && mpz_cmp_si (&tv->u.Z, max) <= 0);
 }
-
+#endif
 
 /* Convert `tv' into type `long', set `fail' if not representable.
    If `fail' gets set for an unsigned `tv', the correct result can be
@@ -1499,19 +1642,24 @@ tarval_ord (tarval *tv, int *fail)
 {
   TARVAL_VRFY (tv);
 
-  switch (tv->mode->code) {
+  switch (get_mode_modecode(tv->mode)) {
     /* unsigned */
   case irm_C: case irm_H: case irm_I: case irm_L:
-    *fail = tv->u.CHIL > tv_val_CHIL (mode_l->max);
+    *fail = tv->u.CHIL > tv_val_CHIL (get_mode_max(mode_l));
     return tv->u.CHIL;
     /* signed */
   case irm_c: case irm_h: case irm_i: case irm_l:
     *fail = 0;
     return tv->u.chil;
   case irm_Z:
-    *fail = (   (mpz_cmp_si (&tv->u.Z, tv_val_chil(mode_l->max)) > 0)
-            || (mpz_cmp_si (&tv->u.Z, tv_val_chil(mode_l->min)) < 0));
+#if _TARVAL_GMP_
+    *fail = (   (mpz_cmp_si (&tv->u.Z, tv_val_chil(get_mode_max(mode_l))) > 0)
+            || (mpz_cmp_si (&tv->u.Z, tv_val_chil(get_mode_max(mode_l))) < 0));
     return mpz_get_si (&tv->u.Z);
+#else
+    *fail = 1;
+    return 0;
+#endif
     /* strange */
   case irm_b:
     *fail = 0;
@@ -1522,27 +1670,28 @@ tarval_ord (tarval *tv, int *fail)
   }
 }
 
-
 \f
 int
 tarval_print (XP_PAR1, const xprintf_info *info ATTRIBUTE((unused)), XP_PARN)
 {
   tarval *val = XP_GETARG (tarval *, 0);
   int printed;
+  char buf[40];
 
   TARVAL_VRFY (val);
 
-  switch (val->mode->code) {
+  switch (get_mode_modecode(val->mode)) {
 
   case irm_T:                  /* none */
     printed = XPSR ("<bad>");
     break;
 
   case irm_f:                  /* float */
-    printed = XPF1R ("%g", (double)(val->u.f));
+    sprintf (buf, "%1.9e", (float)(val->u.f));
+    printed = XPF1R ("%s", buf);
     break;
   case irm_d:                  /* double */
-    printed = XPF1R ("%g", (double)(val->u.d));
+    printed = XPF1R ("%1.30g", (double)(val->u.d));
     break;
 
   case irm_c:                  /* signed char */
@@ -1550,7 +1699,7 @@ tarval_print (XP_PAR1, const xprintf_info *info ATTRIBUTE((unused)), XP_PARN)
     if (isprint (val->u.chil)) {
       printed = XPF1R ("'%c'", val->u.chil);
     } else {
-      printed = XPF1R ("'\\%03o'", val->u.chil);
+      printed = XPF1R ("0x%x", (unsigned long)val->u.chil);
     }
     break;
 
@@ -1569,7 +1718,10 @@ tarval_print (XP_PAR1, const xprintf_info *info ATTRIBUTE((unused)), XP_PARN)
     if (val->u.p.xname) {
       printed = XPR (val->u.p.xname);
     } else if (val->u.p.ent) {
-      printed = XPF1R ("(%I)", val->u.p.ent->name);
+      if (get_entity_peculiarity(val->u.p.ent) == existent)
+       printed = XPF1R ("&(%I)", get_entity_ld_ident(val->u.p.ent));
+      else
+       printed = XPSR ("(NULL)");
     } else {
       assert (val == tarval_p_void);
       printed = XPSR ("(void)");
@@ -1620,37 +1772,16 @@ tarval_print (XP_PAR1, const xprintf_info *info ATTRIBUTE((unused)), XP_PARN)
   return printed;
 }
 
-\f
-/* Labeling of tarvals */
-// CS-hac
-/*
-label
-tarval_label (tarval *tv)
-{
-  if (!tv->lab) {
-    tv->lab = new_label();
-    tv->used = 1;
-  }
-  return tv->lab;
-}
-
-
-void
-tarval_forall_labeled (int (*f) (tarval *, void *), void *data)
-{
-  tarval *tv;
-
-  for (tv = pset_first (tarvals);  tv;  tv = pset_next (tarvals)) {
-    if (tv->lab && f (tv, data)) {
-      pset_break (tarvals);
-      return;
-    }
-  }
-}
-*/
 
 ir_mode *
 get_tv_mode (tarval *tv)
 {
   return tv->mode;
 }
+
+
+entity *get_tv_entity(tarval *tv)
+{
+  /*assert(??? && "not a pointer to an entity");*/
+  return tv->u.p.ent;
+}