15a809b90e91d2ccf4c84181d10d175eb2c1c6bc7Dima Zavin/*
25a809b90e91d2ccf4c84181d10d175eb2c1c6bc7Dima Zavin * Copyright (C) 2011 The Android Open Source Project
35a809b90e91d2ccf4c84181d10d175eb2c1c6bc7Dima Zavin *
45a809b90e91d2ccf4c84181d10d175eb2c1c6bc7Dima Zavin * Licensed under the Apache License, Version 2.0 (the "License");
55a809b90e91d2ccf4c84181d10d175eb2c1c6bc7Dima Zavin * you may not use this file except in compliance with the License.
65a809b90e91d2ccf4c84181d10d175eb2c1c6bc7Dima Zavin * You may obtain a copy of the License at
75a809b90e91d2ccf4c84181d10d175eb2c1c6bc7Dima Zavin *
85a809b90e91d2ccf4c84181d10d175eb2c1c6bc7Dima Zavin *      http://www.apache.org/licenses/LICENSE-2.0
95a809b90e91d2ccf4c84181d10d175eb2c1c6bc7Dima Zavin *
105a809b90e91d2ccf4c84181d10d175eb2c1c6bc7Dima Zavin * Unless required by applicable law or agreed to in writing, software
115a809b90e91d2ccf4c84181d10d175eb2c1c6bc7Dima Zavin * distributed under the License is distributed on an "AS IS" BASIS,
125a809b90e91d2ccf4c84181d10d175eb2c1c6bc7Dima Zavin * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
135a809b90e91d2ccf4c84181d10d175eb2c1c6bc7Dima Zavin * See the License for the specific language governing permissions and
145a809b90e91d2ccf4c84181d10d175eb2c1c6bc7Dima Zavin * limitations under the License.
155a809b90e91d2ccf4c84181d10d175eb2c1c6bc7Dima Zavin */
165a809b90e91d2ccf4c84181d10d175eb2c1c6bc7Dima Zavin
175a809b90e91d2ccf4c84181d10d175eb2c1c6bc7Dima Zavin#ifndef __CUTILS_BITOPS_H
185a809b90e91d2ccf4c84181d10d175eb2c1c6bc7Dima Zavin#define __CUTILS_BITOPS_H
195a809b90e91d2ccf4c84181d10d175eb2c1c6bc7Dima Zavin
205a809b90e91d2ccf4c84181d10d175eb2c1c6bc7Dima Zavin#include <sys/cdefs.h>
215a809b90e91d2ccf4c84181d10d175eb2c1c6bc7Dima Zavin
225a809b90e91d2ccf4c84181d10d175eb2c1c6bc7Dima Zavin__BEGIN_DECLS
235a809b90e91d2ccf4c84181d10d175eb2c1c6bc7Dima Zavin
245a809b90e91d2ccf4c84181d10d175eb2c1c6bc7Dima Zavinstatic inline int popcount(unsigned int x)
255a809b90e91d2ccf4c84181d10d175eb2c1c6bc7Dima Zavin{
265a809b90e91d2ccf4c84181d10d175eb2c1c6bc7Dima Zavin    return __builtin_popcount(x);
275a809b90e91d2ccf4c84181d10d175eb2c1c6bc7Dima Zavin}
285a809b90e91d2ccf4c84181d10d175eb2c1c6bc7Dima Zavin
295a809b90e91d2ccf4c84181d10d175eb2c1c6bc7Dima Zavinstatic inline int popcountl(unsigned long x)
305a809b90e91d2ccf4c84181d10d175eb2c1c6bc7Dima Zavin{
315a809b90e91d2ccf4c84181d10d175eb2c1c6bc7Dima Zavin    return __builtin_popcountl(x);
325a809b90e91d2ccf4c84181d10d175eb2c1c6bc7Dima Zavin}
335a809b90e91d2ccf4c84181d10d175eb2c1c6bc7Dima Zavin
345a809b90e91d2ccf4c84181d10d175eb2c1c6bc7Dima Zavinstatic inline int popcountll(unsigned long long x)
355a809b90e91d2ccf4c84181d10d175eb2c1c6bc7Dima Zavin{
365a809b90e91d2ccf4c84181d10d175eb2c1c6bc7Dima Zavin    return __builtin_popcountll(x);
375a809b90e91d2ccf4c84181d10d175eb2c1c6bc7Dima Zavin}
385a809b90e91d2ccf4c84181d10d175eb2c1c6bc7Dima Zavin
395a809b90e91d2ccf4c84181d10d175eb2c1c6bc7Dima Zavin__END_DECLS
405a809b90e91d2ccf4c84181d10d175eb2c1c6bc7Dima Zavin
415a809b90e91d2ccf4c84181d10d175eb2c1c6bc7Dima Zavin#endif /* __CUTILS_BITOPS_H */
42