]>
Commit | Line | Data |
---|---|---|
1ee3acfb | 1 | /* Implementation of the MVBITS intrinsic |
43ff4e9a | 2 | Copyright (C) 2004, 2006 Free Software Foundation, Inc. |
56746a07 | 3 | Contributed by Tobias Schlüter |
1ee3acfb AP |
4 | |
5 | This file is part of the GNU Fortran 95 runtime library (libgfortran). | |
6 | ||
7 | Libgfortran is free software; you can redistribute it and/or | |
57dea9f6 | 8 | modify it under the terms of the GNU General Public |
1ee3acfb | 9 | License as published by the Free Software Foundation; either |
57dea9f6 TM |
10 | version 2 of the License, or (at your option) any later version. |
11 | ||
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 | |
19 | executable.) | |
1ee3acfb AP |
20 | |
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 | |
57dea9f6 | 24 | GNU General Public License for more details. |
1ee3acfb | 25 | |
57dea9f6 TM |
26 | You should have received a copy of the GNU General Public |
27 | License along with libgfortran; see the file COPYING. If not, | |
fe2ae685 KC |
28 | write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
29 | Boston, MA 02110-1301, USA. */ | |
1ee3acfb AP |
30 | |
31 | /* TODO: This should be replaced by a compiler builtin. */ | |
32 | ||
33 | #ifndef SUB_NAME | |
34 | #include <libgfortran.h> | |
35 | #endif | |
36 | ||
37 | #ifdef SUB_NAME | |
38 | /* MVBITS copies LEN bits starting at bit position FROMPOS from FROM | |
39 | into TO, starting at bit position TOPOS. */ | |
40 | ||
37058415 FXC |
41 | extern void SUB_NAME (const TYPE *, const int *, const int *, TYPE *, |
42 | const int *); | |
7d7b8bfe RH |
43 | export_proto(SUB_NAME); |
44 | ||
1ee3acfb | 45 | void |
37058415 FXC |
46 | SUB_NAME (const TYPE *from, const int *frompos, const int *len, TYPE *to, |
47 | const int *topos) | |
1ee3acfb AP |
48 | { |
49 | TYPE oldbits, newbits, lenmask; | |
50 | ||
43ff4e9a | 51 | lenmask = (*len == sizeof (TYPE)*8) ? ~(TYPE)0 : ((TYPE)1 << *len) - 1; |
1ee3acfb AP |
52 | newbits = (((UTYPE)(*from) >> *frompos) & lenmask) << *topos; |
53 | oldbits = *to & (~(lenmask << *topos)); | |
54 | ||
55 | *to = newbits | oldbits; | |
56 | } | |
57 | #endif | |
58 | ||
59 | #ifndef SUB_NAME | |
56746a07 TS |
60 | # define TYPE GFC_INTEGER_1 |
61 | # define UTYPE GFC_UINTEGER_1 | |
62 | # define SUB_NAME mvbits_i1 | |
63 | # include "mvbits.c" | |
64 | # undef SUB_NAME | |
65 | # undef TYPE | |
66 | # undef UTYPE | |
67 | ||
68 | # define TYPE GFC_INTEGER_2 | |
69 | # define UTYPE GFC_UINTEGER_2 | |
70 | # define SUB_NAME mvbits_i2 | |
71 | # include "mvbits.c" | |
72 | # undef SUB_NAME | |
73 | # undef TYPE | |
74 | # undef UTYPE | |
75 | ||
1ee3acfb AP |
76 | # define TYPE GFC_INTEGER_4 |
77 | # define UTYPE GFC_UINTEGER_4 | |
7d7b8bfe | 78 | # define SUB_NAME mvbits_i4 |
1ee3acfb AP |
79 | # include "mvbits.c" |
80 | # undef SUB_NAME | |
81 | # undef TYPE | |
82 | # undef UTYPE | |
83 | ||
84 | # define TYPE GFC_INTEGER_8 | |
85 | # define UTYPE GFC_UINTEGER_8 | |
7d7b8bfe | 86 | # define SUB_NAME mvbits_i8 |
1ee3acfb AP |
87 | # include "mvbits.c" |
88 | # undef SUB_NAME | |
89 | # undef TYPE | |
90 | # undef UTYPE | |
91 | #endif |