blob: aff5326a220d8fa243f383e9ff2f127fb0c5f56e [file] [log] [blame]
Edward O'Callaghan37a6a452009-08-07 20:30:09 +00001/* ===-- paritysi2.c - Implement __paritysi2 -------------------------------===
2 *
Chandler Carruth7a739a02019-01-19 10:56:40 +00003 * Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 * See https://llvm.org/LICENSE.txt for license information.
5 * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
Edward O'Callaghan37a6a452009-08-07 20:30:09 +00006 *
7 * ===----------------------------------------------------------------------===
8 *
9 * This file implements __paritysi2 for the compiler_rt library.
10 *
11 * ===----------------------------------------------------------------------===
12 */
Daniel Dunbarb3a69012009-06-26 16:47:03 +000013
14#include "int_lib.h"
15
Edward O'Callaghan37a6a452009-08-07 20:30:09 +000016/* Returns: 1 if number of bits is odd else returns 0 */
Daniel Dunbarb3a69012009-06-26 16:47:03 +000017
Anton Korobeynikov1c5f89b2011-04-19 17:52:09 +000018COMPILER_RT_ABI si_int
Daniel Dunbarb3a69012009-06-26 16:47:03 +000019__paritysi2(si_int a)
20{
21 su_int x = (su_int)a;
22 x ^= x >> 16;
23 x ^= x >> 8;
24 x ^= x >> 4;
25 return (0x6996 >> (x & 0xF)) & 1;
26}