text:
 /*!
 * \file
 * \brief
 */ /*-------------------------------------------------------------------*/

#include "es31cShaderBitfieldOperationTests.hpp"
#include "deMath.h"
#include "deRandom.hpp"
#include "deString.h"
#include "deStringUtil.hpp"
#include "deFloat16.h"
#include "gluContextInfo.hpp"
#include "gluDrawUtil.hpp"
#include "gluPixelTransfer.hpp"
#include "gluShaderProgram.hpp"
#include "glw.h"
#include "glwFunctions.hpp"
#include "tcuCommandLine.hpp"
#include "tcuStringTemplate.hpp"
#include "tcuSurface.hpp"
#include "tcuTestLog.hpp"

namespace glcts
{

using tcu::TestLog;
using std::string;
using std::vector;
using glcts::Context;

static std::string specializeVersion(const std::string& source, glu::GLSLVersion version, const char* testStatement)
{
	DE_ASSERT(version == glu::GLSL_VERSION_310_ES || version >= glu::GLSL_VERSION_430);
	std::map<std::string, std::string> args;
	args["VERSION_DECL"]   = glu::getGLSLVersionDeclaration(version);
	args["TEST_STATEMENT"] = testStatement;
	return tcu::StringTemplate(source.c_str()).specialize(args);
}

struct Data
{
	Data()
	{
		memset(this, 0, sizeof *this);
	}
	Data(Data const& init)
	{
		memcpy(this, &init, sizeof *this);
	}

	GLuint  inUvec4[4];
	GLint   inIvec4[4];
	GLfloat inVec4[4];

	GLuint  in2Uvec4[4];
	GLint   in2Ivec4[4];
	GLfloat in2Vec4[4];

	GLint offset;
	GLint bits;
	GLint padding[2];

	GLuint  outUvec4[4];
	GLint   outIvec4[4];
	GLfloat outVec4[4];

	GLuint  out2Uvec4[4];
	GLint   out2Ivec4[4];
	GLfloat out2Vec4[4];
};

struct Uvec4 : public Data
{
	Uvec4(GLuint x = 0, GLuint y = 0, GLuint z = 0, GLuint w = 0)
	{
		inUvec4[0] = x;
		inUvec4[1] = y;
		inUvec4[2] = z;
		inUvec4[3] = w;
	}
};

struct Ivec4 : public Data
{
	Ivec4(GLint x = 0, GLint y = 0, GLint z = 0, GLint w = 0)
	{
		inIvec4[0] = x;
		inIvec4[1] = y;
		inIvec4[2] = z;
		inIvec4[3] = w;
	}
};

struct Vec4 : public Data
{
	Vec4(GLfloat x = 0.0f, GLfloat y = 0.0f, GLfloat z = 0.0f, GLfloat w = 0.0f)
	{
		inVec4[0] = x;
		inVec4[1] = y;
		inVec4[2] = z;
		inVec4[3] = w;
	}
};

class ShaderBitfieldOperationCase : public TestCase
{
public:
	ShaderBitfieldOperationCase(Context& context, const char* name, const char* description,
								glu::GLSLVersion glslVersion, Data const& data, char const* testStatement);
	~ShaderBitfieldOperationCase();

	IterateResult iterate();

protected:
	glu::GLSLVersion m_glslVersion;
	Data			 m_data;
	std::string		 m_testStatement;

	virtual bool test(Data const* data) = 0;
};

ShaderBitfieldOperationCase::ShaderBitfieldOperationCase(Context& context, const char* name, const char* description,
														 glu::GLSLVersion glslVersion, Data const& data,
														 char const* testStatement)
	: TestCase(context, name, description), m_glslVersion(glslVersion), m_data(data), m_testStatement(testStatement)
{
	DE_ASSERT(glslVersion == glu::GLSL_VERSION_310_ES || glslVersion >= glu::GLSL_VERSION_430);
}

ShaderBitfieldOperationCase::~ShaderBitfieldOperationCase()
{
}

ShaderBitfieldOperationCase::IterateResult ShaderBitfieldOperationCase::iterate()
{
	const glw::Functions& gl   = m_context.getRenderContext().getFunctions();
	bool				  isOk = true;

	GLuint data;
	gl.genBuffers(1, &data);
	gl.bindBuffer(GL_SHADER_STORAGE_BUFFER, data);
	gl.bufferData(GL_SHADER_STORAGE_BUFFER, sizeof(Data), &m_data, GL_STATIC_DRAW);
	gl.bindBufferBase(GL_SHADER_STORAGE_BUFFER, 0, data);

	char const* css = "${VERSION_DECL}\n"
					  "\n"
					  "layout(local_size_x = 1) in;\n"
					  "\n"
					  "layout(binding = 0, std430) buffer Data {\n"
					  "    uvec4 inUvec4;\n"
					  "    ivec4 inIvec4;\n"
					  "    vec4 inVec4;\n"
					  "\n"
					  "    uvec4 in2Uvec4;\n"
					  "    ivec4 in2Ivec4;\n"
					  "    vec4 in2Vec4;\n"
					  "\n"
					  "    int offset;\n"
					  "    int bits;\n"
					  "\n"
					  "    uvec4 outUvec4;\n"
					  "    ivec4 outIvec4;\n"
					  "    vec4 outVec4;\n"
					  "\n"
					  "    uvec4 out2Uvec4;\n"
					  "    ivec4 out2Ivec4;\n"
					  "    vec4 out2Vec4;\n"
					  "};\n"
					  "\n"
					  "void main()\n"
					  "{\n"
					  "    ${TEST_STATEMENT};\n"
					  "}\n";

	GLuint		cs		   = gl.createShader(GL_COMPUTE_SHADER);
	std::string csString   = specializeVersion(css, m_glslVersion, m_testStatement.c_str());
	char const* strings[1] = { csString.c_str() };
	gl.shaderSource(cs, 1, strings, 0);
	gl.compileShader(cs);
	GLint compileSuccess = 0;
	gl.getShaderiv(cs, GL_COMPILE_STATUS, &compileSuccess);
	if (!compileSuccess)
	{
		TCU_FAIL("Compile failed");
	}

	GLuint pgm = gl.createProgram();
	gl.attachShader(pgm, cs);
	gl.linkProgram(pgm);
	GLint linkSuccess = 0;
	gl.getProgramiv(pgm, GL_LINK_STATUS, &linkSuccess);
	if (!linkSuccess)
	{
		gl.deleteShader(cs);
		TCU_FAIL("Link failed");
	}

	gl.useProgram(pgm);

	gl.dispatchCompute(1, 1, 1);

	Data const* results = (Data const*)gl.mapBufferRange(GL_SHADER_STORAGE_BUFFER, 0, sizeof(Data), GL_MAP_READ_BIT);
	isOk				= test(results);
	gl.unmapBuffer(GL_SHADER_STORAGE_BUFFER);

	gl.useProgram(0);
	gl.deleteProgram(pgm);
	gl.deleteShader(cs);

	gl.deleteBuffers(1, &data);

	m_testCtx.setTestResult(isOk ? QP_TEST_RESULT_PASS : QP_TEST_RESULT_FAIL, isOk ? "Pass" : "Fail");
	return STOP;
}

class ShaderBitfieldOperationCaseFrexp : public ShaderBitfieldOperationCase
{
public:
	ShaderBitfieldOperationCaseFrexp(Context& context, const char* name, glu::GLSLVersion glslVersion, Data const& data,
									 int components, char const* testStatement)
		: ShaderBitfieldOperationCase(context, name, "", glslVersion, data, testStatement), m_components(components)
	{
	}

private:
	int m_components;

	virtual bool test(Data const* data)
	{
		for (int i = 0; i < m_components; ++i)
		{
			if (data->inVec4[i] == 0.0)
			{
				if (data->outVec4[i] != 0.0 || data->outIvec4[i] != 0)
				{
					return false;
				}
			}
			else if (deFloatAbs(data->outVec4[i]) < 0.5 || deFloatAbs(data->outVec4[i]) >= 1.0)
			{
				return false;
			}

			float result = data->outVec4[i] * deFloatPow(2.0, (float)data->outIvec4[i]);
			if (deFloatAbs(result - data->inVec4[i]) > 0.0001f)
			{
				return false;
			}
		}
		return true;
	}
};

class ShaderBitfieldOperationCaseFrexpFloat : public ShaderBitfieldOperationCaseFrexp
{
public:
	ShaderBitfieldOperationCaseFrexpFloat(Context& context, const char* name, glu::GLSLVersion glslVersion,
										  Data const& data)
		: ShaderBitfieldOperationCaseFrexp(context, name, glslVersion, data, 1,
										   "outVec4.x = frexp(inVec4.x, outIvec4.x)")
	{
	}
};

class ShaderBitfieldOperationCaseFrexpVec2 : public ShaderBitfieldOperationCaseFrexp
{
public:
	ShaderBitfieldOperationCaseFrexpVec2(Context& context, const char* name, glu::GLSLVersion glslVersion,
										 Data const& data)
		: ShaderBitfieldOperationCaseFrexp(context, name, glslVersion, data, 2,
										   "outVec4.xy = frexp(inVec4.xy, outIvec4.xy)")
	{
	}
};

class ShaderBitfieldOperationCaseFrexpVec3 : public ShaderBitfieldOperationCaseFrexp
{
public:
	ShaderBitfieldOperationCaseFrexpVec3(Context& context, const char* name, glu::GLSLVersion glslVersion,
										 Data const& data)
		: ShaderBitfieldOperationCaseFrexp(context, name, glslVersion, data, 3,
										   "outVec4.xyz = frexp(inVec4.xyz, outIvec4.xyz)")
	{
	}
};

class ShaderBitfieldOperationCaseFrexpVec4 : public ShaderBitfieldOperationCaseFrexp
{
public:
	ShaderBitfieldOperationCaseFrexpVec4(Context& context, const char* name, glu::GLSLVersion glslVersion,
										 Data const& data)
		: ShaderBitfieldOperationCaseFrexp(context, name, glslVersion, data, 4, "outVec4 = frexp(inVec4, outIvec4)")
	{
	}
};

class ShaderBitfieldOperationCaseLdexp : public ShaderBitfieldOperationCase
{
public:
	ShaderBitfieldOperationCaseLdexp(Context& context, const char* name, glu::GLSLVersion glslVersion, Data const& data,
									 int components, char const* testStatement)
		: ShaderBitfieldOperationCase(context, name, "", glslVersion, data, testStatement), m_components(components)
	{
	}

private:
	int m_components;

	virtual bool test(Data const* data)
	{
		for (int i = 0; i < m_components; ++i)
		{
			float expected = deFloatLdExp(data->inVec4[i], data->inIvec4[i]);
			if (deFloatAbs(expected - data->outVec4[i]) > 0.0001f)
			{
				return false;
			}
		}
		return true;
	}
};

class ShaderBitfieldOperationCaseLdexpFloat : public ShaderBitfieldOperationCaseLdexp
{
public:
	ShaderBitfieldOperationCaseLdexpFloat(Context& context, const char* name, glu::GLSLVersion glslVersion,
										  Data const& data, Data const& exp)
		: ShaderBitfieldOperationCaseLdexp(context, name, glslVersion, data, 1,
										   "outVec4.x = ldexp(inVec4.x, inIvec4.x)")
	{
		m_data.inIvec4[0] = exp.inIvec4[0];
	}
};

class ShaderBitfieldOperationCaseLdexpVec2 : public ShaderBitfieldOperationCaseLdexp
{
public:
	ShaderBitfieldOperationCaseLdexpVec2(Context& context, const char* name, glu::GLSLVersion glslVersion,
										 Data const& data, Data const& exp)
		: ShaderBitfieldOperationCaseLdexp(context, name, glslVersion, data, 2,
										   "outVec4.xy = ldexp(inVec4.xy, inIvec4.xy)")
	{
		m_data.inIvec4[0] = exp.inIvec4[0];
		m_data.inIvec4[1] = exp.inIvec4[1];
	}
};

class ShaderBitfieldOperationCaseLdexpVec3 : public ShaderBitfieldOperationCaseLdexp
{
public:
	ShaderBitfieldOperationCaseLdexpVec3(Context& context, const char* name, glu::GLSLVersion glslVersion,
										 Data const& data, Data const& exp)
		: ShaderBitfieldOperationCaseLdexp(context, name, glslVersion, data, 3,
										   "outVec4.xyz = ldexp(inVec4.xyz, inIvec4.xyz)")
	{
		m_data.inIvec4[0] = exp.inIvec4[0];
		m_data.inIvec4[1] = exp.inIvec4[1];
		m_data.inIvec4[2] = exp.inIvec4[2];
	}
};

class ShaderBitfieldOperationCaseLdexpVec4 : public ShaderBitfieldOperationCaseLdexp
{
public:
	ShaderBitfieldOperationCaseLdexpVec4(Context& context, const char* name, glu::GLSLVersion glslVersion,
										 Data const& data, Data const& exp)
		: ShaderBitfieldOperationCaseLdexp(context, name, glslVersion, data, 4, "outVec4 = ldexp(inVec4, inIvec4)")
	{
		m_data.inIvec4[0] = exp.inIvec4[0];
		m_data.inIvec4[1] = exp.inIvec4[1];
		m_data.inIvec4[2] = exp.inIvec4[2];
		m_data.inIvec4[3] = exp.inIvec4[3];
	}
};

static float reduce32PrecisionTo16(float f)
{
	return deFloat16To32(deFloat32To16(f));
}

static GLuint pack(float x, float y, float z, float w, float range)
{
	return ((int(deFloatFloor(x * range + 0.5f)) & 0xFF) << 0) |
			((int(deFloatFloor(y * range + 0.5f)) & 0xFF) << 8) |
			((int(deFloatFloor(z * range + 0.5f)) & 0xFF) << 16)|
			((int(deFloatFloor(w * range + 0.5f)) & 0xFF) << 24);
}

static bool checkOutData(GLuint result, const GLfloat input[4], float range)
{
	GLuint expected = pack(input[0], input[1], input[2], input[3], range);

	GLuint expected_mp = pack(reduce32PrecisionTo16(input[0]),
									reduce32PrecisionTo16(input[1]),
									reduce32PrecisionTo16(input[2]),
									reduce32PrecisionTo16(input[3]),
									range);

	return (expected == result || expected_mp == result);
}

class ShaderBitfieldOperationCasePackUnorm : public ShaderBitfieldOperationCase
{
public:
	ShaderBitfieldOperationCasePackUnorm(Context& context, const char* name, glu::GLSLVersion glslVersion,
										 Data const& data)
		: ShaderBitfieldOperationCase(context, name, "", glslVersion, data, "outUvec4.x = packUnorm4x8(inVec4)")
	{
	}

private:
	virtual bool test(Data const* data)
	{
					return checkOutData(data->outUvec4[0], data->inVec4, 255.0f);
	}
};

class ShaderBitfieldOperationCasePackSnorm : public ShaderBitfieldOperationCase
{
public:
	ShaderBitfieldOperationCasePackSnorm(Context& context, const char* name, glu::GLSLVersion glslVersion,
										 Data const& data)
		: ShaderBitfieldOperationCase(context, name, "", glslVersion, data, "outUvec4.x = packSnorm4x8(inVec4)")
	{
	}

private:
	virtual bool test(Data const* data)
	{
					return checkOutData(data->outUvec4[0], data->inVec4, 127.0f);
	}
};

class ShaderBitfieldOperationCaseUnpackUnorm : public ShaderBitfieldOperationCase
{
public:
	ShaderBitfieldOperationCaseUnpackUnorm(Context& context, const char* name, glu::GLSLVersion glslVersion,
										   Data const& data)
		: ShaderBitfieldOperationCase(context, name, "", glslVersion, data, "outVec4 = unpackUnorm4x8(inUvec4.x)")
	{
	}

private:
	virtual bool test(Data const* data)
	{
		GLfloat x = float((data->inUvec4[0] >> 0) & 0xFF) / 255.0f;
		if (deFloatAbs(data->outVec4[0] - x) > 0.0001f)
		{
			return false;
		}
		GLfloat y = float((data->inUvec4[0] >> 8) & 0xFF) / 255.0f;
		if (deFloatAbs(data->outVec4[1] - y) > 0.0001f)
		{
			return false;
		}
		GLfloat z = float((data->inUvec4[0] >> 16) & 0xFF) / 255.0f;
		if (deFloatAbs(data->outVec4[2] - z) > 0.0001f)
		{
			return false;
		}
		GLfloat w = float((data->inUvec4[0] >> 24) & 0xFF) / 255.0f;
		if (deFloatAbs(data->outVec4[3] - w) > 0.0001f)
		{
			return false;
		}

		return true;
	}
};

class ShaderBitfieldOperationCaseUnpackSnorm : public ShaderBitfieldOperationCase
{
public:
	ShaderBitfieldOperationCaseUnpackSnorm(Context& context, const char* name, glu::GLSLVersion glslVersion,
										   Data const& data)
		: ShaderBitfieldOperationCase(context, name, "", glslVersion, data, "outVec4 = unpackSnorm4x8(inUvec4.x)")
	{
	}

private:
	virtual bool test(Data const* data)
	{
		GLfloat x = float((signed char)((data->inUvec4[0] >> 0) & 0xFF)) / 127.0f;
		x		  = de::clamp<GLfloat>(x, -1.0f, 1.0f);
		if (deFloatAbs(data->outVec4[0] - x) > 0.0001f)
		{
			return false;
		}
		GLfloat y = float((signed char)((data->inUvec4[0] >> 8) & 0xFF)) / 127.0f;
		y		  = de::clamp<GLfloat>(y, -1.0f, 1.0f);
		if (deFloatAbs(data->outVec4[1] - y) > 0.0001f)
		{
			return false;
		}
		GLfloat z = float((signed char)((data->inUvec4[0] >> 16) & 0xFF)) / 127.0f;
		z		  = de::clamp<GLfloat>(z, -1.0f, 1.0f);
		if (deFloatAbs(data->outVec4[2] - z) > 0.0001f)
		{
			return false;
		}
		GLfloat w = float((signed char)((data->inUvec4[0] >> 24) & 0xFF)) / 127.0f;
		w		  = de::clamp<GLfloat>(w, -1.0f, 1.0f);
		if (deFloatAbs(data->outVec4[3] - w) > 0.0001f)
		{
			return false;
		}

		return true;
	}
};

class ShaderBitfieldOperationCaseBitfieldExtractUint : public ShaderBitfieldOperationCase
{
public:
	ShaderBitfieldOperationCaseBitfieldExtractUint(Context& context, const char* name, glu::GLSLVersion glslVersion,
												   Data const& data, int offset, int bits, int components,
												   char const* testStatement)
		: ShaderBitfieldOperationCase(context, name, "", glslVersion, data, testStatement), m_components(components)
	{
		if (offset + bits > 32)
		{
			offset -= (offset + bits) - 32;
		}
		m_data.offset = offset;
		m_data.bits   = bits;
	}

private:
	int m_components;

	virtual bool test(Data const* data)
	{
		for (int i = 0; i < m_components; ++i)
		{
			GLuint expected =
				(data->inUvec4[i] >> data->offset) & (data->bits == 32 ? 0xFFFFFFFF : ((1 << data->bits) - 1));
			if (data->outUvec4[i] != expected)
			{
				return false;
			}
		}
		return true;
	}
};

class ShaderBitfieldOperationCaseBitfieldExtractUint1 : public ShaderBitfieldOperationCaseBitfieldExtractUint
{
public:
	ShaderBitfieldOperationCaseBitfieldExtractUint1(Context& context, const char* name, glu::GLSLVersion glslVersion,
													Data const& data, int offset, int bits)
		: ShaderBitfieldOperationCaseBitfieldExtractUint(context, name, glslVersion, data, offset, bits, 1,
														 "outUvec4.x = bitfieldExtract(inUvec4.x, offset, bits)")
	{
	}
};

class ShaderBitfieldOperationCaseBitfieldExtractUint2 : public ShaderBitfieldOperationCaseBitfieldExtractUint
{
public:
	ShaderBitfieldOperationCaseBitfieldExtractUint2(Context& context, const char* name, glu::GLSLVersion glslVersion,
													Data const& data, int offset, int bits)
		: ShaderBitfieldOperationCaseBitfieldExtractUint(context, name, glslVersion, data, offset, bits, 2,
														 "outUvec4.xy = bitfieldExtract(inUvec4.xy, offset, bits)")
	{
	}
};

class ShaderBitfieldOperationCaseBitfieldExtractUint3 : public ShaderBitfieldOperationCaseBitfieldExtractUint
{
public:
	ShaderBitfieldOperationCaseBitfieldExtractUint3(Context& context, const char* name, glu::GLSLVersion glslVersion,
													Data const& data, int offset, int bits)
		: ShaderBitfieldOperationCaseBitfieldExtractUint(context, name, glslVersion, data, offset, bits, 3,
														 "outUvec4.xyz = bitfieldExtract(inUvec4.xyz, offset, bits)")
	{
	}
};

class ShaderBitfieldOperationCaseBitfieldExtractUint4 : public ShaderBitfieldOperationCaseBitfieldExtractUint
{
public:
	ShaderBitfieldOperationCaseBitfieldExtractUint4(Context& context, const char* name, glu::GLSLVersion glslVersion,
													Data const& data, int offset, int bits)
		: ShaderBitfieldOperationCaseBitfieldExtractUint(context, name, glslVersion, data, offset, bits, 4,
														 "outUvec4 = bitfieldExtract(inUvec4, offset, bits)")
	{
	}
};

class ShaderBitfieldOperationCaseBitfieldExtractInt : public ShaderBitfieldOperationCase
{
public:
	ShaderBitfieldOperationCaseBitfieldExtractInt(Context& context, const char* name, glu::GLSLVersion glslVersion,
												  Data const& data, int offset, int bits, int components,
												  char const* testStatement)
		: ShaderBitfieldOperationCase(context, name, "", glslVersion, data, testStatement), m_components(components)
	{
		if (offset + bits > 32)
		{
			offset -= (offset + bits) - 32;
		}
		m_data.offset = offset;
		m_data.bits   = bits;
	}

private:
	int m_components;

	virtual bool test(Data const* data)
	{
		for (int i = 0; i < m_components; ++i)
		{
			GLint expected = data->inIvec4[i] << (32 - (data->offset + data->bits));
			expected >>= 32 - data->bits;
			if (data->outIvec4[i] != expected)
			{
				return false;
			}
		}
		return true;
	}
};

class ShaderBitfieldOperationCaseBitfieldExtractInt1 : public ShaderBitfieldOperationCaseBitfieldExtractInt
{
public:
	ShaderBitfieldOperationCaseBitfieldExtractInt1(Context& context, const char* name, glu::GLSLVersion glslVersion,
												   Data const& data, int offset, int bits)
		: ShaderBitfieldOperationCaseBitfieldExtractInt(context, name, glslVersion, data, offset, bits, 1,
														"outIvec4.x = bitfieldExtract(inIvec4.x, offset, bits)")
	{
	}
};

class ShaderBitfieldOperationCaseBitfieldExtractInt2 : public ShaderBitfieldOperationCaseBitfieldExtractInt
{
public:
	ShaderBitfieldOperationCaseBitfieldExtractInt2(Context& context, const char* name, glu::GLSLVersion glslVersion,
												   Data const& data, int offset, int bits)
		: ShaderBitfieldOperationCaseBitfieldExtractInt(context, name, glslVersion, data, offset, bits, 2,
														"outIvec4.xy = bitfieldExtract(inIvec4.xy, offset, bits)")
	{
	}
};

class ShaderBitfieldOperationCaseBitfieldExtractInt3 : public ShaderBitfieldOperationCaseBitfieldExtractInt
{
public:
	ShaderBitfieldOperationCaseBitfieldExtractInt3(Context& context, const char* name, glu::GLSLVersion glslVersion,
												   Data const& data, int offset, int bits)
		: ShaderBitfieldOperationCaseBitfieldExtractInt(context, name, glslVersion, data, offset, bits, 3,
														"outIvec4.xyz = bitfieldExtract(inIvec4.xyz, offset, bits)")
	{
	}
};

class ShaderBitfieldOperationCaseBitfieldExtractInt4 : public ShaderBitfieldOperationCaseBitfieldExtractInt
{
public:
	ShaderBitfieldOperationCaseBitfieldExtractInt4(Context& context, const char* name, glu::GLSLVersion glslVersion,
												   Data const& data, int offset, int bits)
		: ShaderBitfieldOperationCaseBitfieldExtractInt(context, name, glslVersion, data, offset, bits, 4,
														"outIvec4 = bitfieldExtract(inIvec4, offset, bits)")
	{
	}
};

class ShaderBitfieldOperationCaseBitfieldInsertUint : public ShaderBitfieldOperationCase
{
public:
	ShaderBitfieldOperationCaseBitfieldInsertUint(Context& context, const char* name, glu::GLSLVersion glslVersion,
												  Data const& data, Data const& insert, int offset, int bits,
												  int components, char const* testStatement)
		: ShaderBitfieldOperationCase(context, name, "", glslVersion, data, testStatement), m_components(components)
	{
		for (int i = 0; i < components; ++i)
		{
			m_data.in2Uvec4[i] = insert.inUvec4[i];
		}
		if (offset + bits > 32)
		{
			offset -= (offset + bits) - 32;
		}
		m_data.offset = offset;
		m_data.bits   = bits;
	}

private:
	int m_components;

	virtual bool test(Data const* data)
	{
		for (int i = 0; i < m_components; ++i)
		{
			GLuint mask = (data->bits == 32) ? ~0u : (1 << data->bits) - 1;
			GLuint expected =
				(data->inUvec4[i] & ~(mask << data->offset)) | ((data->in2Uvec4[i] & mask) << data->offset);
			if (data->outUvec4[i] != expected)
			{
				return false;
			}
		}
		return true;
	}
};

class ShaderBitfieldOperationCaseBitfieldInsertUint1 : public ShaderBitfieldOperationCaseBitfieldInsertUint
{
public:
	ShaderBitfieldOperationCaseBitfieldInsertUint1(Context& context, const char* name, glu::GLSLVersion glslVersion,
												   Data const& data, Data const& insert, int offset, int bits)
		: ShaderBitfieldOperationCaseBitfieldInsertUint(
			  context, name, glslVersion, data, insert, offset, bits, 1,
			  "outUvec4.x = bitfieldInsert(inUvec4.x, in2Uvec4.x, offset, bits)")
	{
	}
};

class ShaderBitfieldOperationCaseBitfieldInsertUint2 : public ShaderBitfieldOperationCaseBitfieldInsertUint
{
public:
	ShaderBitfieldOperationCaseBitfieldInsertUint2(Context& context, const char* name, glu::GLSLVersion glslVersion,
												   Data const& data, Data const& insert, int offset, int bits)
		: ShaderBitfieldOperationCaseBitfieldInsertUint(
			  context, name, glslVersion, data, insert, offset, bits, 2,
			  "outUvec4.xy = bitfieldInsert(inUvec4.xy, in2Uvec4.xy, offset, bits)")
	{
	}
};

class ShaderBitfieldOperationCaseBitfieldInsertUint3 : public ShaderBitfieldOperationCaseBitfieldInsertUint
{
public:
	ShaderBitfieldOperationCaseBitfieldInsertUint3(Context& context, const char* name, glu::GLSLVersion glslVersion,
												   Data const& data, Data const& insert, int offset, int bits)
		: ShaderBitfieldOperationCaseBitfieldInsertUint(
			  context, name, glslVersion, data, insert, offset, bits, 3,
			  "outUvec4.xyz = bitfieldInsert(inUvec4.xyz, in2Uvec4.xyz, offset, bits)")
	{
	}
};

class ShaderBitfieldOperationCaseBitfieldInsertUint4 : public ShaderBitfieldOperationCaseBitfieldInsertUint
{
public:
	ShaderBitfieldOperationCaseBitfieldInsertUint4(Context& context, const char* name, glu::GLSLVersion glslVersion,
												   Data const& data, Data const& insert, int offset, int bits)
		: ShaderBitfieldOperationCaseBitfieldInsertUint(context, name, glslVersion, data, insert, offset, bits, 4,
														"outUvec4 = bitfieldInsert(inUvec4, in2Uvec4, offset, bits)")
	{
	}
};

class ShaderBitfieldOperationCaseBitfieldInsertInt : public ShaderBitfieldOperationCase
{
public:
	ShaderBitfieldOperationCaseBitfieldInsertInt(Context& context, const char* name, glu::GLSLVersion glslVersion,
												 Data const& data, Data const& insert, int offset, int bits,
												 int components, char const* testStatement)
		: ShaderBitfieldOperationCase(context, name, "", glslVersion, data, testStatement), m_components(components)
	{
		for (int i = 0; i < components; ++i)
		{
			m_data.in2Ivec4[i] = insert.inIvec4[i];
		}
		if (offset + bits > 32)
		{
			offset -= (offset + bits) - 32;
		}
		m_data.offset = offset;
		m_data.bits   = bits;
	}

private:
	int m_components;

	virtual bool test(Data const* data)
	{
		for (int i = 0; i < m_components; ++i)
		{
			GLuint mask = (data->bits == 32) ? ~0u : (1 << data->bits) - 1;
			GLint  expected =
				(data->inIvec4[i] & ~(mask << data->offset)) | ((data->in2Ivec4[i] & mask) << data->offset);
			if (data->outIvec4[i] != expected)
			{
				return false;
			}
		}
		return true;
	}
};

class ShaderBitfieldOperationCaseBitfieldInsertInt1 : public ShaderBitfieldOperationCaseBitfieldInsertInt
{
public:
	ShaderBitfieldOperationCaseBitfieldInsertInt1(Context& context, const char* name, glu::GLSLVersion glslVersion,
												  Data const& data, Data const& insert, int offset, int bits)
		: ShaderBitfieldOperationCaseBitfieldInsertInt(
			  context, name, glslVersion, data, insert, offset, bits, 1,
			  "outIvec4.x = bitfieldInsert(inIvec4.x, in2Ivec4.x, offset, bits)")
	{
	}
};

class ShaderBitfieldOperationCaseBitfieldInsertInt2 : public ShaderBitfieldOperationCaseBitfieldInsertInt
{
public:
	ShaderBitfieldOperationCaseBitfieldInsertInt2(Context& context, const char* name, glu::GLSLVersion glslVersion,
												  Data const& data, Data const& insert, int offset, int bits)
		: ShaderBitfieldOperationCaseBitfieldInsertInt(
			  context, name, glslVersion, data, insert, offset, bits, 2,
			  "outIvec4.xy = bitfieldInsert(inIvec4.xy, in2Ivec4.xy, offset, bits)")
	{
	}
};

class ShaderBitfieldOperationCaseBitfieldInsertInt3 : public ShaderBitfieldOperationCaseBitfieldInsertInt
{
public:
	ShaderBitfieldOperationCaseBitfieldInsertInt3(Context& context, const char* name, glu::GLSLVersion glslVersion,
												  Data const& data, Data const& insert, int offset, int bits)
		: ShaderBitfieldOperationCaseBitfieldInsertInt(
			  context, name, glslVersion, data, insert, offset, bits, 3,
			  "outIvec4.xyz = bitfieldInsert(inIvec4.xyz, in2Ivec4.xyz, offset, bits)")
	{
	}
};

class ShaderBitfieldOperationCaseBitfieldInsertInt4 : public ShaderBitfieldOperationCaseBitfieldInsertInt
{
public:
	ShaderBitfieldOperationCaseBitfieldInsertInt4(Context& context, const char* name, glu::GLSLVersion glslVersion,
												  Data const& data, Data const& insert, int offset, int bits)
		: ShaderBitfieldOperationCaseBitfieldInsertInt(context, name, glslVersion, data, insert, offset, bits, 4,
													   "outIvec4 = bitfieldInsert(inIvec4, in2Ivec4, offset, bits)")
	{
	}
};

typedef GLuint (*UnaryUFunc)(GLuint input);
typedef GLint (*UnaryIFunc)(GLint input);

static GLuint bitfieldReverse(GLuint input)
{
	GLuint result = 0;
	for (int i = 0; i < 32; ++i)
	{
		result >>= 1;
		result |= (input & 0x80000000);
		input <<= 1;
	}
	return result;
}

static GLuint bitCount(GLuint input)
{
	GLuint result = 0;
	while (input)
	{
		if (input & 1)
		{
			result += 1;
		}
		input >>= 1;
	}
	return result;
}

static GLuint findLSB(GLuint input)
{
	if (!input)
	{
		return -1;
	}
	for (GLuint result = 0;; ++result)
	{
		if (input & 1)
		{
			return result;
		}
		input >>= 1;
	}
}

static GLuint findMSBU(GLuint input)
{
	if (!input)
	{
		return -1;
	}
	for (GLuint result = 31;; --result)
	{
		if (input & 0x80000000)
		{
			return result;
		}
		input <<= 1;
	}
}

static GLint findMSBI(GLint input)
{
	if (input == 0 || input == -1)
	{
		return -1;
	}
	else if (input > 0)
	{
		for (GLuint result = 31;; --result)
		{
			if (input & 0x80000000)
			{
				return result;
			}
			input <<= 1;
		}
	}
	else
	{
		for (GLuint result = 31;; --result)
		{
			if (!(input & 0x80000000))
			{
				return result;
			}
			input <<= 1;
		}
	}
}

class ShaderBitfieldOperationCaseUnaryUint : public ShaderBitfieldOperationCase
{
public:
	ShaderBitfieldOperationCaseUnaryUint(Context& context, const char* name, glu::GLSLVersion glslVersion,
										 char const* funcName, UnaryUFunc func, Data const& data, int components,
										 char const* testStatement)
		: ShaderBitfieldOperationCase(context, name, "", glslVersion, data, testStatement)
		, m_components(components)
		, m_func(func)
	{
		size_t pos = m_testStatement.find("func");
		m_testStatement.replace(pos, 4, funcName);
	}

private:
	int		   m_components;
	UnaryUFunc m_func;

	virtual bool test(Data const* data)
	{
		for (int i = 0; i < m_components; ++i)
		{
			GLuint expected = m_func(data->inUvec4[i]);
			GLuint output   = data->outUvec4[i];
			if (m_func == (UnaryUFunc)glcts::bitCount || m_func == (UnaryUFunc)glcts::findLSB ||
				m_func == (UnaryUFunc)glcts::findMSBU || m_func == (UnaryUFunc)glcts::findMSBI)
			{
				/* The built-in bitCount, findLSB and findMSB functions
				 * return a lowp int, which can be encoded with as little
				 * as 9 bits. Since findLSB and findMSB can return negative
				 * values (namely, -1), we cannot compare the value directly
				 * against a (32-bit) GLuint.
				 */
				GLuint output_9bits = output & 0x1ff;
				GLuint sign_extend  = output_9bits & 0x100 ? 0xfffffe00 : 0;
				output				= output_9bits | sign_extend;
			}

			if (output != expected)
			{
				return false;
			}
		}
		return true;
	}
};

class ShaderBitfieldOperationCaseUnaryUint1 : public ShaderBitfieldOperationCaseUnaryUint
{
public:
	ShaderBitfieldOperationCaseUnaryUint1(Context& context, const char* name, glu::GLSLVersion glslVersion,
										  char const* funcName, UnaryUFunc func, Data const& data)
		: ShaderBitfieldOperationCaseUnaryUint(context, name, glslVersion, funcName, func, data, 1,
											   "outUvec4.x = uint(func(inUvec4.x))")
	{
	}
};

class ShaderBitfieldOperationCaseUnaryUint2 : public ShaderBitfieldOperationCaseUnaryUint
{
public:
	ShaderBitfieldOperationCaseUnaryUint2(Context& context, const char* name, glu::GLSLVersion glslVersion,
										  char const* funcName, UnaryUFunc func, Data const& data)
		: ShaderBitfieldOperationCaseUnaryUint(context, name, glslVersion, funcName, func, data, 2,
											   "outUvec4.xy = uvec2(func(inUvec4.xy))")
	{
	}
};

class ShaderBitfieldOperationCaseUnaryUint3 : public ShaderBitfieldOperationCaseUnaryUint
{
public:
	ShaderBitfieldOperationCaseUnaryUint3(Context& context, const char* name, glu::GLSLVersion glslVersion,
										  char const* funcName, UnaryUFunc func, Data const& data)
		: ShaderBitfieldOperationCaseUnaryUint(context, name, glslVersion, funcName, func, data, 3,
											   "outUvec4.xyz = uvec3(func(inUvec4.xyz))")
	{
	}
};

class ShaderBitfieldOperationCaseUnaryUint4 : public ShaderBitfieldOperationCaseUnaryUint
{
public:
	ShaderBitfieldOperationCaseUnaryUint4(Context& context, const char* name, glu::GLSLVersion glslVersion,
										  char const* funcName, UnaryUFunc func, Data const& data)
		: ShaderBitfieldOperationCaseUnaryUint(context, name, glslVersion, funcName, func, data, 4,
											   "outUvec4 = uvec4(func(inUvec4))")
	{
	}
};

class ShaderBitfieldOperationCaseUnaryInt : public ShaderBitfieldOperationCase
{
public:
	ShaderBitfieldOperationCaseUnaryInt(Context& context, const char* name, glu::GLSLVersion glslVersion,
										char const* funcName, UnaryIFunc func, Data const& data, int components,
										char const* testStatement)
		: ShaderBitfieldOperationCase(context, name, "", glslVersion, data, testStatement)
		, m_components(components)
		, m_func(func)
	{
		size_t pos = m_testStatement.find("func");
		m_testStatement.replace(pos, 4, funcName);
	}

private:
	int		   m_components;
	UnaryIFunc m_func;

	virtual bool test(Data const* data)
	{
		for (int i = 0; i < m_components; ++i)
		{
			GLint expected = m_func(data->inIvec4[i]);
			if (data->outIvec4[i] != expected)
			{
				return false;
			}
		}
		return true;
	}
};

class ShaderBitfieldOperationCaseUnaryInt1 : public ShaderBitfieldOperationCaseUnaryInt
{
public:
	ShaderBitfieldOperationCaseUnaryInt1(Context& context, const char* name, glu::GLSLVersion glslVersion,
										 char const* funcName, UnaryIFunc func, Data const& data)
		: ShaderBitfieldOperationCaseUnaryInt(context, name, glslVersion, funcName, func, data, 1,
											  "outIvec4.x = func(inIvec4.x)")
	{
	}
};

class ShaderBitfieldOperationCaseUnaryInt2 : public ShaderBitfieldOperationCaseUnaryInt
{
public:
	ShaderBitfieldOperationCaseUnaryInt2(Context& context, const char* name, glu::GLSLVersion glslVersion,
										 char const* funcName, UnaryIFunc func, Data const& data)
		: ShaderBitfieldOperationCaseUnaryInt(context, name, glslVersion, funcName, func, data, 2,
											  "outIvec4.xy = func(inIvec4.xy)")
	{
	}
};

class ShaderBitfieldOperationCaseUnaryInt3 : public ShaderBitfieldOperationCaseUnaryInt
{
public:
	ShaderBitfieldOperationCaseUnaryInt3(Context& context, const char* name, glu::GLSLVersion glslVersion,
										 char const* funcName, UnaryIFunc func, Data const& data)
		: ShaderBitfieldOperationCaseUnaryInt(context, name, glslVersion, funcName, func, data, 3,
											  "outIvec4.xyz = func(inIvec4.xyz)")
	{
	}
};

class ShaderBitfieldOperationCaseUnaryInt4 : public ShaderBitfieldOperationCaseUnaryInt
{
public:
	ShaderBitfieldOperationCaseUnaryInt4(Context& context, const char* name, glu::GLSLVersion glslVersion,
										 char const* funcName, UnaryIFunc func, Data const& data)
		: ShaderBitfieldOperationCaseUnaryInt(context, name, glslVersion, funcName, func, data, 4,
											  "outIvec4 = func(inIvec4)")
	{
	}
};

typedef GLuint (*BinaryUFunc)(GLuint input, GLuint input2, GLuint& output2);
typedef GLint (*BinaryIFunc)(GLint input, GLint input2, GLint& output2);

static GLuint uaddCarry(GLuint input, GLuint input2, GLuint& output2)
{
	GLuint result = input + input2;
	output2		  = (input > result) ? 1 : 0;
	return result;
}

static GLuint usubBorrow(GLuint input, GLuint input2, GLuint& output2)
{
	output2 = (input2 > input) ? 1 : 0;
	return input - input2;
}

static GLuint umulExtended(GLuint input, GLuint input2, GLuint& output2)
{
	GLuint64 result = static_cast<GLuint64>(input) * static_cast<GLuint64>(input2);
	output2			= GLuint(result & 0xFFFFFFFF);
	return GLuint(result >> 32);
}

static GLint imulExtended(GLint input, GLint input2, GLint& output2)
{
	GLint64 result = static_cast<GLint64>(input) * static_cast<GLint64>(input2);
	output2		   = GLint(result & 0xFFFFFFFF);
	return GLint(result >> 32);
}

class ShaderBitfieldOperationCaseBinaryUint : public ShaderBitfieldOperationCase
{
public:
	ShaderBitfieldOperationCaseBinaryUint(Context& context, const char* name, glu::GLSLVersion glslVersion,
										  char const* testStatement, BinaryUFunc func, Data const& input,
										  Data const& input2, int components)
		: ShaderBitfieldOperationCase(context, name, "", glslVersion, input, testStatement)
		, m_components(components)
		, m_func(func)
	{
		for (int i = 0; i < components; ++i)
		{
			m_data.in2Uvec4[i] = input2.inUvec4[i];
		}
	}

private:
	int			m_components;
	BinaryUFunc m_func;

	virtual bool test(Data const* data)
	{
		for (int i = 0; i < m_components; ++i)
		{
			GLuint expected2 = 0;
			GLuint expected  = m_func(data->inUvec4[i], data->in2Uvec4[i], expected2);
			if (data->outUvec4[i] != expected || data->out2Uvec4[i] != expected2)
			{
				return false;
			}
		}
		return true;
	}
};

class ShaderBitfieldOperationCaseBinaryUint1 : public ShaderBitfieldOperationCaseBinaryUint
{
public:
	ShaderBitfieldOperationCaseBinaryUint1(Context& context, const char* name, glu::GLSLVersion glslVersion,
										   char const* testStatement, BinaryUFunc func, Data const& input,
										   Data const& input2)
		: ShaderBitfieldOperationCaseBinaryUint(context, name, glslVersion, testStatement, func, input, input2, 1)
	{
	}
};

class ShaderBitfieldOperationCaseBinaryUint2 : public ShaderBitfieldOperationCaseBinaryUint
{
public:
	ShaderBitfieldOperationCaseBinaryUint2(Context& context, const char* name, glu::GLSLVersion glslVersion,
										   char const* testStatement, BinaryUFunc func, Data const& input,
										   Data const& input2)
		: ShaderBitfieldOperationCaseBinaryUint(context, name, glslVersion, testStatement, func, input, input2, 2)
	{
	}
};

class ShaderBitfieldOperationCaseBinaryUint3 : public ShaderBitfieldOperationCaseBinaryUint
{
public:
	ShaderBitfieldOperationCaseBinaryUint3(Context& context, const char* name, glu::GLSLVersion glslVersion,
										   char const* testStatement, BinaryUFunc func, Data const& input,
										   Data const& input2)
		: ShaderBitfieldOperationCaseBinaryUint(context, name, glslVersion, testStatement, func, input, input2, 3)
	{
	}
};

class ShaderBitfieldOperationCaseBinaryUint4 : public ShaderBitfieldOperationCaseBinaryUint
{
public:
	ShaderBitfieldOperationCaseBinaryUint4(Context& context, const char* name, glu::GLSLVersion glslVersion,
										   char const* testStatement, BinaryUFunc func, Data const& input,
										   Data const& input2)
		: ShaderBitfieldOperationCaseBinaryUint(context, name, glslVersion, testStatement, func, input, input2, 4)
	{
	}
};

class ShaderBitfieldOperationCaseBinaryInt : public ShaderBitfieldOperationCase
{
public:
	ShaderBitfieldOperationCaseBinaryInt(Context& context, const char* name, glu::GLSLVersion glslVersion,
										 char const* testStatement, BinaryIFunc func, Data const& input,
										 Data const& input2, int components)
		: ShaderBitfieldOperationCase(context, name, "", glslVersion, input, testStatement)
		, m_components(components)
		, m_func(func)
	{
		for (int i = 0; i < components; ++i)
		{
			m_data.in2Ivec4[i] = input2.inIvec4[i];
		}
	}

private:
	int			m_components;
	BinaryIFunc m_func;

	virtual bool test(Data const* data)
	{
		for (int i = 0; i < m_components; ++i)
		{
			GLint expected2 = 0;
			GLint expected  = m_func(data->inIvec4[i], data->in2Ivec4[i], expected2);
			if (data->outIvec4[i] != expected || data->out2Ivec4[i] != expected2)
			{
				return false;
			}
		}
		return true;
	}
};

class ShaderBitfieldOperationCaseBinaryInt1 : public ShaderBitfieldOperationCaseBinaryInt
{
public:
	ShaderBitfieldOperationCaseBinaryInt1(Context& context, const char* name, glu::GLSLVersion glslVersion,
										  char const* testStatement, BinaryIFunc func, Data const& input,
										  Data const& input2)
		: ShaderBitfieldOperationCaseBinaryInt(context, name, glslVersion, testStatement, func, input, input2, 1)
	{
	}
};

class ShaderBitfieldOperationCaseBinaryInt2 : public ShaderBitfieldOperationCaseBinaryInt
{
public:
	ShaderBitfieldOperationCaseBinaryInt2(Context& context, const char* name, glu::GLSLVersion glslVersion,
										  char const* testStatement, BinaryIFunc func, Data const& input,
										  Data const& input2)
		: ShaderBitfieldOperationCaseBinaryInt(context, name, glslVersion, testStatement, func, input, input2, 2)
	{
	}
};

class ShaderBitfieldOperationCaseBinaryInt3 : public ShaderBitfieldOperationCaseBinaryInt
{
public:
	ShaderBitfieldOperationCaseBinaryInt3(Context& context, const char* name, glu::GLSLVersion glslVersion,
										  char const* testStatement, BinaryIFunc func, Data const& input,
										  Data const& input2)
		: ShaderBitfieldOperationCaseBinaryInt(context, name, glslVersion, testStatement, func, input, input2, 3)
	{
	}
};

class ShaderBitfieldOperationCaseBinaryInt4 : public ShaderBitfieldOperationCaseBinaryInt
{
public:
	ShaderBitfieldOperationCaseBinaryInt4(Context& context, const char* name, glu::GLSLVersion glslVersion,
										  char const* testStatement, BinaryIFunc func, Data const& input,
										  Data const& input2)
		: ShaderBitfieldOperationCaseBinaryInt(context, name, glslVersion, testStatement, func, input, input2, 4)
	{
	}
};

ShaderBitfieldOperationTests::ShaderBitfieldOperationTests(Context& context, glu::GLSLVersion glslVersion)
	: TestCaseGroup(context, "shader_bitfield_operation", "Shader Bitfield Operation tests"), m_glslVersion(glslVersion)
{
}

ShaderBitfieldOperationTests::~ShaderBitfieldOperationTests(void)
{
}

void ShaderBitfieldOperationTests::init(void)
{
	de::Random rnd(m_context.getTestContext().getCommandLine().getBaseSeed());

	// shader_bitfield_operation.frexp
	tcu::TestCaseGroup* frexpGroup = new tcu::TestCaseGroup(m_testCtx, "frexp", "");
	addChild(frexpGroup);
	frexpGroup->addChild(new ShaderBitfieldOperationCaseFrexpFloat(m_context, "float_zero", m_glslVersion, Vec4(0.0)));
	for (int i = 0; i < ITERATIONS; ++i)
	{
		std::stringstream ss;
		ss << "float_" << i;
		frexpGroup->addChild(new ShaderBitfieldOperationCaseFrexpFloat(m_context, ss.str().c_str(), m_glslVersion,
																	   Vec4(rnd.getFloat())));
	}
	frexpGroup->addChild(
		new ShaderBitfieldOperationCaseFrexpVec2(m_context, "vec2_zero", m_glslVersion, Vec4(0.0, 0.0)));
	for (int i = 0; i < ITERATIONS; ++i)
	{
		std::stringstream ss;
		ss << "vec2_" << i;
		frexpGroup->addChild(new ShaderBitfieldOperationCaseFrexpVec2(m_context, ss.str().c_str(), m_glslVersion,
																	  Vec4(rnd.getFloat(), -rnd.getFloat())));
	}
	frexpGroup->addChild(
		new ShaderBitfieldOperationCaseFrexpVec3(m_context, "vec3_zero", m_glslVersion, Vec4(0.0, 0.0, 0.0)));
	for (int i = 0; i < ITERATIONS; ++i)
	{
		std::stringstream ss;
		ss << "vec3_" << i;
		frexpGroup->addChild(new ShaderBitfieldOperationCaseFrexpVec3(
			m_context, ss.str().c_str(), m_glslVersion, Vec4(rnd.getFloat(), -rnd.getFloat(), rnd.getFloat())));
	}
	frexpGroup->addChild(
		new ShaderBitfieldOperationCaseFrexpVec4(m_context, "vec4_zero", m_glslVersion, Vec4(0.0, 0.0, 0.0, 0.0)));
	for (int i = 0; i < ITERATIONS; ++i)
	{
		std::stringstream ss;
		ss << "vec4_" << i;
		frexpGroup->addChild(new ShaderBitfieldOperationCaseFrexpVec4(
			m_context, ss.str().c_str(), m_glslVersion,
			Vec4(rnd.getFloat(), -rnd.getFloat(), rnd.getFloat(), -rnd.getFloat())));
	}

	// shader_bitfield_operation.ldexp
	tcu::TestCaseGroup* ldexpGroup = new tcu::TestCaseGroup(m_testCtx, "ldexp", "");
	addChild(ldexpGroup);
	ldexpGroup->addChild(
		new ShaderBitfieldOperationCaseLdexpFloat(m_context, "float_zero", m_glslVersion, Vec4(0.0), Ivec4(0)));
	for (int i = 0; i < ITERATIONS; ++i)
	{
		std::stringstream ss;
		ss << "float_" << i;
		ldexpGroup->addChild(new ShaderBitfieldOperationCaseLdexpFloat(m_context, ss.str().c_str(), m_glslVersion,
																	   Vec4(rnd.getFloat()), Ivec4(rnd.getInt(-8, 8))));
	}
	ldexpGroup->addChild(
		new ShaderBitfieldOperationCaseLdexpVec2(m_context, "vec2_zero", m_glslVersion, Vec4(0.0, 0.0), Ivec4(0, 0)));
	for (int i = 0; i < ITERATIONS; ++i)
	{
		std::stringstream ss;
		ss << "vec2_" << i;
		ldexpGroup->addChild(new ShaderBitfieldOperationCaseLdexpVec2(m_context, ss.str().c_str(), m_glslVersion,
																	  Vec4(rnd.getFloat(), -rnd.getFloat()),
																	  Ivec4(rnd.getInt(-8, 8), rnd.getInt(-8, 8))));
	}
	ldexpGroup->addChild(new ShaderBitfieldOperationCaseLdexpVec3(m_context, "vec3_zero", m_glslVersion,
																  Vec4(0.0, 0.0, 0.0), Ivec4(0, 0, 0)));
	for (int i = 0; i < ITERATIONS; ++i)
	{
		std::stringstream ss;
		ss << "vec3_" << i;
		ldexpGroup->addChild(new ShaderBitfieldOperationCaseLdexpVec3(
			m_context, ss.str().c_str(), m_glslVersion, Vec4(rnd.getFloat(), -rnd.getFloat(), rnd.getFloat()),
			Ivec4(rnd.getInt(-8, 8), rnd.getInt(-8, 8), rnd.getInt(-8, 8))));
	}
	ldexpGroup->addChild(new ShaderBitfieldOperationCaseLdexpVec4(m_context, "vec4_zero", m_glslVersion,
																  Vec4(0.0, 0.0, 0.0, 0.0), Ivec4(0, 0, 0, 0)));
	for (int i = 0; i < ITERATIONS; ++i)
	{
		std::stringstream ss;
		ss << "vec4_" << i;
		ldexpGroup->addChild(new ShaderBitfieldOperationCaseLdexpVec4(
			m_context, ss.str().c_str(), m_glslVersion,
			Vec4(rnd.getFloat(), -rnd.getFloat(), rnd.getFloat(), -rnd.getFloat()),
			Ivec4(rnd.getInt(-8, 8), rnd.getInt(-8, 8), rnd.getInt(-8, 8), rnd.getInt(-8, 8))));
	}

	// shader_bitfield_operation.packUnorm4x8
	tcu::TestCaseGroup* packUnormGroup = new tcu::TestCaseGroup(m_testCtx, "packUnorm4x8", "");
	addChild(packUnormGroup);
	for (int i = 0; i < ITERATIONS; ++i)
	{
		std::stringstream ss;
		ss << i;
		packUnormGroup->addChild(new ShaderBitfieldOperationCasePackUnorm(
			m_context, ss.str().c_str(), m_glslVersion,
			Vec4(rnd.getFloat(), rnd.getFloat(), rnd.getFloat(), rnd.getFloat())));
	}

	// shader_bitfield_operation.packSnorm4x8
	tcu::TestCaseGroup* packSnormGroup = new tcu::TestCaseGroup(m_testCtx, "packSnorm4x8", "");
	addChild(packSnormGroup);
	for (int i = 0; i < ITERATIONS; ++i)
	{
		std::stringstream ss;
		ss << i;
		packSnormGroup->addChild(new ShaderBitfieldOperationCasePackSnorm(
			m_context, ss.str().c_str(), m_glslVersion,
			Vec4(rnd.getFloat(), -rnd.getFloat(), rnd.getFloat(), -rnd.getFloat())));
	}

	// shader_bitfield_operation.unpackUnorm4x8
	tcu::TestCaseGroup* unpackUnormGroup = new tcu::TestCaseGroup(m_testCtx, "unpackUnorm4x8", "");
	addChild(unpackUnormGroup);
	for (int i = 0; i < ITERATIONS; ++i)
	{
		std::stringstream ss;
		ss << i;
		unpackUnormGroup->addChild(new ShaderBitfieldOperationCaseUnpackUnorm(m_context, ss.str().c_str(),
																			  m_glslVersion, Uvec4(rnd.getUint32())));
	}

	// shader_bitfield_operation.unpackSnorm4x8
	tcu::TestCaseGroup* unpackSnormGroup = new tcu::TestCaseGroup(m_testCtx, "unpackSnorm4x8", "");
	addChild(unpackSnormGroup);
	for (int i = 0; i < ITERATIONS; ++i)
	{
		std::stringstream ss;
		ss << i;
		unpackSnormGroup->addChild(new ShaderBitfieldOperationCaseUnpackSnorm(m_context, ss.str().c_str(),
																			  m_glslVersion, Uvec4(rnd.getUint32())));
	}

	// shader_bitfield_operation.bitfieldExtract
	tcu::TestCaseGroup* bitfieldExtractGroup = new tcu::TestCaseGroup(m_testCtx, "bitfieldExtract", "");
	addChild(bitfieldExtractGroup);
	for (int i = 0; i < ITERATIONS; ++i)
	{
		std::stringstream ss;
		ss << "uint_" << i;
		bitfieldExtractGroup->addChild(new ShaderBitfieldOperationCaseBitfieldExtractUint1(
			m_context, ss.str().c_str(), m_glslVersion, Uvec4(rnd.getUint32()), rnd.getInt(0, 31), rnd.getInt(1, 32)));
	}
	for (int i = 0; i < ITERATIONS; ++i)
	{
		std::stringstream ss;
		ss << "uvec2_" << i;
		bitfieldExtractGroup->addChild(new ShaderBitfieldOperationCaseBitfieldExtractUint2(
			m_context, ss.str().c_str(), m_glslVersion, Uvec4(rnd.getUint32(), rnd.getUint32()), rnd.getInt(0, 31),
			rnd.getInt(1, 32)));
	}
	for (int i = 0; i < ITERATIONS; ++i)
	{
		std::stringstream ss;
		ss << "uvec3_" << i;
		bitfieldExtractGroup->addChild(new ShaderBitfieldOperationCaseBitfieldExtractUint3(
			m_context, ss.str().c_str(), m_glslVersion, Uvec4(rnd.getUint32(), rnd.getUint32(), rnd.getUint32()),
			rnd.getInt(0, 31), rnd.getInt(1, 32)));
	}
	for (int i = 0; i < ITERATIONS; ++i)
	{
		std::stringstream ss;
		ss << "uvec4_" << i;
		bitfieldExtractGroup->addChild(new ShaderBitfieldOperationCaseBitfieldExtractUint4(
			m_context, ss.str().c_str(), m_glslVersion,
			Uvec4(rnd.getUint32(), rnd.getUint32(), rnd.getUint32(), rnd.getUint32()), rnd.getInt(0, 31),
			rnd.getInt(1, 32)));
	}

	for (int i = 0; i < ITERATIONS; ++i)
	{
		std::stringstream ss;
		ss << "int_" << i;
		bitfieldExtractGroup->addChild(new ShaderBitfieldOperationCaseBitfieldExtractInt1(
			m_context, ss.str().c_str(), m_glslVersion, Ivec4(rnd.getUint32()), rnd.getInt(0, 31), rnd.getInt(1, 32)));
	}
	for (int i = 0; i < ITERATIONS; ++i)
	{
		std::stringstream ss;
		ss << "ivec2_" << i;
		bitfieldExtractGroup->addChild(new ShaderBitfieldOperationCaseBitfieldExtractInt2(
			m_context, ss.str().c_str(), m_glslVersion, Ivec4(rnd.getUint32(), rnd.getUint32()), rnd.getInt(0, 31),
			rnd.getInt(1, 32)));
	}
	for (int i = 0; i < ITERATIONS; ++i)
	{
		std::stringstream ss;
		ss << "ivec3_" << i;
		bitfieldExtractGroup->addChild(new ShaderBitfieldOperationCaseBitfieldExtractInt3(
			m_context, ss.str().c_str(), m_glslVersion, Ivec4(rnd.getUint32(), rnd.getUint32(), rnd.getUint32()),
			rnd.getInt(0, 31), rnd.getInt(1, 32)));
	}
	for (int i = 0; i < ITERATIONS; ++i)
	{
		std::stringstream ss;
		ss << "ivec4_" << i;
		bitfieldExtractGroup->addChild(new ShaderBitfieldOperationCaseBitfieldExtractInt4(
			m_context, ss.str().c_str(), m_glslVersion,
			Ivec4(rnd.getUint32(), rnd.getUint32(), rnd.getUint32(), rnd.getUint32()), rnd.getInt(0, 31),
			rnd.getInt(1, 32)));
	}

	// shader_bitfield_operation.bitfieldInsert
	tcu::TestCaseGroup* bitfieldInsertGroup = new tcu::TestCaseGroup(m_testCtx, "bitfieldInsert", "");
	addChild(bitfieldInsertGroup);
	for (int i = 0; i < ITERATIONS; ++i)
	{
		std::stringstream ss;
		ss << "uint_" << i;
		bitfieldInsertGroup->addChild(new ShaderBitfieldOperationCaseBitfieldInsertUint1(
			m_context, ss.str().c_str(), m_glslVersion, Uvec4(rnd.getUint32()), Uvec4(rnd.getUint32()),
			rnd.getInt(0, 31), rnd.getInt(1, 32)));
	}
	for (int i = 0; i < ITERATIONS; ++i)
	{
		std::stringstream ss;
		ss << "uvec2_" << i;
		bitfieldInsertGroup->addChild(new ShaderBitfieldOperationCaseBitfieldInsertUint2(
			m_context, ss.str().c_str(), m_glslVersion, Uvec4(rnd.getUint32(), rnd.getUint32()),
			Uvec4(rnd.getUint32(), rnd.getUint32()), rnd.getInt(0, 31), rnd.getInt(1, 32)));
	}
	for (int i = 0; i < ITERATIONS; ++i)
	{
		std::stringstream ss;
		ss << "uvec3_" << i;
		bitfieldInsertGroup->addChild(new ShaderBitfieldOperationCaseBitfieldInsertUint3(
			m_context, ss.str().c_str(), m_glslVersion, Uvec4(rnd.getUint32(), rnd.getUint32(), rnd.getUint32()),
			Uvec4(rnd.getUint32(), rnd.getUint32(), rnd.getUint32()), rnd.getInt(0, 31), rnd.getInt(1, 32)));
	}
	for (int i = 0; i < ITERATIONS; ++i)
	{
		std::stringstream ss;
		ss << "uvec4_" << i;
		bitfieldInsertGroup->addChild(new ShaderBitfieldOperationCaseBitfieldInsertUint4(
			m_context, ss.str().c_str(), m_glslVersion,
			Uvec4(rnd.getUint32(), rnd.getUint32(), rnd.getUint32(), rnd.getUint32()),
			Uvec4(rnd.getUint32(), rnd.getUint32(), rnd.getUint32(), rnd.getUint32()), rnd.getInt(0, 31),
			rnd.getInt(1, 32)));
	}

	for (int i = 0; i < ITERATIONS; ++i)
	{
		std::stringstream ss;
		ss << "int_" << i;
		bitfieldInsertGroup->addChild(new ShaderBitfieldOperationCaseBitfieldInsertInt1(
			m_context, ss.str().c_str(), m_glslVersion, Ivec4(rnd.getUint32()), Ivec4(rnd.getUint32()),
			rnd.getInt(0, 31), rnd.getInt(1, 32)));
	}
	for (int i = 0; i < ITERATIONS; ++i)
	{
		std::stringstream ss;
		ss << "ivec2_" << i;
		bitfieldInsertGroup->addChild(new ShaderBitfieldOperationCaseBitfieldInsertInt2(
			m_context, ss.str().c_str(), m_glslVersion, Ivec4(rnd.getUint32(), rnd.getUint32()),
			Ivec4(rnd.getUint32(), rnd.getUint32()), rnd.getInt(0, 31), rnd.getInt(1, 32)));
	}
	for (int i = 0; i < ITERATIONS; ++i)
	{
		std::stringstream ss;
		ss << "ivec3_" << i;
		bitfieldInsertGroup->addChild(new ShaderBitfieldOperationCaseBitfieldInsertInt3(
			m_context, ss.str().c_str(), m_glslVersion, Ivec4(rnd.getUint32(), rnd.getUint32(), rnd.getUint32()),
			Ivec4(rnd.getUint32(), rnd.getUint32(), rnd.getUint32()), rnd.getInt(0, 31), rnd.getInt(1, 32)));
	}
	for (int i = 0; i < ITERATIONS; ++i)
	{
		std::stringstream ss;
		ss << "ivec4_" << i;
		bitfieldInsertGroup->addChild(new ShaderBitfieldOperationCaseBitfieldInsertInt4(
			m_context, ss.str().c_str(), m_glslVersion,
			Ivec4(rnd.getUint32(), rnd.getUint32(), rnd.getUint32(), rnd.getUint32()),
			Ivec4(rnd.getUint32(), rnd.getUint32(), rnd.getUint32(), rnd.getUint32()), rnd.getInt(0, 31),
			rnd.getInt(1, 32)));
	}

	struct UnaryTest
	{
		char const* funcName;
		UnaryUFunc  funcU;
		UnaryIFunc  funcI;
	} commonTests[] = {
		{ "bitfieldReverse", bitfieldReverse,
		  reinterpret_cast<UnaryIFunc>(bitfieldReverse) },				  // shader_bitfield_operation.bitfieldReverse
		{ "bitCount", bitCount, reinterpret_cast<UnaryIFunc>(bitCount) }, // shader_bitfield_operation.bitCount
		{ "findLSB", findLSB, reinterpret_cast<UnaryIFunc>(findLSB) },	// shader_bitfield_operation.findLSB
		{ "findMSB", findMSBU, findMSBI },								  // shader_bitfield_operation.findMSB
	};
	for (int test = 0; test < DE_LENGTH_OF_ARRAY(commonTests); ++test)
	{
		tcu::TestCaseGroup* commonGroup = new tcu::TestCaseGroup(m_testCtx, commonTests[test].funcName, "");
		addChild(commonGroup);
		commonGroup->addChild(new ShaderBitfieldOperationCaseUnaryUint1(
			m_context, "uint_zero", m_glslVersion, commonTests[test].funcName, commonTests[test].funcU, Uvec4(0)));
		for (int i = 0; i < ITERATIONS; ++i)
		{
			std::stringstream ss;
			ss << "uint_" << i;
			commonGroup->addChild(new ShaderBitfieldOperationCaseUnaryUint1(
				m_context, ss.str().c_str(), m_glslVersion, commonTests[test].funcName, commonTests[test].funcU,
				Uvec4(rnd.getUint32())));
		}
		for (int i = 0; i < ITERATIONS; ++i)
		{
			std::stringstream ss;
			ss << "uvec2_" << i;
			commonGroup->addChild(new ShaderBitfieldOperationCaseUnaryUint2(
				m_context, ss.str().c_str(), m_glslVersion, commonTests[test].funcName, commonTests[test].funcU,
				Uvec4(rnd.getUint32(), rnd.getUint32())));
		}
		for (int i = 0; i < ITERATIONS; ++i)
		{
			std::stringstream ss;
			ss << "uvec3_" << i;
			commonGroup->addChild(new ShaderBitfieldOperationCaseUnaryUint3(
				m_context, ss.str().c_str(), m_glslVersion, commonTests[test].funcName, commonTests[test].funcU,
				Uvec4(rnd.getUint32(), rnd.getUint32(), rnd.getUint32())));
		}
		for (int i = 0; i < ITERATIONS; ++i)
		{
			std::stringstream ss;
			ss << "uvec4_" << i;
			commonGroup->addChild(new ShaderBitfieldOperationCaseUnaryUint4(
				m_context, ss.str().c_str(), m_glslVersion, commonTests[test].funcName, commonTests[test].funcU,
				Uvec4(rnd.getUint32(), rnd.getUint32(), rnd.getUint32(), rnd.getUint32())));
		}

		commonGroup->addChild(new ShaderBitfieldOperationCaseUnaryInt1(
			m_context, "int_zero", m_glslVersion, commonTests[test].funcName, commonTests[test].funcI, Ivec4(0)));
		commonGroup->addChild(new ShaderBitfieldOperationCaseUnaryInt1(
			m_context, "int_minus_one", m_glslVersion, commonTests[test].funcName, commonTests[test].funcI, Ivec4(-1)));
		for (int i = 0; i < ITERATIONS; ++i)
		{
			std::stringstream ss;
			ss << "int_" << i;
			commonGroup->addChild(new ShaderBitfieldOperationCaseUnaryInt1(
				m_context, ss.str().c_str(), m_glslVersion, commonTests[test].funcName, commonTests[test].funcI,
				Ivec4(rnd.getUint32())));
		}
		for (int i = 0; i < ITERATIONS; ++i)
		{
			std::stringstream ss;
			ss << "ivec2_" << i;
			commonGroup->addChild(new ShaderBitfieldOperationCaseUnaryInt2(
				m_context, ss.str().c_str(), m_glslVersion, commonTests[test].funcName, commonTests[test].funcI,
				Ivec4(rnd.getUint32(), rnd.getUint32())));
		}
		for (int i = 0; i < ITERATIONS; ++i)
		{
			std::stringstream ss;
			ss << "ivec3_" << i;
			commonGroup->addChild(new ShaderBitfieldOperationCaseUnaryInt3(
				m_context, ss.str().c_str(), m_glslVersion, commonTests[test].funcName, commonTests[test].funcI,
				Ivec4(rnd.getUint32(), rnd.getUint32(), rnd.getUint32())));
		}
		for (int i = 0; i < ITERATIONS; ++i)
		{
			std::stringstream ss;
			ss << "ivec4_" << i;
			commonGroup->addChild(new ShaderBitfieldOperationCaseUnaryInt4(
				m_context, ss.str().c_str(), m_glslVersion, commonTests[test].funcName, commonTests[test].funcI,
				Ivec4(rnd.getUint32(), rnd.getUint32(), rnd.getUint32(), rnd.getUint32())));
		}
	}

	// shader_bitfield_operation.uaddCarry
	tcu::TestCaseGroup* uaddCarryGroup = new tcu::TestCaseGroup(m_testCtx, "uaddCarry", "");
	addChild(uaddCarryGroup);
	for (int i = 0; i < ITERATIONS; ++i)
	{
		std::stringstream ss;
		ss << "uint_" << i;
		uaddCarryGroup->addChild(new ShaderBitfieldOperationCaseBinaryUint1(
			m_context, ss.str().c_str(), m_glslVersion, "outUvec4.x = uaddCarry(inUvec4.x, in2Uvec4.x, out2Uvec4.x);",
			uaddCarry, Uvec4(rnd.getUint32()), Uvec4(rnd.getUint32())));
	}
	for (int i = 0; i < ITERATIONS; ++i)
	{
		std::stringstream ss;
		ss << "uvec2_" << i;
		uaddCarryGroup->addChild(new ShaderBitfieldOperationCaseBinaryUint2(
			m_context, ss.str().c_str(), m_glslVersion,
			"outUvec4.xy = uaddCarry(inUvec4.xy, in2Uvec4.xy, out2Uvec4.xy);", uaddCarry,
			Uvec4(rnd.getUint32(), rnd.getUint32()), Uvec4(rnd.getUint32(), rnd.getUint32())));
	}
	for (int i = 0; i < ITERATIONS; ++i)
	{
		std::stringstream ss;
		ss << "uvec3_" << i;
		uaddCarryGroup->addChild(new ShaderBitfieldOperationCaseBinaryUint3(
			m_context, ss.str().c_str(), m_glslVersion,
			"outUvec4.xyz = uaddCarry(inUvec4.xyz, in2Uvec4.xyz, out2Uvec4.xyz);", uaddCarry,
			Uvec4(rnd.getUint32(), rnd.getUint32(), rnd.getUint32()),
			Uvec4(rnd.getUint32(), rnd.getUint32(), rnd.getUint32())));
	}
	for (int i = 0; i < ITERATIONS; ++i)
	{
		std::stringstream ss;
		ss << "uvec4_" << i;
		uaddCarryGroup->addChild(new ShaderBitfieldOperationCaseBinaryUint4(
			m_context, ss.str().c_str(), m_glslVersion, "outUvec4 = uaddCarry(inUvec4, in2Uvec4, out2Uvec4);",
			uaddCarry, Uvec4(rnd.getUint32(), rnd.getUint32(), rnd.getUint32(), rnd.getUint32()),
			Uvec4(rnd.getUint32(), rnd.getUint32(), rnd.getUint32(), rnd.getUint32())));
	}

	// shader_bitfield_operation.usubBorrow
	tcu::TestCaseGroup* usubBorrowGroup = new tcu::TestCaseGroup(m_testCtx, "usubBorrow", "");
	addChild(usubBorrowGroup);
	for (int i = 0; i < ITERATIONS; ++i)
	{
		std::stringstream ss;
		ss << "uint_" << i;
		usubBorrowGroup->addChild(new ShaderBitfieldOperationCaseBinaryUint1(
			m_context, ss.str().c_str(), m_glslVersion, "outUvec4.x = usubBorrow(inUvec4.x, in2Uvec4.x, out2Uvec4.x);",
			usubBorrow, Uvec4(rnd.getUint32()), Uvec4(rnd.getUint32())));
	}
	for (int i = 0; i < ITERATIONS; ++i)
	{
		std::stringstream ss;
		ss << "uvec2_" << i;
		usubBorrowGroup->addChild(new ShaderBitfieldOperationCaseBinaryUint2(
			m_context, ss.str().c_str(), m_glslVersion,
			"outUvec4.xy = usubBorrow(inUvec4.xy, in2Uvec4.xy, out2Uvec4.xy);", usubBorrow,
			Uvec4(rnd.getUint32(), rnd.getUint32()), Uvec4(rnd.getUint32(), rnd.getUint32())));
	}
	for (int i = 0; i < ITERATIONS; ++i)
	{
		std::stringstream ss;
		ss << "uvec3_" << i;
		usubBorrowGroup->addChild(new ShaderBitfieldOperationCaseBinaryUint3(
			m_context, ss.str().c_str(), m_glslVersion,
			"outUvec4.xyz = usubBorrow(inUvec4.xyz, in2Uvec4.xyz, out2Uvec4.xyz);", usubBorrow,
			Uvec4(rnd.getUint32(), rnd.getUint32(), rnd.getUint32()),
			Uvec4(rnd.getUint32(), rnd.getUint32(), rnd.getUint32())));
	}
	for (int i = 0; i < ITERATIONS; ++i)
	{
		std::stringstream ss;
		ss << "uvec4_" << i;
		usubBorrowGroup->addChild(new ShaderBitfieldOperationCaseBinaryUint4(
			m_context, ss.str().c_str(), m_glslVersion, "outUvec4 = usubBorrow(inUvec4, in2Uvec4, out2Uvec4);",
			usubBorrow, Uvec4(rnd.getUint32(), rnd.getUint32(), rnd.getUint32(), rnd.getUint32()),
			Uvec4(rnd.getUint32(), rnd.getUint32(), rnd.getUint32(), rnd.getUint32())));
	}

	// shader_bitfield_operation.umulExtended
	tcu::TestCaseGroup* umulExtendedGroup = new tcu::TestCaseGroup(m_testCtx, "umulExtended", "");
	addChild(umulExtendedGroup);
	for (int i = 0; i < ITERATIONS; ++i)
	{
		std::stringstream ss;
		ss << "uint_" << i;
		umulExtendedGroup->addChild(new ShaderBitfieldOperationCaseBinaryUint1(
			m_context, ss.str().c_str(), m_glslVersion, "umulExtended(inUvec4.x, in2Uvec4.x, outUvec4.x, out2Uvec4.x);",
			umulExtended, Uvec4(rnd.getUint32()), Uvec4(rnd.getUint32())));
	}
	for (int i = 0; i < ITERATIONS; ++i)
	{
		std::stringstream ss;
		ss << "uvec2_" << i;
		umulExtendedGroup->addChild(new ShaderBitfieldOperationCaseBinaryUint2(
			m_context, ss.str().c_str(), m_glslVersion,
			"umulExtended(inUvec4.xy, in2Uvec4.xy, outUvec4.xy, out2Uvec4.xy);", umulExtended,
			Uvec4(rnd.getUint32(), rnd.getUint32()), Uvec4(rnd.getUint32(), rnd.getUint32())));
	}
	for (int i = 0; i < ITERATIONS; ++i)
	{
		std::stringstream ss;
		ss << "uvec3_" << i;
		umulExtendedGroup->addChild(new ShaderBitfieldOperationCaseBinaryUint3(
			m_context, ss.str().c_str(), m_glslVersion,
			"umulExtended(inUvec4.xyz, in2Uvec4.xyz, outUvec4.xyz, out2Uvec4.xyz);", umulExtended,
			Uvec4(rnd.getUint32(), rnd.getUint32(), rnd.getUint32()),
			Uvec4(rnd.getUint32(), rnd.getUint32(), rnd.getUint32())));
	}
	for (int i = 0; i < ITERATIONS; ++i)
	{
		std::stringstream ss;
		ss << "uvec4_" << i;
		umulExtendedGroup->addChild(new ShaderBitfieldOperationCaseBinaryUint4(
			m_context, ss.str().c_str(), m_glslVersion, "umulExtended(inUvec4, in2Uvec4, outUvec4, out2Uvec4);",
			umulExtended, Uvec4(rnd.getUint32(), rnd.getUint32(), rnd.getUint32(), rnd.getUint32()),
			Uvec4(rnd.getUint32(), rnd.getUint32(), rnd.getUint32(), rnd.getUint32())));
	}

	// shader_bitfield_operation.imulExtended
	tcu::TestCaseGroup* imulExtendedGroup = new tcu::TestCaseGroup(m_testCtx, "imulExtended", "");
	addChild(imulExtendedGroup);
	for (int i = 0; i < ITERATIONS; ++i)
	{
		std::stringstream ss;
		ss << "int_" << i;
		imulExtendedGroup->addChild(new ShaderBitfieldOperationCaseBinaryInt1(
			m_context, ss.str().c_str(), m_glslVersion, "imulExtended(inIvec4.x, in2Ivec4.x, outIvec4.x, out2Ivec4.x);",
			imulExtended, Ivec4(rnd.getUint32()), Ivec4(rnd.getUint32())));
	}
	for (int i = 0; i < ITERATIONS; ++i)
	{
		std::stringstream ss;
		ss << "ivec2_" << i;
		imulExtendedGroup->addChild(new ShaderBitfieldOperationCaseBinaryInt2(
			m_context, ss.str().c_str(), m_glslVersion,
			"imulExtended(inIvec4.xy, in2Ivec4.xy, outIvec4.xy, out2Ivec4.xy);", imulExtended,
			Ivec4(rnd.getUint32(), rnd.getUint32()), Ivec4(rnd.getUint32(), rnd.getUint32())));
	}
	for (int i = 0; i < ITERATIONS; ++i)
	{
		std::stringstream ss;
		ss << "ivec3_" << i;
		imulExtendedGroup->addChild(new ShaderBitfieldOperationCaseBinaryInt3(
			m_context, ss.str().c_str(), m_glslVersion,
			"imulExtended(inIvec4.xyz, in2Ivec4.xyz, outIvec4.xyz, out2Ivec4.xyz);", imulExtended,
			Ivec4(rnd.getUint32(), rnd.getUint32(), rnd.getUint32()),
			Ivec4(rnd.getUint32(), rnd.getUint32(), rnd.getUint32())));
	}
	for (int i = 0; i < ITERATIONS; ++i)
	{
		std::stringstream ss;
		ss << "ivec4_" << i;
		imulExtendedGroup->addChild(new ShaderBitfieldOperationCaseBinaryInt4(
			m_context, ss.str().c_str(), m_glslVersion, "imulExtended(inIvec4, in2Ivec4, outIvec4, out2Ivec4);",
			imulExtended, Ivec4(rnd.getUint32(), rnd.getUint32(), rnd.getUint32(), rnd.getUint32()),
			Ivec4(rnd.getUint32(), rnd.getUint32(), rnd.getUint32(), rnd.getUint32())));
	}
}

} // glcts


text:
using System.Collections.Concurrent;
using System.Collections.Generic;
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Adapter;

namespace aaatest.executor.testadapter
{
    /// <summary>
    /// Used as parameter to discoverer
    /// </summary>
    internal class DiscoverySink : ITestCaseDiscoverySink
    {
        private readonly ConcurrentBag<TestCase> _testCases = new ConcurrentBag<TestCase>();
        /// <inheritdoc />
        public void SendTestCase(TestCase discoveredTest)
        {
            _testCases.Add(discoveredTest);
        }

        public IEnumerable<TestCase> Tests => _testCases;
    }
}

redpajama_set_name: RedPajamaGithub


text:
'use strict';
import type {NamedShape, PropTypeAnnotation} from '../../CodegenSchema';

function upperCaseFirst(inString: string): string {
  if (inString.length === 0) {
    return inString;
  }

  return inString[0].toUpperCase() + inString.slice(1);
}

function toSafeCppString(input: string): string {
  return input.split('-').map(upperCaseFirst).join('');
}

function toIntEnumValueName(propName: string, value: number): string {
  return `${toSafeCppString(propName)}${value}`;
}

function getCppTypeForAnnotation(
  type:
    | 'BooleanTypeAnnotation'
    | 'StringTypeAnnotation'
    | 'Int32TypeAnnotation'
    | 'DoubleTypeAnnotation'
    | 'FloatTypeAnnotation',
): string {
  switch (type) {
    case 'BooleanTypeAnnotation':
      return 'bool';
    case 'StringTypeAnnotation':
      return 'std::string';
    case 'Int32TypeAnnotation':
      return 'int';
    case 'DoubleTypeAnnotation':
      return 'double';
    case 'FloatTypeAnnotation':
      return 'Float';
    default:
      (type: empty);
      throw new Error(`Received invalid typeAnnotation ${type}`);
  }
}

function getImports(
  properties: $ReadOnlyArray<NamedShape<PropTypeAnnotation>>,
): Set<string> {
  const imports: Set<string> = new Set();

  function addImportsForNativeName(
    name:
      | 'ColorPrimitive'
      | 'EdgeInsetsPrimitive'
      | 'ImageRequestPrimitive'
      | 'ImageSourcePrimitive'
      | 'PointPrimitive',
  ) {
    switch (name) {
      case 'ColorPrimitive':
        return;
      case 'PointPrimitive':
        return;
      case 'EdgeInsetsPrimitive':
        return;
      case 'ImageRequestPrimitive':
        return;
      case 'ImageSourcePrimitive':
        imports.add('#include <react/renderer/components/image/conversions.h>');
        return;
      default:
        (name: empty);
        throw new Error(`Invalid name, got ${name}`);
    }
  }

  properties.forEach(prop => {
    const typeAnnotation = prop.typeAnnotation;

    if (typeAnnotation.type === 'ReservedPropTypeAnnotation') {
      addImportsForNativeName(typeAnnotation.name);
    }

    if (
      typeAnnotation.type === 'ArrayTypeAnnotation' &&
      typeAnnotation.elementType.type === 'ReservedPropTypeAnnotation'
    ) {
      addImportsForNativeName(typeAnnotation.elementType.name);
    }

    if (typeAnnotation.type === 'ObjectTypeAnnotation') {
      const objectImports = getImports(typeAnnotation.properties);
      // $FlowFixMe[method-unbinding] added when improving typing for this parameters
      objectImports.forEach(imports.add, imports);
    }
  });

  return imports;
}

function generateEventStructName(parts: $ReadOnlyArray<string> = []): string {
  const additional = parts.map(toSafeCppString).join('');
  return `${additional}`;
}

function generateStructName(
  componentName: string,
  parts: $ReadOnlyArray<string> = [],
): string {
  const additional = parts.map(toSafeCppString).join('');
  return `${componentName}${additional}Struct`;
}

function getEnumName(componentName: string, propName: string): string {
  const uppercasedPropName = toSafeCppString(propName);
  return `${componentName}${uppercasedPropName}`;
}

function getEnumMaskName(enumName: string): string {
  return `${enumName}Mask`;
}

function convertDefaultTypeToString(
  componentName: string,
  prop: NamedShape<PropTypeAnnotation>,
): string {
  const typeAnnotation = prop.typeAnnotation;
  switch (typeAnnotation.type) {
    case 'BooleanTypeAnnotation':
      if (typeAnnotation.default == null) {
        return '';
      }
      return String(typeAnnotation.default);
    case 'StringTypeAnnotation':
      if (typeAnnotation.default == null) {
        return '';
      }
      return `"${typeAnnotation.default}"`;
    case 'Int32TypeAnnotation':
      return String(typeAnnotation.default);
    case 'DoubleTypeAnnotation':
      const defaultDoubleVal = typeAnnotation.default;
      return parseInt(defaultDoubleVal, 10) === defaultDoubleVal
        ? typeAnnotation.default.toFixed(1)
        : String(typeAnnotation.default);
    case 'FloatTypeAnnotation':
      const defaultFloatVal = typeAnnotation.default;
      if (defaultFloatVal == null) {
        return '';
      }
      return parseInt(defaultFloatVal, 10) === defaultFloatVal
        ? defaultFloatVal.toFixed(1)
        : String(typeAnnotation.default);
    case 'ReservedPropTypeAnnotation':
      switch (typeAnnotation.name) {
        case 'ColorPrimitive':
          return '';
        case 'ImageSourcePrimitive':
          return '';
        case 'ImageRequestPrimitive':
          return '';
        case 'PointPrimitive':
          return '';
        case 'EdgeInsetsPrimitive':
          return '';
        default:
          (typeAnnotation.name: empty);
          throw new Error(
            `Unsupported type annotation: ${typeAnnotation.name}`,
          );
      }
    case 'ArrayTypeAnnotation': {
      const elementType = typeAnnotation.elementType;
      switch (elementType.type) {
        case 'StringEnumTypeAnnotation':
          if (elementType.default == null) {
            throw new Error(
              'A default is required for array StringEnumTypeAnnotation',
            );
          }
          const enumName = getEnumName(componentName, prop.name);
          const enumMaskName = getEnumMaskName(enumName);
          const defaultValue = `${enumName}::${toSafeCppString(
            elementType.default,
          )}`;
          return `static_cast<${enumMaskName}>(${defaultValue})`;
        default:
          return '';
      }
    }
    case 'ObjectTypeAnnotation': {
      return '';
    }
    case 'StringEnumTypeAnnotation':
      return `${getEnumName(componentName, prop.name)}::${toSafeCppString(
        typeAnnotation.default,
      )}`;
    case 'Int32EnumTypeAnnotation':
      return `${getEnumName(componentName, prop.name)}::${toIntEnumValueName(
        prop.name,
        typeAnnotation.default,
      )}`;
    default:
      (typeAnnotation: empty);
      throw new Error(`Unsupported type annotation: ${typeAnnotation.type}`);
  }
}

module.exports = {
  convertDefaultTypeToString,
  getCppTypeForAnnotation,
  getEnumName,
  getEnumMaskName,
  getImports,
  toSafeCppString,
  toIntEnumValueName,
  generateStructName,
  generateEventStructName,
};


text:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;

namespace Lucas.Solutions.Controllers
{
    using Lucas.Solutions.IO;

    public class PartiesController : ApiController
    {
        private IPartyStore _partyStore;

        // GET: api/Parties
        public IEnumerable<string> Get()
        {
            return new string[] { "value1", "value2" };
        }

        // GET: api/Parties/5
        public Party Get(int id)
        {
            return new Party();
        }

        // POST: api/Parties
        public void Post([FromBody]Party value)
        {
        }

        // PUT: api/Parties/5
        public void Put(int id, [FromBody]Party value)
        {
        }

        // DELETE: api/Parties/5
        public void Delete(int id)
        {
        }
    }
}


text:
package org.apache.pinot.spi.ingestion.batch.spec;

import java.io.Serializable;
import java.util.Map;

/**
 * ExecutionFrameworkSpec defines which ingestion jobs to be running.
 */
public class ExecutionFrameworkSpec implements Serializable {
  /**
   * The name of the execution framework, currently supports: Standalone.
   */
  private String _name;

  /**
   * The class implements org.apache.pinot.spi.ingestion.batch.runner.IngestionJobRunner interface.
   */
  private String _segmentGenerationJobRunnerClassName;

  /**
   * The class implements org.apache.pinot.spi.ingestion.batch.runner.IngestionJobRunner interface.
   */
  private String _segmentTarPushJobRunnerClassName;

  /**
   * The class implements org.apache.pinot.spi.ingestion.batch.runner.IngestionJobRunner interface.
   */
  private String _segmentUriPushJobRunnerClassName;

  /**
   * The class implements org.apache.pinot.spi.ingestion.batch.runner.IngestionJobRunner interface.
   */
  private String _segmentMetadataPushJobRunnerClassName;

  /**
   * Extra configs for execution framework.
   */
  private Map<String, String> _extraConfigs;

  public String getName() {
    return _name;
  }

  public void setName(String name) {
    _name = name;
  }

  public String getSegmentGenerationJobRunnerClassName() {
    return _segmentGenerationJobRunnerClassName;
  }

  public void setSegmentGenerationJobRunnerClassName(String segmentGenerationJobRunnerClassName) {
    _segmentGenerationJobRunnerClassName = segmentGenerationJobRunnerClassName;
  }

  public String getSegmentTarPushJobRunnerClassName() {
    return _segmentTarPushJobRunnerClassName;
  }

  public void setSegmentTarPushJobRunnerClassName(String segmentTarPushJobRunnerClassName) {
    _segmentTarPushJobRunnerClassName = segmentTarPushJobRunnerClassName;
  }

  public String getSegmentUriPushJobRunnerClassName() {
    return _segmentUriPushJobRunnerClassName;
  }

  public void setSegmentUriPushJobRunnerClassName(String segmentUriPushJobRunnerClassName) {
    _segmentUriPushJobRunnerClassName = segmentUriPushJobRunnerClassName;
  }

  public Map<String, String> getExtraConfigs() {
    return _extraConfigs;
  }

  public void setExtraConfigs(Map<String, String> extraConfigs) {
    _extraConfigs = extraConfigs;
  }

  public String getSegmentMetadataPushJobRunnerClassName() {
    return _segmentMetadataPushJobRunnerClassName;
  }

  public void setSegmentMetadataPushJobRunnerClassName(String segmentMetadataPushJobRunnerClassName) {
    _segmentMetadataPushJobRunnerClassName = segmentMetadataPushJobRunnerClassName;
  }
}


text: Computational Physics Fall 2015


text:
module Flapjack
  module Filters
    module Base
      def name
        self.class.to_s.split('::').last
      end
    end
  end
end


text:
from restriccion.libs.env import load_env_params

CONFIG = load_env_params()


text:
require File.expand_path(File.dirname(__FILE__) + '/../../../test/test_helper')

# Ensure that we are using the temporary fixture path
#Engines::Testing.set_fixture_path


text:
//
//////////////////////////////////////////////////////////////////////////////
//
//  Copyright 2013 Autodesk, Inc.  All rights reserved.
//
//  Use of this software is subject to the terms of the Autodesk license
//  agreement provided at the time of installation or download, or which
//  otherwise accompanies this software in either electronic or hard copy form.
//
//////////////////////////////////////////////////////////////////////////////
//
// AcGiStyleAttributes interface

#ifndef __AcGiStyleAttributes_H_Defined__
#define __AcGiStyleAttributes_H_Defined__

#include "AcGiLineAttributes.h"

class ADESK_NO_VTABLE AcGiStyleAttributes
{
public:

    enum AttributeFlags {
        kNothing                = 0x00,
        kColor                  = 0x01,
        kLine                   = 0x02,
        kLineType               = 0x04,
        kPlotStyle              = 0x08,
        kEverything             = 0x0F
    };

    // Ctor/dtor/copy
    AcGiStyleAttributes()   { }
    AcGiStyleAttributes(const AcGiStyleAttributes& source);
    virtual ~AcGiStyleAttributes()  { }

    // Member data access
    // Color
    AcCmEntityColor& getColorAttribute();
    const AcCmEntityColor& getColorAttribute() const;
    void setColorAttribute(const AcCmEntityColor& color);

    // Complex line type
    AcDbObjectId linetypeObjectId() const;
    void setLinetypeObjectId(const AcDbObjectId& newId);

    // Plot style
    AcDbObjectId plotStyleNameId() const;
    void setPlotStyleName(const AcDbObjectId& newId);

    // Interface methods - Other line attributes
    virtual AcGiLineAttributes* getLineAttribute()                              = 0;
    virtual const AcGiLineAttributes* getLineAttribute() const                  = 0;
    virtual void setLineAttribute(const AcGiLineAttributes* pLineAttributes)    = 0;

    virtual void EnsureColorVisibility (AcCmEntityColor& color)                 = 0;

protected:
    /* The style engine will resolve the color, taking into account color
        policy, dither, specified color, assigned pen number, and dimming.
        If m_colorAttribute.isByColor() then use
        getColorAttribute().color();
        if m_colorAttribute.isByPen() then use
        getColorAttribute().penIndex()
    */
    AcCmEntityColor m_colorAttribute;

    AcDbObjectId    m_idLinetype;
    AcDbObjectId    m_idPlotstyle;
};

inline
AcGiStyleAttributes::AcGiStyleAttributes(
    const AcGiStyleAttributes& source)
{
    m_colorAttribute = source.getColorAttribute();
    m_idLinetype = source.linetypeObjectId();
    m_idPlotstyle = source.plotStyleNameId();
}

inline
AcCmEntityColor&
AcGiStyleAttributes::getColorAttribute()
{
    return m_colorAttribute;
}

inline
const AcCmEntityColor&
AcGiStyleAttributes::getColorAttribute() const
{
    return m_colorAttribute;
}

inline
void
AcGiStyleAttributes::setColorAttribute (
    const AcCmEntityColor& color)
{
    m_colorAttribute = color;
}

inline
AcDbObjectId
AcGiStyleAttributes::linetypeObjectId() const
{
    return m_idLinetype;
}

inline
void
AcGiStyleAttributes::setLinetypeObjectId(const AcDbObjectId& newId)
{
    m_idLinetype = newId;
}

inline
AcDbObjectId
AcGiStyleAttributes::plotStyleNameId() const
{
    return m_idPlotstyle;
}

inline
void
AcGiStyleAttributes::setPlotStyleName(const AcDbObjectId& newId)
{
    m_idPlotstyle = newId;
}

#endif // #ifndef __AcGiStyleAttributes_H_Defined__


text:
package es.tid.pce.computingEngine.algorithms.sson;

import java.net.Inet4Address;
import java.util.LinkedList;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import org.jgrapht.GraphPath;
import org.jgrapht.alg.DijkstraShortestPath;
import org.jgrapht.graph.SimpleDirectedWeightedGraph;

import es.tid.pce.computingEngine.ComputingRequest;
import es.tid.pce.computingEngine.ComputingResponse;
import es.tid.pce.computingEngine.algorithms.AlgorithmReservation;
import es.tid.pce.computingEngine.algorithms.ComputingAlgorithm;
import es.tid.pce.computingEngine.algorithms.PCEPUtils;
import es.tid.pce.computingEngine.algorithms.utilities.bandwidthToSlotConversion;
import es.tid.pce.computingEngine.algorithms.utilities.graphs_comparator;
import es.tid.pce.pcep.constructs.EndPoint;
import es.tid.pce.pcep.constructs.EndPointAndRestrictions;
import es.tid.pce.pcep.constructs.GeneralizedBandwidthSSON;
import es.tid.pce.pcep.constructs.P2MPEndpoints;
import es.tid.pce.pcep.constructs.P2PEndpoints;
import es.tid.pce.pcep.constructs.Path;
import es.tid.pce.pcep.constructs.Request;
import es.tid.pce.pcep.constructs.Response;
import es.tid.pce.pcep.objects.BandwidthRequested;
import es.tid.pce.pcep.objects.BandwidthRequestedGeneralizedBandwidth;
import es.tid.pce.pcep.objects.EndPoints;
import es.tid.pce.pcep.objects.EndPointsIPv4;
import es.tid.pce.pcep.objects.ExplicitRouteObject;
import es.tid.pce.pcep.objects.GeneralizedEndPoints;
import es.tid.pce.pcep.objects.Metric;
import es.tid.pce.pcep.objects.Monitoring;
import es.tid.pce.pcep.objects.NoPath;
import es.tid.pce.pcep.objects.ObjectParameters;
import es.tid.pce.pcep.objects.RequestParameters;
import es.tid.pce.pcep.objects.tlvs.NoPathTLV;
import es.tid.pce.server.wson.ReservationManager;
import es.tid.rsvp.RSVPProtocolViolationException;
import es.tid.rsvp.constructs.gmpls.DWDMWavelengthLabel;
import es.tid.rsvp.objects.subobjects.GeneralizedLabelEROSubobject;
import es.tid.rsvp.objects.subobjects.IPv4prefixEROSubobject;
import es.tid.rsvp.objects.subobjects.UnnumberIfIDEROSubobject;
import es.tid.tedb.DomainTEDB;
import es.tid.tedb.IntraDomainEdge;
import es.tid.tedb.SSONInformation;
import es.tid.tedb.TEDB;

/**
 * Implementation of the algorithm "Adaptive Unconstrained Routing Exhaustive".
 *
 *
Reference: A. Mokhtar y M. Azizoglu, "Adaptive wavelength routing in all-optical networks",
 * IEEE/ACM Transactions on Networking, vol. 6, no.2 pp. 197 - 201, abril 1998

 * @author arturo mayoral
 *
 */
public class AURE_SSON_algorithm implements ComputingAlgorithm {

	/**
	 * The Logger.
	 */
	private Logger log=LoggerFactory.getLogger("PCEServer");

	/**
	 * The Path Computing Request to calculate.
	 */
	private ComputingRequest pathReq;

	/**
	 * Access to the Precomputation part of the algorithm.
	 */
	private AURE_SSON_algorithmPreComputation preComp;

	/**
	 * Access to the Reservation Manager to make reservations of Wavalengths/labels.
	 */
	private ReservationManager reservationManager;

	private SSONInformation SSONInfo;

//	/**
//	 * Number of wavelenghts (labels).
//	 */
	//private int num_lambdas;

	/**
	 * The traffic engineering database
	 */
	private DomainTEDB ted;

	private GenericLambdaReservation  reserv;

	public AURE_SSON_algorithm(ComputingRequest pathReq,TEDB ted, ReservationManager reservationManager, int mf){
		//this.num_lambdas=((DomainTEDB)ted).getWSONinfo().getNumLambdas();
		this.pathReq=pathReq;
		this.reservationManager=reservationManager;
		this.ted=(DomainTEDB)ted;
	}

	public ComputingResponse call(){
		//Timestamp of the start of the algorithm;
		long tiempoini =System.nanoTime();
		log.debug("Starting AURE Algorithm");
		//Create the response message
		//It will contain either the path or noPath
		ComputingResponse m_resp=new ComputingResponse();
		m_resp.setEncodingType(pathReq.getEcodingType());
		//The request that needs to be solved
		Request req=pathReq.getRequestList().get(0);
		//Request Id, needed for the response
		long reqId=req.getRequestParameters().getRequestID();
		log.info("Request id: "+reqId+", getting endpoints");
		//Start creating the response
		Response response=new Response();
		RequestParameters rp = new RequestParameters();
		rp.setRequestID(reqId);
		response.setRequestParameters(rp);
		m_resp.addResponse(response);

		//esto hay que cambiarlo para poder leer del GENERALIZED END POINTS
		//if (getObjectType(req.getEndPoints()))
		EndPoints  EP= req.getEndPoints();

		int num_slots = 0;
		int cs;
		int m=0;

		// Conversión Bw a numero de slots en función de la grid.

		bandwidthToSlotConversion conversion= new bandwidthToSlotConversion();

		BandwidthRequested Bw = null;
		BandwidthRequestedGeneralizedBandwidth  bw =null;
		//ERROR
		log.info(" XXXX req.getBandwidth(): " + req.getBandwidth());
		if (req.getBandwidth() instanceof BandwidthRequested){
			Bw = (BandwidthRequested)req.getBandwidth();
			log.info("BW: "+Bw.getBw());
			// Conversión Bw a numero de slots en función de la grid.
			if (Bw.getBw()!=0){
				SSONInfo=((DomainTEDB)ted).getSSONinfo();
				cs = SSONInfo.getCs();
				num_slots=conversion.getNumSlots(Bw.getBw(), cs);

			}
		}else if (req.getBandwidth() instanceof BandwidthRequestedGeneralizedBandwidth){
			bw= (BandwidthRequestedGeneralizedBandwidth)req.getBandwidth();
			log.info("BW: "+bw.getGeneralizedBandwidth());
			if(bw.getGeneralizedBandwidth()!= null){

				if(bw.getGeneralizedBandwidth() instanceof GeneralizedBandwidthSSON ){
				log.info("bw.getGeneralizedBandwidth() is GeneralizedBandwidthSSON type");
				GeneralizedBandwidthSSON a = (GeneralizedBandwidthSSON)bw.getGeneralizedBandwidth();
				m=a.getM();
				num_slots=m*2;
				log.info("XXXX num_slots:"+num_slots);
				}else
					log.info("XXXX bw.getGeneralizedBandwidth() is NOT GeneralizedBandwidthSSON:" +  bw.getGeneralizedBandwidth());
			}
		}

		//BandwidthRequestedGeneralizedBandwidth  bw= (BandwidthRequestedGeneralizedBandwidth)req.getBandwidth(); // Objeto bandwidth para saber la demanda de la peticion.
		Object source_router_id_addr = null;
		Object dest_router_id_addr = null;
		graphs_comparator grc = new graphs_comparator ();

			log.info("Request num_slots: "+num_slots);

		if (EP.getOT()==ObjectParameters.PCEP_OBJECT_TYPE_ENDPOINTS_IPV4){
			EndPointsIPv4  ep=(EndPointsIPv4) req.getEndPoints();
			source_router_id_addr=ep.getSourceIP();
			dest_router_id_addr=ep.getDestIP();
		}else if (EP.getOT()==ObjectParameters.PCEP_OBJECT_TYPE_ENDPOINTS_IPV6){

		}else if (EP.getOT()==ObjectParameters.PCEP_OBJECT_TYPE_GENERALIZED_ENDPOINTS){
			log.info("EP.getOT()==ObjectParameters.PCEP_OBJECT_TYPE_GENERALIZED_ENDPOINTS");
			GeneralizedEndPoints  gep=(GeneralizedEndPoints) req.getEndPoints();
			if(gep.getGeneralizedEndPointsType()==ObjectParameters.PCEP_GENERALIZED_END_POINTS_TYPE_P2P){
				P2PEndpoints p2pep= gep.getP2PEndpoints();
				EndPoint sourceep=p2pep.getSourceEndPoint();
				EndPoint destep=p2pep.getDestinationEndPoint();
				source_router_id_addr=sourceep.getEndPointIPv4TLV().IPv4address;
				dest_router_id_addr=destep.getEndPointIPv4TLV().IPv4address;
			}
			if(gep.getGeneralizedEndPointsType()==ObjectParameters.PCEP_GENERALIZED_END_POINTS_TYPE_P2MP_NEW_LEAVES){
				P2MPEndpoints p2mpep= gep.getP2MPEndpoints();
				EndPointAndRestrictions epandrest=p2mpep.getEndPointAndRestrictions();
				EndPoint sourceep=epandrest.getEndPoint();
				source_router_id_addr=sourceep.getEndPointIPv4TLV().IPv4address;
				int cont=0;
				while (cont<=p2mpep.getEndPointAndRestrictionsList().size()){ //esto est� mal
					epandrest=p2mpep.getEndPointAndRestrictionsList().get(cont);
					EndPoint destep=epandrest.getEndPoint();
					source_router_id_addr=sourceep.getEndPointIPv4TLV().IPv4address;
					dest_router_id_addr=destep.getEndPointIPv4TLV().IPv4address;

				}
			}
		}
		//aqu� acaba lo que he a�adido

		//Now, check if the source and destination are in the TED.
		log.info("Source: "+source_router_id_addr+"; Destination:"+dest_router_id_addr);
		if (!(((ted.containsVertex(source_router_id_addr))&&(ted.containsVertex(dest_router_id_addr))))){
			log.info("Source or destination are NOT in the TED");
			NoPath noPath= new NoPath();
			noPath.setNatureOfIssue(ObjectParameters.NOPATH_NOPATH_SAT_CONSTRAINTS);
			NoPathTLV noPathTLV=new NoPathTLV();
			if (!((ted.containsVertex(source_router_id_addr)))){
				log.debug("Unknown source");
				noPathTLV.setUnknownSource(true);
			}
			if (!((ted.containsVertex(dest_router_id_addr)))){
				log.debug("Unknown destination");
				noPathTLV.setUnknownDestination(true);
			}

			noPath.setNoPathTLV(noPathTLV);
			response.setNoPath(noPath);
			return m_resp;
		}
		// check if src and dst are the same
		if (source_router_id_addr.equals(dest_router_id_addr)){
			log.info("Source and destination are the same!");
			Path path=new Path();
			ExplicitRouteObject ero= new ExplicitRouteObject();
			IPv4prefixEROSubobject eroso= new IPv4prefixEROSubobject();
			eroso.setIpv4address((Inet4Address)source_router_id_addr);
			eroso.setPrefix(32);
			ero.addEROSubobject(eroso);
			path.setEro(ero);

			if (req.getMetricList().size()!=0){
				Metric metric=new Metric();
				metric.setMetricType(req.getMetricList().get(0).getMetricType() );
				log.debug("Number of hops "+0);
				float metricValue=0;
				metric.setMetricValue(metricValue);
				path.getMetricList().add(metric);
			}
			response.addPath(path);
			long tiempofin =System.nanoTime();
			long tiempotot=tiempofin-tiempoini;
			log.info("Ha tardado "+tiempotot+" nanosegundos");
			Monitoring monitoring=pathReq.getMonitoring();
			if (monitoring!=null){
				if (monitoring.isProcessingTimeBit()){

				}
			}
			m_resp.addResponse(response);
			return m_resp;

		}

		boolean nopath=true;//Initially, we still have no path
		boolean end=false;//The search has not ended yet
		int lambda=0;//We begin with lambda index 0
		int lambda_chosen=0;//We begin with lambda index 0
		int central_freq=0; // It represents the central frequency slot n.
		int counter=0;
		boolean is_equal = false;

		double max_metric=Integer.MAX_VALUE;
		log.info("Starting the computation");
		GraphPath<Object,IntraDomainEdge> gp_chosen=null;
		GraphPath<Object,IntraDomainEdge> gp_trully_chosen=null;

		preComp.getGraphLock().lock();
		try{
			while (!end){
				SimpleDirectedWeightedGraph<Object,IntraDomainEdge> graphLambda=preComp.getNetworkGraphs().get(lambda);

				//log.info("Grafo ok "+lambda);
				//log.info("Grafo : "+preComp.printBaseTopology());
				DijkstraShortestPath<Object,IntraDomainEdge>  dsp=new DijkstraShortestPath<Object,IntraDomainEdge> (graphLambda, source_router_id_addr, dest_router_id_addr);
				GraphPath<Object,IntraDomainEdge> gp=dsp.getPath();
				//log.info("DSP completed");
				if (gp==null){
					//There is no path here
					counter=0;
					if (lambda>=preComp.getSSONInfo().getNumLambdas()-1){
						if (nopath==true){
							log.debug("No path found");
							NoPath noPath= new NoPath();
							noPath.setNatureOfIssue(ObjectParameters.NOPATH_NOPATH_SAT_CONSTRAINTS);
							NoPathTLV noPathTLV=new NoPathTLV();
							noPath.setNoPathTLV(noPathTLV);
							response.setNoPath(noPath);
							return m_resp;
						}else {
							end=true;
						}

					}else {
						lambda=lambda+1;
					}

				}
				else{

					if (counter==0){
						if (lambda>=preComp.getSSONInfo().getNumLambdas()-1){
							if (nopath==true){
								log.debug("No path found");
								NoPath noPath= new NoPath();
								noPath.setNatureOfIssue(ObjectParameters.NOPATH_NOPATH_SAT_CONSTRAINTS);
								NoPathTLV noPathTLV=new NoPathTLV();
								noPath.setNoPathTLV(noPathTLV);
								response.setNoPath(noPath);
								return m_resp;
							}else {
								end=true;
							}

						}
						else{
							if (gp.getWeight()<max_metric){
								log.info("LAMBDA "+lambda +" with metric "+gp.getWeight());
								gp_chosen=gp;
								counter=counter+1;
								lambda=lambda+1;
								lambda_chosen=lambda;
								end=false;
							}
							else{
								lambda=lambda+1;
								counter=0;
							}
						}
					}

					else{
						is_equal=grc.edges_comparator(gp, gp_chosen);
						if (is_equal == true){
							counter=counter+1;
							if (counter==num_slots){
									gp_trully_chosen=gp;
									max_metric=gp.getWeight();
									central_freq=lambda-(int)((num_slots-1)/2);
									m=(num_slots)/2;
									counter=0;
									log.info("Central Frequency"+central_freq);
									log.info("Frequency width"+m);
									log.info("Path"+gp_trully_chosen);
									nopath=false;
									//end=true;
								if (lambda>=preComp.getSSONInfo().getNumLambdas()-1){
									nopath=false;
									end=true;
								}
								else {
									lambda=lambda+1;
								}
							}
							else{
								if (lambda>=preComp.getSSONInfo().getNumLambdas()-1){
									if (nopath==true){
										log.debug("No path found");
										NoPath noPath= new NoPath();
										noPath.setNatureOfIssue(ObjectParameters.NOPATH_NOPATH_SAT_CONSTRAINTS);
										NoPathTLV noPathTLV=new NoPathTLV();
										noPath.setNoPathTLV(noPathTLV);
										response.setNoPath(noPath);
										return m_resp;
									}else {
										end=true;
									}
								}else {
									lambda=lambda+1;
									lambda_chosen=lambda;
								}
							}
						}
						else {
							counter=0;
							gp_chosen=null;
							log.info("Camino Distinto en lambda "+lambda);
							if (lambda>=preComp.getSSONInfo().getNumLambdas()-1){
								if (nopath==true){
									log.debug("No path found");
									NoPath noPath= new NoPath();
									noPath.setNatureOfIssue(ObjectParameters.NOPATH_NOPATH_SAT_CONSTRAINTS);
									NoPathTLV noPathTLV=new NoPathTLV();
									noPath.setNoPathTLV(noPathTLV);
									response.setNoPath(noPath);
									return m_resp;
								}else {
									end=true;
								}
							}
							else {
								end=false;
							}
						}
					}
				}
			}
		}
		finally{
			preComp.getGraphLock().unlock();
		}
		if (nopath==false){

			Path path=new Path();
			ExplicitRouteObject ero= new ExplicitRouteObject();
			List<IntraDomainEdge> edge_list=gp_trully_chosen.getEdgeList();
			int i;

			for (i=0;i<edge_list.size();i++){
				UnnumberIfIDEROSubobject eroso= new UnnumberIfIDEROSubobject();
				eroso.setRouterID((Inet4Address)edge_list.get(i).getSource());
				eroso.setInterfaceID(edge_list.get(i).getSrc_if_id());
				eroso.setLoosehop(false);
				ero.addEROSubobject(eroso);
				preComp.getGraphLock().lock();
				//FIXME: Temp, only for HPCE algorithms
				log.info("Lets remove: "+m+(central_freq)+preComp.getSSONInfo().getnMin()+edge_list.get(i).getSource()+edge_list.get(i).getTarget());
				preComp.setReservation(m, (central_freq)+preComp.getSSONInfo().getnMin(), (Inet4Address)edge_list.get(i).getSource(), (Inet4Address)edge_list.get(i).getTarget());

				for (int p=(central_freq)+preComp.getSSONInfo().getnMin()-m; p<(central_freq)+preComp.getSSONInfo().getnMin()+m; p++) {
					log.info("Borramos: "+p);
					preComp.getNetworkGraphs().get(p).removeEdge(edge_list.get(i).getSource(), edge_list.get(i).getTarget());
				}

				preComp.getGraphLock().unlock();

				//ITU-T Format
				DWDMWavelengthLabel WDMlabel=new DWDMWavelengthLabel();
				WDMlabel.setGrid(preComp.getSSONInfo().getGrid());
				WDMlabel.setChannelSpacing(preComp.getSSONInfo().getCs());
				WDMlabel.setN((central_freq)+preComp.getSSONInfo().getnMin());
				WDMlabel.setM(m);
				WDMlabel.setIdentifier(0);
				try {
					WDMlabel.encode();
				} catch (RSVPProtocolViolationException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}

				GeneralizedLabelEROSubobject genLabel= new GeneralizedLabelEROSubobject();
				ero.addEROSubobject(genLabel);

				genLabel.setLabel(WDMlabel.getBytes());
				log.info("ero:" +ero);

				if(req.getRequestParameters().isBidirect()==true){
					//ITU-T Format
					DWDMWavelengthLabel WDMlabel_bidirect=new DWDMWavelengthLabel();
					WDMlabel_bidirect.setGrid(preComp.getSSONInfo().getGrid());
					WDMlabel_bidirect.setChannelSpacing(preComp.getSSONInfo().getCs());
					WDMlabel_bidirect.setN((central_freq)+preComp.getSSONInfo().getnMin());
					WDMlabel_bidirect.setM(m);
					WDMlabel_bidirect.setIdentifier(0);
					try {
						WDMlabel_bidirect.encode();
					} catch (RSVPProtocolViolationException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}

					GeneralizedLabelEROSubobject genLabel_bidirect= new GeneralizedLabelEROSubobject();
					short Ubit = 1;
					genLabel_bidirect.setUbit(Ubit);
					ero.addEROSubobject(genLabel_bidirect);
					genLabel_bidirect.setLabel(WDMlabel_bidirect.getBytes());
				}
				log.info("ero:" +ero);
			}
			log.info("ero:" +ero);

			//log.info("Label bit map: "+ted.getWSONinfo().getCommonAvailableLabels().getLabelSet().toString());
			BandwidthRequestedGeneralizedBandwidth gb = new BandwidthRequestedGeneralizedBandwidth ();
			GeneralizedBandwidthSSON GB_SSON = new GeneralizedBandwidthSSON();
	        GB_SSON.setM(m);
	        gb.setGeneralizedBandwidth(GB_SSON);

			IPv4prefixEROSubobject eroso= new IPv4prefixEROSubobject();
			eroso.setIpv4address((Inet4Address)edge_list.get(edge_list.size()-1).getTarget());
			eroso.setPrefix(32);
			ero.addEROSubobject(eroso);
			path.setEro(ero);
			path.setBandwidth(gb);
			PCEPUtils.completeMetric(path, req, edge_list);
			if (Bw!=null){
				response.setBandwidth(Bw);
			}else if (bw!=null){
				response.setBandwidth(bw);
			}
			response.addPath(path);

			//FIXME: RESERVATION NEEDS TO BE IMPROVED!!!
			LinkedList<Object> sourceVertexList=new LinkedList<Object>();
			LinkedList<Object> targetVertexList=new LinkedList<Object>();
			for (i=0;i<edge_list.size();i++){
				sourceVertexList.add(edge_list.get(i).getSource());
				targetVertexList.add(edge_list.get(i).getTarget());
			}
			sourceVertexList.add(edge_list.get(i-1).getSource());
			targetVertexList.add(edge_list.get(i-1).getTarget());

			if (req.getReservation()!=null){
			  reserv= new GenericLambdaReservation();
			  reserv.setResp(m_resp);
			  reserv.setLambda_chosen(central_freq);
			  reserv.setBidirectional(req.getRequestParameters().isBidirect());
			  reserv.setReservation(req.getReservation());
			  reserv.setSourceVertexList(sourceVertexList);
			  reserv.setTargetVertexList(targetVertexList);
			  reserv.setReservationManager(reservationManager);
			}

		}
		long tiempofin =System.nanoTime();
		long tiempotot=tiempofin-tiempoini;
		log.info("Ha tardado "+tiempotot+" nanosegundos");
		return m_resp;
	}

	public void setPreComp(AURE_SSON_algorithmPreComputation preComp) {
		this.preComp = preComp;
	}

	public AlgorithmReservation getReserv() {
		return reserv;
	}

}


text:
  Carquebut est
       un village
       situé dans le département de Manche en Basse-Normandie. Elle comptait 297 habitants en 2008.

À proximité de Carquebut sont positionnées géographiquement les communes de
Beuzeville-la-Bastille située à 3 km, 148 habitants,
Houesville située à 3 km, 246 habitants,
Écoquenéauville située à 4 km, 69 habitants,
Houtteville située à 4 km, 91 habitants,
Sébeville située à 3 km, 32 habitants,
Hiesville située à 4 km, 67 habitants,
 entre autres. De plus, Carquebut est située à seulement 18 km de Valognes.

Le nombre d'habitations, à Carquebut, se décomposait en 2011 en zero appartements et 137 maisons soit
 un marché plutôt équilibré.

Si vous envisagez de demenager à Carquebut, vous pourrez aisément trouver une maison à acheter.


text:
package qit.jpa.entity.tomcat;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.TableGenerator;
import javax.persistence.UniqueConstraint;

import org.eclipse.persistence.annotations.Multitenant;

@Entity
@Multitenant
@Table (
		name = "ROLES",
		uniqueConstraints = @UniqueConstraint(columnNames={"TENANT_ID", "ROLE"})
		)
@NamedQueries ({
	@NamedQuery (name = "findAllRoles", query = "SELECT m  FROM RoleEO m ORDER BY m.role ASC")
})
public class QitRoleEO implements Serializable {

	private static final long serialVersionUID = 1L;

	@Id
	@TableGenerator(name="RoleIdGen", table="ROLEIDGEN")
	@GeneratedValue(strategy=GenerationType.TABLE, generator="RoleIdGen")
	@Column (name = "ID")
	private Long id;

	@Column (name = "ROLE", nullable=false, length=256)
	private String role;

	@Column (name = "DESC", nullable=true, length=512)
	private String description;

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getRole() {
		return role;
	}

	public void setRole(String role) {
		this.role = role;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}
}


text:
<?php
/**
 * Message translations.
 *
 * This file is automatically generated by 'yii message' command.
 * It contains the localizable messages extracted from source code.
 * You may modify this file by translating the extracted messages.
 *
 * Each array element represents the translation (value) of a message (key).
 * If the value is empty, the message is considered as not translated.
 * Messages that no longer need translation will have their translations
 * enclosed between a pair of '@@' marks.
 *
 * Message string can be used with plural forms format. Check i18n section
 * of the guide for details.
 *
 * NOTE: this file must be saved in UTF-8 encoding.
 */
return [
    'Auth Key' => '',
    'Budget' => '',
    'Chasi' => '',
    'Create' => '',
    'Created At' => '',
    'Distsiplina' => '',
    'Distsiplinas' => '',
    'Dogovor' => '',
    'Ekzamen' => '',
    'Email' => '',
    'Fakultet' => '',
    'Fakultets' => '',
    'Fio' => '',
    'First Name' => '',
    'ID' => '',
    'It is recommended you use an upgraded browser to display the {type} control properly.' => '',
    'K Nedel' => '',
    'Kafedra' => '',
    'Kafedras' => '',
    'Konsultacii' => '',
    'Kontrolnii' => '',
    'Kurs' => '',
    'Kursovoi' => '',
    'Laboratornie' => '',
    'Last Name' => '',
    'Lekcii' => '',
    'Modul' => '',
    'N Semestra' => '',
    'Nagruzka Prepods' => '',
    'Nazvanie' => '',
    'Norma' => '',
    'Normas' => '',
    'Password Hash' => '',
    'Password Reset Token' => '',
    'Period' => '',
    'Periods' => '',
    'Podgrupchel' => '',
    'Prakticheskie' => '',
    'Prepodavatel' => '',
    'Prepodavatels' => '',
    'Raschet Nagruzkis' => '',
    'Specialnost' => '',
    'Specialnosts' => '',
    'Srs' => '',
    'Status' => '',
    'Stavka' => '',
    'Stavkas' => '',
    'Update' => '',
    'Updated At' => '',
    'Username' => '',
    'Users' => '',
    'Zachet' => '',
    'Zvanie' => '',
];