Revert "Removed HLSL cry compilers and tools"

This reverts commit f8a72e5a04.
This commit is contained in:
Aristo7
2021-04-20 12:53:46 -05:00
parent 8410452067
commit c07c57ca2a
155 changed files with 71159 additions and 0 deletions
@@ -0,0 +1,13 @@
// Modifications copyright Amazon.com, Inc. or its affiliates
// Modifications copyright Crytek GmbH
#ifndef AMAZON_CHANGES_H
#define AMAZON_CHANGES_H
// There is a bug on the Adreno 420 driver where reinterpret casts can destroy a variable. We need to replace all instances that look like this:
// floatBitsToInt(Temp2);
// We do not need to change cases that evaluate an expression within the cast operation, like so:
// floatBitsToInt(Temp2 + 1.0f);
void ModifyLineForQualcommReinterpretCastBug( HLSLCrossCompilerContext* psContext, bstring* originalString, bstring* overloadString );
#endif // AMAZON_CHANGES_H
@@ -0,0 +1,580 @@
// Modifications copyright Amazon.com, Inc. or its affiliates
// Modifications copyright Crytek GmbH
#ifndef HLSLCC_H_
#define HLSLCC_H_
#if defined (_WIN32) && defined(HLSLCC_DYNLIB)
#define HLSLCC_APIENTRY __stdcall
#if defined(libHLSLcc_EXPORTS)
#define HLSLCC_API __declspec(dllexport)
#else
#define HLSLCC_API __declspec(dllimport)
#endif
#else
#define HLSLCC_APIENTRY
#define HLSLCC_API
#endif
#include <stdint.h>
#include <stddef.h>
typedef enum
{
LANG_DEFAULT,// Depends on the HLSL shader model.
LANG_ES_100,
LANG_ES_300,
LANG_ES_310,
LANG_120,
LANG_130,
LANG_140,
LANG_150,
LANG_330,
LANG_400,
LANG_410,
LANG_420,
LANG_430,
LANG_440,
} GLLang;
typedef struct {
uint32_t ARB_explicit_attrib_location : 1;
uint32_t ARB_explicit_uniform_location : 1;
uint32_t ARB_shading_language_420pack : 1;
}GlExtensions;
enum {MAX_SHADER_VEC4_OUTPUT = 512};
enum {MAX_SHADER_VEC4_INPUT = 512};
enum {MAX_TEXTURES = 128};
enum {MAX_FORK_PHASES = 2};
enum {MAX_FUNCTION_BODIES = 1024};
enum {MAX_CLASS_TYPES = 1024};
enum {MAX_FUNCTION_POINTERS = 128};
//Reflection
#define MAX_REFLECT_STRING_LENGTH 512
#define MAX_SHADER_VARS 256
#define MAX_CBUFFERS 256
#define MAX_UAV 256
#define MAX_FUNCTION_TABLES 256
#define MAX_RESOURCE_BINDINGS 256
//Operands flags
#define TO_FLAG_NONE 0x0
#define TO_FLAG_INTEGER 0x1
#define TO_FLAG_NAME_ONLY 0x2
#define TO_FLAG_DECLARATION_NAME 0x4
#define TO_FLAG_DESTINATION 0x8 //Operand is being written to by assignment.
#define TO_FLAG_UNSIGNED_INTEGER 0x10
#define TO_FLAG_DOUBLE 0x20
#define TO_FLAG_FLOAT 0x40
#define TO_FLAG_COPY 0x80
typedef enum SPECIAL_NAME
{
NAME_UNDEFINED = 0,
NAME_POSITION = 1,
NAME_CLIP_DISTANCE = 2,
NAME_CULL_DISTANCE = 3,
NAME_RENDER_TARGET_ARRAY_INDEX = 4,
NAME_VIEWPORT_ARRAY_INDEX = 5,
NAME_VERTEX_ID = 6,
NAME_PRIMITIVE_ID = 7,
NAME_INSTANCE_ID = 8,
NAME_IS_FRONT_FACE = 9,
NAME_SAMPLE_INDEX = 10,
// The following are added for D3D11
NAME_FINAL_QUAD_U_EQ_0_EDGE_TESSFACTOR = 11,
NAME_FINAL_QUAD_V_EQ_0_EDGE_TESSFACTOR = 12,
NAME_FINAL_QUAD_U_EQ_1_EDGE_TESSFACTOR = 13,
NAME_FINAL_QUAD_V_EQ_1_EDGE_TESSFACTOR = 14,
NAME_FINAL_QUAD_U_INSIDE_TESSFACTOR = 15,
NAME_FINAL_QUAD_V_INSIDE_TESSFACTOR = 16,
NAME_FINAL_TRI_U_EQ_0_EDGE_TESSFACTOR = 17,
NAME_FINAL_TRI_V_EQ_0_EDGE_TESSFACTOR = 18,
NAME_FINAL_TRI_W_EQ_0_EDGE_TESSFACTOR = 19,
NAME_FINAL_TRI_INSIDE_TESSFACTOR = 20,
NAME_FINAL_LINE_DETAIL_TESSFACTOR = 21,
NAME_FINAL_LINE_DENSITY_TESSFACTOR = 22,
} SPECIAL_NAME;
typedef enum {
INOUT_COMPONENT_UNKNOWN = 0,
INOUT_COMPONENT_UINT32 = 1,
INOUT_COMPONENT_SINT32 = 2,
INOUT_COMPONENT_FLOAT32 = 3
} INOUT_COMPONENT_TYPE;
typedef enum MIN_PRECISION {
MIN_PRECISION_DEFAULT = 0,
MIN_PRECISION_FLOAT_16 = 1,
MIN_PRECISION_FLOAT_2_8 = 2,
MIN_PRECISION_RESERVED = 3,
MIN_PRECISION_SINT_16 = 4,
MIN_PRECISION_UINT_16 = 5,
MIN_PRECISION_ANY_16 = 0xf0,
MIN_PRECISION_ANY_10 = 0xf1
} MIN_PRECISION;
typedef struct InOutSignature_TAG
{
char SemanticName[MAX_REFLECT_STRING_LENGTH];
uint32_t ui32SemanticIndex;
SPECIAL_NAME eSystemValueType;
INOUT_COMPONENT_TYPE eComponentType;
uint32_t ui32Register;
uint32_t ui32Mask;
uint32_t ui32ReadWriteMask;
uint32_t ui32Stream;
MIN_PRECISION eMinPrec;
} InOutSignature;
typedef enum ResourceType_TAG
{
RTYPE_CBUFFER,//0
RTYPE_TBUFFER,//1
RTYPE_TEXTURE,//2
RTYPE_SAMPLER,//3
RTYPE_UAV_RWTYPED,//4
RTYPE_STRUCTURED,//5
RTYPE_UAV_RWSTRUCTURED,//6
RTYPE_BYTEADDRESS,//7
RTYPE_UAV_RWBYTEADDRESS,//8
RTYPE_UAV_APPEND_STRUCTURED,//9
RTYPE_UAV_CONSUME_STRUCTURED,//10
RTYPE_UAV_RWSTRUCTURED_WITH_COUNTER,//11
RTYPE_COUNT,
} ResourceType;
typedef enum ResourceGroup_TAG {
RGROUP_CBUFFER,
RGROUP_TEXTURE,
RGROUP_SAMPLER,
RGROUP_UAV,
RGROUP_COUNT,
} ResourceGroup;
typedef enum REFLECT_RESOURCE_DIMENSION
{
REFLECT_RESOURCE_DIMENSION_UNKNOWN = 0,
REFLECT_RESOURCE_DIMENSION_BUFFER = 1,
REFLECT_RESOURCE_DIMENSION_TEXTURE1D = 2,
REFLECT_RESOURCE_DIMENSION_TEXTURE1DARRAY = 3,
REFLECT_RESOURCE_DIMENSION_TEXTURE2D = 4,
REFLECT_RESOURCE_DIMENSION_TEXTURE2DARRAY = 5,
REFLECT_RESOURCE_DIMENSION_TEXTURE2DMS = 6,
REFLECT_RESOURCE_DIMENSION_TEXTURE2DMSARRAY = 7,
REFLECT_RESOURCE_DIMENSION_TEXTURE3D = 8,
REFLECT_RESOURCE_DIMENSION_TEXTURECUBE = 9,
REFLECT_RESOURCE_DIMENSION_TEXTURECUBEARRAY = 10,
REFLECT_RESOURCE_DIMENSION_BUFFEREX = 11,
} REFLECT_RESOURCE_DIMENSION;
typedef struct ResourceBinding_TAG
{
char Name[MAX_REFLECT_STRING_LENGTH];
ResourceType eType;
uint32_t ui32BindPoint;
uint32_t ui32BindCount;
uint32_t ui32Flags;
REFLECT_RESOURCE_DIMENSION eDimension;
uint32_t ui32ReturnType;
uint32_t ui32NumSamples;
} ResourceBinding;
// Do not change the value of these enums or they will not match what we find in the DXBC file
typedef enum _SHADER_VARIABLE_TYPE {
SVT_VOID = 0,
SVT_BOOL = 1,
SVT_INT = 2,
SVT_FLOAT = 3,
SVT_STRING = 4,
SVT_TEXTURE = 5,
SVT_TEXTURE1D = 6,
SVT_TEXTURE2D = 7,
SVT_TEXTURE3D = 8,
SVT_TEXTURECUBE = 9,
SVT_SAMPLER = 10,
SVT_PIXELSHADER = 15,
SVT_VERTEXSHADER = 16,
SVT_UINT = 19,
SVT_UINT8 = 20,
SVT_GEOMETRYSHADER = 21,
SVT_RASTERIZER = 22,
SVT_DEPTHSTENCIL = 23,
SVT_BLEND = 24,
SVT_BUFFER = 25,
SVT_CBUFFER = 26,
SVT_TBUFFER = 27,
SVT_TEXTURE1DARRAY = 28,
SVT_TEXTURE2DARRAY = 29,
SVT_RENDERTARGETVIEW = 30,
SVT_DEPTHSTENCILVIEW = 31,
SVT_TEXTURE2DMS = 32,
SVT_TEXTURE2DMSARRAY = 33,
SVT_TEXTURECUBEARRAY = 34,
SVT_HULLSHADER = 35,
SVT_DOMAINSHADER = 36,
SVT_INTERFACE_POINTER = 37,
SVT_COMPUTESHADER = 38,
SVT_DOUBLE = 39,
SVT_RWTEXTURE1D = 40,
SVT_RWTEXTURE1DARRAY = 41,
SVT_RWTEXTURE2D = 42,
SVT_RWTEXTURE2DARRAY = 43,
SVT_RWTEXTURE3D = 44,
SVT_RWBUFFER = 45,
SVT_BYTEADDRESS_BUFFER = 46,
SVT_RWBYTEADDRESS_BUFFER = 47,
SVT_STRUCTURED_BUFFER = 48,
SVT_RWSTRUCTURED_BUFFER = 49,
SVT_APPEND_STRUCTURED_BUFFER = 50,
SVT_CONSUME_STRUCTURED_BUFFER = 51,
// Partial precision types
SVT_FLOAT10 = 53,
SVT_FLOAT16 = 54,
SVT_INT16 = 156,
SVT_INT12 = 157,
SVT_UINT16 = 158,
SVT_FORCE_DWORD = 0x7fffffff
} SHADER_VARIABLE_TYPE;
typedef enum _SHADER_VARIABLE_CLASS {
SVC_SCALAR = 0,
SVC_VECTOR = ( SVC_SCALAR + 1 ),
SVC_MATRIX_ROWS = ( SVC_VECTOR + 1 ),
SVC_MATRIX_COLUMNS = ( SVC_MATRIX_ROWS + 1 ),
SVC_OBJECT = ( SVC_MATRIX_COLUMNS + 1 ),
SVC_STRUCT = ( SVC_OBJECT + 1 ),
SVC_INTERFACE_CLASS = ( SVC_STRUCT + 1 ),
SVC_INTERFACE_POINTER = ( SVC_INTERFACE_CLASS + 1 ),
SVC_FORCE_DWORD = 0x7fffffff
} SHADER_VARIABLE_CLASS;
typedef struct ShaderVarType_TAG {
SHADER_VARIABLE_CLASS Class;
SHADER_VARIABLE_TYPE Type;
uint32_t Rows;
uint32_t Columns;
uint32_t Elements;
uint32_t MemberCount;
uint32_t Offset;
char Name[MAX_REFLECT_STRING_LENGTH];
uint32_t ParentCount;
struct ShaderVarType_TAG * Parent;
struct ShaderVarType_TAG * Members;
} ShaderVarType;
typedef struct ShaderVar_TAG
{
char Name[MAX_REFLECT_STRING_LENGTH];
int haveDefaultValue;
uint32_t* pui32DefaultValues;
//Offset/Size in bytes.
uint32_t ui32StartOffset;
uint32_t ui32Size;
uint32_t ui32Flags;
ShaderVarType sType;
} ShaderVar;
typedef struct ConstantBuffer_TAG
{
char Name[MAX_REFLECT_STRING_LENGTH];
uint32_t ui32NumVars;
ShaderVar asVars[MAX_SHADER_VARS];
uint32_t ui32TotalSizeInBytes;
int blob;
} ConstantBuffer;
typedef struct ClassType_TAG
{
char Name[MAX_REFLECT_STRING_LENGTH];
uint16_t ui16ID;
uint16_t ui16ConstBufStride;
uint16_t ui16Texture;
uint16_t ui16Sampler;
} ClassType;
typedef struct ClassInstance_TAG
{
char Name[MAX_REFLECT_STRING_LENGTH];
uint16_t ui16ID;
uint16_t ui16ConstBuf;
uint16_t ui16ConstBufOffset;
uint16_t ui16Texture;
uint16_t ui16Sampler;
} ClassInstance;
typedef enum TESSELLATOR_PARTITIONING
{
TESSELLATOR_PARTITIONING_UNDEFINED = 0,
TESSELLATOR_PARTITIONING_INTEGER = 1,
TESSELLATOR_PARTITIONING_POW2 = 2,
TESSELLATOR_PARTITIONING_FRACTIONAL_ODD = 3,
TESSELLATOR_PARTITIONING_FRACTIONAL_EVEN = 4
} TESSELLATOR_PARTITIONING;
typedef enum TESSELLATOR_OUTPUT_PRIMITIVE
{
TESSELLATOR_OUTPUT_UNDEFINED = 0,
TESSELLATOR_OUTPUT_POINT = 1,
TESSELLATOR_OUTPUT_LINE = 2,
TESSELLATOR_OUTPUT_TRIANGLE_CW = 3,
TESSELLATOR_OUTPUT_TRIANGLE_CCW = 4
} TESSELLATOR_OUTPUT_PRIMITIVE;
typedef enum INTERPOLATION_MODE
{
INTERPOLATION_UNDEFINED = 0,
INTERPOLATION_CONSTANT = 1,
INTERPOLATION_LINEAR = 2,
INTERPOLATION_LINEAR_CENTROID = 3,
INTERPOLATION_LINEAR_NOPERSPECTIVE = 4,
INTERPOLATION_LINEAR_NOPERSPECTIVE_CENTROID = 5,
INTERPOLATION_LINEAR_SAMPLE = 6,
INTERPOLATION_LINEAR_NOPERSPECTIVE_SAMPLE = 7,
} INTERPOLATION_MODE;
typedef enum TRACE_VARIABLE_GROUP
{
TRACE_VARIABLE_INPUT = 0,
TRACE_VARIABLE_TEMP = 1,
TRACE_VARIABLE_OUTPUT = 2
} TRACE_VARIABLE_GROUP;
typedef enum TRACE_VARIABLE_TYPE
{
TRACE_VARIABLE_FLOAT = 0,
TRACE_VARIABLE_SINT = 1,
TRACE_VARIABLE_UINT = 2,
TRACE_VARIABLE_DOUBLE = 3,
TRACE_VARIABLE_UNKNOWN = 4
} TRACE_VARIABLE_TYPE;
typedef struct VariableTraceInfo_TAG
{
TRACE_VARIABLE_GROUP eGroup;
TRACE_VARIABLE_TYPE eType;
uint8_t ui8Index;
uint8_t ui8Component;
} VariableTraceInfo;
typedef struct StepTraceInfo_TAG
{
uint32_t ui32NumVariables;
VariableTraceInfo* psVariables;
} StepTraceInfo;
typedef enum SYMBOL_TYPE
{
SYMBOL_TESSELLATOR_PARTITIONING = 0,
SYMBOL_TESSELLATOR_OUTPUT_PRIMITIVE = 1,
SYMBOL_INPUT_INTERPOLATION_MODE = 2,
SYMBOL_EMULATE_DEPTH_CLAMP = 3
} SYMBOL_TYPE;
typedef struct Symbol_TAG
{
SYMBOL_TYPE eType;
uint32_t ui32ID;
uint32_t ui32Value;
} Symbol;
typedef struct EmbeddedResourceName_TAG
{
uint32_t ui20Offset : 20;
uint32_t ui12Size : 12;
} EmbeddedResourceName;
typedef struct SamplerMask_TAG
{
uint32_t ui10TextureBindPoint : 10;
uint32_t ui10SamplerBindPoint : 10;
uint32_t ui10TextureUnit : 10;
uint32_t bNormalSample : 1;
uint32_t bCompareSample : 1;
} SamplerMask;
typedef struct Sampler_TAG
{
SamplerMask sMask;
EmbeddedResourceName sNormalName;
EmbeddedResourceName sCompareName;
} Sampler;
typedef struct Resource_TAG
{
uint32_t ui32BindPoint;
ResourceGroup eGroup;
EmbeddedResourceName sName;
} Resource;
typedef struct ShaderInfo_TAG
{
uint32_t ui32MajorVersion;
uint32_t ui32MinorVersion;
uint32_t ui32NumInputSignatures;
InOutSignature* psInputSignatures;
uint32_t ui32NumOutputSignatures;
InOutSignature* psOutputSignatures;
uint32_t ui32NumResourceBindings;
ResourceBinding* psResourceBindings;
uint32_t ui32NumConstantBuffers;
ConstantBuffer* psConstantBuffers;
ConstantBuffer* psThisPointerConstBuffer;
uint32_t ui32NumClassTypes;
ClassType* psClassTypes;
uint32_t ui32NumClassInstances;
ClassInstance* psClassInstances;
//Func table ID to class name ID.
uint32_t aui32TableIDToTypeID[MAX_FUNCTION_TABLES];
uint32_t aui32ResourceMap[RGROUP_COUNT][MAX_RESOURCE_BINDINGS];
// GLSL resources
Sampler asSamplers[MAX_RESOURCE_BINDINGS];
Resource asImages[MAX_RESOURCE_BINDINGS];
Resource asUniformBuffers[MAX_RESOURCE_BINDINGS];
Resource asStorageBuffers[MAX_RESOURCE_BINDINGS];
uint32_t ui32NumSamplers;
uint32_t ui32NumImages;
uint32_t ui32NumUniformBuffers;
uint32_t ui32NumStorageBuffers;
// Trace info if tracing is enabled
uint32_t ui32NumTraceSteps;
StepTraceInfo* psTraceSteps;
// Symbols imported
uint32_t ui32NumImports;
Symbol* psImports;
// Symbols exported
uint32_t ui32NumExports;
Symbol* psExports;
// Hash of the input shader for debugging purposes
uint32_t ui32InputHash;
// Offset in the GLSL string where symbol definitions can be inserted
uint32_t ui32SymbolsOffset;
TESSELLATOR_PARTITIONING eTessPartitioning;
TESSELLATOR_OUTPUT_PRIMITIVE eTessOutPrim;
//Required if PixelInterpDependency is true
INTERPOLATION_MODE aePixelInputInterpolation[MAX_SHADER_VEC4_INPUT];
} ShaderInfo;
typedef struct
{
int shaderType; //One of the GL enums.
char* sourceCode;
ShaderInfo reflection;
GLLang GLSLLanguage;
} GLSLShader;
typedef enum _FRAMEBUFFER_FETCH_TYPE
{
FBF_NONE = 0,
FBF_EXT_COLOR = 1 << 0,
FBF_ARM_COLOR = 1 << 1,
FBF_ARM_DEPTH = 1 << 2,
FBF_ARM_STENCIL = 1 << 3,
FBF_ANY = FBF_EXT_COLOR | FBF_ARM_COLOR | FBF_ARM_DEPTH | FBF_ARM_STENCIL
} FRAMEBUFFER_FETCH_TYPE;
// NOTE: HLSLCC flags are specified by command line when executing this cross compiler.
// If these flags change, the command line switch '-flags=XXX' must change as well.
// Open 3D Engine composes the command line in file 'dev\Code\CryEngine\RenderDll\Common\Shaders\RemoteCompiler.cpp'
/*HLSL constant buffers are treated as default-block unform arrays by default. This is done
to support versions of GLSL which lack ARB_uniform_buffer_object functionality.
Setting this flag causes each one to have its own uniform block.
Note: Currently the nth const buffer will be named UnformBufferN. This is likey to change to the original HLSL name in the future.*/
static const unsigned int HLSLCC_FLAG_UNIFORM_BUFFER_OBJECT = 0x1;
static const unsigned int HLSLCC_FLAG_ORIGIN_UPPER_LEFT = 0x2;
static const unsigned int HLSLCC_FLAG_PIXEL_CENTER_INTEGER = 0x4;
static const unsigned int HLSLCC_FLAG_GLOBAL_CONSTS_NEVER_IN_UBO = 0x8;
//GS enabled?
//Affects vertex shader (i.e. need to compile vertex shader again to use with/without GS).
//This flag is needed in order for the interfaces between stages to match when GS is in use.
//PS inputs VtxGeoOutput
//GS outputs VtxGeoOutput
//Vs outputs VtxOutput if GS enabled. VtxGeoOutput otherwise.
static const unsigned int HLSLCC_FLAG_GS_ENABLED = 0x10;
static const unsigned int HLSLCC_FLAG_TESS_ENABLED = 0x20;
//Either use this flag or glBindFragDataLocationIndexed.
//When set the first pixel shader output is the first input to blend
//equation, the others go to the second input.
static const unsigned int HLSLCC_FLAG_DUAL_SOURCE_BLENDING = 0x40;
//If set, shader inputs and outputs are declared with their semantic name.
static const unsigned int HLSLCC_FLAG_INOUT_SEMANTIC_NAMES = 0x80;
static const unsigned int HLSLCC_FLAG_INVERT_CLIP_SPACE_Y = 0x100;
static const unsigned int HLSLCC_FLAG_CONVERT_CLIP_SPACE_Z = 0x200;
static const unsigned int HLSLCC_FLAG_AVOID_RESOURCE_BINDINGS_AND_LOCATIONS = 0x400;
static const unsigned int HLSLCC_FLAG_AVOID_TEMP_REGISTER_ALIASING = 0x800;
static const unsigned int HLSLCC_FLAG_TRACING_INSTRUMENTATION = 0x1000;
static const unsigned int HLSLCC_FLAG_HASH_INPUT = 0x2000;
static const unsigned int HLSLCC_FLAG_ADD_DEBUG_HEADER = 0x4000;
static const unsigned int HLSLCC_FLAG_NO_VERSION_STRING = 0x8000;
static const unsigned int HLSLCC_FLAG_AVOID_SHADER_LOAD_STORE_EXTENSION = 0x10000;
// If set, HLSLcc will generate GLSL code which contains syntactic workarounds for
// driver bugs found in Qualcomm devices running OpenGL ES 3.0
static const unsigned int HLSLCC_FLAG_QUALCOMM_GLES30_DRIVER_WORKAROUND = 0x20000;
// If set, HLSL DX9 lower precision qualifiers (e.g half) will be transformed to DX11 style (e.g min16float)
// before compiling. Necessary to preserve precision information. If not, FXC just silently transform
// everything to full precision (e.g float32).
static const unsigned int HLSLCC_FLAG_HALF_FLOAT_TRANSFORM = 0x40000;
#ifdef __cplusplus
extern "C" {
#endif
HLSLCC_API void HLSLCC_APIENTRY HLSLcc_SetMemoryFunctions(void* (*malloc_override)(size_t),
void* (*calloc_override)(size_t,size_t),
void (*free_override)(void *),
void* (*realloc_override)(void*,size_t));
HLSLCC_API int HLSLCC_APIENTRY TranslateHLSLFromFile(const char* filename, unsigned int flags, GLLang language, const GlExtensions *extensions, GLSLShader* result);
HLSLCC_API int HLSLCC_APIENTRY TranslateHLSLFromMem(const char* shader, size_t size, unsigned int flags, GLLang language, const GlExtensions *extensions, GLSLShader* result);
HLSLCC_API const char* HLSLCC_APIENTRY GetVersionString(GLLang language);
HLSLCC_API void HLSLCC_APIENTRY FreeGLSLShader(GLSLShader*);
#ifdef __cplusplus
}
#endif
#endif
@@ -0,0 +1,7 @@
// Modifications copyright Amazon.com, Inc. or its affiliates
// Modifications copyright Crytek GmbH
extern "C" {
#include "hlslcc.h"
}
@@ -0,0 +1,419 @@
// Modifications copyright Amazon.com, Inc. or its affiliates
// Modifications copyright Crytek GmbH
#include <algorithm>
#define FOURCC(a, b, c, d) ((uint32_t)(uint8_t)(a) | ((uint32_t)(uint8_t)(b) << 8) | ((uint32_t)(uint8_t)(c) << 16) | ((uint32_t)(uint8_t)(d) << 24 ))
enum
{
DXBC_BASE_ALIGNMENT = 4,
FOURCC_DXBC = FOURCC('D', 'X', 'B', 'C'),
FOURCC_RDEF = FOURCC('R', 'D', 'E', 'F'),
FOURCC_ISGN = FOURCC('I', 'S', 'G', 'N'),
FOURCC_OSGN = FOURCC('O', 'S', 'G', 'N'),
FOURCC_PCSG = FOURCC('P', 'C', 'S', 'G'),
FOURCC_SHDR = FOURCC('S', 'H', 'D', 'R'),
FOURCC_SHEX = FOURCC('S', 'H', 'E', 'X'),
FOURCC_GLSL = FOURCC('G', 'L', 'S', 'L'),
FOURCC_ISG1 = FOURCC('I', 'S', 'G', '1'), // When lower precision float/int/uint is used
FOURCC_OSG1 = FOURCC('O', 'S', 'G', '1'), // When lower precision float/int/uint is used
};
#undef FOURCC
template <typename T>
inline T DXBCSwapBytes(const T& kValue)
{
return kValue;
}
#if defined(__BIG_ENDIAN__) || SYSTEM_IS_BIG_ENDIAN
inline uint16_t DXBCSwapBytes(const uint16_t& uValue)
{
return
(((uValue) >> 8) & 0xFF) |
(((uValue) << 8) & 0xFF);
}
inline uint32_t DXBCSwapBytes(const uint32_t& uValue)
{
return
(((uValue) >> 24) & 0x000000FF) |
(((uValue) >> 8) & 0x0000FF00) |
(((uValue) << 8) & 0x00FF0000) |
(((uValue) << 24) & 0xFF000000);
}
#endif //defined(__BIG_ENDIAN__) || SYSTEM_IS_BIG_ENDIAN
template <typename Element>
struct SDXBCBufferBase
{
Element* m_pBegin;
Element* m_pEnd;
Element* m_pIter;
SDXBCBufferBase(Element* pBegin, Element* pEnd)
: m_pBegin(pBegin)
, m_pEnd(pEnd)
, m_pIter(pBegin)
{
}
bool SeekRel(int32_t iOffset)
{
Element* pIterAfter(m_pIter + iOffset);
if (pIterAfter > m_pEnd)
return false;
m_pIter = pIterAfter;
return true;
}
bool SeekAbs(uint32_t uPosition)
{
Element* pIterAfter(m_pBegin + uPosition);
if (pIterAfter > m_pEnd)
return false;
m_pIter = pIterAfter;
return true;
}
};
struct SDXBCInputBuffer : SDXBCBufferBase<const uint8_t>
{
SDXBCInputBuffer(const uint8_t* pBegin, const uint8_t* pEnd)
: SDXBCBufferBase(pBegin, pEnd)
{
}
bool Read(void* pElements, size_t uSize)
{
const uint8_t* pIterAfter(m_pIter + uSize);
if (pIterAfter > m_pEnd)
return false;
memcpy(pElements, m_pIter, uSize);
m_pIter = pIterAfter;
return true;
}
};
struct SDXBCOutputBuffer : SDXBCBufferBase<uint8_t>
{
SDXBCOutputBuffer(uint8_t* pBegin, uint8_t* pEnd)
: SDXBCBufferBase(pBegin, pEnd)
{
}
bool Write(const void* pElements, size_t uSize)
{
uint8_t* pIterAfter(m_pIter + uSize);
if (pIterAfter > m_pEnd)
return false;
memcpy(m_pIter, pElements, uSize);
m_pIter = pIterAfter;
return true;
}
};
template <typename S, typename External, typename Internal>
inline bool DXBCReadAs(S& kStream, External& kValue)
{
Internal kInternal;
bool bResult(kStream.Read(&kInternal, sizeof(Internal)));
kValue = static_cast<External>(DXBCSwapBytes(kInternal));
return bResult;
}
template <typename S, typename Internal>
inline bool DXBCWriteAs(S& kStream, Internal kValue)
{
Internal kInternal(DXBCSwapBytes(kValue));
return kStream.Write(&kInternal, sizeof(Internal));
}
template <typename S, typename T> bool DXBCReadUint8 (S& kStream, T& kValue) { return DXBCReadAs<S, T, uint8_t >(kStream, kValue); }
template <typename S, typename T> bool DXBCReadUint16(S& kStream, T& kValue) { return DXBCReadAs<S, T, uint16_t>(kStream, kValue); }
template <typename S, typename T> bool DXBCReadUint32(S& kStream, T& kValue) { return DXBCReadAs<S, T, uint32_t>(kStream, kValue); }
template <typename S> bool DXBCWriteUint8 (S& kStream, uint8_t kValue) { return DXBCWriteAs<S, uint8_t >(kStream, kValue); }
template <typename S> bool DXBCWriteUint16(S& kStream, uint16_t kValue) { return DXBCWriteAs<S, uint16_t>(kStream, kValue); }
template <typename S> bool DXBCWriteUint32(S& kStream, uint32_t kValue) { return DXBCWriteAs<S, uint32_t>(kStream, kValue); }
template <typename O, typename I>
bool DXBCCopy(O& kOutput, I& kInput, size_t uSize)
{
char acBuffer[1024];
while (uSize > 0)
{
size_t uToCopy(std::min<size_t>(uSize, sizeof(acBuffer)));
if (!kInput.Read(acBuffer, uToCopy) ||
!kOutput.Write(acBuffer, uToCopy))
return false;
uSize -= uToCopy;
}
return true;
}
enum
{
DXBC_SIZE_POSITION = 6 * 4,
DXBC_HEADER_SIZE = 7 * 4,
DXBC_CHUNK_HEADER_SIZE = 2 * 4,
DXBC_MAX_NUM_CHUNKS_IN = 128,
DXBC_MAX_NUM_CHUNKS_OUT = 8,
DXBC_OUT_CHUNKS_INDEX_SIZE = (1 + 1 + DXBC_MAX_NUM_CHUNKS_OUT) * 4,
DXBC_OUT_FIXED_SIZE = DXBC_HEADER_SIZE + DXBC_OUT_CHUNKS_INDEX_SIZE,
};
enum
{
GLSL_HEADER_SIZE = 4 * 8, // uNumSamplers, uNumImages, uNumStorageBuffers, uNumUniformBuffers, uNumImports, uNumExports, uInputHash, uSymbolsOffset
GLSL_SAMPLER_SIZE = 4 * 3, // uSamplerField, uEmbeddedNormalName, uEmbeddedCompareName
GLSL_RESOURCE_SIZE = 4 * 2, // uBindPoint, uName
GLSL_SYMBOL_SIZE = 4 * 3, // uType, uID, uValue
};
inline void DXBCSizeGLSLChunk(uint32_t& uGLSLChunkSize, uint32_t& uGLSLSourceSize, const GLSLShader* pShader)
{
uint32_t uNumSymbols(
pShader->reflection.ui32NumImports +
pShader->reflection.ui32NumExports);
uint32_t uGLSLInfoSize(
DXBC_CHUNK_HEADER_SIZE +
GLSL_HEADER_SIZE +
pShader->reflection.ui32NumSamplers * GLSL_SAMPLER_SIZE +
pShader->reflection.ui32NumImages * GLSL_RESOURCE_SIZE +
pShader->reflection.ui32NumStorageBuffers * GLSL_RESOURCE_SIZE +
pShader->reflection.ui32NumUniformBuffers * GLSL_RESOURCE_SIZE +
uNumSymbols * GLSL_SYMBOL_SIZE);
uGLSLSourceSize = (uint32_t)strlen(pShader->sourceCode) + 1;
uGLSLChunkSize = uGLSLInfoSize + uGLSLSourceSize;
uGLSLChunkSize += DXBC_BASE_ALIGNMENT - 1 - (uGLSLChunkSize - 1) % DXBC_BASE_ALIGNMENT;
}
inline uint32_t DXBCSizeOutputChunk(uint32_t uCode, uint32_t uSizeIn)
{
uint32_t uSizeOut;
switch (uCode)
{
case FOURCC_RDEF:
case FOURCC_ISGN:
case FOURCC_OSGN:
case FOURCC_PCSG:
case FOURCC_OSG1:
case FOURCC_ISG1:
// Preserve entire chunk
uSizeOut = uSizeIn;
break;
case FOURCC_SHDR:
case FOURCC_SHEX:
// Only keep the shader version
uSizeOut = uSizeIn < 4u ? uSizeIn : 4u;
break;
default:
// Discard the chunk
uSizeOut = 0;
break;
}
return uSizeOut + DXBC_BASE_ALIGNMENT - 1 - (uSizeOut - 1) % DXBC_BASE_ALIGNMENT;
}
template <typename I>
size_t DXBCGetCombinedSize(I& kDXBCInput, const GLSLShader* pShader)
{
uint32_t uNumChunksIn;
if (!kDXBCInput.SeekAbs(DXBC_HEADER_SIZE) ||
!DXBCReadUint32(kDXBCInput, uNumChunksIn))
return 0;
uint32_t auChunkOffsetsIn[DXBC_MAX_NUM_CHUNKS_IN];
for (uint32_t uChunk = 0; uChunk < uNumChunksIn; ++uChunk)
{
if (!DXBCReadUint32(kDXBCInput, auChunkOffsetsIn[uChunk]))
return 0;
}
uint32_t uNumChunksOut(0);
uint32_t uOutSize(DXBC_OUT_FIXED_SIZE);
for (uint32_t uChunk = 0; uChunk < uNumChunksIn && uNumChunksOut < DXBC_MAX_NUM_CHUNKS_OUT; ++uChunk)
{
uint32_t uChunkCode, uChunkSizeIn;
if (!kDXBCInput.SeekAbs(auChunkOffsetsIn[uChunk]) ||
!DXBCReadUint32(kDXBCInput, uChunkCode) ||
!DXBCReadUint32(kDXBCInput, uChunkSizeIn))
return 0;
uint32_t uChunkSizeOut(DXBCSizeOutputChunk(uChunkCode, uChunkSizeIn));
if (uChunkSizeOut > 0)
{
uOutSize += DXBC_CHUNK_HEADER_SIZE + uChunkSizeOut;
}
}
uint32_t uGLSLSourceSize, uGLSLChunkSize;
DXBCSizeGLSLChunk(uGLSLChunkSize, uGLSLSourceSize, pShader);
uOutSize += uGLSLChunkSize;
return uOutSize;
}
template <typename I, typename O>
bool DXBCCombineWithGLSL(I& kInput, O& kOutput, const GLSLShader* pShader)
{
uint32_t uNumChunksIn;
if (!DXBCCopy(kOutput, kInput, DXBC_HEADER_SIZE) ||
!DXBCReadUint32(kInput, uNumChunksIn) ||
uNumChunksIn > DXBC_MAX_NUM_CHUNKS_IN)
return false;
uint32_t auChunkOffsetsIn[DXBC_MAX_NUM_CHUNKS_IN];
for (uint32_t uChunk = 0; uChunk < uNumChunksIn; ++uChunk)
{
if (!DXBCReadUint32(kInput, auChunkOffsetsIn[uChunk]))
return false;
}
uint32_t auZeroChunkIndex[DXBC_OUT_CHUNKS_INDEX_SIZE] = {0};
if (!kOutput.Write(auZeroChunkIndex, DXBC_OUT_CHUNKS_INDEX_SIZE))
return false;
// Copy required input chunks just after the chunk index
uint32_t uOutSize(DXBC_OUT_FIXED_SIZE);
uint32_t uNumChunksOut(0);
uint32_t auChunkOffsetsOut[DXBC_MAX_NUM_CHUNKS_OUT];
for (uint32_t uChunk = 0; uChunk < uNumChunksIn; ++uChunk)
{
uint32_t uChunkCode, uChunkSizeIn;
if (!kInput.SeekAbs(auChunkOffsetsIn[uChunk]) ||
!DXBCReadUint32(kInput, uChunkCode) ||
!DXBCReadUint32(kInput, uChunkSizeIn))
return false;
// Filter only input chunks of the specified types
uint32_t uChunkSizeOut(DXBCSizeOutputChunk(uChunkCode, uChunkSizeIn));
if (uChunkSizeOut > 0)
{
if (uNumChunksOut >= DXBC_MAX_NUM_CHUNKS_OUT)
return false;
if (!DXBCWriteUint32(kOutput, uChunkCode) ||
!DXBCWriteUint32(kOutput, uChunkSizeOut) ||
!DXBCCopy(kOutput, kInput, uChunkSizeOut))
return false;
auChunkOffsetsOut[uNumChunksOut] = uOutSize;
++uNumChunksOut;
uOutSize += DXBC_CHUNK_HEADER_SIZE + uChunkSizeOut;
}
}
// Write GLSL chunk
uint32_t uGLSLChunkOffset(uOutSize);
uint32_t uGLSLChunkSize, uGLSLSourceSize;
DXBCSizeGLSLChunk(uGLSLChunkSize, uGLSLSourceSize, pShader);
if (!DXBCWriteUint32(kOutput, (uint32_t)FOURCC_GLSL) ||
!DXBCWriteUint32(kOutput, uGLSLChunkSize) ||
!DXBCWriteUint32(kOutput, pShader->reflection.ui32NumSamplers) ||
!DXBCWriteUint32(kOutput, pShader->reflection.ui32NumImages) ||
!DXBCWriteUint32(kOutput, pShader->reflection.ui32NumStorageBuffers) ||
!DXBCWriteUint32(kOutput, pShader->reflection.ui32NumUniformBuffers) ||
!DXBCWriteUint32(kOutput, pShader->reflection.ui32NumImports) ||
!DXBCWriteUint32(kOutput, pShader->reflection.ui32NumExports) ||
!DXBCWriteUint32(kOutput, pShader->reflection.ui32InputHash) ||
!DXBCWriteUint32(kOutput, pShader->reflection.ui32SymbolsOffset))
return false;
for (uint32_t uSampler = 0; uSampler < pShader->reflection.ui32NumSamplers; ++uSampler)
{
uint32_t uSamplerField =
(pShader->reflection.asSamplers[uSampler].sMask.ui10TextureBindPoint << 22) |
(pShader->reflection.asSamplers[uSampler].sMask.ui10SamplerBindPoint << 12) |
(pShader->reflection.asSamplers[uSampler].sMask.ui10TextureUnit << 2) |
(pShader->reflection.asSamplers[uSampler].sMask.bNormalSample << 1) |
(pShader->reflection.asSamplers[uSampler].sMask.bCompareSample << 0);
if (!DXBCWriteUint32(kOutput, uSamplerField))
return false;
uint32_t uEmbeddedNormalName =
(pShader->reflection.asSamplers[uSampler].sNormalName.ui20Offset << 12) |
(pShader->reflection.asSamplers[uSampler].sNormalName.ui12Size << 0);
if (!DXBCWriteUint32(kOutput, uEmbeddedNormalName))
return false;
uint32_t uEmbeddedCompareName =
(pShader->reflection.asSamplers[uSampler].sCompareName.ui20Offset << 12) |
(pShader->reflection.asSamplers[uSampler].sCompareName.ui12Size << 0);
if (!DXBCWriteUint32(kOutput, uEmbeddedCompareName))
return false;
}
for (uint32_t uImage = 0; uImage < pShader->reflection.ui32NumImages; ++uImage)
{
const Resource* psResource = pShader->reflection.asImages + uImage;
uint32_t uEmbeddedName =
(psResource->sName.ui20Offset << 12) |
(psResource->sName.ui12Size << 0);
if (!DXBCWriteUint32(kOutput, psResource->ui32BindPoint) ||
!DXBCWriteUint32(kOutput, uEmbeddedName))
return false;
}
for (uint32_t uStorageBuffer = 0; uStorageBuffer < pShader->reflection.ui32NumStorageBuffers; ++uStorageBuffer)
{
const Resource* psResource = pShader->reflection.asStorageBuffers + uStorageBuffer;
uint32_t uEmbeddedName =
(psResource->sName.ui20Offset << 12) |
(psResource->sName.ui12Size << 0);
if (!DXBCWriteUint32(kOutput, psResource->ui32BindPoint) ||
!DXBCWriteUint32(kOutput, uEmbeddedName))
return false;
}
for (uint32_t uUniformBuffer = 0; uUniformBuffer < pShader->reflection.ui32NumUniformBuffers; ++uUniformBuffer)
{
const Resource* psResource = pShader->reflection.asUniformBuffers + uUniformBuffer;
uint32_t uEmbeddedName =
(psResource->sName.ui20Offset << 12) |
(psResource->sName.ui12Size << 0);
if (!DXBCWriteUint32(kOutput, psResource->ui32BindPoint) ||
!DXBCWriteUint32(kOutput, uEmbeddedName))
return false;
}
for (uint32_t uSymbol = 0; uSymbol < pShader->reflection.ui32NumImports; ++uSymbol)
{
if (!DXBCWriteUint32(kOutput, pShader->reflection.psImports[uSymbol].eType) ||
!DXBCWriteUint32(kOutput, pShader->reflection.psImports[uSymbol].ui32ID) ||
!DXBCWriteUint32(kOutput, pShader->reflection.psImports[uSymbol].ui32Value))
return false;
}
for (uint32_t uSymbol = 0; uSymbol < pShader->reflection.ui32NumExports; ++uSymbol)
{
if (!DXBCWriteUint32(kOutput, pShader->reflection.psExports[uSymbol].eType) ||
!DXBCWriteUint32(kOutput, pShader->reflection.psExports[uSymbol].ui32ID) ||
!DXBCWriteUint32(kOutput, pShader->reflection.psExports[uSymbol].ui32Value))
return false;
}
if (!kOutput.Write(pShader->sourceCode, uGLSLSourceSize))
return false;
uOutSize += uGLSLChunkSize;
// Write total size and chunk index
if (!kOutput.SeekAbs(DXBC_SIZE_POSITION) ||
!DXBCWriteUint32(kOutput, uOutSize) ||
!kOutput.SeekAbs(DXBC_HEADER_SIZE) ||
!DXBCWriteUint32(kOutput, uNumChunksOut + 1))
return false;
for (uint32_t uChunk = 0; uChunk < uNumChunksOut; ++uChunk)
{
if (!DXBCWriteUint32(kOutput, auChunkOffsetsOut[uChunk]))
return false;
}
DXBCWriteUint32(kOutput, uGLSLChunkOffset);
return true;
}
@@ -0,0 +1,801 @@
/* A portable stdint.h
****************************************************************************
* BSD License:
****************************************************************************
*
* Copyright (c) 2005-2011 Paul Hsieh
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************
*
* Version 0.1.12
*
* The ANSI C standard committee, for the C99 standard, specified the
* inclusion of a new standard include file called stdint.h. This is
* a very useful and long desired include file which contains several
* very precise definitions for integer scalar types that is
* critically important for making portable several classes of
* applications including cryptography, hashing, variable length
* integer libraries and so on. But for most developers its likely
* useful just for programming sanity.
*
* The problem is that most compiler vendors have decided not to
* implement the C99 standard, and the next C++ language standard
* (which has a lot more mindshare these days) will be a long time in
* coming and its unknown whether or not it will include stdint.h or
* how much adoption it will have. Either way, it will be a long time
* before all compilers come with a stdint.h and it also does nothing
* for the extremely large number of compilers available today which
* do not include this file, or anything comparable to it.
*
* So that's what this file is all about. Its an attempt to build a
* single universal include file that works on as many platforms as
* possible to deliver what stdint.h is supposed to. A few things
* that should be noted about this file:
*
* 1) It is not guaranteed to be portable and/or present an identical
* interface on all platforms. The extreme variability of the
* ANSI C standard makes this an impossibility right from the
* very get go. Its really only meant to be useful for the vast
* majority of platforms that possess the capability of
* implementing usefully and precisely defined, standard sized
* integer scalars. Systems which are not intrinsically 2s
* complement may produce invalid constants.
*
* 2) There is an unavoidable use of non-reserved symbols.
*
* 3) Other standard include files are invoked.
*
* 4) This file may come in conflict with future platforms that do
* include stdint.h. The hope is that one or the other can be
* used with no real difference.
*
* 5) In the current verison, if your platform can't represent
* int32_t, int16_t and int8_t, it just dumps out with a compiler
* error.
*
* 6) 64 bit integers may or may not be defined. Test for their
* presence with the test: #ifdef INT64_MAX or #ifdef UINT64_MAX.
* Note that this is different from the C99 specification which
* requires the existence of 64 bit support in the compiler. If
* this is not defined for your platform, yet it is capable of
* dealing with 64 bits then it is because this file has not yet
* been extended to cover all of your system's capabilities.
*
* 7) (u)intptr_t may or may not be defined. Test for its presence
* with the test: #ifdef PTRDIFF_MAX. If this is not defined
* for your platform, then it is because this file has not yet
* been extended to cover all of your system's capabilities, not
* because its optional.
*
* 8) The following might not been defined even if your platform is
* capable of defining it:
*
* WCHAR_MIN
* WCHAR_MAX
* (u)int64_t
* PTRDIFF_MIN
* PTRDIFF_MAX
* (u)intptr_t
*
* 9) The following have not been defined:
*
* WINT_MIN
* WINT_MAX
*
* 10) The criteria for defining (u)int_least(*)_t isn't clear,
* except for systems which don't have a type that precisely
* defined 8, 16, or 32 bit types (which this include file does
* not support anyways). Default definitions have been given.
*
* 11) The criteria for defining (u)int_fast(*)_t isn't something I
* would trust to any particular compiler vendor or the ANSI C
* committee. It is well known that "compatible systems" are
* commonly created that have very different performance
* characteristics from the systems they are compatible with,
* especially those whose vendors make both the compiler and the
* system. Default definitions have been given, but its strongly
* recommended that users never use these definitions for any
* reason (they do *NOT* deliver any serious guarantee of
* improved performance -- not in this file, nor any vendor's
* stdint.h).
*
* 12) The following macros:
*
* PRINTF_INTMAX_MODIFIER
* PRINTF_INT64_MODIFIER
* PRINTF_INT32_MODIFIER
* PRINTF_INT16_MODIFIER
* PRINTF_LEAST64_MODIFIER
* PRINTF_LEAST32_MODIFIER
* PRINTF_LEAST16_MODIFIER
* PRINTF_INTPTR_MODIFIER
*
* are strings which have been defined as the modifiers required
* for the "d", "u" and "x" printf formats to correctly output
* (u)intmax_t, (u)int64_t, (u)int32_t, (u)int16_t, (u)least64_t,
* (u)least32_t, (u)least16_t and (u)intptr_t types respectively.
* PRINTF_INTPTR_MODIFIER is not defined for some systems which
* provide their own stdint.h. PRINTF_INT64_MODIFIER is not
* defined if INT64_MAX is not defined. These are an extension
* beyond what C99 specifies must be in stdint.h.
*
* In addition, the following macros are defined:
*
* PRINTF_INTMAX_HEX_WIDTH
* PRINTF_INT64_HEX_WIDTH
* PRINTF_INT32_HEX_WIDTH
* PRINTF_INT16_HEX_WIDTH
* PRINTF_INT8_HEX_WIDTH
* PRINTF_INTMAX_DEC_WIDTH
* PRINTF_INT64_DEC_WIDTH
* PRINTF_INT32_DEC_WIDTH
* PRINTF_INT16_DEC_WIDTH
* PRINTF_INT8_DEC_WIDTH
*
* Which specifies the maximum number of characters required to
* print the number of that type in either hexadecimal or decimal.
* These are an extension beyond what C99 specifies must be in
* stdint.h.
*
* Compilers tested (all with 0 warnings at their highest respective
* settings): Borland Turbo C 2.0, WATCOM C/C++ 11.0 (16 bits and 32
* bits), Microsoft Visual C++ 6.0 (32 bit), Microsoft Visual Studio
* .net (VC7), Intel C++ 4.0, GNU gcc v3.3.3
*
* This file should be considered a work in progress. Suggestions for
* improvements, especially those which increase coverage are strongly
* encouraged.
*
* Acknowledgements
*
* The following people have made significant contributions to the
* development and testing of this file:
*
* Chris Howie
* John Steele Scott
* Dave Thorup
* John Dill
*
*/
// Modifications copyright Amazon.com, Inc. or its affiliates
#include <stddef.h>
#include <limits.h>
#include <signal.h>
/*
* For gcc with _STDINT_H, fill in the PRINTF_INT*_MODIFIER macros, and
* do nothing else. On the Mac OS X version of gcc this is _STDINT_H_.
*/
#if ((defined(__STDC__) && __STDC__ && __STDC_VERSION__ >= 199901L) || (defined (__WATCOMC__) && (defined (_STDINT_H_INCLUDED) || __WATCOMC__ >= 1250)) || (defined(__GNUC__) && (defined(_STDINT_H) || defined(_STDINT_H_) || defined (__UINT_FAST64_TYPE__)) )) && !defined (_PSTDINT_H_INCLUDED)
#include <stdint.h>
#define _PSTDINT_H_INCLUDED
# ifndef PRINTF_INT64_MODIFIER
# define PRINTF_INT64_MODIFIER "ll"
# endif
# ifndef PRINTF_INT32_MODIFIER
# define PRINTF_INT32_MODIFIER "l"
# endif
# ifndef PRINTF_INT16_MODIFIER
# define PRINTF_INT16_MODIFIER "h"
# endif
# ifndef PRINTF_INTMAX_MODIFIER
# define PRINTF_INTMAX_MODIFIER PRINTF_INT64_MODIFIER
# endif
# ifndef PRINTF_INT64_HEX_WIDTH
# define PRINTF_INT64_HEX_WIDTH "16"
# endif
# ifndef PRINTF_INT32_HEX_WIDTH
# define PRINTF_INT32_HEX_WIDTH "8"
# endif
# ifndef PRINTF_INT16_HEX_WIDTH
# define PRINTF_INT16_HEX_WIDTH "4"
# endif
# ifndef PRINTF_INT8_HEX_WIDTH
# define PRINTF_INT8_HEX_WIDTH "2"
# endif
# ifndef PRINTF_INT64_DEC_WIDTH
# define PRINTF_INT64_DEC_WIDTH "20"
# endif
# ifndef PRINTF_INT32_DEC_WIDTH
# define PRINTF_INT32_DEC_WIDTH "10"
# endif
# ifndef PRINTF_INT16_DEC_WIDTH
# define PRINTF_INT16_DEC_WIDTH "5"
# endif
# ifndef PRINTF_INT8_DEC_WIDTH
# define PRINTF_INT8_DEC_WIDTH "3"
# endif
# ifndef PRINTF_INTMAX_HEX_WIDTH
# define PRINTF_INTMAX_HEX_WIDTH PRINTF_INT64_HEX_WIDTH
# endif
# ifndef PRINTF_INTMAX_DEC_WIDTH
# define PRINTF_INTMAX_DEC_WIDTH PRINTF_INT64_DEC_WIDTH
# endif
/*
* Something really weird is going on with Open Watcom. Just pull some of
* these duplicated definitions from Open Watcom's stdint.h file for now.
*/
# if defined (__WATCOMC__) && __WATCOMC__ >= 1250
# if !defined (INT64_C)
# define INT64_C(x) (x + (INT64_MAX - INT64_MAX))
# endif
# if !defined (UINT64_C)
# define UINT64_C(x) (x + (UINT64_MAX - UINT64_MAX))
# endif
# if !defined (INT32_C)
# define INT32_C(x) (x + (INT32_MAX - INT32_MAX))
# endif
# if !defined (UINT32_C)
# define UINT32_C(x) (x + (UINT32_MAX - UINT32_MAX))
# endif
# if !defined (INT16_C)
# define INT16_C(x) (x)
# endif
# if !defined (UINT16_C)
# define UINT16_C(x) (x)
# endif
# if !defined (INT8_C)
# define INT8_C(x) (x)
# endif
# if !defined (UINT8_C)
# define UINT8_C(x) (x)
# endif
# if !defined (UINT64_MAX)
# define UINT64_MAX 18446744073709551615ULL
# endif
# if !defined (INT64_MAX)
# define INT64_MAX 9223372036854775807LL
# endif
# if !defined (UINT32_MAX)
# define UINT32_MAX 4294967295UL
# endif
# if !defined (INT32_MAX)
# define INT32_MAX 2147483647L
# endif
# if !defined (INTMAX_MAX)
# define INTMAX_MAX INT64_MAX
# endif
# if !defined (INTMAX_MIN)
# define INTMAX_MIN INT64_MIN
# endif
# endif
#endif
#ifndef _PSTDINT_H_INCLUDED
#define _PSTDINT_H_INCLUDED
#ifndef SIZE_MAX
# define SIZE_MAX (~(size_t)0)
#endif
/*
* Deduce the type assignments from limits.h under the assumption that
* integer sizes in bits are powers of 2, and follow the ANSI
* definitions.
*/
#ifndef UINT8_MAX
# define UINT8_MAX 0xff
#endif
#ifndef uint8_t
# if (UCHAR_MAX == UINT8_MAX) || defined (S_SPLINT_S)
typedef unsigned char uint8_t;
# define UINT8_C(v) ((uint8_t) v)
# else
# error "Platform not supported"
# endif
#endif
#ifndef INT8_MAX
# define INT8_MAX 0x7f
#endif
#ifndef INT8_MIN
# define INT8_MIN INT8_C(0x80)
#endif
#ifndef int8_t
# if (SCHAR_MAX == INT8_MAX) || defined (S_SPLINT_S)
typedef signed char int8_t;
# define INT8_C(v) ((int8_t) v)
# else
# error "Platform not supported"
# endif
#endif
#ifndef UINT16_MAX
# define UINT16_MAX 0xffff
#endif
#ifndef uint16_t
#if (UINT_MAX == UINT16_MAX) || defined (S_SPLINT_S)
typedef unsigned int uint16_t;
# ifndef PRINTF_INT16_MODIFIER
# define PRINTF_INT16_MODIFIER ""
# endif
# define UINT16_C(v) ((uint16_t) (v))
#elif (USHRT_MAX == UINT16_MAX)
typedef unsigned short uint16_t;
# define UINT16_C(v) ((uint16_t) (v))
# ifndef PRINTF_INT16_MODIFIER
# define PRINTF_INT16_MODIFIER "h"
# endif
#else
#error "Platform not supported"
#endif
#endif
#ifndef INT16_MAX
# define INT16_MAX 0x7fff
#endif
#ifndef INT16_MIN
# define INT16_MIN INT16_C(0x8000)
#endif
#ifndef int16_t
#if (INT_MAX == INT16_MAX) || defined (S_SPLINT_S)
typedef signed int int16_t;
# define INT16_C(v) ((int16_t) (v))
# ifndef PRINTF_INT16_MODIFIER
# define PRINTF_INT16_MODIFIER ""
# endif
#elif (SHRT_MAX == INT16_MAX)
typedef signed short int16_t;
# define INT16_C(v) ((int16_t) (v))
# ifndef PRINTF_INT16_MODIFIER
# define PRINTF_INT16_MODIFIER "h"
# endif
#else
#error "Platform not supported"
#endif
#endif
#ifndef UINT32_MAX
# define UINT32_MAX (0xffffffffUL)
#endif
#ifndef uint32_t
#if (ULONG_MAX == UINT32_MAX) || defined (S_SPLINT_S)
typedef unsigned long uint32_t;
# define UINT32_C(v) v ## UL
# ifndef PRINTF_INT32_MODIFIER
# define PRINTF_INT32_MODIFIER "l"
# endif
#elif (UINT_MAX == UINT32_MAX)
typedef unsigned int uint32_t;
# ifndef PRINTF_INT32_MODIFIER
# define PRINTF_INT32_MODIFIER ""
# endif
# define UINT32_C(v) v ## U
#elif (USHRT_MAX == UINT32_MAX)
typedef unsigned short uint32_t;
# define UINT32_C(v) ((unsigned short) (v))
# ifndef PRINTF_INT32_MODIFIER
# define PRINTF_INT32_MODIFIER ""
# endif
#else
#error "Platform not supported"
#endif
#endif
#ifndef INT32_MAX
# define INT32_MAX (0x7fffffffL)
#endif
#ifndef INT32_MIN
# define INT32_MIN INT32_C(0x80000000)
#endif
#ifndef int32_t
#if (LONG_MAX == INT32_MAX) || defined (S_SPLINT_S)
typedef signed long int32_t;
# define INT32_C(v) v ## L
# ifndef PRINTF_INT32_MODIFIER
# define PRINTF_INT32_MODIFIER "l"
# endif
#elif (INT_MAX == INT32_MAX)
typedef signed int int32_t;
# define INT32_C(v) v
# ifndef PRINTF_INT32_MODIFIER
# define PRINTF_INT32_MODIFIER ""
# endif
#elif (SHRT_MAX == INT32_MAX)
typedef signed short int32_t;
# define INT32_C(v) ((short) (v))
# ifndef PRINTF_INT32_MODIFIER
# define PRINTF_INT32_MODIFIER ""
# endif
#else
#error "Platform not supported"
#endif
#endif
/*
* The macro stdint_int64_defined is temporarily used to record
* whether or not 64 integer support is available. It must be
* defined for any 64 integer extensions for new platforms that are
* added.
*/
#undef stdint_int64_defined
#if (defined(__STDC__) && defined(__STDC_VERSION__)) || defined (S_SPLINT_S)
# if (__STDC__ && __STDC_VERSION__ >= 199901L) || defined (S_SPLINT_S)
# define stdint_int64_defined
typedef long long int64_t;
typedef unsigned long long uint64_t;
# define UINT64_C(v) v ## ULL
# define INT64_C(v) v ## LL
# ifndef PRINTF_INT64_MODIFIER
# define PRINTF_INT64_MODIFIER "ll"
# endif
# endif
#endif
#if !defined (stdint_int64_defined)
# if defined(__GNUC__)
# define stdint_int64_defined
__extension__ typedef long long int64_t;
__extension__ typedef unsigned long long uint64_t;
# define UINT64_C(v) v ## ULL
# define INT64_C(v) v ## LL
# ifndef PRINTF_INT64_MODIFIER
# define PRINTF_INT64_MODIFIER "ll"
# endif
# elif defined(__MWERKS__) || defined (__SUNPRO_C) || defined (__SUNPRO_CC) || defined (__APPLE_CC__) || defined (_LONG_LONG) || defined (_CRAYC) || defined (S_SPLINT_S)
# define stdint_int64_defined
typedef long long int64_t;
typedef unsigned long long uint64_t;
# define UINT64_C(v) v ## ULL
# define INT64_C(v) v ## LL
# ifndef PRINTF_INT64_MODIFIER
# define PRINTF_INT64_MODIFIER "ll"
# endif
# elif (defined(__WATCOMC__) && defined(__WATCOM_INT64__)) || (defined(_MSC_VER) && _INTEGRAL_MAX_BITS >= 64) || (defined (__BORLANDC__) && __BORLANDC__ > 0x460) || defined (__alpha) || defined (__DECC)
# define stdint_int64_defined
typedef __int64 int64_t;
typedef unsigned __int64 uint64_t;
# define UINT64_C(v) v ## UI64
# define INT64_C(v) v ## I64
# ifndef PRINTF_INT64_MODIFIER
# define PRINTF_INT64_MODIFIER "I64"
# endif
# endif
#endif
#if !defined (LONG_LONG_MAX) && defined (INT64_C)
# define LONG_LONG_MAX INT64_C (9223372036854775807)
#endif
#ifndef ULONG_LONG_MAX
# define ULONG_LONG_MAX UINT64_C (18446744073709551615)
#endif
#if !defined (INT64_MAX) && defined (INT64_C)
# define INT64_MAX INT64_C (9223372036854775807)
#endif
#if !defined (INT64_MIN) && defined (INT64_C)
# define INT64_MIN INT64_C (-9223372036854775808)
#endif
#if !defined (UINT64_MAX) && defined (INT64_C)
# define UINT64_MAX UINT64_C (18446744073709551615)
#endif
/*
* Width of hexadecimal for number field.
*/
#ifndef PRINTF_INT64_HEX_WIDTH
# define PRINTF_INT64_HEX_WIDTH "16"
#endif
#ifndef PRINTF_INT32_HEX_WIDTH
# define PRINTF_INT32_HEX_WIDTH "8"
#endif
#ifndef PRINTF_INT16_HEX_WIDTH
# define PRINTF_INT16_HEX_WIDTH "4"
#endif
#ifndef PRINTF_INT8_HEX_WIDTH
# define PRINTF_INT8_HEX_WIDTH "2"
#endif
#ifndef PRINTF_INT64_DEC_WIDTH
# define PRINTF_INT64_DEC_WIDTH "20"
#endif
#ifndef PRINTF_INT32_DEC_WIDTH
# define PRINTF_INT32_DEC_WIDTH "10"
#endif
#ifndef PRINTF_INT16_DEC_WIDTH
# define PRINTF_INT16_DEC_WIDTH "5"
#endif
#ifndef PRINTF_INT8_DEC_WIDTH
# define PRINTF_INT8_DEC_WIDTH "3"
#endif
/*
* Ok, lets not worry about 128 bit integers for now. Moore's law says
* we don't need to worry about that until about 2040 at which point
* we'll have bigger things to worry about.
*/
#ifdef stdint_int64_defined
typedef int64_t intmax_t;
typedef uint64_t uintmax_t;
# define INTMAX_MAX INT64_MAX
# define INTMAX_MIN INT64_MIN
# define UINTMAX_MAX UINT64_MAX
# define UINTMAX_C(v) UINT64_C(v)
# define INTMAX_C(v) INT64_C(v)
# ifndef PRINTF_INTMAX_MODIFIER
# define PRINTF_INTMAX_MODIFIER PRINTF_INT64_MODIFIER
# endif
# ifndef PRINTF_INTMAX_HEX_WIDTH
# define PRINTF_INTMAX_HEX_WIDTH PRINTF_INT64_HEX_WIDTH
# endif
# ifndef PRINTF_INTMAX_DEC_WIDTH
# define PRINTF_INTMAX_DEC_WIDTH PRINTF_INT64_DEC_WIDTH
# endif
#else
typedef int32_t intmax_t;
typedef uint32_t uintmax_t;
# define INTMAX_MAX INT32_MAX
# define UINTMAX_MAX UINT32_MAX
# define UINTMAX_C(v) UINT32_C(v)
# define INTMAX_C(v) INT32_C(v)
# ifndef PRINTF_INTMAX_MODIFIER
# define PRINTF_INTMAX_MODIFIER PRINTF_INT32_MODIFIER
# endif
# ifndef PRINTF_INTMAX_HEX_WIDTH
# define PRINTF_INTMAX_HEX_WIDTH PRINTF_INT32_HEX_WIDTH
# endif
# ifndef PRINTF_INTMAX_DEC_WIDTH
# define PRINTF_INTMAX_DEC_WIDTH PRINTF_INT32_DEC_WIDTH
# endif
#endif
/*
* Because this file currently only supports platforms which have
* precise powers of 2 as bit sizes for the default integers, the
* least definitions are all trivial. Its possible that a future
* version of this file could have different definitions.
*/
#ifndef stdint_least_defined
typedef int8_t int_least8_t;
typedef uint8_t uint_least8_t;
typedef int16_t int_least16_t;
typedef uint16_t uint_least16_t;
typedef int32_t int_least32_t;
typedef uint32_t uint_least32_t;
# define PRINTF_LEAST32_MODIFIER PRINTF_INT32_MODIFIER
# define PRINTF_LEAST16_MODIFIER PRINTF_INT16_MODIFIER
# define UINT_LEAST8_MAX UINT8_MAX
# define INT_LEAST8_MAX INT8_MAX
# define UINT_LEAST16_MAX UINT16_MAX
# define INT_LEAST16_MAX INT16_MAX
# define UINT_LEAST32_MAX UINT32_MAX
# define INT_LEAST32_MAX INT32_MAX
# define INT_LEAST8_MIN INT8_MIN
# define INT_LEAST16_MIN INT16_MIN
# define INT_LEAST32_MIN INT32_MIN
# ifdef stdint_int64_defined
typedef int64_t int_least64_t;
typedef uint64_t uint_least64_t;
# define PRINTF_LEAST64_MODIFIER PRINTF_INT64_MODIFIER
# define UINT_LEAST64_MAX UINT64_MAX
# define INT_LEAST64_MAX INT64_MAX
# define INT_LEAST64_MIN INT64_MIN
# endif
#endif
#undef stdint_least_defined
/*
* The ANSI C committee pretending to know or specify anything about
* performance is the epitome of misguided arrogance. The mandate of
* this file is to *ONLY* ever support that absolute minimum
* definition of the fast integer types, for compatibility purposes.
* No extensions, and no attempt to suggest what may or may not be a
* faster integer type will ever be made in this file. Developers are
* warned to stay away from these types when using this or any other
* stdint.h.
*/
typedef int_least8_t int_fast8_t;
typedef uint_least8_t uint_fast8_t;
typedef int_least16_t int_fast16_t;
typedef uint_least16_t uint_fast16_t;
typedef int_least32_t int_fast32_t;
typedef uint_least32_t uint_fast32_t;
#define UINT_FAST8_MAX UINT_LEAST8_MAX
#define INT_FAST8_MAX INT_LEAST8_MAX
#define UINT_FAST16_MAX UINT_LEAST16_MAX
#define INT_FAST16_MAX INT_LEAST16_MAX
#define UINT_FAST32_MAX UINT_LEAST32_MAX
#define INT_FAST32_MAX INT_LEAST32_MAX
#define INT_FAST8_MIN INT_LEAST8_MIN
#define INT_FAST16_MIN INT_LEAST16_MIN
#define INT_FAST32_MIN INT_LEAST32_MIN
#ifdef stdint_int64_defined
typedef int_least64_t int_fast64_t;
typedef uint_least64_t uint_fast64_t;
# define UINT_FAST64_MAX UINT_LEAST64_MAX
# define INT_FAST64_MAX INT_LEAST64_MAX
# define INT_FAST64_MIN INT_LEAST64_MIN
#endif
#undef stdint_int64_defined
/*
* Whatever piecemeal, per compiler thing we can do about the wchar_t
* type limits.
*/
#if defined(__WATCOMC__) || defined(_MSC_VER) || defined (__GNUC__)
# include <wchar.h>
# ifndef WCHAR_MIN
# define WCHAR_MIN 0
# endif
# ifndef WCHAR_MAX
# define WCHAR_MAX ((wchar_t)-1)
# endif
#endif
/*
* Whatever piecemeal, per compiler/platform thing we can do about the
* (u)intptr_t types and limits.
*/
#if defined (_MSC_VER) && defined (_UINTPTR_T_DEFINED)
# define STDINT_H_UINTPTR_T_DEFINED
#endif
#ifndef STDINT_H_UINTPTR_T_DEFINED
# if defined (__alpha__) || defined (__ia64__) || defined (__x86_64__) || defined (_WIN64)
# define stdint_intptr_bits 64
# elif defined (__WATCOMC__) || defined (__TURBOC__)
# if defined(__TINY__) || defined(__SMALL__) || defined(__MEDIUM__)
# define stdint_intptr_bits 16
# else
# define stdint_intptr_bits 32
# endif
# elif defined (__i386__) || defined (_WIN32) || defined (WIN32)
# define stdint_intptr_bits 32
# elif defined (__INTEL_COMPILER)
/* TODO -- what did Intel do about x86-64? */
# endif
# ifdef stdint_intptr_bits
# define stdint_intptr_glue3_i(a,b,c) a##b##c
# define stdint_intptr_glue3(a,b,c) stdint_intptr_glue3_i(a,b,c)
# ifndef PRINTF_INTPTR_MODIFIER
# define PRINTF_INTPTR_MODIFIER stdint_intptr_glue3(PRINTF_INT,stdint_intptr_bits,_MODIFIER)
# endif
# ifndef PTRDIFF_MAX
# define PTRDIFF_MAX stdint_intptr_glue3(INT,stdint_intptr_bits,_MAX)
# endif
# ifndef PTRDIFF_MIN
# define PTRDIFF_MIN stdint_intptr_glue3(INT,stdint_intptr_bits,_MIN)
# endif
# ifndef UINTPTR_MAX
# define UINTPTR_MAX stdint_intptr_glue3(UINT,stdint_intptr_bits,_MAX)
# endif
# ifndef INTPTR_MAX
# define INTPTR_MAX stdint_intptr_glue3(INT,stdint_intptr_bits,_MAX)
# endif
# ifndef INTPTR_MIN
# define INTPTR_MIN stdint_intptr_glue3(INT,stdint_intptr_bits,_MIN)
# endif
# ifndef INTPTR_C
# define INTPTR_C(x) stdint_intptr_glue3(INT,stdint_intptr_bits,_C)(x)
# endif
# ifndef UINTPTR_C
# define UINTPTR_C(x) stdint_intptr_glue3(UINT,stdint_intptr_bits,_C)(x)
# endif
typedef stdint_intptr_glue3(uint,stdint_intptr_bits,_t) uintptr_t;
typedef stdint_intptr_glue3( int,stdint_intptr_bits,_t) intptr_t;
# else
/* TODO -- This following is likely wrong for some platforms, and does
nothing for the definition of uintptr_t. */
typedef ptrdiff_t intptr_t;
# endif
# define STDINT_H_UINTPTR_T_DEFINED
#endif
/*
* Assumes sig_atomic_t is signed and we have a 2s complement machine.
*/
#ifndef SIG_ATOMIC_MAX
# define SIG_ATOMIC_MAX ((((sig_atomic_t) 1) << (sizeof (sig_atomic_t)*CHAR_BIT-1)) - 1)
#endif
#endif
#if defined (__TEST_PSTDINT_FOR_CORRECTNESS)
/*
* Please compile with the maximum warning settings to make sure macros are not
* defined more than once.
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#define glue3_aux(x,y,z) x ## y ## z
#define glue3(x,y,z) glue3_aux(x,y,z)
#define DECLU(bits) glue3(uint,bits,_t) glue3(u,bits,=) glue3(UINT,bits,_C) (0);
#define DECLI(bits) glue3(int,bits,_t) glue3(i,bits,=) glue3(INT,bits,_C) (0);
#define DECL(us,bits) glue3(DECL,us,) (bits)
#define TESTUMAX(bits) glue3(u,bits,=) glue3(~,u,bits); if (glue3(UINT,bits,_MAX) glue3(!=,u,bits)) printf ("Something wrong with UINT%d_MAX\n", bits)
int main () {
DECL(I,8)
DECL(U,8)
DECL(I,16)
DECL(U,16)
DECL(I,32)
DECL(U,32)
#ifdef INT64_MAX
DECL(I,64)
DECL(U,64)
#endif
intmax_t imax = INTMAX_C(0);
uintmax_t umax = UINTMAX_C(0);
char str0[256], str1[256];
sprintf (str0, "%d %x\n", 0, ~0);
sprintf (str1, "%d %x\n", i8, ~0);
if (0 != strcmp (str0, str1)) printf ("Something wrong with i8 : %s\n", str1);
sprintf (str1, "%u %x\n", u8, ~0);
if (0 != strcmp (str0, str1)) printf ("Something wrong with u8 : %s\n", str1);
sprintf (str1, "%d %x\n", i16, ~0);
if (0 != strcmp (str0, str1)) printf ("Something wrong with i16 : %s\n", str1);
sprintf (str1, "%u %x\n", u16, ~0);
if (0 != strcmp (str0, str1)) printf ("Something wrong with u16 : %s\n", str1);
sprintf (str1, "%" PRINTF_INT32_MODIFIER "d %x\n", i32, ~0);
if (0 != strcmp (str0, str1)) printf ("Something wrong with i32 : %s\n", str1);
sprintf (str1, "%" PRINTF_INT32_MODIFIER "u %x\n", u32, ~0);
if (0 != strcmp (str0, str1)) printf ("Something wrong with u32 : %s\n", str1);
#ifdef INT64_MAX
sprintf (str1, "%" PRINTF_INT64_MODIFIER "d %x\n", i64, ~0);
if (0 != strcmp (str0, str1)) printf ("Something wrong with i64 : %s\n", str1);
#endif
sprintf (str1, "%" PRINTF_INTMAX_MODIFIER "d %x\n", imax, ~0);
if (0 != strcmp (str0, str1)) printf ("Something wrong with imax : %s\n", str1);
sprintf (str1, "%" PRINTF_INTMAX_MODIFIER "u %x\n", umax, ~0);
if (0 != strcmp (str0, str1)) printf ("Something wrong with umax : %s\n", str1);
TESTUMAX(8);
TESTUMAX(16);
TESTUMAX(32);
#ifdef INT64_MAX
TESTUMAX(64);
#endif
return EXIT_SUCCESS;
}
#endif