/* Copyright (C) 2008 - Ruben Niederhagen
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 3
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, you will find it online at
 * http://www.gnu.org/licenses/gpl.html
 */

/**
 * \file
 * \author Ruben Niederhagen (ruben@polycephaly.org)
 */

#ifndef _IOLAOS_INCLUDE_TYPES_H_
#define _IOLAOS_INCLUDE_TYPES_H_

#include <stdint.h>

#ifdef __cplusplus
extern "C" {
#endif

/** \brief Dump variable with format string.
 *
 * The given variable is dumped with information about file and line via printf.
 * A format string must be given for correct output.
 *
 * \param x Variable to dump.
 * \param fmt Formant string for printf.
 *
 * Example:
 *
 * Given the file 'example.c':
 * \code
 *
 * void main()
 * {
 *   int i = 5;
 *
 *   dump(i, %i");
 * }
 * \endcode
 *
 * This will give the output:
 *
 * example.c:5: i=5
 *
 *
 */
#define dump(x, fmt) printf("%s:%u: %s=" fmt "\n", __FILE__, __LINE__, #x, x)

/** \brief This union helps transfering pointers between PPE and the SPE.
 *
 * On the SPEs, any pointer to effective adresses has a size 64bit. Thus 
 * transfering pointers between PPE and SPEs may be painful if PPE-code is
 * compiled for 32bit via the compiler-flag -m32. This structure helps 
 * transfering pointers by adding a 32bit padding in case of 32bit-code. The
 * padding must be 0 for 32bit addresses.
 */
typedef union
{
	struct 
	{
#ifndef __powerpc64__
	void *pad; /**< Padding for 32bit effective addresses. Must be 0. This member only exists for 32bit-code.*/
#endif
	void *p; /**< Pointer to effective address. 32bit or 64bit depending on compiler flag. */
	} ;
	uint64_t ull; /**< Cast of the effective address to 64bit interger value for SPE-usage. */
	uint32_t ui[2]; /**< Cast of the effective address to two 32bit integers for convenience. */
} addr64_t;

#ifdef __cplusplus
}
#endif

#endif /* _IOLAOS_INCLUDE_TYPES_H_ */
