D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 12868 - core.simd.int4 equality
Summary: core.simd.int4 equality
Status: NEW
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P4 enhancement
Assignee: No Owner
URL:
Keywords: SIMD
Depends on:
Blocks:
 
Reported: 2014-06-06 17:18 UTC by bearophile_hugs
Modified: 2024-12-13 18:21 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description bearophile_hugs 2014-06-06 17:18:27 UTC
Value equality is quite important for the usability of a type. This code is currently refused:

void main() {
    import core.simd: int4;
    import std.algorithm: uniq;
    int4[] data = [[1, 2, 3, 4], [1, 2, 3, 4], [10, 20, 30, 40]];
    data.uniq;
}



dmd 2.066alpha gives:

test.d(5): Error: template std.algorithm.uniq does not match any function template declaration. Candidates are:
...\ldc2\bin/../import\std\algorithm.d(3346):        std.algorithm.uniq(alias pred = "a == b", Range)(Range r) if (isInputRange!Range && is(typeof(binaryFun!pred(r.front, r.front)) == bool))
test.d(5): Error: template std.algorithm.uniq(alias pred = "a == b", Range)(Range r) if (isInputRange!Range && is(typeof(binaryFun!pred(r.front, r.front)) == bool)) cannot deduce template function from argument types !()(__vector(int[4])[])



A workaround is to call .array, but this is quite inefficient code:

void main() {
    import core.simd: int4;
    import std.algorithm: uniq;
    int4[] data = [[1, 2, 3, 4], [1, 2, 3, 4], [10, 20, 30, 40]];
    data.uniq!q{ a.array == b.array };
}


There are two different possible equalities among SIMD values: the first returns a bool normally, and the second returns a SIMD value that contains N booleans represented as zero/notzero values. The first can be computed with a xor followed by a sum + shuffle + sum + shuffle ... for log2(N) cycles.

I think the first equality operation should be built-in. 

An alternative is to have a function like this but I think it's not a large improvement because it has to perform the same operations as a built-in equality:

void main() {
    import core.simd: int4;
    import std.algorithm: uniq;
    int4[] data = [[1, 2, 3, 4], [1, 2, 3, 4], [10, 20, 30, 40]];
    data.uniq!q{ simdEquality(a, b) };
}



But such simdEquality function is OK for the second kind of SIMD equality, that returns a SIMD of booleans.
Comment 1 dlangBugzillaToGithub 2024-12-13 18:21:19 UTC
THIS ISSUE HAS BEEN MOVED TO GITHUB

https://github.com/dlang/dmd/issues/18835

DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB