1 // { dg-do compile { target i?86-*-* x86_64-*-* } }
2 // { dg-options "-O3 -fwhole-program -msse2 -Wno-return-type" }
4 typedef long unsigned int __darwin_size_t;
5 typedef __darwin_size_t size_t;
7 typedef float __m128 __attribute__ ((__vector_size__ (16), __may_alias__));
8 typedef float __v4sf __attribute__ ((__vector_size__ (16)));
9 extern inline __m128 __attribute__((__gnu_inline__, __always_inline__, __artificial__)) _mm_mul_ps (__m128 __A, __m128 __B) {
10 return (__m128) __builtin_ia32_mulps ((__v4sf)__A, (__v4sf)__B);
12 extern inline __m128 __attribute__((__gnu_inline__, __always_inline__, __artificial__)) _mm_set1_ps (float __F) {
13 return __extension__ (__m128)(__v4sf){
16 extern inline __m128 __attribute__((__gnu_inline__, __always_inline__, __artificial__)) _mm_setr_ps (float __Z, float __Y, float __X, float __W) {
19 template <typename T, int N> struct vectorX {
21 template<> struct vectorX<float, 3> {
27 vectorX(__m128 s) : s(s) {
31 __attribute__((aligned));
32 template<> struct vectorX<float, 4> {
34 typedef vectorX<float, 4> V;
41 vectorX(T a_, T b, T c, T d = 1) : s(_mm_setr_ps(a_,b,c,d)) {
43 vectorX(__m128 s) : s(s) {
45 vectorX(const V &t) : s(t.s) {
47 V &operator *=(const T t) {
48 s = _mm_mul_ps(s, _mm_set1_ps(t));
51 inline V operator *(const T t) const __attribute__((always_inline)) {
55 __attribute__((aligned));
56 typedef vectorX<real, 3> color3;
57 typedef vectorX<real, 4> color4;
59 static inline color4 c3to4(color c) {
64 static inline color c4to3(color4 c) {
67 static inline color4 to_premultiplied(color c, real a) {
68 color4 res = c3to4(c);
71 static inline color4 to_premultiplied(color4 cs) {
72 return to_premultiplied(c4to3(cs), cs.a);
76 struct flat_texture : public texture {
78 flat_texture(const color4 &c) : c(to_premultiplied(c)) {
81 struct checkerboard_texture : public texture {
83 checkerboard_texture(const color4 &even, const color4 &odd) : even(to_premultiplied(even)), odd(to_premultiplied(odd)) {
86 struct texture_placement {
90 texture_placement textures[16];
96 static void set_color(primitive *p, color4 c) {
97 p->mat.textures[0].tex = new flat_texture(c);
99 static primitive **checkerboard_scene(int *pi) {
100 primitive **prims = new primitive*[6];
101 set_color(prims[0], color4(.7,.7,.7));
102 prims[1]->mat.textures[prims[1]->mat.texcount++].tex = new checkerboard_texture(color4(1,.1,.1),color4(.1,.15,1));
103 set_color(prims[2], color4(.7,.9,.7));
105 int main (int argc, char * const argv[]) {
107 primitive **prims = checkerboard_scene(&primi);