Skip to content

Commit

Permalink
Use built-in Read7BitEncodedInt
Browse files Browse the repository at this point in the history
* Remove ReaderExtensions.cs from ILCompiler.Ryujit
  • Loading branch information
PaulusParssinen committed Jan 31, 2024
1 parent 19ed77b commit 0413875
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ uint ReadTokenWithMemory(ref uint lastToken)
return reader.ReadUInt32();
}

uint current = reader.Read7BitEncodedUInt();
uint current = (uint)reader.Read7BitEncodedInt();
byte highByte = (byte)(current >> 24);
uint result;

Expand Down Expand Up @@ -116,7 +116,7 @@ private int ReadSmallInt()

private uint ReadSmallUInt()
{
return minified ? reader.Read7BitEncodedUInt() : reader.ReadUInt32();
return minified ? (uint)reader.Read7BitEncodedInt() : reader.ReadUInt32();
}
#endregion

Expand Down Expand Up @@ -327,7 +327,7 @@ IBC.MethodData ReadMethod()

if (minified)
{
uint firstBlockHitCount = reader.Read7BitEncodedUInt();
uint firstBlockHitCount = (uint)reader.Read7BitEncodedInt();
result.BasicBlocks.Add(new IBC.BasicBlockData { ILOffset = 0, ExecutionCount = firstBlockHitCount });
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,36 +39,6 @@ public static string ReadEncodedString(this BinaryReader reader, int length)

return new string(characters, 0, length - 1);
}

// BinaryReader.Read7BitEncodedInt is protected internal, so its
// implementation is duplicated here.
public static int Read7BitEncodedInt(this BinaryReader reader)
{
int result = 0;
int shift = 0;
byte current;
do
{
current = reader.ReadByte();

result |= (current & 0x7f) << shift;

shift += 7;
}
while ((shift <= 28) && ((current & 0x80) != 0));

if ((current & 0x80) != 0)
{
throw new InvalidDataException("Improperly encoded integer");
}

return result;
}

public static uint Read7BitEncodedUInt(this BinaryReader reader)
{
return (uint)reader.Read7BitEncodedInt();
}
}

public static class WriterExtensions
Expand All @@ -92,23 +62,5 @@ public static void WriteEncodedString(this BinaryWriter writer, string s)

writer.Write((short)'\0');
}

// BinaryWriter.Write7BitEncodedInt is protected internal, so its
// implementation is duplicated here.
public static void Write7BitEncodedInt(this BinaryWriter writer, uint i)
{
while (i > 0x7f)
{
writer.Write((byte)(i | 0x80));
i >>= 7;
}

writer.Write((byte)i);
}

public static void Write7BitEncodedInt(this BinaryWriter writer, int i)
{
writer.Write7BitEncodedInt((uint)i);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@

<Compile Include="..\ILCompiler.ReadyToRun\IBC\IBCDataModel.cs" Link="Pgo\IBCDataModel.cs" />
<Compile Include="..\ILCompiler.ReadyToRun\IBC\IBCProfileData.cs" Link="Pgo\IBCProfileData.cs" />
<Compile Include="..\ILCompiler.ReadyToRun\IBC\ReaderExtensions.cs" Link="Pgo\ReaderExtensions.cs" />
<Compile Include="..\ILCompiler.ReadyToRun\IBC\MIbcProfileParser.cs" Link="Pgo\MIbcProfileParser.cs" />

<Compile Include="..\ILCompiler.ReadyToRun\Compiler\ProfileData.cs" Link="Pgo\ProfileData.cs" />
Expand Down

0 comments on commit 0413875

Please sign in to comment.