Skip to content

[mono][interp] implement interp bitcast intrinsics #115443

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

lewing
Copy link
Member

@lewing lewing commented May 10, 2025

based on #103915

Copy link
Contributor

Tagging subscribers to this area: @BrzVlad, @kotlarmilos
See info in area-owners.md if you want to be subscribed.

OPDEF(MINT_BITCAST_I4_R4, "bitcast.i4.r4", 3, 1, 1, MintOpNoArgs)
OPDEF(MINT_BITCAST_I8_R8, "bitcast.i8.r8", 3, 1, 1, MintOpNoArgs)
OPDEF(MINT_BITCAST_R4_I4, "bitcast.r4.i4", 3, 1, 1, MintOpNoArgs)
OPDEF(MINT_BITCAST_R8_I8, "bitcast.r8.i8", 3, 1, 1, MintOpNoArgs)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't understand why the type matters. Sounds like we should just emit MINT_MOV_4 or MINT_MOV_8.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really did just extract the changes from the linked pr and try to get them working as a first step. I think the intent was to make sure the jiterp sees the reinterpret but I'm not sure it matters in a practical sense?

cc @kg

@lewing
Copy link
Member Author

lewing commented May 12, 2025

[21:53:51] fail: [MONO] MemoryExtensions.IndexOfAnyInRange: Store local stack type mismatch 1 5
Error
    at Pc (http://127.0.0.1:49275/_framework/dotnet.runtime.js:3:171796)
    at wasm_trace_logger (http://127.0.0.1:49275/_framework/dotnet.native.wasm:wasm-function[159]:0xb288)
    at eglib_log_adapter (http://127.0.0.1:49275/_framework/dotnet.native.wasm:wasm-function[655]:0x455c6)
    at monoeg_g_logv_nofree (http://127.0.0.1:49275/_framework/dotnet.native.wasm:wasm-function[580]:0x436bb)
    at monoeg_g_log (http://127.0.0.1:49275/_framework/dotnet.native.wasm:wasm-function[582]:0x4377e)
    at store_local (http://127.0.0.1:49275/_framework/dotnet.native.wasm:wasm-function[365]:0x2b83e)
    at generate_code (http://127.0.0.1:49275/_framework/dotnet.native.wasm:wasm-function[362]:0x2365a)
    at interp_inline_method (http://127.0.0.1:49275/_framework/dotnet.native.wasm:wasm-function[417]:0x3c6bc)
    at interp_transform_call (http://127.0.0.1:49275/_framework/dotnet.native.wasm:wasm-function[373]:0x2cc80)
    at generate_code (http://127.0.0.1:49275/_framework/dotnet.native.wasm:wasm-function[362]:0x24a51)
    at mono_interp_transform_method (http://127.0.0.1:49275/_framework/dotnet.native.wasm:wasm-function[405]:0x30dfb)
    at tier_up_method (http://127.0.0.1:49275/_framework/dotnet.native.wasm:wasm-function[467]:0x401af)
    at mono_interp_exec_method (http://127.0.0.1:49275/_framework/dotnet.native.wasm:wasm-function[213]:0x1a62a)
    at interp_runtime_invoke (http://127.0.0.1:49275/_framework/dotnet.native.wasm:wasm-function[256]:0x1e1d4)
    at mono_jit_runtime_invoke (http://127.0.0.1:49275/_framework/dotnet.native.wasm:wasm-function[3236]:0xf9328)
    at do_runtime_invoke (http://127.0.0.1:49275/_framework/dotnet.native.wasm:wasm-function[2559]:0xcd12e)
    at mono_runtime_invoke_checked (http://127.0.0.1:49275/_framework/dotnet.native.wasm:wasm-function[2558]:0xcd0b3)
    at ves_icall_InternalInvoke_raw (http://127.0.0.1:49275/_framework/dotnet.native.wasm:wasm-function[1912]:0xa59a7)
    at do_icall (http://127.0.0.1:49275/_framework/dotnet.native.wasm:wasm-function[297]:0x20186)
    at do_icall_wrapper (http://127.0.0.1:49275/_framework/dotnet.native.wasm:wasm-function[222]:0x1d344)
    at mono_interp_exec_method (http://127.0.0.1:49275/_framework/dotnet.native.wasm:wasm-function[213]:0xf1ca)
    at interp_entry (http://127.0.0.1:49275/_framework/dotnet.native.wasm:wasm-function[290]:0x1fb83)
    at interp_entry_static_0 (http://127.0.0.1:49275/_framework/dotnet.native.wasm:wasm-function[326]:0x20d29)
    at wasm_native_to_interp_System_Private_CoreLib_System_Threading_ThreadPool_BackgroundJobHandler (http://127.0.0.1:49275/_framework/dotnet.native.wasm:wasm-function[185]:0xca2e)
    at mono_background_exec (http://127.0.0.1:49275/_framework/dotnet.native.wasm:wasm-function[797]:0x4a99e)
    at e.<computed> (http://127.0.0.1:49275/_framework/dotnet.runtime.js:3:183072)
    at Zo (http://127.0.0.1:49275/_framework/dotnet.runtime.js:3:56689)
    at callUserCallback (http://127.0.0.1:49275/_framework/dotnet.native.js:8:106543)
    at http://127.0.0.1:49275/_framework/dotnet.native.js:8:106811

@lewing
Copy link
Member Author

lewing commented Jun 2, 2025

this will also help reduce the impact of #116221

@lewing
Copy link
Member Author

lewing commented Jun 2, 2025

@kg @BrzVlad I'm happy to finish this up if I can get some guidance on the correct direction.

return FALSE;
}
g_assert (size < G_MAXUINT16);

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At this point we have the size. I imagine we should just do the following:

if (size <= 4)
    add_ins (MINT_MOV_4);
else if (size <= 8)
    add_ins (MINT_MOV_8);
else
    add_ins (MINT_MOV_VT);

td->sp--;
interp_add_ins (td, MINT_MOV_VT);
interp_ins_set_sreg (td->last_ins, td->sp [0].var);
push_type_vt (td, tto_klass, size);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The bug in your code is that here you are always pushing a VT type on the stack, where you could actually have a primitive type since you could cast a valuetype (of size 8) to an int64 for example. If you use the suggestion from above this should no longer be a problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants