+ /*
+ * The rounding may not be quite the same with PIPE_ARCH_SSE
+ * (util_iround right now only does nearest/even on x87,
+ * otherwise nearest/away-from-zero).
+ * Both should be acceptable, I think.
+ */
+#if defined(PIPE_ARCH_SSE)
+ __m128 v0r, v1r;
+ __m128 vxy0xy2, vxy1xy0;
+ __m128i vxy0xy2i, vxy1xy0i;
+ __m128i dxdy0120, x0x2y0y2, x1x0y1y0, x0120, y0120;
+ __m128 pix_offset = _mm_set1_ps(setup->pixel_offset);
+ __m128 fixed_one = _mm_set1_ps((float)FIXED_ONE);
+ v0r = _mm_castpd_ps(_mm_load_sd((double *)v0[0]));
+ vxy0xy2 = _mm_loadh_pi(v0r, (__m64 *)v2[0]);
+ v1r = _mm_castpd_ps(_mm_load_sd((double *)v1[0]));
+ vxy1xy0 = _mm_movelh_ps(v1r, vxy0xy2);
+ vxy0xy2 = _mm_sub_ps(vxy0xy2, pix_offset);
+ vxy1xy0 = _mm_sub_ps(vxy1xy0, pix_offset);
+ vxy0xy2 = _mm_mul_ps(vxy0xy2, fixed_one);
+ vxy1xy0 = _mm_mul_ps(vxy1xy0, fixed_one);
+ vxy0xy2i = _mm_cvtps_epi32(vxy0xy2);
+ vxy1xy0i = _mm_cvtps_epi32(vxy1xy0);
+ dxdy0120 = _mm_sub_epi32(vxy0xy2i, vxy1xy0i);
+ _mm_store_si128((__m128i *)&position->dx01, dxdy0120);
+ /*
+ * For the mul, would need some more shuffles, plus emulation
+ * for the signed mul (without sse41), so don't bother.
+ */
+ x0x2y0y2 = _mm_shuffle_epi32(vxy0xy2i, _MM_SHUFFLE(3,1,2,0));
+ x1x0y1y0 = _mm_shuffle_epi32(vxy1xy0i, _MM_SHUFFLE(3,1,2,0));
+ x0120 = _mm_unpacklo_epi32(x0x2y0y2, x1x0y1y0);
+ y0120 = _mm_unpackhi_epi32(x0x2y0y2, x1x0y1y0);
+ _mm_store_si128((__m128i *)&position->x[0], x0120);
+ _mm_store_si128((__m128i *)&position->y[0], y0120);
+
+#else
+ position->x[0] = subpixel_snap(v0[0][0] - setup->pixel_offset);
+ position->x[1] = subpixel_snap(v1[0][0] - setup->pixel_offset);
+ position->x[2] = subpixel_snap(v2[0][0] - setup->pixel_offset);
+ position->x[3] = 0; // should be unused
+
+ position->y[0] = subpixel_snap(v0[0][1] - setup->pixel_offset);
+ position->y[1] = subpixel_snap(v1[0][1] - setup->pixel_offset);
+ position->y[2] = subpixel_snap(v2[0][1] - setup->pixel_offset);
+ position->y[3] = 0; // should be unused
+
+ position->dx01 = position->x[0] - position->x[1];
+ position->dy01 = position->y[0] - position->y[1];
+
+ position->dx20 = position->x[2] - position->x[0];
+ position->dy20 = position->y[2] - position->y[0];
+#endif
+
+ position->area = IMUL64(position->dx01, position->dy20) -
+ IMUL64(position->dx20, position->dy01);
+}
+
+
+/**
+ * Rotate a triangle, flipping its clockwise direction,
+ * Swaps values for xy[0] and xy[1]
+ */
+static inline void
+rotate_fixed_position_01( struct fixed_position* position )
+{
+ int x, y;
+
+ x = position->x[1];
+ y = position->y[1];
+ position->x[1] = position->x[0];
+ position->y[1] = position->y[0];
+ position->x[0] = x;
+ position->y[0] = y;
+
+ position->dx01 = -position->dx01;
+ position->dy01 = -position->dy01;
+ position->dx20 = position->x[2] - position->x[0];
+ position->dy20 = position->y[2] - position->y[0];
+
+ position->area = -position->area;
+}
+
+
+/**
+ * Rotate a triangle, flipping its clockwise direction,
+ * Swaps values for xy[1] and xy[2]
+ */
+static inline void
+rotate_fixed_position_12( struct fixed_position* position )
+{
+ int x, y;
+
+ x = position->x[2];
+ y = position->y[2];
+ position->x[2] = position->x[1];
+ position->y[2] = position->y[1];
+ position->x[1] = x;
+ position->y[1] = y;
+
+ x = position->dx01;
+ y = position->dy01;
+ position->dx01 = -position->dx20;
+ position->dy01 = -position->dy20;
+ position->dx20 = -x;
+ position->dy20 = -y;
+
+ position->area = -position->area;