xref: /freebsd/contrib/llvm-project/compiler-rt/lib/builtins/paritydi2.c (revision e8d8bef961a50d4dc22501cde4fb9fb0be1b2532)
10b57cec5SDimitry Andric //===-- paritydi2.c - Implement __paritydi2 -------------------------------===//
20b57cec5SDimitry Andric //
30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60b57cec5SDimitry Andric //
70b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
80b57cec5SDimitry Andric //
90b57cec5SDimitry Andric // This file implements __paritydi2 for the compiler_rt library.
100b57cec5SDimitry Andric //
110b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
120b57cec5SDimitry Andric 
130b57cec5SDimitry Andric #include "int_lib.h"
140b57cec5SDimitry Andric 
150b57cec5SDimitry Andric // Returns: 1 if number of bits is odd else returns 0
160b57cec5SDimitry Andric 
__paritydi2(di_int a)175ffd83dbSDimitry Andric COMPILER_RT_ABI int __paritydi2(di_int a) {
180b57cec5SDimitry Andric   dwords x;
190b57cec5SDimitry Andric   x.all = a;
20*e8d8bef9SDimitry Andric   su_int x2 = x.s.high ^ x.s.low;
21*e8d8bef9SDimitry Andric   x2 ^= x2 >> 16;
22*e8d8bef9SDimitry Andric   x2 ^= x2 >> 8;
23*e8d8bef9SDimitry Andric   x2 ^= x2 >> 4;
24*e8d8bef9SDimitry Andric   return (0x6996 >> (x2 & 0xF)) & 1;
250b57cec5SDimitry Andric }
26