2 * Copyright (C) 1995-2008 University of Karlsruhe. All right reserved.
4 * This file is part of libFirm.
6 * This file may be distributed and/or modified under the terms of the
7 * GNU General Public License version 2 as published by the Free Software
8 * Foundation and appearing in the file LICENSE.GPL included in the
9 * packaging of this file.
11 * Licensees holding valid libFirm Professional Edition licenses may use
12 * this file in accordance with the libFirm Commercial License.
13 * Agreement provided with the Software.
15 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
16 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * @brief Representation of and static computations on target machine
25 * @author Mathias Heil
29 * Values are stored in a format depending upon chosen arithmetic
30 * module. Default uses strcalc and fltcalc.
31 * This implementation assumes:
32 * - target has IEEE-754 floating-point arithmetic.
44 #include "bitfiddle.h"
54 #include "firm_common.h"
57 /** Size of hash tables. Should correspond to average number of distinct constant
59 #define N_CONSTANTS 2048
61 /* get the integer overflow mode */
62 #define GET_OVERFLOW_MODE() int_overflow_mode
64 /* unused, float to int doesn't work yet */
65 enum float_to_int_mode {
70 #define GET_FLOAT_TO_INT_MODE() TRUNCATE
72 #define SWITCH_NOINFINITY 0
73 #define SWITCH_NODENORMALS 0
75 /****************************************************************************
76 * local definitions and macros
77 ****************************************************************************/
79 # define TARVAL_VERIFY(a) tarval_verify((a))
81 # define TARVAL_VERIFY(a) ((void)0)
84 #define INSERT_TARVAL(tv) ((tarval*)set_insert(tarvals, (tv), sizeof(tarval), hash_tv((tv))))
85 #define FIND_TARVAL(tv) ((tarval*)set_find(tarvals, (tv), sizeof(tarval), hash_tv((tv))))
87 #define INSERT_VALUE(val, size) (set_insert(values, (val), size, hash_val((val), size)))
88 #define FIND_VALUE(val, size) (set_find(values, (val), size, hash_val((val), size)))
90 #define fail_verify(a) _fail_verify((a), __FILE__, __LINE__)
92 /** A set containing all existing tarvals. */
93 static struct set *tarvals = NULL;
94 /** A set containing all existing values. */
95 static struct set *values = NULL;
97 /** The carry flag for SOME operations. -1 means UNDEFINED here */
98 static int carry_flag = -1;
100 /** The integer overflow mode. */
101 static tarval_int_overflow_mode_t int_overflow_mode = TV_OVERFLOW_WRAP;
103 /** if this is set non-zero, the constant folding for floating point is OFF */
104 static int no_float = 0;
106 /** IEEE-754r half precision */
107 static const ieee_descriptor_t half_desc = { 5, 10, 0, NORMAL };
108 /** IEEE-754 single precision */
109 static const ieee_descriptor_t single_desc = { 8, 23, 0, NORMAL };
110 /** IEEE-754 double precision */
111 static const ieee_descriptor_t double_desc = { 11, 52, 0, NORMAL };
112 /** Intel x87 extended precision */
113 static const ieee_descriptor_t extended_desc = { 15, 63, 1, NORMAL };
115 /** IEEE-754r quad precision */
116 static const ieee_descriptor_t quad_desc = { 15, 112, 0, NORMAL };
118 /****************************************************************************
120 ****************************************************************************/
122 static int hash_val(const void *value, unsigned int length);
123 static int hash_tv(tarval *tv);
124 static void _fail_verify(tarval *tv, const char* file, int line)
126 /* print a memory image of the tarval and throw an assertion */
128 panic("%s:%d: Invalid tarval: mode: %F\n value: [%p]", file, line, tv->mode, tv->value);
130 panic("%s:%d: Invalid tarval (null)", file, line);
133 inline static void tarval_verify(tarval *tv) __attribute__ ((unused));
136 inline static void tarval_verify(tarval *tv)
142 if ((tv == tarval_bad) || (tv == tarval_undefined)) return;
143 if ((tv == tarval_b_true) || (tv == tarval_b_false)) return;
145 if (!FIND_TARVAL(tv)) fail_verify(tv);
146 if (tv->length > 0 && !FIND_VALUE(tv->value, tv->length)) fail_verify(tv);
150 /** Hash a tarval. */
151 static int hash_tv(tarval *tv) {
152 return (PTR_TO_INT(tv->value) ^ PTR_TO_INT(tv->mode)) + tv->length;
155 /** Hash a value. Treat it as a byte array. */
156 static int hash_val(const void *value, unsigned int length) {
158 unsigned int hash = 0;
160 /* scramble the byte - array */
161 for (i = 0; i < length; ++i) {
162 hash += (hash << 5) ^ (hash >> 27) ^ ((char*)value)[i];
163 hash += (hash << 11) ^ (hash >> 17);
169 static int cmp_tv(const void *p1, const void *p2, size_t n) {
170 const tarval *tv1 = p1;
171 const tarval *tv2 = p2;
174 assert(tv1->kind == k_tarval);
175 assert(tv2->kind == k_tarval);
176 if (tv1->mode < tv2->mode)
178 if (tv1->mode > tv2->mode)
180 if (tv1->length < tv2->length)
182 if (tv1->length > tv2->length)
184 if (tv1->value < tv2->value)
186 if (tv1->value > tv2->value)
192 /** finds tarval with value/mode or creates new tarval */
193 static tarval *get_tarval(const void *value, int length, ir_mode *mode) {
200 /* if there already is such a value, it is returned, else value
201 * is copied into the set */
202 char *temp = alloca(length);
203 memcpy(temp, value, length);
204 if (get_mode_arithmetic(mode) == irma_twos_complement) {
205 sign_extend(temp, mode);
207 tv.value = INSERT_VALUE(temp, length);
211 /* if there is such a tarval, it is returned, else tv is copied
213 return (tarval *)INSERT_TARVAL(&tv);
219 static tarval *get_tarval_overflow(const void *value, int length, ir_mode *mode)
223 switch (get_mode_sort(mode)) {
225 /* addresses always wrap around */
226 temp = alloca(sc_get_buffer_length());
227 memcpy(temp, value, sc_get_buffer_length());
228 sc_truncate(get_mode_size_bits(mode), temp);
229 /* the sc_ module expects that all bits are set ... */
230 sign_extend(temp, mode);
231 return get_tarval(temp, length, mode);
233 case irms_int_number:
234 if (sc_comp(value, get_mode_max(mode)->value) == 1) {
235 switch (GET_OVERFLOW_MODE()) {
236 case TV_OVERFLOW_SATURATE:
237 return get_mode_max(mode);
238 case TV_OVERFLOW_WRAP:
239 temp = alloca(sc_get_buffer_length());
240 memcpy(temp, value, sc_get_buffer_length());
241 sc_truncate(get_mode_size_bits(mode), temp);
242 /* the sc_ module expects that all bits are set ... */
243 sign_extend(temp, mode);
244 return get_tarval(temp, length, mode);
245 case TV_OVERFLOW_BAD:
248 return get_tarval(value, length, mode);
251 if (sc_comp(value, get_mode_min(mode)->value) == -1) {
252 switch (GET_OVERFLOW_MODE()) {
253 case TV_OVERFLOW_SATURATE:
254 return get_mode_min(mode);
255 case TV_OVERFLOW_WRAP: {
256 char *temp = alloca(sc_get_buffer_length());
257 memcpy(temp, value, sc_get_buffer_length());
258 sc_truncate(get_mode_size_bits(mode), temp);
259 return get_tarval(temp, length, mode);
261 case TV_OVERFLOW_BAD:
264 return get_tarval(value, length, mode);
269 case irms_float_number:
270 if (SWITCH_NOINFINITY && fc_is_inf(value)) {
271 /* clip infinity to maximum value */
272 return fc_is_negative(value) ? get_mode_min(mode) : get_mode_max(mode);
275 if (SWITCH_NODENORMALS && fc_is_subnormal(value)) {
276 /* clip denormals to zero */
277 return get_mode_null(mode);
284 return get_tarval(value, length, mode);
288 * public variables declared in tv.h
290 static tarval reserved_tv[6];
292 tarval *tarval_b_false = &reserved_tv[0];
293 tarval *tarval_b_true = &reserved_tv[1];
294 tarval *tarval_bad = &reserved_tv[2];
295 tarval *tarval_undefined = &reserved_tv[3];
296 tarval *tarval_reachable = &reserved_tv[4];
297 tarval *tarval_unreachable = &reserved_tv[5];
300 * get the float descriptor for given mode.
302 static const ieee_descriptor_t *get_descriptor(const ir_mode *mode) {
303 switch (get_mode_size_bits(mode)) {
304 case 16: return &half_desc;
305 case 32: return &single_desc;
306 case 64: return &double_desc;
308 case 96: return &extended_desc;
309 case 128: return &quad_desc;
311 panic("Unsupported mode in get_descriptor()");
317 * public functions declared in tv.h
321 * Constructors =============================================================
323 tarval *new_tarval_from_str(const char *str, size_t len, ir_mode *mode)
325 const ieee_descriptor_t *desc;
331 switch (get_mode_sort(mode)) {
332 case irms_control_flow:
335 panic("Unsupported tarval creation with mode %F", mode);
337 case irms_internal_boolean:
338 /* match [tT][rR][uU][eE]|[fF][aA][lL][sS][eE] */
339 if (!strcasecmp(str, "true"))
340 return tarval_b_true;
341 else if (!strcasecmp(str, "false"))
342 return tarval_b_false;
344 /* XXX This is C semantics */
345 return atoi(str) ? tarval_b_true : tarval_b_false;
347 case irms_float_number:
348 desc = get_descriptor(mode);
349 fc_val_from_str(str, len, desc, NULL);
350 return get_tarval(fc_get_buffer(), fc_get_buffer_length(), mode);
353 if (!strcasecmp(str, "null"))
354 return get_tarval_null(mode);
356 case irms_int_number:
357 sc_val_from_str(str, len, NULL, mode);
358 return get_tarval(sc_get_buffer(), sc_get_buffer_length(), mode);
360 panic("Unsupported tarval creation with mode %F", mode);
364 * helper function, create a tarval from long
366 tarval *new_tarval_from_long(long l, ir_mode *mode) {
369 switch (get_mode_sort(mode)) {
370 case irms_internal_boolean:
371 /* XXX C semantics ! */
372 return l ? tarval_b_true : tarval_b_false ;
375 /* same as integer modes */
376 case irms_int_number:
377 sc_val_from_long(l, NULL);
378 return get_tarval(sc_get_buffer(), sc_get_buffer_length(), mode);
380 case irms_float_number:
381 return new_tarval_from_double((long double)l, mode);
384 assert(0 && "unsupported mode sort");
389 /* returns non-zero if can be converted to long */
390 int tarval_is_long(tarval *tv) {
391 if (!mode_is_int(tv->mode) && !mode_is_reference(tv->mode))
394 if (get_mode_size_bits(tv->mode) > (int) (sizeof(long) << 3)) {
395 /* the value might be too big to fit in a long */
396 sc_max_from_bits(sizeof(long) << 3, 0, NULL);
397 if (sc_comp(sc_get_buffer(), tv->value) == -1) {
398 /* really doesn't fit */
405 /* this might overflow the machine's long, so use only with small values */
406 long get_tarval_long(tarval* tv) {
407 assert(tarval_is_long(tv) && "tarval too big to fit in long");
409 return sc_val_to_long(tv->value);
412 tarval *new_tarval_from_double(long double d, ir_mode *mode) {
413 const ieee_descriptor_t *desc;
415 assert(mode && (get_mode_sort(mode) == irms_float_number));
416 desc = get_descriptor(mode);
417 fc_val_from_ieee754(d, desc, NULL);
418 return get_tarval(fc_get_buffer(), fc_get_buffer_length(), mode);
421 /* returns non-zero if can be converted to double */
422 int tarval_is_double(tarval *tv) {
425 return (get_mode_sort(tv->mode) == irms_float_number);
428 long double get_tarval_double(tarval *tv) {
429 assert(tarval_is_double(tv));
431 return fc_val_to_ieee754(tv->value);
436 * Access routines for tarval fields ========================================
439 /* get the mode of the tarval */
440 ir_mode *(get_tarval_mode)(const tarval *tv) {
441 return _get_tarval_mode(tv);
445 * Special value query functions ============================================
447 * These functions calculate and return a tarval representing the requested
449 * The functions get_mode_{Max,Min,...} return tarvals retrieved from these
450 * functions, but these are stored on initialization of the irmode module and
451 * therefore the irmode functions should be preferred to the functions below.
454 tarval *(get_tarval_bad)(void) {
455 return _get_tarval_bad();
458 tarval *(get_tarval_undefined)(void) {
459 return _get_tarval_undefined();
462 tarval *(get_tarval_b_false)(void) {
463 return _get_tarval_b_false();
466 tarval *(get_tarval_b_true)(void) {
467 return _get_tarval_b_true();
470 tarval *(get_tarval_reachable)(void) {
471 return _get_tarval_reachable();
474 tarval *(get_tarval_unreachable)(void) {
475 return _get_tarval_unreachable();
478 tarval *get_tarval_max(ir_mode *mode) {
479 const ieee_descriptor_t *desc;
482 if (get_mode_n_vector_elems(mode) > 1) {
483 /* vector arithmetic not implemented yet */
487 switch (get_mode_sort(mode)) {
488 case irms_control_flow:
491 panic("mode %F does not support maximum value", mode);
493 case irms_internal_boolean:
494 return tarval_b_true;
496 case irms_float_number:
497 desc = get_descriptor(mode);
498 fc_get_max(desc, NULL);
499 return get_tarval(fc_get_buffer(), fc_get_buffer_length(), mode);
502 case irms_int_number:
503 sc_max_from_bits(get_mode_size_bits(mode), mode_is_signed(mode), NULL);
504 return get_tarval(sc_get_buffer(), sc_get_buffer_length(), mode);
509 tarval *get_tarval_min(ir_mode *mode) {
510 const ieee_descriptor_t *desc;
513 if (get_mode_n_vector_elems(mode) > 1) {
514 /* vector arithmetic not implemented yet */
518 switch (get_mode_sort(mode)) {
519 case irms_control_flow:
522 panic("mode %F does not support minimum value", mode);
524 case irms_internal_boolean:
525 return tarval_b_false;
527 case irms_float_number:
528 desc = get_descriptor(mode);
529 fc_get_min(desc, NULL);
530 return get_tarval(fc_get_buffer(), fc_get_buffer_length(), mode);
533 case irms_int_number:
534 sc_min_from_bits(get_mode_size_bits(mode), mode_is_signed(mode), NULL);
535 return get_tarval(sc_get_buffer(), sc_get_buffer_length(), mode);
540 /** The bit pattern for the pointer NULL */
541 static long _null_value = 0;
543 tarval *get_tarval_null(ir_mode *mode) {
546 if (get_mode_n_vector_elems(mode) > 1) {
547 /* vector arithmetic not implemented yet */
551 switch (get_mode_sort(mode)) {
552 case irms_control_flow:
555 panic("mode %F does not support null value", mode);
557 case irms_float_number:
558 return new_tarval_from_double(0.0, mode);
560 case irms_internal_boolean:
561 case irms_int_number:
562 return new_tarval_from_long(0l, mode);
565 return new_tarval_from_long(_null_value, mode);
570 tarval *get_tarval_one(ir_mode *mode) {
573 if (get_mode_n_vector_elems(mode) > 1)
574 panic("vector arithmetic not implemented yet");
576 switch (get_mode_sort(mode)) {
577 case irms_control_flow:
580 panic("mode %F does not support one value", mode);
582 case irms_internal_boolean:
583 return tarval_b_true;
585 case irms_float_number:
586 return new_tarval_from_double(1.0, mode);
589 case irms_int_number:
590 return new_tarval_from_long(1l, mode);
595 tarval *get_tarval_all_one(ir_mode *mode) {
598 if (get_mode_n_vector_elems(mode) > 1)
599 panic("vector arithmetic not implemented yet");
601 switch (get_mode_sort(mode)) {
602 case irms_control_flow:
605 panic("mode %F does not support all-one value", mode);
607 case irms_int_number:
608 case irms_internal_boolean:
610 return tarval_not(get_mode_null(mode));
613 case irms_float_number:
614 return new_tarval_from_double(1.0, mode);
619 int tarval_is_constant(tarval *tv) {
620 int num_res = sizeof(reserved_tv) / sizeof(reserved_tv[0]);
622 /* reserved tarvals are NOT constants. Note that although
623 tarval_b_true and tarval_b_false are reserved, they are constants of course. */
624 return (tv < &reserved_tv[2] || tv > &reserved_tv[num_res - 1]);
627 tarval *get_tarval_minus_one(ir_mode *mode) {
630 if (get_mode_n_vector_elems(mode) > 1)
631 panic("vector arithmetic not implemented yet");
633 switch (get_mode_sort(mode)) {
634 case irms_control_flow:
637 case irms_internal_boolean:
638 panic("mode %F does not support minus one value", mode);
643 case irms_float_number:
644 return mode_is_signed(mode) ? new_tarval_from_double(-1.0, mode) : tarval_bad;
646 case irms_int_number:
647 return new_tarval_from_long(-1l, mode);
652 tarval *get_tarval_nan(ir_mode *mode) {
653 const ieee_descriptor_t *desc;
656 if (get_mode_n_vector_elems(mode) > 1)
657 panic("vector arithmetic not implemented yet");
659 if (get_mode_sort(mode) == irms_float_number) {
660 desc = get_descriptor(mode);
661 fc_get_qnan(desc, NULL);
662 return get_tarval(fc_get_buffer(), fc_get_buffer_length(), mode);
664 panic("mode %F does not support NaN value", mode);
667 tarval *get_tarval_plus_inf(ir_mode *mode) {
669 if (get_mode_n_vector_elems(mode) > 1)
670 panic("vector arithmetic not implemented yet");
672 if (get_mode_sort(mode) == irms_float_number) {
673 const ieee_descriptor_t *desc = get_descriptor(mode);
674 fc_get_plusinf(desc, NULL);
675 return get_tarval(fc_get_buffer(), fc_get_buffer_length(), mode);
677 panic("mode %F does not support +inf value", mode);
680 tarval *get_tarval_minus_inf(ir_mode *mode) {
683 if (get_mode_n_vector_elems(mode) > 1)
684 panic("vector arithmetic not implemented yet");
686 if (get_mode_sort(mode) == irms_float_number) {
687 const ieee_descriptor_t *desc = get_descriptor(mode);
688 fc_get_minusinf(desc, NULL);
689 return get_tarval(fc_get_buffer(), fc_get_buffer_length(), mode);
691 panic("mode %F does not support -inf value", mode);
695 * Arithmetic operations on tarvals ========================================
699 * test if negative number, 1 means 'yes'
701 int tarval_is_negative(tarval *a) {
702 if (get_mode_n_vector_elems(a->mode) > 1)
703 panic("vector arithmetic not implemented yet");
705 switch (get_mode_sort(a->mode)) {
706 case irms_int_number:
707 if (!mode_is_signed(a->mode)) return 0;
709 return sc_comp(a->value, get_mode_null(a->mode)->value) == -1 ? 1 : 0;
711 case irms_float_number:
712 return fc_is_negative(a->value);
715 panic("mode %F does not support negation value", a->mode);
720 * test if null, 1 means 'yes'
722 int tarval_is_null(tarval *a) {
725 a == get_mode_null(get_tarval_mode(a));
729 * test if one, 1 means 'yes'
731 int tarval_is_one(tarval *a) {
734 a == get_mode_one(get_tarval_mode(a));
737 int tarval_is_all_one(tarval *tv) {
740 tv == get_mode_all_one(get_tarval_mode(tv));
744 * test if one, 1 means 'yes'
746 int tarval_is_minus_one(tarval *a) {
749 a == get_mode_minus_one(get_tarval_mode(a));
755 pn_Cmp tarval_cmp(tarval *a, tarval *b) {
758 if (a == tarval_bad || b == tarval_bad) {
759 panic("Comparison with tarval_bad");
763 if (a == tarval_undefined || b == tarval_undefined)
766 if (a->mode != b->mode)
769 if (get_mode_n_vector_elems(a->mode) > 1) {
770 /* vector arithmetic not implemented yet */
771 assert(0 && "cmp not implemented for vector modes");
774 /* Here the two tarvals are unequal and of the same mode */
775 switch (get_mode_sort(a->mode)) {
776 case irms_control_flow:
783 case irms_float_number:
784 /* it should be safe to enable this even if other arithmetic is disabled */
786 return pn_Cmp_False;*/
788 * BEWARE: we cannot compare a == b here, because
789 * a NaN is always Unordered to any other value, even to itself!
791 switch (fc_comp(a->value, b->value)) {
792 case -1: return pn_Cmp_Lt;
793 case 0: return pn_Cmp_Eq;
794 case 1: return pn_Cmp_Gt;
795 case 2: return pn_Cmp_Uo;
796 default: return pn_Cmp_False;
799 case irms_int_number:
802 return sc_comp(a->value, b->value) == 1 ? pn_Cmp_Gt : pn_Cmp_Lt;
804 case irms_internal_boolean:
807 return a == tarval_b_true ? pn_Cmp_Gt : pn_Cmp_Lt;
813 * convert to other mode
815 tarval *tarval_convert_to(tarval *src, ir_mode *dst_mode) {
818 const ieee_descriptor_t *desc;
825 if (src->mode == dst_mode)
828 if (get_mode_n_vector_elems(src->mode) > 1) {
829 /* vector arithmetic not implemented yet */
833 switch (get_mode_sort(src->mode)) {
834 case irms_control_flow:
839 /* cast float to something */
840 case irms_float_number:
841 switch (get_mode_sort(dst_mode)) {
842 case irms_float_number:
843 desc = get_descriptor(dst_mode);
844 fc_cast(src->value, desc, NULL);
845 return get_tarval(fc_get_buffer(), fc_get_buffer_length(), dst_mode);
847 case irms_int_number:
848 switch (GET_FLOAT_TO_INT_MODE()) {
850 res = fc_int(src->value, NULL);
853 res = fc_rnd(src->value, NULL);
856 panic("Unsupported float to int conversion mode in tarval_convert_to()");
859 buffer = alloca(sc_get_buffer_length());
860 if (! fc_flt2int(res, buffer, dst_mode))
862 return get_tarval(buffer, sc_get_buffer_length(), dst_mode);
865 /* the rest can't be converted */
870 /* cast int/characters to something */
871 case irms_int_number:
872 switch (get_mode_sort(dst_mode)) {
875 case irms_int_number:
876 buffer = alloca(sc_get_buffer_length());
877 memcpy(buffer, src->value, sc_get_buffer_length());
878 sign_extend(buffer, dst_mode);
879 return get_tarval_overflow(buffer, src->length, dst_mode);
881 case irms_internal_boolean:
882 /* XXX C semantics */
883 if (src == get_mode_null(src->mode)) return tarval_b_false;
884 else return tarval_b_true;
886 case irms_float_number:
887 /* XXX floating point unit does not understand internal integer
888 * representation, convert to string first, then create float from
890 buffer = alloca(100);
891 /* decimal string representation because hexadecimal output is
892 * interpreted unsigned by fc_val_from_str, so this is a HACK */
893 snprintf(buffer, 100, "%s",
894 sc_print(src->value, get_mode_size_bits(src->mode), SC_DEC, mode_is_signed(src->mode)));
895 buffer[100 - 1] = '\0';
896 desc = get_descriptor(dst_mode);
897 fc_val_from_str(buffer, 0, desc, NULL);
898 return get_tarval(fc_get_buffer(), fc_get_buffer_length(), dst_mode);
905 case irms_internal_boolean:
906 /* beware: this is C semantic for the INTERNAL boolean mode */
907 if (get_mode_sort(dst_mode) == irms_int_number)
908 return src == tarval_b_true ? get_mode_one(dst_mode) : get_mode_null(dst_mode);
912 if (get_mode_sort(dst_mode) == irms_int_number) {
913 buffer = alloca(sc_get_buffer_length());
914 memcpy(buffer, src->value, sc_get_buffer_length());
915 sign_extend(buffer, src->mode);
916 return get_tarval_overflow(buffer, src->length, dst_mode);
927 tarval *tarval_not(tarval *a) {
932 /* works for vector mode without changes */
934 switch (get_mode_sort(a->mode)) {
936 case irms_int_number:
937 buffer = alloca(sc_get_buffer_length());
938 sc_not(a->value, buffer);
939 return get_tarval(buffer, a->length, a->mode);
941 case irms_internal_boolean:
942 if (a == tarval_b_true)
943 return tarval_b_false;
944 if (a == tarval_b_false)
945 return tarval_b_true;
949 assert(0 && "bitwise negation is only allowed for integer and boolean");
955 * arithmetic negation
957 tarval *tarval_neg(tarval *a) {
960 assert(mode_is_num(a->mode)); /* negation only for numerical values */
964 /* note: negation is allowed even for unsigned modes. */
966 if (get_mode_n_vector_elems(a->mode) > 1) {
967 /* vector arithmetic not implemented yet */
971 switch (get_mode_sort(a->mode)) {
972 case irms_int_number:
973 buffer = alloca(sc_get_buffer_length());
974 sc_neg(a->value, buffer);
975 return get_tarval_overflow(buffer, a->length, a->mode);
977 case irms_float_number:
978 /* it should be safe to enable this even if other arithmetic is disabled */
982 fc_neg(a->value, NULL);
983 return get_tarval_overflow(fc_get_buffer(), fc_get_buffer_length(), a->mode);
993 tarval *tarval_add(tarval *a, tarval *b) {
998 if (get_mode_n_vector_elems(a->mode) > 1 || get_mode_n_vector_elems(b->mode) > 1) {
999 /* vector arithmetic not implemented yet */
1003 if (mode_is_reference(a->mode) && a->mode != b->mode) {
1004 b = tarval_convert_to(b, a->mode);
1005 } else if (mode_is_reference(b->mode) && b->mode != a->mode) {
1006 a = tarval_convert_to(a, b->mode);
1009 assert(a->mode == b->mode);
1011 switch (get_mode_sort(a->mode)) {
1012 case irms_reference:
1013 case irms_int_number:
1014 /* modes of a,b are equal, so result has mode of a as this might be the character */
1015 buffer = alloca(sc_get_buffer_length());
1016 sc_add(a->value, b->value, buffer);
1017 carry_flag = sc_get_bit_at(buffer, get_mode_size_bits(a->mode));
1018 return get_tarval_overflow(buffer, a->length, a->mode);
1020 case irms_float_number:
1024 fc_add(a->value, b->value, NULL);
1025 return get_tarval_overflow(fc_get_buffer(), fc_get_buffer_length(), a->mode);
1035 tarval *tarval_sub(tarval *a, tarval *b, ir_mode *dst_mode) {
1040 if (get_mode_n_vector_elems(a->mode) > 1 || get_mode_n_vector_elems(b->mode) > 1) {
1041 /* vector arithmetic not implemented yet */
1045 if (dst_mode != NULL) {
1046 if (a->mode != dst_mode)
1047 a = tarval_convert_to(a, dst_mode);
1048 if (b->mode != dst_mode)
1049 b = tarval_convert_to(b, dst_mode);
1051 assert(a->mode == b->mode);
1053 switch (get_mode_sort(a->mode)) {
1054 case irms_reference:
1055 case irms_int_number:
1056 /* modes of a,b are equal, so result has mode of a as this might be the character */
1057 buffer = alloca(sc_get_buffer_length());
1058 sc_sub(a->value, b->value, buffer);
1059 carry_flag = sc_get_bit_at(buffer, get_mode_size_bits(a->mode));
1060 return get_tarval_overflow(buffer, a->length, a->mode);
1062 case irms_float_number:
1066 fc_sub(a->value, b->value, NULL);
1067 return get_tarval_overflow(fc_get_buffer(), fc_get_buffer_length(), a->mode);
1077 tarval *tarval_mul(tarval *a, tarval *b) {
1080 assert(a->mode == b->mode);
1084 if (get_mode_n_vector_elems(a->mode) > 1) {
1085 /* vector arithmetic not implemented yet */
1089 switch (get_mode_sort(a->mode)) {
1090 case irms_int_number:
1091 /* modes of a,b are equal */
1092 buffer = alloca(sc_get_buffer_length());
1093 sc_mul(a->value, b->value, buffer);
1094 return get_tarval_overflow(buffer, a->length, a->mode);
1096 case irms_float_number:
1100 fc_mul(a->value, b->value, NULL);
1101 return get_tarval_overflow(fc_get_buffer(), fc_get_buffer_length(), a->mode);
1109 * floating point division
1111 tarval *tarval_quo(tarval *a, tarval *b) {
1112 assert((a->mode == b->mode) && mode_is_float(a->mode));
1119 if (get_mode_n_vector_elems(a->mode) > 1) {
1120 /* vector arithmetic not implemented yet */
1124 fc_div(a->value, b->value, NULL);
1125 return get_tarval_overflow(fc_get_buffer(), fc_get_buffer_length(), a->mode);
1130 * overflow is impossible, but look out for division by zero
1132 tarval *tarval_div(tarval *a, tarval *b) {
1133 assert((a->mode == b->mode) && mode_is_int(a->mode));
1137 if (get_mode_n_vector_elems(a->mode) > 1) {
1138 /* vector arithmetic not implemented yet */
1143 if (b == get_mode_null(b->mode)) return tarval_bad;
1144 /* modes of a,b are equal */
1145 sc_div(a->value, b->value, NULL);
1146 return get_tarval(sc_get_buffer(), sc_get_buffer_length(), a->mode);
1151 * overflow is impossible, but look out for division by zero
1153 tarval *tarval_mod(tarval *a, tarval *b) {
1154 assert((a->mode == b->mode) && mode_is_int(a->mode));
1158 if (get_mode_n_vector_elems(a->mode) > 1) {
1159 /* vector arithmetic not implemented yet */
1164 if (b == get_mode_null(b->mode)) return tarval_bad;
1165 /* modes of a,b are equal */
1166 sc_mod(a->value, b->value, NULL);
1167 return get_tarval(sc_get_buffer(), sc_get_buffer_length(), a->mode);
1171 * integer division AND remainder
1172 * overflow is impossible, but look out for division by zero
1174 tarval *tarval_divmod(tarval *a, tarval *b, tarval **mod) {
1175 int len = sc_get_buffer_length();
1176 char *div_res = alloca(len);
1177 char *mod_res = alloca(len);
1179 assert((a->mode == b->mode) && mode_is_int(a->mode));
1183 if (get_mode_n_vector_elems(a->mode) > 1) {
1184 /* vector arithmetic not implemented yet */
1190 if (b == get_mode_null(b->mode)) return tarval_bad;
1191 /* modes of a,b are equal */
1192 sc_divmod(a->value, b->value, div_res, mod_res);
1193 *mod = get_tarval(mod_res, len, a->mode);
1194 return get_tarval(div_res, len, a->mode);
1200 tarval *tarval_abs(tarval *a) {
1204 assert(mode_is_num(a->mode));
1206 if (get_mode_n_vector_elems(a->mode) > 1) {
1207 /* vector arithmetic not implemented yet */
1211 switch (get_mode_sort(a->mode)) {
1212 case irms_int_number:
1213 if (sc_comp(a->value, get_mode_null(a->mode)->value) == -1) {
1214 buffer = alloca(sc_get_buffer_length());
1215 sc_neg(a->value, buffer);
1216 return get_tarval_overflow(buffer, a->length, a->mode);
1220 case irms_float_number:
1221 /* it should be safe to enable this even if other arithmetic is disabled */
1223 return tarval_bad;*/
1225 if (fc_comp(a->value, get_mode_null(a->mode)->value) == -1) {
1226 fc_neg(a->value, NULL);
1227 return get_tarval_overflow(fc_get_buffer(), fc_get_buffer_length(), a->mode);
1240 tarval *tarval_and(tarval *a, tarval *b) {
1241 assert(a->mode == b->mode);
1243 /* works even for vector modes */
1246 switch (get_mode_sort(a->mode)) {
1247 case irms_internal_boolean:
1248 return (a == tarval_b_false) ? a : b;
1250 case irms_int_number:
1251 sc_and(a->value, b->value, NULL);
1252 return get_tarval(sc_get_buffer(), sc_get_buffer_length(), a->mode);
1255 assert(0 && "operation not defined on mode");
1260 tarval *tarval_andnot(tarval *a, tarval *b)
1262 assert(a->mode == b->mode);
1264 /* works even for vector modes */
1267 switch (get_mode_sort(a->mode)) {
1268 case irms_internal_boolean:
1269 return a == tarval_b_true && b == tarval_b_false ? tarval_b_true : tarval_b_false;
1271 case irms_int_number:
1272 sc_andnot(a->value, b->value, NULL);
1273 return get_tarval(sc_get_buffer(), sc_get_buffer_length(), a->mode);
1276 assert(0 && "operation not defined on mode");
1284 tarval *tarval_or(tarval *a, tarval *b) {
1285 assert(a->mode == b->mode);
1287 /* works even for vector modes */
1290 switch (get_mode_sort(a->mode)) {
1291 case irms_internal_boolean:
1292 return (a == tarval_b_true) ? a : b;
1294 case irms_int_number:
1295 sc_or(a->value, b->value, NULL);
1296 return get_tarval(sc_get_buffer(), sc_get_buffer_length(), a->mode);
1299 assert(0 && "operation not defined on mode");
1305 * bitwise exclusive or (xor)
1307 tarval *tarval_eor(tarval *a, tarval *b) {
1308 assert((a->mode == b->mode));
1310 /* works even for vector modes */
1313 switch (get_mode_sort(a->mode)) {
1314 case irms_internal_boolean:
1315 return (a == b)? tarval_b_false : tarval_b_true;
1317 case irms_int_number:
1318 sc_xor(a->value, b->value, NULL);
1319 return get_tarval(sc_get_buffer(), sc_get_buffer_length(), a->mode);
1322 assert(0 && "operation not defined on mode");
1328 * bitwise left shift
1330 tarval *tarval_shl(tarval *a, tarval *b) {
1331 char *temp_val = NULL;
1333 assert(mode_is_int(a->mode) && mode_is_int(b->mode));
1337 if (get_mode_n_vector_elems(a->mode) > 1 || get_mode_n_vector_elems(a->mode) > 1) {
1338 /* vector arithmetic not implemented yet */
1342 if (get_mode_modulo_shift(a->mode) != 0) {
1343 temp_val = alloca(sc_get_buffer_length());
1345 sc_val_from_ulong(get_mode_modulo_shift(a->mode), temp_val);
1346 sc_mod(b->value, temp_val, temp_val);
1348 temp_val = (char*)b->value;
1350 sc_shl(a->value, temp_val, get_mode_size_bits(a->mode), mode_is_signed(a->mode), NULL);
1351 return get_tarval(sc_get_buffer(), sc_get_buffer_length(), a->mode);
1355 * bitwise unsigned right shift
1357 tarval *tarval_shr(tarval *a, tarval *b) {
1358 char *temp_val = NULL;
1360 assert(mode_is_int(a->mode) && mode_is_int(b->mode));
1364 if (get_mode_n_vector_elems(a->mode) > 1 || get_mode_n_vector_elems(a->mode) > 1) {
1365 /* vector arithmetic not implemented yet */
1369 if (get_mode_modulo_shift(a->mode) != 0) {
1370 temp_val = alloca(sc_get_buffer_length());
1372 sc_val_from_ulong(get_mode_modulo_shift(a->mode), temp_val);
1373 sc_mod(b->value, temp_val, temp_val);
1375 temp_val = (char*)b->value;
1377 sc_shr(a->value, temp_val, get_mode_size_bits(a->mode), mode_is_signed(a->mode), NULL);
1378 return get_tarval(sc_get_buffer(), sc_get_buffer_length(), a->mode);
1382 * bitwise signed right shift
1384 tarval *tarval_shrs(tarval *a, tarval *b) {
1385 char *temp_val = NULL;
1387 assert(mode_is_int(a->mode) && mode_is_int(b->mode));
1391 if (get_mode_n_vector_elems(a->mode) > 1 || get_mode_n_vector_elems(a->mode) > 1) {
1392 /* vector arithmetic not implemented yet */
1396 if (get_mode_modulo_shift(a->mode) != 0) {
1397 temp_val = alloca(sc_get_buffer_length());
1399 sc_val_from_ulong(get_mode_modulo_shift(a->mode), temp_val);
1400 sc_mod(b->value, temp_val, temp_val);
1402 temp_val = (char*)b->value;
1404 sc_shrs(a->value, temp_val, get_mode_size_bits(a->mode), mode_is_signed(a->mode), NULL);
1405 return get_tarval(sc_get_buffer(), sc_get_buffer_length(), a->mode);
1409 * bitwise rotation to left
1411 tarval *tarval_rotl(tarval *a, tarval *b) {
1412 char *temp_val = NULL;
1414 assert(mode_is_int(a->mode) && mode_is_int(b->mode));
1418 if (get_mode_n_vector_elems(a->mode) > 1 || get_mode_n_vector_elems(a->mode) > 1) {
1419 /* vector arithmetic not implemented yet */
1423 if (get_mode_modulo_shift(a->mode) != 0) {
1424 temp_val = alloca(sc_get_buffer_length());
1426 sc_val_from_ulong(get_mode_modulo_shift(a->mode), temp_val);
1427 sc_mod(b->value, temp_val, temp_val);
1429 temp_val = (char*)b->value;
1431 sc_rotl(a->value, temp_val, get_mode_size_bits(a->mode), mode_is_signed(a->mode), NULL);
1432 return get_tarval(sc_get_buffer(), sc_get_buffer_length(), a->mode);
1436 * carry flag of the last operation
1438 int tarval_carry(void) {
1439 if (carry_flag == -1)
1440 panic("Carry undefined for the last operation");
1447 int tarval_snprintf(char *buf, size_t len, tarval *tv) {
1448 static const tarval_mode_info default_info = { TVO_NATIVE, NULL, NULL };
1452 const tarval_mode_info *mode_info;
1453 const char *prefix, *suffix;
1455 mode_info = tv->mode->tv_priv;
1457 mode_info = &default_info;
1458 prefix = mode_info->mode_prefix ? mode_info->mode_prefix : "";
1459 suffix = mode_info->mode_suffix ? mode_info->mode_suffix : "";
1461 switch (get_mode_sort(tv->mode)) {
1462 case irms_reference:
1463 if (tv == tv->mode->null) return snprintf(buf, len, "NULL");
1465 case irms_int_number:
1466 switch (mode_info->mode_output) {
1469 str = sc_print(tv->value, get_mode_size_bits(tv->mode), SC_DEC, mode_is_signed(tv->mode));
1473 str = sc_print(tv->value, get_mode_size_bits(tv->mode), SC_OCT, 0);
1480 str = sc_print(tv->value, get_mode_size_bits(tv->mode), SC_HEX, 0);
1483 return snprintf(buf, len, "%s%s%s", prefix, str, suffix);
1485 case irms_float_number:
1486 switch (mode_info->mode_output) {
1488 return snprintf(buf, len, "%s%s%s", prefix, fc_print(tv->value, tv_buf, sizeof(tv_buf), FC_PACKED), suffix);
1491 return snprintf(buf, len, "%s%s%s", prefix, fc_print(tv->value, tv_buf, sizeof(tv_buf), FC_HEX), suffix);
1496 return snprintf(buf, len, "%s%s%s", prefix, fc_print(tv->value, tv_buf, sizeof(tv_buf), FC_DEC), suffix);
1500 case irms_internal_boolean:
1501 switch (mode_info->mode_output) {
1507 return snprintf(buf, len, "%s%c%s", prefix, (tv == tarval_b_true) ? '1' : '0', suffix);
1511 return snprintf(buf, len, "%s%s%s", prefix, (tv == tarval_b_true) ? "true" : "false", suffix);
1514 case irms_control_flow:
1516 case irms_auxiliary:
1517 if (tv == tarval_bad)
1518 return snprintf(buf, len, "<TV_BAD>");
1519 if (tv == tarval_undefined)
1520 return snprintf(buf, len, "<TV_UNDEF>");
1521 if (tv == tarval_unreachable)
1522 return snprintf(buf, len, "<TV_UNREACHABLE>");
1523 if (tv == tarval_reachable)
1524 return snprintf(buf, len, "<TV_REACHABLE>");
1525 return snprintf(buf, len, "<TV_??""?>");
1532 * Output of tarvals to stdio.
1534 int tarval_printf(tarval *tv) {
1538 res = tarval_snprintf(buf, sizeof(buf), tv);
1539 assert(res < (int) sizeof(buf) && "buffer to small for tarval_snprintf");
1544 char *get_tarval_bitpattern(tarval *tv) {
1546 int n = get_mode_size_bits(tv->mode);
1547 int bytes = (n + 7) / 8;
1548 char *res = XMALLOCN(char, n + 1);
1551 for(i = 0; i < bytes; i++) {
1552 byte = get_tarval_sub_bits(tv, i);
1553 for(j = 1; j < 256; j <<= 1)
1555 res[pos++] = j & byte ? '1' : '0';
1564 * access to the bitpattern
1566 unsigned char get_tarval_sub_bits(tarval *tv, unsigned byte_ofs) {
1567 switch (get_mode_arithmetic(tv->mode)) {
1568 case irma_twos_complement:
1569 return sc_sub_bits(tv->value, get_mode_size_bits(tv->mode), byte_ofs);
1571 return fc_sub_bits(tv->value, get_mode_size_bits(tv->mode), byte_ofs);
1573 panic("get_tarval_sub_bits(): arithmetic mode not supported");
1578 * Specify the output options of one mode.
1580 * This functions stores the modinfo, so DO NOT DESTROY it.
1582 * Returns zero on success.
1584 int set_tarval_mode_output_option(ir_mode *mode, const tarval_mode_info *modeinfo) {
1587 mode->tv_priv = modeinfo;
1592 * Returns the output options of one mode.
1594 * This functions returns the mode info of a given mode.
1596 const tarval_mode_info *get_tarval_mode_output_option(ir_mode *mode) {
1599 return mode->tv_priv;
1603 * Returns non-zero if a given (integer) tarval has only one single bit
1606 int tarval_is_single_bit(tarval *tv) {
1610 if (!tv || tv == tarval_bad) return 0;
1611 if (! mode_is_int(tv->mode)) return 0;
1613 l = get_mode_size_bytes(tv->mode);
1614 for (bits = 0, i = l - 1; i >= 0; --i) {
1615 unsigned char v = get_tarval_sub_bits(tv, (unsigned)i);
1617 /* check for more than one bit in these */
1629 * Return the number of set bits in a given (integer) tarval.
1631 int get_tarval_popcnt(tarval *tv)
1636 if (!tv || tv == tarval_bad) return -1;
1637 if (! mode_is_int(tv->mode)) return -1;
1639 l = get_mode_size_bytes(tv->mode);
1640 for (bits = 0, i = l - 1; i >= 0; --i) {
1641 unsigned char v = get_tarval_sub_bits(tv, (unsigned)i);
1649 * Return the number of the lowest set bit in a given (integer) tarval.
1651 * @param tv the tarval
1653 * @return number of lowest set bit or -1 on error
1655 int get_tarval_lowest_bit(tarval *tv)
1659 if (!tv || tv == tarval_bad) return -1;
1660 if (! mode_is_int(tv->mode)) return -1;
1662 l = get_mode_size_bytes(tv->mode);
1663 for (i = 0; i < l; ++i) {
1664 unsigned char v = get_tarval_sub_bits(tv, (unsigned)i);
1667 return ntz(v) + i * 8;
1673 * Returns non-zero if the mantissa of a floating point IEEE-754
1674 * tarval is zero (i.e. 1.0Exxx)
1676 int tarval_ieee754_zero_mantissa(tarval *tv) {
1677 assert(get_mode_arithmetic(tv->mode) == irma_ieee754);
1678 return fc_zero_mantissa(tv->value);
1681 /* Returns the exponent of a floating point IEEE-754 tarval. */
1682 int tarval_ieee754_get_exponent(tarval *tv) {
1683 assert(get_mode_arithmetic(tv->mode) == irma_ieee754);
1684 return fc_get_exponent(tv->value);
1688 * Check if the tarval can be converted to the given mode without
1691 int tarval_ieee754_can_conv_lossless(tarval *tv, ir_mode *mode) {
1692 const ieee_descriptor_t *desc = get_descriptor(mode);
1693 return fc_can_lossless_conv_to(tv->value, desc);
1696 /* Set the immediate precision for IEEE-754 results. */
1697 unsigned tarval_ieee754_set_immediate_precision(unsigned bits) {
1698 return fc_set_immediate_precision(bits);
1701 /* Returns non-zero if the result of the last IEEE-754 operation was exact. */
1702 unsigned tarval_ieee754_get_exact(void) {
1703 return fc_is_exact();
1706 /* Return the size of the mantissa in bits (including possible
1707 implicit bits) for the given mode. */
1708 unsigned tarval_ieee754_get_mantissa_size(const ir_mode *mode) {
1709 const ieee_descriptor_t *desc;
1711 assert(get_mode_arithmetic(mode) == irma_ieee754);
1712 desc = get_descriptor(mode);
1714 return desc->mantissa_size + desc->explicit_one;
1717 /* check if its the a floating point NaN */
1718 int tarval_is_NaN(tarval *tv) {
1719 if (! mode_is_float(tv->mode))
1721 return fc_is_nan(tv->value);
1724 /* check if its the a floating point +inf */
1725 int tarval_is_plus_inf(tarval *tv) {
1726 if (! mode_is_float(tv->mode))
1728 return fc_is_inf(tv->value) && !fc_is_negative(tv->value);
1731 /* check if its the a floating point -inf */
1732 int tarval_is_minus_inf(tarval *tv) {
1733 if (! mode_is_float(tv->mode))
1735 return fc_is_inf(tv->value) && fc_is_negative(tv->value);
1738 /* check if the tarval represents a finite value */
1739 int tarval_is_finite(tarval *tv) {
1740 if (mode_is_float(tv->mode))
1741 return !fc_is_nan(tv->value) && !fc_is_inf(tv->value);
1746 * Sets the overflow mode for integer operations.
1748 void tarval_set_integer_overflow_mode(tarval_int_overflow_mode_t ov_mode) {
1749 int_overflow_mode = ov_mode;
1752 /* Get the overflow mode for integer operations. */
1753 tarval_int_overflow_mode_t tarval_get_integer_overflow_mode(void) {
1754 return int_overflow_mode;
1757 /* Enable/Disable floating point constant folding. */
1758 void tarval_enable_fp_ops(int enable) {
1762 int tarval_fp_ops_enabled(void) {
1767 * default mode_info for output as HEX
1769 static const tarval_mode_info hex_output = {
1776 * Initialization of the tarval module: called before init_mode()
1778 void init_tarval_1(long null_value, int support_quad_precision) {
1779 /* if these assertion fail, tarval_is_constant() will follow ... */
1780 assert(tarval_b_false == &reserved_tv[0] && "b_false MUST be the first reserved tarval!");
1781 assert(tarval_b_true == &reserved_tv[1] && "b_true MUST be the second reserved tarval!");
1783 _null_value = null_value;
1785 /* initialize the sets holding the tarvals with a comparison function and
1786 * an initial size, which is the expected number of constants */
1787 tarvals = new_set(cmp_tv, N_CONSTANTS);
1788 values = new_set(memcmp, N_CONSTANTS);
1789 /* calls init_strcalc() with needed size */
1790 init_fltcalc(support_quad_precision ? 112 : 64);
1794 * Initialization of the tarval module: called after init_mode()
1796 void init_tarval_2(void) {
1797 tarval_bad->kind = k_tarval;
1798 tarval_bad->mode = mode_BAD;
1799 tarval_bad->value = INT_TO_PTR(resid_tarval_bad);
1801 tarval_undefined->kind = k_tarval;
1802 tarval_undefined->mode = mode_ANY;
1803 tarval_undefined->value = INT_TO_PTR(resid_tarval_undefined);
1805 tarval_b_true->kind = k_tarval;
1806 tarval_b_true->mode = mode_b;
1807 tarval_b_true->value = INT_TO_PTR(resid_tarval_b_true);
1809 tarval_b_false->kind = k_tarval;
1810 tarval_b_false->mode = mode_b;
1811 tarval_b_false->value = INT_TO_PTR(resid_tarval_b_false);
1813 tarval_unreachable->kind = k_tarval;
1814 tarval_unreachable->mode = mode_X;
1815 tarval_unreachable->value = INT_TO_PTR(resid_tarval_unreachable);
1817 tarval_reachable->kind = k_tarval;
1818 tarval_reachable->mode = mode_X;
1819 tarval_reachable->value = INT_TO_PTR(resid_tarval_reachable);
1822 * assign output modes that are compatible with the
1823 * old implementation: Hex output
1825 set_tarval_mode_output_option(mode_Bs, &hex_output);
1826 set_tarval_mode_output_option(mode_Bu, &hex_output);
1827 set_tarval_mode_output_option(mode_Hs, &hex_output);
1828 set_tarval_mode_output_option(mode_Hu, &hex_output);
1829 set_tarval_mode_output_option(mode_Is, &hex_output);
1830 set_tarval_mode_output_option(mode_Iu, &hex_output);
1831 set_tarval_mode_output_option(mode_Ls, &hex_output);
1832 set_tarval_mode_output_option(mode_Lu, &hex_output);
1833 set_tarval_mode_output_option(mode_P, &hex_output);
1836 /* free all memory occupied by tarval. */
1837 void finish_tarval(void) {
1840 del_set(tarvals); tarvals = NULL;
1841 del_set(values); values = NULL;
1844 int (is_tarval)(const void *thing) {
1845 return _is_tarval(thing);
1848 /****************************************************************************
1850 ****************************************************************************/