select.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /* Copyright (C) 1997, 1998 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. The GNU C Library is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU Library General Public License as
  5. published by the Free Software Foundation; either version 2 of the
  6. License, or (at your option) any later version.
  7. The GNU C Library is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. Library General Public License for more details.
  11. You should have received a copy of the GNU Library General Public
  12. License along with the GNU C Library; see the file COPYING.LIB. If not,
  13. write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  14. Boston, MA 02111-1307, USA. */
  15. #ifndef _SYS_SELECT_H
  16. # error "Never use <bits/select.h> directly; include <sys/select.h> instead."
  17. #endif
  18. #if defined __GNUC__ && __GNUC__ >= 2
  19. # define __FD_ZERO(fdsp) \
  20. do { \
  21. __asm__ __volatile__ ("mov.l %1,er5\n\t" \
  22. "mov.l er5,er6\n\t" \
  23. "inc.l #1,er6\n\t" \
  24. "mov.b #0,r4l\n\t" \
  25. "mov.b r4l,@er5\n\t" \
  26. "mov.l %0,er4\n\t" \
  27. "eepmov.w\n\t" \
  28. :: "r" (sizeof (fd_set)-1), \
  29. "r" (&__FDS_BITS (fdsp)[0]) \
  30. : "er4","er5","er6","memory"); \
  31. } while (0)
  32. # define __FD_SET(fd, fdsp) \
  33. __asm__ __volatile__ ("mov.l %0,er0\n\t" \
  34. "mov.l %1,er1\n\t" \
  35. "shlr.b r1l\n\t" \
  36. "shlr.b r1l\n\t" \
  37. "shlr.b r1l\n\t" \
  38. "add.l er1,er0\n\t" \
  39. "mov.l %1,er1\n\t" \
  40. "and.b #7,r1l\n\t" \
  41. "bset r1l,@er0\n\t" \
  42. : "=m" (__FDS_BITS (fdsp)[__FDELT (fd)]) \
  43. : "r" (((int) (fd)) % __NFDBITS) \
  44. : "cc","memory","er0","er1")
  45. # define __FD_CLR(fd, fdsp) \
  46. __asm__ __volatile__ ("mov.l %0,er0\n\t" \
  47. "mov.l %1,er1\n\t" \
  48. "shlr.b r1l\n\t" \
  49. "shlr.b r1l\n\t" \
  50. "shlr.b r1l\n\t" \
  51. "add.l er1,er0\n\t" \
  52. "mov.l %1,er1\n\t" \
  53. "and.b #7,r1l\n\t" \
  54. "bclr r1l,@er0\n\t" \
  55. : "=m" (__FDS_BITS (fdsp)[__FDELT (fd)]) \
  56. : "r" (((int) (fd)) % __NFDBITS) \
  57. : "cc","memory","er0","er1")
  58. # define __FD_ISSET(fd, fdsp) \
  59. (__extension__ \
  60. ({register char __result; \
  61. __asm__ __volatile__ ("mov.l %1,er0\n\t" \
  62. "sub.l er1,er1\n\t" \
  63. "mov.w %0,r1\n\t" \
  64. "shlr.b r1l\n\t" \
  65. "shlr.b r1l\n\t" \
  66. "shlr.b r1l\n\t" \
  67. "add.l er1,er0\n\t" \
  68. "mov.w %0,r1\n\t" \
  69. "and.b #7,r1l\n\t" \
  70. "btst.b r1l,@er0\n\t" \
  71. "beq 1f\n\t" \
  72. "sub.l er0,er0\n\t" \
  73. "mov.b r1h,r0l\n\t" \
  74. "bra 2f\n" \
  75. "1:\tsub.l er0,er0\n" \
  76. "2:\tmov.w r0,%0\n\t" \
  77. : "=r" (__result) \
  78. : "r" (((int) (fd)) % __NFDBITS), \
  79. "m" (__FDS_BITS (fdsp)[__FDELT (fd)]) \
  80. : "cc"); \
  81. __result; }))
  82. #else /* ! GNU CC */
  83. /* We don't use `memset' because this would require a prototype and
  84. the array isn't too big. */
  85. # define __FD_ZERO(set) \
  86. do { \
  87. unsigned int __i; \
  88. fd_set *__arr = (set); \
  89. for (__i = 0; __i < sizeof (fd_set) / sizeof (__fd_mask); ++__i) \
  90. __FDS_BITS (__arr)[__i] = 0; \
  91. } while (0)
  92. # define __FD_SET(d, set) (__FDS_BITS (set)[__FDELT (d)] |= __FDMASK (d))
  93. # define __FD_CLR(d, set) (__FDS_BITS (set)[__FDELT (d)] &= ~__FDMASK (d))
  94. # define __FD_ISSET(d, set) (__FDS_BITS (set)[__FDELT (d)] & __FDMASK (d))
  95. #endif /* GNU CC */