[svn:parrot] r36772 - in trunk/src: . packfile

rurban at svn.parrot.org rurban at svn.parrot.org
Sun Feb 15 20:09:05 UTC 2009


Author: rurban
Date: Sun Feb 15 20:09:04 2009
New Revision: 36772
URL: https://trac.parrot.org/parrot/changeset/36772

Log:
[core] add more needed 12 + 16 double byte transformers. switch trick by Infinoid.

Modified:
   trunk/src/packfile.c
   trunk/src/packfile/pf_items.c

Modified: trunk/src/packfile.c
==============================================================================
--- trunk/src/packfile.c	Sun Feb 15 20:07:04 2009	(r36771)
+++ trunk/src/packfile.c	Sun Feb 15 20:09:04 2009	(r36772)
@@ -1233,14 +1233,15 @@
 #if NUMVAL_SIZE == 8
     header->floattype = FLOATTYPE_8;
 #else
-#  if (NUMVAL_SIZE == 12) && PARROT_BIGENDIAN
+#  if (NUMVAL_SIZE == 12) && !PARROT_BIGENDIAN
     header->floattype = FLOATTYPE_12;
 #  else
 #    if (NUMVAL_SIZE == 16)
     header->floattype = FLOATTYPE_16;
 #    else
     exit_fatal(1, "PackFile_set_header: Unsupported floattype NUMVAL_SIZE=%d,"
-               " PARROT_BIGENDIAN=%d\n", NUMVAL_SIZE, PARROT_BIGENDIAN);
+               " PARROT_BIGENDIAN=%d\n", NUMVAL_SIZE, 
+               PARROT_BIGENDIAN ? "big-endian" : "little-endian");
 #    endif
 #  endif
 #endif
@@ -4551,8 +4552,8 @@
 
 =head1 HISTORY
 
-Parrot_readbc and Parrot_loadbc renamed. Trace macros and 64-bit fixes
-by Reini Urban 2009.
+Parrot_readbc and Parrot_loadbc renamed. Trace macros, long double and 
+64-bit conversion work by Reini Urban 2009.
 
 Rework by Melvin; new bytecode format, make bytecode portable. (Do
 endian conversion and wordsize transforms on the fly.)

Modified: trunk/src/packfile/pf_items.c
==============================================================================
--- trunk/src/packfile/pf_items.c	Sun Feb 15 20:07:04 2009	(r36771)
+++ trunk/src/packfile/pf_items.c	Sun Feb 15 20:09:04 2009	(r36772)
@@ -39,6 +39,20 @@
 /* HEADERIZER BEGIN: static */
 /* Don't modify between HEADERIZER BEGIN / HEADERIZER END.  Your changes will be lost. */
 
+static void cvt_num12_num16(
+    ARGOUT(unsigned char *dest),
+    ARGIN(const unsigned char *src))
+        __attribute__nonnull__(1)
+        __attribute__nonnull__(2)
+        FUNC_MODIFIES(*dest);
+
+static void cvt_num12_num16_be(
+    ARGOUT(unsigned char *dest),
+    ARGIN(const unsigned char *src))
+        __attribute__nonnull__(1)
+        __attribute__nonnull__(2)
+        FUNC_MODIFIES(*dest);
+
 static void cvt_num12_num8(
     ARGOUT(unsigned char *dest),
     ARGIN(const unsigned char *src))
@@ -67,9 +81,9 @@
         __attribute__nonnull__(2)
         FUNC_MODIFIES(*dest);
 
-static void cvt_num16_num12_le(
+static void cvt_num16_num12_be(
     ARGOUT(unsigned char *dest),
-    ARGIN(unsigned char *src))
+    ARGIN(const unsigned char *src))
         __attribute__nonnull__(1)
         __attribute__nonnull__(2)
         FUNC_MODIFIES(*dest);
@@ -95,6 +109,34 @@
         __attribute__nonnull__(2)
         FUNC_MODIFIES(*dest);
 
+static void cvt_num8_num12(
+    ARGOUT(unsigned char *dest),
+    ARGIN(const unsigned char *src))
+        __attribute__nonnull__(1)
+        __attribute__nonnull__(2)
+        FUNC_MODIFIES(*dest);
+
+static void cvt_num8_num12_be(
+    ARGOUT(unsigned char *dest),
+    ARGIN(const unsigned char *src))
+        __attribute__nonnull__(1)
+        __attribute__nonnull__(2)
+        FUNC_MODIFIES(*dest);
+
+static void cvt_num8_num16(
+    ARGOUT(unsigned char *dest),
+    ARGIN(const unsigned char *src))
+        __attribute__nonnull__(1)
+        __attribute__nonnull__(2)
+        FUNC_MODIFIES(*dest);
+
+static void cvt_num8_num16_be(
+    ARGOUT(unsigned char *dest),
+    ARGIN(const unsigned char *src))
+        __attribute__nonnull__(1)
+        __attribute__nonnull__(2)
+        FUNC_MODIFIES(*dest);
+
 PARROT_WARN_UNUSED_RESULT
 static opcode_t fetch_op_be_4(ARGIN(const unsigned char *b))
         __attribute__nonnull__(1);
@@ -123,6 +165,12 @@
 static opcode_t fetch_op_test(ARGIN(const unsigned char *b))
         __attribute__nonnull__(1);
 
+#define ASSERT_ARGS_cvt_num12_num16 __attribute__unused__ int _ASSERT_ARGS_CHECK = \
+       PARROT_ASSERT_ARG(dest) \
+    || PARROT_ASSERT_ARG(src)
+#define ASSERT_ARGS_cvt_num12_num16_be __attribute__unused__ int _ASSERT_ARGS_CHECK = \
+       PARROT_ASSERT_ARG(dest) \
+    || PARROT_ASSERT_ARG(src)
 #define ASSERT_ARGS_cvt_num12_num8 __attribute__unused__ int _ASSERT_ARGS_CHECK = \
        PARROT_ASSERT_ARG(dest) \
     || PARROT_ASSERT_ARG(src)
@@ -135,7 +183,7 @@
 #define ASSERT_ARGS_cvt_num16_num12 __attribute__unused__ int _ASSERT_ARGS_CHECK = \
        PARROT_ASSERT_ARG(dest) \
     || PARROT_ASSERT_ARG(src)
-#define ASSERT_ARGS_cvt_num16_num12_le __attribute__unused__ int _ASSERT_ARGS_CHECK = \
+#define ASSERT_ARGS_cvt_num16_num12_be __attribute__unused__ int _ASSERT_ARGS_CHECK = \
        PARROT_ASSERT_ARG(dest) \
     || PARROT_ASSERT_ARG(src)
 #define ASSERT_ARGS_cvt_num16_num8 __attribute__unused__ int _ASSERT_ARGS_CHECK = \
@@ -147,6 +195,18 @@
 #define ASSERT_ARGS_cvt_num16_num8_le __attribute__unused__ int _ASSERT_ARGS_CHECK = \
        PARROT_ASSERT_ARG(dest) \
     || PARROT_ASSERT_ARG(src)
+#define ASSERT_ARGS_cvt_num8_num12 __attribute__unused__ int _ASSERT_ARGS_CHECK = \
+       PARROT_ASSERT_ARG(dest) \
+    || PARROT_ASSERT_ARG(src)
+#define ASSERT_ARGS_cvt_num8_num12_be __attribute__unused__ int _ASSERT_ARGS_CHECK = \
+       PARROT_ASSERT_ARG(dest) \
+    || PARROT_ASSERT_ARG(src)
+#define ASSERT_ARGS_cvt_num8_num16 __attribute__unused__ int _ASSERT_ARGS_CHECK = \
+       PARROT_ASSERT_ARG(dest) \
+    || PARROT_ASSERT_ARG(src)
+#define ASSERT_ARGS_cvt_num8_num16_be __attribute__unused__ int _ASSERT_ARGS_CHECK = \
+       PARROT_ASSERT_ARG(dest) \
+    || PARROT_ASSERT_ARG(src)
 #define ASSERT_ARGS_fetch_op_be_4 __attribute__unused__ int _ASSERT_ARGS_CHECK = \
        PARROT_ASSERT_ARG(b)
 #define ASSERT_ARGS_fetch_op_be_8 __attribute__unused__ int _ASSERT_ARGS_CHECK = \
@@ -244,11 +304,50 @@
 
 /*
 
-=item C<static void cvt_num12_num8>
+=item C<static void cvt_num16_num12>
 
-Converts i386 LE 12-byte long double to IEEE 754 8 byte double.
+Converts IEEE 754 LE 16-byte long double to i386 LE 12-byte long double .
 
-not yet implemented (throws internal_exception).
+Not yet implemented (throws internal_exception).
+
+=cut
+
+*/
+
+static void
+cvt_num16_num12(ARGOUT(unsigned char *dest), ARGIN(const unsigned char *src))
+{
+    ASSERT_ARGS(cvt_num16_num12)
+    exit_fatal(1, "TODO cvt_num16_num12\n");
+}
+
+
+/*
+
+=item C<static void cvt_num12_num16>
+
+Converts i386 LE 12-byte long double to IEEE 754 LE 16-byte long double.
+
+Not yet implemented (throws internal_exception).
+
+=cut
+
+*/
+
+static void
+cvt_num12_num16(ARGOUT(unsigned char *dest), ARGIN(const unsigned char *src))
+{
+    ASSERT_ARGS(cvt_num12_num16)
+    exit_fatal(1, "TODO cvt_num12_num16\n");
+}
+
+/*
+
+=item C<static void cvt_num16_num8>
+
+Converts IEEE 754 16-byte long double to IEEE 754 8 byte double.
+
+Untested.
 
 =cut
 
@@ -258,26 +357,51 @@
 cvt_num16_num8(ARGOUT(unsigned char *dest), ARGIN(const unsigned char *src))
 {
     ASSERT_ARGS(cvt_num16_num8)
-    exit_fatal(1, "TODO cvt_num16_num8\n");
+    long double d;
+    memcpy(&d, src, 16);
+    *dest = (double)d; /* TODO: test */
 }
 
 /*
 
-=item C<static void cvt_num16_num12>
+=item C<static void cvt_num8_num16>
 
-Converts IEEE 754 LE 16-byte long double to i386 LE 12-byte long double .
+Converts IEEE 754 8-byte double to IEEE 754 16 byte long double.
 
-Not yet implemented (throws internal_exception).
+Untested.
 
 =cut
 
 */
 
 static void
-cvt_num16_num12(ARGOUT(unsigned char *dest), ARGIN(const unsigned char *src))
+cvt_num8_num16(ARGOUT(unsigned char *dest), ARGIN(const unsigned char *src))
 {
-    ASSERT_ARGS(cvt_num16_num12)
-    exit_fatal(1, "TODO cvt_num16_num12\n");
+    ASSERT_ARGS(cvt_num8_num16)
+    double d;
+    memcpy(&d, src, 8);
+    *dest = (long double)d; /* TODO: test */
+}
+
+/*
+
+=item C<static void cvt_num8_num12>
+
+Converts i386 8-byte double to i386 12 byte long double.
+
+Untested.
+
+=cut
+
+*/
+
+static void
+cvt_num8_num12(ARGOUT(unsigned char *dest), ARGIN(const unsigned char *src))
+{
+    ASSERT_ARGS(cvt_num8_num16)
+    double d;
+    memcpy(&d, src, 8);
+    *dest = (long double)d; /* TODO: test */
 }
 
 /*
@@ -286,7 +410,7 @@
 
 Converts a 12-byte i386 long double into a big-endian IEEE 754 8-byte double.
 
-Converting to BE not yet implemented (throws internal_exception).
+Untested.
 
 =cut
 
@@ -302,6 +426,29 @@
     fetch_buf_le_8(dest, b);
 }
 
+
+/*
+
+=item C<static void cvt_num8_num12_be>
+
+Converts a big-endian IEEE 754 8-byte double to i386 LE 12-byte long double.
+
+Untested.
+
+=cut
+
+*/
+
+static void
+cvt_num8_num12_be(ARGOUT(unsigned char *dest), ARGIN(const unsigned char *src))
+{
+    ASSERT_ARGS(cvt_num12_num8_be)
+    unsigned char b[12];
+    cvt_num8_num12(b, src);
+    /* TODO test endianize */
+    fetch_buf_le_8(dest, b);
+}
+
 /*
 
 =item C<static void cvt_num12_num8_le>
@@ -309,6 +456,8 @@
 Converts a 12-byte i386 long double into a little-endian IEEE 754
 8-byte double.
 
+Untested.
+
 =cut
 
 */
@@ -329,7 +478,7 @@
 Converts a IEEE 754 16-byte long double into a little-endian IEEE 754
 8-byte double.
 
-Not yet implemented (throws internal_exception).
+Untested.
 
 =cut
 
@@ -350,7 +499,7 @@
 
 Converts a IEEE 754 16-byte IA64 long double into a big-endian IEEE 754 8-byte double.
 
-Not yet implemented (throws internal_exception).
+Untested.
 
 =cut
 
@@ -367,23 +516,53 @@
 
 /*
 
-=item C<static void cvt_num16_num12_le>
+=item C<static void cvt_num16_num12_be>
 
 Converts a IEEE 754 16-byte BE long double into a 12-byte i386 long double.
 
-Not yet implemented (throws internal_exception).
+Untested.
 
 =cut
 
 */
 
 static void
-cvt_num16_num12_le(ARGOUT(unsigned char *dest), ARGIN(unsigned char *src))
+cvt_num16_num12_be(ARGOUT(unsigned char *dest), ARGIN(const unsigned char *src))
 {
-    ASSERT_ARGS(cvt_num16_num12_le)
+    ASSERT_ARGS(cvt_num16_num12_be)
     unsigned char b[12];
     cvt_num16_num12(b, src);
-    fetch_buf_le_12(dest, b);
+    fetch_buf_be_12(dest, b);
+}
+
+/*
+
+=item C<static void cvt_num8_num16_be>
+
+Converts IEEE 754 8-byte double to IEEE 754 BE 16 byte long double.
+
+Untested.
+
+=cut
+
+*/
+
+static void
+cvt_num8_num16_be(ARGOUT(unsigned char *dest), ARGIN(const unsigned char *src))
+{
+    ASSERT_ARGS(cvt_num8_num16_be)
+    unsigned char b[16];
+    cvt_num8_num16(b, src);
+    fetch_buf_be_16(dest, b);
+}
+
+static void
+cvt_num12_num16_be(ARGOUT(unsigned char *dest), ARGIN(const unsigned char *src))
+{
+    ASSERT_ARGS(cvt_num8_num16_be)
+    unsigned char b[16];
+    cvt_num12_num16(b, src);
+    fetch_buf_be_16(dest, b);
 }
 
 /*
@@ -1091,51 +1270,76 @@
         else
             pf->fetch_op = fetch_op_le_8;
 
-        if (pf->header->floattype == FLOATTYPE_8 && NUMVAL_SIZE == 8)
+        switch (pf->header->floattype) {
+#  if NUMVAL_SIZE == 8
+          case FLOATTYPE_8:
             pf->fetch_nv = fetch_buf_le_8;
-        else if (pf->header->floattype == FLOATTYPE_12 && NUMVAL_SIZE == 12)
-            pf->fetch_nv = fetch_buf_le_12;
-        else if (pf->header->floattype == FLOATTYPE_16 && NUMVAL_SIZE == 16)
-            pf->fetch_nv = fetch_buf_le_16;
-        else if (pf->header->floattype == FLOATTYPE_12 && NUMVAL_SIZE == 8)
+            break;
+          case FLOATTYPE_12:
             pf->fetch_nv = cvt_num12_num8_le;
-        else if (pf->header->floattype == FLOATTYPE_16 && NUMVAL_SIZE == 12)
-            pf->fetch_nv = cvt_num16_num12_le;
-        else if (pf->header->floattype == FLOATTYPE_16 && NUMVAL_SIZE == 8)
+            break;
+          case FLOATTYPE_16:
             pf->fetch_nv = cvt_num16_num8_le;
-        else
+            break;
+#  endif
+#  if NUMVAL_SIZE == 16
+          case FLOATTYPE_8:
+            pf->fetch_nv = cvt_num8_num16_le;
+            break;
+          case FLOATTYPE_12:
+            pf->fetch_nv = cvt_num12_num16_le;
+            break;
+          case FLOATTYPE_16:
+            pf->fetch_nv = fetch_buf_le_16;
+            break;
+#  endif
+          default:
             exit_fatal(1,
-              "PackFile_unpack: unsupported float conversion %d to %d, PARROT_BIGENDIAN=%d\n",
+              "PackFile_unpack: unsupported float conversion %d to %d, "
+              "PARROT_BIGENDIAN=%d\n",
               NUMVAL_SIZE, pf->header->floattype, PARROT_BIGENDIAN);
-        return 0;
+            break;
+        }
+        return;
     }
-    else {
+    else {  /* no need_endianize */
         if (pf->header->wordsize == 4)
             pf->fetch_op = fetch_op_be_4;
         else
             pf->fetch_op = fetch_op_be_8;
 
-        if (pf->header->floattype == FLOATTYPE_8 && NUMVAL_SIZE == 8)
-            pf->fetch_nv = fetch_buf_be_8;
-        else if (pf->header->floattype == FLOATTYPE_12 && NUMVAL_SIZE == 12)
-            pf->fetch_nv = fetch_buf_be_12;
-        else if (pf->header->floattype == FLOATTYPE_16 && NUMVAL_SIZE == 16)
-            pf->fetch_nv = fetch_buf_be_16;
-        else if (pf->header->floattype == FLOATTYPE_12 && NUMVAL_SIZE == 8)
+        switch (pf->header->floattype) {
+#  if NUMVAL_SIZE == 8
+          case FLOATTYPE_8:
+            break;
+          case FLOATTYPE_12:
             pf->fetch_nv = cvt_num12_num8;
-        else if (pf->header->floattype == FLOATTYPE_16 && NUMVAL_SIZE == 12)
-            pf->fetch_nv = cvt_num16_num12;
-        else if (pf->header->floattype == FLOATTYPE_16 && NUMVAL_SIZE == 8)
+            break;
+          case FLOATTYPE_16:
             pf->fetch_nv = cvt_num16_num8;
-        else {
+            break;
+#  endif
+#  if NUMVAL_SIZE == 16
+          case FLOATTYPE_8:
+            pf->fetch_nv = cvt_num8_num16;
+            break;
+          case FLOATTYPE_12:
+            pf->fetch_nv = cvt_num12_num16;
+            break;
+          case FLOATTYPE_16:
+            break;
+#  endif
+          default:
             exit_fatal(1,
-                       "PackFile_unpack: unsupported float conversion %d to %d,"
-                       " PARROT_BIGENDIAN=%d\n", NUMVAL_SIZE,
-                       pf->header->floattype, PARROT_BIGENDIAN);
+              "PackFile_unpack: unsupported float conversion %d to %d, "
+              "PARROT_BIGENDIAN=%d\n",
+              NUMVAL_SIZE, pf->header->floattype, PARROT_BIGENDIAN);
+            break;
         }
+        return;
     }
 
-#else
+#else  /* ENDIAN */
 
     pf->fetch_iv = pf->fetch_op;
     /* this Parrot is on a LITTLE ENDIAN machine */
@@ -1145,21 +1349,48 @@
         else
             pf->fetch_op = fetch_op_be_8;
 
-        if (pf->header->floattype == FLOATTYPE_8 && NUMVAL_SIZE == 8)
+        switch (pf->header->floattype) {
+#  if NUMVAL_SIZE == 8
+          case FLOATTYPE_8:
             pf->fetch_nv = fetch_buf_be_8;
-        else if (pf->header->floattype == FLOATTYPE_16 && NUMVAL_SIZE == 16)
-            pf->fetch_nv = fetch_buf_be_16;
-        else if (pf->header->floattype == FLOATTYPE_12 && NUMVAL_SIZE == 8)
+            break;
+          case FLOATTYPE_12:
             pf->fetch_nv = cvt_num12_num8_be;
-        else if (pf->header->floattype == FLOATTYPE_16 && NUMVAL_SIZE == 8)
+            break;
+          case FLOATTYPE_16:
             pf->fetch_nv = cvt_num16_num8_be;
-        else {
+            break;
+#  endif
+#  if NUMVAL_SIZE == 12
+          case FLOATTYPE_8:
+            pf->fetch_nv = cvt_num8_num12_be;
+            break;
+          case FLOATTYPE_12:
+            pf->fetch_nv = fetch_buf_be_12;
+            break;
+          case FLOATTYPE_16:
+            pf->fetch_nv = cvt_num16_num12_be;
+            break;
+#  endif
+#  if NUMVAL_SIZE == 16
+          case FLOATTYPE_8:
+            pf->fetch_nv = cvt_num8_num16_be;
+            break;
+          case FLOATTYPE_12:
+            pf->fetch_nv = cvt_num12_num16_be;
+            break;
+          case FLOATTYPE_16:
+            pf->fetch_nv = fetch_buf_be_16;
+            break;
+#  endif
+          default:
             exit_fatal(1,
-                       "PackFile_unpack: unsupported float conversion %d to %d,"
-                       " PARROT_BIGENDIAN=%d\n", NUMVAL_SIZE,
-                       pf->header->floattype, PARROT_BIGENDIAN);
-            return;
+              "PackFile_unpack: unsupported float conversion %d to %d, "
+              "PARROT_BIGENDIAN=%d\n",
+              NUMVAL_SIZE, pf->header->floattype, PARROT_BIGENDIAN);
+            break;
         }
+        return;
     }
     else {
         if (pf->header->wordsize == 4)
@@ -1167,24 +1398,45 @@
         else
             pf->fetch_op = fetch_op_le_8;
 
-        if (pf->header->floattype == FLOATTYPE_8 && NUMVAL_SIZE == 8)
-            pf->fetch_nv = fetch_buf_le_8;
-        else if (pf->header->floattype == FLOATTYPE_12 && NUMVAL_SIZE == 12)
-            pf->fetch_nv = fetch_buf_le_12;
-        else if (pf->header->floattype == FLOATTYPE_16 && NUMVAL_SIZE == 16)
-            pf->fetch_nv = fetch_buf_le_16;
-        else if (pf->header->floattype == FLOATTYPE_12 && NUMVAL_SIZE == 8)
+        switch (pf->header->floattype) {
+#  if NUMVAL_SIZE == 8
+          case FLOATTYPE_8:
+            break;
+          case FLOATTYPE_12:
             pf->fetch_nv = cvt_num12_num8;
-        else if (pf->header->floattype == FLOATTYPE_16 && NUMVAL_SIZE == 12)
-            pf->fetch_nv = cvt_num16_num12;
-        else if (pf->header->floattype == FLOATTYPE_16 && NUMVAL_SIZE == 8)
+            break;
+          case FLOATTYPE_16:
             pf->fetch_nv = cvt_num16_num8;
-        else {
+            break;
+#  endif
+#  if NUMVAL_SIZE == 12
+          case FLOATTYPE_8:
+            pf->fetch_nv = cvt_num8_num12;
+            break;
+          case FLOATTYPE_12:
+            break;
+          case FLOATTYPE_16:
+            pf->fetch_nv = cvt_num16_num12;
+            break;
+#  endif
+#  if NUMVAL_SIZE == 16
+          case FLOATTYPE_8:
+            pf->fetch_nv = cvt_num8_num16;
+            break;
+          case FLOATTYPE_12:
+            pf->fetch_nv = cvt_num12_num16;
+            break;
+          case FLOATTYPE_16:
+            break;
+#  endif
+          default:
             exit_fatal(1,
-                       "PackFile_unpack: unsupported float conversion %d to %d,"
-                       " PARROT_BIGENDIAN=%d\n", NUMVAL_SIZE,
-                       pf->header->floattype, PARROT_BIGENDIAN);
+              "PackFile_unpack: unsupported float conversion %d to %d, "
+              "PARROT_BIGENDIAN=%d\n",
+              NUMVAL_SIZE, pf->header->floattype, PARROT_BIGENDIAN);
+            break;
         }
+        return;
     }
 #endif
 }


More information about the parrot-commits mailing list