From: Iain Buclaw Date: Mon, 31 Aug 2020 20:42:10 +0000 (+0200) Subject: d: __vectors unsupported in hardware should be rejected at compile-time. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=f0a3bab43fda3084eaf1bdaac58936757f30ea35;p=gcc.git d: __vectors unsupported in hardware should be rejected at compile-time. gcc/d/ChangeLog: PR d/96869 * d-builtins.cc (build_frontend_type): Don't expose intrinsics that use unsupported vector types. * d-target.cc (Target::isVectorTypeSupported): Restrict to supporting only if TARGET_VECTOR_MODE_SUPPORTED_P is true. Don't allow complex or boolean vector types. gcc/testsuite/ChangeLog: PR d/96869 * gdc.dg/simd.d: Removed. * gdc.dg/cast1.d: New test. * gdc.dg/gdc213.d: Compile with target vect_sizes_16B_8B. * gdc.dg/gdc284.d: Likewise. * gdc.dg/gdc67.d: Likewise. * gdc.dg/pr96869.d: New test. * gdc.dg/simd1.d: New test. * gdc.dg/simd10447.d: New test. * gdc.dg/simd12776.d: New test. * gdc.dg/simd13841.d: New test. * gdc.dg/simd13927.d: New test. * gdc.dg/simd15123.d: New test. * gdc.dg/simd15144.d: New test. * gdc.dg/simd16087.d: New test. * gdc.dg/simd16697.d: New test. * gdc.dg/simd17237.d: New test. * gdc.dg/simd17695.d: New test. * gdc.dg/simd17720a.d: New test. * gdc.dg/simd17720b.d: New test. * gdc.dg/simd19224.d: New test. * gdc.dg/simd19627.d: New test. * gdc.dg/simd19628.d: New test. * gdc.dg/simd19629.d: New test. * gdc.dg/simd19630.d: New test. * gdc.dg/simd2a.d: New test. * gdc.dg/simd2b.d: New test. * gdc.dg/simd2c.d: New test. * gdc.dg/simd2d.d: New test. * gdc.dg/simd2e.d: New test. * gdc.dg/simd2f.d: New test. * gdc.dg/simd2g.d: New test. * gdc.dg/simd2h.d: New test. * gdc.dg/simd2i.d: New test. * gdc.dg/simd2j.d: New test. * gdc.dg/simd7951.d: New test. * gdc.dg/torture/array2.d: New test. * gdc.dg/torture/array3.d: New test. * gdc.dg/torture/simd16488a.d: New test. * gdc.dg/torture/simd16488b.d: New test. * gdc.dg/torture/simd16703.d: New test. * gdc.dg/torture/simd19223.d: New test. * gdc.dg/torture/simd19607.d: New test. * gdc.dg/torture/simd3.d: New test. * gdc.dg/torture/simd4.d: New test. * gdc.dg/torture/simd7411.d: New test. * gdc.dg/torture/simd7413a.d: New test. * gdc.dg/torture/simd7413b.d: New test. * gdc.dg/torture/simd7414.d: New test. * gdc.dg/torture/simd9200.d: New test. * gdc.dg/torture/simd9304.d: New test. * gdc.dg/torture/simd9449.d: New test. * gdc.dg/torture/simd9910.d: New test. --- diff --git a/gcc/d/d-builtins.cc b/gcc/d/d-builtins.cc index 6272ab83a76..e3d7adc2deb 100644 --- a/gcc/d/d-builtins.cc +++ b/gcc/d/d-builtins.cc @@ -208,7 +208,7 @@ build_frontend_type (tree type) break; dtype = dtype->sarrayOf (nunits)->addMod (mod); - if (dtype->nextOf ()->isTypeBasic () == NULL) + if (target.isVectorTypeSupported (dtype->size (), dtype->nextOf ())) break; dtype = (TypeVector::create (dtype))->addMod (mod); diff --git a/gcc/d/d-target.cc b/gcc/d/d-target.cc index ea425ad897c..4a38cca56b4 100644 --- a/gcc/d/d-target.cc +++ b/gcc/d/d-target.cc @@ -247,16 +247,17 @@ Target::isVectorTypeSupported (int sz, Type *type) if (type == Type::tvoid) type = Type::tuns8; - /* No support for non-trivial types. */ - if (!type->isTypeBasic ()) + /* No support for non-trivial types, complex types, or booleans. */ + if (!type->isTypeBasic () || type->iscomplex () || type->ty == Tbool) return 3; - /* If there is no hardware support, check if we can safely emulate it. */ - tree ctype = build_ctype (type); - machine_mode mode = TYPE_MODE (ctype); + /* In [simd/vector extensions], which vector types are supported depends on + the target. The implementation is expected to only support the vector + types that are implemented in the target's hardware. */ + unsigned HOST_WIDE_INT nunits = sz / type->size (); + tree ctype = build_vector_type (build_ctype (type), nunits); - if (!targetm.vector_mode_supported_p (mode) - && !targetm.scalar_mode_supported_p (as_a (mode))) + if (!targetm.vector_mode_supported_p (TYPE_MODE (ctype))) return 3; return 0; diff --git a/gcc/testsuite/gdc.dg/cast1.d b/gcc/testsuite/gdc.dg/cast1.d new file mode 100644 index 00000000000..3fe7d99c031 --- /dev/null +++ b/gcc/testsuite/gdc.dg/cast1.d @@ -0,0 +1,7 @@ +// { dg-do compile } +float bug8060(float x) +{ + int i = *cast(int*)&x; + ++i; + return *cast(float*)&i; +} diff --git a/gcc/testsuite/gdc.dg/gdc213.d b/gcc/testsuite/gdc.dg/gdc213.d index 11e5c63f9e3..c5bd1df8dbc 100644 --- a/gcc/testsuite/gdc.dg/gdc213.d +++ b/gcc/testsuite/gdc.dg/gdc213.d @@ -1,6 +1,6 @@ // https://bugzilla.gdcproject.org/show_bug.cgi?id=213 -// { dg-options "-Wno-psabi" } -// { dg-do compile } +// { dg-additional-options "-mavx" { target avx_runtime } } +// { dg-do compile { target { avx_runtime || vect_sizes_16B_8B } } } import core.simd; diff --git a/gcc/testsuite/gdc.dg/gdc284.d b/gcc/testsuite/gdc.dg/gdc284.d index c8854287911..0c39217a37b 100644 --- a/gcc/testsuite/gdc.dg/gdc284.d +++ b/gcc/testsuite/gdc.dg/gdc284.d @@ -1,6 +1,6 @@ // https://bugzilla.gdcproject.org/show_bug.cgi?id=284 -// { dg-options "-Wno-psabi" } -// { dg-do compile } +// { dg-additional-options "-mavx" { target avx_runtime } } +// { dg-do compile { target { avx_runtime || vect_sizes_16B_8B } } } alias v284 = __vector(int[2]); diff --git a/gcc/testsuite/gdc.dg/gdc67.d b/gcc/testsuite/gdc.dg/gdc67.d index 9289abfadc7..a309a4bff5f 100644 --- a/gcc/testsuite/gdc.dg/gdc67.d +++ b/gcc/testsuite/gdc.dg/gdc67.d @@ -1,4 +1,5 @@ // https://bugzilla.gdcproject.org/show_bug.cgi?id=67 -// { dg-do compile } +// { dg-additional-options "-mavx" { target avx_runtime } } +// { dg-do compile { target { avx_runtime || vect_sizes_16B_8B } } } __vector(float[4])[2] d; // ICE diff --git a/gcc/testsuite/gdc.dg/pr96869.d b/gcc/testsuite/gdc.dg/pr96869.d new file mode 100644 index 00000000000..c4ace30a546 --- /dev/null +++ b/gcc/testsuite/gdc.dg/pr96869.d @@ -0,0 +1,32 @@ +// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96869 +// { dg-do compile } + +__vector(float[0]) var01; +// { dg-error "0 byte vector type __vector\\\(float\\\[0\\\]\\\) is not supported on this platform" "" { target *-*-* } .-1 } +__vector(float[3]) var02; +// { dg-error "12 byte vector type __vector\\\(float\\\[3\\\]\\\) is not supported on this platform" "" { target *-*-* } .-1 } +__vector(float[][4]) var03; +// { dg-error "vector type __vector\\\(float\\\[\\\]\\\[4\\\]\\\) is not supported on this platform" "" { target *-*-* } .-1 } +__vector(float[4][4]) var04; +// { dg-error "vector type __vector\\\(float\\\[4\\\]\\\[4\\\]\\\) is not supported on this platform" "" { target *-*-* } .-1 } +__vector(float[float][4]) var05; +// { dg-error "vector type __vector\\\(float\\\[float\\\]\\\[4\\\]\\\) is not supported on this platform" "" { target *-*-* } .-1 } +__vector(float function()[4]) var06; +// { dg-error "vector type __vector\\\(float function\\\(\\\)\\\[4\\\]\\\) is not supported on this platform" "" { target *-*-* } .-1 } +__vector(float delegate()[4]) var07; +// { dg-error "vector type __vector\\\(float delegate\\\(\\\)\\\[4\\\]\\\) is not supported on this platform" "" { target *-*-* } .-1 } +enum E { a, b, c } +__vector(E[4]) var08; +// { dg-error "vector type __vector\\\(E\\\[4\\\]\\\) is not supported on this platform" "" { target *-*-* } .-1 } +struct S { float a; } +__vector(S[4]) var09; +// { dg-error "vector type __vector\\\(S\\\[4\\\]\\\) is not supported on this platform" "" { target *-*-* } .-1 } +class C { float a; } +__vector(C[4]) var10; +// { dg-error "vector type __vector\\\(C\\\[4\\\]\\\) is not supported on this platform" "" { target *-*-* } .-1 } +__vector(cfloat[4]) var11; +// { dg-error "vector type __vector\\\(cfloat\\\[4\\\]\\\) is not supported on this platform" "" { target *-*-* } .-1 } +__vector(bool[4]) var12; +// { dg-error "vector type __vector\\\(bool\\\[4\\\]\\\) is not supported on this platform" "" { target *-*-* } .-1 } +__vector(real[128]) var13; +// { dg-error "vector type __vector\\\(real\\\[128\\\]\\\) is not supported on this platform" "" { target *-*-* } .-1 } diff --git a/gcc/testsuite/gdc.dg/simd.d b/gcc/testsuite/gdc.dg/simd.d deleted file mode 100644 index 40d5b5700c3..00000000000 --- a/gcc/testsuite/gdc.dg/simd.d +++ /dev/null @@ -1,1947 +0,0 @@ -// { dg-options "-Wno-psabi" } -// { dg-do run { target hw } } -import core.simd; -import core.stdc.string; - -alias TypeTuple(T...) = T; - -/*****************************************/ -// https://issues.dlang.org/show_bug.cgi?id=16087 - -static assert(void8.sizeof == 8); -static assert(float2.sizeof == 8); -static assert(byte8.sizeof == 8); -static assert(ubyte8.sizeof == 8); -static assert(short4.sizeof == 8); -static assert(ushort4.sizeof == 8); -static assert(int2.sizeof == 8); -static assert(uint2.sizeof == 8); - -static assert(void16.alignof == 16); -static assert(double2.alignof == 16); -static assert(float4.alignof == 16); -static assert(byte16.alignof == 16); -static assert(ubyte16.alignof == 16); -static assert(short8.alignof == 16); -static assert(ushort8.alignof == 16); -static assert(int4.alignof == 16); -static assert(uint4.alignof == 16); -static assert(long2.alignof == 16); -static assert(ulong2.alignof == 16); - -static assert(void16.sizeof == 16); -static assert(double2.sizeof == 16); -static assert(float4.sizeof == 16); -static assert(byte16.sizeof == 16); -static assert(ubyte16.sizeof == 16); -static assert(short8.sizeof == 16); -static assert(ushort8.sizeof == 16); -static assert(int4.sizeof == 16); -static assert(uint4.sizeof == 16); -static assert(long2.sizeof == 16); -static assert(ulong2.sizeof == 16); - -static assert(void32.alignof == 32); -static assert(double4.alignof == 32); -static assert(float8.alignof == 32); -static assert(byte32.alignof == 32); -static assert(ubyte32.alignof == 32); -static assert(short16.alignof == 32); -static assert(ushort16.alignof == 32); -static assert(int8.alignof == 32); -static assert(uint8.alignof == 32); -static assert(long4.alignof == 32); -static assert(ulong4.alignof == 32); - -static assert(void32.sizeof == 32); -static assert(double4.sizeof == 32); -static assert(float8.sizeof == 32); -static assert(byte32.sizeof == 32); -static assert(ubyte32.sizeof == 32); -static assert(short16.sizeof == 32); -static assert(ushort16.sizeof == 32); -static assert(int8.sizeof == 32); -static assert(uint8.sizeof == 32); -static assert(long4.sizeof == 32); -static assert(ulong4.sizeof == 32); - -/*****************************************/ - -void test1() -{ - void16 v1 = void,v2 = void; - byte16 b; - v2 = b; - v1 = v2; - static assert(!__traits(compiles, v1 + v2)); - static assert(!__traits(compiles, v1 - v2)); - static assert(!__traits(compiles, v1 * v2)); - static assert(!__traits(compiles, v1 / v2)); - static assert(!__traits(compiles, v1 % v2)); - static assert(!__traits(compiles, v1 & v2)); - static assert(!__traits(compiles, v1 | v2)); - static assert(!__traits(compiles, v1 ^ v2)); - static assert(!__traits(compiles, v1 ~ v2)); - static assert(!__traits(compiles, v1 ^^ v2)); - static assert(!__traits(compiles, v1 is v2)); - static assert(!__traits(compiles, v1 !is v2)); - static assert(!__traits(compiles, v1 == v2)); - static assert(!__traits(compiles, v1 != v2)); - static assert(!__traits(compiles, v1 < v2)); - static assert(!__traits(compiles, v1 > v2)); - static assert(!__traits(compiles, v1 <= v2)); - static assert(!__traits(compiles, v1 >= v2)); - static assert(!__traits(compiles, v1 <> v2)); - static assert(!__traits(compiles, v1 !< v2)); - static assert(!__traits(compiles, v1 !> v2)); - static assert(!__traits(compiles, v1 !<> v2)); - static assert(!__traits(compiles, v1 <>= v2)); - static assert(!__traits(compiles, v1 !<= v2)); - static assert(!__traits(compiles, v1 !>= v2)); - static assert(!__traits(compiles, v1 !<>= v2)); - static assert(!__traits(compiles, v1 << 1)); - static assert(!__traits(compiles, v1 >> 1)); - static assert(!__traits(compiles, v1 >>> 1)); - static assert(!__traits(compiles, v1 && v2)); - static assert(!__traits(compiles, v1 || v2)); - static assert(!__traits(compiles, ~v1)); - static assert(!__traits(compiles, -v1)); - static assert(!__traits(compiles, +v1)); - static assert(!__traits(compiles, !v1)); - - static assert(!__traits(compiles, v1 += v2)); - static assert(!__traits(compiles, v1 -= v2)); - static assert(!__traits(compiles, v1 *= v2)); - static assert(!__traits(compiles, v1 /= v2)); - static assert(!__traits(compiles, v1 %= v2)); - static assert(!__traits(compiles, v1 &= v2)); - static assert(!__traits(compiles, v1 |= v2)); - static assert(!__traits(compiles, v1 ^= v2)); - static assert(!__traits(compiles, v1 ~= v2)); - static assert(!__traits(compiles, v1 ^^= v2)); - static assert(!__traits(compiles, v1 <<= 1)); - static assert(!__traits(compiles, v1 >>= 1)); - static assert(!__traits(compiles, v1 >>>= 1)); - - // A cast from vector to non-vector is allowed only when the target is same size Tsarray. - static assert(!__traits(compiles, cast(byte)v1)); // 1byte - static assert(!__traits(compiles, cast(short)v1)); // 2byte - static assert(!__traits(compiles, cast(int)v1)); // 4byte - static assert(!__traits(compiles, cast(long)v1)); // 8byte - static assert(!__traits(compiles, cast(float)v1)); // 4byte - static assert(!__traits(compiles, cast(double)v1)); // 8byte - static assert(!__traits(compiles, cast(int[2])v1)); // 8byte Tsarray - static assert( __traits(compiles, cast(int[4])v1)); // 16byte Tsarray, OK - static assert( __traits(compiles, cast(long[2])v1)); // 16byte Tsarray, OK -} - -/*****************************************/ - -void test2() -{ - byte16 v1, v2 = 1, v3 = 1; - v1 = v2; - v1 = v2 + v3; - v1 = v2 - v3; - v1 = v2 * v3; - v1 = v2 / v3; - v1 = v2 % v3; - v1 = v2 & v3; - v1 = v2 | v3; - v1 = v2 ^ v3; - static assert(!__traits(compiles, v1 ~ v2)); - static assert(!__traits(compiles, v1 ^^ v2)); - static assert(!__traits(compiles, v1 is v2)); - static assert(!__traits(compiles, v1 !is v2)); - static assert(!__traits(compiles, v1 == v2)); - static assert(!__traits(compiles, v1 != v2)); - static assert(!__traits(compiles, v1 < v2)); - static assert(!__traits(compiles, v1 > v2)); - static assert(!__traits(compiles, v1 <= v2)); - static assert(!__traits(compiles, v1 >= v2)); - static assert(!__traits(compiles, v1 <> v2)); - static assert(!__traits(compiles, v1 !< v2)); - static assert(!__traits(compiles, v1 !> v2)); - static assert(!__traits(compiles, v1 !<> v2)); - static assert(!__traits(compiles, v1 <>= v2)); - static assert(!__traits(compiles, v1 !<= v2)); - static assert(!__traits(compiles, v1 !>= v2)); - static assert(!__traits(compiles, v1 !<>= v2)); - v1 = v2 << 1; - v1 = v2 >> 1; - v1 = v2 >>> 1; - static assert(!__traits(compiles, v1 && v2)); - static assert(!__traits(compiles, v1 || v2)); - v1 = ~v2; - v1 = -v2; - v1 = +v2; - static assert(!__traits(compiles, !v1)); - - v1 += v2; - v1 -= v2; - v1 *= v2; - v1 /= v2; - v1 %= v2; - v1 &= v2; - v1 |= v2; - v1 ^= v2; - static assert(!__traits(compiles, v1 ~= v2)); - static assert(!__traits(compiles, v1 ^^= v2)); - v1 <<= 1; - v1 >>= 1; - v1 >>>= 1; - - // A cast from vector to non-vector is allowed only when the target is same size Tsarray. - static assert(!__traits(compiles, cast(byte)v1)); // 1byte - static assert(!__traits(compiles, cast(short)v1)); // 2byte - static assert(!__traits(compiles, cast(int)v1)); // 4byte - static assert(!__traits(compiles, cast(long)v1)); // 8byte - static assert(!__traits(compiles, cast(float)v1)); // 4byte - static assert(!__traits(compiles, cast(double)v1)); // 8byte - static assert(!__traits(compiles, cast(int[2])v1)); // 8byte Tsarray - static assert( __traits(compiles, cast(int[4])v1)); // 16byte Tsarray, OK - static assert( __traits(compiles, cast(long[2])v1)); // 16byte Tsarray, OK -} - -/*****************************************/ - -void test2b() -{ - ubyte16 v1, v2 = 1, v3 = 1; - v1 = v2; - v1 = v2 + v3; - v1 = v2 - v3; - v1 = v2 * v3; - v1 = v2 / v3; - v1 = v2 % v3; - v1 = v2 & v3; - v1 = v2 | v3; - v1 = v2 ^ v3; - static assert(!__traits(compiles, v1 ~ v2)); - static assert(!__traits(compiles, v1 ^^ v2)); - static assert(!__traits(compiles, v1 is v2)); - static assert(!__traits(compiles, v1 !is v2)); - static assert(!__traits(compiles, v1 == v2)); - static assert(!__traits(compiles, v1 != v2)); - static assert(!__traits(compiles, v1 < v2)); - static assert(!__traits(compiles, v1 > v2)); - static assert(!__traits(compiles, v1 <= v2)); - static assert(!__traits(compiles, v1 >= v2)); - static assert(!__traits(compiles, v1 <> v2)); - static assert(!__traits(compiles, v1 !< v2)); - static assert(!__traits(compiles, v1 !> v2)); - static assert(!__traits(compiles, v1 !<> v2)); - static assert(!__traits(compiles, v1 <>= v2)); - static assert(!__traits(compiles, v1 !<= v2)); - static assert(!__traits(compiles, v1 !>= v2)); - static assert(!__traits(compiles, v1 !<>= v2)); - v1 = v2 << 1; - v1 = v2 >> 1; - v1 = v2 >>> 1; - static assert(!__traits(compiles, v1 && v2)); - static assert(!__traits(compiles, v1 || v2)); - v1 = ~v2; - v1 = -v2; - v1 = +v2; - static assert(!__traits(compiles, !v1)); - - v1 += v2; - v1 -= v2; - v1 *= v2; - v1 /= v2; - v1 %= v2; - v1 &= v2; - v1 |= v2; - v1 ^= v2; - static assert(!__traits(compiles, v1 ~= v2)); - static assert(!__traits(compiles, v1 ^^= v2)); - v1 <<= 1; - v1 >>= 1; - v1 >>>= 1; - - // A cast from vector to non-vector is allowed only when the target is same size Tsarray. - static assert(!__traits(compiles, cast(byte)v1)); // 1byte - static assert(!__traits(compiles, cast(short)v1)); // 2byte - static assert(!__traits(compiles, cast(int)v1)); // 4byte - static assert(!__traits(compiles, cast(long)v1)); // 8byte - static assert(!__traits(compiles, cast(float)v1)); // 4byte - static assert(!__traits(compiles, cast(double)v1)); // 8byte - static assert(!__traits(compiles, cast(int[2])v1)); // 8byte Tsarray - static assert( __traits(compiles, cast(int[4])v1)); // 16byte Tsarray, OK - static assert( __traits(compiles, cast(long[2])v1)); // 16byte Tsarray, OK -} - -/*****************************************/ - -void test2c() -{ - short8 v1, v2 = 1, v3 = 1; - v1 = v2; - v1 = v2 + v3; - v1 = v2 - v3; - v1 = v2 * v3; - v1 = v2 / v3; - v1 = v2 % v3; - v1 = v2 & v3; - v1 = v2 | v3; - v1 = v2 ^ v3; - static assert(!__traits(compiles, v1 ~ v2)); - static assert(!__traits(compiles, v1 ^^ v2)); - static assert(!__traits(compiles, v1 is v2)); - static assert(!__traits(compiles, v1 !is v2)); - static assert(!__traits(compiles, v1 == v2)); - static assert(!__traits(compiles, v1 != v2)); - static assert(!__traits(compiles, v1 < v2)); - static assert(!__traits(compiles, v1 > v2)); - static assert(!__traits(compiles, v1 <= v2)); - static assert(!__traits(compiles, v1 >= v2)); - static assert(!__traits(compiles, v1 <> v2)); - static assert(!__traits(compiles, v1 !< v2)); - static assert(!__traits(compiles, v1 !> v2)); - static assert(!__traits(compiles, v1 !<> v2)); - static assert(!__traits(compiles, v1 <>= v2)); - static assert(!__traits(compiles, v1 !<= v2)); - static assert(!__traits(compiles, v1 !>= v2)); - static assert(!__traits(compiles, v1 !<>= v2)); - v1 = v2 << 1; - v1 = v2 >> 1; - v1 = v2 >>> 1; - static assert(!__traits(compiles, v1 && v2)); - static assert(!__traits(compiles, v1 || v2)); - v1 = ~v2; - v1 = -v2; - v1 = +v2; - static assert(!__traits(compiles, !v1)); - - v1 += v2; - v1 -= v2; - v1 *= v2; - v1 /= v2; - v1 %= v2; - v1 &= v2; - v1 |= v2; - v1 ^= v2; - static assert(!__traits(compiles, v1 ~= v2)); - static assert(!__traits(compiles, v1 ^^= v2)); - v1 <<= 1; - v1 >>= 1; - v1 >>>= 1; - v1 = v1 * 3; - - // A cast from vector to non-vector is allowed only when the target is same size Tsarray. - static assert(!__traits(compiles, cast(byte)v1)); // 1byte - static assert(!__traits(compiles, cast(short)v1)); // 2byte - static assert(!__traits(compiles, cast(int)v1)); // 4byte - static assert(!__traits(compiles, cast(long)v1)); // 8byte - static assert(!__traits(compiles, cast(float)v1)); // 4byte - static assert(!__traits(compiles, cast(double)v1)); // 8byte - static assert(!__traits(compiles, cast(int[2])v1)); // 8byte Tsarray - static assert( __traits(compiles, cast(int[4])v1)); // 16byte Tsarray, OK - static assert( __traits(compiles, cast(long[2])v1)); // 16byte Tsarray, OK -} - -/*****************************************/ - -void test2d() -{ - ushort8 v1, v2 = 1, v3 = 1; - v1 = v2; - v1 = v2 + v3; - v1 = v2 - v3; - v1 = v2 * v3; - v1 = v2 / v3; - v1 = v2 % v3; - v1 = v2 & v3; - v1 = v2 | v3; - v1 = v2 ^ v3; - static assert(!__traits(compiles, v1 ~ v2)); - static assert(!__traits(compiles, v1 ^^ v2)); - static assert(!__traits(compiles, v1 is v2)); - static assert(!__traits(compiles, v1 !is v2)); - static assert(!__traits(compiles, v1 == v2)); - static assert(!__traits(compiles, v1 != v2)); - static assert(!__traits(compiles, v1 < v2)); - static assert(!__traits(compiles, v1 > v2)); - static assert(!__traits(compiles, v1 <= v2)); - static assert(!__traits(compiles, v1 >= v2)); - static assert(!__traits(compiles, v1 <> v2)); - static assert(!__traits(compiles, v1 !< v2)); - static assert(!__traits(compiles, v1 !> v2)); - static assert(!__traits(compiles, v1 !<> v2)); - static assert(!__traits(compiles, v1 <>= v2)); - static assert(!__traits(compiles, v1 !<= v2)); - static assert(!__traits(compiles, v1 !>= v2)); - static assert(!__traits(compiles, v1 !<>= v2)); - v1 = v2 << 1; - v1 = v2 >> 1; - v1 = v2 >>> 1; - static assert(!__traits(compiles, v1 && v2)); - static assert(!__traits(compiles, v1 || v2)); - v1 = ~v2; - v1 = -v2; - v1 = +v2; - static assert(!__traits(compiles, !v1)); - - v1 += v2; - v1 -= v2; - v1 *= v2; - v1 /= v2; - v1 %= v2; - v1 &= v2; - v1 |= v2; - v1 ^= v2; - static assert(!__traits(compiles, v1 ~= v2)); - static assert(!__traits(compiles, v1 ^^= v2)); - v1 <<= 1; - v1 >>= 1; - v1 >>>= 1; - - // A cast from vector to non-vector is allowed only when the target is same size Tsarray. - static assert(!__traits(compiles, cast(byte)v1)); // 1byte - static assert(!__traits(compiles, cast(short)v1)); // 2byte - static assert(!__traits(compiles, cast(int)v1)); // 4byte - static assert(!__traits(compiles, cast(long)v1)); // 8byte - static assert(!__traits(compiles, cast(float)v1)); // 4byte - static assert(!__traits(compiles, cast(double)v1)); // 8byte - static assert(!__traits(compiles, cast(int[2])v1)); // 8byte Tsarray - static assert( __traits(compiles, cast(int[4])v1)); // 16byte Tsarray, OK - static assert( __traits(compiles, cast(long[2])v1)); // 16byte Tsarray, OK -} - -/*****************************************/ - -void test2e() -{ - int4 v1, v2 = 1, v3 = 1; - v1 = v2; - v1 = v2 + v3; - v1 = v2 - v3; - v1 = v2 * v3; - v1 = v2 / v3; - v1 = v2 % v3; - v1 = v2 & v3; - v1 = v2 | v3; - v1 = v2 ^ v3; - static assert(!__traits(compiles, v1 ~ v2)); - static assert(!__traits(compiles, v1 ^^ v2)); - static assert(!__traits(compiles, v1 is v2)); - static assert(!__traits(compiles, v1 !is v2)); - static assert(!__traits(compiles, v1 == v2)); - static assert(!__traits(compiles, v1 != v2)); - static assert(!__traits(compiles, v1 < v2)); - static assert(!__traits(compiles, v1 > v2)); - static assert(!__traits(compiles, v1 <= v2)); - static assert(!__traits(compiles, v1 >= v2)); - static assert(!__traits(compiles, v1 <> v2)); - static assert(!__traits(compiles, v1 !< v2)); - static assert(!__traits(compiles, v1 !> v2)); - static assert(!__traits(compiles, v1 !<> v2)); - static assert(!__traits(compiles, v1 <>= v2)); - static assert(!__traits(compiles, v1 !<= v2)); - static assert(!__traits(compiles, v1 !>= v2)); - static assert(!__traits(compiles, v1 !<>= v2)); - v1 = v2 << 1; - v1 = v2 >> 1; - v1 = v2 >>> 1; - static assert(!__traits(compiles, v1 && v2)); - static assert(!__traits(compiles, v1 || v2)); - v1 = ~v2; - v1 = -v2; - v1 = +v2; - static assert(!__traits(compiles, !v1)); - - v1 += v2; - v1 -= v2; - v1 *= v2; - v1 /= v2; - v1 %= v2; - v1 &= v2; - v1 |= v2; - v1 ^= v2; - static assert(!__traits(compiles, v1 ~= v2)); - static assert(!__traits(compiles, v1 ^^= v2)); - v1 <<= 1; - v1 >>= 1; - v1 >>>= 1; - - // A cast from vector to non-vector is allowed only when the target is same size Tsarray. - static assert(!__traits(compiles, cast(byte)v1)); // 1byte - static assert(!__traits(compiles, cast(short)v1)); // 2byte - static assert(!__traits(compiles, cast(int)v1)); // 4byte - static assert(!__traits(compiles, cast(long)v1)); // 8byte - static assert(!__traits(compiles, cast(float)v1)); // 4byte - static assert(!__traits(compiles, cast(double)v1)); // 8byte - static assert(!__traits(compiles, cast(int[2])v1)); // 8byte Tsarray - static assert( __traits(compiles, cast(int[4])v1)); // 16byte Tsarray, OK - static assert( __traits(compiles, cast(long[2])v1)); // 16byte Tsarray, OK -} - -/*****************************************/ - -void test2f() -{ - uint4 v1, v2 = 1, v3 = 1; - v1 = v2; - v1 = v2 + v3; - v1 = v2 - v3; - v1 = v2 * v3; - v1 = v2 / v3; - v1 = v2 % v3; - v1 = v2 & v3; - v1 = v2 | v3; - v1 = v2 ^ v3; - static assert(!__traits(compiles, v1 ~ v2)); - static assert(!__traits(compiles, v1 ^^ v2)); - static assert(!__traits(compiles, v1 is v2)); - static assert(!__traits(compiles, v1 !is v2)); - static assert(!__traits(compiles, v1 == v2)); - static assert(!__traits(compiles, v1 != v2)); - static assert(!__traits(compiles, v1 < v2)); - static assert(!__traits(compiles, v1 > v2)); - static assert(!__traits(compiles, v1 <= v2)); - static assert(!__traits(compiles, v1 >= v2)); - static assert(!__traits(compiles, v1 <> v2)); - static assert(!__traits(compiles, v1 !< v2)); - static assert(!__traits(compiles, v1 !> v2)); - static assert(!__traits(compiles, v1 !<> v2)); - static assert(!__traits(compiles, v1 <>= v2)); - static assert(!__traits(compiles, v1 !<= v2)); - static assert(!__traits(compiles, v1 !>= v2)); - static assert(!__traits(compiles, v1 !<>= v2)); - v1 = v2 << 1; - v1 = v2 >> 1; - v1 = v2 >>> 1; - static assert(!__traits(compiles, v1 && v2)); - static assert(!__traits(compiles, v1 || v2)); - v1 = ~v2; - v1 = -v2; - v1 = +v2; - static assert(!__traits(compiles, !v1)); - - v1 += v2; - v1 -= v2; - v1 *= v2; - v1 /= v2; - v1 %= v2; - v1 &= v2; - v1 |= v2; - v1 ^= v2; - static assert(!__traits(compiles, v1 ~= v2)); - static assert(!__traits(compiles, v1 ^^= v2)); - v1 <<= 1; - v1 >>= 1; - v1 >>>= 1; - - // A cast from vector to non-vector is allowed only when the target is same size Tsarray. - static assert(!__traits(compiles, cast(byte)v1)); // 1byte - static assert(!__traits(compiles, cast(short)v1)); // 2byte - static assert(!__traits(compiles, cast(int)v1)); // 4byte - static assert(!__traits(compiles, cast(long)v1)); // 8byte - static assert(!__traits(compiles, cast(float)v1)); // 4byte - static assert(!__traits(compiles, cast(double)v1)); // 8byte - static assert(!__traits(compiles, cast(int[2])v1)); // 8byte Tsarray - static assert( __traits(compiles, cast(int[4])v1)); // 16byte Tsarray, OK - static assert( __traits(compiles, cast(long[2])v1)); // 16byte Tsarray, OK -} - -/*****************************************/ - -void test2g() -{ - long2 v1, v2 = 1, v3 = 1; - v1 = v2; - v1 = v2 + v3; - v1 = v2 - v3; - v1 = v2 * v3; - v1 = v2 / v3; - v1 = v2 % v3; - v1 = v2 & v3; - v1 = v2 | v3; - v1 = v2 ^ v3; - static assert(!__traits(compiles, v1 ~ v2)); - static assert(!__traits(compiles, v1 ^^ v2)); - static assert(!__traits(compiles, v1 is v2)); - static assert(!__traits(compiles, v1 !is v2)); - static assert(!__traits(compiles, v1 == v2)); - static assert(!__traits(compiles, v1 != v2)); - static assert(!__traits(compiles, v1 < v2)); - static assert(!__traits(compiles, v1 > v2)); - static assert(!__traits(compiles, v1 <= v2)); - static assert(!__traits(compiles, v1 >= v2)); - static assert(!__traits(compiles, v1 <> v2)); - static assert(!__traits(compiles, v1 !< v2)); - static assert(!__traits(compiles, v1 !> v2)); - static assert(!__traits(compiles, v1 !<> v2)); - static assert(!__traits(compiles, v1 <>= v2)); - static assert(!__traits(compiles, v1 !<= v2)); - static assert(!__traits(compiles, v1 !>= v2)); - static assert(!__traits(compiles, v1 !<>= v2)); - v1 = v2 << 1; - v1 = v2 >> 1; - v1 = v2 >>> 1; - static assert(!__traits(compiles, v1 && v2)); - static assert(!__traits(compiles, v1 || v2)); - v1 = ~v2; - v1 = -v2; - v1 = +v2; - static assert(!__traits(compiles, !v1)); - - v1 += v2; - v1 -= v2; - v1 *= v2; - v1 /= v2; - v1 %= v2; - v1 &= v2; - v1 |= v2; - v1 ^= v2; - static assert(!__traits(compiles, v1 ~= v2)); - static assert(!__traits(compiles, v1 ^^= v2)); - v1 <<= 1; - v1 >>= 1; - v1 >>>= 1; - - // A cast from vector to non-vector is allowed only when the target is same size Tsarray. - static assert(!__traits(compiles, cast(byte)v1)); // 1byte - static assert(!__traits(compiles, cast(short)v1)); // 2byte - static assert(!__traits(compiles, cast(int)v1)); // 4byte - static assert(!__traits(compiles, cast(long)v1)); // 8byte - static assert(!__traits(compiles, cast(float)v1)); // 4byte - static assert(!__traits(compiles, cast(double)v1)); // 8byte - static assert(!__traits(compiles, cast(int[2])v1)); // 8byte Tsarray - static assert( __traits(compiles, cast(int[4])v1)); // 16byte Tsarray, OK - static assert( __traits(compiles, cast(long[2])v1)); // 16byte Tsarray, OK -} - -/*****************************************/ - -void test2h() -{ - ulong2 v1, v2 = 1, v3 = 1; - v1 = v2; - v1 = v2 + v3; - v1 = v2 - v3; - v1 = v2 * v3; - v1 = v2 / v3; - v1 = v2 % v3; - v1 = v2 & v3; - v1 = v2 | v3; - v1 = v2 ^ v3; - static assert(!__traits(compiles, v1 ~ v2)); - static assert(!__traits(compiles, v1 ^^ v2)); - static assert(!__traits(compiles, v1 is v2)); - static assert(!__traits(compiles, v1 !is v2)); - static assert(!__traits(compiles, v1 == v2)); - static assert(!__traits(compiles, v1 != v2)); - static assert(!__traits(compiles, v1 < v2)); - static assert(!__traits(compiles, v1 > v2)); - static assert(!__traits(compiles, v1 <= v2)); - static assert(!__traits(compiles, v1 >= v2)); - static assert(!__traits(compiles, v1 <> v2)); - static assert(!__traits(compiles, v1 !< v2)); - static assert(!__traits(compiles, v1 !> v2)); - static assert(!__traits(compiles, v1 !<> v2)); - static assert(!__traits(compiles, v1 <>= v2)); - static assert(!__traits(compiles, v1 !<= v2)); - static assert(!__traits(compiles, v1 !>= v2)); - static assert(!__traits(compiles, v1 !<>= v2)); - v1 = v2 << 1; - v1 = v2 >> 1; - v1 = v2 >>> 1; - static assert(!__traits(compiles, v1 && v2)); - static assert(!__traits(compiles, v1 || v2)); - v1 = ~v2; - v1 = -v2; - v1 = +v2; - static assert(!__traits(compiles, !v1)); - - v1 += v2; - v1 -= v2; - v1 *= v2; - v1 /= v2; - v1 %= v2; - v1 &= v2; - v1 |= v2; - v1 ^= v2; - static assert(!__traits(compiles, v1 ~= v2)); - static assert(!__traits(compiles, v1 ^^= v2)); - v1 <<= 1; - v1 >>= 1; - v1 >>>= 1; - - // A cast from vector to non-vector is allowed only when the target is same size Tsarray. - static assert(!__traits(compiles, cast(byte)v1)); // 1byte - static assert(!__traits(compiles, cast(short)v1)); // 2byte - static assert(!__traits(compiles, cast(int)v1)); // 4byte - static assert(!__traits(compiles, cast(long)v1)); // 8byte - static assert(!__traits(compiles, cast(float)v1)); // 4byte - static assert(!__traits(compiles, cast(double)v1)); // 8byte - static assert(!__traits(compiles, cast(int[2])v1)); // 8byte Tsarray - static assert( __traits(compiles, cast(int[4])v1)); // 16byte Tsarray, OK - static assert( __traits(compiles, cast(long[2])v1)); // 16byte Tsarray, OK -} - -/*****************************************/ - -void test2i() -{ - float4 v1, v2 = 1, v3 = 1; - v1 = v2; - v1 = v2 + v3; - v1 = v2 - v3; - v1 = v2 * v3; - v1 = v2 / v3; - static assert(!__traits(compiles, v1 % v2)); - static assert(!__traits(compiles, v1 & v2)); - static assert(!__traits(compiles, v1 | v2)); - static assert(!__traits(compiles, v1 ^ v2)); - static assert(!__traits(compiles, v1 ~ v2)); - static assert(!__traits(compiles, v1 ^^ v2)); - static assert(!__traits(compiles, v1 is v2)); - static assert(!__traits(compiles, v1 !is v2)); - static assert(!__traits(compiles, v1 == v2)); - static assert(!__traits(compiles, v1 != v2)); - static assert(!__traits(compiles, v1 < v2)); - static assert(!__traits(compiles, v1 > v2)); - static assert(!__traits(compiles, v1 <= v2)); - static assert(!__traits(compiles, v1 >= v2)); - static assert(!__traits(compiles, v1 <> v2)); - static assert(!__traits(compiles, v1 !< v2)); - static assert(!__traits(compiles, v1 !> v2)); - static assert(!__traits(compiles, v1 !<> v2)); - static assert(!__traits(compiles, v1 <>= v2)); - static assert(!__traits(compiles, v1 !<= v2)); - static assert(!__traits(compiles, v1 !>= v2)); - static assert(!__traits(compiles, v1 !<>= v2)); - static assert(!__traits(compiles, v1 << 1)); - static assert(!__traits(compiles, v1 >> 1)); - static assert(!__traits(compiles, v1 >>> 1)); - static assert(!__traits(compiles, v1 && v2)); - static assert(!__traits(compiles, v1 || v2)); - static assert(!__traits(compiles, ~v1)); - v1 = -v2; - v1 = +v2; - static assert(!__traits(compiles, !v1)); - - v1 += v2; - v1 -= v2; - v1 *= v2; - v1 /= v2; - static assert(!__traits(compiles, v1 %= v2)); - static assert(!__traits(compiles, v1 &= v2)); - static assert(!__traits(compiles, v1 |= v2)); - static assert(!__traits(compiles, v1 ^= v2)); - static assert(!__traits(compiles, v1 ~= v2)); - static assert(!__traits(compiles, v1 ^^= v2)); - static assert(!__traits(compiles, v1 <<= 1)); - static assert(!__traits(compiles, v1 >>= 1)); - static assert(!__traits(compiles, v1 >>>= 1)); - - // A cast from vector to non-vector is allowed only when the target is same size Tsarray. - static assert(!__traits(compiles, cast(byte)v1)); // 1byte - static assert(!__traits(compiles, cast(short)v1)); // 2byte - static assert(!__traits(compiles, cast(int)v1)); // 4byte - static assert(!__traits(compiles, cast(long)v1)); // 8byte - static assert(!__traits(compiles, cast(float)v1)); // 4byte - static assert(!__traits(compiles, cast(double)v1)); // 8byte - static assert(!__traits(compiles, cast(int[2])v1)); // 8byte Tsarray - static assert( __traits(compiles, cast(int[4])v1)); // 16byte Tsarray, OK - static assert( __traits(compiles, cast(long[2])v1)); // 16byte Tsarray, OK -} - -/*****************************************/ - -void test2j() -{ - double2 v1, v2 = 1, v3 = 1; - v1 = v2; - v1 = v2 + v3; - v1 = v2 - v3; - v1 = v2 * v3; - v1 = v2 / v3; - static assert(!__traits(compiles, v1 % v2)); - static assert(!__traits(compiles, v1 & v2)); - static assert(!__traits(compiles, v1 | v2)); - static assert(!__traits(compiles, v1 ^ v2)); - static assert(!__traits(compiles, v1 ~ v2)); - static assert(!__traits(compiles, v1 ^^ v2)); - static assert(!__traits(compiles, v1 is v2)); - static assert(!__traits(compiles, v1 !is v2)); - static assert(!__traits(compiles, v1 == v2)); - static assert(!__traits(compiles, v1 != v2)); - static assert(!__traits(compiles, v1 < v2)); - static assert(!__traits(compiles, v1 > v2)); - static assert(!__traits(compiles, v1 <= v2)); - static assert(!__traits(compiles, v1 >= v2)); - static assert(!__traits(compiles, v1 <> v2)); - static assert(!__traits(compiles, v1 !< v2)); - static assert(!__traits(compiles, v1 !> v2)); - static assert(!__traits(compiles, v1 !<> v2)); - static assert(!__traits(compiles, v1 <>= v2)); - static assert(!__traits(compiles, v1 !<= v2)); - static assert(!__traits(compiles, v1 !>= v2)); - static assert(!__traits(compiles, v1 !<>= v2)); - static assert(!__traits(compiles, v1 << 1)); - static assert(!__traits(compiles, v1 >> 1)); - static assert(!__traits(compiles, v1 >>> 1)); - static assert(!__traits(compiles, v1 && v2)); - static assert(!__traits(compiles, v1 || v2)); - static assert(!__traits(compiles, ~v1)); - v1 = -v2; - v1 = +v2; - static assert(!__traits(compiles, !v1)); - - v1 += v2; - v1 -= v2; - v1 *= v2; - v1 /= v2; - static assert(!__traits(compiles, v1 %= v2)); - static assert(!__traits(compiles, v1 &= v2)); - static assert(!__traits(compiles, v1 |= v2)); - static assert(!__traits(compiles, v1 ^= v2)); - static assert(!__traits(compiles, v1 ~= v2)); - static assert(!__traits(compiles, v1 ^^= v2)); - static assert(!__traits(compiles, v1 <<= 1)); - static assert(!__traits(compiles, v1 >>= 1)); - static assert(!__traits(compiles, v1 >>>= 1)); - - // A cast from vector to non-vector is allowed only when the target is same size Tsarray. - static assert(!__traits(compiles, cast(byte)v1)); // 1byte - static assert(!__traits(compiles, cast(short)v1)); // 2byte - static assert(!__traits(compiles, cast(int)v1)); // 4byte - static assert(!__traits(compiles, cast(long)v1)); // 8byte - static assert(!__traits(compiles, cast(float)v1)); // 4byte - static assert(!__traits(compiles, cast(double)v1)); // 8byte - static assert(!__traits(compiles, cast(int[2])v1)); // 8byte Tsarray - static assert( __traits(compiles, cast(int[4])v1)); // 16byte Tsarray, OK - static assert( __traits(compiles, cast(long[2])v1)); // 16byte Tsarray, OK -} - -/*****************************************/ - -void test4() -{ - int4 c = 7; - (cast(int[4])c)[3] = 4; - (cast(int*)&c)[2] = 4; - c.array[1] = 4; - c.ptr[3] = 4; - assert(c.length == 4); -} - -/*****************************************/ - -void BaseTypeOfVector(T : __vector(T[N]), size_t N)(int i) -{ - assert(is(T == int)); - assert(N == 4); -} - - -void test7411() -{ - BaseTypeOfVector!(__vector(int[4]))(3); -} - -/*****************************************/ -// https://issues.dlang.org/show_bug.cgi?id=7951 - -float[4] test7951() -{ - float4 v1; - float4 v2; - - return cast(float[4])(v1+v2); -} - -/*****************************************/ - -void test7951_2() -{ - float[4] v1 = [1,2,3,4]; - float[4] v2 = [1,2,3,4]; - float4 f1, f2, f3; - f1.array = v1; - f2.array = v2; - f3 = f1 + f2; -} - -/*****************************************/ - -immutable ulong2 gulong2 = 0x8000_0000_0000_0000; -immutable uint4 guint4 = 0x8000_0000; -immutable ushort8 gushort8 = 0x8000; -immutable ubyte16 gubyte16 = 0x80; - -immutable long2 glong2 = 0x7000_0000_0000_0000; -immutable int4 gint4 = 0x7000_0000; -immutable short8 gshort8 = 0x7000; -immutable byte16 gbyte16 = 0x70; - -immutable float4 gfloat4 = 4.0; -immutable double2 gdouble2 = 8.0; - -void test7414() -{ - immutable ulong2 lulong2 = 0x8000_0000_0000_0000; - assert(memcmp(&lulong2, &gulong2, gulong2.sizeof) == 0); - - immutable uint4 luint4 = 0x8000_0000; - assert(memcmp(&luint4, &guint4, guint4.sizeof) == 0); - - immutable ushort8 lushort8 = 0x8000; - assert(memcmp(&lushort8, &gushort8, gushort8.sizeof) == 0); - - immutable ubyte16 lubyte16 = 0x80; - assert(memcmp(&lubyte16, &gubyte16, gubyte16.sizeof) == 0); - - - immutable long2 llong2 = 0x7000_0000_0000_0000; - assert(memcmp(&llong2, &glong2, glong2.sizeof) == 0); - - immutable int4 lint4 = 0x7000_0000; - assert(memcmp(&lint4, &gint4, gint4.sizeof) == 0); - - immutable short8 lshort8 = 0x7000; - assert(memcmp(&lshort8, &gshort8, gshort8.sizeof) == 0); - - immutable byte16 lbyte16 = 0x70; - assert(memcmp(&lbyte16, &gbyte16, gbyte16.sizeof) == 0); - - - immutable float4 lfloat4 = 4.0; - assert(memcmp(&lfloat4, &gfloat4, gfloat4.sizeof) == 0); - - immutable double2 ldouble2 = 8.0; - assert(memcmp(&ldouble2, &gdouble2, gdouble2.sizeof) == 0); -} - -/*****************************************/ - -void test7413() -{ - byte16 b = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]; - assert(b.array[0] == 1); - assert(b.array[1] == 2); - assert(b.array[2] == 3); - assert(b.array[3] == 4); - assert(b.array[4] == 5); - assert(b.array[5] == 6); - assert(b.array[6] == 7); - assert(b.array[7] == 8); - assert(b.array[8] == 9); - assert(b.array[9] == 10); - assert(b.array[10] == 11); - assert(b.array[11] == 12); - assert(b.array[12] == 13); - assert(b.array[13] == 14); - assert(b.array[14] == 15); - assert(b.array[15] == 16); - - ubyte16 ub = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]; - assert(ub.array[0] == 1); - assert(ub.array[1] == 2); - assert(ub.array[2] == 3); - assert(ub.array[3] == 4); - assert(ub.array[4] == 5); - assert(ub.array[5] == 6); - assert(ub.array[6] == 7); - assert(ub.array[7] == 8); - assert(ub.array[8] == 9); - assert(ub.array[9] == 10); - assert(ub.array[10] == 11); - assert(ub.array[11] == 12); - assert(ub.array[12] == 13); - assert(ub.array[13] == 14); - assert(ub.array[14] == 15); - assert(ub.array[15] == 16); - - short8 s = [1,2,3,4,5,6,7,8]; - assert(s.array[0] == 1); - assert(s.array[1] == 2); - assert(s.array[2] == 3); - assert(s.array[3] == 4); - assert(s.array[4] == 5); - assert(s.array[5] == 6); - assert(s.array[6] == 7); - assert(s.array[7] == 8); - - ushort8 us = [1,2,3,4,5,6,7,8]; - assert(us.array[0] == 1); - assert(us.array[1] == 2); - assert(us.array[2] == 3); - assert(us.array[3] == 4); - assert(us.array[4] == 5); - assert(us.array[5] == 6); - assert(us.array[6] == 7); - assert(us.array[7] == 8); - - int4 i = [1,2,3,4]; - assert(i.array[0] == 1); - assert(i.array[1] == 2); - assert(i.array[2] == 3); - assert(i.array[3] == 4); - - uint4 ui = [1,2,3,4]; - assert(ui.array[0] == 1); - assert(ui.array[1] == 2); - assert(ui.array[2] == 3); - assert(ui.array[3] == 4); - - long2 l = [1,2]; - assert(l.array[0] == 1); - assert(l.array[1] == 2); - - ulong2 ul = [1,2]; - assert(ul.array[0] == 1); - assert(ul.array[1] == 2); - - float4 f = [1,2,3,4]; - assert(f.array[0] == 1); - assert(f.array[1] == 2); - assert(f.array[2] == 3); - assert(f.array[3] == 4); - - double2 d = [1,2]; - assert(d.array[0] == 1); - assert(d.array[1] == 2); -} - -/*****************************************/ - -byte16 b = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]; -ubyte16 ub = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]; -short8 s = [1,2,3,4,5,6,7,8]; -ushort8 us = [1,2,3,4,5,6,7,8]; -int4 i = [1,2,3,4]; -uint4 ui = [1,2,3,4]; -long2 l = [1,2]; -ulong2 ul = [1,2]; -float4 f = [1,2,3,4]; -double2 d = [1,2]; - -void test7413_2() -{ - assert(b.array[0] == 1); - assert(b.array[1] == 2); - assert(b.array[2] == 3); - assert(b.array[3] == 4); - assert(b.array[4] == 5); - assert(b.array[5] == 6); - assert(b.array[6] == 7); - assert(b.array[7] == 8); - assert(b.array[8] == 9); - assert(b.array[9] == 10); - assert(b.array[10] == 11); - assert(b.array[11] == 12); - assert(b.array[12] == 13); - assert(b.array[13] == 14); - assert(b.array[14] == 15); - assert(b.array[15] == 16); - - assert(ub.array[0] == 1); - assert(ub.array[1] == 2); - assert(ub.array[2] == 3); - assert(ub.array[3] == 4); - assert(ub.array[4] == 5); - assert(ub.array[5] == 6); - assert(ub.array[6] == 7); - assert(ub.array[7] == 8); - assert(ub.array[8] == 9); - assert(ub.array[9] == 10); - assert(ub.array[10] == 11); - assert(ub.array[11] == 12); - assert(ub.array[12] == 13); - assert(ub.array[13] == 14); - assert(ub.array[14] == 15); - assert(ub.array[15] == 16); - - assert(s.array[0] == 1); - assert(s.array[1] == 2); - assert(s.array[2] == 3); - assert(s.array[3] == 4); - assert(s.array[4] == 5); - assert(s.array[5] == 6); - assert(s.array[6] == 7); - assert(s.array[7] == 8); - - assert(us.array[0] == 1); - assert(us.array[1] == 2); - assert(us.array[2] == 3); - assert(us.array[3] == 4); - assert(us.array[4] == 5); - assert(us.array[5] == 6); - assert(us.array[6] == 7); - assert(us.array[7] == 8); - - assert(i.array[0] == 1); - assert(i.array[1] == 2); - assert(i.array[2] == 3); - assert(i.array[3] == 4); - - assert(ui.array[0] == 1); - assert(ui.array[1] == 2); - assert(ui.array[2] == 3); - assert(ui.array[3] == 4); - - assert(l.array[0] == 1); - assert(l.array[1] == 2); - - assert(ul.array[0] == 1); - assert(ul.array[1] == 2); - - assert(f.array[0] == 1); - assert(f.array[1] == 2); - assert(f.array[2] == 3); - assert(f.array[3] == 4); - - assert(d.array[0] == 1); - assert(d.array[1] == 2); -} - -/*****************************************/ - -float bug8060(float x) { - int i = *cast(int*)&x; - ++i; - return *cast(float*)&i; -} - -/*****************************************/ -// https://issues.dlang.org/show_bug.cgi?id=9200 - -void bar9200(double[2] a) -{ - assert(a[0] == 1); - assert(a[1] == 2); -} - -double2 * v9200(double2* a) -{ - return a; -} - -void test9200() -{ - double2 a = [1, 2]; - - *v9200(&a) = a; - - bar9200(a.array); -} - -/*****************************************/ -// https://issues.dlang.org/show_bug.cgi?id=9304 -// https://issues.dlang.org/show_bug.cgi?id=9322 - -float4 foo9304(float4 a) -{ - return -a; -} - - -void test9304() -{ - auto a = foo9304([0, 1, 2, 3]); - assert(a.array == [0,-1,-2,-3]); -} - -/*****************************************/ - -void test9910() -{ - float4 f = [1, 1, 1, 1]; - auto works = f + 3; - auto bug = 3 + f; - - assert (works.array == [4,4,4,4]); - assert (bug.array == [4,4,4,4]); // no property 'array' for type 'int' -} - -/*****************************************/ - -bool normalize(double[] range, double sum = 1) -{ - double s = 0; - const length = range.length; - foreach (e; range) - { - s += e; - } - if (s == 0) - { - return false; - } - return true; -} - -void test12852() -{ - double[3] range = [0.0, 0.0, 0.0]; - assert(normalize(range[]) == false); - range[1] = 3.0; - assert(normalize(range[]) == true); -} - -/*****************************************/ - -void test9449() -{ - ubyte16[1] table; -} - -/*****************************************/ - -void test9449_2() -{ - float[4][2] m = [[2.0, 1, 3, 4], [5.0, 6, 7, 8]]; // segfault - - assert(m[0][0] == 2.0); - assert(m[0][1] == 1); - assert(m[0][2] == 3); - assert(m[0][3] == 4); - - assert(m[1][0] == 5.0); - assert(m[1][1] == 6); - assert(m[1][2] == 7); - assert(m[1][3] == 8); -} - -/*****************************************/ -// https://issues.dlang.org/show_bug.cgi?id=13841 - -void test13841() -{ - alias Vector16s = TypeTuple!( - void16, byte16, short8, int4, long2, - ubyte16, ushort8, uint4, ulong2, float4, double2); - foreach (V1; Vector16s) - { - foreach (V2; Vector16s) - { - V1 v1 = void; - V2 v2 = void; - static if (is(V1 == V2)) - { - static assert( is(typeof(true ? v1 : v2) == V1)); - } - else - { - static assert(!is(typeof(true ? v1 : v2))); - } - } - } -} - -/*****************************************/ -// https://issues.dlang.org/show_bug.cgi?id=12776 - -void test12776() -{ - alias Vector16s = TypeTuple!( - void16, byte16, short8, int4, long2, - ubyte16, ushort8, uint4, ulong2, float4, double2); - foreach (V; Vector16s) - { - static assert(is(typeof( V .init) == V )); - static assert(is(typeof( const(V).init) == const(V))); - static assert(is(typeof( inout( V).init) == inout( V))); - static assert(is(typeof( inout(const V).init) == inout(const V))); - static assert(is(typeof(shared( V).init) == shared( V))); - static assert(is(typeof(shared( const V).init) == shared( const V))); - static assert(is(typeof(shared(inout V).init) == shared(inout V))); - static assert(is(typeof(shared(inout const V).init) == shared(inout const V))); - static assert(is(typeof( immutable(V).init) == immutable(V))); - } -} - -/*****************************************/ - -void foo13988(double[] arr) -{ - static ulong repr(double d) { return *cast(ulong*)&d; } - foreach (x; arr) - assert(repr(arr[0]) == *cast(ulong*)&(arr[0])); -} - - -void test13988() -{ - double[] arr = [3.0]; - foo13988(arr); -} - -/*****************************************/ -// https://issues.dlang.org/show_bug.cgi?id=15123 - -void test15123() -{ - alias Vector16s = TypeTuple!( - void16, byte16, short8, int4, long2, - ubyte16, ushort8, uint4, ulong2, float4, double2); - foreach (V; Vector16s) - { - auto x = V.init; - } -} - -/*****************************************/ -// https://issues.dlang.org/show_bug.cgi?id=15144 - -void test15144() -{ - enum ubyte16 csXMM1 = ['a','b','c',0,0,0,0,0]; - __gshared ubyte16 csXMM2 = ['a','b','c',0,0,0,0,0]; - immutable ubyte16 csXMM3 = ['a','b','c',0,0,0,0,0]; -} - -/*****************************************/ -// https://issues.dlang.org/show_bug.cgi?id=13927 - -void test13927(ulong2 a) -{ - ulong2 b = [long.min, long.min]; - auto tmp = a - b; -} - -/*****************************************/ -// https://issues.dlang.org/show_bug.cgi?id=16488 - -void foo_byte16(byte t, byte s) -{ - byte16 f = s; - auto p = cast(byte*)&f; - foreach (i; 0 .. 16) - assert(p[i] == s); -} - -void foo_ubyte16(ubyte t, ubyte s) -{ - ubyte16 f = s; - auto p = cast(ubyte*)&f; - foreach (i; 0 .. 16) - assert(p[i] == s); -} - - -void foo_short8(short t, short s) -{ - short8 f = s; - auto p = cast(short*)&f; - foreach (i; 0 .. 8) - assert(p[i] == s); -} - -void foo_ushort8(ushort t, ushort s) -{ - ushort8 f = s; - auto p = cast(ushort*)&f; - foreach (i; 0 .. 8) - assert(p[i] == s); -} - - -void foo_int4(int t, int s) -{ - int4 f = s; - auto p = cast(int*)&f; - foreach (i; 0 .. 4) - assert(p[i] == s); -} - -void foo_uint4(uint t, uint s, uint u) -{ - uint4 f = s; - auto p = cast(uint*)&f; - foreach (i; 0 .. 4) - assert(p[i] == s); -} - - -void foo_long2(long t, long s, long u) -{ - long2 f = s; - auto p = cast(long*)&f; - foreach (i; 0 .. 2) - assert(p[i] == s); -} - -void foo_ulong2(ulong t, ulong s) -{ - ulong2 f = s; - auto p = cast(ulong*)&f; - foreach (i; 0 .. 2) - assert(p[i] == s); -} - -void foo_float4(float t, float s) -{ - float4 f = s; - auto p = cast(float*)&f; - foreach (i; 0 .. 4) - assert(p[i] == s); -} - -void foo_double2(double t, double s, double u) -{ - double2 f = s; - auto p = cast(double*)&f; - foreach (i; 0 .. 2) - assert(p[i] == s); -} - - -void test16448() -{ - foo_byte16(5, -10); - foo_ubyte16(5, 11); - - foo_short8(5, -6); - foo_short8(5, 7); - - foo_int4(5, -6); - foo_uint4(5, 0x12345678, 22); - - foo_long2(5, -6, 1); - foo_ulong2(5, 0x12345678_87654321L); - - foo_float4(5, -6); - foo_double2(5, -6, 2); -} - -/*****************************************/ - -void foo_byte32(byte t, byte s) -{ - byte32 f = s; - auto p = cast(byte*)&f; - foreach (i; 0 .. 32) - assert(p[i] == s); -} - -void foo_ubyte32(ubyte t, ubyte s) -{ - ubyte32 f = s; - auto p = cast(ubyte*)&f; - foreach (i; 0 .. 32) - assert(p[i] == s); -} - -void foo_short16(short t, short s) -{ - short16 f = s; - auto p = cast(short*)&f; - foreach (i; 0 .. 16) - assert(p[i] == s); -} - -void foo_ushort16(ushort t, ushort s) -{ - ushort16 f = s; - auto p = cast(ushort*)&f; - foreach (i; 0 .. 16) - assert(p[i] == s); -} - -void foo_int8(int t, int s) -{ - int8 f = s; - auto p = cast(int*)&f; - foreach (i; 0 .. 8) - assert(p[i] == s); -} - -void foo_uint8(uint t, uint s, uint u) -{ - uint8 f = s; - auto p = cast(uint*)&f; - foreach (i; 0 .. 8) - assert(p[i] == s); -} - -void foo_long4(long t, long s, long u) -{ - long4 f = s; - auto p = cast(long*)&f; - foreach (i; 0 .. 4) - assert(p[i] == s); -} - -void foo_ulong4(ulong t, ulong s) -{ - ulong4 f = s; - auto p = cast(ulong*)&f; - foreach (i; 0 .. 4) - assert(p[i] == s); -} - -void foo_float8(float t, float s) -{ - float8 f = s; - auto p = cast(float*)&f; - foreach (i; 0 .. 8) - assert(p[i] == s); -} - -void foo_double4(double t, double s, double u) -{ - double4 f = s; - auto p = cast(double*)&f; - foreach (i; 0 .. 4) - assert(p[i] == s); -} - -void test16448_32() -{ - import core.cpuid; - if (!core.cpuid.avx) - return; - - foo_byte32(5, -10); - foo_ubyte32(5, 11); - - foo_short16(5, -6); - foo_short16(5, 7); - - foo_int8(5, -6); - foo_uint8(5, 0x12345678, 22); - - foo_long4(5, -6, 1); - foo_ulong4(5, 0x12345678_87654321L); - - foo_float8(5, -6); - foo_double4(5, -6, 2); -} - - -/*****************************************/ -// https://issues.dlang.org/show_bug.cgi?id=16703 - -float index(float4 f4, size_t i) -{ - return f4[i]; - //return (*cast(float[4]*)&f4)[2]; -} - -float[4] slice(float4 f4) -{ - return f4[]; -} - -float slice2(float4 f4, size_t lwr, size_t upr, size_t i) -{ - float[] fa = f4[lwr .. upr]; - return fa[i]; -} - -void test16703() -{ - float4 f4 = [1,2,3,4]; - assert(index(f4, 0) == 1); - assert(index(f4, 1) == 2); - assert(index(f4, 2) == 3); - assert(index(f4, 3) == 4); - - float[4] fsa = slice(f4); - assert(fsa == [1.0f,2,3,4]); - - assert(slice2(f4, 1, 3, 0) == 2); - assert(slice2(f4, 1, 3, 1) == 3); -} - -/*****************************************/ - -struct Sunsto -{ - align (1): // make sure f4 is misaligned - byte b; - union - { - float4 f4; - ubyte[16] a; - } -} - -ubyte[16] foounsto() -{ - float4 vf = 6; - Sunsto s; - s.f4 = vf * 2; - vf = s.f4; - - return s.a; -} - -void testOPvecunsto() -{ - auto a = foounsto(); - version (LittleEndian) - assert(a == [0, 0, 64, 65, 0, 0, 64, 65, 0, 0, 64, 65, 0, 0, 64, 65]); - version (BigEndian) - assert(a == [65, 64, 0, 0, 65, 64, 0, 0, 65, 64, 0, 0, 65, 64, 0, 0]); -} - -/*****************************************/ -// https://issues.dlang.org/show_bug.cgi?id=10447 - -void test10447() -{ - immutable __vector(double[2]) a = [1.0, 2.0]; - __vector(double[2]) r; - r += a; - r = r * a; -} - -/*****************************************/ -// https://issues.dlang.org/show_bug.cgi?id=17237 - -struct S17237 -{ - bool a; - struct - { - bool b; - int8 c; - } -} - -static assert(S17237.a.offsetof == 0); -static assert(S17237.b.offsetof == 32); -static assert(S17237.c.offsetof == 64); - -/*****************************************/ -// https://issues.dlang.org/show_bug.cgi?id=16697 - -static assert(!is(float == __vector)); -static assert(!is(float[1] == __vector)); -static assert(!is(float[4] == __vector)); -static assert( is(__vector(float[4]) == __vector)); -static assert(!is(__vector(float[3]) == __vector)); -static assert(!is(__vector(float[5]) == __vector)); -static assert( is(__vector(float[4]) X == __vector) && is(X == float[4])); -static assert( is(__vector(byte[16]) X == __vector) && is(X == byte[16])); - -/*****************************************/ -// https://issues.dlang.org/show_bug.cgi?id=17720 - -void test17720() -{ - alias Vector16s = TypeTuple!( - void16, byte16, short8, int4, long2, - ubyte16, ushort8, uint4, ulong2, float4, double2); - alias Vector32s = TypeTuple!( - void32, byte32, short16, int8, long4, - ubyte32, ushort16, uint8, ulong4, float8, double4); - - // OK: __vector(T) -> __vector(void[]) of same size. - // NG: __vector(T) -> __vector(void[]) of different size. - // NG: explicit cast __vector(T) -> __vector(void[]) of different size. - foreach (V; Vector16s) - { - static assert( __traits(compiles, { void16 v = V.init; })); - static assert(!__traits(compiles, { void32 v = V.init; })); - static assert(!__traits(compiles, { void32 v = cast(void32)V.init; })); - } - foreach (V; Vector32s) - { - static assert( __traits(compiles, { void32 v = V.init; })); - static assert(!__traits(compiles, { void16 v = V.init; })); - static assert(!__traits(compiles, { void16 v = cast(void16)V.init; })); - } - - // NG: __vector(T) -> __vector(T) of same size. - // OK: explicit cast __vector(T) -> __vector(T) of same size. - // NG: __vector(T) -> __vector(T) of different size. - // NG: explicit cast __vector(T) -> __vector(T) of different size. - foreach (V; Vector16s) - { - static if (is(V == double2)) - { - static assert(!__traits(compiles, { long2 v = V.init; })); - static assert( __traits(compiles, { long2 v = cast(long2)V.init; })); - } - else - { - static assert(!__traits(compiles, { double2 v = V.init; })); - static assert( __traits(compiles, { double2 v = cast(double2)V.init; })); - } - static assert(!__traits(compiles, { double4 v = V.init; })); - static assert(!__traits(compiles, { double4 v = cast(double4)V.init; })); - } - foreach (V; Vector32s) - { - static if (is(V == double4)) - { - static assert(!__traits(compiles, { long4 v = V.init; })); - static assert( __traits(compiles, { long4 v = cast(long4)V.init; })); - } - else - { - static assert(!__traits(compiles, { double4 v = V.init; })); - static assert( __traits(compiles, { double4 v = cast(double4)V.init; })); - } - static assert(!__traits(compiles, { double2 v = V.init; })); - static assert(!__traits(compiles, { double2 v = cast(double2)V.init; })); - } -} - -/*****************************************/ -// https://issues.dlang.org/show_bug.cgi?id=17695 - -void test17695(__vector(ubyte[16]) a) -{ - auto b = -a; -} - -/*****************************************/ -// https://issues.dlang.org/show_bug.cgi?id=19223 - -int test19223a(const int[4] x) -{ - int sum = 0; - foreach (i; x) sum += i; - return sum; -} - -void test19223() -{ - int4 v1 = int4.init; - assert(test19223a(v1.array) == 0); - assert(test19223a(int4.init.array) == 0); -} - -/*****************************************/ -// https://issues.dlang.org/show_bug.cgi?id=19224 - -float test19224(const float[4] val) -{ - float sum = 0; - foreach (x; val) sum += x; - return sum; -} - -enum x19224 = test19224(float4.init.array); -static assert(x19224 is float.nan); - -enum y19224 = test19224(float4(1).array); -static assert(y19224 == 4); - -/*****************************************/ -// https://issues.dlang.org/show_bug.cgi?id=19607 - -int test19607a(const int[4] x) -{ - int sum = 0; - foreach (i; x) sum += i; - return sum; -} - -void test19607() -{ - int4 v1 = 1; - assert(test19607a(v1.array) == 4); - assert(test19607a(int4(2).array) == 8); -} - -/*****************************************/ -// https://issues.dlang.org/show_bug.cgi?id=19627 - -enum int[4] fail19627 = cast(int[4])int4(0); - -/*****************************************/ -// https://issues.dlang.org/show_bug.cgi?id=19628 - -enum ice19628a = int4.init[0]; -enum ice19628b = int4.init.array[0]; -enum ice19628c = (cast(int[4])int4.init.array)[0]; -enum ice19628d = (cast(int[4])int4.init)[0]; - -enum int4 v19628a = int4.init; -enum idx19628a = v19628a[0]; -static assert(idx19628a == 0); - -enum int[4] v19628b = int4.init.array; -enum idx19628b = v19628b[0]; -static assert(idx19628b == 0); - -enum int[4] v19628c = cast(int[4])int4.init.array; -enum idx19628c = v19628c[0]; -static assert(idx19628c == 0); - -enum int[4] v19628d = cast(int[4])int4.init; -enum idx19628d = v19628d[0]; -static assert(idx19628d == 0); - -immutable int4 v19628e = int4.init; -immutable idx19628e = v19628e[0]; -static assert(idx19628e == 0); - -immutable int[4] v19628f = int4.init.array; -immutable idx19628f = v19628f[0]; -static assert(idx19628f == 0); - -immutable int[4] v19628g = cast(int[4])int4.init.array; -immutable idx19628g = v19628g[0]; -static assert(idx19628g == 0); - -immutable idx19628h = v19628h[0]; -immutable int[4] v19628h = cast(int[4])int4.init; -static assert(idx19628h == 0); - -/*****************************************/ -// https://issues.dlang.org/show_bug.cgi?id=19629 - -enum fail19629a = int4(0)[0]; -enum fail19629b = int4(0).array[0]; -enum fail19629c = (cast(int[4])int4(0).array)[0]; -enum fail19628d = (cast(int[4])int4(0))[0]; - -enum int4 v19629a = int4(0); -enum idx19629a = v19629a[0]; -static assert(idx19629a == 0); - -enum int[4] v19629b = int4(0).array; -enum idx19629b = v19629b[0]; -static assert(idx19629b == 0); - -enum int[4] v19629c = cast(int[4])int4(0).array; -enum idx19629c = v19629c[0]; -static assert(idx19629c == 0); - -enum int[4] v19629d = cast(int[4])int4(0); -enum idx19629d = v19629d[0]; -static assert(idx19629d == 0); - -immutable int4 v19629e = int4(0); -immutable idx19629e = v19629e[0]; -static assert(idx19629e == 0); - -immutable int[4] v19629f = int4(0).array; -immutable idx19629f = v19629f[0]; -static assert(idx19629f == 0); - -immutable int[4] v19629g = cast(int[4])int4(0).array; -immutable idx19629g = v19629g[0]; -static assert(idx19629g == 0); - -immutable int[4] v19629h = cast(int[4])int4(0); -immutable idx19629h = v19629h[0]; -static assert(idx19629h == 0); - -/*****************************************/ -// https://issues.dlang.org/show_bug.cgi?id=19630 - -enum fail19630a = int4.init[1..2]; -enum fail19630b = int4.init.array[1..2]; -enum fail19630c = (cast(int[4])int4.init.array)[1..2]; -enum fail19630d = (cast(int[4])int4.init)[1..2]; -enum fail19630e = int4(0)[1..2]; -enum fail19630f = int4(0).array[1..2]; -enum fail19630g = (cast(int[4])int4(0).array)[1..2]; -enum fail19630h = (cast(int[4])int4(0))[1..2]; - -enum int4 v19630a = int4.init; -enum slice19630a = v19630a[1..2]; -static assert(slice19630a == [0]); - -enum int[4] v19630b = int4.init.array; -enum slice19630b = v19630b[1..2]; -static assert(slice19630b == [0]); - -enum int[4] v19630c = cast(int[4])int4.init.array; -enum slice19630c = v19630c[1..2]; -static assert(slice19630c == [0]); - -enum int[4] v19630d = cast(int[4])int4.init; -enum slice19630d = v19630d[1..2]; -static assert(slice19630d == [0]); - -enum int4 v19630e = int4(0); -enum slice19630e = v19630e[1..2]; -static assert(slice19630e == [0]); - -enum int[4] v19630f = int4(0).array; -enum slice19630f = v19630f[1..2]; -static assert(slice19630f == [0]); - -enum int[4] v19630g = cast(int[4])int4(0).array; -enum slice19630g = v19630g[1..2]; -static assert(slice19630g == [0]); - -enum int[4] v19630h = cast(int[4])int4(0); -enum slice19630h = v19630h[1..2]; -static assert(slice19630h == [0]); - -immutable int4 v19630i = int4.init; -immutable slice19630i = v19630i[1..2]; -static assert(slice19630i == [0]); - -immutable int[4] v19630j = int4.init.array; -immutable slice19630j = v19630j[1..2]; -static assert(slice19630j == [0]); - -immutable int[4] v19630k = cast(int[4])int4.init.array; -immutable slice19630k = v19630k[1..2]; -static assert(slice19630k == [0]); - -immutable int[4] v19630l = cast(int[4])int4.init; -immutable slice19630l = v19630l[1..2]; -static assert(slice19630l == [0]); - -immutable int4 v19630m = int4(0); -immutable slice19630m = v19630m[1..2]; -static assert(slice19630m == [0]); - -immutable int[4] v19630n = int4(0).array; -immutable slice19630n = v19630n[1..2]; -static assert(slice19630n == [0]); - -immutable int[4] v19630o = cast(int[4])int4(0).array; -immutable slice19630o = v19630o[1..2]; -static assert(slice19630o == [0]); - -immutable int[4] v19630p = cast(int[4])int4(0); -immutable slice19630p = v19630p[1..2]; -static assert(slice19630p == [0]); - -/*****************************************/ - -int main() -{ - test1(); - test2(); - test2b(); - test2c(); - test2d(); - test2e(); - test2f(); - test2g(); - test2h(); - test2i(); - test2j(); - - test4(); - test7411(); - - test7951(); - test7951_2(); - test7414(); - test7413(); - test7413_2(); - test9200(); - test9304(); - test9910(); - test12852(); - test9449(); - test9449_2(); - test13988(); - test16448(); - test16448_32(); - test16703(); - testOPvecunsto(); - test10447(); - - test19223(); - test19607(); - - return 0; -} diff --git a/gcc/testsuite/gdc.dg/simd1.d b/gcc/testsuite/gdc.dg/simd1.d new file mode 100644 index 00000000000..374dcae5e94 --- /dev/null +++ b/gcc/testsuite/gdc.dg/simd1.d @@ -0,0 +1,71 @@ +// { dg-additional-options "-mavx" { target avx_runtime } } +// { dg-do compile { target { avx_runtime || vect_sizes_16B_8B } } } +import core.simd; + +void test1() +{ + void16 v1 = void,v2 = void; + byte16 b; + v2 = b; + v1 = v2; + static assert(!__traits(compiles, v1 + v2)); + static assert(!__traits(compiles, v1 - v2)); + static assert(!__traits(compiles, v1 * v2)); + static assert(!__traits(compiles, v1 / v2)); + static assert(!__traits(compiles, v1 % v2)); + static assert(!__traits(compiles, v1 & v2)); + static assert(!__traits(compiles, v1 | v2)); + static assert(!__traits(compiles, v1 ^ v2)); + static assert(!__traits(compiles, v1 ~ v2)); + static assert(!__traits(compiles, v1 ^^ v2)); + static assert(!__traits(compiles, v1 is v2)); + static assert(!__traits(compiles, v1 !is v2)); + static assert(!__traits(compiles, v1 == v2)); + static assert(!__traits(compiles, v1 != v2)); + static assert(!__traits(compiles, v1 < v2)); + static assert(!__traits(compiles, v1 > v2)); + static assert(!__traits(compiles, v1 <= v2)); + static assert(!__traits(compiles, v1 >= v2)); + static assert(!__traits(compiles, v1 <> v2)); + static assert(!__traits(compiles, v1 !< v2)); + static assert(!__traits(compiles, v1 !> v2)); + static assert(!__traits(compiles, v1 !<> v2)); + static assert(!__traits(compiles, v1 <>= v2)); + static assert(!__traits(compiles, v1 !<= v2)); + static assert(!__traits(compiles, v1 !>= v2)); + static assert(!__traits(compiles, v1 !<>= v2)); + static assert(!__traits(compiles, v1 << 1)); + static assert(!__traits(compiles, v1 >> 1)); + static assert(!__traits(compiles, v1 >>> 1)); + static assert(!__traits(compiles, v1 && v2)); + static assert(!__traits(compiles, v1 || v2)); + static assert(!__traits(compiles, ~v1)); + static assert(!__traits(compiles, -v1)); + static assert(!__traits(compiles, +v1)); + static assert(!__traits(compiles, !v1)); + + static assert(!__traits(compiles, v1 += v2)); + static assert(!__traits(compiles, v1 -= v2)); + static assert(!__traits(compiles, v1 *= v2)); + static assert(!__traits(compiles, v1 /= v2)); + static assert(!__traits(compiles, v1 %= v2)); + static assert(!__traits(compiles, v1 &= v2)); + static assert(!__traits(compiles, v1 |= v2)); + static assert(!__traits(compiles, v1 ^= v2)); + static assert(!__traits(compiles, v1 ~= v2)); + static assert(!__traits(compiles, v1 ^^= v2)); + static assert(!__traits(compiles, v1 <<= 1)); + static assert(!__traits(compiles, v1 >>= 1)); + static assert(!__traits(compiles, v1 >>>= 1)); + + // A cast from vector to non-vector is allowed only when the target is same size Tsarray. + static assert(!__traits(compiles, cast(byte)v1)); // 1byte + static assert(!__traits(compiles, cast(short)v1)); // 2byte + static assert(!__traits(compiles, cast(int)v1)); // 4byte + static assert(!__traits(compiles, cast(long)v1)); // 8byte + static assert(!__traits(compiles, cast(float)v1)); // 4byte + static assert(!__traits(compiles, cast(double)v1)); // 8byte + static assert(!__traits(compiles, cast(int[2])v1)); // 8byte Tsarray + static assert( __traits(compiles, cast(int[4])v1)); // 16byte Tsarray, OK + static assert( __traits(compiles, cast(long[2])v1)); // 16byte Tsarray, OK +} diff --git a/gcc/testsuite/gdc.dg/simd10447.d b/gcc/testsuite/gdc.dg/simd10447.d new file mode 100644 index 00000000000..e0064c42306 --- /dev/null +++ b/gcc/testsuite/gdc.dg/simd10447.d @@ -0,0 +1,11 @@ +// https://issues.dlang.org/show_bug.cgi?id=10447 +// { dg-additional-options "-mavx" { target avx_runtime } } +// { dg-do compile { target { avx_runtime || vect_sizes_16B_8B } } } + +void test10447() +{ + immutable __vector(double[2]) a = [1.0, 2.0]; + __vector(double[2]) r; + r += a; + r = r * a; +} diff --git a/gcc/testsuite/gdc.dg/simd12776.d b/gcc/testsuite/gdc.dg/simd12776.d new file mode 100644 index 00000000000..52c10af4c34 --- /dev/null +++ b/gcc/testsuite/gdc.dg/simd12776.d @@ -0,0 +1,25 @@ +// https://issues.dlang.org/show_bug.cgi?id=12776 +// { dg-additional-options "-mavx" { target avx_runtime } } +// { dg-do compile { target { avx_runtime || vect_sizes_16B_8B } } } +import core.simd; + +alias TypeTuple(T...) = T; + +void test12776() +{ + alias Vector16s = TypeTuple!( + void16, byte16, short8, int4, long2, + ubyte16, ushort8, uint4, ulong2, float4, double2); + foreach (V; Vector16s) + { + static assert(is(typeof( V .init) == V )); + static assert(is(typeof( const(V).init) == const(V))); + static assert(is(typeof( inout( V).init) == inout( V))); + static assert(is(typeof( inout(const V).init) == inout(const V))); + static assert(is(typeof(shared( V).init) == shared( V))); + static assert(is(typeof(shared( const V).init) == shared( const V))); + static assert(is(typeof(shared(inout V).init) == shared(inout V))); + static assert(is(typeof(shared(inout const V).init) == shared(inout const V))); + static assert(is(typeof( immutable(V).init) == immutable(V))); + } +} diff --git a/gcc/testsuite/gdc.dg/simd13841.d b/gcc/testsuite/gdc.dg/simd13841.d new file mode 100644 index 00000000000..1e75026b523 --- /dev/null +++ b/gcc/testsuite/gdc.dg/simd13841.d @@ -0,0 +1,29 @@ +// https://issues.dlang.org/show_bug.cgi?id=13841 +// { dg-additional-options "-mavx" { target avx_runtime } } +// { dg-do compile { target { avx_runtime || vect_sizes_16B_8B } } } +import core.simd; + +alias TypeTuple(T...) = T; + +void test13841() +{ + alias Vector16s = TypeTuple!( + void16, byte16, short8, int4, long2, + ubyte16, ushort8, uint4, ulong2, float4, double2); + foreach (V1; Vector16s) + { + foreach (V2; Vector16s) + { + V1 v1 = void; + V2 v2 = void; + static if (is(V1 == V2)) + { + static assert( is(typeof(true ? v1 : v2) == V1)); + } + else + { + static assert(!is(typeof(true ? v1 : v2))); + } + } + } +} diff --git a/gcc/testsuite/gdc.dg/simd13927.d b/gcc/testsuite/gdc.dg/simd13927.d new file mode 100644 index 00000000000..7fad993872b --- /dev/null +++ b/gcc/testsuite/gdc.dg/simd13927.d @@ -0,0 +1,10 @@ +// https://issues.dlang.org/show_bug.cgi?id=13927 +// { dg-additional-options "-mavx" { target avx_runtime } } +// { dg-do compile { target { avx_runtime || vect_sizes_16B_8B } } } +import core.simd; + +void test13927(ulong2 a) +{ + ulong2 b = [long.min, long.min]; + auto tmp = a - b; +} diff --git a/gcc/testsuite/gdc.dg/simd13927b.d b/gcc/testsuite/gdc.dg/simd13927b.d new file mode 100644 index 00000000000..fbbaf867cd8 --- /dev/null +++ b/gcc/testsuite/gdc.dg/simd13927b.d @@ -0,0 +1,12 @@ +// https://issues.dlang.org/show_bug.cgi?id=13927 +// { dg-additional-options "-mavx" { target avx_runtime } } +// { dg-do compile { target { avx_runtime || vect_sizes_16B_8B } } } +import core.simd; + +alias double8 = __vector(double[8]); + +void test13927(double8 a) +{ + double8 b = [long.min, long.min, long.max, long.max]; + auto tmp = a - b; +} diff --git a/gcc/testsuite/gdc.dg/simd15123.d b/gcc/testsuite/gdc.dg/simd15123.d new file mode 100644 index 00000000000..b3ec16c4e6a --- /dev/null +++ b/gcc/testsuite/gdc.dg/simd15123.d @@ -0,0 +1,17 @@ +// https://issues.dlang.org/show_bug.cgi?id=15123 +// { dg-additional-options "-mavx" { target avx_runtime } } +// { dg-do compile { target { avx_runtime || vect_sizes_16B_8B } } } +import core.simd; + +alias TypeTuple(T...) = T; + +void test15123() +{ + alias Vector16s = TypeTuple!( + void16, byte16, short8, int4, long2, + ubyte16, ushort8, uint4, ulong2, float4, double2); + foreach (V; Vector16s) + { + auto x = V.init; + } +} diff --git a/gcc/testsuite/gdc.dg/simd15144.d b/gcc/testsuite/gdc.dg/simd15144.d new file mode 100644 index 00000000000..80e0748361d --- /dev/null +++ b/gcc/testsuite/gdc.dg/simd15144.d @@ -0,0 +1,11 @@ +// https://issues.dlang.org/show_bug.cgi?id=15144 +// { dg-additional-options "-mavx" { target avx_runtime } } +// { dg-do compile { target { avx_runtime || vect_sizes_16B_8B } } } +import core.simd; + +void test15144() +{ + enum ubyte16 csXMM1 = ['a','b','c',0,0,0,0,0]; + __gshared ubyte16 csXMM2 = ['a','b','c',0,0,0,0,0]; + immutable ubyte16 csXMM3 = ['a','b','c',0,0,0,0,0]; +} diff --git a/gcc/testsuite/gdc.dg/simd16087.d b/gcc/testsuite/gdc.dg/simd16087.d new file mode 100644 index 00000000000..b4a5823f4d8 --- /dev/null +++ b/gcc/testsuite/gdc.dg/simd16087.d @@ -0,0 +1,98 @@ +// https://issues.dlang.org/show_bug.cgi?id=16087 +// { dg-do compile } +import core.simd; + +static if (__traits(compiles, void8)) static assert(void8.alignof == 8); +static if (__traits(compiles, double1)) static assert(double1.alignof == 8); +static if (__traits(compiles, float2)) static assert(float2.alignof == 8); +static if (__traits(compiles, byte8)) static assert(byte8.alignof == 8); +static if (__traits(compiles, ubyte8)) static assert(ubyte8.alignof == 8); +static if (__traits(compiles, short4)) static assert(short4.alignof == 8); +static if (__traits(compiles, ushort4)) static assert(ushort4.alignof == 8); +static if (__traits(compiles, int2)) static assert(int2.alignof == 8); +static if (__traits(compiles, uint2)) static assert(uint2.alignof == 8); +static if (__traits(compiles, long1)) static assert(long1.alignof == 8); +static if (__traits(compiles, ulong1)) static assert(ulong1.alignof == 8); + +static if (__traits(compiles, void8)) static assert(void8.sizeof == 8); +static if (__traits(compiles, double1)) static assert(double1.sizeof == 8); +static if (__traits(compiles, float2)) static assert(float2.sizeof == 8); +static if (__traits(compiles, byte8)) static assert(byte8.sizeof == 8); +static if (__traits(compiles, ubyte8)) static assert(ubyte8.sizeof == 8); +static if (__traits(compiles, short4)) static assert(short4.sizeof == 8); +static if (__traits(compiles, ushort4)) static assert(ushort4.sizeof == 8); +static if (__traits(compiles, int2)) static assert(int2.sizeof == 8); +static if (__traits(compiles, uint2)) static assert(uint2.sizeof == 8); +static if (__traits(compiles, long1)) static assert(long1.sizeof == 8); +static if (__traits(compiles, ulong1)) static assert(ulong1.sizeof == 8); + +static if (__traits(compiles, void16)) static assert(void16.alignof == 16); +static if (__traits(compiles, double2)) static assert(double2.alignof == 16); +static if (__traits(compiles, float4)) static assert(float4.alignof == 16); +static if (__traits(compiles, byte16)) static assert(byte16.alignof == 16); +static if (__traits(compiles, ubyte16)) static assert(ubyte16.alignof == 16); +static if (__traits(compiles, short8)) static assert(short8.alignof == 16); +static if (__traits(compiles, ushort8)) static assert(ushort8.alignof == 16); +static if (__traits(compiles, int4)) static assert(int4.alignof == 16); +static if (__traits(compiles, uint4)) static assert(uint4.alignof == 16); +static if (__traits(compiles, long2)) static assert(long2.alignof == 16); +static if (__traits(compiles, ulong2)) static assert(ulong2.alignof == 16); + +static if (__traits(compiles, void16)) static assert(void16.sizeof == 16); +static if (__traits(compiles, double2)) static assert(double2.sizeof == 16); +static if (__traits(compiles, float4)) static assert(float4.sizeof == 16); +static if (__traits(compiles, byte16)) static assert(byte16.sizeof == 16); +static if (__traits(compiles, ubyte16)) static assert(ubyte16.sizeof == 16); +static if (__traits(compiles, short8)) static assert(short8.sizeof == 16); +static if (__traits(compiles, ushort8)) static assert(ushort8.sizeof == 16); +static if (__traits(compiles, int4)) static assert(int4.sizeof == 16); +static if (__traits(compiles, uint4)) static assert(uint4.sizeof == 16); +static if (__traits(compiles, long2)) static assert(long2.sizeof == 16); +static if (__traits(compiles, ulong2)) static assert(ulong2.sizeof == 16); +static if (__traits(compiles, void32)) static assert(void32.alignof == 32); +static if (__traits(compiles, double4)) static assert(double4.alignof == 32); +static if (__traits(compiles, float8)) static assert(float8.alignof == 32); +static if (__traits(compiles, byte32)) static assert(byte32.alignof == 32); +static if (__traits(compiles, ubyte32)) static assert(ubyte32.alignof == 32); +static if (__traits(compiles, short16)) static assert(short16.alignof == 32); +static if (__traits(compiles, ushort16)) static assert(ushort16.alignof == 32); +static if (__traits(compiles, int8)) static assert(int8.alignof == 32); +static if (__traits(compiles, uint8)) static assert(uint8.alignof == 32); +static if (__traits(compiles, long4)) static assert(long4.alignof == 32); +static if (__traits(compiles, ulong4)) static assert(ulong4.alignof == 32); + +static if (__traits(compiles, void32)) static assert(void32.sizeof == 32); +static if (__traits(compiles, double4)) static assert(double4.sizeof == 32); +static if (__traits(compiles, float8)) static assert(float8.sizeof == 32); +static if (__traits(compiles, byte32)) static assert(byte32.sizeof == 32); +static if (__traits(compiles, ubyte32)) static assert(ubyte32.sizeof == 32); +static if (__traits(compiles, short16)) static assert(short16.sizeof == 32); +static if (__traits(compiles, ushort16)) static assert(ushort16.sizeof == 32); +static if (__traits(compiles, int8)) static assert(int8.sizeof == 32); +static if (__traits(compiles, uint8)) static assert(uint8.sizeof == 32); +static if (__traits(compiles, long4)) static assert(long4.sizeof == 32); +static if (__traits(compiles, ulong4)) static assert(ulong4.sizeof == 32); + +static if (__traits(compiles, void64)) static assert(void64.alignof == 64); +static if (__traits(compiles, double8)) static assert(double8.alignof == 64); +static if (__traits(compiles, float16)) static assert(float16.alignof == 64); +static if (__traits(compiles, byte64)) static assert(byte64.alignof == 64); +static if (__traits(compiles, ubyte64)) static assert(ubyte64.alignof == 64); +static if (__traits(compiles, short32)) static assert(short32.alignof == 64); +static if (__traits(compiles, ushort32)) static assert(ushort32.alignof == 64); +static if (__traits(compiles, int16)) static assert(int16.alignof == 64); +static if (__traits(compiles, uint16)) static assert(uint16.alignof == 64); +static if (__traits(compiles, long8)) static assert(long8.alignof == 64); +static if (__traits(compiles, ulong8)) static assert(ulong8.alignof == 64); + +static if (__traits(compiles, void64)) static assert(void64.sizeof == 64); +static if (__traits(compiles, double8)) static assert(double8.sizeof == 64); +static if (__traits(compiles, float16)) static assert(float16.sizeof == 64); +static if (__traits(compiles, byte64)) static assert(byte64.sizeof == 64); +static if (__traits(compiles, ubyte64)) static assert(ubyte64.sizeof == 64); +static if (__traits(compiles, short32)) static assert(short32.sizeof == 64); +static if (__traits(compiles, ushort32)) static assert(ushort32.sizeof == 64); +static if (__traits(compiles, int16)) static assert(int16.sizeof == 64); +static if (__traits(compiles, uint16)) static assert(uint16.sizeof == 64); +static if (__traits(compiles, long8)) static assert(long8.sizeof == 64); +static if (__traits(compiles, ulong8)) static assert(ulong8.sizeof == 64); diff --git a/gcc/testsuite/gdc.dg/simd16697.d b/gcc/testsuite/gdc.dg/simd16697.d new file mode 100644 index 00000000000..8ef343d153f --- /dev/null +++ b/gcc/testsuite/gdc.dg/simd16697.d @@ -0,0 +1,12 @@ +// https://issues.dlang.org/show_bug.cgi?id=16697 +// { dg-additional-options "-mavx" { target avx_runtime } } +// { dg-do compile { target { avx_runtime || vect_sizes_16B_8B } } } + +static assert(!is(float == __vector)); +static assert(!is(float[1] == __vector)); +static assert(!is(float[4] == __vector)); +static assert( is(__vector(float[4]) == __vector)); +static assert(!is(__vector(float[3]) == __vector)); +static assert(!is(__vector(float[5]) == __vector)); +static assert( is(__vector(float[4]) X == __vector) && is(X == float[4])); +static assert( is(__vector(byte[16]) X == __vector) && is(X == byte[16])); diff --git a/gcc/testsuite/gdc.dg/simd17237.d b/gcc/testsuite/gdc.dg/simd17237.d new file mode 100644 index 00000000000..a9832357094 --- /dev/null +++ b/gcc/testsuite/gdc.dg/simd17237.d @@ -0,0 +1,18 @@ +// https://issues.dlang.org/show_bug.cgi?id=17237 +// { dg-additional-options "-mavx2" { target avx2_runtime } } +// { dg-do compile { target { avx2_runtime || vect_sizes_32B_16B } } } +import core.simd; + +struct S17237 +{ + bool a; + struct + { + bool b; + int8 c; + } +} + +static assert(S17237.a.offsetof == 0); +static assert(S17237.b.offsetof == 32); +static assert(S17237.c.offsetof == 64); diff --git a/gcc/testsuite/gdc.dg/simd17695.d b/gcc/testsuite/gdc.dg/simd17695.d new file mode 100644 index 00000000000..5d45584712c --- /dev/null +++ b/gcc/testsuite/gdc.dg/simd17695.d @@ -0,0 +1,8 @@ +// https://issues.dlang.org/show_bug.cgi?id=17695 +// { dg-additional-options "-mavx" { target avx_runtime } } +// { dg-do compile { target { avx_runtime || vect_sizes_16B_8B } } } + +void test17695(__vector(ubyte[16]) a) +{ + auto b = -a; +} diff --git a/gcc/testsuite/gdc.dg/simd17720a.d b/gcc/testsuite/gdc.dg/simd17720a.d new file mode 100644 index 00000000000..d1608969f7b --- /dev/null +++ b/gcc/testsuite/gdc.dg/simd17720a.d @@ -0,0 +1,43 @@ +// https://issues.dlang.org/show_bug.cgi?id=17720 +// { dg-additional-options "-mavx" { target avx_runtime } } +// { dg-do compile { target { avx_runtime || vect_sizes_16B_8B } } } +import core.simd; + +alias TypeTuple(T...) = T; + +void test17720() +{ + alias Vector16s = TypeTuple!( + void16, byte16, short8, int4, long2, + ubyte16, ushort8, uint4, ulong2, float4, double2); + + // OK: __vector(T) -> __vector(void[]) of same size. + // NG: __vector(T) -> __vector(void[]) of different size. + // NG: explicit cast __vector(T) -> __vector(void[]) of different size. + foreach (V; Vector16s) + { + static assert( __traits(compiles, { void16 v = V.init; })); + static assert(!__traits(compiles, { void32 v = V.init; })); + static assert(!__traits(compiles, { void32 v = cast(void32)V.init; })); + } + + // NG: __vector(T) -> __vector(T) of same size. + // OK: explicit cast __vector(T) -> __vector(T) of same size. + // NG: __vector(T) -> __vector(T) of different size. + // NG: explicit cast __vector(T) -> __vector(T) of different size. + foreach (V; Vector16s) + { + static if (is(V == double2)) + { + static assert(!__traits(compiles, { long2 v = V.init; })); + static assert( __traits(compiles, { long2 v = cast(long2)V.init; })); + } + else + { + static assert(!__traits(compiles, { double2 v = V.init; })); + static assert( __traits(compiles, { double2 v = cast(double2)V.init; })); + } + static assert(!__traits(compiles, { double4 v = V.init; })); + static assert(!__traits(compiles, { double4 v = cast(double4)V.init; })); + } +} diff --git a/gcc/testsuite/gdc.dg/simd17720b.d b/gcc/testsuite/gdc.dg/simd17720b.d new file mode 100644 index 00000000000..c0d4153fca0 --- /dev/null +++ b/gcc/testsuite/gdc.dg/simd17720b.d @@ -0,0 +1,43 @@ +// https://issues.dlang.org/show_bug.cgi?id=17720 +// { dg-additional-options "-mavx2" { target avx2_runtime } } +// { dg-do compile { target { avx2_runtime || vect_sizes_32B_16B } } } +import core.simd; + +alias TypeTuple(T...) = T; + +void test17720() +{ + alias Vector32s = TypeTuple!( + void32, byte32, short16, int8, long4, + ubyte32, ushort16, uint8, ulong4, float8, double4); + + // OK: __vector(T) -> __vector(void[]) of same size. + // NG: __vector(T) -> __vector(void[]) of different size. + // NG: explicit cast __vector(T) -> __vector(void[]) of different size. + foreach (V; Vector32s) + { + static assert( __traits(compiles, { void32 v = V.init; })); + static assert(!__traits(compiles, { void16 v = V.init; })); + static assert(!__traits(compiles, { void16 v = cast(void16)V.init; })); + } + + // NG: __vector(T) -> __vector(T) of same size. + // OK: explicit cast __vector(T) -> __vector(T) of same size. + // NG: __vector(T) -> __vector(T) of different size. + // NG: explicit cast __vector(T) -> __vector(T) of different size. + foreach (V; Vector32s) + { + static if (is(V == double4)) + { + static assert(!__traits(compiles, { long4 v = V.init; })); + static assert( __traits(compiles, { long4 v = cast(long4)V.init; })); + } + else + { + static assert(!__traits(compiles, { double4 v = V.init; })); + static assert( __traits(compiles, { double4 v = cast(double4)V.init; })); + } + static assert(!__traits(compiles, { double2 v = V.init; })); + static assert(!__traits(compiles, { double2 v = cast(double2)V.init; })); + } +} diff --git a/gcc/testsuite/gdc.dg/simd19224.d b/gcc/testsuite/gdc.dg/simd19224.d new file mode 100644 index 00000000000..c9d42aa2af2 --- /dev/null +++ b/gcc/testsuite/gdc.dg/simd19224.d @@ -0,0 +1,17 @@ +// https://issues.dlang.org/show_bug.cgi?id=19224 +// { dg-additional-options "-mavx" { target avx_runtime } } +// { dg-do compile { target { avx_runtime || vect_sizes_16B_8B } } } +import core.simd; + +float test19224(const float[4] val) +{ + float sum = 0; + foreach (x; val) sum += x; + return sum; +} + +enum x19224 = test19224(float4.init.array); +static assert(x19224 is float.nan); + +enum y19224 = test19224(float4(1).array); +static assert(y19224 == 4); diff --git a/gcc/testsuite/gdc.dg/simd19627.d b/gcc/testsuite/gdc.dg/simd19627.d new file mode 100644 index 00000000000..a26bb3642c6 --- /dev/null +++ b/gcc/testsuite/gdc.dg/simd19627.d @@ -0,0 +1,6 @@ +// https://issues.dlang.org/show_bug.cgi?id=19627 +// { dg-additional-options "-mavx" { target avx_runtime } } +// { dg-do compile { target { avx_runtime || vect_sizes_16B_8B } } } +import core.simd; + +enum int[4] fail19627 = cast(int[4])int4(0); diff --git a/gcc/testsuite/gdc.dg/simd19628.d b/gcc/testsuite/gdc.dg/simd19628.d new file mode 100644 index 00000000000..2c5ddf102d2 --- /dev/null +++ b/gcc/testsuite/gdc.dg/simd19628.d @@ -0,0 +1,41 @@ +// https://issues.dlang.org/show_bug.cgi?id=19628 +// { dg-additional-options "-mavx" { target avx_runtime } } +// { dg-do compile { target { avx_runtime || vect_sizes_16B_8B } } } +import core.simd; + +enum ice19628a = int4.init[0]; +enum ice19628b = int4.init.array[0]; +enum ice19628c = (cast(int[4])int4.init.array)[0]; +enum ice19628d = (cast(int[4])int4.init)[0]; + +enum int4 v19628a = int4.init; +enum idx19628a = v19628a[0]; +static assert(idx19628a == 0); + +enum int[4] v19628b = int4.init.array; +enum idx19628b = v19628b[0]; +static assert(idx19628b == 0); + +enum int[4] v19628c = cast(int[4])int4.init.array; +enum idx19628c = v19628c[0]; +static assert(idx19628c == 0); + +enum int[4] v19628d = cast(int[4])int4.init; +enum idx19628d = v19628d[0]; +static assert(idx19628d == 0); + +immutable int4 v19628e = int4.init; +immutable idx19628e = v19628e[0]; +static assert(idx19628e == 0); + +immutable int[4] v19628f = int4.init.array; +immutable idx19628f = v19628f[0]; +static assert(idx19628f == 0); + +immutable int[4] v19628g = cast(int[4])int4.init.array; +immutable idx19628g = v19628g[0]; +static assert(idx19628g == 0); + +immutable idx19628h = v19628h[0]; +immutable int[4] v19628h = cast(int[4])int4.init; +static assert(idx19628h == 0); diff --git a/gcc/testsuite/gdc.dg/simd19629.d b/gcc/testsuite/gdc.dg/simd19629.d new file mode 100644 index 00000000000..7a9e2b71db9 --- /dev/null +++ b/gcc/testsuite/gdc.dg/simd19629.d @@ -0,0 +1,41 @@ +// https://issues.dlang.org/show_bug.cgi?id=19629 +// { dg-additional-options "-mavx" { target avx_runtime } } +// { dg-do compile { target { avx_runtime || vect_sizes_16B_8B } } } +import core.simd; + +enum fail19629a = int4(0)[0]; +enum fail19629b = int4(0).array[0]; +enum fail19629c = (cast(int[4])int4(0).array)[0]; +enum fail19628d = (cast(int[4])int4(0))[0]; + +enum int4 v19629a = int4(0); +enum idx19629a = v19629a[0]; +static assert(idx19629a == 0); + +enum int[4] v19629b = int4(0).array; +enum idx19629b = v19629b[0]; +static assert(idx19629b == 0); + +enum int[4] v19629c = cast(int[4])int4(0).array; +enum idx19629c = v19629c[0]; +static assert(idx19629c == 0); + +enum int[4] v19629d = cast(int[4])int4(0); +enum idx19629d = v19629d[0]; +static assert(idx19629d == 0); + +immutable int4 v19629e = int4(0); +immutable idx19629e = v19629e[0]; +static assert(idx19629e == 0); + +immutable int[4] v19629f = int4(0).array; +immutable idx19629f = v19629f[0]; +static assert(idx19629f == 0); + +immutable int[4] v19629g = cast(int[4])int4(0).array; +immutable idx19629g = v19629g[0]; +static assert(idx19629g == 0); + +immutable int[4] v19629h = cast(int[4])int4(0); +immutable idx19629h = v19629h[0]; +static assert(idx19629h == 0); diff --git a/gcc/testsuite/gdc.dg/simd19630.d b/gcc/testsuite/gdc.dg/simd19630.d new file mode 100644 index 00000000000..0d45d28f47a --- /dev/null +++ b/gcc/testsuite/gdc.dg/simd19630.d @@ -0,0 +1,77 @@ +// https://issues.dlang.org/show_bug.cgi?id=19630 +// { dg-additional-options "-mavx" { target avx_runtime } } +// { dg-do compile { target { avx_runtime || vect_sizes_16B_8B } } } +import core.simd; + +enum fail19630a = int4.init[1..2]; +enum fail19630b = int4.init.array[1..2]; +enum fail19630c = (cast(int[4])int4.init.array)[1..2]; +enum fail19630d = (cast(int[4])int4.init)[1..2]; +enum fail19630e = int4(0)[1..2]; +enum fail19630f = int4(0).array[1..2]; +enum fail19630g = (cast(int[4])int4(0).array)[1..2]; +enum fail19630h = (cast(int[4])int4(0))[1..2]; + +enum int4 v19630a = int4.init; +enum slice19630a = v19630a[1..2]; +static assert(slice19630a == [0]); + +enum int[4] v19630b = int4.init.array; +enum slice19630b = v19630b[1..2]; +static assert(slice19630b == [0]); + +enum int[4] v19630c = cast(int[4])int4.init.array; +enum slice19630c = v19630c[1..2]; +static assert(slice19630c == [0]); + +enum int[4] v19630d = cast(int[4])int4.init; +enum slice19630d = v19630d[1..2]; +static assert(slice19630d == [0]); + +enum int4 v19630e = int4(0); +enum slice19630e = v19630e[1..2]; +static assert(slice19630e == [0]); + +enum int[4] v19630f = int4(0).array; +enum slice19630f = v19630f[1..2]; +static assert(slice19630f == [0]); + +enum int[4] v19630g = cast(int[4])int4(0).array; +enum slice19630g = v19630g[1..2]; +static assert(slice19630g == [0]); + +enum int[4] v19630h = cast(int[4])int4(0); +enum slice19630h = v19630h[1..2]; +static assert(slice19630h == [0]); + +immutable int4 v19630i = int4.init; +immutable slice19630i = v19630i[1..2]; +static assert(slice19630i == [0]); + +immutable int[4] v19630j = int4.init.array; +immutable slice19630j = v19630j[1..2]; +static assert(slice19630j == [0]); + +immutable int[4] v19630k = cast(int[4])int4.init.array; +immutable slice19630k = v19630k[1..2]; +static assert(slice19630k == [0]); + +immutable int[4] v19630l = cast(int[4])int4.init; +immutable slice19630l = v19630l[1..2]; +static assert(slice19630l == [0]); + +immutable int4 v19630m = int4(0); +immutable slice19630m = v19630m[1..2]; +static assert(slice19630m == [0]); + +immutable int[4] v19630n = int4(0).array; +immutable slice19630n = v19630n[1..2]; +static assert(slice19630n == [0]); + +immutable int[4] v19630o = cast(int[4])int4(0).array; +immutable slice19630o = v19630o[1..2]; +static assert(slice19630o == [0]); + +immutable int[4] v19630p = cast(int[4])int4(0); +immutable slice19630p = v19630p[1..2]; +static assert(slice19630p == [0]); diff --git a/gcc/testsuite/gdc.dg/simd2a.d b/gcc/testsuite/gdc.dg/simd2a.d new file mode 100644 index 00000000000..b630a473b18 --- /dev/null +++ b/gcc/testsuite/gdc.dg/simd2a.d @@ -0,0 +1,69 @@ +// { dg-additional-options "-mavx" { target avx_runtime } } +// { dg-do compile { target { avx_runtime || vect_sizes_16B_8B } } } +import core.simd; + +void test2a() +{ + byte16 v1, v2 = 1, v3 = 1; + v1 = v2; + v1 = v2 + v3; + v1 = v2 - v3; + v1 = v2 * v3; + v1 = v2 / v3; + v1 = v2 % v3; + v1 = v2 & v3; + v1 = v2 | v3; + v1 = v2 ^ v3; + static assert(!__traits(compiles, v1 ~ v2)); + static assert(!__traits(compiles, v1 ^^ v2)); + static assert(!__traits(compiles, v1 is v2)); + static assert(!__traits(compiles, v1 !is v2)); + static assert(!__traits(compiles, v1 == v2)); + static assert(!__traits(compiles, v1 != v2)); + static assert(!__traits(compiles, v1 < v2)); + static assert(!__traits(compiles, v1 > v2)); + static assert(!__traits(compiles, v1 <= v2)); + static assert(!__traits(compiles, v1 >= v2)); + static assert(!__traits(compiles, v1 <> v2)); + static assert(!__traits(compiles, v1 !< v2)); + static assert(!__traits(compiles, v1 !> v2)); + static assert(!__traits(compiles, v1 !<> v2)); + static assert(!__traits(compiles, v1 <>= v2)); + static assert(!__traits(compiles, v1 !<= v2)); + static assert(!__traits(compiles, v1 !>= v2)); + static assert(!__traits(compiles, v1 !<>= v2)); + v1 = v2 << 1; + v1 = v2 >> 1; + v1 = v2 >>> 1; + static assert(!__traits(compiles, v1 && v2)); + static assert(!__traits(compiles, v1 || v2)); + v1 = ~v2; + v1 = -v2; + v1 = +v2; + static assert(!__traits(compiles, !v1)); + + v1 += v2; + v1 -= v2; + v1 *= v2; + v1 /= v2; + v1 %= v2; + v1 &= v2; + v1 |= v2; + v1 ^= v2; + static assert(!__traits(compiles, v1 ~= v2)); + static assert(!__traits(compiles, v1 ^^= v2)); + v1 <<= 1; + v1 >>= 1; + v1 >>>= 1; + + // A cast from vector to non-vector is allowed only when the target is same size Tsarray. + static assert(!__traits(compiles, cast(byte)v1)); // 1byte + static assert(!__traits(compiles, cast(short)v1)); // 2byte + static assert(!__traits(compiles, cast(int)v1)); // 4byte + static assert(!__traits(compiles, cast(long)v1)); // 8byte + static assert(!__traits(compiles, cast(float)v1)); // 4byte + static assert(!__traits(compiles, cast(double)v1)); // 8byte + static assert(!__traits(compiles, cast(int[2])v1)); // 8byte Tsarray + static assert( __traits(compiles, cast(int[4])v1)); // 16byte Tsarray, OK + static assert( __traits(compiles, cast(long[2])v1)); // 16byte Tsarray, OK +} diff --git a/gcc/testsuite/gdc.dg/simd2b.d b/gcc/testsuite/gdc.dg/simd2b.d new file mode 100644 index 00000000000..35c42880ce2 --- /dev/null +++ b/gcc/testsuite/gdc.dg/simd2b.d @@ -0,0 +1,69 @@ +// { dg-additional-options "-mavx" { target avx_runtime } } +// { dg-do compile { target { avx_runtime || vect_sizes_16B_8B } } } +import core.simd; + +void test2b() +{ + ubyte16 v1, v2 = 1, v3 = 1; + v1 = v2; + v1 = v2 + v3; + v1 = v2 - v3; + v1 = v2 * v3; + v1 = v2 / v3; + v1 = v2 % v3; + v1 = v2 & v3; + v1 = v2 | v3; + v1 = v2 ^ v3; + static assert(!__traits(compiles, v1 ~ v2)); + static assert(!__traits(compiles, v1 ^^ v2)); + static assert(!__traits(compiles, v1 is v2)); + static assert(!__traits(compiles, v1 !is v2)); + static assert(!__traits(compiles, v1 == v2)); + static assert(!__traits(compiles, v1 != v2)); + static assert(!__traits(compiles, v1 < v2)); + static assert(!__traits(compiles, v1 > v2)); + static assert(!__traits(compiles, v1 <= v2)); + static assert(!__traits(compiles, v1 >= v2)); + static assert(!__traits(compiles, v1 <> v2)); + static assert(!__traits(compiles, v1 !< v2)); + static assert(!__traits(compiles, v1 !> v2)); + static assert(!__traits(compiles, v1 !<> v2)); + static assert(!__traits(compiles, v1 <>= v2)); + static assert(!__traits(compiles, v1 !<= v2)); + static assert(!__traits(compiles, v1 !>= v2)); + static assert(!__traits(compiles, v1 !<>= v2)); + v1 = v2 << 1; + v1 = v2 >> 1; + v1 = v2 >>> 1; + static assert(!__traits(compiles, v1 && v2)); + static assert(!__traits(compiles, v1 || v2)); + v1 = ~v2; + v1 = -v2; + v1 = +v2; + static assert(!__traits(compiles, !v1)); + + v1 += v2; + v1 -= v2; + v1 *= v2; + v1 /= v2; + v1 %= v2; + v1 &= v2; + v1 |= v2; + v1 ^= v2; + static assert(!__traits(compiles, v1 ~= v2)); + static assert(!__traits(compiles, v1 ^^= v2)); + v1 <<= 1; + v1 >>= 1; + v1 >>>= 1; + + // A cast from vector to non-vector is allowed only when the target is same size Tsarray. + static assert(!__traits(compiles, cast(byte)v1)); // 1byte + static assert(!__traits(compiles, cast(short)v1)); // 2byte + static assert(!__traits(compiles, cast(int)v1)); // 4byte + static assert(!__traits(compiles, cast(long)v1)); // 8byte + static assert(!__traits(compiles, cast(float)v1)); // 4byte + static assert(!__traits(compiles, cast(double)v1)); // 8byte + static assert(!__traits(compiles, cast(int[2])v1)); // 8byte Tsarray + static assert( __traits(compiles, cast(int[4])v1)); // 16byte Tsarray, OK + static assert( __traits(compiles, cast(long[2])v1)); // 16byte Tsarray, OK +} diff --git a/gcc/testsuite/gdc.dg/simd2c.d b/gcc/testsuite/gdc.dg/simd2c.d new file mode 100644 index 00000000000..2f19e75a35b --- /dev/null +++ b/gcc/testsuite/gdc.dg/simd2c.d @@ -0,0 +1,70 @@ +// { dg-additional-options "-mavx" { target avx_runtime } } +// { dg-do compile { target { avx_runtime || vect_sizes_16B_8B } } } +import core.simd; + +void test2c() +{ + short8 v1, v2 = 1, v3 = 1; + v1 = v2; + v1 = v2 + v3; + v1 = v2 - v3; + v1 = v2 * v3; + v1 = v2 / v3; + v1 = v2 % v3; + v1 = v2 & v3; + v1 = v2 | v3; + v1 = v2 ^ v3; + static assert(!__traits(compiles, v1 ~ v2)); + static assert(!__traits(compiles, v1 ^^ v2)); + static assert(!__traits(compiles, v1 is v2)); + static assert(!__traits(compiles, v1 !is v2)); + static assert(!__traits(compiles, v1 == v2)); + static assert(!__traits(compiles, v1 != v2)); + static assert(!__traits(compiles, v1 < v2)); + static assert(!__traits(compiles, v1 > v2)); + static assert(!__traits(compiles, v1 <= v2)); + static assert(!__traits(compiles, v1 >= v2)); + static assert(!__traits(compiles, v1 <> v2)); + static assert(!__traits(compiles, v1 !< v2)); + static assert(!__traits(compiles, v1 !> v2)); + static assert(!__traits(compiles, v1 !<> v2)); + static assert(!__traits(compiles, v1 <>= v2)); + static assert(!__traits(compiles, v1 !<= v2)); + static assert(!__traits(compiles, v1 !>= v2)); + static assert(!__traits(compiles, v1 !<>= v2)); + v1 = v2 << 1; + v1 = v2 >> 1; + v1 = v2 >>> 1; + static assert(!__traits(compiles, v1 && v2)); + static assert(!__traits(compiles, v1 || v2)); + v1 = ~v2; + v1 = -v2; + v1 = +v2; + static assert(!__traits(compiles, !v1)); + + v1 += v2; + v1 -= v2; + v1 *= v2; + v1 /= v2; + v1 %= v2; + v1 &= v2; + v1 |= v2; + v1 ^= v2; + static assert(!__traits(compiles, v1 ~= v2)); + static assert(!__traits(compiles, v1 ^^= v2)); + v1 <<= 1; + v1 >>= 1; + v1 >>>= 1; + v1 = v1 * 3; + + // A cast from vector to non-vector is allowed only when the target is same size Tsarray. + static assert(!__traits(compiles, cast(byte)v1)); // 1byte + static assert(!__traits(compiles, cast(short)v1)); // 2byte + static assert(!__traits(compiles, cast(int)v1)); // 4byte + static assert(!__traits(compiles, cast(long)v1)); // 8byte + static assert(!__traits(compiles, cast(float)v1)); // 4byte + static assert(!__traits(compiles, cast(double)v1)); // 8byte + static assert(!__traits(compiles, cast(int[2])v1)); // 8byte Tsarray + static assert( __traits(compiles, cast(int[4])v1)); // 16byte Tsarray, OK + static assert( __traits(compiles, cast(long[2])v1)); // 16byte Tsarray, OK +} diff --git a/gcc/testsuite/gdc.dg/simd2d.d b/gcc/testsuite/gdc.dg/simd2d.d new file mode 100644 index 00000000000..9d378e4cdba --- /dev/null +++ b/gcc/testsuite/gdc.dg/simd2d.d @@ -0,0 +1,69 @@ +// { dg-additional-options "-mavx" { target avx_runtime } } +// { dg-do compile { target { avx_runtime || vect_sizes_16B_8B } } } +import core.simd; + +void test2d() +{ + ushort8 v1, v2 = 1, v3 = 1; + v1 = v2; + v1 = v2 + v3; + v1 = v2 - v3; + v1 = v2 * v3; + v1 = v2 / v3; + v1 = v2 % v3; + v1 = v2 & v3; + v1 = v2 | v3; + v1 = v2 ^ v3; + static assert(!__traits(compiles, v1 ~ v2)); + static assert(!__traits(compiles, v1 ^^ v2)); + static assert(!__traits(compiles, v1 is v2)); + static assert(!__traits(compiles, v1 !is v2)); + static assert(!__traits(compiles, v1 == v2)); + static assert(!__traits(compiles, v1 != v2)); + static assert(!__traits(compiles, v1 < v2)); + static assert(!__traits(compiles, v1 > v2)); + static assert(!__traits(compiles, v1 <= v2)); + static assert(!__traits(compiles, v1 >= v2)); + static assert(!__traits(compiles, v1 <> v2)); + static assert(!__traits(compiles, v1 !< v2)); + static assert(!__traits(compiles, v1 !> v2)); + static assert(!__traits(compiles, v1 !<> v2)); + static assert(!__traits(compiles, v1 <>= v2)); + static assert(!__traits(compiles, v1 !<= v2)); + static assert(!__traits(compiles, v1 !>= v2)); + static assert(!__traits(compiles, v1 !<>= v2)); + v1 = v2 << 1; + v1 = v2 >> 1; + v1 = v2 >>> 1; + static assert(!__traits(compiles, v1 && v2)); + static assert(!__traits(compiles, v1 || v2)); + v1 = ~v2; + v1 = -v2; + v1 = +v2; + static assert(!__traits(compiles, !v1)); + + v1 += v2; + v1 -= v2; + v1 *= v2; + v1 /= v2; + v1 %= v2; + v1 &= v2; + v1 |= v2; + v1 ^= v2; + static assert(!__traits(compiles, v1 ~= v2)); + static assert(!__traits(compiles, v1 ^^= v2)); + v1 <<= 1; + v1 >>= 1; + v1 >>>= 1; + + // A cast from vector to non-vector is allowed only when the target is same size Tsarray. + static assert(!__traits(compiles, cast(byte)v1)); // 1byte + static assert(!__traits(compiles, cast(short)v1)); // 2byte + static assert(!__traits(compiles, cast(int)v1)); // 4byte + static assert(!__traits(compiles, cast(long)v1)); // 8byte + static assert(!__traits(compiles, cast(float)v1)); // 4byte + static assert(!__traits(compiles, cast(double)v1)); // 8byte + static assert(!__traits(compiles, cast(int[2])v1)); // 8byte Tsarray + static assert( __traits(compiles, cast(int[4])v1)); // 16byte Tsarray, OK + static assert( __traits(compiles, cast(long[2])v1)); // 16byte Tsarray, OK +} diff --git a/gcc/testsuite/gdc.dg/simd2e.d b/gcc/testsuite/gdc.dg/simd2e.d new file mode 100644 index 00000000000..30d7c1aa165 --- /dev/null +++ b/gcc/testsuite/gdc.dg/simd2e.d @@ -0,0 +1,69 @@ +// { dg-additional-options "-mavx" { target avx_runtime } } +// { dg-do compile { target { avx_runtime || vect_sizes_16B_8B } } } +import core.simd; + +void test2e() +{ + int4 v1, v2 = 1, v3 = 1; + v1 = v2; + v1 = v2 + v3; + v1 = v2 - v3; + v1 = v2 * v3; + v1 = v2 / v3; + v1 = v2 % v3; + v1 = v2 & v3; + v1 = v2 | v3; + v1 = v2 ^ v3; + static assert(!__traits(compiles, v1 ~ v2)); + static assert(!__traits(compiles, v1 ^^ v2)); + static assert(!__traits(compiles, v1 is v2)); + static assert(!__traits(compiles, v1 !is v2)); + static assert(!__traits(compiles, v1 == v2)); + static assert(!__traits(compiles, v1 != v2)); + static assert(!__traits(compiles, v1 < v2)); + static assert(!__traits(compiles, v1 > v2)); + static assert(!__traits(compiles, v1 <= v2)); + static assert(!__traits(compiles, v1 >= v2)); + static assert(!__traits(compiles, v1 <> v2)); + static assert(!__traits(compiles, v1 !< v2)); + static assert(!__traits(compiles, v1 !> v2)); + static assert(!__traits(compiles, v1 !<> v2)); + static assert(!__traits(compiles, v1 <>= v2)); + static assert(!__traits(compiles, v1 !<= v2)); + static assert(!__traits(compiles, v1 !>= v2)); + static assert(!__traits(compiles, v1 !<>= v2)); + v1 = v2 << 1; + v1 = v2 >> 1; + v1 = v2 >>> 1; + static assert(!__traits(compiles, v1 && v2)); + static assert(!__traits(compiles, v1 || v2)); + v1 = ~v2; + v1 = -v2; + v1 = +v2; + static assert(!__traits(compiles, !v1)); + + v1 += v2; + v1 -= v2; + v1 *= v2; + v1 /= v2; + v1 %= v2; + v1 &= v2; + v1 |= v2; + v1 ^= v2; + static assert(!__traits(compiles, v1 ~= v2)); + static assert(!__traits(compiles, v1 ^^= v2)); + v1 <<= 1; + v1 >>= 1; + v1 >>>= 1; + + // A cast from vector to non-vector is allowed only when the target is same size Tsarray. + static assert(!__traits(compiles, cast(byte)v1)); // 1byte + static assert(!__traits(compiles, cast(short)v1)); // 2byte + static assert(!__traits(compiles, cast(int)v1)); // 4byte + static assert(!__traits(compiles, cast(long)v1)); // 8byte + static assert(!__traits(compiles, cast(float)v1)); // 4byte + static assert(!__traits(compiles, cast(double)v1)); // 8byte + static assert(!__traits(compiles, cast(int[2])v1)); // 8byte Tsarray + static assert( __traits(compiles, cast(int[4])v1)); // 16byte Tsarray, OK + static assert( __traits(compiles, cast(long[2])v1)); // 16byte Tsarray, OK +} diff --git a/gcc/testsuite/gdc.dg/simd2f.d b/gcc/testsuite/gdc.dg/simd2f.d new file mode 100644 index 00000000000..f8448801dba --- /dev/null +++ b/gcc/testsuite/gdc.dg/simd2f.d @@ -0,0 +1,69 @@ +// { dg-additional-options "-mavx" { target avx_runtime } } +// { dg-do compile { target { avx_runtime || vect_sizes_16B_8B } } } +import core.simd; + +void test2f() +{ + uint4 v1, v2 = 1, v3 = 1; + v1 = v2; + v1 = v2 + v3; + v1 = v2 - v3; + v1 = v2 * v3; + v1 = v2 / v3; + v1 = v2 % v3; + v1 = v2 & v3; + v1 = v2 | v3; + v1 = v2 ^ v3; + static assert(!__traits(compiles, v1 ~ v2)); + static assert(!__traits(compiles, v1 ^^ v2)); + static assert(!__traits(compiles, v1 is v2)); + static assert(!__traits(compiles, v1 !is v2)); + static assert(!__traits(compiles, v1 == v2)); + static assert(!__traits(compiles, v1 != v2)); + static assert(!__traits(compiles, v1 < v2)); + static assert(!__traits(compiles, v1 > v2)); + static assert(!__traits(compiles, v1 <= v2)); + static assert(!__traits(compiles, v1 >= v2)); + static assert(!__traits(compiles, v1 <> v2)); + static assert(!__traits(compiles, v1 !< v2)); + static assert(!__traits(compiles, v1 !> v2)); + static assert(!__traits(compiles, v1 !<> v2)); + static assert(!__traits(compiles, v1 <>= v2)); + static assert(!__traits(compiles, v1 !<= v2)); + static assert(!__traits(compiles, v1 !>= v2)); + static assert(!__traits(compiles, v1 !<>= v2)); + v1 = v2 << 1; + v1 = v2 >> 1; + v1 = v2 >>> 1; + static assert(!__traits(compiles, v1 && v2)); + static assert(!__traits(compiles, v1 || v2)); + v1 = ~v2; + v1 = -v2; + v1 = +v2; + static assert(!__traits(compiles, !v1)); + + v1 += v2; + v1 -= v2; + v1 *= v2; + v1 /= v2; + v1 %= v2; + v1 &= v2; + v1 |= v2; + v1 ^= v2; + static assert(!__traits(compiles, v1 ~= v2)); + static assert(!__traits(compiles, v1 ^^= v2)); + v1 <<= 1; + v1 >>= 1; + v1 >>>= 1; + + // A cast from vector to non-vector is allowed only when the target is same size Tsarray. + static assert(!__traits(compiles, cast(byte)v1)); // 1byte + static assert(!__traits(compiles, cast(short)v1)); // 2byte + static assert(!__traits(compiles, cast(int)v1)); // 4byte + static assert(!__traits(compiles, cast(long)v1)); // 8byte + static assert(!__traits(compiles, cast(float)v1)); // 4byte + static assert(!__traits(compiles, cast(double)v1)); // 8byte + static assert(!__traits(compiles, cast(int[2])v1)); // 8byte Tsarray + static assert( __traits(compiles, cast(int[4])v1)); // 16byte Tsarray, OK + static assert( __traits(compiles, cast(long[2])v1)); // 16byte Tsarray, OK +} diff --git a/gcc/testsuite/gdc.dg/simd2g.d b/gcc/testsuite/gdc.dg/simd2g.d new file mode 100644 index 00000000000..8e8bc15623c --- /dev/null +++ b/gcc/testsuite/gdc.dg/simd2g.d @@ -0,0 +1,69 @@ +// { dg-additional-options "-mavx" { target avx_runtime } } +// { dg-do compile { target { avx_runtime || vect_sizes_16B_8B } } } +import core.simd; + +void test2g() +{ + long2 v1, v2 = 1, v3 = 1; + v1 = v2; + v1 = v2 + v3; + v1 = v2 - v3; + v1 = v2 * v3; + v1 = v2 / v3; + v1 = v2 % v3; + v1 = v2 & v3; + v1 = v2 | v3; + v1 = v2 ^ v3; + static assert(!__traits(compiles, v1 ~ v2)); + static assert(!__traits(compiles, v1 ^^ v2)); + static assert(!__traits(compiles, v1 is v2)); + static assert(!__traits(compiles, v1 !is v2)); + static assert(!__traits(compiles, v1 == v2)); + static assert(!__traits(compiles, v1 != v2)); + static assert(!__traits(compiles, v1 < v2)); + static assert(!__traits(compiles, v1 > v2)); + static assert(!__traits(compiles, v1 <= v2)); + static assert(!__traits(compiles, v1 >= v2)); + static assert(!__traits(compiles, v1 <> v2)); + static assert(!__traits(compiles, v1 !< v2)); + static assert(!__traits(compiles, v1 !> v2)); + static assert(!__traits(compiles, v1 !<> v2)); + static assert(!__traits(compiles, v1 <>= v2)); + static assert(!__traits(compiles, v1 !<= v2)); + static assert(!__traits(compiles, v1 !>= v2)); + static assert(!__traits(compiles, v1 !<>= v2)); + v1 = v2 << 1; + v1 = v2 >> 1; + v1 = v2 >>> 1; + static assert(!__traits(compiles, v1 && v2)); + static assert(!__traits(compiles, v1 || v2)); + v1 = ~v2; + v1 = -v2; + v1 = +v2; + static assert(!__traits(compiles, !v1)); + + v1 += v2; + v1 -= v2; + v1 *= v2; + v1 /= v2; + v1 %= v2; + v1 &= v2; + v1 |= v2; + v1 ^= v2; + static assert(!__traits(compiles, v1 ~= v2)); + static assert(!__traits(compiles, v1 ^^= v2)); + v1 <<= 1; + v1 >>= 1; + v1 >>>= 1; + + // A cast from vector to non-vector is allowed only when the target is same size Tsarray. + static assert(!__traits(compiles, cast(byte)v1)); // 1byte + static assert(!__traits(compiles, cast(short)v1)); // 2byte + static assert(!__traits(compiles, cast(int)v1)); // 4byte + static assert(!__traits(compiles, cast(long)v1)); // 8byte + static assert(!__traits(compiles, cast(float)v1)); // 4byte + static assert(!__traits(compiles, cast(double)v1)); // 8byte + static assert(!__traits(compiles, cast(int[2])v1)); // 8byte Tsarray + static assert( __traits(compiles, cast(int[4])v1)); // 16byte Tsarray, OK + static assert( __traits(compiles, cast(long[2])v1)); // 16byte Tsarray, OK +} diff --git a/gcc/testsuite/gdc.dg/simd2h.d b/gcc/testsuite/gdc.dg/simd2h.d new file mode 100644 index 00000000000..f7542e83b8c --- /dev/null +++ b/gcc/testsuite/gdc.dg/simd2h.d @@ -0,0 +1,69 @@ +// { dg-additional-options "-mavx" { target avx_runtime } } +// { dg-do compile { target { avx_runtime || vect_sizes_16B_8B } } } +import core.simd; + +void test2h() +{ + ulong2 v1, v2 = 1, v3 = 1; + v1 = v2; + v1 = v2 + v3; + v1 = v2 - v3; + v1 = v2 * v3; + v1 = v2 / v3; + v1 = v2 % v3; + v1 = v2 & v3; + v1 = v2 | v3; + v1 = v2 ^ v3; + static assert(!__traits(compiles, v1 ~ v2)); + static assert(!__traits(compiles, v1 ^^ v2)); + static assert(!__traits(compiles, v1 is v2)); + static assert(!__traits(compiles, v1 !is v2)); + static assert(!__traits(compiles, v1 == v2)); + static assert(!__traits(compiles, v1 != v2)); + static assert(!__traits(compiles, v1 < v2)); + static assert(!__traits(compiles, v1 > v2)); + static assert(!__traits(compiles, v1 <= v2)); + static assert(!__traits(compiles, v1 >= v2)); + static assert(!__traits(compiles, v1 <> v2)); + static assert(!__traits(compiles, v1 !< v2)); + static assert(!__traits(compiles, v1 !> v2)); + static assert(!__traits(compiles, v1 !<> v2)); + static assert(!__traits(compiles, v1 <>= v2)); + static assert(!__traits(compiles, v1 !<= v2)); + static assert(!__traits(compiles, v1 !>= v2)); + static assert(!__traits(compiles, v1 !<>= v2)); + v1 = v2 << 1; + v1 = v2 >> 1; + v1 = v2 >>> 1; + static assert(!__traits(compiles, v1 && v2)); + static assert(!__traits(compiles, v1 || v2)); + v1 = ~v2; + v1 = -v2; + v1 = +v2; + static assert(!__traits(compiles, !v1)); + + v1 += v2; + v1 -= v2; + v1 *= v2; + v1 /= v2; + v1 %= v2; + v1 &= v2; + v1 |= v2; + v1 ^= v2; + static assert(!__traits(compiles, v1 ~= v2)); + static assert(!__traits(compiles, v1 ^^= v2)); + v1 <<= 1; + v1 >>= 1; + v1 >>>= 1; + + // A cast from vector to non-vector is allowed only when the target is same size Tsarray. + static assert(!__traits(compiles, cast(byte)v1)); // 1byte + static assert(!__traits(compiles, cast(short)v1)); // 2byte + static assert(!__traits(compiles, cast(int)v1)); // 4byte + static assert(!__traits(compiles, cast(long)v1)); // 8byte + static assert(!__traits(compiles, cast(float)v1)); // 4byte + static assert(!__traits(compiles, cast(double)v1)); // 8byte + static assert(!__traits(compiles, cast(int[2])v1)); // 8byte Tsarray + static assert( __traits(compiles, cast(int[4])v1)); // 16byte Tsarray, OK + static assert( __traits(compiles, cast(long[2])v1)); // 16byte Tsarray, OK +} diff --git a/gcc/testsuite/gdc.dg/simd2i.d b/gcc/testsuite/gdc.dg/simd2i.d new file mode 100644 index 00000000000..2e3587dce77 --- /dev/null +++ b/gcc/testsuite/gdc.dg/simd2i.d @@ -0,0 +1,69 @@ +// { dg-additional-options "-mavx" { target avx_runtime } } +// { dg-do compile { target { avx_runtime || vect_sizes_16B_8B } } } +import core.simd; + +void test2i() +{ + float4 v1, v2 = 1, v3 = 1; + v1 = v2; + v1 = v2 + v3; + v1 = v2 - v3; + v1 = v2 * v3; + v1 = v2 / v3; + static assert(!__traits(compiles, v1 % v2)); + static assert(!__traits(compiles, v1 & v2)); + static assert(!__traits(compiles, v1 | v2)); + static assert(!__traits(compiles, v1 ^ v2)); + static assert(!__traits(compiles, v1 ~ v2)); + static assert(!__traits(compiles, v1 ^^ v2)); + static assert(!__traits(compiles, v1 is v2)); + static assert(!__traits(compiles, v1 !is v2)); + static assert(!__traits(compiles, v1 == v2)); + static assert(!__traits(compiles, v1 != v2)); + static assert(!__traits(compiles, v1 < v2)); + static assert(!__traits(compiles, v1 > v2)); + static assert(!__traits(compiles, v1 <= v2)); + static assert(!__traits(compiles, v1 >= v2)); + static assert(!__traits(compiles, v1 <> v2)); + static assert(!__traits(compiles, v1 !< v2)); + static assert(!__traits(compiles, v1 !> v2)); + static assert(!__traits(compiles, v1 !<> v2)); + static assert(!__traits(compiles, v1 <>= v2)); + static assert(!__traits(compiles, v1 !<= v2)); + static assert(!__traits(compiles, v1 !>= v2)); + static assert(!__traits(compiles, v1 !<>= v2)); + static assert(!__traits(compiles, v1 << 1)); + static assert(!__traits(compiles, v1 >> 1)); + static assert(!__traits(compiles, v1 >>> 1)); + static assert(!__traits(compiles, v1 && v2)); + static assert(!__traits(compiles, v1 || v2)); + static assert(!__traits(compiles, ~v1)); + v1 = -v2; + v1 = +v2; + static assert(!__traits(compiles, !v1)); + + v1 += v2; + v1 -= v2; + v1 *= v2; + v1 /= v2; + static assert(!__traits(compiles, v1 %= v2)); + static assert(!__traits(compiles, v1 &= v2)); + static assert(!__traits(compiles, v1 |= v2)); + static assert(!__traits(compiles, v1 ^= v2)); + static assert(!__traits(compiles, v1 ~= v2)); + static assert(!__traits(compiles, v1 ^^= v2)); + static assert(!__traits(compiles, v1 <<= 1)); + static assert(!__traits(compiles, v1 >>= 1)); + static assert(!__traits(compiles, v1 >>>= 1)); + + // A cast from vector to non-vector is allowed only when the target is same size Tsarray. + static assert(!__traits(compiles, cast(byte)v1)); // 1byte + static assert(!__traits(compiles, cast(short)v1)); // 2byte + static assert(!__traits(compiles, cast(int)v1)); // 4byte + static assert(!__traits(compiles, cast(long)v1)); // 8byte + static assert(!__traits(compiles, cast(float)v1)); // 4byte + static assert(!__traits(compiles, cast(double)v1)); // 8byte + static assert(!__traits(compiles, cast(int[2])v1)); // 8byte Tsarray + static assert( __traits(compiles, cast(int[4])v1)); // 16byte Tsarray, OK + static assert( __traits(compiles, cast(long[2])v1)); // 16byte Tsarray, OK +} diff --git a/gcc/testsuite/gdc.dg/simd2j.d b/gcc/testsuite/gdc.dg/simd2j.d new file mode 100644 index 00000000000..7b607848580 --- /dev/null +++ b/gcc/testsuite/gdc.dg/simd2j.d @@ -0,0 +1,69 @@ +// { dg-additional-options "-mavx" { target avx_runtime } } +// { dg-do compile { target { avx_runtime || vect_sizes_16B_8B } } } +import core.simd; + +void test2j() +{ + double2 v1, v2 = 1, v3 = 1; + v1 = v2; + v1 = v2 + v3; + v1 = v2 - v3; + v1 = v2 * v3; + v1 = v2 / v3; + static assert(!__traits(compiles, v1 % v2)); + static assert(!__traits(compiles, v1 & v2)); + static assert(!__traits(compiles, v1 | v2)); + static assert(!__traits(compiles, v1 ^ v2)); + static assert(!__traits(compiles, v1 ~ v2)); + static assert(!__traits(compiles, v1 ^^ v2)); + static assert(!__traits(compiles, v1 is v2)); + static assert(!__traits(compiles, v1 !is v2)); + static assert(!__traits(compiles, v1 == v2)); + static assert(!__traits(compiles, v1 != v2)); + static assert(!__traits(compiles, v1 < v2)); + static assert(!__traits(compiles, v1 > v2)); + static assert(!__traits(compiles, v1 <= v2)); + static assert(!__traits(compiles, v1 >= v2)); + static assert(!__traits(compiles, v1 <> v2)); + static assert(!__traits(compiles, v1 !< v2)); + static assert(!__traits(compiles, v1 !> v2)); + static assert(!__traits(compiles, v1 !<> v2)); + static assert(!__traits(compiles, v1 <>= v2)); + static assert(!__traits(compiles, v1 !<= v2)); + static assert(!__traits(compiles, v1 !>= v2)); + static assert(!__traits(compiles, v1 !<>= v2)); + static assert(!__traits(compiles, v1 << 1)); + static assert(!__traits(compiles, v1 >> 1)); + static assert(!__traits(compiles, v1 >>> 1)); + static assert(!__traits(compiles, v1 && v2)); + static assert(!__traits(compiles, v1 || v2)); + static assert(!__traits(compiles, ~v1)); + v1 = -v2; + v1 = +v2; + static assert(!__traits(compiles, !v1)); + + v1 += v2; + v1 -= v2; + v1 *= v2; + v1 /= v2; + static assert(!__traits(compiles, v1 %= v2)); + static assert(!__traits(compiles, v1 &= v2)); + static assert(!__traits(compiles, v1 |= v2)); + static assert(!__traits(compiles, v1 ^= v2)); + static assert(!__traits(compiles, v1 ~= v2)); + static assert(!__traits(compiles, v1 ^^= v2)); + static assert(!__traits(compiles, v1 <<= 1)); + static assert(!__traits(compiles, v1 >>= 1)); + static assert(!__traits(compiles, v1 >>>= 1)); + + // A cast from vector to non-vector is allowed only when the target is same size Tsarray. + static assert(!__traits(compiles, cast(byte)v1)); // 1byte + static assert(!__traits(compiles, cast(short)v1)); // 2byte + static assert(!__traits(compiles, cast(int)v1)); // 4byte + static assert(!__traits(compiles, cast(long)v1)); // 8byte + static assert(!__traits(compiles, cast(float)v1)); // 4byte + static assert(!__traits(compiles, cast(double)v1)); // 8byte + static assert(!__traits(compiles, cast(int[2])v1)); // 8byte Tsarray + static assert( __traits(compiles, cast(int[4])v1)); // 16byte Tsarray, OK + static assert( __traits(compiles, cast(long[2])v1)); // 16byte Tsarray, OK +} diff --git a/gcc/testsuite/gdc.dg/simd7951.d b/gcc/testsuite/gdc.dg/simd7951.d new file mode 100644 index 00000000000..99ce1510f8f --- /dev/null +++ b/gcc/testsuite/gdc.dg/simd7951.d @@ -0,0 +1,22 @@ +// https://issues.dlang.org/show_bug.cgi?id=7951 +// { dg-additional-options "-mavx" { target avx_runtime } } +// { dg-do compile { target { avx_runtime || vect_sizes_16B_8B } } } +import core.simd; + +float[4] test7951() +{ + float4 v1; + float4 v2; + + return cast(float[4])(v1+v2); +} + +void test7951_2() +{ + float[4] v1 = [1,2,3,4]; + float[4] v2 = [1,2,3,4]; + float4 f1, f2, f3; + f1.array = v1; + f2.array = v2; + f3 = f1 + f2; +} diff --git a/gcc/testsuite/gdc.dg/torture/array2.d b/gcc/testsuite/gdc.dg/torture/array2.d new file mode 100644 index 00000000000..71d5f4c57bf --- /dev/null +++ b/gcc/testsuite/gdc.dg/torture/array2.d @@ -0,0 +1,25 @@ +// { dg-do run } +// { dg-skip-if "needs gcc/config.d" { ! d_runtime } } + +bool normalize(double[] range, double sum = 1) +{ + double s = 0; + const length = range.length; + foreach (e; range) + { + s += e; + } + if (s == 0) + { + return false; + } + return true; +} + +void main() +{ + double[3] range = [0.0, 0.0, 0.0]; + assert(normalize(range[]) == false); + range[1] = 3.0; + assert(normalize(range[]) == true); +} diff --git a/gcc/testsuite/gdc.dg/torture/array3.d b/gcc/testsuite/gdc.dg/torture/array3.d new file mode 100644 index 00000000000..4a6b6db0483 --- /dev/null +++ b/gcc/testsuite/gdc.dg/torture/array3.d @@ -0,0 +1,15 @@ +// { dg-do run } +// { dg-skip-if "needs gcc/config.d" { ! d_runtime } } + +void foo13988(double[] arr) +{ + static ulong repr(double d) { return *cast(ulong*)&d; } + foreach (x; arr) + assert(repr(arr[0]) == *cast(ulong*)&(arr[0])); +} + +void main() +{ + double[] arr = [3.0]; + foo13988(arr); +} diff --git a/gcc/testsuite/gdc.dg/torture/simd16488a.d b/gcc/testsuite/gdc.dg/torture/simd16488a.d new file mode 100644 index 00000000000..5578f78aba7 --- /dev/null +++ b/gcc/testsuite/gdc.dg/torture/simd16488a.d @@ -0,0 +1,106 @@ +// https://issues.dlang.org/show_bug.cgi?id=16488 +// { dg-additional-options "-mavx" { target avx_runtime } } +// { dg-do run { target { avx_runtime || vect_sizes_16B_8B } } } +// { dg-skip-if "needs gcc/config.d" { ! d_runtime } } +import core.simd; + +void foo_byte16(byte t, byte s) +{ + byte16 f = s; + auto p = cast(byte*)&f; + foreach (i; 0 .. 16) + assert(p[i] == s); +} + +void foo_ubyte16(ubyte t, ubyte s) +{ + ubyte16 f = s; + auto p = cast(ubyte*)&f; + foreach (i; 0 .. 16) + assert(p[i] == s); +} + + +void foo_short8(short t, short s) +{ + short8 f = s; + auto p = cast(short*)&f; + foreach (i; 0 .. 8) + assert(p[i] == s); +} + +void foo_ushort8(ushort t, ushort s) +{ + ushort8 f = s; + auto p = cast(ushort*)&f; + foreach (i; 0 .. 8) + assert(p[i] == s); +} + + +void foo_int4(int t, int s) +{ + int4 f = s; + auto p = cast(int*)&f; + foreach (i; 0 .. 4) + assert(p[i] == s); +} + +void foo_uint4(uint t, uint s, uint u) +{ + uint4 f = s; + auto p = cast(uint*)&f; + foreach (i; 0 .. 4) + assert(p[i] == s); +} + + +void foo_long2(long t, long s, long u) +{ + long2 f = s; + auto p = cast(long*)&f; + foreach (i; 0 .. 2) + assert(p[i] == s); +} + +void foo_ulong2(ulong t, ulong s) +{ + ulong2 f = s; + auto p = cast(ulong*)&f; + foreach (i; 0 .. 2) + assert(p[i] == s); +} + +void foo_float4(float t, float s) +{ + float4 f = s; + auto p = cast(float*)&f; + foreach (i; 0 .. 4) + assert(p[i] == s); +} + +void foo_double2(double t, double s, double u) +{ + double2 f = s; + auto p = cast(double*)&f; + foreach (i; 0 .. 2) + assert(p[i] == s); +} + +void main() +{ + foo_byte16(5, -10); + foo_ubyte16(5, 11); + + foo_short8(5, -6); + foo_short8(5, 7); + + foo_int4(5, -6); + foo_uint4(5, 0x12345678, 22); + + foo_long2(5, -6, 1); + foo_ulong2(5, 0x12345678_87654321L); + + foo_float4(5, -6); + foo_double2(5, -6, 2); +} diff --git a/gcc/testsuite/gdc.dg/torture/simd16488b.d b/gcc/testsuite/gdc.dg/torture/simd16488b.d new file mode 100644 index 00000000000..52027a2aa23 --- /dev/null +++ b/gcc/testsuite/gdc.dg/torture/simd16488b.d @@ -0,0 +1,103 @@ +// https://issues.dlang.org/show_bug.cgi?id=16488 +// { dg-additional-options "-mavx2" { target avx2_runtime } } +// { dg-do run { target { avx2_runtime || vect_sizes_32B_16B } } } +// { dg-skip-if "needs gcc/config.d" { ! d_runtime } } +import core.simd; + +void foo_byte32(byte t, byte s) +{ + byte32 f = s; + auto p = cast(byte*)&f; + foreach (i; 0 .. 32) + assert(p[i] == s); +} + +void foo_ubyte32(ubyte t, ubyte s) +{ + ubyte32 f = s; + auto p = cast(ubyte*)&f; + foreach (i; 0 .. 32) + assert(p[i] == s); +} + +void foo_short16(short t, short s) +{ + short16 f = s; + auto p = cast(short*)&f; + foreach (i; 0 .. 16) + assert(p[i] == s); +} + +void foo_ushort16(ushort t, ushort s) +{ + ushort16 f = s; + auto p = cast(ushort*)&f; + foreach (i; 0 .. 16) + assert(p[i] == s); +} + +void foo_int8(int t, int s) +{ + int8 f = s; + auto p = cast(int*)&f; + foreach (i; 0 .. 8) + assert(p[i] == s); +} + +void foo_uint8(uint t, uint s, uint u) +{ + uint8 f = s; + auto p = cast(uint*)&f; + foreach (i; 0 .. 8) + assert(p[i] == s); +} + +void foo_long4(long t, long s, long u) +{ + long4 f = s; + auto p = cast(long*)&f; + foreach (i; 0 .. 4) + assert(p[i] == s); +} + +void foo_ulong4(ulong t, ulong s) +{ + ulong4 f = s; + auto p = cast(ulong*)&f; + foreach (i; 0 .. 4) + assert(p[i] == s); +} + +void foo_float8(float t, float s) +{ + float8 f = s; + auto p = cast(float*)&f; + foreach (i; 0 .. 8) + assert(p[i] == s); +} + +void foo_double4(double t, double s, double u) +{ + double4 f = s; + auto p = cast(double*)&f; + foreach (i; 0 .. 4) + assert(p[i] == s); +} + +void main() +{ + foo_byte32(5, -10); + foo_ubyte32(5, 11); + + foo_short16(5, -6); + foo_short16(5, 7); + + foo_int8(5, -6); + foo_uint8(5, 0x12345678, 22); + + foo_long4(5, -6, 1); + foo_ulong4(5, 0x12345678_87654321L); + + foo_float8(5, -6); + foo_double4(5, -6, 2); +} diff --git a/gcc/testsuite/gdc.dg/torture/simd16703.d b/gcc/testsuite/gdc.dg/torture/simd16703.d new file mode 100644 index 00000000000..5b9e0156e33 --- /dev/null +++ b/gcc/testsuite/gdc.dg/torture/simd16703.d @@ -0,0 +1,36 @@ +// https://issues.dlang.org/show_bug.cgi?id=16703 +// { dg-additional-options "-mavx" { target avx_runtime } } +// { dg-do run { target { avx_runtime || vect_sizes_16B_8B } } } +// { dg-skip-if "needs gcc/config.d" { ! d_runtime } } +import core.simd; + +float index(float4 f4, size_t i) +{ + return f4[i]; +} + +float[4] slice(float4 f4) +{ + return f4[]; +} + +float slice2(float4 f4, size_t lwr, size_t upr, size_t i) +{ + float[] fa = f4[lwr .. upr]; + return fa[i]; +} + +void main() +{ + float4 f4 = [1,2,3,4]; + assert(index(f4, 0) == 1); + assert(index(f4, 1) == 2); + assert(index(f4, 2) == 3); + assert(index(f4, 3) == 4); + + float[4] fsa = slice(f4); + assert(fsa == [1.0f,2,3,4]); + + assert(slice2(f4, 1, 3, 0) == 2); + assert(slice2(f4, 1, 3, 1) == 3); +} diff --git a/gcc/testsuite/gdc.dg/torture/simd19223.d b/gcc/testsuite/gdc.dg/torture/simd19223.d new file mode 100644 index 00000000000..f63ec58c06d --- /dev/null +++ b/gcc/testsuite/gdc.dg/torture/simd19223.d @@ -0,0 +1,19 @@ +// https://issues.dlang.org/show_bug.cgi?id=19223 +// { dg-additional-options "-mavx" { target avx_runtime } } +// { dg-do run { target { avx_runtime || vect_sizes_16B_8B } } } +// { dg-skip-if "needs gcc/config.d" { ! d_runtime } } +import core.simd; + +int test19223a(const int[4] x) +{ + int sum = 0; + foreach (i; x) sum += i; + return sum; +} + +void main() +{ + int4 v1 = int4.init; + assert(test19223a(v1.array) == 0); + assert(test19223a(int4.init.array) == 0); +} diff --git a/gcc/testsuite/gdc.dg/torture/simd19607.d b/gcc/testsuite/gdc.dg/torture/simd19607.d new file mode 100644 index 00000000000..68ee72e5ceb --- /dev/null +++ b/gcc/testsuite/gdc.dg/torture/simd19607.d @@ -0,0 +1,19 @@ +// https://issues.dlang.org/show_bug.cgi?id=19607 +// { dg-additional-options "-mavx" { target avx_runtime } } +// { dg-do run { target { avx_runtime || vect_sizes_16B_8B } } } +// { dg-skip-if "needs gcc/config.d" { ! d_runtime } } +import core.simd; + +int test19607a(const int[4] x) +{ + int sum = 0; + foreach (i; x) sum += i; + return sum; +} + +void main() +{ + int4 v1 = 1; + assert(test19607a(v1.array) == 4); + assert(test19607a(int4(2).array) == 8); +} diff --git a/gcc/testsuite/gdc.dg/torture/simd3.d b/gcc/testsuite/gdc.dg/torture/simd3.d new file mode 100644 index 00000000000..7ce26793e7a --- /dev/null +++ b/gcc/testsuite/gdc.dg/torture/simd3.d @@ -0,0 +1,34 @@ +// { dg-additional-options "-mavx" { target avx_runtime } } +// { dg-do run { target { avx_runtime || vect_sizes_16B_8B } } } +// { dg-skip-if "needs gcc/config.d" { ! d_runtime } } +import core.simd; + +struct Sunsto +{ + align (1): // make sure f4 is misaligned + byte b; + union + { + float4 f4; + ubyte[16] a; + } +} + +ubyte[16] foounsto() +{ + float4 vf = 6; + Sunsto s; + s.f4 = vf * 2; + vf = s.f4; + + return s.a; +} + +void main() +{ + auto a = foounsto(); + version (LittleEndian) + assert(a == [0, 0, 64, 65, 0, 0, 64, 65, 0, 0, 64, 65, 0, 0, 64, 65]); + version (BigEndian) + assert(a == [65, 64, 0, 0, 65, 64, 0, 0, 65, 64, 0, 0, 65, 64, 0, 0]); +} diff --git a/gcc/testsuite/gdc.dg/torture/simd4.d b/gcc/testsuite/gdc.dg/torture/simd4.d new file mode 100644 index 00000000000..30b52192f18 --- /dev/null +++ b/gcc/testsuite/gdc.dg/torture/simd4.d @@ -0,0 +1,14 @@ +// { dg-additional-options "-mavx" { target avx_runtime } } +// { dg-do run { target { avx_runtime || vect_sizes_16B_8B } } } +// { dg-skip-if "needs gcc/config.d" { ! d_runtime } } +import core.simd; + +void main() +{ + int4 c = 7; + (cast(int[4])c)[3] = 4; + (cast(int*)&c)[2] = 4; + c.array[1] = 4; + c.ptr[3] = 4; + assert(c.length == 4); +} diff --git a/gcc/testsuite/gdc.dg/torture/simd7411.d b/gcc/testsuite/gdc.dg/torture/simd7411.d new file mode 100644 index 00000000000..2ed74ff472f --- /dev/null +++ b/gcc/testsuite/gdc.dg/torture/simd7411.d @@ -0,0 +1,16 @@ +// https://issues.dlang.org/show_bug.cgi?id=7411 +// { dg-additional-options "-mavx" { target avx_runtime } } +// { dg-do run { target { avx_runtime || vect_sizes_16B_8B } } } +// { dg-skip-if "needs gcc/config.d" { ! d_runtime } } +import core.simd; + +void BaseTypeOfVector(T : __vector(T[N]), size_t N)(int i) +{ + assert(is(T == int)); + assert(N == 4); +} + +void main() +{ + BaseTypeOfVector!(__vector(int[4]))(3); +} diff --git a/gcc/testsuite/gdc.dg/torture/simd7413a.d b/gcc/testsuite/gdc.dg/torture/simd7413a.d new file mode 100644 index 00000000000..13bd69a122f --- /dev/null +++ b/gcc/testsuite/gdc.dg/torture/simd7413a.d @@ -0,0 +1,95 @@ +// https://issues.dlang.org/show_bug.cgi?id=7413 +// { dg-additional-options "-mavx" { target avx_runtime } } +// { dg-do run { target { avx_runtime || vect_sizes_16B_8B } } } +// { dg-skip-if "needs gcc/config.d" { ! d_runtime } } +// { dg-skip-if "needs gcc/config.d" { ! d_runtime } } +import core.simd; + +void main() +{ + byte16 b = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]; + assert(b.array[0] == 1); + assert(b.array[1] == 2); + assert(b.array[2] == 3); + assert(b.array[3] == 4); + assert(b.array[4] == 5); + assert(b.array[5] == 6); + assert(b.array[6] == 7); + assert(b.array[7] == 8); + assert(b.array[8] == 9); + assert(b.array[9] == 10); + assert(b.array[10] == 11); + assert(b.array[11] == 12); + assert(b.array[12] == 13); + assert(b.array[13] == 14); + assert(b.array[14] == 15); + assert(b.array[15] == 16); + + ubyte16 ub = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]; + assert(ub.array[0] == 1); + assert(ub.array[1] == 2); + assert(ub.array[2] == 3); + assert(ub.array[3] == 4); + assert(ub.array[4] == 5); + assert(ub.array[5] == 6); + assert(ub.array[6] == 7); + assert(ub.array[7] == 8); + assert(ub.array[8] == 9); + assert(ub.array[9] == 10); + assert(ub.array[10] == 11); + assert(ub.array[11] == 12); + assert(ub.array[12] == 13); + assert(ub.array[13] == 14); + assert(ub.array[14] == 15); + assert(ub.array[15] == 16); + + short8 s = [1,2,3,4,5,6,7,8]; + assert(s.array[0] == 1); + assert(s.array[1] == 2); + assert(s.array[2] == 3); + assert(s.array[3] == 4); + assert(s.array[4] == 5); + assert(s.array[5] == 6); + assert(s.array[6] == 7); + assert(s.array[7] == 8); + + ushort8 us = [1,2,3,4,5,6,7,8]; + assert(us.array[0] == 1); + assert(us.array[1] == 2); + assert(us.array[2] == 3); + assert(us.array[3] == 4); + assert(us.array[4] == 5); + assert(us.array[5] == 6); + assert(us.array[6] == 7); + assert(us.array[7] == 8); + + int4 i = [1,2,3,4]; + assert(i.array[0] == 1); + assert(i.array[1] == 2); + assert(i.array[2] == 3); + assert(i.array[3] == 4); + + uint4 ui = [1,2,3,4]; + assert(ui.array[0] == 1); + assert(ui.array[1] == 2); + assert(ui.array[2] == 3); + assert(ui.array[3] == 4); + + long2 l = [1,2]; + assert(l.array[0] == 1); + assert(l.array[1] == 2); + + ulong2 ul = [1,2]; + assert(ul.array[0] == 1); + assert(ul.array[1] == 2); + + float4 f = [1,2,3,4]; + assert(f.array[0] == 1); + assert(f.array[1] == 2); + assert(f.array[2] == 3); + assert(f.array[3] == 4); + + double2 d = [1,2]; + assert(d.array[0] == 1); + assert(d.array[1] == 2); +} diff --git a/gcc/testsuite/gdc.dg/torture/simd7413b.d b/gcc/testsuite/gdc.dg/torture/simd7413b.d new file mode 100644 index 00000000000..c1ee6aa7c76 --- /dev/null +++ b/gcc/testsuite/gdc.dg/torture/simd7413b.d @@ -0,0 +1,95 @@ +// https://issues.dlang.org/show_bug.cgi?id=7413 +// { dg-additional-options "-mavx" { target avx_runtime } } +// { dg-do run { target { avx_runtime || vect_sizes_16B_8B } } } +// { dg-skip-if "needs gcc/config.d" { ! d_runtime } } +import core.simd; + +byte16 b = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]; +ubyte16 ub = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]; +short8 s = [1,2,3,4,5,6,7,8]; +ushort8 us = [1,2,3,4,5,6,7,8]; +int4 i = [1,2,3,4]; +uint4 ui = [1,2,3,4]; +long2 l = [1,2]; +ulong2 ul = [1,2]; +float4 f = [1,2,3,4]; +double2 d = [1,2]; + +void main() +{ + assert(b.array[0] == 1); + assert(b.array[1] == 2); + assert(b.array[2] == 3); + assert(b.array[3] == 4); + assert(b.array[4] == 5); + assert(b.array[5] == 6); + assert(b.array[6] == 7); + assert(b.array[7] == 8); + assert(b.array[8] == 9); + assert(b.array[9] == 10); + assert(b.array[10] == 11); + assert(b.array[11] == 12); + assert(b.array[12] == 13); + assert(b.array[13] == 14); + assert(b.array[14] == 15); + assert(b.array[15] == 16); + + assert(ub.array[0] == 1); + assert(ub.array[1] == 2); + assert(ub.array[2] == 3); + assert(ub.array[3] == 4); + assert(ub.array[4] == 5); + assert(ub.array[5] == 6); + assert(ub.array[6] == 7); + assert(ub.array[7] == 8); + assert(ub.array[8] == 9); + assert(ub.array[9] == 10); + assert(ub.array[10] == 11); + assert(ub.array[11] == 12); + assert(ub.array[12] == 13); + assert(ub.array[13] == 14); + assert(ub.array[14] == 15); + assert(ub.array[15] == 16); + + assert(s.array[0] == 1); + assert(s.array[1] == 2); + assert(s.array[2] == 3); + assert(s.array[3] == 4); + assert(s.array[4] == 5); + assert(s.array[5] == 6); + assert(s.array[6] == 7); + assert(s.array[7] == 8); + + assert(us.array[0] == 1); + assert(us.array[1] == 2); + assert(us.array[2] == 3); + assert(us.array[3] == 4); + assert(us.array[4] == 5); + assert(us.array[5] == 6); + assert(us.array[6] == 7); + assert(us.array[7] == 8); + + assert(i.array[0] == 1); + assert(i.array[1] == 2); + assert(i.array[2] == 3); + assert(i.array[3] == 4); + + assert(ui.array[0] == 1); + assert(ui.array[1] == 2); + assert(ui.array[2] == 3); + assert(ui.array[3] == 4); + + assert(l.array[0] == 1); + assert(l.array[1] == 2); + + assert(ul.array[0] == 1); + assert(ul.array[1] == 2); + + assert(f.array[0] == 1); + assert(f.array[1] == 2); + assert(f.array[2] == 3); + assert(f.array[3] == 4); + + assert(d.array[0] == 1); + assert(d.array[1] == 2); +} diff --git a/gcc/testsuite/gdc.dg/torture/simd7414.d b/gcc/testsuite/gdc.dg/torture/simd7414.d new file mode 100644 index 00000000000..c4359405dd5 --- /dev/null +++ b/gcc/testsuite/gdc.dg/torture/simd7414.d @@ -0,0 +1,54 @@ +// https://issues.dlang.org/show_bug.cgi?id=7414 +// { dg-additional-options "-mavx" { target avx_runtime } } +// { dg-do run { target { avx_runtime || vect_sizes_16B_8B } } } +// { dg-skip-if "needs gcc/config.d" { ! d_runtime } } +import core.simd; +import core.stdc.string; + +immutable ulong2 gulong2 = 0x8000_0000_0000_0000; +immutable uint4 guint4 = 0x8000_0000; +immutable ushort8 gushort8 = 0x8000; +immutable ubyte16 gubyte16 = 0x80; + +immutable long2 glong2 = 0x7000_0000_0000_0000; +immutable int4 gint4 = 0x7000_0000; +immutable short8 gshort8 = 0x7000; +immutable byte16 gbyte16 = 0x70; + +immutable float4 gfloat4 = 4.0; +immutable double2 gdouble2 = 8.0; + +void main() +{ + immutable ulong2 lulong2 = 0x8000_0000_0000_0000; + assert(memcmp(&lulong2, &gulong2, gulong2.sizeof) == 0); + + immutable uint4 luint4 = 0x8000_0000; + assert(memcmp(&luint4, &guint4, guint4.sizeof) == 0); + + immutable ushort8 lushort8 = 0x8000; + assert(memcmp(&lushort8, &gushort8, gushort8.sizeof) == 0); + + immutable ubyte16 lubyte16 = 0x80; + assert(memcmp(&lubyte16, &gubyte16, gubyte16.sizeof) == 0); + + + immutable long2 llong2 = 0x7000_0000_0000_0000; + assert(memcmp(&llong2, &glong2, glong2.sizeof) == 0); + + immutable int4 lint4 = 0x7000_0000; + assert(memcmp(&lint4, &gint4, gint4.sizeof) == 0); + + immutable short8 lshort8 = 0x7000; + assert(memcmp(&lshort8, &gshort8, gshort8.sizeof) == 0); + + immutable byte16 lbyte16 = 0x70; + assert(memcmp(&lbyte16, &gbyte16, gbyte16.sizeof) == 0); + + + immutable float4 lfloat4 = 4.0; + assert(memcmp(&lfloat4, &gfloat4, gfloat4.sizeof) == 0); + + immutable double2 ldouble2 = 8.0; + assert(memcmp(&ldouble2, &gdouble2, gdouble2.sizeof) == 0); +} diff --git a/gcc/testsuite/gdc.dg/torture/simd9200.d b/gcc/testsuite/gdc.dg/torture/simd9200.d new file mode 100644 index 00000000000..04dfc5d4d51 --- /dev/null +++ b/gcc/testsuite/gdc.dg/torture/simd9200.d @@ -0,0 +1,25 @@ +// https://issues.dlang.org/show_bug.cgi?id=9200 +// { dg-additional-options "-mavx" { target avx_runtime } } +// { dg-do run { target { avx_runtime || vect_sizes_16B_8B } } } +// { dg-skip-if "needs gcc/config.d" { ! d_runtime } } +import core.simd; + +void bar9200(double[2] a) +{ + assert(a[0] == 1); + assert(a[1] == 2); +} + +double2 * v9200(double2* a) +{ + return a; +} + +void main() +{ + double2 a = [1, 2]; + + *v9200(&a) = a; + + bar9200(a.array); +} diff --git a/gcc/testsuite/gdc.dg/torture/simd9304.d b/gcc/testsuite/gdc.dg/torture/simd9304.d new file mode 100644 index 00000000000..275e88968de --- /dev/null +++ b/gcc/testsuite/gdc.dg/torture/simd9304.d @@ -0,0 +1,17 @@ +// https://issues.dlang.org/show_bug.cgi?id=9304 +// https://issues.dlang.org/show_bug.cgi?id=9322 +// { dg-additional-options "-mavx" { target avx_runtime } } +// { dg-do run { target { avx_runtime || vect_sizes_16B_8B } } } +// { dg-skip-if "needs gcc/config.d" { ! d_runtime } } +import core.simd; + +float4 foo9304(float4 a) +{ + return -a; +} + +void main() +{ + auto a = foo9304([0, 1, 2, 3]); + assert(a.array == [0,-1,-2,-3]); +} diff --git a/gcc/testsuite/gdc.dg/torture/simd9449.d b/gcc/testsuite/gdc.dg/torture/simd9449.d new file mode 100644 index 00000000000..54f6f436f52 --- /dev/null +++ b/gcc/testsuite/gdc.dg/torture/simd9449.d @@ -0,0 +1,31 @@ +// https://issues.dlang.org/show_bug.cgi?id=9449 +// { dg-additional-options "-mavx" { target avx_runtime } } +// { dg-do run { target { avx_runtime || vect_sizes_16B_8B } } } +// { dg-skip-if "needs gcc/config.d" { ! d_runtime } } +import core.simd; + +void test9449() +{ + ubyte16[1] table; +} + +void test9449_2() +{ + float[4][2] m = [[2.0, 1, 3, 4], [5.0, 6, 7, 8]]; // segfault + + assert(m[0][0] == 2.0); + assert(m[0][1] == 1); + assert(m[0][2] == 3); + assert(m[0][3] == 4); + + assert(m[1][0] == 5.0); + assert(m[1][1] == 6); + assert(m[1][2] == 7); + assert(m[1][3] == 8); +} + +void main() +{ + test9449(); + test9449_2(); +} diff --git a/gcc/testsuite/gdc.dg/torture/simd9910.d b/gcc/testsuite/gdc.dg/torture/simd9910.d new file mode 100644 index 00000000000..749ca4d5e08 --- /dev/null +++ b/gcc/testsuite/gdc.dg/torture/simd9910.d @@ -0,0 +1,15 @@ +// https://issues.dlang.org/show_bug.cgi?id=9910 +// { dg-additional-options "-mavx" { target avx_runtime } } +// { dg-do run { target { avx_runtime || vect_sizes_16B_8B } } } +// { dg-skip-if "needs gcc/config.d" { ! d_runtime } } +import core.simd; + +void main() +{ + float4 f = [1, 1, 1, 1]; + auto works = f + 3; + auto bug = 3 + f; + + assert (works.array == [4,4,4,4]); + assert (bug.array == [4,4,4,4]); // no property 'array' for type 'int' +}