2 Copyright (C) 2001-2007, The Perl Foundation.
7 src/byteorder.c - Byteordering functions
11 These are assigned to a vtable when the PBC file is loaded.
13 If the vtable method for conversion from the native byteorder is called,
14 it is a I<no op> and will work, but the caller should know if the
15 byteorder in the PBC file is native and skip the conversion and just map
18 =head2 Byte order handlers
20 Configure will have checked for supported word sizes.
28 #include "parrot/parrot.h"
29 #include "parrot/packfile.h"
31 /* HEADERIZER HFILE: include/parrot/packfile.h */
35 =item C<INTVAL fetch_iv_le>
37 This function converts a 4 or 8 byte C<INTVAL> into little endian
38 format. If the native format is already little endian, then no
45 PARROT_WARN_UNUSED_RESULT
54 return (w
<< 24) | ((w
& 0xff00) << 8) | ((w
& 0xff0000) >> 8) | (w
>> 24);
59 r
|= (w
& 0xff00) << 40;
60 r
|= (w
& 0xff0000) << 24;
61 r
|= (w
& 0xff000000) << 8;
62 r
|= (w
& 0xff00000000) >> 8;
63 r
|= (w
& 0xff0000000000) >> 24;
64 r
|= (w
& 0xff000000000000) >> 40;
65 r
|= (w
& 0xff00000000000000) >> 56;
73 =item C<INTVAL fetch_iv_be>
75 This function converts a 4 or 8 byte C<INTVAL> into big endian format.
76 If the native format is already big endian, then no conversion is done.
82 PARROT_WARN_UNUSED_RESULT
91 return (w
<< 24) | ((w
& 0xff00) << 8) | ((w
& 0xff0000) >> 8) | (w
>> 24);
95 r
|= (w
& 0xff00) << 40;
96 r
|= (w
& 0xff0000) << 24;
97 r
|= (w
& 0xff000000) << 8;
98 r
|= (w
& 0xff00000000) >> 8;
99 r
|= (w
& 0xff0000000000) >> 24;
100 r
|= (w
& 0xff000000000000) >> 40;
101 r
|= (w
& 0xff00000000000000) >> 56;
109 =item C<opcode_t fetch_op_be>
111 Same as C<fetch_iv_be> for opcode_t
117 PARROT_WARN_UNUSED_RESULT
118 PARROT_CONST_FUNCTION
120 fetch_op_be(opcode_t w
)
125 # if OPCODE_T_SIZE == 4
126 return (w
<< 24) | ((w
& 0x0000ff00) << 8) | ((w
& 0x00ff0000) >> 8) |
127 ((w
& 0xff000000) >> 24);
132 r
|= (w
& 0xff00) << 40;
133 r
|= (w
& 0xff0000) << 24;
134 r
|= (w
& 0xff000000) << 8;
135 r
|= (w
& 0xff00000000) >> 8;
136 r
|= (w
& 0xff0000000000) >> 24;
137 r
|= (w
& 0xff000000000000) >> 40;
138 r
|= (w
& 0xff00000000000000) >> 56;
146 =item C<opcode_t fetch_op_le>
148 Same as C<fetch_iv_le> for opcode_t
154 PARROT_WARN_UNUSED_RESULT
155 PARROT_CONST_FUNCTION
157 fetch_op_le(opcode_t w
)
159 #if !PARROT_BIGENDIAN
162 # if OPCODE_T_SIZE == 4
163 return (w
<< 24) | ((w
& 0x0000ff00) << 8) | ((w
& 0x00ff0000) >> 8) |
164 ((w
& 0xff000000) >> 24);
169 r
|= (w
& 0xff00) << 40;
170 r
|= (w
& 0xff0000) << 24;
171 r
|= (w
& 0xff000000) << 8;
172 r
|= (w
& 0xff00000000) >> 8;
173 r
|= (w
& 0xff0000000000) >> 24;
174 r
|= (w
& 0xff000000000000) >> 40;
175 r
|= (w
& 0xff00000000000000) >> 56;
185 Unrolled routines for swapping various sizes from 32-128 bits. These
186 should only be used if alignment is unknown or we are pulling something
187 out of a padded buffer.
195 =item C<void fetch_buf_be_4>
197 RT#48260: Not yet documented!!!
204 fetch_buf_be_4(ARGOUT(unsigned char *rb
), ARGIN(const unsigned char *b
))
218 =item C<void fetch_buf_le_4>
220 RT#48260: Not yet documented!!!
227 fetch_buf_le_4(ARGOUT(unsigned char *rb
), ARGIN(const unsigned char *b
))
229 #if !PARROT_BIGENDIAN
241 =item C<void fetch_buf_be_8>
243 RT#48260: Not yet documented!!!
250 fetch_buf_be_8(ARGOUT(unsigned char *rb
), ARGIN(const unsigned char *b
))
268 =item C<void fetch_buf_le_8>
270 RT#48260: Not yet documented!!!
277 fetch_buf_le_8(ARGOUT(unsigned char *rb
), ARGIN(const unsigned char *b
))
279 #if !PARROT_BIGENDIAN
295 =item C<void fetch_buf_le_12>
297 RT#48260: Not yet documented!!!
304 fetch_buf_le_12(ARGOUT(unsigned char *rb
), ARGIN(const unsigned char *b
))
306 #if !PARROT_BIGENDIAN
326 =item C<void fetch_buf_be_12>
328 RT#48260: Not yet documented!!!
335 fetch_buf_be_12(ARGOUT(unsigned char *rb
), ARGIN(const unsigned char *b
))
357 =item C<void fetch_buf_le_16>
359 RT#48260: Not yet documented!!!
366 fetch_buf_le_16(ARGOUT(unsigned char *rb
), ARGIN(const unsigned char *b
))
368 #if !PARROT_BIGENDIAN
392 =item C<void fetch_buf_be_16>
394 RT#48260: Not yet documented!!!
401 fetch_buf_be_16(ARGOUT(unsigned char *rb
), ARGIN(const unsigned char *b
))
431 Initial version by Melvin on 2002/05/01
439 * c-file-style: "parrot"
441 * vim: expandtab shiftwidth=4: