thegu5
thegu5
CC#
Created by thegu5 on 6/13/2024 in #help
Float (signed) number comparisons compiled to unsigned version of instruction
Why does
public bool lteq(float a, float b) {
return a <= b;
}
public bool lteq(float a, float b) {
return a <= b;
}
compile to
IL_0000: ldarg.1
IL_0001: ldarg.2
IL_0002: cgt.un
IL_0004: ldc.i4.0
IL_0005: ceq
IL_0007: ret
IL_0000: ldarg.1
IL_0001: ldarg.2
IL_0002: cgt.un
IL_0004: ldc.i4.0
IL_0005: ceq
IL_0007: ret
whereas
public bool not(float a, float b) {
return !(a > b);
}
public bool not(float a, float b) {
return !(a > b);
}
compiles to the same thing but with cgt instead of cgt.un? Are these two expressions not equivalent? I'm also confused why it's using .un for two signed numbers that are ordered sharplab: https://sharplab.io/#v2:EYLgxg9gTgpgtADwGwBYA0AXEBLANgHwAEAmARgFgAoQgZgAIS6BhOgbyrs4fuAglzoA7CBgAUAM1wQAhhjrS0dSTLnAAlGw5dthAOx0AhKOl0AfHXUBuLZwC+N7hb4DcGGAEcJU2fMXKf6pqU2jr6JgA8ALwW1sFc9pS2QA
5 replies
CC#
Created by thegu5 on 6/11/2024 in #help
Debugging a ReflectionTypeLoadException
I'm using a tool called Cpp2IL to generate types like this in assemblies:
c#
// Cpp2IlInjected.WasmMethod.WasmMethod
using System;

[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
public sealed class WasmMethod : Attribute
{
public int Index;
}
c#
// Cpp2IlInjected.WasmMethod.WasmMethod
using System;

[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
public sealed class WasmMethod : Attribute
{
public int Index;
}
(il:)
.class public auto ansi sealed Cpp2IlInjected.WasmMethod.WasmMethod
extends [mscorlib]System.Attribute
{
.custom instance void [mscorlib]System.AttributeUsageAttribute::.ctor(valuetype [mscorlib]System.AttributeTargets) = (
01 00 40 00 00 00 01 00 54 02 0d 41 6c 6c 6f 77
4d 75 6c 74 69 70 6c 65 00
)
// Fields
.field public int32 Index

// Methods
.method public specialname rtspecialname
instance void .cctor () cil managed
{
// Method begins at RVA 0x8d77
// Header size: 1
// Code size: 7 (0x7)
.maxstack 8

IL_0000: ldarg.0
IL_0001: call instance void [mscorlib]System.Attribute::.ctor()
IL_0006: ret
} // end of method WasmMethod::.cctor

} // end of class Cpp2IlInjected.WasmMethod.WasmMethod
.class public auto ansi sealed Cpp2IlInjected.WasmMethod.WasmMethod
extends [mscorlib]System.Attribute
{
.custom instance void [mscorlib]System.AttributeUsageAttribute::.ctor(valuetype [mscorlib]System.AttributeTargets) = (
01 00 40 00 00 00 01 00 54 02 0d 41 6c 6c 6f 77
4d 75 6c 74 69 70 6c 65 00
)
// Fields
.field public int32 Index

// Methods
.method public specialname rtspecialname
instance void .cctor () cil managed
{
// Method begins at RVA 0x8d77
// Header size: 1
// Code size: 7 (0x7)
.maxstack 8

IL_0000: ldarg.0
IL_0001: call instance void [mscorlib]System.Attribute::.ctor()
IL_0006: ret
} // end of method WasmMethod::.cctor

} // end of class Cpp2IlInjected.WasmMethod.WasmMethod
everything looks valid after comparing it to output from https://sharplab.io - so, are there any ways I continue debugging this to figure out what went wrong with generation? (/is there anything incorrect that stands out?)
3 replies
CC#
Created by thegu5 on 6/5/2024 in #help
Error in Json Source Generation (ambiguous operator)
No description
8 replies