https://gcc.gnu.org/g:9fcc853542b05636617b9c3eaa503679846b4159
commit 9fcc853542b05636617b9c3eaa503679846b4159 Author: Mikael Morin <[email protected]> Date: Fri Nov 6 22:14:19 2026 +0100 Prise en charge span dans internal_unpack Diff: --- libgfortran/m4/in_unpack.m4 | 4 +- libgfortran/runtime/in_unpack_generic.c | 217 ++++++++++++++++---------------- 2 files changed, 115 insertions(+), 106 deletions(-) diff --git a/libgfortran/m4/in_unpack.m4 b/libgfortran/m4/in_unpack.m4 index 8d2f88ff3a72..2e9f8e8773b8 100644 --- a/libgfortran/m4/in_unpack.m4 +++ b/libgfortran/m4/in_unpack.m4 @@ -41,6 +41,7 @@ internal_unpack_'rtype_ccode` ('rtype` * d, const 'rtype_name` * src) index_type stride0; index_type dim; index_type dsize; + index_type span_units; 'rtype_name` * restrict dest; dest = d->base_addr; @@ -49,10 +50,11 @@ internal_unpack_'rtype_ccode` ('rtype` * d, const 'rtype_name` * src) dim = GFC_DESCRIPTOR_RANK (d); dsize = 1; + span_units = GFC_DESCRIPTOR_SPAN (d) / sizeof ('rtype_name`); for (index_type n = 0; n < dim; n++) { count[n] = 0; - stride[n] = GFC_DESCRIPTOR_STRIDE(d,n); + stride[n] = GFC_DESCRIPTOR_STRIDE(d,n) * span_units; extent[n] = GFC_DESCRIPTOR_EXTENT(d,n); if (extent[n] <= 0) return; diff --git a/libgfortran/runtime/in_unpack_generic.c b/libgfortran/runtime/in_unpack_generic.c index 99b4e598d710..80ed50f4140c 100644 --- a/libgfortran/runtime/in_unpack_generic.c +++ b/libgfortran/runtime/in_unpack_generic.c @@ -38,6 +38,7 @@ internal_unpack (gfc_array_char * d, const void * s) index_type stride0; index_type dim; index_type dsize; + index_type span; char *dest; const char *src; index_type size; @@ -48,151 +49,157 @@ internal_unpack (gfc_array_char * d, const void * s) if (s == dest || !s) return; + span = GFC_DESCRIPTOR SPAN (d); + size = GFC_DESCRIPTOR_SIZE (d); type_size = GFC_DTYPE_TYPE_SIZE (d); - switch (type_size) + if (span == size) { - case GFC_DTYPE_INTEGER_1: - case GFC_DTYPE_LOGICAL_1: - internal_unpack_1 ((gfc_array_i1 *) d, (const GFC_INTEGER_1 *) s); - return; + switch (type_size) + { + case GFC_DTYPE_INTEGER_1: + case GFC_DTYPE_LOGICAL_1: + internal_unpack_1 ((gfc_array_i1 *) d, (const GFC_INTEGER_1 *) s); + return; - case GFC_DTYPE_INTEGER_2: - case GFC_DTYPE_LOGICAL_2: - internal_unpack_2 ((gfc_array_i2 *) d, (const GFC_INTEGER_2 *) s); - return; + case GFC_DTYPE_INTEGER_2: + case GFC_DTYPE_LOGICAL_2: + internal_unpack_2 ((gfc_array_i2 *) d, (const GFC_INTEGER_2 *) s); + return; - case GFC_DTYPE_INTEGER_4: - case GFC_DTYPE_LOGICAL_4: - internal_unpack_4 ((gfc_array_i4 *) d, (const GFC_INTEGER_4 *) s); - return; + case GFC_DTYPE_INTEGER_4: + case GFC_DTYPE_LOGICAL_4: + internal_unpack_4 ((gfc_array_i4 *) d, (const GFC_INTEGER_4 *) s); + return; - case GFC_DTYPE_INTEGER_8: - case GFC_DTYPE_LOGICAL_8: - internal_unpack_8 ((gfc_array_i8 *) d, (const GFC_INTEGER_8 *) s); - return; + case GFC_DTYPE_INTEGER_8: + case GFC_DTYPE_LOGICAL_8: + internal_unpack_8 ((gfc_array_i8 *) d, (const GFC_INTEGER_8 *) s); + return; #if defined (HAVE_GFC_INTEGER_16) - case GFC_DTYPE_INTEGER_16: - case GFC_DTYPE_LOGICAL_16: - internal_unpack_16 ((gfc_array_i16 *) d, (const GFC_INTEGER_16 *) s); - return; + case GFC_DTYPE_INTEGER_16: + case GFC_DTYPE_LOGICAL_16: + internal_unpack_16 ((gfc_array_i16 *) d, (const GFC_INTEGER_16 *) s); + return; #endif - case GFC_DTYPE_REAL_4: - internal_unpack_r4 ((gfc_array_r4 *) d, (const GFC_REAL_4 *) s); - return; + case GFC_DTYPE_REAL_4: + internal_unpack_r4 ((gfc_array_r4 *) d, (const GFC_REAL_4 *) s); + return; - case GFC_DTYPE_REAL_8: - internal_unpack_r8 ((gfc_array_r8 *) d, (const GFC_REAL_8 *) s); - return; + case GFC_DTYPE_REAL_8: + internal_unpack_r8 ((gfc_array_r8 *) d, (const GFC_REAL_8 *) s); + return; -/* FIXME: This here is a hack, which will have to be removed when - the array descriptor is reworked. Currently, we don't store the - kind value for the type, but only the size. Because on targets with - _Float128, we have sizeof(long double) == sizeof(_Float128), - we cannot discriminate here and have to fall back to the generic - handling (which is suboptimal). */ + /* FIXME: This here is a hack, which will have to be removed when + the array descriptor is reworked. Currently, we don't store the + kind value for the type, but only the size. Because on targets with + _Float128, we have sizeof(long double) == sizeof(_Float128), + we cannot discriminate here and have to fall back to the generic + handling (which is suboptimal). */ #if !defined(GFC_REAL_16_IS_FLOAT128) # if defined(HAVE_GFC_REAL_10) - case GFC_DTYPE_REAL_10: - internal_unpack_r10 ((gfc_array_r10 *) d, (const GFC_REAL_10 *) s); - return; + case GFC_DTYPE_REAL_10: + internal_unpack_r10 ((gfc_array_r10 *) d, (const GFC_REAL_10 *) s); + return; # endif # if defined(HAVE_GFC_REAL_16) - case GFC_DTYPE_REAL_16: - internal_unpack_r16 ((gfc_array_r16 *) d, (const GFC_REAL_16 *) s); - return; + case GFC_DTYPE_REAL_16: + internal_unpack_r16 ((gfc_array_r16 *) d, (const GFC_REAL_16 *) s); + return; # endif #endif - case GFC_DTYPE_COMPLEX_4: - internal_unpack_c4 ((gfc_array_c4 *)d, (const GFC_COMPLEX_4 *)s); - return; + case GFC_DTYPE_COMPLEX_4: + internal_unpack_c4 ((gfc_array_c4 *)d, (const GFC_COMPLEX_4 *)s); + return; - case GFC_DTYPE_COMPLEX_8: - internal_unpack_c8 ((gfc_array_c8 *)d, (const GFC_COMPLEX_8 *)s); - return; + case GFC_DTYPE_COMPLEX_8: + internal_unpack_c8 ((gfc_array_c8 *)d, (const GFC_COMPLEX_8 *)s); + return; -/* FIXME: This here is a hack, which will have to be removed when - the array descriptor is reworked. Currently, we don't store the - kind value for the type, but only the size. Because on targets with - _Float128, we have sizeof(long double) == sizeof(_Float128), - we cannot discriminate here and have to fall back to the generic - handling (which is suboptimal). */ + /* FIXME: This here is a hack, which will have to be removed when + the array descriptor is reworked. Currently, we don't store the + kind value for the type, but only the size. Because on targets with + _Float128, we have sizeof(long double) == sizeof(_Float128), + we cannot discriminate here and have to fall back to the generic + handling (which is suboptimal). */ #if !defined(GFC_REAL_16_IS_FLOAT128) # if defined(HAVE_GFC_COMPLEX_10) - case GFC_DTYPE_COMPLEX_10: - internal_unpack_c10 ((gfc_array_c10 *) d, (const GFC_COMPLEX_10 *) s); - return; + case GFC_DTYPE_COMPLEX_10: + internal_unpack_c10 ((gfc_array_c10 *) d, (const GFC_COMPLEX_10 *) s); + return; # endif # if defined(HAVE_GFC_COMPLEX_16) - case GFC_DTYPE_COMPLEX_16: - internal_unpack_c16 ((gfc_array_c16 *) d, (const GFC_COMPLEX_16 *) s); - return; + case GFC_DTYPE_COMPLEX_16: + internal_unpack_c16 ((gfc_array_c16 *) d, (const GFC_COMPLEX_16 *) s); + return; # endif #endif - default: - break; + default: + break; + } } - switch (GFC_DESCRIPTOR_SIZE(d)) + if (span % size == 0) { - case 1: - internal_unpack_1 ((gfc_array_i1 *) d, (const GFC_INTEGER_1 *) s); - return; - - case 2: - if (GFC_UNALIGNED_2(d->base_addr) || GFC_UNALIGNED_2(s)) - break; - else + switch (GFC_DESCRIPTOR_SIZE(d)) { - internal_unpack_2 ((gfc_array_i2 *) d, (const GFC_INTEGER_2 *) s); - return; - } - - case 4: - if (GFC_UNALIGNED_4(d->base_addr) || GFC_UNALIGNED_4(s)) - break; - else - { - internal_unpack_4 ((gfc_array_i4 *) d, (const GFC_INTEGER_4 *) s); + case 1: + internal_unpack_1 ((gfc_array_i1 *) d, (const GFC_INTEGER_1 *) s); return; - } - case 8: - if (GFC_UNALIGNED_8(d->base_addr) || GFC_UNALIGNED_8(s)) - break; - else - { - internal_unpack_8 ((gfc_array_i8 *) d, (const GFC_INTEGER_8 *) s); - return; - } + case 2: + if (GFC_UNALIGNED_2(d->base_addr) || GFC_UNALIGNED_2(s)) + break; + else + { + internal_unpack_2 ((gfc_array_i2 *) d, (const GFC_INTEGER_2 *) s); + return; + } + + case 4: + if (GFC_UNALIGNED_4(d->base_addr) || GFC_UNALIGNED_4(s)) + break; + else + { + internal_unpack_4 ((gfc_array_i4 *) d, (const GFC_INTEGER_4 *) s); + return; + } + + case 8: + if (GFC_UNALIGNED_8(d->base_addr) || GFC_UNALIGNED_8(s)) + break; + else + { + internal_unpack_8 ((gfc_array_i8 *) d, (const GFC_INTEGER_8 *) s); + return; + } #ifdef HAVE_GFC_INTEGER_16 - case 16: - if (GFC_UNALIGNED_16(d->base_addr) || GFC_UNALIGNED_16(s)) - break; - else - { - internal_unpack_16 ((gfc_array_i16 *) d, (const GFC_INTEGER_16 *) s); - return; - } + case 16: + if (GFC_UNALIGNED_16(d->base_addr) || GFC_UNALIGNED_16(s)) + break; + else + { + internal_unpack_16 ((gfc_array_i16 *) d, (const GFC_INTEGER_16 *) s); + return; + } #endif - default: - break; + default: + break; + } } - size = GFC_DESCRIPTOR_SIZE (d); - dim = GFC_DESCRIPTOR_RANK (d); - dsize = 1; + dsize = size; for (index_type n = 0; n < dim; n++) { count[n] = 0; - stride[n] = GFC_DESCRIPTOR_STRIDE(d,n); + stride[n] = GFC_DESCRIPTOR_STRIDE_BYTES(d,n); extent[n] = GFC_DESCRIPTOR_EXTENT(d,n); if (extent[n] <= 0) return; @@ -207,11 +214,11 @@ internal_unpack (gfc_array_char * d, const void * s) if (dsize != 0) { - memcpy (dest, src, dsize * size); + memcpy (dest, src, dsize); return; } - stride0 = stride[0] * size; + stride0 = stride[0]; while (dest) { @@ -230,7 +237,7 @@ internal_unpack (gfc_array_char * d, const void * s) count[n] = 0; /* We could precalculate these products, but this is a less frequently used path so probably not worth it. */ - dest -= stride[n] * extent[n] * size; + dest -= stride[n] * extent[n]; n++; if (n == dim) { @@ -240,7 +247,7 @@ internal_unpack (gfc_array_char * d, const void * s) else { count[n]++; - dest += stride[n] * size; + dest += stride[n]; } } }
