1 /* Copyright (c) 2017  SiFive Inc. All rights reserved.
2 
3    This copyrighted material is made available to anyone wishing to use,
4    modify, copy, or redistribute it subject to the terms and conditions
5    of the FreeBSD License.   This program is distributed in the hope that
6    it will be useful, but WITHOUT ANY WARRANTY expressed or implied,
7    including the implied warranties of MERCHANTABILITY or FITNESS FOR
8    A PARTICULAR PURPOSE.  A copy of this license is available at
9    http://www.opensource.org/licenses.
10 */
11 
__libc_detect_null(unsigned long w)12 static __inline unsigned long __libc_detect_null(unsigned long w)
13 {
14   unsigned long mask = 0x7f7f7f7f;
15   if (sizeof (long) == 8)
16     mask = ((mask << 16) << 16) | mask;
17   return ~(((w & mask) + mask) | w | mask);
18 }
19