Skip to content

Commit

Permalink
Issue-475 : Using the unsigned operations where it s available on Pri…
Browse files Browse the repository at this point in the history
…mitiveType
  • Loading branch information
PapisKang authored and ForNeVeR committed Jun 27, 2024
1 parent 1779a31 commit b32f8ae
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 2 deletions.
18 changes: 18 additions & 0 deletions Cesium.CodeGen.Tests/CodeGenArrayTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,24 @@ int main() {
}
""");

[Fact]
public Task SignedByteArrayTest() => DoTest(@"
int main() {
signed char x[1] = { -1 };
signed char y = x[0];
int z = (int)y;
return z;
}");

[Fact]
public Task UnSignedByteArrayTest2() => DoTest(@"
int main() {
unsigned char a[1] = { 255 };
unsigned char b = a[0];
int c = (int)b;
return c;
}");

[Fact]
public Task PointerAsArray() => DoTest("""
int main(void)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
System.Int32 <Module>::main()
Locals:
System.SByte* V_0
System.SByte V_1
System.Int32 V_2
IL_0000: ldc.i4.1
IL_0001: conv.u
IL_0002: localloc
IL_0004: stloc.0
IL_0005: ldsflda <ConstantPool>/<ConstantPoolItemType1> <ConstantPool>::ConstDataBuffer0
IL_000a: ldloc V_0
IL_000e: ldc.i4.1
IL_000f: conv.u
IL_0010: call System.Void Cesium.Runtime.RuntimeHelpers::InitializeCompound(System.Void*,System.Void*,System.UInt32)
IL_0015: ldloc.0
IL_0016: ldc.i4.0
IL_0017: conv.i
IL_0018: ldc.i4 1
IL_001d: mul
IL_001e: add
IL_001f: ldind.i1
IL_0020: stloc.1
IL_0021: ldloc.1
IL_0022: conv.i4
IL_0023: stloc.2
IL_0024: ldloc.2
IL_0025: ret

System.Int32 <Module>::<SyntheticEntrypoint>()
Locals:
System.Int32 V_0
IL_0000: call System.Int32 <Module>::main()
IL_0005: stloc.s V_0
IL_0007: ldloc.s V_0
IL_0009: call System.Void Cesium.Runtime.RuntimeHelpers::Exit(System.Int32)
IL_000e: ldloc.s V_0
IL_0010: ret
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
System.Int32 <Module>::main()
Locals:
System.Byte* V_0
System.Byte V_1
System.Int32 V_2
IL_0000: ldc.i4.1
IL_0001: conv.u
IL_0002: localloc
IL_0004: stloc.0
IL_0005: ldsflda <ConstantPool>/<ConstantPoolItemType1> <ConstantPool>::ConstDataBuffer0
IL_000a: ldloc V_0
IL_000e: ldc.i4.1
IL_000f: conv.u
IL_0010: call System.Void Cesium.Runtime.RuntimeHelpers::InitializeCompound(System.Void*,System.Void*,System.UInt32)
IL_0015: ldloc.0
IL_0016: ldc.i4.0
IL_0017: conv.i
IL_0018: ldc.i4 1
IL_001d: mul
IL_001e: add
IL_001f: ldind.u1
IL_0020: stloc.1
IL_0021: ldloc.1
IL_0022: conv.i4
IL_0023: stloc.2
IL_0024: ldloc.2
IL_0025: ret

System.Int32 <Module>::<SyntheticEntrypoint>()
Locals:
System.Int32 V_0
IL_0000: call System.Int32 <Module>::main()
IL_0005: stloc.s V_0
IL_0007: ldloc.s V_0
IL_0009: call System.Void Cesium.Runtime.RuntimeHelpers::Exit(System.Int32)
IL_000e: ldloc.s V_0
IL_0010: ret
4 changes: 2 additions & 2 deletions Cesium.CodeGen/Ir/Types/PrimitiveType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,9 @@ internal static class PrimitiveTypeInfo
{ PrimitiveTypeKind.SignedChar, (OpCodes.Ldind_I1, OpCodes.Stind_I1) },
{ PrimitiveTypeKind.UnsignedChar, (OpCodes.Ldind_U1, OpCodes.Stind_I1) },
{ PrimitiveTypeKind.Short, (OpCodes.Ldind_I2, OpCodes.Stind_I2) },
{ PrimitiveTypeKind.UnsignedShort, (OpCodes.Ldind_I2, OpCodes.Stind_I2) },
{ PrimitiveTypeKind.UnsignedShort, (OpCodes.Ldind_U2, OpCodes.Stind_I2) },
{ PrimitiveTypeKind.Int, (OpCodes.Ldind_I4, OpCodes.Stind_I4) },
{ PrimitiveTypeKind.UnsignedInt, (OpCodes.Ldind_I4, OpCodes.Stind_I4) },
{ PrimitiveTypeKind.UnsignedInt, (OpCodes.Ldind_U4, OpCodes.Stind_I4) },
{ PrimitiveTypeKind.Float, (OpCodes.Ldind_R4, OpCodes.Stind_R4) },
{ PrimitiveTypeKind.Long, (OpCodes.Ldind_I8, OpCodes.Stind_I8) },
{ PrimitiveTypeKind.UnsignedLong, (OpCodes.Ldind_I8, OpCodes.Stind_I8) },
Expand Down

0 comments on commit b32f8ae

Please sign in to comment.