Commits

Anonymous committed e5be468

Codes speciaux pour petits tableaux de flottants.
Nettoyage du magic number.

git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@165f963ae5c-01c2-4b8c-9fe0-0dff7051ff02

Comments (0)

Files changed (3)

         if (sizeof(double) != 8)
           invalid_argument("output_value: non-standard floats");
         nfloats = Wosize_val(v) / Double_wosize;
-        output32(chan, CODE_DOUBLE_ARRAY_NATIVE, nfloats);
+        if (nfloats < 0x100) {
+          output8(chan, CODE_DOUBLE_ARRAY8_NATIVE, nfloats);
+        } else {
+          output32(chan, CODE_DOUBLE_ARRAY32_NATIVE, nfloats);
+        }
         putblock(chan, (char *) v, Bosize_val(v));
         size_32 += 1 + nfloats * 2;
         size_64 += 1 + nfloats;
      value v;
 {
   value start_loc, final_loc;
-  putword(chan, Compact_magic_number);
+  putword(chan, Intext_magic_number);
   start_loc = pos_out(chan);
   putword(chan, 0);
   putword(chan, 0);
         really_getblock(chan, (char *) v, 8);
         if (code != CODE_DOUBLE_NATIVE) Reverse_double(v);
         break;
-      case CODE_DOUBLE_ARRAY_LITTLE:
-      case CODE_DOUBLE_ARRAY_BIG:
+      case CODE_DOUBLE_ARRAY8_LITTLE:
+      case CODE_DOUBLE_ARRAY8_BIG:
+        len = input8u(chan);
+      read_double_array:
         if (sizeof(double) != 8) {
           stat_free((char *) intern_obj_table);
           Hd_val(intern_block) = intern_header; /* Don't confuse the GC */
           invalid_argument("input_value: non-standard floats");
         }
-        len = input32u(chan);
         size = len * Double_wosize;
         v = Val_hp(intern_ptr);
         intern_obj_table[obj_counter++] = v;
         *intern_ptr = Make_header(size, Double_array_tag, intern_color);
         intern_ptr += 1 + size;
         really_getblock(chan, (char *) v, len * 8);
-        if (code != CODE_DOUBLE_NATIVE) {
+        if (code != CODE_DOUBLE_ARRAY8_NATIVE && 
+            code != CODE_DOUBLE_ARRAY32_NATIVE) {
           mlsize_t i;
           for (i = 0; i < len; i++) Reverse_double((value)((double *)v + i));
         }
         break;
+      case CODE_DOUBLE_ARRAY32_LITTLE:
+      case CODE_DOUBLE_ARRAY32_BIG:
+        len = input32u(chan);
+        goto read_double_array;
       }
     }
   }
   value res;
 
   magic = getword(chan);
-  if (magic != Compact_magic_number) failwith("input_value: bad object");
+  if (magic != Intext_magic_number) failwith("input_value: bad object");
   num_objects = getword(chan);
   size_32 = getword(chan);
   size_64 = getword(chan);
 
 /* Magic number */
 
-#define Base_magic_number 0x8495A6B9
-#define Compact_magic_number (Base_magic_number + 4)
+#define Intext_magic_number 0x8495A6BD
 
 /* Codes for the compact format */
 
 #define CODE_STRING32 0xA
 #define CODE_DOUBLE_BIG 0xB
 #define CODE_DOUBLE_LITTLE 0xC
+#define CODE_DOUBLE_ARRAY8_BIG 0xD
+#define CODE_DOUBLE_ARRAY8_LITTLE 0xE
+#define CODE_DOUBLE_ARRAY32_BIG 0xF
+#define CODE_DOUBLE_ARRAY32_LITTLE 0x7
+
 #ifdef BIG_ENDIAN
 #define CODE_DOUBLE_NATIVE CODE_DOUBLE_BIG
+#define CODE_DOUBLE_ARRAY8_NATIVE CODE_DOUBLE_ARRAY8_BIG
+#define CODE_DOUBLE_ARRAY32_NATIVE CODE_DOUBLE_ARRAY32_BIG
 #else
 #define CODE_DOUBLE_NATIVE CODE_DOUBLE_LITTLE
-#endif
-#define CODE_DOUBLE_ARRAY_BIG 0xD
-#define CODE_DOUBLE_ARRAY_LITTLE 0xE
-#ifdef BIG_ENDIAN
-#define CODE_DOUBLE_ARRAY_NATIVE CODE_DOUBLE_ARRAY_BIG
-#else
-#define CODE_DOUBLE_ARRAY_NATIVE CODE_DOUBLE_ARRAY_LITTLE
+#define CODE_DOUBLE_ARRAY8_NATIVE CODE_DOUBLE_ARRAY8_LITTLE
+#define CODE_DOUBLE_ARRAY32_NATIVE CODE_DOUBLE_ARRAY32_LITTLE
 #endif
 
 /* Initial sizes of data structures for extern */