+smaller_mode(const ir_mode *sm, const ir_mode *lm) {
+ int sm_bits, lm_bits;
+
+ assert(sm);
+ assert(lm);
+
+ if (sm == lm) return 1;
+
+ sm_bits = get_mode_size_bits(sm);
+ lm_bits = get_mode_size_bits(lm);
+
+ switch (get_mode_sort(sm)) {
+ case irms_int_number:
+ switch (get_mode_sort(lm)) {
+ case irms_int_number:
+ /* integers are convertable if
+ * - both have the same sign and lm is the larger one
+ * - lm is the signed one and is at least two bits larger
+ * (one for the sign, one for the highest bit of sm)
+ * - sm & lm are two_complement and lm has greater or equal number of bits
+ */
+ if ( get_mode_arithmetic(sm) == get_mode_arithmetic(lm)
+ && get_mode_arithmetic(sm) == irma_twos_complement) {
+ return lm_bits >= sm_bits;
+ } else if (mode_is_signed(sm)) {
+ if ( mode_is_signed(lm) && (lm_bits >= sm_bits) )
+ return 1;
+ } else if (mode_is_signed(lm)) {
+ if (lm_bits > sm_bits + 1)
+ return 1;
+ } else if (lm_bits >= sm_bits) {
+ return 1;
+ }
+ break;
+
+ case irms_float_number:
+ /* int to float works if the float is large enough */
+ return 0;
+
+ default:
+ break;
+ }
+ break;
+
+ case irms_float_number:
+ if (get_mode_arithmetic(sm) == get_mode_arithmetic(lm)) {
+ if ( (get_mode_sort(lm) == irms_float_number)
+ && (get_mode_size_bits(lm) >= get_mode_size_bits(sm)) )
+ return 1;
+ }
+ break;
+
+ case irms_reference:
+ /* do exist machines out there with different pointer lenghts ?*/
+ return 0;
+
+ case irms_internal_boolean:
+ return mode_is_int(lm);
+
+ default:
+ break;
+ }
+
+ /* else */
+ return 0;
+}
+
+/* Return the signed integer equivalent mode for an reference mode. */
+ir_mode *get_reference_mode_signed_eq(ir_mode *mode) {
+ assert(mode_is_reference(mode));
+ return mode->eq_signed;
+}
+
+/* Sets the signed integer equivalent mode for an reference mode. */
+void set_reference_mode_signed_eq(ir_mode *ref_mode, ir_mode *int_mode) {
+ assert(mode_is_reference(ref_mode));
+ assert(mode_is_int(int_mode));
+ ref_mode->eq_signed = int_mode;
+}
+
+/* Return the unsigned integer equivalent mode for an reference mode. */
+ir_mode *get_reference_mode_unsigned_eq(ir_mode *mode) {
+ assert(mode_is_reference(mode));
+ return mode->eq_unsigned;
+}
+
+/* Sets the unsigned integer equivalent mode for an reference mode. */
+void set_reference_mode_unsigned_eq(ir_mode *ref_mode, ir_mode *int_mode) {
+ assert(mode_is_reference(ref_mode));
+ assert(mode_is_int(int_mode));
+ ref_mode->eq_unsigned = int_mode;
+}
+
+/* initialization, build the default modes */
+void
+init_mode (void) {
+ ir_mode newmode;
+
+ obstack_init(&modes);
+
+ num_modes = 0;
+ /* initialize predefined modes */
+
+ /* Internal Modes */
+ newmode.arithmetic = irma_none;
+ newmode.size = 0;
+ newmode.sign = 0;
+ newmode.modulo_shift = 0;
+ newmode.vector_elem = 0;
+ newmode.eq_signed = NULL;
+ newmode.eq_unsigned = NULL;
+ newmode.link = NULL;
+ newmode.tv_priv = NULL;
+
+ /* Control Flow Modes*/
+ newmode.sort = irms_control_flow;
+
+ /* Basic Block */
+ newmode.name = new_id_from_chars("BB", 2);
+ newmode.code = irm_BB;
+
+ mode_BB = register_mode(&newmode);
+
+ /* eXecution */
+ newmode.name = new_id_from_chars("X", 1);
+ newmode.code = irm_X;
+
+ mode_X = register_mode(&newmode);
+
+ /* Memory Modes */
+ newmode.sort = irms_memory;
+
+ /* Memory */
+ newmode.name = new_id_from_chars("M", 1);
+ newmode.code = irm_M;
+
+ mode_M = register_mode(&newmode);
+
+ /* Auxiliary Modes */
+ newmode.sort = irms_auxiliary,
+
+ /* Tuple */
+ newmode.name = new_id_from_chars("T", 1);
+ newmode.code = irm_T;
+
+ mode_T = register_mode(&newmode);
+
+ /* ANY */
+ newmode.name = new_id_from_chars("ANY", 3);
+ newmode.code = irm_ANY;
+
+ mode_ANY = register_mode(&newmode);
+
+ /* BAD */
+ newmode.name = new_id_from_chars("BAD", 3);
+ newmode.code = irm_BAD;
+
+ mode_BAD = register_mode(&newmode);
+
+ /* Internal Boolean Modes */
+ newmode.sort = irms_internal_boolean;
+
+ /* boolean */
+ newmode.name = new_id_from_chars("b", 1);
+ newmode.code = irm_b;
+
+ mode_b = register_mode(&newmode);
+
+ /* Data Modes */
+ newmode.vector_elem = 1;
+
+ /* Float Number Modes */
+ newmode.sort = irms_float_number;
+ newmode.arithmetic = irma_ieee754;
+
+ /* float */
+ newmode.name = new_id_from_chars("F", 1);
+ newmode.code = irm_F;
+ newmode.sign = 1;
+ newmode.size = 32;
+
+ mode_F = register_mode(&newmode);
+
+ /* double */
+ newmode.name = new_id_from_chars("D", 1);
+ newmode.code = irm_D;
+ newmode.sign = 1;
+ newmode.size = 64;
+
+ mode_D = register_mode(&newmode);
+
+ /* extended */
+ newmode.name = new_id_from_chars("E", 1);
+ newmode.code = irm_E;
+ newmode.sign = 1;
+ newmode.size = 80;
+
+ mode_E = register_mode(&newmode);
+
+ /* Integer Number Modes */
+ newmode.sort = irms_int_number;
+ newmode.arithmetic = irma_twos_complement;
+
+ /* signed byte */
+ newmode.name = new_id_from_chars("Bs", 2);
+ newmode.code = irm_Bs;
+ newmode.sign = 1;
+ newmode.size = 8;
+ newmode.modulo_shift = 32;
+
+ mode_Bs = register_mode(&newmode);
+
+ /* unsigned byte */
+ newmode.name = new_id_from_chars("Bu", 2);
+ newmode.code = irm_Bu;
+ newmode.arithmetic = irma_twos_complement;
+ newmode.sign = 0;
+ newmode.size = 8;
+ newmode.modulo_shift = 32;
+
+ mode_Bu = register_mode(&newmode);
+
+ /* signed short integer */
+ newmode.name = new_id_from_chars("Hs", 2);
+ newmode.code = irm_Hs;
+ newmode.sign = 1;
+ newmode.size = 16;
+ newmode.modulo_shift = 32;
+
+ mode_Hs = register_mode(&newmode);
+
+ /* unsigned short integer */
+ newmode.name = new_id_from_chars("Hu", 2);
+ newmode.code = irm_Hu;
+ newmode.sign = 0;
+ newmode.size = 16;
+ newmode.modulo_shift = 32;
+
+ mode_Hu = register_mode(&newmode);
+
+ /* signed integer */
+ newmode.name = new_id_from_chars("Is", 2);
+ newmode.code = irm_Is;
+ newmode.sign = 1;
+ newmode.size = 32;
+ newmode.modulo_shift = 32;
+
+ mode_Is = register_mode(&newmode);
+
+ /* unsigned integer */
+ newmode.name = new_id_from_chars("Iu", 2);
+ newmode.code = irm_Iu;
+ newmode.sign = 0;
+ newmode.size = 32;
+ newmode.modulo_shift = 32;
+
+ mode_Iu = register_mode(&newmode);
+
+ /* signed long integer */
+ newmode.name = new_id_from_chars("Ls", 2);
+ newmode.code = irm_Ls;
+ newmode.sign = 1;
+ newmode.size = 64;
+ newmode.modulo_shift = 64;
+
+ mode_Ls = register_mode(&newmode);
+
+ /* unsigned long integer */
+ newmode.name = new_id_from_chars("Lu", 2);
+ newmode.code = irm_Lu;
+ newmode.sign = 0;
+ newmode.size = 64;
+ newmode.modulo_shift = 64;
+
+ mode_Lu = register_mode(&newmode);
+
+ /* signed long long integer */
+ newmode.name = new_id_from_chars("LLs", 3);
+ newmode.code = irm_LLs;
+ newmode.sign = 1;
+ newmode.size = 128;
+ newmode.modulo_shift = 128;
+
+ mode_LLs = register_mode(&newmode);
+
+ /* unsigned long long integer */
+ newmode.name = new_id_from_chars("LLu", 3);
+ newmode.code = irm_LLu;
+ newmode.sign = 0;
+ newmode.size = 128;
+ newmode.modulo_shift = 128;
+
+ mode_LLu = register_mode(&newmode);
+
+ /* Reference Mode */
+ newmode.sort = irms_reference;
+ newmode.arithmetic = irma_twos_complement;
+
+ /* pointer */
+ newmode.name = new_id_from_chars("P", 1);
+ newmode.code = irm_P;
+ newmode.sign = 0;
+ newmode.size = 32;
+ newmode.modulo_shift = 0;
+ newmode.eq_signed = mode_Is;
+ newmode.eq_unsigned = mode_Iu;
+
+ mode_P = register_mode(&newmode);
+
+ /* set the machine specific modes to the predefined ones */
+ mode_P_code = mode_P;
+ mode_P_data = mode_P;
+}
+
+/* find a signed mode for an unsigned integer mode */
+ir_mode *find_unsigned_mode(const ir_mode *mode) {
+ ir_mode n = *mode;
+
+ assert(mode->sort == irms_int_number);
+ n.sign = 0;
+ return find_mode(&n);
+}
+
+/* find an unsigned mode for a signed integer mode */
+ir_mode *find_signed_mode(const ir_mode *mode) {
+ ir_mode n = *mode;
+
+ assert(mode->sort == irms_int_number);
+ n.sign = 1;
+ return find_mode(&n);
+}
+
+/* finds a integer mode with 2*n bits for an integer mode with n bits. */
+ir_mode *find_double_bits_int_mode(const ir_mode *mode) {
+ ir_mode n = *mode;
+
+ assert(mode->sort == irms_int_number && mode->arithmetic == irma_twos_complement);
+
+ n.size = 2*mode->size;
+ return find_mode(&n);
+}
+
+/*
+ * Returns non-zero if the given mode honors signed zero's, i.e.,
+ * a +0 and a -0 exists and handled differently.
+ */
+int mode_honor_signed_zeros(const ir_mode *mode) {
+ /* for floating point, we know that IEEE 754 has +0 and -0,
+ * but always handles it identical.
+ */
+ return
+ mode->sort == irms_float_number &&
+ mode->arithmetic != irma_ieee754;
+}
+
+/*
+ * Returns non-zero if the given mode might overflow on unary Minus.
+ *
+ * This does NOT happen on IEEE 754.
+ */
+int mode_overflow_on_unary_Minus(const ir_mode *mode) {
+ if (mode->sort == irms_float_number)
+ return mode->arithmetic == irma_ieee754 ? 0 : 1;
+ return 1;
+}
+
+/*
+ * Returns non-zero if the mode has a reversed wrap-around
+ * logic, especially (a + x) - x == a.
+ *
+ * This is normally true for integer modes, not for floating
+ * point modes.
+ */
+int mode_wrap_around(const ir_mode *mode) {
+ /* FIXME: better would be an extra mode property */
+ return mode_is_int(mode);
+}
+
+void finish_mode(void) {
+ obstack_free(&modes, 0);
+
+ mode_T = NULL;
+ mode_X = NULL;
+ mode_M = NULL;
+ mode_BB = NULL;
+ mode_ANY = NULL;
+ mode_BAD = NULL;
+
+ mode_F = NULL;
+ mode_D = NULL;
+ mode_E = NULL;
+
+ mode_Bs = NULL;
+ mode_Bu = NULL;
+ mode_Hs = NULL;
+ mode_Hu = NULL;
+ mode_Is = NULL;
+ mode_Iu = NULL;
+ mode_Ls = NULL;
+ mode_Lu = NULL;
+
+ mode_b = NULL;
+
+ mode_P = NULL;
+ mode_P_code = NULL;
+ mode_P_data = NULL;