13c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#ifndef _TCUFORMATUTIL_HPP
23c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#define _TCUFORMATUTIL_HPP
33c827367444ee418f129b2c238299f49d3264554Jarkko Poyry/*-------------------------------------------------------------------------
43c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * drawElements Quality Program Tester Core
53c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * ----------------------------------------
63c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *
73c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Copyright 2014 The Android Open Source Project
83c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *
93c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Licensed under the Apache License, Version 2.0 (the "License");
103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * you may not use this file except in compliance with the License.
113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * You may obtain a copy of the License at
123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *
133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *      http://www.apache.org/licenses/LICENSE-2.0
143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *
153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Unless required by applicable law or agreed to in writing, software
163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * distributed under the License is distributed on an "AS IS" BASIS,
173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * See the License for the specific language governing permissions and
193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * limitations under the License.
203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *
213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*!
223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \file
233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \brief String format utilities.
243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*--------------------------------------------------------------------*/
253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuDefs.hpp"
273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "deString.h"
283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include <ostream>
303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include <string>
313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
323c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace tcu
333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
343c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace Format
353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry// Hexadecimal value formatter.
383c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <int NumDigits>
393c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass Hex
403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
413c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic:
423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	Hex (deUint64 value_) : value(value_) {}
433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	std::ostream& toStream (std::ostream& stream) const
453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		return stream << this->toString();
473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	std::string toString (void) const
503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		DE_STATIC_ASSERT(0 < NumDigits && NumDigits <= 16);
523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const char longFmt[]	= {'0', 'x', '%', '0', '0' + NumDigits/10, '0' + NumDigits%10, 'l', 'l', 'x', 0};
543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const char shortFmt[]	= {'0', 'x', '%', '0', '0' + NumDigits, 'l', 'l', 'x', 0};
553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		char buf[sizeof(deUint64)*2 + 3];
573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		deSprintf(buf, sizeof(buf), NumDigits > 9 ? longFmt : shortFmt, value);
583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		return std::string(buf);
603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
623c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprivate:
633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint64 value;
643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
663c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <int NumDigits>
673c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystd::ostream& operator<< (std::ostream& stream, tcu::Format::Hex<NumDigits> hex)
683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return hex.toStream(stream);
703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry// Bitfield formatter.
733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
743c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass BitDesc
753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
763c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic:
773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint64	bit;
783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const char*	name;
793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	BitDesc (deUint64 bit_, const char* name_) : bit(bit_), name(name_) {}
813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#define TCU_BIT_DESC(BIT) tcu::Format::BitDesc(BIT, #BIT)
843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
853c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <int BitfieldSize>
863c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass Bitfield
873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
883c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic:
893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	Bitfield (deUint64 value, const BitDesc* begin, const BitDesc* end)
903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		: m_value	(value)
913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, m_begin	(begin)
923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, m_end		(end)
933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	std::ostream& toStream (std::ostream& stream)
973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		deUint64 bitsLeft = m_value;
993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		for (const BitDesc* curDesc = m_begin; curDesc != m_end; curDesc++)
1003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
1013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			if (curDesc->bit & bitsLeft)
1023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			{
1033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				if (bitsLeft != m_value)
1043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					stream << "|";
1053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				stream << curDesc->name;
1063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				bitsLeft ^= curDesc->bit;
1073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			}
1083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
1093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (bitsLeft != 0)
1113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
1123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			if (bitsLeft != m_value)
1133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				stream << "|";
1143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			stream << Hex<BitfieldSize/4>(bitsLeft);
1153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
1163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		return stream;
1183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
1193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1203c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprivate:
1213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint64			m_value;
1223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const BitDesc*		m_begin;
1233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const BitDesc*		m_end;
1243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
1253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1263c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <int BitfieldSize>
1273c827367444ee418f129b2c238299f49d3264554Jarkko Poyryinline std::ostream& operator<< (std::ostream& stream, Bitfield<BitfieldSize> decoder)
1283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return decoder.toStream(stream);
1303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
1313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry// Enum formatter.
1333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry// \todo [2012-10-30 pyry] Use template for GetName.
1343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1353c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass Enum
1363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1373c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic:
1383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	typedef const char* (*GetNameFunc) (int value);
1393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	Enum (GetNameFunc getName, int value)
1413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		: m_getName	(getName)
1423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, m_value	(value)
1433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
1443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
1453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	std::ostream& toStream (std::ostream& stream) const
1473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
1483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const char* name = m_getName(m_value);
1493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (name)
1503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			return stream << name;
1513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		else
1523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			return stream << Hex<sizeof(int)*2>(m_value);
1533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
1543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	std::string toString (void) const
1563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
1573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const char* name = m_getName(m_value);
1583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (name)
1593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			return std::string(name);
1603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		else
1613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			return Hex<sizeof(int)*2>(m_value).toString();
1623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
1633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1643c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprivate:
1653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	GetNameFunc		m_getName;
1663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int				m_value;
1673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
1683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1693c827367444ee418f129b2c238299f49d3264554Jarkko Poyryinline std::ostream& operator<< (std::ostream& stream, Enum fmt) { return fmt.toStream(stream); }
1703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry// Array formatters.
1723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1733c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <typename Iterator>
1743c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass Array
1753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1763c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic:
1773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	Iterator	begin;
1783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	Iterator	end;
1793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	Array (const Iterator& begin_, const Iterator& end_) : begin(begin_), end(end_) {}
1813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
1823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1833c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <typename T>
1843c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass ArrayPointer
1853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1863c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic:
1873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const T*	arr;
1883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int			size;
1893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	ArrayPointer (const T* arr_, int size_) : arr(arr_), size(size_) {}
1913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
1923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1933c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <typename Iterator>
1943c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystd::ostream& operator<< (std::ostream& str, const Array<Iterator>& fmt)
1953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	str << "{ ";
1973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (Iterator cur = fmt.begin; cur != fmt.end; ++cur)
1983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
1993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (cur != fmt.begin)
2003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			str << ", ";
2013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		str << *cur;
2023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
2033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	str << " }";
2043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return str;
2053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
2063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2073c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <typename T>
2083c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystd::ostream& operator<< (std::ostream& str, const ArrayPointer<T>& fmt)
2093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
2103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (fmt.arr != DE_NULL)
2113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		return str << Array<const T*>(fmt.arr, fmt.arr+fmt.size);
2123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	else
2133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		return str << "(null)";
2143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
2153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry// Hex format iterator (useful for combining with ArrayFormatter).
2173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry// \todo [2012-10-30 pyry] Implement more generic format iterator.
2183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2193c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <typename T, typename Iterator = const T*>
2203c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass HexIterator
2213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
2223c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic:
2233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry										HexIterator			(Iterator iter) : m_iter(iter) {}
2243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	HexIterator<T, Iterator>&			operator++			(void)	{ ++m_iter; return *this;		}
2263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	HexIterator<T, Iterator>			operator++			(int)	{ return HexIterator(m_iter++);	}
2273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	bool								operator==			(const HexIterator<T, Iterator>& other) const { return m_iter == other.m_iter; }
2293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	bool								operator!=			(const HexIterator<T, Iterator>& other) const { return m_iter != other.m_iter; }
2303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#if !defined(__INTELLISENSE__)
2323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Intellisense in VS2013 crashes when parsing this.
2333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	Hex<sizeof(T)*2>					operator*			(void) const { return Hex<sizeof(T)*2>(*m_iter);	}
2343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#endif
2353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2363c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprivate:
2373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	Iterator							m_iter;
2383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
2393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // Format
2413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2423c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <int Bits>		inline deUint64 makeMask64			(void)				{ return (1ull<<Bits)-1;								}
2433c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <>				inline deUint64 makeMask64<64>		(void)				{ return ~0ull;											}
2443c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <typename T>	inline deUint64	toUint64			(T value)			{ return (deUint64)value & makeMask64<sizeof(T)*8>();	}
2453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry/** Format value as hexadecimal number. */
2473c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <int NumDigits, typename T>
2483c827367444ee418f129b2c238299f49d3264554Jarkko Poyryinline Format::Hex<NumDigits> toHex (T value)
2493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
2503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return Format::Hex<NumDigits>(toUint64(value));
2513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
2523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry/** Format value as hexadecimal number. */
2543c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <typename T>
2553c827367444ee418f129b2c238299f49d3264554Jarkko Poyryinline Format::Hex<sizeof(T)*2> toHex (T value)
2563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
2573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return Format::Hex<sizeof(T)*2>(toUint64(value));
2583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
2593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry/** Decode and format bitfield. */
2613c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <typename T, size_t Size>
2623c827367444ee418f129b2c238299f49d3264554Jarkko Poyryinline Format::Bitfield<sizeof(T)*8> formatBitfield (T value, const Format::BitDesc (&desc)[Size])
2633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
2643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return Format::Bitfield<sizeof(T)*8>((deUint64)value, &desc[0], &desc[Size]);
2653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
2663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry/** Format array contents. */
2683c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <typename Iterator>
2693c827367444ee418f129b2c238299f49d3264554Jarkko Poyryinline Format::Array<Iterator> formatArray (const Iterator& begin, const Iterator& end)
2703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
2713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return Format::Array<Iterator>(begin, end);
2723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
2733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry/** Format array contents. */
2753c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <typename T>
2763c827367444ee418f129b2c238299f49d3264554Jarkko Poyryinline Format::ArrayPointer<T> formatArray (const T* arr, int size)
2773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
2783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return Format::ArrayPointer<T>(arr, size);
2793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
2803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // tcu
2823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#endif // _TCUFORMATUTIL_HPP
284