more debug info
[libfirm] / ir / ir / irmode.c
index 55108bb..75b02bc 100644 (file)
@@ -592,6 +592,37 @@ int smaller_mode(const ir_mode *sm, const ir_mode *lm) {
        return 0;
 }
 
+/* Returns true if a value of mode sm can be converted into mode lm
+   and backwards without loss. */
+int values_in_mode(const ir_mode *sm, const ir_mode *lm) {
+       int sm_bits, lm_bits;
+       ir_mode_arithmetic arith;
+
+       assert(sm);
+       assert(lm);
+
+       if (sm == lm) return 1;
+
+       if (sm == mode_b)
+               return mode_is_int(lm);
+
+       sm_bits = get_mode_size_bits(sm);
+       lm_bits = get_mode_size_bits(lm);
+
+       arith = get_mode_arithmetic(sm);
+       if (arith != get_mode_arithmetic(lm))
+               return 0;
+
+       switch (arith) {
+               case irma_twos_complement:
+               case irma_ieee754:
+                       return get_mode_size_bits(sm) <= get_mode_size_bits(lm);
+
+               default:
+                       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));