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
2081ec96df4f83df9781368c6f2b8160ee1b177f75Alex Ray#include <stdbool.h>
212111bc7b28af06757fa8108bab045188d4b337fdAlex Ray#include <string.h>
222111bc7b28af06757fa8108bab045188d4b337fdAlex Ray#include <strings.h>
235a809b90e91d2ccf4c84181d10d175eb2c1c6bc7Dima Zavin#include <sys/cdefs.h>
245a809b90e91d2ccf4c84181d10d175eb2c1c6bc7Dima Zavin
255a809b90e91d2ccf4c84181d10d175eb2c1c6bc7Dima Zavin__BEGIN_DECLS
265a809b90e91d2ccf4c84181d10d175eb2c1c6bc7Dima Zavin
270e8810ccbec84999727940e68a5a5d654ee589e1Elliott Hughesstatic inline int popcount(unsigned int x) {
285a809b90e91d2ccf4c84181d10d175eb2c1c6bc7Dima Zavin    return __builtin_popcount(x);
295a809b90e91d2ccf4c84181d10d175eb2c1c6bc7Dima Zavin}
305a809b90e91d2ccf4c84181d10d175eb2c1c6bc7Dima Zavin
310e8810ccbec84999727940e68a5a5d654ee589e1Elliott Hughesstatic inline int popcountl(unsigned long x) {
325a809b90e91d2ccf4c84181d10d175eb2c1c6bc7Dima Zavin    return __builtin_popcountl(x);
335a809b90e91d2ccf4c84181d10d175eb2c1c6bc7Dima Zavin}
345a809b90e91d2ccf4c84181d10d175eb2c1c6bc7Dima Zavin
350e8810ccbec84999727940e68a5a5d654ee589e1Elliott Hughesstatic inline int popcountll(unsigned long long x) {
365a809b90e91d2ccf4c84181d10d175eb2c1c6bc7Dima Zavin    return __builtin_popcountll(x);
375a809b90e91d2ccf4c84181d10d175eb2c1c6bc7Dima Zavin}
385a809b90e91d2ccf4c84181d10d175eb2c1c6bc7Dima Zavin
395a809b90e91d2ccf4c84181d10d175eb2c1c6bc7Dima Zavin__END_DECLS
405a809b90e91d2ccf4c84181d10d175eb2c1c6bc7Dima Zavin
415a809b90e91d2ccf4c84181d10d175eb2c1c6bc7Dima Zavin#endif /* __CUTILS_BITOPS_H */
42