Skip to content

Commit

Permalink
smolv: encode VectorShuffle
Browse files Browse the repository at this point in the history
Compression: original size 807.0KB
0 SMOL         : 449.8KB ( 55.7%) -37.3
2 smLZ4HC      : 127.5KB ( 15.8%) -12.5
4 smZstd       : 118.0KB ( 14.6%) -10.8
6 smZstd20     :  85.6KB ( 10.6%) -6.7
  • Loading branch information
aras-p committed Aug 27, 2016
1 parent 281e607 commit 270f4f7
Showing 1 changed file with 35 additions and 14 deletions.
49 changes: 35 additions & 14 deletions source/smolv.cpp
Expand Up @@ -923,14 +923,22 @@ bool smolv::Encode(const void* spirvData, size_t spirvSize, ByteArray& outSmolv)
// write the rest of the instruction words
if (op == SpvOpDecorate || op == SpvOpMemberDecorate)
{
// Decorate & MemberDecorate (20.5% total space in test data): delta+varint from previous, varint on rest
// Decorate & MemberDecorate (20.4% space in test data): delta+varint from previous, varint on rest
uint32_t v = words[ioffs];
smolv_WriteVarint(outSmolv, v - prevDecorate);
prevDecorate = v;
ioffs++;
for (; ioffs < instrLen; ++ioffs)
smolv_WriteVarint(outSmolv, words[ioffs]);
}
else if (op == SpvOpVectorShuffle)
{
// VectorShuffle (9.8% space in test data): vector IDs as deltas from result + varint, varint on rest
smolv_WriteVarint(outSmolv, prevResult - words[ioffs]); ioffs++;
smolv_WriteVarint(outSmolv, prevResult - words[ioffs]); ioffs++;
for (; ioffs < instrLen; ++ioffs)
smolv_WriteVarint(outSmolv, words[ioffs]);
}
else
{
// regular op with no special handling
Expand Down Expand Up @@ -978,16 +986,14 @@ bool smolv::Decode(const void* smolvData, size_t smolvSize, ByteArray& outSpirv)
// read type as varint, if we have it
if (smolv_OpHasType(op))
{
if (!smolv_ReadVarint(bytes, bytesEnd, val))
return false;
if (!smolv_ReadVarint(bytes, bytesEnd, val)) return false;
smolv_Write4(outSpirv, val);
ioffs++;
}
// read result as delta+varint, if we have it
if (smolv_OpHasResult(op))
{
if (!smolv_ReadVarint(bytes, bytesEnd, val))
return false;
if (!smolv_ReadVarint(bytes, bytesEnd, val)) return false;
val = prevResult + smolv_ZigDecode(val);
smolv_Write4(outSpirv, val);
prevResult = val;
Expand All @@ -998,16 +1004,29 @@ bool smolv::Decode(const void* smolvData, size_t smolvSize, ByteArray& outSpirv)
if (op == SpvOpDecorate || op == SpvOpMemberDecorate)
{
// Decorate: delta+varint from previous, varint on rest
if (!smolv_ReadVarint(bytes, bytesEnd, val))
return false;
if (!smolv_ReadVarint(bytes, bytesEnd, val)) return false;
val = prevDecorate + val;
smolv_Write4(outSpirv, val);
prevDecorate = val;
ioffs++;
for (; ioffs < instrLen; ++ioffs)
{
if (!smolv_ReadVarint(bytes, bytesEnd, val))
return false;
if (!smolv_ReadVarint(bytes, bytesEnd, val)) return false;
smolv_Write4(outSpirv, val);
}
}
else if (op == SpvOpVectorShuffle)
{
// VectorShuffle: vector IDs as deltas from result + varint, varint on rest
if (!smolv_ReadVarint(bytes, bytesEnd, val)) return false;
smolv_Write4(outSpirv, prevResult - val);
ioffs++;
if (!smolv_ReadVarint(bytes, bytesEnd, val)) return false;
smolv_Write4(outSpirv, prevResult - val);
ioffs++;
for (; ioffs < instrLen; ++ioffs)
{
if (!smolv_ReadVarint(bytes, bytesEnd, val)) return false;
smolv_Write4(outSpirv, val);
}
}
Expand All @@ -1016,8 +1035,7 @@ bool smolv::Decode(const void* smolvData, size_t smolvSize, ByteArray& outSpirv)
// regular op with no special handling
for (; ioffs < instrLen; ++ioffs)
{
if (!smolv_Read4(bytes, bytesEnd, val))
return false;
if (!smolv_Read4(bytes, bytesEnd, val)) return false;
smolv_Write4(outSpirv, val);
}
}
Expand All @@ -1029,6 +1047,11 @@ bool smolv::Decode(const void* smolvData, size_t smolvSize, ByteArray& outSpirv)
}



// --------------------------------------------------------------------------------------------
// Calculating instruction count / space stats on SPIR-V and SMOL-V


bool smolv::InputStatsCalculate(smolv::InputStats* stats, const void* spirvData, size_t spirvSize)
{
if (!stats)
Expand Down Expand Up @@ -1154,10 +1177,8 @@ bool smolv::InputStatsCalculateSmol(smolv::InputStats* stats, const void* smolvD
}

// read the rest of the instruction words
if (op == SpvOpDecorate || op == SpvOpMemberDecorate)
if (op == SpvOpDecorate || op == SpvOpMemberDecorate || op == SpvOpVectorShuffle)
{
if (!smolv_ReadVarint(bytes, bytesEnd, val)) return false;
ioffs++;
for (; ioffs < instrLen; ++ioffs)
{
if (!smolv_ReadVarint(bytes, bytesEnd, val)) return false;
Expand Down

0 comments on commit 270f4f7

Please sign in to comment.