mirror of
https://git.naxdy.org/Mirror/Ryujinx.git
synced 2025-02-21 00:23:36 +00:00
- Dictionary for lookups of type declarations, constants, extinst - LiteralInteger internal data format -> ushort - Deterministic HashCode implementation to avoid spirv result not being the same between runs - Inline operand list instead of List<T>, falls back to array if many operands. (large performance boost) TODO: improve instruction allocation, structured program creator, ssa?
51 lines
1.3 KiB
C#
51 lines
1.3 KiB
C#
using System;
|
|
using System.IO;
|
|
using System.Text;
|
|
|
|
namespace Spv.Generator
|
|
{
|
|
public class LiteralString : Operand, IEquatable<LiteralString>
|
|
{
|
|
public OperandType Type => OperandType.String;
|
|
|
|
private string _value;
|
|
|
|
public LiteralString(string value)
|
|
{
|
|
_value = value;
|
|
}
|
|
|
|
public ushort WordCount => (ushort)(_value.Length / 4 + 1);
|
|
|
|
public void WriteOperand(BinaryWriter writer)
|
|
{
|
|
writer.Write(_value.AsSpan());
|
|
|
|
int paddingSize = 4 - (Encoding.ASCII.GetByteCount(_value) % 4);
|
|
|
|
Span<byte> padding = stackalloc byte[paddingSize];
|
|
|
|
writer.Write(padding);
|
|
}
|
|
|
|
public override bool Equals(object obj)
|
|
{
|
|
return obj is LiteralString literalString && Equals(literalString);
|
|
}
|
|
|
|
public bool Equals(LiteralString cmpObj)
|
|
{
|
|
return Type == cmpObj.Type && _value.Equals(cmpObj._value);
|
|
}
|
|
|
|
public override int GetHashCode()
|
|
{
|
|
return DeterministicHashCode.Combine(Type, DeterministicHashCode.GetHashCode(_value));
|
|
}
|
|
|
|
public bool Equals(Operand obj)
|
|
{
|
|
return obj is LiteralString literalString && Equals(literalString);
|
|
}
|
|
}
|
|
}
|