Skip to content
This repository was archived by the owner on Nov 1, 2020. It is now read-only.

Wasm: implement ckfinite#8097

Merged
jkotas merged 3 commits intodotnet:masterfrom
yowl:wasm-ckfinite
Apr 21, 2020
Merged

Wasm: implement ckfinite#8097
jkotas merged 3 commits intodotnet:masterfrom
yowl:wasm-ckfinite

Conversation

@yowl
Copy link
Copy Markdown
Contributor

@yowl yowl commented Apr 19, 2020

This follows #5405 now that we have exception support. Added all the test cases from the cases mentioned there, https://github.com/dotnet/coreclr/blob/9b0a9fd623/tests/src/JIT/IL_Conformance/Old/Base/ckfinite.il

Thanks @am11

WIP as depends on #8096, when I'll squash commits.

Closes #4549

@yowl
Copy link
Copy Markdown
Contributor Author

yowl commented Apr 20, 2020

Unfortunately the diff is confused as I've factored out some code into CreateAndThrowException but it's not picking that up well.

@yowl yowl changed the title WIP: Wasm: implement ckfinite Wasm: implement ckfinite Apr 20, 2020
builder.PositionAtEnd(throwBlock);
MetadataType nullRefType = _compilation.NodeFactory.TypeSystemContext.SystemModule.GetType("System", "NullReferenceException");

CreateAndThrowException(builder, "NullReferenceException", NullRefFunction);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The other codegens use ThrowHelpers for this purpose. E.g. there is ThrowHelpers.ThrowNullReferenceException.

Would it be make sense to do the same for WASM?

Copy link
Copy Markdown
Contributor Author

@yowl yowl Apr 20, 2020

Choose a reason for hiding this comment

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

Thanks, I notice there is no ThrowArithmeticException there, but there is ThrowOverflowException. Looking at some of the code that was used for this , https://github.com/dotnet/coreclr/blob/9b0a9fd623/tests/src/JIT/IL_Conformance/Old/Base/ckfinite.il, it is catching an OverflowException but if I look at https://docs.microsoft.com/en-us/dotnet/api/system.reflection.emit.opcodes.ckfinite?view=netcore-3.1 it says it should throw an ArithmeticException, which is the direction I went, but I'd need to add a helper method for that. Should I do that or use an OverflowException ?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

it says it should throw an ArithmeticException

OverflowException inherits from ArithmeticException so the docs are not wrong. It is ok to throw more specific exception that what the docs say. It may be nice to make the docs more accurate.

The behavior should match what CoreCLR does.

In any case, you can add these helpers as needed.

{
if (llvmCheckFunction.Handle == IntPtr.Zero)
{
llvmCheckFunction = Module.AddFunction("corert.throwckfinite" + size, LLVMTypeRef.CreateFunction(LLVMTypeRef.Void, new LLVMTypeRef[] { LLVMTypeRef.CreatePointer(LLVMTypeRef.Int8, 0), size == 32 ? LLVMTypeRef.Float : LLVMTypeRef.Double }, false));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Similar here - this can be a helper method in MathHelpers.

builder.PositionAtEnd(throwBlock);

HandleDirectCall(ctorDef, ctorDef.Signature, new StackEntry[] { exceptionEntry }, null, default(LLVMValueRef), 0, NullRefFunction.GetParam(0), builder, false, default(LLVMValueRef), ctorDef);
ThrowException(builder, "Internal.Runtime.CompilerHelpers", "MathHelpers", "ThrowCkFiniteExc", llvmCheckFunction);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I would just use the existing ThrowHelpers.ThrowOverflowException

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I hope I'm not sending you round in circles on this. I think I've got it right...

@jkotas jkotas merged commit 4f16563 into dotnet:master Apr 21, 2020
@yowl yowl deleted the wasm-ckfinite branch April 21, 2020 13:33
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement ckfinite opcode

2 participants