mvbits.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /* Implementation of the MVBITS intrinsic
  2. Copyright (C) 2004-2015 Free Software Foundation, Inc.
  3. Contributed by Tobias Schlüter
  4. This file is part of the GNU Fortran 95 runtime library (libgfortran).
  5. Libgfortran is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU General Public
  7. License as published by the Free Software Foundation; either
  8. version 3 of the License, or (at your option) any later version.
  9. Libgfortran is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. Under Section 7 of GPL version 3, you are granted additional
  14. permissions described in the GCC Runtime Library Exception, version
  15. 3.1, as published by the Free Software Foundation.
  16. You should have received a copy of the GNU General Public License and
  17. a copy of the GCC Runtime Library Exception along with this program;
  18. see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
  19. <http://www.gnu.org/licenses/>. */
  20. /* TODO: This should be replaced by a compiler builtin. */
  21. #ifndef SUB_NAME
  22. #include <libgfortran.h>
  23. #endif
  24. #ifdef SUB_NAME
  25. /* MVBITS copies LEN bits starting at bit position FROMPOS from FROM
  26. into TO, starting at bit position TOPOS. */
  27. extern void SUB_NAME (const TYPE *, const int *, const int *, TYPE *,
  28. const int *);
  29. export_proto(SUB_NAME);
  30. void
  31. SUB_NAME (const TYPE *from, const int *frompos, const int *len, TYPE *to,
  32. const int *topos)
  33. {
  34. TYPE oldbits, newbits, lenmask;
  35. lenmask = (*len == sizeof (TYPE)*8) ? ~(TYPE)0 : ((TYPE)1 << *len) - 1;
  36. newbits = (((UTYPE)(*from) >> *frompos) & lenmask) << *topos;
  37. oldbits = *to & (~(lenmask << *topos));
  38. *to = newbits | oldbits;
  39. }
  40. #endif
  41. #ifndef SUB_NAME
  42. # define TYPE GFC_INTEGER_1
  43. # define UTYPE GFC_UINTEGER_1
  44. # define SUB_NAME mvbits_i1
  45. # include "mvbits.c"
  46. # undef SUB_NAME
  47. # undef TYPE
  48. # undef UTYPE
  49. # define TYPE GFC_INTEGER_2
  50. # define UTYPE GFC_UINTEGER_2
  51. # define SUB_NAME mvbits_i2
  52. # include "mvbits.c"
  53. # undef SUB_NAME
  54. # undef TYPE
  55. # undef UTYPE
  56. # define TYPE GFC_INTEGER_4
  57. # define UTYPE GFC_UINTEGER_4
  58. # define SUB_NAME mvbits_i4
  59. # include "mvbits.c"
  60. # undef SUB_NAME
  61. # undef TYPE
  62. # undef UTYPE
  63. # define TYPE GFC_INTEGER_8
  64. # define UTYPE GFC_UINTEGER_8
  65. # define SUB_NAME mvbits_i8
  66. # include "mvbits.c"
  67. # undef SUB_NAME
  68. # undef TYPE
  69. # undef UTYPE
  70. #endif