Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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
@petdance petdance authored
View
1  MANIFEST
@@ -1279,7 +1279,6 @@ src/ops/string.ops []
src/ops/sys.ops []
src/ops/var.ops []
src/packfile/api.c []
-src/packfile/byteorder.h []
src/packfile/object_serialization.c []
src/packfile/output.c []
src/packfile/pf_items.c []
View
3  config/gen/makefiles/root.in
@@ -1,4 +1,4 @@
-# Copyright (C) 2001-2011, Parrot Foundation.
+# Copyright (C) 2001-2012, Parrot Foundation.
###############################################################################
#
@@ -1682,7 +1682,6 @@ src/packfile/output$(O) : \
src/packfile/pf_items$(O) : \
$(PARROT_H_HEADERS) \
- src/packfile/byteorder.h \
src/packfile/pf_items.str \
src/packfile/pf_items.c
View
571 src/packfile/byteorder.h
@@ -1,571 +0,0 @@
-/*
-Copyright (C) 2001-2009, Parrot Foundation.
-
-=head1 NAME
-
-src/byteorder.c - Byteordering functions
-
-=head1 DESCRIPTION
-
-These are assigned to a vtable when the PBC file is loaded.
-
-If the vtable function for conversion from the native byteorder is called,
-it is a I<no op> and will work, but the caller should know if the
-byteorder in the PBC file is native and skip the conversion and just map
-it in.
-
-=head2 Byte order handlers
-
-Configure will have checked for supported word sizes.
-
-=over 4
-
-=cut
-
-*/
-
-#ifndef PARROT_BYTEORDER_H_GUARD
-#define PARROT_BYTEORDER_H_GUARD
-
-#include "parrot/parrot.h"
-
-/* HEADERIZER HFILE: none */
-
-/*
-
-=item C<static INTVAL fetch_iv_le(INTVAL w)>
-
-This function converts a 4 or 8 byte C<INTVAL> into little endian
-format. If the native format is already little endian, then no
-conversion is done.
-
-=cut
-
-*/
-
-PARROT_INLINE
-PARROT_WARN_UNUSED_RESULT
-PARROT_CONST_FUNCTION
-static INTVAL
-fetch_iv_le(INTVAL w)
-{
-#if !PARROT_BIGENDIAN
- return w;
-#else
-# if INTVAL_SIZE == 4
- return (w << 24) | ((w & 0xff00) << 8) | ((w & 0xff0000) >> 8) | (w >> 24);
-# else
-# if INTVAL_SIZE == 8
- INTVAL r;
-
- r = w << 56;
- r |= (w & 0xff00) << 40;
- r |= (w & 0xff0000) << 24;
- r |= (w & 0xff000000) << 8;
- r |= (w & 0xff00000000) >> 8;
- r |= (w & 0xff0000000000) >> 24;
- r |= (w & 0xff000000000000) >> 40;
- r |= (w & 0xff00000000000000) >> 56;
- return r;
-# else
- exit_fatal(1, "Unsupported INTVAL_SIZE=%d\n",
- INTVAL_SIZE);
-# endif
-# endif
-#endif
-}
-
-/*
-
-=item C<static INTVAL fetch_iv_be(INTVAL w)>
-
-This function converts a 4 or 8 byte C<INTVAL> into big endian format.
-If the native format is already big endian, then no conversion is done.
-
-=cut
-
-*/
-
-PARROT_INLINE
-PARROT_WARN_UNUSED_RESULT
-PARROT_CONST_FUNCTION
-static INTVAL
-fetch_iv_be(INTVAL w)
-{
-#if PARROT_BIGENDIAN
- return w;
-#else
-# if INTVAL_SIZE == 4
- return (w << 24) | ((w & 0xff00) << 8) | ((w & 0xff0000) >> 8) | (w >> 24);
-# else
-# if INTVAL_SIZE == 8
- INTVAL r;
- r = w << 56;
- r |= (w & 0xff00) << 40;
- r |= (w & 0xff0000) << 24;
- r |= (w & 0xff000000) << 8;
- r |= (w & 0xff00000000) >> 8;
- r |= (w & 0xff0000000000) >> 24;
- r |= (w & 0xff000000000000) >> 40;
- r |= (w & 0xff00000000000000) >> 56;
- return r;
-# else
- exit_fatal(1, "Unsupported INTVAL_SIZE=%d\n",
- INTVAL_SIZE);
-# endif
-# endif
-#endif
-}
-
-/*
-
-=item C<static opcode_t fetch_op_be(opcode_t w)>
-
-Same as C<fetch_iv_be> for opcode_t
-
-=cut
-
-*/
-
-PARROT_INLINE
-PARROT_WARN_UNUSED_RESULT
-PARROT_CONST_FUNCTION
-static opcode_t
-fetch_op_be(opcode_t w)
-{
-#if PARROT_BIGENDIAN
- return w;
-#else
-# if OPCODE_T_SIZE == 4
- return (w << 24) | ((w & 0x0000ff00) << 8) | ((w & 0x00ff0000) >> 8) |
- ((w & 0xff000000) >> 24);
-# else
- opcode_t r;
-
- r = w << 56;
- r |= (w & 0xff00) << 40;
- r |= (w & 0xff0000) << 24;
- r |= (w & 0xff000000) << 8;
- r |= (w & 0xff00000000) >> 8;
- r |= (w & 0xff0000000000) >> 24;
- r |= (w & 0xff000000000000) >> 40;
- r |= (w & 0xff00000000000000) >> 56;
- return r;
-# endif
-#endif
-}
-
-/*
-
-=item C<static opcode_t fetch_op_le(opcode_t w)>
-
-Same as C<fetch_iv_le> for opcode_t
-
-=cut
-
-*/
-
-PARROT_INLINE
-PARROT_WARN_UNUSED_RESULT
-PARROT_CONST_FUNCTION
-static opcode_t
-fetch_op_le(opcode_t w)
-{
-#if !PARROT_BIGENDIAN
- return w;
-#else
-# if OPCODE_T_SIZE == 4
- return (w << 24) | ((w & 0x0000ff00) << 8) | ((w & 0x00ff0000) >> 8) |
- ((w & 0xff000000) >> 24);
-# else
- opcode_t r;
-
- r = w << 56;
- r |= (w & 0xff00) << 40;
- r |= (w & 0xff0000) << 24;
- r |= (w & 0xff000000) << 8;
- r |= (w & 0xff00000000) >> 8;
- r |= (w & 0xff0000000000) >> 24;
- r |= (w & 0xff000000000000) >> 40;
- r |= (w & 0xff00000000000000) >> 56;
- return r;
-# endif
-#endif
-}
-
-/*
-
-=pod
-
-Unrolled routines for swapping various sizes from 32-128 bits. These
-should only be used if alignment is unknown or we are pulling something
-out of a padded buffer.
-
-=cut
-
-*/
-
-/*
-
-=item C<static void fetch_buf_be_4(unsigned char *rb, const unsigned char *b)>
-
-Converts a 4-byte big-endian buffer C<b> into a little-endian C<rb>.
-
-=cut
-
-*/
-
-PARROT_INLINE
-static void
-fetch_buf_be_4(ARGOUT(unsigned char *rb), ARGIN(const unsigned char *b))
-{
-#if PARROT_BIGENDIAN
- memcpy(rb, b, 4);
-#else
- rb[0] = b[3];
- rb[1] = b[2];
- rb[2] = b[1];
- rb[3] = b[0];
-#endif
-}
-
-/*
-
-=item C<static void fetch_buf_le_4(unsigned char *rb, const unsigned char *b)>
-
-Converts a 4-byte little-endian buffer C<b> into a big-endian buffer C<rb>.
-
-=cut
-
-*/
-
-PARROT_INLINE
-static void
-fetch_buf_le_4(ARGOUT(unsigned char *rb), ARGIN(const unsigned char *b))
-{
-#if !PARROT_BIGENDIAN
- memcpy(rb, b, 4);
-#else
- rb[0] = b[3];
- rb[1] = b[2];
- rb[2] = b[1];
- rb[3] = b[0];
-#endif
-}
-
-/*
-
-=item C<static void fetch_buf_be_8(unsigned char *rb, const unsigned char *b)>
-
-Converts an 8-byte big-endian buffer C<b> into a little-endian buffer C<rb>
-
-=cut
-
-*/
-
-PARROT_INLINE
-static void
-fetch_buf_be_8(ARGOUT(unsigned char *rb), ARGIN(const unsigned char *b))
-{
-#if PARROT_BIGENDIAN
- memcpy(rb, b, 8);
-#else
- rb[0] = b[7];
- rb[1] = b[6];
- rb[2] = b[5];
- rb[3] = b[4];
- rb[4] = b[3];
- rb[5] = b[2];
- rb[6] = b[1];
- rb[7] = b[0];
-#endif
-}
-
-/*
-
-=item C<static void fetch_buf_le_8(unsigned char *rb, const unsigned char *b)>
-
-Converts an 8-byte little-endian buffer C<b> into a big-endian buffer C<rb>.
-
-=cut
-
-*/
-
-PARROT_INLINE
-static void
-fetch_buf_le_8(ARGOUT(unsigned char *rb), ARGIN(const unsigned char *b))
-{
-#if !PARROT_BIGENDIAN
- memcpy(rb, b, 8);
-#else
- rb[0] = b[7];
- rb[1] = b[6];
- rb[2] = b[5];
- rb[3] = b[4];
- rb[4] = b[3];
- rb[5] = b[2];
- rb[6] = b[1];
- rb[7] = b[0];
-#endif
-}
-
-/*
-
-=item C<static void fetch_buf_le_12(unsigned char *rb, const unsigned char *b)>
-
-Converts a 12-byte little-endian buffer C<b> into a big-endian buffer C<b>.
-
-=cut
-
-*/
-
-PARROT_INLINE
-static void
-fetch_buf_le_12(ARGOUT(unsigned char *rb), ARGIN(const unsigned char *b))
-{
-#if !PARROT_BIGENDIAN
- memcpy(rb, b, 12);
-#else
- rb[0] = b[11];
- rb[1] = b[10];
- rb[2] = b[9];
- rb[3] = b[8];
- rb[4] = b[7];
- rb[5] = b[6];
- rb[6] = b[5];
- rb[7] = b[4];
- rb[8] = b[3];
- rb[9] = b[2];
- rb[10] = b[1];
- rb[11] = b[0];
-#endif
-}
-
-/*
-
-=item C<static void fetch_buf_be_12(unsigned char *rb, const unsigned char *b)>
-
-Converts a 12-byte big-endian buffer C<b> into a little-endian buffer C<b>.
-
-=cut
-
-*/
-
-PARROT_INLINE
-static void
-fetch_buf_be_12(ARGOUT(unsigned char *rb), ARGIN(const unsigned char *b))
-{
-#if PARROT_BIGENDIAN
- memcpy(rb, b, 12);
-#else
- rb[0] = b[11];
- rb[1] = b[10];
- rb[2] = b[9];
- rb[3] = b[8];
- rb[4] = b[7];
- rb[5] = b[6];
- rb[6] = b[5];
- rb[7] = b[4];
- rb[8] = b[3];
- rb[9] = b[2];
- rb[10] = b[1];
- rb[11] = b[0];
-#endif
-}
-
-/*
-
-=item C<static void fetch_buf_le_16(unsigned char *rb, const unsigned char *b)>
-
-Converts a 16-byte little-endian buffer C<b> into a big-endian buffer C<b>.
-
-=cut
-
-*/
-
-PARROT_INLINE
-static void
-fetch_buf_le_16(ARGOUT(unsigned char *rb), ARGIN(const unsigned char *b))
-{
-#if !PARROT_BIGENDIAN
- memcpy(rb, b, 16);
-#else
- rb[0] = b[15];
- rb[1] = b[14];
- rb[2] = b[13];
- rb[3] = b[12];
- rb[4] = b[11];
- rb[5] = b[10];
- rb[6] = b[9];
- rb[7] = b[8];
- rb[8] = b[7];
- rb[9] = b[6];
- rb[10] = b[5];
- rb[11] = b[4];
- rb[12] = b[3];
- rb[13] = b[2];
- rb[14] = b[1];
- rb[15] = b[0];
-#endif
-}
-
-/*
-
-=item C<static void fetch_buf_be_16(unsigned char *rb, const unsigned char *b)>
-
-Converts a 16-byte big-endian buffer C<b> into a little-endian buffer C<b>.
-
-=cut
-
-*/
-
-PARROT_INLINE
-static void
-fetch_buf_be_16(ARGOUT(unsigned char *rb), ARGIN(const unsigned char *b))
-{
-#if PARROT_BIGENDIAN
- memcpy(rb, b, 16);
-#else
- rb[0] = b[15];
- rb[1] = b[14];
- rb[2] = b[13];
- rb[3] = b[12];
- rb[4] = b[11];
- rb[5] = b[10];
- rb[6] = b[9];
- rb[7] = b[8];
- rb[8] = b[7];
- rb[9] = b[6];
- rb[10] = b[5];
- rb[11] = b[4];
- rb[12] = b[3];
- rb[13] = b[2];
- rb[14] = b[1];
- rb[15] = b[0];
-#endif
-}
-
-/*
-
-=item C<static void fetch_buf_le_32(unsigned char *rb, const unsigned char *b)>
-
-Converts a 32-byte little-endian buffer C<b> into a big-endian buffer C<b>.
-
-=cut
-
-*/
-
-PARROT_INLINE
-static void
-fetch_buf_le_32(ARGOUT(unsigned char *rb), ARGIN(const unsigned char *b))
-{
-#if !PARROT_BIGENDIAN
- memcpy(rb, b, 32);
-#else
- rb[0] = b[31];
- rb[1] = b[30];
- rb[2] = b[29];
- rb[3] = b[28];
- rb[4] = b[27];
- rb[5] = b[26];
- rb[6] = b[25];
- rb[7] = b[24];
- rb[8] = b[23];
- rb[9] = b[22];
- rb[10] = b[21];
- rb[11] = b[20];
- rb[12] = b[19];
- rb[13] = b[18];
- rb[14] = b[17];
- rb[15] = b[16];
- rb[16] = b[15];
- rb[17] = b[14];
- rb[18] = b[13];
- rb[19] = b[12];
- rb[20] = b[11];
- rb[21] = b[10];
- rb[22] = b[9];
- rb[23] = b[8];
- rb[24] = b[7];
- rb[25] = b[6];
- rb[26] = b[5];
- rb[27] = b[4];
- rb[28] = b[3];
- rb[29] = b[2];
- rb[30] = b[1];
- rb[31] = b[0];
-#endif
-}
-
-/*
-
-=item C<static void fetch_buf_be_32(unsigned char *rb, const unsigned char *b)>
-
-Converts a 32-byte big-endian buffer C<b> into a little-endian buffer C<b>.
-
-=cut
-
-*/
-
-PARROT_INLINE
-static void
-fetch_buf_be_32(ARGOUT(unsigned char *rb), ARGIN(const unsigned char *b))
-{
-#if PARROT_BIGENDIAN
- memcpy(rb, b, 32);
-#else
- rb[0] = b[31];
- rb[1] = b[30];
- rb[2] = b[29];
- rb[3] = b[28];
- rb[4] = b[27];
- rb[5] = b[26];
- rb[6] = b[25];
- rb[7] = b[24];
- rb[8] = b[23];
- rb[9] = b[22];
- rb[10] = b[21];
- rb[11] = b[20];
- rb[12] = b[19];
- rb[13] = b[18];
- rb[14] = b[17];
- rb[15] = b[16];
- rb[16] = b[15];
- rb[17] = b[14];
- rb[18] = b[13];
- rb[19] = b[12];
- rb[20] = b[11];
- rb[21] = b[10];
- rb[22] = b[9];
- rb[23] = b[8];
- rb[24] = b[7];
- rb[25] = b[6];
- rb[26] = b[5];
- rb[27] = b[4];
- rb[28] = b[3];
- rb[29] = b[2];
- rb[30] = b[1];
- rb[31] = b[0];
-#endif
-}
-
-#endif /* PARROT_BYTEORDER_H_GUARD */
-
-/*
-
-=back
-
-=head1 HISTORY
-
-Initial version by Melvin on 2002/05/01
-
-=cut
-
-*/
-
-/*
- * Local variables:
- * c-file-style: "parrot"
- * End:
- * vim: expandtab shiftwidth=4 cinoptions='\:2=2' :
- */
View
660 src/packfile/pf_items.c
@@ -1,5 +1,5 @@
/*
-Copyright (C) 2001-2010, Parrot Foundation.
+Copyright (C) 2001-2012, Parrot Foundation.
=head1 NAME
@@ -32,7 +32,6 @@ for "little endian".
*/
#include "parrot/parrot.h"
-#include "byteorder.h"
#include "pf_items.str"
/* HEADERIZER HFILE: include/parrot/packfile.h */
@@ -138,6 +137,101 @@ static void cvt_num8_num16_le(
__attribute__nonnull__(2)
FUNC_MODIFIES(*dest);
+PARROT_INLINE
+static void fetch_buf_be_12(
+ ARGOUT(unsigned char *rb),
+ ARGIN(const unsigned char *b))
+ __attribute__nonnull__(1)
+ __attribute__nonnull__(2)
+ FUNC_MODIFIES(*rb);
+
+PARROT_INLINE
+static void fetch_buf_be_16(
+ ARGOUT(unsigned char *rb),
+ ARGIN(const unsigned char *b))
+ __attribute__nonnull__(1)
+ __attribute__nonnull__(2)
+ FUNC_MODIFIES(*rb);
+
+PARROT_INLINE
+static void fetch_buf_be_32(
+ ARGOUT(unsigned char *rb),
+ ARGIN(const unsigned char *b))
+ __attribute__nonnull__(1)
+ __attribute__nonnull__(2)
+ FUNC_MODIFIES(*rb);
+
+PARROT_INLINE
+static void fetch_buf_be_4(
+ ARGOUT(unsigned char *rb),
+ ARGIN(const unsigned char *b))
+ __attribute__nonnull__(1)
+ __attribute__nonnull__(2)
+ FUNC_MODIFIES(*rb);
+
+PARROT_INLINE
+static void fetch_buf_be_8(
+ ARGOUT(unsigned char *rb),
+ ARGIN(const unsigned char *b))
+ __attribute__nonnull__(1)
+ __attribute__nonnull__(2)
+ FUNC_MODIFIES(*rb);
+
+PARROT_INLINE
+static void fetch_buf_le_12(
+ ARGOUT(unsigned char *rb),
+ ARGIN(const unsigned char *b))
+ __attribute__nonnull__(1)
+ __attribute__nonnull__(2)
+ FUNC_MODIFIES(*rb);
+
+PARROT_INLINE
+static void fetch_buf_le_16(
+ ARGOUT(unsigned char *rb),
+ ARGIN(const unsigned char *b))
+ __attribute__nonnull__(1)
+ __attribute__nonnull__(2)
+ FUNC_MODIFIES(*rb);
+
+PARROT_INLINE
+static void fetch_buf_le_32(
+ ARGOUT(unsigned char *rb),
+ ARGIN(const unsigned char *b))
+ __attribute__nonnull__(1)
+ __attribute__nonnull__(2)
+ FUNC_MODIFIES(*rb);
+
+PARROT_INLINE
+static void fetch_buf_le_4(
+ ARGOUT(unsigned char *rb),
+ ARGIN(const unsigned char *b))
+ __attribute__nonnull__(1)
+ __attribute__nonnull__(2)
+ FUNC_MODIFIES(*rb);
+
+PARROT_INLINE
+static void fetch_buf_le_8(
+ ARGOUT(unsigned char *rb),
+ ARGIN(const unsigned char *b))
+ __attribute__nonnull__(1)
+ __attribute__nonnull__(2)
+ FUNC_MODIFIES(*rb);
+
+PARROT_INLINE
+PARROT_WARN_UNUSED_RESULT
+PARROT_CONST_FUNCTION
+static INTVAL fetch_iv_be(INTVAL w);
+
+PARROT_INLINE
+PARROT_WARN_UNUSED_RESULT
+PARROT_CONST_FUNCTION
+static INTVAL fetch_iv_le(INTVAL w);
+
+PARROT_INLINE
+PARROT_WARN_UNUSED_RESULT
+PARROT_CONST_FUNCTION
+static opcode_t fetch_op_be(opcode_t w);
+
PARROT_WARN_UNUSED_RESULT
static opcode_t fetch_op_be_4(ARGIN(const unsigned char *b))
__attribute__nonnull__(1);
@@ -146,6 +240,11 @@ PARROT_WARN_UNUSED_RESULT
static opcode_t fetch_op_be_8(ARGIN(const unsigned char *b))
__attribute__nonnull__(1);
+PARROT_INLINE
+PARROT_WARN_UNUSED_RESULT
+PARROT_CONST_FUNCTION
+static opcode_t fetch_op_le(opcode_t w);
+
PARROT_WARN_UNUSED_RESULT
static opcode_t fetch_op_le_4(ARGIN(const unsigned char *b))
__attribute__nonnull__(1);
@@ -196,10 +295,44 @@ static opcode_t fetch_op_le_8(ARGIN(const unsigned char *b))
#define ASSERT_ARGS_cvt_num8_num16_le __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(dest) \
, PARROT_ASSERT_ARG(src))
+#define ASSERT_ARGS_fetch_buf_be_12 __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+ PARROT_ASSERT_ARG(rb) \
+ , PARROT_ASSERT_ARG(b))
+#define ASSERT_ARGS_fetch_buf_be_16 __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+ PARROT_ASSERT_ARG(rb) \
+ , PARROT_ASSERT_ARG(b))
+#define ASSERT_ARGS_fetch_buf_be_32 __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+ PARROT_ASSERT_ARG(rb) \
+ , PARROT_ASSERT_ARG(b))
+#define ASSERT_ARGS_fetch_buf_be_4 __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+ PARROT_ASSERT_ARG(rb) \
+ , PARROT_ASSERT_ARG(b))
+#define ASSERT_ARGS_fetch_buf_be_8 __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+ PARROT_ASSERT_ARG(rb) \
+ , PARROT_ASSERT_ARG(b))
+#define ASSERT_ARGS_fetch_buf_le_12 __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+ PARROT_ASSERT_ARG(rb) \
+ , PARROT_ASSERT_ARG(b))
+#define ASSERT_ARGS_fetch_buf_le_16 __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+ PARROT_ASSERT_ARG(rb) \
+ , PARROT_ASSERT_ARG(b))
+#define ASSERT_ARGS_fetch_buf_le_32 __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+ PARROT_ASSERT_ARG(rb) \
+ , PARROT_ASSERT_ARG(b))
+#define ASSERT_ARGS_fetch_buf_le_4 __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+ PARROT_ASSERT_ARG(rb) \
+ , PARROT_ASSERT_ARG(b))
+#define ASSERT_ARGS_fetch_buf_le_8 __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+ PARROT_ASSERT_ARG(rb) \
+ , PARROT_ASSERT_ARG(b))
+#define ASSERT_ARGS_fetch_iv_be __attribute__unused__ int _ASSERT_ARGS_CHECK = (0)
+#define ASSERT_ARGS_fetch_iv_le __attribute__unused__ int _ASSERT_ARGS_CHECK = (0)
+#define ASSERT_ARGS_fetch_op_be __attribute__unused__ int _ASSERT_ARGS_CHECK = (0)
#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 = (\
PARROT_ASSERT_ARG(b))
+#define ASSERT_ARGS_fetch_op_le __attribute__unused__ int _ASSERT_ARGS_CHECK = (0)
#define ASSERT_ARGS_fetch_op_le_4 __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(b))
#define ASSERT_ARGS_fetch_op_le_8 __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
@@ -988,6 +1121,7 @@ is 1 I<per definition>.
*/
PARROT_CONST_FUNCTION
+PARROT_WARN_UNUSED_RESULT
size_t
PF_size_opcode(void)
{
@@ -1714,19 +1848,528 @@ PackFile_assign_transforms(ARGMOD(PackFile *pf))
#endif
}
+
/*
-=back
+=item C<static INTVAL fetch_iv_le(INTVAL w)>
+
+This function converts a 4 or 8 byte C<INTVAL> into little endian
+format. If the native format is already little endian, then no
+conversion is done.
+
+=cut
+
+*/
+
+PARROT_INLINE
+PARROT_WARN_UNUSED_RESULT
+PARROT_CONST_FUNCTION
+static INTVAL
+fetch_iv_le(INTVAL w)
+{
+#if !PARROT_BIGENDIAN
+ return w;
+#else
+# if INTVAL_SIZE == 4
+ return (w << 24) | ((w & 0xff00) << 8) | ((w & 0xff0000) >> 8) | (w >> 24);
+# else
+# if INTVAL_SIZE == 8
+ INTVAL r;
+
+ r = w << 56;
+ r |= (w & 0xff00) << 40;
+ r |= (w & 0xff0000) << 24;
+ r |= (w & 0xff000000) << 8;
+ r |= (w & 0xff00000000) >> 8;
+ r |= (w & 0xff0000000000) >> 24;
+ r |= (w & 0xff000000000000) >> 40;
+ r |= (w & 0xff00000000000000) >> 56;
+ return r;
+# else
+ exit_fatal(1, "Unsupported INTVAL_SIZE=%d\n",
+ INTVAL_SIZE);
+# endif
+# endif
+#endif
+}
+
+/*
+
+=item C<static INTVAL fetch_iv_be(INTVAL w)>
+
+This function converts a 4 or 8 byte C<INTVAL> into big endian format.
+If the native format is already big endian, then no conversion is done.
+
+=cut
+
+*/
+
+PARROT_INLINE
+PARROT_WARN_UNUSED_RESULT
+PARROT_CONST_FUNCTION
+static INTVAL
+fetch_iv_be(INTVAL w)
+{
+#if PARROT_BIGENDIAN
+ return w;
+#else
+# if INTVAL_SIZE == 4
+ return (w << 24) | ((w & 0xff00) << 8) | ((w & 0xff0000) >> 8) | (w >> 24);
+# else
+# if INTVAL_SIZE == 8
+ INTVAL r;
+ r = w << 56;
+ r |= (w & 0xff00) << 40;
+ r |= (w & 0xff0000) << 24;
+ r |= (w & 0xff000000) << 8;
+ r |= (w & 0xff00000000) >> 8;
+ r |= (w & 0xff0000000000) >> 24;
+ r |= (w & 0xff000000000000) >> 40;
+ r |= (w & 0xff00000000000000) >> 56;
+ return r;
+# else
+ exit_fatal(1, "Unsupported INTVAL_SIZE=%d\n", INTVAL_SIZE);
+# endif
+# endif
+#endif
+}
-=head1 HISTORY
+/*
+
+=item C<static opcode_t fetch_op_be(opcode_t w)>
-Initial review by leo 2003.11.21
+Same as C<fetch_iv_be> for opcode_t
-Most routines moved from F<src/packfile.c>.
+=cut
+
+*/
+
+PARROT_INLINE
+PARROT_WARN_UNUSED_RESULT
+PARROT_CONST_FUNCTION
+static opcode_t
+fetch_op_be(opcode_t w)
+{
+#if PARROT_BIGENDIAN
+ return w;
+#else
+# if OPCODE_T_SIZE == 4
+ return (w << 24) | ((w & 0x0000ff00) << 8) | ((w & 0x00ff0000) >> 8) |
+ ((w & 0xff000000) >> 24);
+# else
+ opcode_t r;
+
+ r = w << 56;
+ r |= (w & 0xff00) << 40;
+ r |= (w & 0xff0000) << 24;
+ r |= (w & 0xff000000) << 8;
+ r |= (w & 0xff00000000) >> 8;
+ r |= (w & 0xff0000000000) >> 24;
+ r |= (w & 0xff000000000000) >> 40;
+ r |= (w & 0xff00000000000000) >> 56;
+ return r;
+# endif
+#endif
+}
+
+/*
+
+=item C<static opcode_t fetch_op_le(opcode_t w)>
+
+Same as C<fetch_iv_le> for opcode_t
+
+=cut
+
+*/
+
+PARROT_INLINE
+PARROT_WARN_UNUSED_RESULT
+PARROT_CONST_FUNCTION
+static opcode_t
+fetch_op_le(opcode_t w)
+{
+#if !PARROT_BIGENDIAN
+ return w;
+#else
+# if OPCODE_T_SIZE == 4
+ return (w << 24) | ((w & 0x0000ff00) << 8) | ((w & 0x00ff0000) >> 8) |
+ ((w & 0xff000000) >> 24);
+# else
+ opcode_t r;
+
+ r = w << 56;
+ r |= (w & 0xff00) << 40;
+ r |= (w & 0xff0000) << 24;
+ r |= (w & 0xff000000) << 8;
+ r |= (w & 0xff00000000) >> 8;
+ r |= (w & 0xff0000000000) >> 24;
+ r |= (w & 0xff000000000000) >> 40;
+ r |= (w & 0xff00000000000000) >> 56;
+ return r;
+# endif
+#endif
+}
+
+/*
+
+=pod
+
+Unrolled routines for swapping various sizes from 32-128 bits. These
+should only be used if alignment is unknown or we are pulling something
+out of a padded buffer.
+
+=cut
+
+*/
+
+/*
+
+=item C<static void fetch_buf_be_4(unsigned char *rb, const unsigned char *b)>
+
+Converts a 4-byte big-endian buffer C<b> into a little-endian C<rb>.
+
+=cut
+
+*/
+
+PARROT_INLINE
+static void
+fetch_buf_be_4(ARGOUT(unsigned char *rb), ARGIN(const unsigned char *b))
+{
+#if PARROT_BIGENDIAN
+ memcpy(rb, b, 4);
+#else
+ rb[0] = b[3];
+ rb[1] = b[2];
+ rb[2] = b[1];
+ rb[3] = b[0];
+#endif
+}
+
+/*
-Renamed PackFile_* to PF_*
+=item C<static void fetch_buf_le_4(unsigned char *rb, const unsigned char *b)>
-Added 16 byte types.
+Converts a 4-byte little-endian buffer C<b> into a big-endian buffer C<rb>.
+
+=cut
+
+*/
+
+PARROT_INLINE
+static void
+fetch_buf_le_4(ARGOUT(unsigned char *rb), ARGIN(const unsigned char *b))
+{
+#if !PARROT_BIGENDIAN
+ memcpy(rb, b, 4);
+#else
+ rb[0] = b[3];
+ rb[1] = b[2];
+ rb[2] = b[1];
+ rb[3] = b[0];
+#endif
+}
+
+/*
+
+=item C<static void fetch_buf_be_8(unsigned char *rb, const unsigned char *b)>
+
+Converts an 8-byte big-endian buffer C<b> into a little-endian buffer C<rb>
+
+=cut
+
+*/
+
+PARROT_INLINE
+static void
+fetch_buf_be_8(ARGOUT(unsigned char *rb), ARGIN(const unsigned char *b))
+{
+#if PARROT_BIGENDIAN
+ memcpy(rb, b, 8);
+#else
+ rb[0] = b[7];
+ rb[1] = b[6];
+ rb[2] = b[5];
+ rb[3] = b[4];
+ rb[4] = b[3];
+ rb[5] = b[2];
+ rb[6] = b[1];
+ rb[7] = b[0];
+#endif
+}
+
+/*
+
+=item C<static void fetch_buf_le_8(unsigned char *rb, const unsigned char *b)>
+
+Converts an 8-byte little-endian buffer C<b> into a big-endian buffer C<rb>.
+
+=cut
+
+*/
+
+PARROT_INLINE
+static void
+fetch_buf_le_8(ARGOUT(unsigned char *rb), ARGIN(const unsigned char *b))
+{
+#if !PARROT_BIGENDIAN
+ memcpy(rb, b, 8);
+#else
+ rb[0] = b[7];
+ rb[1] = b[6];
+ rb[2] = b[5];
+ rb[3] = b[4];
+ rb[4] = b[3];
+ rb[5] = b[2];
+ rb[6] = b[1];
+ rb[7] = b[0];
+#endif
+}
+
+/*
+
+=item C<static void fetch_buf_le_12(unsigned char *rb, const unsigned char *b)>
+
+Converts a 12-byte little-endian buffer C<b> into a big-endian buffer C<b>.
+
+=cut
+
+*/
+
+PARROT_INLINE
+static void
+fetch_buf_le_12(ARGOUT(unsigned char *rb), ARGIN(const unsigned char *b))
+{
+#if !PARROT_BIGENDIAN
+ memcpy(rb, b, 12);
+#else
+ rb[0] = b[11];
+ rb[1] = b[10];
+ rb[2] = b[9];
+ rb[3] = b[8];
+ rb[4] = b[7];
+ rb[5] = b[6];
+ rb[6] = b[5];
+ rb[7] = b[4];
+ rb[8] = b[3];
+ rb[9] = b[2];
+ rb[10] = b[1];
+ rb[11] = b[0];
+#endif
+}
+
+/*
+
+=item C<static void fetch_buf_be_12(unsigned char *rb, const unsigned char *b)>
+
+Converts a 12-byte big-endian buffer C<b> into a little-endian buffer C<b>.
+
+=cut
+
+*/
+
+PARROT_INLINE
+static void
+fetch_buf_be_12(ARGOUT(unsigned char *rb), ARGIN(const unsigned char *b))
+{
+#if PARROT_BIGENDIAN
+ memcpy(rb, b, 12);
+#else
+ rb[0] = b[11];
+ rb[1] = b[10];
+ rb[2] = b[9];
+ rb[3] = b[8];
+ rb[4] = b[7];
+ rb[5] = b[6];
+ rb[6] = b[5];
+ rb[7] = b[4];
+ rb[8] = b[3];
+ rb[9] = b[2];
+ rb[10] = b[1];
+ rb[11] = b[0];
+#endif
+}
+
+/*
+
+=item C<static void fetch_buf_le_16(unsigned char *rb, const unsigned char *b)>
+
+Converts a 16-byte little-endian buffer C<b> into a big-endian buffer C<b>.
+
+=cut
+
+*/
+
+PARROT_INLINE
+static void
+fetch_buf_le_16(ARGOUT(unsigned char *rb), ARGIN(const unsigned char *b))
+{
+#if !PARROT_BIGENDIAN
+ memcpy(rb, b, 16);
+#else
+ rb[0] = b[15];
+ rb[1] = b[14];
+ rb[2] = b[13];
+ rb[3] = b[12];
+ rb[4] = b[11];
+ rb[5] = b[10];
+ rb[6] = b[9];
+ rb[7] = b[8];
+ rb[8] = b[7];
+ rb[9] = b[6];
+ rb[10] = b[5];
+ rb[11] = b[4];
+ rb[12] = b[3];
+ rb[13] = b[2];
+ rb[14] = b[1];
+ rb[15] = b[0];
+#endif
+}
+
+/*
+
+=item C<static void fetch_buf_be_16(unsigned char *rb, const unsigned char *b)>
+
+Converts a 16-byte big-endian buffer C<b> into a little-endian buffer C<b>.
+
+=cut
+
+*/
+
+PARROT_INLINE
+static void
+fetch_buf_be_16(ARGOUT(unsigned char *rb), ARGIN(const unsigned char *b))
+{
+#if PARROT_BIGENDIAN
+ memcpy(rb, b, 16);
+#else
+ rb[0] = b[15];
+ rb[1] = b[14];
+ rb[2] = b[13];
+ rb[3] = b[12];
+ rb[4] = b[11];
+ rb[5] = b[10];
+ rb[6] = b[9];
+ rb[7] = b[8];
+ rb[8] = b[7];
+ rb[9] = b[6];
+ rb[10] = b[5];
+ rb[11] = b[4];
+ rb[12] = b[3];
+ rb[13] = b[2];
+ rb[14] = b[1];
+ rb[15] = b[0];
+#endif
+}
+
+/*
+
+=item C<static void fetch_buf_le_32(unsigned char *rb, const unsigned char *b)>
+
+Converts a 32-byte little-endian buffer C<b> into a big-endian buffer C<b>.
+
+=cut
+
+*/
+
+PARROT_INLINE
+static void
+fetch_buf_le_32(ARGOUT(unsigned char *rb), ARGIN(const unsigned char *b))
+{
+#if !PARROT_BIGENDIAN
+ memcpy(rb, b, 32);
+#else
+ rb[0] = b[31];
+ rb[1] = b[30];
+ rb[2] = b[29];
+ rb[3] = b[28];
+ rb[4] = b[27];
+ rb[5] = b[26];
+ rb[6] = b[25];
+ rb[7] = b[24];
+ rb[8] = b[23];
+ rb[9] = b[22];
+ rb[10] = b[21];
+ rb[11] = b[20];
+ rb[12] = b[19];
+ rb[13] = b[18];
+ rb[14] = b[17];
+ rb[15] = b[16];
+ rb[16] = b[15];
+ rb[17] = b[14];
+ rb[18] = b[13];
+ rb[19] = b[12];
+ rb[20] = b[11];
+ rb[21] = b[10];
+ rb[22] = b[9];
+ rb[23] = b[8];
+ rb[24] = b[7];
+ rb[25] = b[6];
+ rb[26] = b[5];
+ rb[27] = b[4];
+ rb[28] = b[3];
+ rb[29] = b[2];
+ rb[30] = b[1];
+ rb[31] = b[0];
+#endif
+}
+
+/*
+
+=item C<static void fetch_buf_be_32(unsigned char *rb, const unsigned char *b)>
+
+Converts a 32-byte big-endian buffer C<b> into a little-endian buffer C<b>.
+
+=cut
+
+*/
+
+PARROT_INLINE
+static void
+fetch_buf_be_32(ARGOUT(unsigned char *rb), ARGIN(const unsigned char *b))
+{
+#if PARROT_BIGENDIAN
+ memcpy(rb, b, 32);
+#else
+ rb[0] = b[31];
+ rb[1] = b[30];
+ rb[2] = b[29];
+ rb[3] = b[28];
+ rb[4] = b[27];
+ rb[5] = b[26];
+ rb[6] = b[25];
+ rb[7] = b[24];
+ rb[8] = b[23];
+ rb[9] = b[22];
+ rb[10] = b[21];
+ rb[11] = b[20];
+ rb[12] = b[19];
+ rb[13] = b[18];
+ rb[14] = b[17];
+ rb[15] = b[16];
+ rb[16] = b[15];
+ rb[17] = b[14];
+ rb[18] = b[13];
+ rb[19] = b[12];
+ rb[20] = b[11];
+ rb[21] = b[10];
+ rb[22] = b[9];
+ rb[23] = b[8];
+ rb[24] = b[7];
+ rb[25] = b[6];
+ rb[26] = b[5];
+ rb[27] = b[4];
+ rb[28] = b[3];
+ rb[29] = b[2];
+ rb[30] = b[1];
+ rb[31] = b[0];
+#endif
+}
+
+
+/*
+
+=back
=head1 TODO
@@ -1742,7 +2385,6 @@ C<<PF_size_<type>()>> - return the needed size in C<opcode_t> units.
*/
-
/*
* Local variables:
* c-file-style: "parrot"
Please sign in to comment.
Something went wrong with that request. Please try again.