+/* Normalize the byte order of FROM into TO. If no normalization is
+ needed then FMT->byteorder is returned and TO is not changed;
+ otherwise the format of the normalized form in TO is returned. */
+
+static enum floatformat_byteorders
+floatformat_normalize_byteorder (const struct floatformat *fmt,
+ const void *from, void *to)
+{
+ const unsigned char *swapin;
+ unsigned char *swapout;
+ int words;
+
+ if (fmt->byteorder == floatformat_little
+ || fmt->byteorder == floatformat_big)
+ return fmt->byteorder;
+
+ words = fmt->totalsize / FLOATFORMAT_CHAR_BIT;
+ words >>= 2;
+
+ swapout = (unsigned char *)to;
+ swapin = (const unsigned char *)from;
+
+ if (fmt->byteorder == floatformat_vax)
+ {
+ while (words-- > 0)
+ {
+ *swapout++ = swapin[1];
+ *swapout++ = swapin[0];
+ *swapout++ = swapin[3];
+ *swapout++ = swapin[2];
+ swapin += 4;
+ }
+ /* This may look weird, since VAX is little-endian, but it is
+ easier to translate to big-endian than to little-endian. */
+ return floatformat_big;
+ }
+ else
+ {
+ gdb_assert (fmt->byteorder == floatformat_littlebyte_bigword);
+
+ while (words-- > 0)
+ {
+ *swapout++ = swapin[3];
+ *swapout++ = swapin[2];
+ *swapout++ = swapin[1];
+ *swapout++ = swapin[0];
+ swapin += 4;
+ }
+ return floatformat_big;
+ }
+}
+