- int len_v1, len_v2, len_v;
- enum bfd_endian byte_order_v1, byte_order_v2, byte_order_v;
- gdb_byte v1[16], v2[16];
- gdb_byte v[16];
+ value *fp_val = allocate_value (type1);
+
+ fp.write_fixed_point
+ (gdb::make_array_view (value_contents_raw (fp_val).data (),
+ TYPE_LENGTH (type1)),
+ type_byte_order (type1),
+ type1->is_unsigned (),
+ type1->fixed_point_scaling_factor ());
+
+ return fp_val;
+ };
+
+ switch (op)
+ {
+ case BINOP_ADD:
+ mpq_add (res.val, v1.val, v2.val);
+ val = fixed_point_to_value (res);
+ break;
+
+ case BINOP_SUB:
+ mpq_sub (res.val, v1.val, v2.val);
+ val = fixed_point_to_value (res);
+ break;
+
+ case BINOP_MIN:
+ val = fixed_point_to_value (mpq_cmp (v1.val, v2.val) < 0 ? v1 : v2);
+ break;
+
+ case BINOP_MAX:
+ val = fixed_point_to_value (mpq_cmp (v1.val, v2.val) > 0 ? v1 : v2);
+ break;
+
+ case BINOP_MUL:
+ mpq_mul (res.val, v1.val, v2.val);
+ val = fixed_point_to_value (res);
+ break;
+
+ case BINOP_DIV:
+ if (mpq_sgn (v2.val) == 0)
+ error (_("Division by zero"));
+ mpq_div (res.val, v1.val, v2.val);
+ val = fixed_point_to_value (res);
+ break;
+
+ case BINOP_EQUAL:
+ val = value_from_ulongest (language_bool_type (language, gdbarch),
+ mpq_cmp (v1.val, v2.val) == 0 ? 1 : 0);
+ break;
+
+ case BINOP_LESS:
+ val = value_from_ulongest (language_bool_type (language, gdbarch),
+ mpq_cmp (v1.val, v2.val) < 0 ? 1 : 0);
+ break;
+
+ default:
+ error (_("Integer-only operation on fixed point number."));
+ }
+
+ return val;
+}
+
+/* A helper function that finds the type to use for a binary operation
+ involving TYPE1 and TYPE2. */
+
+static struct type *
+promotion_type (struct type *type1, struct type *type2)
+{
+ struct type *result_type;