This is the mail archive of the fortran@gcc.gnu.org mailing list for the GNU Fortran project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[gfortran] Fix PR17631: intrinsic MVBITS missing


This is an implmentation of the MVBITS intrinsic. It is not complete in that
it doesn't support integer kinds besides integer*4, but since implementing
this in the library isn't a really smart thing to do (MVBITS should take some
10 assembler instructions to implement) I didn't bother to either learn m4 or
implement some preprocessor hackery to support other types as well.

(I didn't manage creating a builtin implmentation, because MVBITS is a
subroutine, and we only implement builtin functions. Feel free to fix this.)

Built on i686. i also verified that the intrinsic works as expected and will
add a testcase alongside the implementation.

- Tobi

Index: Makefile.am
===================================================================
RCS file: /cvs/gcc/gcc/libgfortran/Makefile.am,v
retrieving revision 1.18
diff -u -p -r1.18 Makefile.am
--- Makefile.am 15 Sep 2004 14:09:12 -0000      1.18
+++ Makefile.am 23 Sep 2004 18:37:50 -0000
@@ -52,6 +52,7 @@ intrinsics/etime.c \
 intrinsics/getcwd.c \
 intrinsics/getXid.c \
 intrinsics/ishftc.c \
+intrinsics/mvbits.c \
 intrinsics/pack_generic.c \
 intrinsics/size.c \
 intrinsics/spread_generic.c \
/* Implementation of the MVBITS intrinsic
   Copyright (C) 2004 Free Software Foundation, Inc.
   Contributed by Tobias Schlüter

This file is part of the GNU Fortran 95 runtime library (libgfortran).

Libgfortran is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

Libgfortran is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with libgfortran; see the file COPYING.LIB.  If not,
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.  */

/* TODO: This should be replaced by a compiler builtin.  */

#include <libgfortran.h>

/* MVBITS copies LEN bits starting at bit position FROMPOS from FROM
   into TO, starting at bit position TOPOS.  */

void 
prefix (mvbits) (GFC_INTEGER_4 *from, GFC_INTEGER_4 *frompos,
		 GFC_INTEGER_4 *len, GFC_INTEGER_4 *to,
		 GFC_INTEGER_4 *topos)
{
  GFC_INTEGER_4 oldbits, newbits, lenmask;

  lenmask = (1 << *len) - 1;
  newbits = ((*from & (lenmask << *frompos)) >> *frompos) << *topos;
  oldbits = *to & !(lenmask << *topos);

  *to = newbits | oldbits;
}

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]