X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/5ab49fcc1c0f8ba0a9353ce79388bb6d0ab12394..b01b2a3a3042334245c03df9ec70b62e197fecf0:/src/gras/DataDesc/ddt_convert.c diff --git a/src/gras/DataDesc/ddt_convert.c b/src/gras/DataDesc/ddt_convert.c index d08721910c..efc4946f04 100644 --- a/src/gras/DataDesc/ddt_convert.c +++ b/src/gras/DataDesc/ddt_convert.c @@ -8,24 +8,62 @@ /* This program is free software; you can redistribute it and/or modify it under the terms of the license (GNU LGPL) which comes with this package. */ -#include "DataDesc/datadesc_private.h" +/************************************************************************/ +/* C combines the power of assembler with the portability of assembler. */ +/************************************************************************/ +#include "gras/DataDesc/datadesc_private.h" + +XBT_LOG_NEW_DEFAULT_SUBCATEGORY(ddt_convert,datadesc, + "Inter-architecture convertions"); /*** - *** Table of all known architectures. + *** Table of all known architectures: + *** + *** l C<1/1> I<2/2:4/4:4/4:8/4> P<4/4:4/4> D<4/4:8/4> + *** l C<1/1> I<2/2:4/4:8/8:8/8> P<4/4:4/4> D<4/4:8/8> + *** B C<1/1> I<2/2:4/4:4/8:8/8> P<4/4:4/4> D<4/4:8/4> + *** B C<1/1> I<2/2:4/8:8/8:8/8> P<4/4:4/4> D<4/4:8/4> + *** B C:1/1: I:2/2:4/4:4/4:8/8: P:4/4:4/4: D:4/4:8/4: AIX + *** B C:1/1: I:2/2:4/2:4/2:8/2: P:4/2:4/2: D:4/2:8/2: ARM ***/ const gras_arch_desc_t gras_arches[gras_arch_count] = { - {"i386", 0, {1,2,4,4,8, 4,4, 4,8}}, - {"ppc", 1. {1,2,4,4,8, 4,4, 4,8}} + {"little32", 0, {1,2,4,4,8, 4,4, 4,8}, + {1,2,4,4,4, 4,4, 4,4}}, + + {"little64", 0, {1,2,4,8,8, 8,8, 4,8}, + {1,2,4,8,8, 8,8, 4,8}}, + + {"big32", 1, {1,2,4,4,8, 4,4, 4,8}, + {1,2,4,4,8, 4,4, 4,8}}, + + {"big64", 1, {1,2,4,8,8, 8,8, 4,8}, + {1,2,4,8,8, 8,8, 4,8}}, + + {"aix", 1, {1,2,4,4,8, 4,4, 4,8}, + {1,2,4,4,8, 4,4, 4,4}}, + + {"arm", 1, {1,2,4,4,8, 4,4, 4,8}, + {1,2,2,2,2, 2,2, 2,2}} + }; const char *gras_datadesc_arch_name(int code) { - if (code < 0 || code > gras_arch_count) - return "[arch code out of bound]"; + if (code < 0 || code >= gras_arch_count) + return "[unknown arch]"; return gras_arches[code].name; } +/** + * Local function doing the grunt work + */ +static void +gras_dd_reverse_bytes(void *to, + const void *from, + size_t length); + + /** * gras_dd_convert_elm: * @@ -33,17 +71,172 @@ const char *gras_datadesc_arch_name(int code) { * The data to be converted is stored in @src, and is to be stored in @dst. * Both pointers may be the same location if no resizing is needed. */ -gras_error_t -gras_dd_convert_elm(gras_datadesc_type_t *type, +xbt_error_t +gras_dd_convert_elm(gras_datadesc_type_t type, int count, int r_arch, void *src, void *dst) { + gras_dd_cat_scalar_t scal = type->category.scalar_data; + int cpt; + const void *r_data; + void *l_data; + unsigned long r_size, l_size; + /* Hexadecimal displayer + union { + char c[sizeof(int)]; + int i; + } tester; + */ + + xbt_assert(type->category_code == e_gras_datadesc_type_cat_scalar); + xbt_assert(r_arch != GRAS_THISARCH); + + r_size = type->size[r_arch]; + l_size = type->size[GRAS_THISARCH]; + DEBUG4("r_size=%lu l_size=%lu, src=%p dst=%p", + r_size,l_size,src,dst); + + DEBUG2("remote=%c local=%c", gras_arches[r_arch].endian?'B':'l', + gras_arches[GRAS_THISARCH].endian?'B':'l'); + + if(r_size != l_size) { + for(cpt = 0, r_data = src, l_data = dst; + cpt < count; + cpt++, + r_data = (char *)r_data + r_size, + l_data = (char *)l_data + l_size) { + + /* + fprintf(stderr,"r_data="); + for (cpt=0; cpt 127) != (*l_sign > 127)) { + if(*r_sign > 127) + *l_sign += 128; + else + *l_sign -= 128; + } + } + } else { + DEBUG1("Extend %d bytes", sizeChange); + if (scal.encoding != e_gras_dd_scalar_encoding_sint) { + DEBUG0("This is signed"); + padding = 0; /* pad unsigned with 0 */ + } else { + /* extend sign */ + r_sign = gras_arches[r_arch].endian ? ((unsigned char*)r_data + r_size - 1) + : (unsigned char*)r_data; + padding = (*r_sign > 127) ? 0xff : 0; + } + + memset(l_data, padding, l_size); + memcpy(!gras_arches[r_arch].endian ? l_data : ((char *)l_data + sizeChange), + r_data, r_size); + + /* + fprintf(stderr,"r_data="); + for (cpt=0; cpt 1) { + + for(cpt = 0, r_data=dst, l_data=dst; + cpt < count; + cpt++, + r_data = (char *)r_data + l_size, /* resizing already done */ + l_data = (char *)l_data + l_size) { + + DEBUG1("Flip elm %d",cpt); + gras_dd_reverse_bytes(l_data, r_data, l_size); + } + } return no_error; } +static void +gras_dd_reverse_bytes(void *to, + const void *from, + size_t length) { + + char charBegin; + const char *fromBegin; + const char *fromEnd; + char *toBegin; + char *toEnd; + + for(fromBegin = (const char *)from, + fromEnd = fromBegin + length - 1, + toBegin = (char *)to, + toEnd = toBegin + length - 1; + + fromBegin <= fromEnd; + + fromBegin++, fromEnd--, + toBegin++, toEnd--) { + + charBegin = *fromBegin; + *toBegin = *fromEnd; + *toEnd = charBegin; + } +} + + /** * gras_arch_selfid: *