1 /* TV --- Target Values, aka Constant Table.
2 Copyright (C) 1995, 1996 Christian von Roques */
6 /****i* tv/implementation
13 * Internal storage for tarvals, 1st draft:
14 * Integers as well as pointers are stored in a hex formatted string holding
15 * 16 characters. Booleans are not stored as there are only two of them.
17 * Floats are just reinterpreted as byte strings, because I am not sure if
18 * there is loss if I convert float to long double and back and furthermore
19 * the implementation of a fully ieee compatible floating point emulation
20 * is not sensible for now
21 * With this information it is easy to decide the kind of stored value:
22 * Integers have size 16, floats 4, doubles 8, long doubles 12.
25 /* This implementation assumes:
26 * both host and target have IEEE-754 floating-point arithmetic. */
28 /* !!! float and double divides MUST NOT SIGNAL !!! */
29 /* @@@ query the floating-point expception status flags */
31 /* @@@ Problem: All Values are stored twice, once as Univ_*s and a 2nd
32 time in their real target mode. :-( */
34 #define MAX_INT_LENGTH 8
35 #define CHAR_BUFFER_SIZE ((MAX_INT_LENGTH) * 2)
41 #include <assert.h> /* assertions */
42 #include <stdlib.h> /* atoi() */
43 #include <string.h> /* nice things for strings */
44 #include <strings.h> /* nice things for strings */
48 #include "set.h" /* to store tarvals in */
49 #include "tune.h" /* some constants */
50 #include "entity_t.h" /* needed to store pointers to entities */
51 #include "irmode.h" /* defines modes etc */
53 #include "irnode.h" /* defines boolean return values */
58 /****************************************************************************
59 * local definitions and macros
60 ****************************************************************************/
62 # define TARVAL_VERIFY(a) tarval_verify((a))
64 # define TARVAL_VERIFY(a) ((void)0)
67 #define INSERT_TARVAL(tv) ((tarval*)set_insert(tarvals, (tv), sizeof(tarval), hash_tv((tv))))
68 #define FIND_TARVAL(tv) ((tarval*)set_find(tarvals, (tv), sizeof(tarval), hash_tv((tv))))
70 #define INSERT_VALUE(val, size) (set_insert(values, (val), size, hash_val((val), size)))
71 #define FIND_VALUE(val, size) (set_find(values, (val), size, hash_val((val), size)))
73 #define fail_verify(a) _fail_verify((a), __FILE__, __LINE__)
75 static long long count = 0;
76 # define ANNOUNCE() printf(__FILE__": call no. %lld (%s)\n", count++, __FUNCTION__);
78 # define ANNOUNCE() ((void)0)
80 /****************************************************************************
82 ****************************************************************************/
83 static struct set *tarvals; /* container for tarval structs */
84 static struct set *values; /* container for values */
86 /****************************************************************************
88 ****************************************************************************/
90 static int hash_val(const void *value, unsigned int length);
91 static int hash_tv(tarval *tv);
92 static void _fail_verify(tarval *tv, const char* file, int line)
94 /* print a memory image of the tarval and throw an assertion */
96 printf("%s:%d: Invalid tarval:\n mode: %s\n value: [%p]\n", file, line, get_mode_name(tv->mode), tv->value);
98 printf("%s:%d: Invalid tarval (null)", file, line);
102 INLINE static void tarval_verify(tarval *tv) __attribute__ ((unused));
105 INLINE static void tarval_verify(tarval *tv)
111 if ((tv == tarval_bad) || (tv == tarval_undefined)) return;
112 if ((tv == tarval_b_true) || (tv == tarval_b_false)) return;
114 if (!FIND_TARVAL(tv)) fail_verify(tv);
115 if (tv->length > 0 && !FIND_VALUE(tv->value, tv->length)) fail_verify(tv);
121 static int hash_tv(tarval *tv)
123 return ((unsigned int)tv->value ^ (unsigned int)tv->mode) + tv->length;
126 static int hash_val(const void *value, unsigned int length)
129 unsigned int hash = 0;
131 /* scramble the byte - array */
132 for (i = 0; i < length; i++)
134 hash += (hash << 5) ^ (hash >> 27) ^ ((char*)value)[i];
135 hash += (hash << 11) ^ (hash >> 17);
141 /* finds tarval with value/mode or creates new tarval */
142 static tarval *get_tarval(const void *value, int length, ir_mode *mode)
149 /* if there already is such a value, it is returned, else value
150 * is copied into the set */
151 tv.value = INSERT_VALUE(value, length);
155 /* if there is such a tarval, it is returned, else tv is copied
157 return (tarval *)INSERT_TARVAL(&tv);
161 * Returns non-zero if a tarval overflows.
163 * @todo Implementation did not work on all modes
165 static int overflows(tarval *tv)
167 switch (get_mode_sort(tv->mode))
170 case irms_int_number:
171 if (sc_comp(tv->value, get_mode_max(tv->mode)->value) == 1) return 1;
172 if (sc_comp(tv->value, get_mode_min(tv->mode)->value) == -1) return 1;
175 case irms_float_number:
179 if (fc_comp(tv->value, get_mode_max(tv->mode)->value) == 1) return 1;
180 if (fc_comp(tv->value, get_mode_min(tv->mode)->value) == -1) return 1;
191 * public variables declared in tv.h
194 tarval *tarval_undefined;
195 tarval *tarval_b_false;
196 tarval *tarval_b_true;
197 tarval *tarval_P_void;
200 * public functions declared in tv.h
204 * Constructors =============================================================
206 tarval *new_tarval_from_str(const char *str, size_t len, ir_mode *mode)
213 switch (get_mode_sort(mode))
215 case irms_control_flow:
221 case irms_internal_boolean:
222 /* match tTrRuUeE/fFaAlLsSeE */
223 if (strcasecmp(str, "true")) return tarval_b_true;
224 else if (strcasecmp(str, "false")) return tarval_b_true;
226 return atoi(str) ? tarval_b_true : tarval_b_false;
228 case irms_float_number:
229 fc_val_from_str(str, len);
230 return get_tarval(fc_get_buffer(), fc_get_buffer_length(), mode);
232 case irms_int_number:
234 sc_val_from_str(str, len);
235 return get_tarval(sc_get_buffer(), sc_get_buffer_length(), mode);
238 return get_tarval(str, len, mode);
241 assert(0); /* can't be reached, can it? */
246 int tarval_is_str(tarval *tv)
251 return ((get_mode_sort(tv->mode) == reference) && (tv->value != NULL) && (tv->length > 0));
253 char *tarval_to_str(tarval *tv)
256 assert(tarval_is_str(tv));
257 return (char *)tv->value;
262 * helper function, create a tarval from long
264 tarval *new_tarval_from_long(long l, ir_mode *mode)
267 assert(mode && !((get_mode_sort(mode) == irms_memory)||(get_mode_sort(mode)==irms_control_flow)||(get_mode_sort(mode)==irms_auxiliary)));
269 switch(get_mode_sort(mode))
271 case irms_internal_boolean:
272 /* XXX C-Semantics ! */
273 return l ? tarval_b_true : tarval_b_false ;
275 case irms_int_number:
278 return get_tarval(sc_get_buffer(), sc_get_buffer_length(), mode);
280 case irms_float_number:
281 return new_tarval_from_double((long double)l, mode);
284 return l ? tarval_bad : get_tarval(NULL, 0, mode); /* null pointer or tarval_bad */
292 /* returns non-zero if can be converted to long */
293 int tarval_is_long(tarval *tv)
296 if (get_mode_sort(tv->mode) != irms_int_number) return 0;
298 if (get_mode_size_bits(tv->mode) > sizeof(long)<<3)
300 /* the value might be too big to fit in a long */
301 sc_max_from_bits(sizeof(long)<<3, 0);
302 if (sc_comp(sc_get_buffer(), tv->value) == -1)
304 /* really doesn't fit */
311 /* this might overflow the machine's long, so use only with small values */
312 long tarval_to_long(tarval* tv)
315 assert(tarval_is_long(tv) && "tarval too big to fit in long");
317 return sc_val_to_long(tv->value);
320 tarval *new_tarval_from_double(long double d, ir_mode *mode)
323 assert(mode && (get_mode_sort(mode) == irms_float_number));
325 fc_val_from_float(d);
326 return get_tarval(fc_get_buffer(), fc_get_buffer_length(), mode);
329 /* returns non-zero if can be converted to double */
330 int tarval_is_double(tarval *tv)
335 return (get_mode_sort(tv->mode) == irms_float_number);
338 long double tarval_to_double(tarval *tv)
341 assert(tarval_is_double(tv));
343 return fc_val_to_float(tv->value);
346 /* The tarval represents the address of the entity. As the address must
347 be constant the entity must have as owner the global type. */
348 tarval *new_tarval_from_entity (entity *ent, ir_mode *mode)
352 assert(mode && (get_mode_sort(mode) == irms_reference));
354 return get_tarval((void *)ent, 0, mode);
356 int tarval_is_entity(tarval *tv)
360 /* tv->value == NULL means dereferencing a null pointer */
361 return ((get_mode_sort(tv->mode) == irms_reference) && (tv->value != NULL) && (tv->length == 0)
362 && (tv != tarval_P_void));
365 entity *tarval_to_entity(tarval *tv)
370 if (tarval_is_entity(tv))
371 return (entity *)tv->value;
373 assert(0 && "tarval did not represent an entity");
378 void free_tarval_entity(entity *ent) {
379 /* There can be a tarval referencing this entity. Even if the
380 tarval is not used by the code any more, it can still reference
381 the entity as tarvals live indepently of the entity referenced.
382 Further the tarval is hashed into a set. If a hash function
383 evaluation happens to collide with this tarval, we will vrfy that
384 it contains a proper entity and we will crash if the entity is
387 Unluckily, tarvals can neither be changed nor deleted, and to find
388 one, all existing reference modes have to be tried -> a facility
389 to retrieve all modes of a kind is needed. */
394 * Access routines for tarval fields ========================================
396 ir_mode *get_tarval_mode (tarval *tv) /* get the mode of the tarval */
404 * Special value query functions ============================================
406 * These functions calculate and return a tarval representing the requested
408 * The functions get_mode_{Max,Min,...} return tarvals retrieved from these
409 * functions, but these are stored on initialization of the irmode module and
410 * therefore the irmode functions should be prefered to the functions below.
413 tarval *get_tarval_bad(void)
418 tarval *get_tarval_undefined(void)
421 return tarval_undefined;
423 tarval *get_tarval_b_false(void)
426 return tarval_b_false;
428 tarval *get_tarval_b_true(void)
431 return tarval_b_true;
433 tarval *get_tarval_P_void(void)
436 return tarval_P_void;
439 tarval *get_tarval_max(ir_mode *mode)
444 switch(get_mode_sort(mode))
447 case irms_control_flow:
453 case irms_internal_boolean:
454 return tarval_b_true;
456 case irms_float_number:
457 fc_get_max(get_mode_size_bits(mode));
458 return get_tarval(fc_get_buffer(), fc_get_buffer_length(), mode);
460 case irms_int_number:
462 sc_max_from_bits(get_mode_size_bits(mode), mode_is_signed(mode));
463 return get_tarval(sc_get_buffer(), sc_get_buffer_length(), mode);
468 tarval *get_tarval_min(ir_mode *mode)
473 switch(get_mode_sort(mode))
476 case irms_control_flow:
482 case irms_internal_boolean:
483 return tarval_b_false;
485 case irms_float_number:
486 fc_get_min(get_mode_size_bits(mode));
487 return get_tarval(fc_get_buffer(), fc_get_buffer_length(), mode);
489 case irms_int_number:
491 sc_min_from_bits(get_mode_size_bits(mode), mode_is_signed(mode));
492 return get_tarval(sc_get_buffer(), sc_get_buffer_length(), mode);
497 tarval *get_tarval_null(ir_mode *mode)
502 switch(get_mode_sort(mode))
504 case irms_control_flow:
507 case irms_internal_boolean:
511 case irms_float_number:
512 return new_tarval_from_double(0.0, mode);
514 case irms_int_number:
516 return new_tarval_from_long(0l, mode);
519 return tarval_P_void;
524 tarval *get_tarval_one(ir_mode *mode)
529 switch(get_mode_sort(mode))
531 case irms_control_flow:
534 case irms_internal_boolean:
539 case irms_float_number:
540 return new_tarval_from_double(1.0, mode);
542 case irms_int_number:
544 return new_tarval_from_long(1l, mode);
550 tarval *get_tarval_nan(ir_mode *mode)
555 if (get_mode_sort(mode) == irms_float_number) {
557 return get_tarval(fc_get_buffer(), fc_get_buffer_length(), mode);
560 assert(0 && "tarval is not floating point");
565 tarval *get_tarval_inf(ir_mode *mode)
570 if (get_mode_sort(mode) == irms_float_number) {
572 return get_tarval(fc_get_buffer(), fc_get_buffer_length(), mode);
575 assert(0 && "tarval is not floating point");
581 * Arithmethic operations on tarvals ========================================
585 * test if negative number, 1 means 'yes'
587 int tarval_is_negative(tarval *a)
592 switch (get_mode_sort(a->mode))
594 case irms_int_number:
595 if (!mode_is_signed(a->mode)) return 0;
597 return sc_comp(a->value, get_mode_null(a->mode)->value) == -1 ? 1 : 0;
599 case irms_float_number:
600 return fc_comp(a->value, get_mode_null(a->mode)->value) == -1 ? 1 : 0;
603 assert(0 && "not implemented");
609 * test if null, 1 means 'yes'
611 int tarval_is_null(tarval *a)
613 ir_mode *m = get_tarval_mode(a);
615 return a == get_tarval_null(m);
621 pnc_number tarval_cmp(tarval *a, tarval *b)
627 if (a == tarval_bad || b == tarval_bad) assert(0 && "Comparison with tarval_bad");
628 if (a == tarval_undefined || b == tarval_undefined) return False;
629 if (a == b) return Eq;
630 if (get_tarval_mode(a) != get_tarval_mode(b)) return Uo;
632 /* Here the two tarvals are unequal and of the same mode */
633 switch (get_mode_sort(a->mode))
635 case irms_control_flow:
640 case irms_float_number:
641 return (fc_comp(a->value, b->value)==1)?(Gt):(Lt);
643 case irms_int_number:
645 return (sc_comp(a->value, b->value)==1)?(Gt):(Lt);
647 case irms_internal_boolean:
648 return (a == tarval_b_true)?(Gt):(Lt);
657 * convert to other mode
659 tarval *tarval_convert_to(tarval *src, ir_mode *m)
667 if (src->mode == m) return src;
669 switch (get_mode_sort(src->mode))
671 case irms_control_flow:
676 case irms_float_number:
677 switch (get_mode_sort(m)) {
678 case irms_float_number:
680 tv.length = src->length;
681 tv.value = src->value;
682 if (overflows(&tv)) {
686 return INSERT_TARVAL(&tv);
693 case irms_int_number:
694 switch (get_mode_sort(m)) {
695 case irms_int_number:
698 tv.length = src->length;
699 tv.value = src->value;
703 return INSERT_TARVAL(&tv);
705 case irms_internal_boolean:
706 /* XXX C semantics */
707 if (src == get_mode_null(src->mode)) return tarval_b_false;
708 else return tarval_b_true;
715 case irms_internal_boolean:
716 switch (get_mode_sort(m))
718 case irms_int_number:
719 if (src == tarval_b_true) return get_mode_one(m);
720 else return get_mode_null(m);
739 tarval *tarval_neg(tarval *a)
743 assert(mode_is_num(a->mode)); /* negation only for numerical values */
744 assert(mode_is_signed(a->mode)); /* negation is difficult without negative numbers, isn't it */
746 switch (get_mode_sort(a->mode))
748 case irms_int_number:
750 return get_tarval(sc_get_buffer(), sc_get_buffer_length(), a->mode);
752 case irms_float_number:
754 return get_tarval(fc_get_buffer(), fc_get_buffer_length(), a->mode);
764 tarval *tarval_add(tarval *a, tarval *b)
769 assert((a->mode == b->mode) || (get_mode_sort(a->mode) == irms_character && mode_is_int(b->mode)));
771 switch (get_mode_sort(a->mode))
774 case irms_int_number:
775 /* modes of a,b are equal, so result has mode of a as this might be the character */
776 sc_add(a->value, b->value);
777 /* FIXME: Check for overflow */
778 return get_tarval(sc_get_buffer(), sc_get_buffer_length(), a->mode);
780 case irms_float_number:
781 /* FIXME: Overflow/Underflow/transition to inf when mode < 80bit */
782 fc_add(a->value, b->value);
783 return get_tarval(fc_get_buffer(), fc_get_buffer_length(), a->mode);
793 tarval *tarval_sub(tarval *a, tarval *b)
798 assert((a->mode == b->mode) || (get_mode_sort(a->mode) == irms_character && mode_is_int(b->mode)));
800 switch (get_mode_sort(a->mode))
803 case irms_int_number:
804 /* modes of a,b are equal, so result has mode of a as this might be the character */
805 sc_sub(a->value, b->value);
806 /* FIXME: check for overflow */
807 return get_tarval(sc_get_buffer(), sc_get_buffer_length(), a->mode);
809 case irms_float_number:
810 /* FIXME: Overflow/Underflow/transition to inf when mode < 80bit */
811 fc_add(a->value, b->value);
812 return get_tarval(fc_get_buffer(), fc_get_buffer_length(), a->mode);
822 tarval *tarval_mul(tarval *a, tarval *b)
827 assert((a->mode == b->mode) && mode_is_num(a->mode));
829 switch (get_mode_sort(a->mode))
831 case irms_int_number:
832 /* modes of a,b are equal */
833 sc_mul(a->value, b->value);
834 /* FIXME: check for overflow */
835 return get_tarval(sc_get_buffer(), sc_get_buffer_length(), a->mode);
837 case irms_float_number:
838 /* FIXME: Overflow/Underflow/transition to inf when mode < 80bit */
839 fc_add(a->value, b->value);
840 return get_tarval(fc_get_buffer(), fc_get_buffer_length(), a->mode);
848 * floating point division
850 tarval *tarval_quo(tarval *a, tarval *b)
855 assert((a->mode == b->mode) && mode_is_float(a->mode));
857 /* FIXME: Overflow/Underflow/transition to inf when mode < 80bit */
858 fc_div(a->value, b->value);
859 return get_tarval(fc_get_buffer(), fc_get_buffer_length(), a->mode);
865 tarval *tarval_div(tarval *a, tarval *b)
870 assert((a->mode == b->mode) && mode_is_int(a->mode));
872 /* modes of a,b are equal */
873 sc_div(a->value, b->value);
874 return get_tarval(sc_get_buffer(), sc_get_buffer_length(), a->mode);
880 tarval *tarval_mod(tarval *a, tarval *b)
885 assert((a->mode == b->mode) && mode_is_int(a->mode));
887 /* modes of a,b are equal */
888 sc_mod(a->value, b->value);
889 return get_tarval(sc_get_buffer(), sc_get_buffer_length(), a->mode);
895 tarval *tarval_abs(tarval *a)
899 assert(mode_is_num(a->mode));
901 switch (get_mode_sort(a->mode))
903 case irms_int_number:
904 if (sc_comp(a->value, get_mode_null(a->mode)->value) == -1)
907 return get_tarval(sc_get_buffer(), sc_get_buffer_length(), a->mode);
911 case irms_float_number:
923 tarval *tarval_and(tarval *a, tarval *b)
928 assert(a->mode == b->mode);
930 /* GL: needed for easy optimization. */
931 if (a->mode == mode_b) return (a == tarval_b_false) ? a : b;
933 assert(mode_is_int(a->mode));
935 sc_and(a->value, b->value);
936 return get_tarval(sc_get_buffer(), sc_get_buffer_length(), a->mode);
942 tarval *tarval_or (tarval *a, tarval *b)
947 assert(a->mode == b->mode);
949 /* GL: needed for easy optimization. */
950 if (a->mode == mode_b) return (a == tarval_b_true) ? a : b;
953 assert(mode_is_int(a->mode));
955 sc_or(a->value, b->value);
956 return get_tarval(sc_get_buffer(), sc_get_buffer_length(), a->mode);
960 * bitwise exclusive or (xor)
962 tarval *tarval_eor(tarval *a, tarval *b)
967 assert((a->mode == b->mode) && mode_is_int(a->mode));
969 sc_or(a->value, b->value);
970 return get_tarval(sc_get_buffer(), sc_get_buffer_length(), a->mode);
976 tarval *tarval_shl(tarval *a, tarval *b)
981 assert(mode_is_int(a->mode) && mode_is_int(b->mode));
983 sc_shl(a->value, b->value, get_mode_size_bits(a->mode), mode_is_signed(a->mode));
984 return get_tarval(sc_get_buffer(), sc_get_buffer_length(), a->mode);
988 * bitwise unsigned right shift
990 tarval *tarval_shr(tarval *a, tarval *b)
995 assert(mode_is_int(a->mode) && mode_is_int(b->mode));
997 sc_shr(a->value, b->value, get_mode_size_bits(a->mode), mode_is_signed(a->mode));
998 return get_tarval(sc_get_buffer(), sc_get_buffer_length(), a->mode);
1002 * bitwise signed right shift
1004 tarval *tarval_shrs(tarval *a, tarval *b)
1009 assert(mode_is_int(a->mode) && mode_is_int(b->mode));
1011 sc_shrs(a->value, b->value, get_mode_size_bits(a->mode), mode_is_signed(a->mode));
1012 return get_tarval(sc_get_buffer(), sc_get_buffer_length(), a->mode);
1018 tarval *tarval_rot(tarval *a, tarval *b)
1023 assert(mode_is_int(a->mode) && mode_is_int(b->mode));
1025 sc_rot(a->value, b->value, get_mode_size_bits(a->mode), mode_is_signed(a->mode));
1026 return get_tarval(sc_get_buffer(), sc_get_buffer_length(), a->mode);
1033 int tarval_snprintf(char *buf, size_t len, tarval *tv)
1035 static const tarval_mode_info default_info = { TVO_NATIVE, NULL, NULL };
1039 const tarval_mode_info *mode_info;
1040 const char *prefix, *suffix;
1044 mode_info = tv->mode->tv_priv;
1046 mode_info = &default_info;
1047 prefix = mode_info->mode_prefix ? mode_info->mode_prefix : "";
1048 suffix = mode_info->mode_suffix ? mode_info->mode_suffix : "";
1050 switch (get_mode_sort(tv->mode))
1052 case irms_int_number:
1053 case irms_character:
1054 switch (mode_info->mode_output) {
1057 str = sc_print(tv->value, get_mode_size_bits(tv->mode), SC_DEC);
1061 str = sc_print(tv->value, get_mode_size_bits(tv->mode), SC_OCT);
1067 str = sc_print(tv->value, get_mode_size_bits(tv->mode), SC_HEX);
1070 return snprintf(buf, len, "%s%s%s", prefix, str, suffix);
1072 case irms_float_number:
1073 return snprintf(buf, len, "%s%s%s", prefix, fc_print_dec(tv->value, tv_buf, sizeof(tv_buf)), suffix);
1075 case irms_reference:
1076 if (tv==tarval_P_void) return snprintf(buf, len, "NULL");
1077 if (tv->value != NULL)
1078 if (tarval_is_entity(tv)) {
1079 if (get_entity_peculiarity((entity *)tv->value) == existent)
1080 return snprintf(buf, len, "%s%s%s", prefix, get_entity_ld_name((entity *)tv->value), suffix);
1082 if (mode_info->mode_output == TVO_NATIVE)
1083 return snprintf(buf, len, "NULL");
1085 return snprintf(buf, len, "0");
1089 if (size > tv->length) {
1090 memcpy(buf, tv->value, tv->length);
1091 buf[tv->length] = '\0';
1095 memcpy(buf, tv->value, size-1);
1101 return snprintf(buf, len, "void");
1103 case irms_internal_boolean:
1104 switch (mode_info->mode_output) {
1110 return snprintf(buf, len, "%s%c%s", prefix, (tv == tarval_b_true) ? '1' : '0', suffix);
1114 return snprintf(buf, len, "%s%s%s", prefix, (tv == tarval_b_true) ? "true" : "false", suffix);
1117 case irms_control_flow:
1119 case irms_auxiliary:
1120 return snprintf(buf, len, "<BAD>");
1128 * Output of tarvals to stdio.
1130 int tarval_printf(tarval *tv) {
1134 res = tarval_snprintf(buf, sizeof(buf), tv);
1135 assert(res < sizeof(buf) && "buffer to small for tarval_snprintf");
1141 char *tarval_bitpattern(tarval *tv)
1147 * access to the bitpattern
1149 unsigned char tarval_sub_bits(tarval *tv, unsigned byte_ofs)
1151 switch (get_mode_sort(tv->mode)) {
1152 case irms_int_number:
1153 case irms_character:
1154 return sc_sub_bits(tv->value, tv->length, byte_ofs);
1156 case irms_float_number:
1157 return fc_sub_bits(tv->value, get_mode_size_bits(tv->mode), byte_ofs);
1165 * Specify the output options of one mode.
1167 * This functions stores the modinfo, so DO NOT DESTROY it.
1169 * Returns zero on success.
1171 int tarval_set_mode_output_option(ir_mode *mode, const tarval_mode_info *modeinfo)
1175 mode->tv_priv = modeinfo;
1179 /* Identifying some tarvals ??? */
1180 /* Implemented in old tv.c as such:
1181 * return 0 for additive neutral,
1182 * 1 for multiplicative neutral,
1183 * -1 for bitwise-and neutral
1186 * Implemented for completeness */
1187 long tarval_classify(tarval *tv)
1190 if (!tv || tv == tarval_bad) return 2;
1192 if (tv == get_mode_null(tv->mode)) return 0;
1193 else if (tv == get_mode_one(tv->mode)) return 1;
1194 else if ((get_mode_sort(tv->mode) == irms_int_number)
1195 && (tv == new_tarval_from_long(-1, tv->mode))) return -1;
1201 * Initialization of the tarval module: called before init_mode()
1203 void init_tarval_1(void)
1206 /* initialize the sets holding the tarvals with a comparison function and
1207 * an initial size, which is the expected number of constants */
1208 tarvals = new_set(memcmp, TUNE_NCONSTANTS);
1209 values = new_set(memcmp, TUNE_NCONSTANTS);
1210 /* init with default precision */
1212 /* init_fltcalc(0); not yet*/
1213 tarval_bad = (tarval*)malloc(sizeof(tarval));
1214 tarval_undefined = (tarval*)malloc(sizeof(tarval));
1215 tarval_b_true = (tarval*)malloc(sizeof(tarval));
1216 tarval_b_false = (tarval*)malloc(sizeof(tarval));
1217 tarval_P_void = (tarval*)malloc(sizeof(tarval));
1221 * default mode_info for output as HEX
1223 static const tarval_mode_info hex_output = {
1230 * default mode_info for output as reference
1232 static const tarval_mode_info reference_output = {
1240 * Initialization of the tarval module: called after init_mode()
1242 void init_tarval_2(void)
1246 tarval_bad->mode = mode_BAD;
1247 tarval_undefined->mode = mode_ANY;
1248 tarval_b_true->mode = mode_b;
1249 tarval_b_false->mode = mode_b;
1250 tarval_P_void->mode = mode_P;
1253 * assign output modes that are compatible with the
1254 * old implementation: Hex output
1256 tarval_set_mode_output_option(mode_U, &hex_output);
1257 tarval_set_mode_output_option(mode_C, &hex_output);
1258 tarval_set_mode_output_option(mode_Bs, &hex_output);
1259 tarval_set_mode_output_option(mode_Bu, &hex_output);
1260 tarval_set_mode_output_option(mode_Hs, &hex_output);
1261 tarval_set_mode_output_option(mode_Hu, &hex_output);
1262 tarval_set_mode_output_option(mode_Hs, &hex_output);
1263 tarval_set_mode_output_option(mode_Hu, &hex_output);
1264 tarval_set_mode_output_option(mode_Is, &hex_output);
1265 tarval_set_mode_output_option(mode_Iu, &hex_output);
1266 tarval_set_mode_output_option(mode_Ls, &hex_output);
1267 tarval_set_mode_output_option(mode_Lu, &hex_output);
1268 tarval_set_mode_output_option(mode_P, &reference_output);
1271 /****************************************************************************
1273 ****************************************************************************/