1 /*
2 * Copyright (c) 2017-2019, NVIDIA CORPORATION. All rights reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 */
17
18 #include <stdint.h>
19
20 int32_t
__mth_i_ipoppar(uint32_t u32)21 __mth_i_ipoppar(uint32_t u32)
22 {
23 uint32_t r32;
24
25 #if defined(TARGET_X8664)
26 asm("popcnt %1, %0\n"
27 "\tandl $0x1, %0"
28 : "=r"(r32)
29 : "r"(u32)
30 :
31 );
32 #elif defined(TARGET_LINUX_POWER)
33 asm("popcntw %0, %1\n"
34 "\trldicl %0, %0, 0, 63"
35 : "=r"(r32)
36 : "r"(u32)
37 :
38 );
39 #else
40 r32 = u32;
41 r32 ^= r32 >> 16;
42 r32 ^= r32 >> 8;
43 r32 ^= r32 >> 4;
44 r32 ^= r32 >> 2;
45 r32 ^= r32 >> 1;
46 r32 &= 0x1;
47 #endif
48
49 return r32;
50 }
51