Update.
[glibc.git] / sysdeps / i386 / selectbits.h
blob973ecad58e9ac034af167a056f8a9566426e7639
1 /* Copyright (C) 1997 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
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.
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.
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. */
19 #ifndef _SELECTBITS_H
20 #define _SELECTBITS_H 1
22 #if defined __GNUC__ && __GNUC__ >= 2
24 #define __FD_ZERO(fdsetp) \
25 __asm__ __volatile__ ("cld ; rep ; stosl" \
26 : "=m" (*(__fd_set *) (fdsetp)) \
27 : "a" (0), "c" (sizeof (__fd_set) \
28 / sizeof (__fd_mask)), \
29 "D" ((__fd_set *) (fdsetp)) \
30 :"cx","di")
31 #define __FD_SET(fd, fdsetp) \
32 __asm__ __volatile__ ("btsl %1,%0" \
33 : "=m" (*(__fd_set *) (fdsetp)) \
34 : "r" ((int) (fd)))
35 #define __FD_CLR(fd, fdsetp) \
36 __asm__ __volatile__ ("btrl %1,%0" \
37 : "=m" (*(__fd_set *) (fdsetp)) \
38 : "r" ((int) (fd)))
39 #define __FD_ISSET(fd, fdsetp) \
40 (__extension__ \
41 ({unsigned char __result; \
42 __asm__ __volatile__ ("btl %1,%2 ; setb %0" \
43 : "=q" (__result) \
44 : "r" ((int) (fd)), "m" (*(__fd_set *) (fdsetp))); \
45 __result; }))
47 #else /* ! GNU CC */
49 #define __FD_ZERO(set) \
50 ((void) memset ((__ptr_t) (set), 0, sizeof (fd_set)))
51 #define __FD_SET(d, set) ((set)->fds_bits[__FDELT(d)] |= __FDMASK(d))
52 #define __FD_CLR(d, set) ((set)->fds_bits[__FDELT(d)] &= ~__FDMASK(d))
53 #define __FD_ISSET(d, set) ((set)->fds_bits[__FDELT(d)] & __FDMASK(d))
55 #endif /* GNU CC */
57 #endif /* selectbits.h */