Skip to content

Commit

Permalink
Replace individual EOpConv<A>To<B> with a single EOpConvNumeric
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffbolznv committed Nov 6, 2024
1 parent 76cc41d commit aaf008a
Show file tree
Hide file tree
Showing 10 changed files with 352 additions and 1,442 deletions.
493 changes: 126 additions & 367 deletions SPIRV/GlslangToSpv.cpp

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions SPIRV/SpvBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,8 @@ class Builder {
// For making new constants (will return old constant if the requested one was already made).
Id makeNullConstant(Id typeId);
Id makeBoolConstant(bool b, bool specConstant = false);
Id makeIntConstant(Id typeId, unsigned value, bool specConstant);
Id makeInt64Constant(Id typeId, unsigned long long value, bool specConstant);
Id makeInt8Constant(int i, bool specConstant = false)
{ return makeIntConstant(makeIntType(8), (unsigned)i, specConstant); }
Id makeUint8Constant(unsigned u, bool specConstant = false)
Expand Down Expand Up @@ -894,8 +896,6 @@ class Builder {
void setUseReplicatedComposites(bool use) { useReplicatedComposites = use; }

protected:
Id makeIntConstant(Id typeId, unsigned value, bool specConstant);
Id makeInt64Constant(Id typeId, unsigned long long value, bool specConstant);
Id findScalarConstant(Op typeClass, Op opcode, Id typeId, unsigned value);
Id findScalarConstant(Op typeClass, Op opcode, Id typeId, unsigned v1, unsigned v2);
Id findCompositeConstant(Op typeClass, Id typeId, const std::vector<Id>& comps);
Expand Down
16 changes: 8 additions & 8 deletions Test/baseResults/findFunction.frag.out
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ ERROR: node is still EOpNull!
0:5 'c' ( in int16_t)
0:7 Sequence
0:7 Branch: Return with expression
0:7 Convert int16_t to int64 ( temp int64_t)
0:7 Convert int16_t to int64_t ( temp int64_t)
0:7 inclusive-or ( temp int16_t)
0:7 Convert int8_t to int16_t ( temp int16_t)
0:7 'a' ( in int8_t)
Expand All @@ -34,7 +34,7 @@ ERROR: node is still EOpNull!
0:10 'c' ( in int)
0:12 Sequence
0:12 Branch: Return with expression
0:12 Convert int to int64 ( temp int64_t)
0:12 Convert int to int64_t ( temp int64_t)
0:12 inclusive-or ( temp int)
0:12 Convert int8_t to int ( temp int)
0:12 'a' ( in int8_t)
Expand All @@ -49,7 +49,7 @@ ERROR: node is still EOpNull!
0:15 'c' ( in int)
0:17 Sequence
0:17 Branch: Return with expression
0:17 Convert int to int64 ( temp int64_t)
0:17 Convert int to int64_t ( temp int64_t)
0:17 add ( temp int)
0:17 divide ( temp int)
0:17 'a' ( in int)
Expand All @@ -62,7 +62,7 @@ ERROR: node is still EOpNull!
0:20 'c' ( in float)
0:22 Sequence
0:22 Branch: Return with expression
0:22 Convert float to int64 ( temp int64_t)
0:22 Convert float to int64_t ( temp int64_t)
0:22 subtract ( temp float)
0:22 Convert float16_t to float ( temp float)
0:22 'a' ( in float16_t)
Expand All @@ -77,7 +77,7 @@ ERROR: node is still EOpNull!
0:25 'c' ( in float)
0:27 Sequence
0:27 Branch: Return with expression
0:27 Convert float to int64 ( temp int64_t)
0:27 Convert float to int64_t ( temp int64_t)
0:27 subtract ( temp float)
0:27 Convert float16_t to float ( temp float)
0:27 'a' ( in float16_t)
Expand Down Expand Up @@ -146,7 +146,7 @@ ERROR: node is still EOpNull!
0:10 'c' ( in int)
0:12 Sequence
0:12 Branch: Return with expression
0:12 Convert int to int64 ( temp int64_t)
0:12 Convert int to int64_t ( temp int64_t)
0:12 inclusive-or ( temp int)
0:12 Convert int8_t to int ( temp int)
0:12 'a' ( in int8_t)
Expand All @@ -161,7 +161,7 @@ ERROR: node is still EOpNull!
0:20 'c' ( in float)
0:22 Sequence
0:22 Branch: Return with expression
0:22 Convert float to int64 ( temp int64_t)
0:22 Convert float to int64_t ( temp int64_t)
0:22 subtract ( temp float)
0:22 Convert float16_t to float ( temp float)
0:22 'a' ( in float16_t)
Expand All @@ -176,7 +176,7 @@ ERROR: node is still EOpNull!
0:25 'c' ( in float)
0:27 Sequence
0:27 Branch: Return with expression
0:27 Convert float to int64 ( temp int64_t)
0:27 Convert float to int64_t ( temp int64_t)
0:27 subtract ( temp float)
0:27 Convert float16_t to float ( temp float)
0:27 'a' ( in float16_t)
Expand Down
16 changes: 8 additions & 8 deletions Test/baseResults/hlsl.wavevote.comp.out
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ local_size = (32, 16, 1)
0:6 Constant:
0:6 0 (const int)
0:6 Construct uint64 (layout( row_major std430) buffer uint64_t)
0:6 Convert uint to uint64 ( temp 4-component vector of uint64_t)
0:6 Convert uint to uint64_t ( temp 4-component vector of uint64_t)
0:6 subgroupBallot ( temp 4-component vector of uint)
0:6 subgroupAny ( temp bool)
0:6 Compare Equal ( temp bool)
Expand All @@ -38,7 +38,7 @@ local_size = (32, 16, 1)
0:7 Constant:
0:7 1 (const int)
0:7 Construct uint64 (layout( row_major std430) buffer uint64_t)
0:7 Convert uint to uint64 ( temp 4-component vector of uint64_t)
0:7 Convert uint to uint64_t ( temp 4-component vector of uint64_t)
0:7 subgroupBallot ( temp 4-component vector of uint)
0:7 subgroupAll ( temp bool)
0:7 Compare Equal ( temp bool)
Expand All @@ -59,7 +59,7 @@ local_size = (32, 16, 1)
0:8 Constant:
0:8 2 (const int)
0:8 Construct uint64 (layout( row_major std430) buffer uint64_t)
0:8 Convert uint to uint64 ( temp 4-component vector of uint64_t)
0:8 Convert uint to uint64_t ( temp 4-component vector of uint64_t)
0:8 subgroupBallot ( temp 4-component vector of uint)
0:8 subgroupAllEqual ( temp bool)
0:8 Compare Equal ( temp bool)
Expand All @@ -80,7 +80,7 @@ local_size = (32, 16, 1)
0:9 Constant:
0:9 2 (const int)
0:9 Construct uint64 (layout( row_major std430) buffer uint64_t)
0:9 Convert uint to uint64 ( temp 4-component vector of uint64_t)
0:9 Convert uint to uint64_t ( temp 4-component vector of uint64_t)
0:9 subgroupBallot ( temp 4-component vector of uint)
0:9 subgroupAllEqual ( temp bool)
0:9 direct index ( temp uint)
Expand Down Expand Up @@ -121,7 +121,7 @@ local_size = (32, 16, 1)
0:6 Constant:
0:6 0 (const int)
0:6 Construct uint64 (layout( row_major std430) buffer uint64_t)
0:6 Convert uint to uint64 ( temp 4-component vector of uint64_t)
0:6 Convert uint to uint64_t ( temp 4-component vector of uint64_t)
0:6 subgroupBallot ( temp 4-component vector of uint)
0:6 subgroupAny ( temp bool)
0:6 Compare Equal ( temp bool)
Expand All @@ -142,7 +142,7 @@ local_size = (32, 16, 1)
0:7 Constant:
0:7 1 (const int)
0:7 Construct uint64 (layout( row_major std430) buffer uint64_t)
0:7 Convert uint to uint64 ( temp 4-component vector of uint64_t)
0:7 Convert uint to uint64_t ( temp 4-component vector of uint64_t)
0:7 subgroupBallot ( temp 4-component vector of uint)
0:7 subgroupAll ( temp bool)
0:7 Compare Equal ( temp bool)
Expand All @@ -163,7 +163,7 @@ local_size = (32, 16, 1)
0:8 Constant:
0:8 2 (const int)
0:8 Construct uint64 (layout( row_major std430) buffer uint64_t)
0:8 Convert uint to uint64 ( temp 4-component vector of uint64_t)
0:8 Convert uint to uint64_t ( temp 4-component vector of uint64_t)
0:8 subgroupBallot ( temp 4-component vector of uint)
0:8 subgroupAllEqual ( temp bool)
0:8 Compare Equal ( temp bool)
Expand All @@ -184,7 +184,7 @@ local_size = (32, 16, 1)
0:9 Constant:
0:9 2 (const int)
0:9 Construct uint64 (layout( row_major std430) buffer uint64_t)
0:9 Convert uint to uint64 ( temp 4-component vector of uint64_t)
0:9 Convert uint to uint64_t ( temp 4-component vector of uint64_t)
0:9 subgroupBallot ( temp 4-component vector of uint)
0:9 subgroupAllEqual ( temp bool)
0:9 direct index ( temp uint)
Expand Down
23 changes: 23 additions & 0 deletions glslang/Include/BaseTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,29 @@ __inline bool isTypeFloat(TBasicType type)
}
}

__inline uint32_t GetNumBits(TBasicType type)
{
switch (type) {
case EbtInt8:
case EbtUint8:
return 8;
case EbtFloat16:
case EbtInt16:
case EbtUint16:
return 16;
case EbtInt:
case EbtUint:
case EbtFloat:
return 32;
case EbtDouble:
case EbtInt64:
case EbtUint64:
return 64;
}
assert(false);
return 0;
}

__inline int getTypeRank(TBasicType type)
{
int res = -1;
Expand Down
190 changes: 7 additions & 183 deletions glslang/Include/intermediate.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,189 +87,9 @@ enum TOperator {

EOpDeclare, // Used by debugging to force declaration of variable in correct scope

// (u)int* -> bool
EOpConvInt8ToBool,
EOpConvUint8ToBool,
EOpConvInt16ToBool,
EOpConvUint16ToBool,
EOpConvIntToBool,
EOpConvUintToBool,
EOpConvInt64ToBool,
EOpConvUint64ToBool,

// float* -> bool
EOpConvFloat16ToBool,
EOpConvFloatToBool,
EOpConvDoubleToBool,

// bool -> (u)int*
EOpConvBoolToInt8,
EOpConvBoolToUint8,
EOpConvBoolToInt16,
EOpConvBoolToUint16,
EOpConvBoolToInt,
EOpConvBoolToUint,
EOpConvBoolToInt64,
EOpConvBoolToUint64,

// bool -> float*
EOpConvBoolToFloat16,
EOpConvBoolToFloat,
EOpConvBoolToDouble,

// int8_t -> (u)int*
EOpConvInt8ToInt16,
EOpConvInt8ToInt,
EOpConvInt8ToInt64,
EOpConvInt8ToUint8,
EOpConvInt8ToUint16,
EOpConvInt8ToUint,
EOpConvInt8ToUint64,

// uint8_t -> (u)int*
EOpConvUint8ToInt8,
EOpConvUint8ToInt16,
EOpConvUint8ToInt,
EOpConvUint8ToInt64,
EOpConvUint8ToUint16,
EOpConvUint8ToUint,
EOpConvUint8ToUint64,

// int8_t -> float*
EOpConvInt8ToFloat16,
EOpConvInt8ToFloat,
EOpConvInt8ToDouble,

// uint8_t -> float*
EOpConvUint8ToFloat16,
EOpConvUint8ToFloat,
EOpConvUint8ToDouble,

// int16_t -> (u)int*
EOpConvInt16ToInt8,
EOpConvInt16ToInt,
EOpConvInt16ToInt64,
EOpConvInt16ToUint8,
EOpConvInt16ToUint16,
EOpConvInt16ToUint,
EOpConvInt16ToUint64,

// uint16_t -> (u)int*
EOpConvUint16ToInt8,
EOpConvUint16ToInt16,
EOpConvUint16ToInt,
EOpConvUint16ToInt64,
EOpConvUint16ToUint8,
EOpConvUint16ToUint,
EOpConvUint16ToUint64,

// int16_t -> float*
EOpConvInt16ToFloat16,
EOpConvInt16ToFloat,
EOpConvInt16ToDouble,

// uint16_t -> float*
EOpConvUint16ToFloat16,
EOpConvUint16ToFloat,
EOpConvUint16ToDouble,

// int32_t -> (u)int*
EOpConvIntToInt8,
EOpConvIntToInt16,
EOpConvIntToInt64,
EOpConvIntToUint8,
EOpConvIntToUint16,
EOpConvIntToUint,
EOpConvIntToUint64,

// uint32_t -> (u)int*
EOpConvUintToInt8,
EOpConvUintToInt16,
EOpConvUintToInt,
EOpConvUintToInt64,
EOpConvUintToUint8,
EOpConvUintToUint16,
EOpConvUintToUint64,

// int32_t -> float*
EOpConvIntToFloat16,
EOpConvIntToFloat,
EOpConvIntToDouble,

// uint32_t -> float*
EOpConvUintToFloat16,
EOpConvUintToFloat,
EOpConvUintToDouble,

// int64_t -> (u)int*
EOpConvInt64ToInt8,
EOpConvInt64ToInt16,
EOpConvInt64ToInt,
EOpConvInt64ToUint8,
EOpConvInt64ToUint16,
EOpConvInt64ToUint,
EOpConvInt64ToUint64,

// uint64_t -> (u)int*
EOpConvUint64ToInt8,
EOpConvUint64ToInt16,
EOpConvUint64ToInt,
EOpConvUint64ToInt64,
EOpConvUint64ToUint8,
EOpConvUint64ToUint16,
EOpConvUint64ToUint,

// int64_t -> float*
EOpConvInt64ToFloat16,
EOpConvInt64ToFloat,
EOpConvInt64ToDouble,

// uint64_t -> float*
EOpConvUint64ToFloat16,
EOpConvUint64ToFloat,
EOpConvUint64ToDouble,

// float16_t -> (u)int*
EOpConvFloat16ToInt8,
EOpConvFloat16ToInt16,
EOpConvFloat16ToInt,
EOpConvFloat16ToInt64,
EOpConvFloat16ToUint8,
EOpConvFloat16ToUint16,
EOpConvFloat16ToUint,
EOpConvFloat16ToUint64,

// float16_t -> float*
EOpConvFloat16ToFloat,
EOpConvFloat16ToDouble,

// float -> (u)int*
EOpConvFloatToInt8,
EOpConvFloatToInt16,
EOpConvFloatToInt,
EOpConvFloatToInt64,
EOpConvFloatToUint8,
EOpConvFloatToUint16,
EOpConvFloatToUint,
EOpConvFloatToUint64,

// float -> float*
EOpConvFloatToFloat16,
EOpConvFloatToDouble,

// float64 _t-> (u)int*
EOpConvDoubleToInt8,
EOpConvDoubleToInt16,
EOpConvDoubleToInt,
EOpConvDoubleToInt64,
EOpConvDoubleToUint8,
EOpConvDoubleToUint16,
EOpConvDoubleToUint,
EOpConvDoubleToUint64,

// float64_t -> float*
EOpConvDoubleToFloat16,
EOpConvDoubleToFloat,
// Operator used to represent all conversions between int, float, and bool.
// The specific types are inferred from TBasicType.
EOpConvNumeric,

// uint64_t <-> pointer
EOpConvUint64ToPtr,
Expand Down Expand Up @@ -1136,6 +956,10 @@ enum TOperator {
EOpImageBlockMatchGatherSADQCOM,
};

inline bool IsOpNumericConv(const TOperator op) {
return op == EOpConvNumeric;
}

enum TLinkType {
ELinkNone,
ELinkExport,
Expand Down
Loading

0 comments on commit aaf008a

Please sign in to comment.