Skip to content
This repository
Browse code

Eliminated packfile/byteorder.h and put the static functions in it in…

… packfile/pf_items.c. This is part GitHub #728 #728
  • Loading branch information...
commit 4cb2d3bbbc26485392f00f5a857cf9334d91f47b 1 parent ffed5f6
Andy Lester authored March 05, 2012
1  MANIFEST
@@ -1279,7 +1279,6 @@ src/ops/string.ops                                          []
1279 1279
 src/ops/sys.ops                                             []
1280 1280
 src/ops/var.ops                                             []
1281 1281
 src/packfile/api.c                                          []
1282  
-src/packfile/byteorder.h                                    []
1283 1282
 src/packfile/object_serialization.c                         []
1284 1283
 src/packfile/output.c                                       []
1285 1284
 src/packfile/pf_items.c                                     []
3  config/gen/makefiles/root.in
... ...
@@ -1,4 +1,4 @@
1  
-# Copyright (C) 2001-2011, Parrot Foundation.
  1
+# Copyright (C) 2001-2012, Parrot Foundation.
2 2
 
3 3
 ###############################################################################
4 4
 #
@@ -1682,7 +1682,6 @@ src/packfile/output$(O) : \
1682 1682
 
1683 1683
 src/packfile/pf_items$(O) : \
1684 1684
 	$(PARROT_H_HEADERS) \
1685  
-	src/packfile/byteorder.h \
1686 1685
 	src/packfile/pf_items.str \
1687 1686
 	src/packfile/pf_items.c
1688 1687
 
571  src/packfile/byteorder.h
... ...
@@ -1,571 +0,0 @@
1  
-/*
2  
-Copyright (C) 2001-2009, Parrot Foundation.
3  
-
4  
-=head1 NAME
5  
-
6  
-src/byteorder.c - Byteordering functions
7  
-
8  
-=head1 DESCRIPTION
9  
-
10  
-These are assigned to a vtable when the PBC file is loaded.
11  
-
12  
-If the vtable function for conversion from the native byteorder is called,
13  
-it is a I<no op> and will work, but the caller should know if the
14  
-byteorder in the PBC file is native and skip the conversion and just map
15  
-it in.
16  
-
17  
-=head2 Byte order handlers
18  
-
19  
-Configure will have checked for supported word sizes.
20  
-
21  
-=over 4
22  
-
23  
-=cut
24  
-
25  
-*/
26  
-
27  
-#ifndef PARROT_BYTEORDER_H_GUARD
28  
-#define PARROT_BYTEORDER_H_GUARD
29  
-
30  
-#include "parrot/parrot.h"
31  
-
32  
-/* HEADERIZER HFILE: none */
33  
-
34  
-/*
35  
-
36  
-=item C<static INTVAL fetch_iv_le(INTVAL w)>
37  
-
38  
-This function converts a 4 or 8 byte C<INTVAL> into little endian
39  
-format. If the native format is already little endian, then no
40  
-conversion is done.
41  
-
42  
-=cut
43  
-
44  
-*/
45  
-
46  
-PARROT_INLINE
47  
-PARROT_WARN_UNUSED_RESULT
48  
-PARROT_CONST_FUNCTION
49  
-static INTVAL
50  
-fetch_iv_le(INTVAL w)
51  
-{
52  
-#if !PARROT_BIGENDIAN
53  
-    return w;
54  
-#else
55  
-#  if INTVAL_SIZE == 4
56  
-    return (w << 24) | ((w & 0xff00) << 8) | ((w & 0xff0000) >> 8) | (w >> 24);
57  
-#  else
58  
-#    if INTVAL_SIZE == 8
59  
-    INTVAL r;
60  
-
61  
-    r = w << 56;
62  
-    r |= (w & 0xff00) << 40;
63  
-    r |= (w & 0xff0000) << 24;
64  
-    r |= (w & 0xff000000) << 8;
65  
-    r |= (w & 0xff00000000) >> 8;
66  
-    r |= (w & 0xff0000000000) >> 24;
67  
-    r |= (w & 0xff000000000000) >> 40;
68  
-    r |= (w & 0xff00000000000000) >> 56;
69  
-    return r;
70  
-#    else
71  
-    exit_fatal(1, "Unsupported INTVAL_SIZE=%d\n",
72  
-               INTVAL_SIZE);
73  
-#    endif
74  
-#  endif
75  
-#endif
76  
-}
77  
-
78  
-/*
79  
-
80  
-=item C<static INTVAL fetch_iv_be(INTVAL w)>
81  
-
82  
-This function converts a 4 or 8 byte C<INTVAL> into big endian format.
83  
-If the native format is already big endian, then no conversion is done.
84  
-
85  
-=cut
86  
-
87  
-*/
88  
-
89  
-PARROT_INLINE
90  
-PARROT_WARN_UNUSED_RESULT
91  
-PARROT_CONST_FUNCTION
92  
-static INTVAL
93  
-fetch_iv_be(INTVAL w)
94  
-{
95  
-#if PARROT_BIGENDIAN
96  
-    return w;
97  
-#else
98  
-#  if INTVAL_SIZE == 4
99  
-    return (w << 24) | ((w & 0xff00) << 8) | ((w & 0xff0000) >> 8) | (w >> 24);
100  
-#  else
101  
-#    if INTVAL_SIZE == 8
102  
-    INTVAL r;
103  
-    r = w << 56;
104  
-    r |= (w & 0xff00) << 40;
105  
-    r |= (w & 0xff0000) << 24;
106  
-    r |= (w & 0xff000000) << 8;
107  
-    r |= (w & 0xff00000000) >> 8;
108  
-    r |= (w & 0xff0000000000) >> 24;
109  
-    r |= (w & 0xff000000000000) >> 40;
110  
-    r |= (w & 0xff00000000000000) >> 56;
111  
-    return r;
112  
-#    else
113  
-    exit_fatal(1, "Unsupported INTVAL_SIZE=%d\n",
114  
-               INTVAL_SIZE);
115  
-#    endif
116  
-#  endif
117  
-#endif
118  
-}
119  
-
120  
-/*
121  
-
122  
-=item C<static opcode_t fetch_op_be(opcode_t w)>
123  
-
124  
-Same as C<fetch_iv_be> for opcode_t
125  
-
126  
-=cut
127  
-
128  
-*/
129  
-
130  
-PARROT_INLINE
131  
-PARROT_WARN_UNUSED_RESULT
132  
-PARROT_CONST_FUNCTION
133  
-static opcode_t
134  
-fetch_op_be(opcode_t w)
135  
-{
136  
-#if PARROT_BIGENDIAN
137  
-    return w;
138  
-#else
139  
-#  if OPCODE_T_SIZE == 4
140  
-    return (w << 24) | ((w & 0x0000ff00) << 8) | ((w & 0x00ff0000) >> 8) |
141  
-        ((w & 0xff000000) >> 24);
142  
-#  else
143  
-    opcode_t r;
144  
-
145  
-    r = w << 56;
146  
-    r |= (w & 0xff00) << 40;
147  
-    r |= (w & 0xff0000) << 24;
148  
-    r |= (w & 0xff000000) << 8;
149  
-    r |= (w & 0xff00000000) >> 8;
150  
-    r |= (w & 0xff0000000000) >> 24;
151  
-    r |= (w & 0xff000000000000) >> 40;
152  
-    r |= (w & 0xff00000000000000) >> 56;
153  
-    return r;
154  
-#  endif
155  
-#endif
156  
-}
157  
-
158  
-/*
159  
-
160  
-=item C<static opcode_t fetch_op_le(opcode_t w)>
161  
-
162  
-Same as C<fetch_iv_le> for opcode_t
163  
-
164  
-=cut
165  
-
166  
-*/
167  
-
168  
-PARROT_INLINE
169  
-PARROT_WARN_UNUSED_RESULT
170  
-PARROT_CONST_FUNCTION
171  
-static opcode_t
172  
-fetch_op_le(opcode_t w)
173  
-{
174  
-#if !PARROT_BIGENDIAN
175  
-    return w;
176  
-#else
177  
-#  if OPCODE_T_SIZE == 4
178  
-    return (w << 24) | ((w & 0x0000ff00) << 8) | ((w & 0x00ff0000) >> 8) |
179  
-        ((w & 0xff000000) >> 24);
180  
-#  else
181  
-    opcode_t r;
182  
-
183  
-    r = w << 56;
184  
-    r |= (w & 0xff00) << 40;
185  
-    r |= (w & 0xff0000) << 24;
186  
-    r |= (w & 0xff000000) << 8;
187  
-    r |= (w & 0xff00000000) >> 8;
188  
-    r |= (w & 0xff0000000000) >> 24;
189  
-    r |= (w & 0xff000000000000) >> 40;
190  
-    r |= (w & 0xff00000000000000) >> 56;
191  
-    return r;
192  
-#  endif
193  
-#endif
194  
-}
195  
-
196  
-/*
197  
-
198  
-=pod
199  
-
200  
-Unrolled routines for swapping various sizes from 32-128 bits. These
201  
-should only be used if alignment is unknown or we are pulling something
202  
-out of a padded buffer.
203  
-
204  
-=cut
205  
-
206  
-*/
207  
-
208  
-/*
209  
-
210  
-=item C<static void fetch_buf_be_4(unsigned char *rb, const unsigned char *b)>
211  
-
212  
-Converts a 4-byte big-endian buffer C<b> into a little-endian C<rb>.
213  
-
214  
-=cut
215  
-
216  
-*/
217  
-
218  
-PARROT_INLINE
219  
-static void
220  
-fetch_buf_be_4(ARGOUT(unsigned char *rb), ARGIN(const unsigned char *b))
221  
-{
222  
-#if PARROT_BIGENDIAN
223  
-    memcpy(rb, b, 4);
224  
-#else
225  
-    rb[0] = b[3];
226  
-    rb[1] = b[2];
227  
-    rb[2] = b[1];
228  
-    rb[3] = b[0];
229  
-#endif
230  
-}
231  
-
232  
-/*
233  
-
234  
-=item C<static void fetch_buf_le_4(unsigned char *rb, const unsigned char *b)>
235  
-
236  
-Converts a 4-byte little-endian buffer C<b> into a big-endian buffer C<rb>.
237  
-
238  
-=cut
239  
-
240  
-*/
241  
-
242  
-PARROT_INLINE
243  
-static void
244  
-fetch_buf_le_4(ARGOUT(unsigned char *rb), ARGIN(const unsigned char *b))
245  
-{
246  
-#if !PARROT_BIGENDIAN
247  
-    memcpy(rb, b, 4);
248  
-#else
249  
-    rb[0] = b[3];
250  
-    rb[1] = b[2];
251  
-    rb[2] = b[1];
252  
-    rb[3] = b[0];
253  
-#endif
254  
-}
255  
-
256  
-/*
257  
-
258  
-=item C<static void fetch_buf_be_8(unsigned char *rb, const unsigned char *b)>
259  
-
260  
-Converts an 8-byte big-endian buffer C<b> into a little-endian buffer C<rb>
261  
-
262  
-=cut
263  
-
264  
-*/
265  
-
266  
-PARROT_INLINE
267  
-static void
268  
-fetch_buf_be_8(ARGOUT(unsigned char *rb), ARGIN(const unsigned char *b))
269  
-{
270  
-#if PARROT_BIGENDIAN
271  
-    memcpy(rb, b, 8);
272  
-#else
273  
-    rb[0] = b[7];
274  
-    rb[1] = b[6];
275  
-    rb[2] = b[5];
276  
-    rb[3] = b[4];
277  
-    rb[4] = b[3];
278  
-    rb[5] = b[2];
279  
-    rb[6] = b[1];
280  
-    rb[7] = b[0];
281  
-#endif
282  
-}
283  
-
284  
-/*
285  
-
286  
-=item C<static void fetch_buf_le_8(unsigned char *rb, const unsigned char *b)>
287  
-
288  
-Converts an 8-byte little-endian buffer C<b> into a big-endian buffer C<rb>.
289  
-
290  
-=cut
291  
-
292  
-*/
293  
-
294  
-PARROT_INLINE
295  
-static void
296  
-fetch_buf_le_8(ARGOUT(unsigned char *rb), ARGIN(const unsigned char *b))
297  
-{
298  
-#if !PARROT_BIGENDIAN
299  
-    memcpy(rb, b, 8);
300  
-#else
301  
-    rb[0] = b[7];
302  
-    rb[1] = b[6];
303  
-    rb[2] = b[5];
304  
-    rb[3] = b[4];
305  
-    rb[4] = b[3];
306  
-    rb[5] = b[2];
307  
-    rb[6] = b[1];
308  
-    rb[7] = b[0];
309  
-#endif
310  
-}
311  
-
312  
-/*
313  
-
314  
-=item C<static void fetch_buf_le_12(unsigned char *rb, const unsigned char *b)>
315  
-
316  
-Converts a 12-byte little-endian buffer C<b> into a big-endian buffer C<b>.
317  
-
318  
-=cut
319  
-
320  
-*/
321  
-
322  
-PARROT_INLINE
323  
-static void
324  
-fetch_buf_le_12(ARGOUT(unsigned char *rb), ARGIN(const unsigned char *b))
325  
-{
326  
-#if !PARROT_BIGENDIAN
327  
-    memcpy(rb, b, 12);
328  
-#else
329  
-    rb[0] = b[11];
330  
-    rb[1] = b[10];
331  
-    rb[2] = b[9];
332  
-    rb[3] = b[8];
333  
-    rb[4] = b[7];
334  
-    rb[5] = b[6];
335  
-    rb[6] = b[5];
336  
-    rb[7] = b[4];
337  
-    rb[8] = b[3];
338  
-    rb[9] = b[2];
339  
-    rb[10] = b[1];
340  
-    rb[11] = b[0];
341  
-#endif
342  
-}
343  
-
344  
-/*
345  
-
346  
-=item C<static void fetch_buf_be_12(unsigned char *rb, const unsigned char *b)>
347  
-
348  
-Converts a 12-byte big-endian buffer C<b> into a little-endian buffer C<b>.
349  
-
350  
-=cut
351  
-
352  
-*/
353  
-
354  
-PARROT_INLINE
355  
-static void
356  
-fetch_buf_be_12(ARGOUT(unsigned char *rb), ARGIN(const unsigned char *b))
357  
-{
358  
-#if PARROT_BIGENDIAN
359  
-    memcpy(rb, b, 12);
360  
-#else
361  
-    rb[0] = b[11];
362  
-    rb[1] = b[10];
363  
-    rb[2] = b[9];
364  
-    rb[3] = b[8];
365  
-    rb[4] = b[7];
366  
-    rb[5] = b[6];
367  
-    rb[6] = b[5];
368  
-    rb[7] = b[4];
369  
-    rb[8] = b[3];
370  
-    rb[9] = b[2];
371  
-    rb[10] = b[1];
372  
-    rb[11] = b[0];
373  
-#endif
374  
-}
375  
-
376  
-/*
377  
-
378  
-=item C<static void fetch_buf_le_16(unsigned char *rb, const unsigned char *b)>
379  
-
380  
-Converts a 16-byte little-endian buffer C<b> into a big-endian buffer C<b>.
381  
-
382  
-=cut
383  
-
384  
-*/
385  
-
386  
-PARROT_INLINE
387  
-static void
388  
-fetch_buf_le_16(ARGOUT(unsigned char *rb), ARGIN(const unsigned char *b))
389  
-{
390  
-#if !PARROT_BIGENDIAN
391  
-    memcpy(rb, b, 16);
392  
-#else
393  
-    rb[0] = b[15];
394  
-    rb[1] = b[14];
395  
-    rb[2] = b[13];
396  
-    rb[3] = b[12];
397  
-    rb[4] = b[11];
398  
-    rb[5] = b[10];
399  
-    rb[6] = b[9];
400  
-    rb[7] = b[8];
401  
-    rb[8] = b[7];
402  
-    rb[9] = b[6];
403  
-    rb[10] = b[5];
404  
-    rb[11] = b[4];
405  
-    rb[12] = b[3];
406  
-    rb[13] = b[2];
407  
-    rb[14] = b[1];
408  
-    rb[15] = b[0];
409  
-#endif
410  
-}
411  
-
412  
-/*
413  
-
414  
-=item C<static void fetch_buf_be_16(unsigned char *rb, const unsigned char *b)>
415  
-
416  
-Converts a 16-byte big-endian buffer C<b> into a little-endian buffer C<b>.
417  
-
418  
-=cut
419  
-
420  
-*/
421  
-
422  
-PARROT_INLINE
423  
-static void
424  
-fetch_buf_be_16(ARGOUT(unsigned char *rb), ARGIN(const unsigned char *b))
425  
-{
426  
-#if PARROT_BIGENDIAN
427  
-    memcpy(rb, b, 16);
428  
-#else
429  
-    rb[0] = b[15];
430  
-    rb[1] = b[14];
431  
-    rb[2] = b[13];
432  
-    rb[3] = b[12];
433  
-    rb[4] = b[11];
434  
-    rb[5] = b[10];
435  
-    rb[6] = b[9];
436  
-    rb[7] = b[8];
437  
-    rb[8] = b[7];
438  
-    rb[9] = b[6];
439  
-    rb[10] = b[5];
440  
-    rb[11] = b[4];
441  
-    rb[12] = b[3];
442  
-    rb[13] = b[2];
443  
-    rb[14] = b[1];
444  
-    rb[15] = b[0];
445  
-#endif
446  
-}
447  
-
448  
-/*
449  
-
450  
-=item C<static void fetch_buf_le_32(unsigned char *rb, const unsigned char *b)>
451  
-
452  
-Converts a 32-byte little-endian buffer C<b> into a big-endian buffer C<b>.
453  
-
454  
-=cut
455  
-
456  
-*/
457  
-
458  
-PARROT_INLINE
459  
-static void
460  
-fetch_buf_le_32(ARGOUT(unsigned char *rb), ARGIN(const unsigned char *b))
461  
-{
462  
-#if !PARROT_BIGENDIAN
463  
-    memcpy(rb, b, 32);
464  
-#else
465  
-    rb[0] = b[31];
466  
-    rb[1] = b[30];
467  
-    rb[2] = b[29];
468  
-    rb[3] = b[28];
469  
-    rb[4] = b[27];
470  
-    rb[5] = b[26];
471  
-    rb[6] = b[25];
472  
-    rb[7] = b[24];
473  
-    rb[8] = b[23];
474  
-    rb[9] = b[22];
475  
-    rb[10] = b[21];
476  
-    rb[11] = b[20];
477  
-    rb[12] = b[19];
478  
-    rb[13] = b[18];
479  
-    rb[14] = b[17];
480  
-    rb[15] = b[16];
481  
-    rb[16] = b[15];
482  
-    rb[17] = b[14];
483  
-    rb[18] = b[13];
484  
-    rb[19] = b[12];
485  
-    rb[20] = b[11];
486  
-    rb[21] = b[10];
487  
-    rb[22] = b[9];
488  
-    rb[23] = b[8];
489  
-    rb[24] = b[7];
490  
-    rb[25] = b[6];
491  
-    rb[26] = b[5];
492  
-    rb[27] = b[4];
493  
-    rb[28] = b[3];
494  
-    rb[29] = b[2];
495  
-    rb[30] = b[1];
496  
-    rb[31] = b[0];
497  
-#endif
498  
-}
499  
-
500  
-/*
501  
-
502  
-=item C<static void fetch_buf_be_32(unsigned char *rb, const unsigned char *b)>
503  
-
504  
-Converts a 32-byte big-endian buffer C<b> into a little-endian buffer C<b>.
505  
-
506  
-=cut
507  
-
508  
-*/
509  
-
510  
-PARROT_INLINE
511  
-static void
512  
-fetch_buf_be_32(ARGOUT(unsigned char *rb), ARGIN(const unsigned char *b))
513  
-{
514  
-#if PARROT_BIGENDIAN
515  
-    memcpy(rb, b, 32);
516  
-#else
517  
-    rb[0] = b[31];
518  
-    rb[1] = b[30];
519  
-    rb[2] = b[29];
520  
-    rb[3] = b[28];
521  
-    rb[4] = b[27];
522  
-    rb[5] = b[26];
523  
-    rb[6] = b[25];
524  
-    rb[7] = b[24];
525  
-    rb[8] = b[23];
526  
-    rb[9] = b[22];
527  
-    rb[10] = b[21];
528  
-    rb[11] = b[20];
529  
-    rb[12] = b[19];
530  
-    rb[13] = b[18];
531  
-    rb[14] = b[17];
532  
-    rb[15] = b[16];
533  
-    rb[16] = b[15];
534  
-    rb[17] = b[14];
535  
-    rb[18] = b[13];
536  
-    rb[19] = b[12];
537  
-    rb[20] = b[11];
538  
-    rb[21] = b[10];
539  
-    rb[22] = b[9];
540  
-    rb[23] = b[8];
541  
-    rb[24] = b[7];
542  
-    rb[25] = b[6];
543  
-    rb[26] = b[5];
544  
-    rb[27] = b[4];
545  
-    rb[28] = b[3];
546  
-    rb[29] = b[2];
547  
-    rb[30] = b[1];
548  
-    rb[31] = b[0];
549  
-#endif
550  
-}
551  
-
552  
-#endif /* PARROT_BYTEORDER_H_GUARD */
553  
-
554  
-/*
555  
-
556  
-=back
557  
-
558  
-=head1 HISTORY
559  
-
560  
-Initial version by Melvin on 2002/05/01
561  
-
562  
-=cut
563  
-
564  
-*/
565  
-
566  
-/*
567  
- * Local variables:
568  
- *   c-file-style: "parrot"
569  
- * End:
570  
- * vim: expandtab shiftwidth=4 cinoptions='\:2=2' :
571  
- */
660  src/packfile/pf_items.c
... ...
@@ -1,5 +1,5 @@
1 1
 /*
2  
-Copyright (C) 2001-2010, Parrot Foundation.
  2
+Copyright (C) 2001-2012, Parrot Foundation.
3 3
 
4 4
 =head1 NAME
5 5
 
@@ -32,7 +32,6 @@ for "little endian".
32 32
 */
33 33
 
34 34
 #include "parrot/parrot.h"
35  
-#include "byteorder.h"
36 35
 #include "pf_items.str"
37 36
 
38 37
 /* HEADERIZER HFILE: include/parrot/packfile.h */
@@ -138,6 +137,101 @@ static void cvt_num8_num16_le(
138 137
         __attribute__nonnull__(2)
139 138
         FUNC_MODIFIES(*dest);
140 139
 
  140
+PARROT_INLINE
  141
+static void fetch_buf_be_12(
  142
+    ARGOUT(unsigned char *rb),
  143
+    ARGIN(const unsigned char *b))
  144
+        __attribute__nonnull__(1)
  145
+        __attribute__nonnull__(2)
  146
+        FUNC_MODIFIES(*rb);
  147
+
  148
+PARROT_INLINE
  149
+static void fetch_buf_be_16(
  150
+    ARGOUT(unsigned char *rb),
  151
+    ARGIN(const unsigned char *b))
  152
+        __attribute__nonnull__(1)
  153
+        __attribute__nonnull__(2)
  154
+        FUNC_MODIFIES(*rb);
  155
+
  156
+PARROT_INLINE
  157
+static void fetch_buf_be_32(
  158
+    ARGOUT(unsigned char *rb),
  159
+    ARGIN(const unsigned char *b))
  160
+        __attribute__nonnull__(1)
  161
+        __attribute__nonnull__(2)
  162
+        FUNC_MODIFIES(*rb);
  163
+
  164
+PARROT_INLINE
  165
+static void fetch_buf_be_4(
  166
+    ARGOUT(unsigned char *rb),
  167
+    ARGIN(const unsigned char *b))
  168
+        __attribute__nonnull__(1)
  169
+        __attribute__nonnull__(2)
  170
+        FUNC_MODIFIES(*rb);
  171
+
  172
+PARROT_INLINE
  173
+static void fetch_buf_be_8(
  174
+    ARGOUT(unsigned char *rb),
  175
+    ARGIN(const unsigned char *b))
  176
+        __attribute__nonnull__(1)
  177
+        __attribute__nonnull__(2)
  178
+        FUNC_MODIFIES(*rb);
  179
+
  180
+PARROT_INLINE
  181
+static void fetch_buf_le_12(
  182
+    ARGOUT(unsigned char *rb),
  183
+    ARGIN(const unsigned char *b))
  184
+        __attribute__nonnull__(1)
  185
+        __attribute__nonnull__(2)
  186
+        FUNC_MODIFIES(*rb);
  187
+
  188
+PARROT_INLINE
  189
+static void fetch_buf_le_16(
  190
+    ARGOUT(unsigned char *rb),
  191
+    ARGIN(const unsigned char *b))
  192
+        __attribute__nonnull__(1)
  193
+        __attribute__nonnull__(2)
  194
+        FUNC_MODIFIES(*rb);
  195
+
  196
+PARROT_INLINE
  197
+static void fetch_buf_le_32(
  198
+    ARGOUT(unsigned char *rb),
  199
+    ARGIN(const unsigned char *b))
  200
+        __attribute__nonnull__(1)
  201
+        __attribute__nonnull__(2)
  202
+        FUNC_MODIFIES(*rb);
  203
+
  204
+PARROT_INLINE
  205
+static void fetch_buf_le_4(
  206
+    ARGOUT(unsigned char *rb),
  207
+    ARGIN(const unsigned char *b))
  208
+        __attribute__nonnull__(1)
  209
+        __attribute__nonnull__(2)
  210
+        FUNC_MODIFIES(*rb);
  211
+
  212
+PARROT_INLINE
  213
+static void fetch_buf_le_8(
  214
+    ARGOUT(unsigned char *rb),
  215
+    ARGIN(const unsigned char *b))
  216
+        __attribute__nonnull__(1)
  217
+        __attribute__nonnull__(2)
  218
+        FUNC_MODIFIES(*rb);
  219
+
  220
+PARROT_INLINE
  221
+PARROT_WARN_UNUSED_RESULT
  222
+PARROT_CONST_FUNCTION
  223
+static INTVAL fetch_iv_be(INTVAL w);
  224
+
  225
+PARROT_INLINE
  226
+PARROT_WARN_UNUSED_RESULT
  227
+PARROT_CONST_FUNCTION
  228
+static INTVAL fetch_iv_le(INTVAL w);
  229
+
  230
+PARROT_INLINE
  231
+PARROT_WARN_UNUSED_RESULT
  232
+PARROT_CONST_FUNCTION
  233
+static opcode_t fetch_op_be(opcode_t w);
  234
+
141 235
 PARROT_WARN_UNUSED_RESULT
142 236
 static opcode_t fetch_op_be_4(ARGIN(const unsigned char *b))
143 237
         __attribute__nonnull__(1);
@@ -146,6 +240,11 @@ PARROT_WARN_UNUSED_RESULT
146 240
 static opcode_t fetch_op_be_8(ARGIN(const unsigned char *b))
147 241
         __attribute__nonnull__(1);
148 242
 
  243
+PARROT_INLINE
  244
+PARROT_WARN_UNUSED_RESULT
  245
+PARROT_CONST_FUNCTION
  246
+static opcode_t fetch_op_le(opcode_t w);
  247
+
149 248
 PARROT_WARN_UNUSED_RESULT
150 249
 static opcode_t fetch_op_le_4(ARGIN(const unsigned char *b))
151 250
         __attribute__nonnull__(1);
@@ -196,10 +295,44 @@ static opcode_t fetch_op_le_8(ARGIN(const unsigned char *b))
196 295
 #define ASSERT_ARGS_cvt_num8_num16_le __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
197 296
        PARROT_ASSERT_ARG(dest) \
198 297
     , PARROT_ASSERT_ARG(src))
  298
+#define ASSERT_ARGS_fetch_buf_be_12 __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
  299
+       PARROT_ASSERT_ARG(rb) \
  300
+    , PARROT_ASSERT_ARG(b))
  301
+#define ASSERT_ARGS_fetch_buf_be_16 __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
  302
+       PARROT_ASSERT_ARG(rb) \
  303
+    , PARROT_ASSERT_ARG(b))
  304
+#define ASSERT_ARGS_fetch_buf_be_32 __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
  305
+       PARROT_ASSERT_ARG(rb) \
  306
+    , PARROT_ASSERT_ARG(b))
  307
+#define ASSERT_ARGS_fetch_buf_be_4 __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
  308
+       PARROT_ASSERT_ARG(rb) \
  309
+    , PARROT_ASSERT_ARG(b))
  310
+#define ASSERT_ARGS_fetch_buf_be_8 __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
  311
+       PARROT_ASSERT_ARG(rb) \
  312
+    , PARROT_ASSERT_ARG(b))
  313
+#define ASSERT_ARGS_fetch_buf_le_12 __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
  314
+       PARROT_ASSERT_ARG(rb) \
  315
+    , PARROT_ASSERT_ARG(b))
  316
+#define ASSERT_ARGS_fetch_buf_le_16 __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
  317
+       PARROT_ASSERT_ARG(rb) \
  318
+    , PARROT_ASSERT_ARG(b))
  319
+#define ASSERT_ARGS_fetch_buf_le_32 __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
  320
+       PARROT_ASSERT_ARG(rb) \
  321
+    , PARROT_ASSERT_ARG(b))
  322
+#define ASSERT_ARGS_fetch_buf_le_4 __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
  323
+       PARROT_ASSERT_ARG(rb) \
  324
+    , PARROT_ASSERT_ARG(b))
  325
+#define ASSERT_ARGS_fetch_buf_le_8 __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
  326
+       PARROT_ASSERT_ARG(rb) \
  327
+    , PARROT_ASSERT_ARG(b))
  328
+#define ASSERT_ARGS_fetch_iv_be __attribute__unused__ int _ASSERT_ARGS_CHECK = (0)
  329
+#define ASSERT_ARGS_fetch_iv_le __attribute__unused__ int _ASSERT_ARGS_CHECK = (0)
  330
+#define ASSERT_ARGS_fetch_op_be __attribute__unused__ int _ASSERT_ARGS_CHECK = (0)
199 331
 #define ASSERT_ARGS_fetch_op_be_4 __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
200 332
        PARROT_ASSERT_ARG(b))
201 333
 #define ASSERT_ARGS_fetch_op_be_8 __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
202 334
        PARROT_ASSERT_ARG(b))
  335
+#define ASSERT_ARGS_fetch_op_le __attribute__unused__ int _ASSERT_ARGS_CHECK = (0)
203 336
 #define ASSERT_ARGS_fetch_op_le_4 __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
204 337
        PARROT_ASSERT_ARG(b))
205 338
 #define ASSERT_ARGS_fetch_op_le_8 __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
@@ -988,6 +1121,7 @@ is 1 I<per definition>.
988 1121
 */
989 1122
 
990 1123
 PARROT_CONST_FUNCTION
  1124
+PARROT_WARN_UNUSED_RESULT
991 1125
 size_t
992 1126
 PF_size_opcode(void)
993 1127
 {
@@ -1714,19 +1848,528 @@ PackFile_assign_transforms(ARGMOD(PackFile *pf))
1714 1848
 #endif
1715 1849
 }
1716 1850
 
  1851
+
1717 1852
 /*
1718 1853
 
1719  
-=back
  1854
+=item C<static INTVAL fetch_iv_le(INTVAL w)>
  1855
+
  1856
+This function converts a 4 or 8 byte C<INTVAL> into little endian
  1857
+format. If the native format is already little endian, then no
  1858
+conversion is done.
  1859
+
  1860
+=cut
  1861
+
  1862
+*/
  1863
+
  1864
+PARROT_INLINE
  1865
+PARROT_WARN_UNUSED_RESULT
  1866
+PARROT_CONST_FUNCTION
  1867
+static INTVAL
  1868
+fetch_iv_le(INTVAL w)
  1869
+{
  1870
+#if !PARROT_BIGENDIAN
  1871
+    return w;
  1872
+#else
  1873
+#  if INTVAL_SIZE == 4
  1874
+    return (w << 24) | ((w & 0xff00) << 8) | ((w & 0xff0000) >> 8) | (w >> 24);
  1875
+#  else
  1876
+#    if INTVAL_SIZE == 8
  1877
+    INTVAL r;
  1878
+
  1879
+    r = w << 56;
  1880
+    r |= (w & 0xff00) << 40;
  1881
+    r |= (w & 0xff0000) << 24;
  1882
+    r |= (w & 0xff000000) << 8;
  1883
+    r |= (w & 0xff00000000) >> 8;
  1884
+    r |= (w & 0xff0000000000) >> 24;
  1885
+    r |= (w & 0xff000000000000) >> 40;
  1886
+    r |= (w & 0xff00000000000000) >> 56;
  1887
+    return r;
  1888
+#    else
  1889
+    exit_fatal(1, "Unsupported INTVAL_SIZE=%d\n",
  1890
+               INTVAL_SIZE);
  1891
+#    endif
  1892
+#  endif
  1893
+#endif
  1894
+}
  1895
+
  1896
+/*
  1897
+
  1898
+=item C<static INTVAL fetch_iv_be(INTVAL w)>
  1899
+
  1900
+This function converts a 4 or 8 byte C<INTVAL> into big endian format.
  1901
+If the native format is already big endian, then no conversion is done.
  1902
+
  1903
+=cut
  1904
+
  1905
+*/
  1906
+
  1907
+PARROT_INLINE
  1908
+PARROT_WARN_UNUSED_RESULT
  1909
+PARROT_CONST_FUNCTION
  1910
+static INTVAL
  1911
+fetch_iv_be(INTVAL w)
  1912
+{
  1913
+#if PARROT_BIGENDIAN
  1914
+    return w;
  1915
+#else
  1916
+#  if INTVAL_SIZE == 4
  1917
+    return (w << 24) | ((w & 0xff00) << 8) | ((w & 0xff0000) >> 8) | (w >> 24);
  1918
+#  else
  1919
+#    if INTVAL_SIZE == 8
  1920
+    INTVAL r;
  1921
+    r = w << 56;
  1922
+    r |= (w & 0xff00) << 40;
  1923
+    r |= (w & 0xff0000) << 24;
  1924
+    r |= (w & 0xff000000) << 8;
  1925
+    r |= (w & 0xff00000000) >> 8;
  1926
+    r |= (w & 0xff0000000000) >> 24;
  1927
+    r |= (w & 0xff000000000000) >> 40;
  1928
+    r |= (w & 0xff00000000000000) >> 56;
  1929
+    return r;
  1930
+#    else
  1931
+    exit_fatal(1, "Unsupported INTVAL_SIZE=%d\n", INTVAL_SIZE);
  1932
+#    endif
  1933
+#  endif
  1934
+#endif
  1935
+}
1720 1936
 
1721  
-=head1 HISTORY
  1937
+/*
  1938
+
  1939
+=item C<static opcode_t fetch_op_be(opcode_t w)>
1722 1940
 
1723  
-Initial review by leo 2003.11.21
  1941
+Same as C<fetch_iv_be> for opcode_t
1724 1942
 
1725  
-Most routines moved from F<src/packfile.c>.
  1943
+=cut
  1944
+
  1945
+*/
  1946
+
  1947
+PARROT_INLINE
  1948
+PARROT_WARN_UNUSED_RESULT
  1949
+PARROT_CONST_FUNCTION
  1950
+static opcode_t
  1951
+fetch_op_be(opcode_t w)
  1952
+{
  1953
+#if PARROT_BIGENDIAN
  1954
+    return w;
  1955
+#else
  1956
+#  if OPCODE_T_SIZE == 4
  1957
+    return (w << 24) | ((w & 0x0000ff00) << 8) | ((w & 0x00ff0000) >> 8) |
  1958
+        ((w & 0xff000000) >> 24);
  1959
+#  else
  1960
+    opcode_t r;
  1961
+
  1962
+    r = w << 56;
  1963
+    r |= (w & 0xff00) << 40;
  1964
+    r |= (w & 0xff0000) << 24;
  1965
+    r |= (w & 0xff000000) << 8;
  1966
+    r |= (w & 0xff00000000) >> 8;
  1967
+    r |= (w & 0xff0000000000) >> 24;
  1968
+    r |= (w & 0xff000000000000) >> 40;
  1969
+    r |= (w & 0xff00000000000000) >> 56;
  1970
+    return r;
  1971
+#  endif
  1972
+#endif
  1973
+}
  1974
+
  1975
+/*
  1976
+
  1977
+=item C<static opcode_t fetch_op_le(opcode_t w)>
  1978
+
  1979
+Same as C<fetch_iv_le> for opcode_t
  1980
+
  1981
+=cut
  1982
+
  1983
+*/
  1984
+
  1985
+PARROT_INLINE
  1986
+PARROT_WARN_UNUSED_RESULT
  1987
+PARROT_CONST_FUNCTION
  1988
+static opcode_t
  1989
+fetch_op_le(opcode_t w)
  1990
+{
  1991
+#if !PARROT_BIGENDIAN
  1992
+    return w;
  1993
+#else
  1994
+#  if OPCODE_T_SIZE == 4
  1995
+    return (w << 24) | ((w & 0x0000ff00) << 8) | ((w & 0x00ff0000) >> 8) |
  1996
+        ((w & 0xff000000) >> 24);
  1997
+#  else
  1998
+    opcode_t r;
  1999
+
  2000
+    r = w << 56;
  2001
+    r |= (w & 0xff00) << 40;
  2002
+    r |= (w & 0xff0000) << 24;
  2003
+    r |= (w & 0xff000000) << 8;
  2004
+    r |= (w & 0xff00000000) >> 8;
  2005
+    r |= (w & 0xff0000000000) >> 24;
  2006
+    r |= (w & 0xff000000000000) >> 40;
  2007
+    r |= (w & 0xff00000000000000) >> 56;
  2008
+    return r;
  2009
+#  endif
  2010
+#endif
  2011
+}
  2012
+
  2013
+/*
  2014
+
  2015
+=pod
  2016
+
  2017
+Unrolled routines for swapping various sizes from 32-128 bits. These
  2018
+should only be used if alignment is unknown or we are pulling something
  2019
+out of a padded buffer.
  2020
+
  2021
+=cut
  2022
+
  2023
+*/
  2024
+
  2025
+/*
  2026
+
  2027
+=item C<static void fetch_buf_be_4(unsigned char *rb, const unsigned char *b)>
  2028
+
  2029
+Converts a 4-byte big-endian buffer C<b> into a little-endian C<rb>.
  2030
+
  2031
+=cut
  2032
+
  2033
+*/
  2034
+
  2035
+PARROT_INLINE
  2036
+static void
  2037
+fetch_buf_be_4(ARGOUT(unsigned char *rb), ARGIN(const unsigned char *b))
  2038
+{
  2039
+#if PARROT_BIGENDIAN
  2040
+    memcpy(rb, b, 4);
  2041
+#else
  2042
+    rb[0] = b[3];
  2043
+    rb[1] = b[2];
  2044
+    rb[2] = b[1];
  2045
+    rb[3] = b[0];
  2046
+#endif
  2047
+}
  2048
+
  2049
+/*
1726 2050
 
1727  
-Renamed PackFile_* to PF_*
  2051
+=item C<static void fetch_buf_le_4(unsigned char *rb, const unsigned char *b)>
1728 2052
 
1729  
-Added 16 byte types.
  2053
+Converts a 4-byte little-endian buffer C<b> into a big-endian buffer C<rb>.
  2054
+
  2055
+=cut
  2056
+
  2057
+*/
  2058
+
  2059
+PARROT_INLINE
  2060
+static void
  2061
+fetch_buf_le_4(ARGOUT(unsigned char *rb), ARGIN(const unsigned char *b))
  2062
+{
  2063
+#if !PARROT_BIGENDIAN
  2064
+    memcpy(rb, b, 4);
  2065
+#else
  2066
+    rb[0] = b[3];
  2067
+    rb[1] = b[2];
  2068
+    rb[2] = b[1];
  2069
+    rb[3] = b[0];
  2070
+#endif
  2071
+}
  2072
+
  2073
+/*
  2074
+
  2075
+=item C<static void fetch_buf_be_8(unsigned char *rb, const unsigned char *b)>
  2076
+
  2077
+Converts an 8-byte big-endian buffer C<b> into a little-endian buffer C<rb>
  2078
+
  2079
+=cut
  2080
+
  2081
+*/
  2082
+
  2083
+PARROT_INLINE
  2084
+static void
  2085
+fetch_buf_be_8(ARGOUT(unsigned char *rb), ARGIN(const unsigned char *b))
  2086
+{
  2087
+#if PARROT_BIGENDIAN
  2088
+    memcpy(rb, b, 8);
  2089
+#else
  2090
+    rb[0] = b[7];
  2091
+    rb[1] = b[6];
  2092
+    rb[2] = b[5];
  2093
+    rb[3] = b[4];
  2094
+    rb[4] = b[3];
  2095
+    rb[5] = b[2];
  2096
+    rb[6] = b[1];
  2097
+    rb[7] = b[0];
  2098
+#endif
  2099
+}
  2100
+
  2101
+/*
  2102
+
  2103
+=item C<static void fetch_buf_le_8(unsigned char *rb, const unsigned char *b)>
  2104
+
  2105
+Converts an 8-byte little-endian buffer C<b> into a big-endian buffer C<rb>.
  2106
+
  2107
+=cut
  2108
+
  2109
+*/
  2110
+
  2111
+PARROT_INLINE
  2112
+static void
  2113
+fetch_buf_le_8(ARGOUT(unsigned char *rb), ARGIN(const unsigned char *b))
  2114
+{
  2115
+#if !PARROT_BIGENDIAN
  2116
+    memcpy(rb, b, 8);
  2117
+#else
  2118
+    rb[0] = b[7];
  2119
+    rb[1] = b[6];
  2120
+    rb[2] = b[5];
  2121
+    rb[3] = b[4];
  2122
+    rb[4] = b[3];
  2123
+    rb[5] = b[2];
  2124
+    rb[6] = b[1];
  2125
+    rb[7] = b[0];
  2126
+#endif
  2127
+}
  2128
+
  2129
+/*
  2130
+
  2131
+=item C<static void fetch_buf_le_12(unsigned char *rb, const unsigned char *b)>
  2132
+
  2133
+Converts a 12-byte little-endian buffer C<b> into a big-endian buffer C<b>.
  2134
+
  2135
+=cut
  2136
+
  2137
+*/
  2138
+
  2139
+PARROT_INLINE
  2140
+static void
  2141
+fetch_buf_le_12(ARGOUT(unsigned char *rb), ARGIN(const unsigned char *b))
  2142
+{
  2143
+#if !PARROT_BIGENDIAN
  2144
+    memcpy(rb, b, 12);
  2145
+#else
  2146
+    rb[0]  = b[11];
  2147
+    rb[1]  = b[10];
  2148
+    rb[2]  = b[9];
  2149
+    rb[3]  = b[8];
  2150
+    rb[4]  = b[7];
  2151
+    rb[5]  = b[6];
  2152
+    rb[6]  = b[5];
  2153
+    rb[7]  = b[4];
  2154
+    rb[8]  = b[3];
  2155
+    rb[9]  = b[2];
  2156
+    rb[10] = b[1];
  2157
+    rb[11] = b[0];
  2158
+#endif
  2159
+}
  2160
+
  2161
+/*
  2162
+
  2163
+=item C<static void fetch_buf_be_12(unsigned char *rb, const unsigned char *b)>
  2164
+
  2165
+Converts a 12-byte big-endian buffer C<b> into a little-endian buffer C<b>.
  2166
+
  2167
+=cut
  2168
+
  2169
+*/
  2170
+
  2171
+PARROT_INLINE
  2172
+static void
  2173
+fetch_buf_be_12(ARGOUT(unsigned char *rb), ARGIN(const unsigned char *b))
  2174
+{
  2175
+#if PARROT_BIGENDIAN
  2176
+    memcpy(rb, b, 12);
  2177
+#else
  2178
+    rb[0]  = b[11];
  2179
+    rb[1]  = b[10];
  2180
+    rb[2]  = b[9];
  2181
+    rb[3]  = b[8];
  2182
+    rb[4]  = b[7];
  2183
+    rb[5]  = b[6];
  2184
+    rb[6]  = b[5];
  2185
+    rb[7]  = b[4];
  2186
+    rb[8]  = b[3];
  2187
+    rb[9]  = b[2];
  2188
+    rb[10] = b[1];
  2189
+    rb[11] = b[0];
  2190
+#endif
  2191
+}
  2192
+
  2193
+/*
  2194
+
  2195
+=item C<static void fetch_buf_le_16(unsigned char *rb, const unsigned char *b)>
  2196
+
  2197
+Converts a 16-byte little-endian buffer C<b> into a big-endian buffer C<b>.
  2198
+
  2199
+=cut
  2200
+
  2201
+*/
  2202
+
  2203
+PARROT_INLINE
  2204
+static void
  2205
+fetch_buf_le_16(ARGOUT(unsigned char *rb), ARGIN(const unsigned char *b))
  2206
+{
  2207
+#if !PARROT_BIGENDIAN
  2208
+    memcpy(rb, b, 16);
  2209
+#else
  2210
+    rb[0]  = b[15];
  2211
+    rb[1]  = b[14];
  2212
+    rb[2]  = b[13];
  2213
+    rb[3]  = b[12];
  2214
+    rb[4]  = b[11];
  2215
+    rb[5]  = b[10];
  2216
+    rb[6]  = b[9];
  2217
+    rb[7]  = b[8];
  2218
+    rb[8]  = b[7];
  2219
+    rb[9]  = b[6];
  2220
+    rb[10] = b[5];
  2221
+    rb[11] = b[4];
  2222
+    rb[12] = b[3];
  2223
+    rb[13] = b[2];
  2224
+    rb[14] = b[1];
  2225
+    rb[15] = b[0];
  2226
+#endif
  2227
+}
  2228
+
  2229
+/*
  2230
+
  2231
+=item C<static void fetch_buf_be_16(unsigned char *rb, const unsigned char *b)>
  2232
+
  2233
+Converts a 16-byte big-endian buffer C<b> into a little-endian buffer C<b>.
  2234
+
  2235
+=cut
  2236
+
  2237
+*/
  2238
+
  2239
+PARROT_INLINE
  2240
+static void
  2241
+fetch_buf_be_16(ARGOUT(unsigned char *rb), ARGIN(const unsigned char *b))
  2242
+{
  2243
+#if PARROT_BIGENDIAN
  2244
+    memcpy(rb, b, 16);
  2245
+#else
  2246
+    rb[0]  = b[15];
  2247
+    rb[1]  = b[14];
  2248
+    rb[2]  = b[13];
  2249
+    rb[3]  = b[12];
  2250
+    rb[4]  = b[11];
  2251
+    rb[5]  = b[10];
  2252
+    rb[6]  = b[9];
  2253
+    rb[7]  = b[8];
  2254
+    rb[8]  = b[7];
  2255
+    rb[9]  = b[6];
  2256
+    rb[10] = b[5];