/* SPDX-License-Identifier: GPL-2.0+ */
/*
 * Complete helper definitions from Linux v6.18 include/linux/xarray.h.
 * Copyright (c) 2017 Microsoft Corporation
 * Author: Matthew Wilcox <willy@infradead.org>
 */

static inline void *xa_mk_value(unsigned long v)
{
	WARN_ON((long)v < 0);
	return (void *)((v << 1) | 1);
}

static inline unsigned long xa_to_value(const void *entry)
{
	return (unsigned long)entry >> 1;
}

static inline bool xa_is_value(const void *entry)
{
	return (unsigned long)entry & 1;
}

static inline void *xa_mk_internal(unsigned long v)
{
	return (void *)((v << 2) | 2);
}

static inline unsigned long xa_to_internal(const void *entry)
{
	return (unsigned long)entry >> 2;
}

static inline bool xa_is_internal(const void *entry)
{
	return ((unsigned long)entry & 3) == 2;
}
