f2ab43ebbb62839fbd981a4fb406fefc7f388297
[platform/upstream/glibc.git] / sysdeps / i386 / bits / select.h
1 /* Copyright (C) 1997 Free Software Foundation, Inc.
2    This file is part of the GNU C Library.
3
4    The GNU C Library is free software; you can redistribute it and/or
5    modify it under the terms of the GNU Library General Public License as
6    published by the Free Software Foundation; either version 2 of the
7    License, or (at your option) any later version.
8
9    The GNU C Library 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 GNU
12    Library General Public License for more details.
13
14    You should have received a copy of the GNU Library General Public
15    License along with the GNU C Library; see the file COPYING.LIB.  If not,
16    write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17    Boston, MA 02111-1307, USA.  */
18
19 #ifndef _SYS_SELECT_H
20 # error "Never use <bits/select.h> directly; include <sys/select.h> instead."
21 #endif
22
23
24 #if defined __GNUC__ && __GNUC__ >= 2
25
26 # define __FD_ZERO(fdsetp) \
27   __asm__ __volatile__ ("cld; rep; stosl"                                     \
28                         : "=m" ((fdsetp)->fds_bits[__FDELT (__FD_SETSIZE)])   \
29                         : "a" (0), "c" (sizeof (__fd_set)                     \
30                                         / sizeof (__fd_mask)),                \
31                           "D" (&(fdsetp)->fds_bits[0])                        \
32                         :"cx","di","memory")
33 # define __FD_SET(fd, fdsetp) \
34   __asm__ __volatile__ ("btsl %1,%0"                                          \
35                         : "=m" ((fdsetp)->fds_bits[__FDELT (fd)])             \
36                         : "r" (((int) (fd)) % __NFDBITS)                      \
37                         : "cc","memory")
38 # define __FD_CLR(fd, fdsetp) \
39   __asm__ __volatile__ ("btrl %1,%0"                                          \
40                         : "=m" ((fdsetp)->fds_bits[__FDELT (fd)])             \
41                         : "r" (((int) (fd)) % __NFDBITS)                      \
42                         : "cc","memory")
43 # define __FD_ISSET(fd, fdsetp) \
44   (__extension__                                                              \
45    ({register char __result;                                                  \
46      __asm__ __volatile__ ("btl %1,%2 ; setcb %b0"                            \
47                            : "=q" (__result)                                  \
48                            : "r" (((int) (fd)) % __NFDBITS),                  \
49                              "m" ((fdsetp)->fds_bits[__FDELT (fd)])           \
50                            : "cc");                                           \
51      __result; }))
52
53 #else   /* ! GNU CC */
54
55 /* We don't use `memset' because this would require a prototype and
56    the array isn't too big.  */
57 # define __FD_ZERO(set)  \
58   do {                                                                        \
59     unsigned int __i;                                                         \
60     __fd_set *__arr = (set);                                                  \
61     for (__i = 0; __i < sizeof (__fd_set) / sizeof (__fd_mask); ++__i)        \
62       __arr->fds_bits[__i] = 0;                                               \
63   } while (0)
64 # define __FD_SET(d, set)       ((set)->fds_bits[__FDELT (d)] |= __FDMASK (d))
65 # define __FD_CLR(d, set)       ((set)->fds_bits[__FDELT (d)] &= ~__FDMASK (d))
66 # define __FD_ISSET(d, set)     ((set)->fds_bits[__FDELT (d)] & __FDMASK (d))
67
68 #endif  /* GNU CC */