OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [tags/] [gnu-dev/] [fsf-gcc-snapshot-1-mar-12/] [or1k-gcc/] [libgfortran/] [generated/] [unpack_r10.c] - Diff between revs 733 and 783

Only display areas with differences | Details | Blame | View Log

Rev 733 Rev 783
/* Specific implementation of the UNPACK intrinsic
/* Specific implementation of the UNPACK intrinsic
   Copyright 2008, 2009 Free Software Foundation, Inc.
   Copyright 2008, 2009 Free Software Foundation, Inc.
   Contributed by Thomas Koenig <tkoenig@gcc.gnu.org>, based on
   Contributed by Thomas Koenig <tkoenig@gcc.gnu.org>, based on
   unpack_generic.c by Paul Brook <paul@nowt.org>.
   unpack_generic.c by Paul Brook <paul@nowt.org>.
 
 
This file is part of the GNU Fortran 95 runtime library (libgfortran).
This file is part of the GNU Fortran 95 runtime library (libgfortran).
 
 
Libgfortran is free software; you can redistribute it and/or
Libgfortran is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public
modify it under the terms of the GNU General Public
License as published by the Free Software Foundation; either
License as published by the Free Software Foundation; either
version 3 of the License, or (at your option) any later version.
version 3 of the License, or (at your option) any later version.
 
 
Ligbfortran is distributed in the hope that it will be useful,
Ligbfortran is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.
GNU General Public License for more details.
 
 
Under Section 7 of GPL version 3, you are granted additional
Under Section 7 of GPL version 3, you are granted additional
permissions described in the GCC Runtime Library Exception, version
permissions described in the GCC Runtime Library Exception, version
3.1, as published by the Free Software Foundation.
3.1, as published by the Free Software Foundation.
 
 
You should have received a copy of the GNU General Public License and
You should have received a copy of the GNU General Public License and
a copy of the GCC Runtime Library Exception along with this program;
a copy of the GCC Runtime Library Exception along with this program;
see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
<http://www.gnu.org/licenses/>.  */
<http://www.gnu.org/licenses/>.  */
 
 
#include "libgfortran.h"
#include "libgfortran.h"
#include <stdlib.h>
#include <stdlib.h>
#include <assert.h>
#include <assert.h>
#include <string.h>
#include <string.h>
 
 
 
 
#if defined (HAVE_GFC_REAL_10)
#if defined (HAVE_GFC_REAL_10)
 
 
void
void
unpack0_r10 (gfc_array_r10 *ret, const gfc_array_r10 *vector,
unpack0_r10 (gfc_array_r10 *ret, const gfc_array_r10 *vector,
                 const gfc_array_l1 *mask, const GFC_REAL_10 *fptr)
                 const gfc_array_l1 *mask, const GFC_REAL_10 *fptr)
{
{
  /* r.* indicates the return array.  */
  /* r.* indicates the return array.  */
  index_type rstride[GFC_MAX_DIMENSIONS];
  index_type rstride[GFC_MAX_DIMENSIONS];
  index_type rstride0;
  index_type rstride0;
  index_type rs;
  index_type rs;
  GFC_REAL_10 * restrict rptr;
  GFC_REAL_10 * restrict rptr;
  /* v.* indicates the vector array.  */
  /* v.* indicates the vector array.  */
  index_type vstride0;
  index_type vstride0;
  GFC_REAL_10 *vptr;
  GFC_REAL_10 *vptr;
  /* Value for field, this is constant.  */
  /* Value for field, this is constant.  */
  const GFC_REAL_10 fval = *fptr;
  const GFC_REAL_10 fval = *fptr;
  /* m.* indicates the mask array.  */
  /* m.* indicates the mask array.  */
  index_type mstride[GFC_MAX_DIMENSIONS];
  index_type mstride[GFC_MAX_DIMENSIONS];
  index_type mstride0;
  index_type mstride0;
  const GFC_LOGICAL_1 *mptr;
  const GFC_LOGICAL_1 *mptr;
 
 
  index_type count[GFC_MAX_DIMENSIONS];
  index_type count[GFC_MAX_DIMENSIONS];
  index_type extent[GFC_MAX_DIMENSIONS];
  index_type extent[GFC_MAX_DIMENSIONS];
  index_type n;
  index_type n;
  index_type dim;
  index_type dim;
 
 
  int empty;
  int empty;
  int mask_kind;
  int mask_kind;
 
 
  empty = 0;
  empty = 0;
 
 
  mptr = mask->data;
  mptr = mask->data;
 
 
  /* Use the same loop for all logical types, by using GFC_LOGICAL_1
  /* Use the same loop for all logical types, by using GFC_LOGICAL_1
     and using shifting to address size and endian issues.  */
     and using shifting to address size and endian issues.  */
 
 
  mask_kind = GFC_DESCRIPTOR_SIZE (mask);
  mask_kind = GFC_DESCRIPTOR_SIZE (mask);
 
 
  if (mask_kind == 1 || mask_kind == 2 || mask_kind == 4 || mask_kind == 8
  if (mask_kind == 1 || mask_kind == 2 || mask_kind == 4 || mask_kind == 8
#ifdef HAVE_GFC_LOGICAL_16
#ifdef HAVE_GFC_LOGICAL_16
      || mask_kind == 16
      || mask_kind == 16
#endif
#endif
      )
      )
    {
    {
      /*  Do not convert a NULL pointer as we use test for NULL below.  */
      /*  Do not convert a NULL pointer as we use test for NULL below.  */
      if (mptr)
      if (mptr)
        mptr = GFOR_POINTER_TO_L1 (mptr, mask_kind);
        mptr = GFOR_POINTER_TO_L1 (mptr, mask_kind);
    }
    }
  else
  else
    runtime_error ("Funny sized logical array");
    runtime_error ("Funny sized logical array");
 
 
  if (ret->data == NULL)
  if (ret->data == NULL)
    {
    {
      /* The front end has signalled that we need to populate the
      /* The front end has signalled that we need to populate the
         return array descriptor.  */
         return array descriptor.  */
      dim = GFC_DESCRIPTOR_RANK (mask);
      dim = GFC_DESCRIPTOR_RANK (mask);
      rs = 1;
      rs = 1;
      for (n = 0; n < dim; n++)
      for (n = 0; n < dim; n++)
        {
        {
          count[n] = 0;
          count[n] = 0;
          GFC_DIMENSION_SET(ret->dim[n], 0,
          GFC_DIMENSION_SET(ret->dim[n], 0,
                            GFC_DESCRIPTOR_EXTENT(mask,n) - 1, rs);
                            GFC_DESCRIPTOR_EXTENT(mask,n) - 1, rs);
          extent[n] = GFC_DESCRIPTOR_EXTENT(ret,n);
          extent[n] = GFC_DESCRIPTOR_EXTENT(ret,n);
          empty = empty || extent[n] <= 0;
          empty = empty || extent[n] <= 0;
          rstride[n] = GFC_DESCRIPTOR_STRIDE(ret,n);
          rstride[n] = GFC_DESCRIPTOR_STRIDE(ret,n);
          mstride[n] = GFC_DESCRIPTOR_STRIDE_BYTES(mask,n);
          mstride[n] = GFC_DESCRIPTOR_STRIDE_BYTES(mask,n);
          rs *= extent[n];
          rs *= extent[n];
        }
        }
      ret->offset = 0;
      ret->offset = 0;
      ret->data = internal_malloc_size (rs * sizeof (GFC_REAL_10));
      ret->data = internal_malloc_size (rs * sizeof (GFC_REAL_10));
    }
    }
  else
  else
    {
    {
      dim = GFC_DESCRIPTOR_RANK (ret);
      dim = GFC_DESCRIPTOR_RANK (ret);
      for (n = 0; n < dim; n++)
      for (n = 0; n < dim; n++)
        {
        {
          count[n] = 0;
          count[n] = 0;
          extent[n] = GFC_DESCRIPTOR_EXTENT(ret,n);
          extent[n] = GFC_DESCRIPTOR_EXTENT(ret,n);
          empty = empty || extent[n] <= 0;
          empty = empty || extent[n] <= 0;
          rstride[n] = GFC_DESCRIPTOR_STRIDE(ret,n);
          rstride[n] = GFC_DESCRIPTOR_STRIDE(ret,n);
          mstride[n] = GFC_DESCRIPTOR_STRIDE_BYTES(mask,n);
          mstride[n] = GFC_DESCRIPTOR_STRIDE_BYTES(mask,n);
        }
        }
      if (rstride[0] == 0)
      if (rstride[0] == 0)
        rstride[0] = 1;
        rstride[0] = 1;
    }
    }
 
 
  if (empty)
  if (empty)
    return;
    return;
 
 
  if (mstride[0] == 0)
  if (mstride[0] == 0)
    mstride[0] = 1;
    mstride[0] = 1;
 
 
  vstride0 = GFC_DESCRIPTOR_STRIDE(vector,0);
  vstride0 = GFC_DESCRIPTOR_STRIDE(vector,0);
  if (vstride0 == 0)
  if (vstride0 == 0)
    vstride0 = 1;
    vstride0 = 1;
  rstride0 = rstride[0];
  rstride0 = rstride[0];
  mstride0 = mstride[0];
  mstride0 = mstride[0];
  rptr = ret->data;
  rptr = ret->data;
  vptr = vector->data;
  vptr = vector->data;
 
 
  while (rptr)
  while (rptr)
    {
    {
      if (*mptr)
      if (*mptr)
        {
        {
          /* From vector.  */
          /* From vector.  */
          *rptr = *vptr;
          *rptr = *vptr;
          vptr += vstride0;
          vptr += vstride0;
        }
        }
      else
      else
        {
        {
          /* From field.  */
          /* From field.  */
          *rptr = fval;
          *rptr = fval;
        }
        }
      /* Advance to the next element.  */
      /* Advance to the next element.  */
      rptr += rstride0;
      rptr += rstride0;
      mptr += mstride0;
      mptr += mstride0;
      count[0]++;
      count[0]++;
      n = 0;
      n = 0;
      while (count[n] == extent[n])
      while (count[n] == extent[n])
        {
        {
          /* When we get to the end of a dimension, reset it and increment
          /* When we get to the end of a dimension, reset it and increment
             the next dimension.  */
             the next dimension.  */
          count[n] = 0;
          count[n] = 0;
          /* We could precalculate these products, but this is a less
          /* We could precalculate these products, but this is a less
             frequently used path so probably not worth it.  */
             frequently used path so probably not worth it.  */
          rptr -= rstride[n] * extent[n];
          rptr -= rstride[n] * extent[n];
          mptr -= mstride[n] * extent[n];
          mptr -= mstride[n] * extent[n];
          n++;
          n++;
          if (n >= dim)
          if (n >= dim)
            {
            {
              /* Break out of the loop.  */
              /* Break out of the loop.  */
              rptr = NULL;
              rptr = NULL;
              break;
              break;
            }
            }
          else
          else
            {
            {
              count[n]++;
              count[n]++;
              rptr += rstride[n];
              rptr += rstride[n];
              mptr += mstride[n];
              mptr += mstride[n];
            }
            }
        }
        }
    }
    }
}
}
 
 
void
void
unpack1_r10 (gfc_array_r10 *ret, const gfc_array_r10 *vector,
unpack1_r10 (gfc_array_r10 *ret, const gfc_array_r10 *vector,
                 const gfc_array_l1 *mask, const gfc_array_r10 *field)
                 const gfc_array_l1 *mask, const gfc_array_r10 *field)
{
{
  /* r.* indicates the return array.  */
  /* r.* indicates the return array.  */
  index_type rstride[GFC_MAX_DIMENSIONS];
  index_type rstride[GFC_MAX_DIMENSIONS];
  index_type rstride0;
  index_type rstride0;
  index_type rs;
  index_type rs;
  GFC_REAL_10 * restrict rptr;
  GFC_REAL_10 * restrict rptr;
  /* v.* indicates the vector array.  */
  /* v.* indicates the vector array.  */
  index_type vstride0;
  index_type vstride0;
  GFC_REAL_10 *vptr;
  GFC_REAL_10 *vptr;
  /* f.* indicates the field array.  */
  /* f.* indicates the field array.  */
  index_type fstride[GFC_MAX_DIMENSIONS];
  index_type fstride[GFC_MAX_DIMENSIONS];
  index_type fstride0;
  index_type fstride0;
  const GFC_REAL_10 *fptr;
  const GFC_REAL_10 *fptr;
  /* m.* indicates the mask array.  */
  /* m.* indicates the mask array.  */
  index_type mstride[GFC_MAX_DIMENSIONS];
  index_type mstride[GFC_MAX_DIMENSIONS];
  index_type mstride0;
  index_type mstride0;
  const GFC_LOGICAL_1 *mptr;
  const GFC_LOGICAL_1 *mptr;
 
 
  index_type count[GFC_MAX_DIMENSIONS];
  index_type count[GFC_MAX_DIMENSIONS];
  index_type extent[GFC_MAX_DIMENSIONS];
  index_type extent[GFC_MAX_DIMENSIONS];
  index_type n;
  index_type n;
  index_type dim;
  index_type dim;
 
 
  int empty;
  int empty;
  int mask_kind;
  int mask_kind;
 
 
  empty = 0;
  empty = 0;
 
 
  mptr = mask->data;
  mptr = mask->data;
 
 
  /* Use the same loop for all logical types, by using GFC_LOGICAL_1
  /* Use the same loop for all logical types, by using GFC_LOGICAL_1
     and using shifting to address size and endian issues.  */
     and using shifting to address size and endian issues.  */
 
 
  mask_kind = GFC_DESCRIPTOR_SIZE (mask);
  mask_kind = GFC_DESCRIPTOR_SIZE (mask);
 
 
  if (mask_kind == 1 || mask_kind == 2 || mask_kind == 4 || mask_kind == 8
  if (mask_kind == 1 || mask_kind == 2 || mask_kind == 4 || mask_kind == 8
#ifdef HAVE_GFC_LOGICAL_16
#ifdef HAVE_GFC_LOGICAL_16
      || mask_kind == 16
      || mask_kind == 16
#endif
#endif
      )
      )
    {
    {
      /*  Do not convert a NULL pointer as we use test for NULL below.  */
      /*  Do not convert a NULL pointer as we use test for NULL below.  */
      if (mptr)
      if (mptr)
        mptr = GFOR_POINTER_TO_L1 (mptr, mask_kind);
        mptr = GFOR_POINTER_TO_L1 (mptr, mask_kind);
    }
    }
  else
  else
    runtime_error ("Funny sized logical array");
    runtime_error ("Funny sized logical array");
 
 
  if (ret->data == NULL)
  if (ret->data == NULL)
    {
    {
      /* The front end has signalled that we need to populate the
      /* The front end has signalled that we need to populate the
         return array descriptor.  */
         return array descriptor.  */
      dim = GFC_DESCRIPTOR_RANK (mask);
      dim = GFC_DESCRIPTOR_RANK (mask);
      rs = 1;
      rs = 1;
      for (n = 0; n < dim; n++)
      for (n = 0; n < dim; n++)
        {
        {
          count[n] = 0;
          count[n] = 0;
          GFC_DIMENSION_SET(ret->dim[n], 0,
          GFC_DIMENSION_SET(ret->dim[n], 0,
                            GFC_DESCRIPTOR_EXTENT(mask,n) - 1, rs);
                            GFC_DESCRIPTOR_EXTENT(mask,n) - 1, rs);
          extent[n] = GFC_DESCRIPTOR_EXTENT(ret,n);
          extent[n] = GFC_DESCRIPTOR_EXTENT(ret,n);
          empty = empty || extent[n] <= 0;
          empty = empty || extent[n] <= 0;
          rstride[n] = GFC_DESCRIPTOR_STRIDE(ret,n);
          rstride[n] = GFC_DESCRIPTOR_STRIDE(ret,n);
          fstride[n] = GFC_DESCRIPTOR_STRIDE(field,n);
          fstride[n] = GFC_DESCRIPTOR_STRIDE(field,n);
          mstride[n] = GFC_DESCRIPTOR_STRIDE_BYTES(mask,n);
          mstride[n] = GFC_DESCRIPTOR_STRIDE_BYTES(mask,n);
          rs *= extent[n];
          rs *= extent[n];
        }
        }
      ret->offset = 0;
      ret->offset = 0;
      ret->data = internal_malloc_size (rs * sizeof (GFC_REAL_10));
      ret->data = internal_malloc_size (rs * sizeof (GFC_REAL_10));
    }
    }
  else
  else
    {
    {
      dim = GFC_DESCRIPTOR_RANK (ret);
      dim = GFC_DESCRIPTOR_RANK (ret);
      for (n = 0; n < dim; n++)
      for (n = 0; n < dim; n++)
        {
        {
          count[n] = 0;
          count[n] = 0;
          extent[n] = GFC_DESCRIPTOR_EXTENT(ret,n);
          extent[n] = GFC_DESCRIPTOR_EXTENT(ret,n);
          empty = empty || extent[n] <= 0;
          empty = empty || extent[n] <= 0;
          rstride[n] = GFC_DESCRIPTOR_STRIDE(ret,n);
          rstride[n] = GFC_DESCRIPTOR_STRIDE(ret,n);
          fstride[n] = GFC_DESCRIPTOR_STRIDE(field,n);
          fstride[n] = GFC_DESCRIPTOR_STRIDE(field,n);
          mstride[n] = GFC_DESCRIPTOR_STRIDE_BYTES(mask,n);
          mstride[n] = GFC_DESCRIPTOR_STRIDE_BYTES(mask,n);
        }
        }
      if (rstride[0] == 0)
      if (rstride[0] == 0)
        rstride[0] = 1;
        rstride[0] = 1;
    }
    }
 
 
  if (empty)
  if (empty)
    return;
    return;
 
 
  if (fstride[0] == 0)
  if (fstride[0] == 0)
    fstride[0] = 1;
    fstride[0] = 1;
  if (mstride[0] == 0)
  if (mstride[0] == 0)
    mstride[0] = 1;
    mstride[0] = 1;
 
 
  vstride0 = GFC_DESCRIPTOR_STRIDE(vector,0);
  vstride0 = GFC_DESCRIPTOR_STRIDE(vector,0);
  if (vstride0 == 0)
  if (vstride0 == 0)
    vstride0 = 1;
    vstride0 = 1;
  rstride0 = rstride[0];
  rstride0 = rstride[0];
  fstride0 = fstride[0];
  fstride0 = fstride[0];
  mstride0 = mstride[0];
  mstride0 = mstride[0];
  rptr = ret->data;
  rptr = ret->data;
  fptr = field->data;
  fptr = field->data;
  vptr = vector->data;
  vptr = vector->data;
 
 
  while (rptr)
  while (rptr)
    {
    {
      if (*mptr)
      if (*mptr)
        {
        {
          /* From vector.  */
          /* From vector.  */
          *rptr = *vptr;
          *rptr = *vptr;
          vptr += vstride0;
          vptr += vstride0;
        }
        }
      else
      else
        {
        {
          /* From field.  */
          /* From field.  */
          *rptr = *fptr;
          *rptr = *fptr;
        }
        }
      /* Advance to the next element.  */
      /* Advance to the next element.  */
      rptr += rstride0;
      rptr += rstride0;
      fptr += fstride0;
      fptr += fstride0;
      mptr += mstride0;
      mptr += mstride0;
      count[0]++;
      count[0]++;
      n = 0;
      n = 0;
      while (count[n] == extent[n])
      while (count[n] == extent[n])
        {
        {
          /* When we get to the end of a dimension, reset it and increment
          /* When we get to the end of a dimension, reset it and increment
             the next dimension.  */
             the next dimension.  */
          count[n] = 0;
          count[n] = 0;
          /* We could precalculate these products, but this is a less
          /* We could precalculate these products, but this is a less
             frequently used path so probably not worth it.  */
             frequently used path so probably not worth it.  */
          rptr -= rstride[n] * extent[n];
          rptr -= rstride[n] * extent[n];
          fptr -= fstride[n] * extent[n];
          fptr -= fstride[n] * extent[n];
          mptr -= mstride[n] * extent[n];
          mptr -= mstride[n] * extent[n];
          n++;
          n++;
          if (n >= dim)
          if (n >= dim)
            {
            {
              /* Break out of the loop.  */
              /* Break out of the loop.  */
              rptr = NULL;
              rptr = NULL;
              break;
              break;
            }
            }
          else
          else
            {
            {
              count[n]++;
              count[n]++;
              rptr += rstride[n];
              rptr += rstride[n];
              fptr += fstride[n];
              fptr += fstride[n];
              mptr += mstride[n];
              mptr += mstride[n];
            }
            }
        }
        }
    }
    }
}
}
 
 
#endif
#endif
 
 
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.