xref: /openbsd-src/gnu/llvm/compiler-rt/lib/builtins/paritydi2.c (revision d89ec533011f513df1010f142a111086a0785f09)
13cab2bb3Spatrick //===-- paritydi2.c - Implement __paritydi2 -------------------------------===//
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 __paritydi2 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 
__paritydi2(di_int a)171f9cb04fSpatrick COMPILER_RT_ABI int __paritydi2(di_int a) {
183cab2bb3Spatrick   dwords x;
193cab2bb3Spatrick   x.all = a;
20*d89ec533Spatrick   su_int x2 = x.s.high ^ x.s.low;
21*d89ec533Spatrick   x2 ^= x2 >> 16;
22*d89ec533Spatrick   x2 ^= x2 >> 8;
23*d89ec533Spatrick   x2 ^= x2 >> 4;
24*d89ec533Spatrick   return (0x6996 >> (x2 & 0xF)) & 1;
253cab2bb3Spatrick }
26