Skip to content
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

fix Issue 17720 - Wrong code using vector extensions with different types #7065

Merged
merged 1 commit into from
Jul 31, 2020

Conversation

ibuclaw
Copy link
Member

@ibuclaw ibuclaw commented Aug 6, 2017

No description provided.

@dlang-bot
Copy link
Contributor

dlang-bot commented Aug 6, 2017

Thanks for your pull request, @ibuclaw!

Bugzilla references

Auto-close Bugzilla Severity Description
17720 major Wrong code using vector extensions with different types

Testing this PR locally

If you don't have a local development environment setup, you can use Digger to test this PR:

dub run digger -- build "master + dmd#7065"

Copy link
Member

@PetarKirov PetarKirov left a comment

Choose a reason for hiding this comment

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

Looks good to me.

@ibuclaw
Copy link
Member Author

ibuclaw commented Aug 7, 2017

Hmm, I did not think this one entirely through. Fixed it up with more extensive test, however it looks like DMD's __simd depends on implicitly being able to convert void16 any other vector type of the same size.

Not sure if I should bite my lip and allow this. Maybe @WalterBright might want to chime in as its his intrinsic.

@WalterBright
Copy link
Member

It's failing the autotester because of checkwhitespace.

I'm not sure I totally understand your comment, but you can convert an array of ints to an array of void and then to an array of float, and you'll get ints painted to floats. This is allowed behavior.

@WalterBright
Copy link
Member

When fixing a bugzilla issue, please put the PR URL in the bugzilla issue, so somebody else doesn't waste time trying to fix it because he's ignorant there is an extant fix already. I already did it for this one.

@ibuclaw
Copy link
Member Author

ibuclaw commented Aug 8, 2017

I'm not sure I totally understand your comment, but you can convert an array of ints to an array of void and then to an array of float, and you'll get ints painted to floats. This is allowed behavior.

__simd accepts and returns a void16. So it expects that any vector is implicitly convertible to and from void.

My original intent here is to make vectors be treated less like an arithmetic type and more like a static/dynamic array. However given the current __simd usage, they need to be a even more relaxed than both.

float[4] sf;
void[16] sv = void;
sv = sf;  // OK
sf = sv;  // Error cannot implictly convert void[16] to float[].

float[] af;
void[] av;
av = af;  // OK
af = av;  // Error cannot implicitly convert void[] to float[].

I was intending to push towards Error cannot implicitly convert void16 to float4.

@ibuclaw
Copy link
Member Author

ibuclaw commented Aug 8, 2017

You can see the error I'm talking about in the autotester now.

@ibuclaw
Copy link
Member Author

ibuclaw commented Aug 9, 2017

@TurkeyMan - maybe you could give a short sentence on whether allowing implicit conversion from void vector to any other vector type seems reasonable.

@TurkeyMan
Copy link
Contributor

How would you argue in favour?
Practically it can be convenient in a lot of typical simd code, but I kinda feel like it's antithetical to D in general. It's certainly not @safe ;)
I reckon it'd be better to put a bunch of overloads/wrappers in core.simd to match return types to the argument types like most C++ simd headers do?

@ibuclaw
Copy link
Member Author

ibuclaw commented Aug 13, 2017

Added overrides in dlang/druntime#1900 - however using one of them exposes an ICE, others seem fine.

@ibuclaw
Copy link
Member Author

ibuclaw commented Oct 10, 2017

Blocked by druntime and dmd bug for the moment (this patch is already in gdc, so I have a vested interest to see that someone fixes it).

@ibuclaw ibuclaw added Merge:Blocked and removed Review:Blocking Other Work review and pulling should be a priority labels Jul 11, 2020
@ibuclaw
Copy link
Member Author

ibuclaw commented Jul 11, 2020

All checks pass, I'll leave it up to the RM @thewilsonator to decide if any action is required for forcing casts when using __simd().

src/dmd/mtype.d Outdated Show resolved Hide resolved
@ibuclaw
Copy link
Member Author

ibuclaw commented Jul 15, 2020

Added changelog entry.

@ibuclaw
Copy link
Member Author

ibuclaw commented Jul 15, 2020

Github UI doesn't seem to be updating to reveal the new commit...

@ibuclaw ibuclaw force-pushed the issue17720 branch 2 times, most recently from ed1ac16 to 429788b Compare July 15, 2020 20:59
@ghost
Copy link

ghost commented Jul 25, 2020

Why dont you choose to start a deprecation ?

@ibuclaw
Copy link
Member Author

ibuclaw commented Jul 25, 2020

Why dont you choose to start a deprecation ?

GDC has been running with this for as long as the bug report has been open.

Actually I'd like to make this even more restricted. Implicit casting between shared and non-shared is still allowed, but shouldn't be. However that will really begin to break code, so will need a deprecation.

This just makes an error code that is broken anyway.

@ghost
Copy link

ghost commented Jul 25, 2020

So the problem is just that the PR has been forgotten but it's good to merge, right ?

@ghost ghost added Merge:72h no objection -> merge The PR will be merged if there are no objections raised. and removed Merge:Blocked labels Jul 25, 2020
@ibuclaw
Copy link
Member Author

ibuclaw commented Jul 26, 2020

So the problem is just that the PR has been forgotten but it's good to merge, right ?

Pretty much. The only blocking part was the dmd intrinsic __simd, which has the signature void16(void16, void16). This is a dumb intrinsic, and new overrides should be added to deal with both allowing AVX instructions and returning a result other than void (eg: float4)

@ghost ghost force-pushed the issue17720 branch from 429788b to 04ce2f4 Compare July 31, 2020 06:04
@ghost ghost added the Merge:auto-merge label Jul 31, 2020
@ghost ghost force-pushed the issue17720 branch from 04ce2f4 to 6b7e394 Compare July 31, 2020 06:44
@ghost ghost added the Merge:auto-merge label Jul 31, 2020
@ghost ghost force-pushed the issue17720 branch from 6b7e394 to 0aeef22 Compare July 31, 2020 08:47
@ghost ghost added the Merge:auto-merge label Jul 31, 2020
@dlang-bot dlang-bot merged commit 701b1d2 into dlang:master Jul 31, 2020
@ibuclaw ibuclaw deleted the issue17720 branch July 31, 2020 16:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Compiler:GDC Gnu D Compiler Merge:auto-merge Merge:72h no objection -> merge The PR will be merged if there are no objections raised. Severity:Bug Fix
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants