1 /* Implementation of the MVBITS intrinsic
2 Copyright (C) 2004 Free Software Foundation, Inc.
3 Contributed by Tobias Schlüter
5 This file is part of the GNU Fortran 95 runtime library (libgfortran).
7 Libgfortran is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public
9 License as published by the Free Software Foundation; either
10 version 2 of the License, or (at your option) any later version.
12 In addition to the permissions in the GNU General Public License, the
13 Free Software Foundation gives you unlimited permission to link the
14 compiled version of this file into combinations with other programs,
15 and to distribute those combinations without any restriction coming
16 from the use of this file. (The General Public License restrictions
17 do apply in other respects; for example, they cover modification of
18 the file, and distribution when not linked into a combine
21 Libgfortran is distributed in the hope that it will be useful,
22 but WITHOUT ANY WARRANTY; without even the implied warranty of
23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 GNU General Public License for more details.
26 You should have received a copy of the GNU General Public
27 License along with libgfortran; see the file COPYING. If not,
28 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
29 Boston, MA 02111-1307, USA. */
31 /* TODO: This should be replaced by a compiler builtin. */
34 #include <libgfortran.h>
38 /* MVBITS copies LEN bits starting at bit position FROMPOS from FROM
39 into TO, starting at bit position TOPOS. */
41 extern void SUB_NAME (const TYPE
*, const GFC_INTEGER_4
*,
42 const GFC_INTEGER_4
*, TYPE
*, const GFC_INTEGER_4
*);
43 export_proto(SUB_NAME
);
46 SUB_NAME (const TYPE
*from
, const GFC_INTEGER_4
*frompos
,
47 const GFC_INTEGER_4
*len
, TYPE
*to
, const GFC_INTEGER_4
*topos
)
49 TYPE oldbits
, newbits
, lenmask
;
51 lenmask
= (*len
== sizeof (TYPE
)*8) ? ~(TYPE
)0 : (1 << *len
) - 1;
52 newbits
= (((UTYPE
)(*from
) >> *frompos
) & lenmask
) << *topos
;
53 oldbits
= *to
& (~(lenmask
<< *topos
));
55 *to
= newbits
| oldbits
;
60 # define TYPE GFC_INTEGER_1
61 # define UTYPE GFC_UINTEGER_1
62 # define SUB_NAME mvbits_i1
68 # define TYPE GFC_INTEGER_2
69 # define UTYPE GFC_UINTEGER_2
70 # define SUB_NAME mvbits_i2
76 # define TYPE GFC_INTEGER_4
77 # define UTYPE GFC_UINTEGER_4
78 # define SUB_NAME mvbits_i4
84 # define TYPE GFC_INTEGER_8
85 # define UTYPE GFC_UINTEGER_8
86 # define SUB_NAME mvbits_i8