xref: /openbsd-src/gnu/llvm/compiler-rt/lib/builtins/paritysi2.c (revision 1f9cb04fc6f537ca6cf5a53c28927340cba218a2)
13cab2bb3Spatrick //===-- paritysi2.c - Implement __paritysi2 -------------------------------===//
23cab2bb3Spatrick //
33cab2bb3Spatrick // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
43cab2bb3Spatrick // See https://llvm.org/LICENSE.txt for license information.
53cab2bb3Spatrick // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
63cab2bb3Spatrick //
73cab2bb3Spatrick //===----------------------------------------------------------------------===//
83cab2bb3Spatrick //
93cab2bb3Spatrick // This file implements __paritysi2 for the compiler_rt library.
103cab2bb3Spatrick //
113cab2bb3Spatrick //===----------------------------------------------------------------------===//
123cab2bb3Spatrick 
133cab2bb3Spatrick #include "int_lib.h"
143cab2bb3Spatrick 
153cab2bb3Spatrick // Returns: 1 if number of bits is odd else returns 0
163cab2bb3Spatrick 
__paritysi2(si_int a)17*1f9cb04fSpatrick COMPILER_RT_ABI int __paritysi2(si_int a) {
183cab2bb3Spatrick   su_int x = (su_int)a;
193cab2bb3Spatrick   x ^= x >> 16;
203cab2bb3Spatrick   x ^= x >> 8;
213cab2bb3Spatrick   x ^= x >> 4;
223cab2bb3Spatrick   return (0x6996 >> (x & 0xF)) & 1;
233cab2bb3Spatrick }
24