IL2CPU icon indicating copy to clipboard operation
IL2CPU copied to clipboard

Add uint support to Conv_R4

Open retrievaaaa opened this issue 4 years ago • 3 comments

Area of Cosmos - What area of Cosmos are we dealing with?

IL2CPU

Expected Behaviour - What do you think that should happen?

Should compile fine

Actual Behaviour - What unexpectedly happens?

Compilation fails

2>Detecting fields for type 'IL2CPU.Debug.Symbols.Method'
2>IL2CPU : error : Exception: System.Exception: Error compiling method 'SystemInt32cs_ttfTTFstbtt__run_charstringcs_ttfstbtt_fontinfopointerSystemInt32cs_ttfTTFstbtt__csctxpointer': System.NotSupportedException: Specified method is not supported.
2>   at Cosmos.IL2CPU.X86.IL.Conv_R4.Execute(Il2cpuMethodInfo aMethod, ILOpCode aOpCode) in C:\Users\FrancescoDettling\source\repos\Cosmos\IL2CPU\source\Cosmos.IL2CPU\IL\Conv_R4.cs:line 37
2>   at Cosmos.IL2CPU.AppAssembler.EmitInstructions(Il2cpuMethodInfo aMethod, List`1 aCurrentGroup, Boolean& emitINT3) in C:\Users\FrancescoDettling\source\repos\Cosmos\IL2CPU\source\Cosmos.IL2CPU\AppAssembler.cs:line 632
2>   at Cosmos.IL2CPU.AppAssembler.ProcessMethod(Il2cpuMethodInfo aMethod, List`1 aOpCodes) in C:\Users\FrancescoDettling\source\repos\Cosmos\IL2CPU\source\Cosmos.IL2CPU\AppAssembler.cs:line 476
2> ---> System.NotSupportedException: Specified method is not supported.
2>   at Cosmos.IL2CPU.X86.IL.Conv_R4.Execute(Il2cpuMethodInfo aMethod, ILOpCode aOpCode) in C:\Users\FrancescoDettling\source\repos\Cosmos\IL2CPU\source\Cosmos.IL2CPU\IL\Conv_R4.cs:line 37
2>   at Cosmos.IL2CPU.AppAssembler.EmitInstructions(Il2cpuMethodInfo aMethod, List`1 aCurrentGroup, Boolean& emitINT3) in C:\Users\FrancescoDettling\source\repos\Cosmos\IL2CPU\source\Cosmos.IL2CPU\AppAssembler.cs:line 632
2>   at Cosmos.IL2CPU.AppAssembler.ProcessMethod(Il2cpuMethodInfo aMethod, List`1 aOpCodes) in C:\Users\FrancescoDettling\source\repos\Cosmos\IL2CPU\source\Cosmos.IL2CPU\AppAssembler.cs:line 476
2>   --- End of inner exception stack trace ---
2>   at Cosmos.IL2CPU.AppAssembler.ProcessMethod(Il2cpuMethodInfo aMethod, List`1 aOpCodes) in C:\Users\FrancescoDettling\source\repos\Cosmos\IL2CPU\source\Cosmos.IL2CPU\AppAssembler.cs:line 482
2>   at Cosmos.IL2CPU.ILScanner.Assemble() in C:\Users\FrancescoDettling\source\repos\Cosmos\IL2CPU\source\Cosmos.IL2CPU\ILScanner.cs:line 1044
2>   at Cosmos.IL2CPU.ILScanner.Execute(MethodBase aStartMethod, IEnumerable`1 plugsAssemblies) in C:\Users\FrancescoDettling\source\repos\Cosmos\IL2CPU\source\Cosmos.IL2CPU\ILScanner.cs:line 278
2>   at Cosmos.IL2CPU.CompilerEngine.Execute() in C:\Users\FrancescoDettling\source\repos\Cosmos\IL2CPU\source\Cosmos.IL2CPU\CompilerEngine.cs:line 222

Reproduction - How did you get this error to appear?

Clone this repository: https://github.com/GoldenretriverYT/CosmosTTF/tree/implement-new-ttf Then try to add it to your Cosmos OS. The method causing this error is stbtt__run_charstring in NewTTFLib.cs

Version - Were you using the User Kit or Dev Kit? And what User Kit version or Dev Kit commit (Cosmos, IL2CPU, X#)?

Latest DevKit

retrievaaaa avatar Aug 22 '22 07:08 retrievaaaa

After further inspection, this seems to be caused by this: https://github.com/CosmosOS/IL2CPU/blob/12172758af82ba2c9673fcd1688c5a3d7aa8a97a/source/Cosmos.IL2CPU/IL/Conv_R4.cs

After checking the generated DLLs. I can confirm that conv.r4 is used in the DLL, with int32 and uint32.

retrievaaaa avatar Aug 22 '22 07:08 retrievaaaa

This can be fixed by doing

int temp = (int)stbtt__cff_int(&b);
f = temp;

instead of

f = (Int32)stbtt__cff_int(&b);

retrievaaaa avatar Aug 22 '22 07:08 retrievaaaa

Its probably cause Roslyn optimized out the cast, because it believes uint32 is directly castable to float (which is true in regular C#) so I believe support for that should be added.

retrievaaaa avatar Aug 23 '22 06:08 retrievaaaa