1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962
|
/*
* Copyright (C) 2007-2017 Gabest
* http://www.gabest.org
*
* This Program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA USA.
* http://www.gnu.org/copyleft/gpl.html
*
*/
class alignas(16) GSVector4
{
public:
union
{
struct {float x, y, z, w;};
struct {float r, g, b, a;};
struct {float left, top, right, bottom;};
float v[4];
float f32[4];
int8 i8[16];
int16 i16[8];
int32 i32[4];
int64 i64[2];
uint8 u8[16];
uint16 u16[8];
uint32 u32[4];
uint64 u64[2];
__m128 m;
};
static GSVector4 m_ps0123;
static GSVector4 m_ps4567;
static GSVector4 m_half;
static GSVector4 m_one;
static GSVector4 m_two;
static GSVector4 m_four;
static GSVector4 m_x4b000000;
static GSVector4 m_x4f800000;
static GSVector4 m_max;
static GSVector4 m_min;
static void InitVectors();
__forceinline GSVector4()
{
}
constexpr GSVector4(const GSVector4&) = default;
__forceinline GSVector4(float x, float y, float z, float w)
{
m = _mm_set_ps(w, z, y, x);
}
__forceinline GSVector4(float x, float y)
{
m = _mm_unpacklo_ps(_mm_load_ss(&x), _mm_load_ss(&y));
}
__forceinline GSVector4(int x, int y, int z, int w)
{
GSVector4i v(x, y, z, w);
m = _mm_cvtepi32_ps(v.m);
}
__forceinline GSVector4(int x, int y)
{
m = _mm_cvtepi32_ps(_mm_unpacklo_epi32(_mm_cvtsi32_si128(x), _mm_cvtsi32_si128(y)));
}
//Not currently used, just causes a compiler warning
/*__forceinline GSVector4(const GSVector4& v)
{
m = v.m;
}*/
__forceinline explicit GSVector4(const GSVector2& v)
{
m = _mm_castsi128_ps(_mm_loadl_epi64((__m128i*)&v));
}
__forceinline explicit GSVector4(const GSVector2i& v)
{
m = _mm_cvtepi32_ps(_mm_loadl_epi64((__m128i*)&v));
}
__forceinline explicit GSVector4(__m128 m)
{
this->m = m;
}
__forceinline explicit GSVector4(float f)
{
*this = f;
}
__forceinline explicit GSVector4(int i)
{
#if _M_SSE >= 0x501
m = _mm_cvtepi32_ps(_mm_broadcastd_epi32(_mm_cvtsi32_si128(i)));
#else
GSVector4i v((int)i);
*this = GSVector4(v);
#endif
}
__forceinline explicit GSVector4(uint32 u)
{
GSVector4i v((int)u);
*this = GSVector4(v) + (m_x4f800000 & GSVector4::cast(v.sra32(31)));
}
__forceinline explicit GSVector4(const GSVector4i& v);
__forceinline static GSVector4 cast(const GSVector4i& v);
#if _M_SSE >= 0x500
__forceinline static GSVector4 cast(const GSVector8& v);
#endif
#if _M_SSE >= 0x501
__forceinline static GSVector4 cast(const GSVector8i& v);
#endif
__forceinline void operator = (const GSVector4& v)
{
m = v.m;
}
__forceinline void operator = (float f)
{
#if _M_SSE >= 0x501
m = _mm_broadcastss_ps(_mm_load_ss(&f));
#else
m = _mm_set1_ps(f);
#endif
}
__forceinline void operator = (__m128 m)
{
this->m = m;
}
__forceinline operator __m128() const
{
return m;
}
__forceinline uint32 rgba32() const
{
return GSVector4i(*this).rgba32();
}
__forceinline static GSVector4 rgba32(uint32 rgba)
{
return GSVector4(GSVector4i::load((int)rgba).u8to32());
}
__forceinline static GSVector4 rgba32(uint32 rgba, int shift)
{
return GSVector4(GSVector4i::load((int)rgba).u8to32() << shift);
}
__forceinline GSVector4 abs() const
{
return *this & cast(GSVector4i::x7fffffff());
}
__forceinline GSVector4 neg() const
{
return *this ^ cast(GSVector4i::x80000000());
}
__forceinline GSVector4 rcp() const
{
return GSVector4(_mm_rcp_ps(m));
}
__forceinline GSVector4 rcpnr() const
{
GSVector4 v = rcp();
return (v + v) - (v * v) * *this;
}
template<int mode> __forceinline GSVector4 round() const
{
#if _M_SSE >= 0x401
return GSVector4(_mm_round_ps(m, mode));
#else
GSVector4 a = *this;
GSVector4 b = (a & cast(GSVector4i::x80000000())) | m_x4b000000;
b = a + b - b;
if((mode & 7) == (Round_NegInf & 7))
{
return b - ((a < b) & m_one);
}
if((mode & 7) == (Round_PosInf & 7))
{
return b + ((a > b) & m_one);
}
ASSERT((mode & 7) == (Round_NearestInt & 7)); // other modes aren't implemented
return b;
#endif
}
__forceinline GSVector4 floor() const
{
return round<Round_NegInf>();
}
__forceinline GSVector4 ceil() const
{
return round<Round_PosInf>();
}
// http://jrfonseca.blogspot.com/2008/09/fast-sse2-pow-tables-or-polynomials.html
#define LOG_POLY0(x, c0) GSVector4(c0)
#define LOG_POLY1(x, c0, c1) (LOG_POLY0(x, c1).madd(x, GSVector4(c0)))
#define LOG_POLY2(x, c0, c1, c2) (LOG_POLY1(x, c1, c2).madd(x, GSVector4(c0)))
#define LOG_POLY3(x, c0, c1, c2, c3) (LOG_POLY2(x, c1, c2, c3).madd(x, GSVector4(c0)))
#define LOG_POLY4(x, c0, c1, c2, c3, c4) (LOG_POLY3(x, c1, c2, c3, c4).madd(x, GSVector4(c0)))
#define LOG_POLY5(x, c0, c1, c2, c3, c4, c5) (LOG_POLY4(x, c1, c2, c3, c4, c5).madd(x, GSVector4(c0)))
__forceinline GSVector4 log2(int precision = 5) const
{
// NOTE: sign bit ignored, safe to pass negative numbers
// The idea behind this algorithm is to split the float into two parts, log2(m * 2^e) => log2(m) + log2(2^e) => log2(m) + e,
// and then approximate the logarithm of the mantissa (it's 1.x when normalized, a nice short range).
GSVector4 one = m_one;
GSVector4i i = GSVector4i::cast(*this);
GSVector4 e = GSVector4(((i << 1) >> 24) - GSVector4i::x0000007f());
GSVector4 m = GSVector4::cast((i << 9) >> 9) | one;
GSVector4 p;
// Minimax polynomial fit of log2(x)/(x - 1), for x in range [1, 2[
switch(precision)
{
case 3:
p = LOG_POLY2(m, 2.28330284476918490682f, -1.04913055217340124191f, 0.204446009836232697516f);
break;
case 4:
p = LOG_POLY3(m, 2.61761038894603480148f, -1.75647175389045657003f, 0.688243882994381274313f, -0.107254423828329604454f);
break;
default:
case 5:
p = LOG_POLY4(m, 2.8882704548164776201f, -2.52074962577807006663f, 1.48116647521213171641f, -0.465725644288844778798f, 0.0596515482674574969533f);
break;
case 6:
p = LOG_POLY5(m, 3.1157899f, -3.3241990f, 2.5988452f, -1.2315303f, 3.1821337e-1f, -3.4436006e-2f);
break;
}
// This effectively increases the polynomial degree by one, but ensures that log2(1) == 0
p = p * (m - one);
return p + e;
}
__forceinline GSVector4 madd(const GSVector4& a, const GSVector4& b) const
{
#if 0//_M_SSE >= 0x501
return GSVector4(_mm_fmadd_ps(m, a, b));
#else
return *this * a + b;
#endif
}
__forceinline GSVector4 msub(const GSVector4& a, const GSVector4& b) const
{
#if 0//_M_SSE >= 0x501
return GSVector4(_mm_fmsub_ps(m, a, b));
#else
return *this * a - b;
#endif
}
__forceinline GSVector4 nmadd(const GSVector4& a, const GSVector4& b) const
{
#if 0//_M_SSE >= 0x501
return GSVector4(_mm_fnmadd_ps(m, a, b));
#else
return b - *this * a;
#endif
}
__forceinline GSVector4 nmsub(const GSVector4& a, const GSVector4& b) const
{
#if 0//_M_SSE >= 0x501
return GSVector4(_mm_fnmsub_ps(m, a, b));
#else
return -b - *this * a;
#endif
}
__forceinline GSVector4 addm(const GSVector4& a, const GSVector4& b) const
{
return a.madd(b, *this); // *this + a * b
}
__forceinline GSVector4 subm(const GSVector4& a, const GSVector4& b) const
{
return a.nmadd(b, *this); // *this - a * b
}
__forceinline GSVector4 hadd() const
{
#if _M_SSE >= 0x300
return GSVector4(_mm_hadd_ps(m, m));
#else
return xzxz() + ywyw();
#endif
}
__forceinline GSVector4 hadd(const GSVector4& v) const
{
#if _M_SSE >= 0x300
return GSVector4(_mm_hadd_ps(m, v.m));
#else
return xzxz(v) + ywyw(v);
#endif
}
__forceinline GSVector4 hsub() const
{
#if _M_SSE >= 0x300
return GSVector4(_mm_hsub_ps(m, m));
#else
return xzxz() - ywyw();
#endif
}
__forceinline GSVector4 hsub(const GSVector4& v) const
{
#if _M_SSE >= 0x300
return GSVector4(_mm_hsub_ps(m, v.m));
#else
return xzxz(v) - ywyw(v);
#endif
}
#if _M_SSE >= 0x401
template<int i> __forceinline GSVector4 dp(const GSVector4& v) const
{
return GSVector4(_mm_dp_ps(m, v.m, i));
}
#endif
__forceinline GSVector4 sat(const GSVector4& a, const GSVector4& b) const
{
return GSVector4(_mm_min_ps(_mm_max_ps(m, a), b));
}
__forceinline GSVector4 sat(const GSVector4& a) const
{
return GSVector4(_mm_min_ps(_mm_max_ps(m, a.xyxy()), a.zwzw()));
}
__forceinline GSVector4 sat(const float scale = 255) const
{
return sat(zero(), GSVector4(scale));
}
__forceinline GSVector4 clamp(const float scale = 255) const
{
return min(GSVector4(scale));
}
__forceinline GSVector4 min(const GSVector4& a) const
{
return GSVector4(_mm_min_ps(m, a));
}
__forceinline GSVector4 max(const GSVector4& a) const
{
return GSVector4(_mm_max_ps(m, a));
}
#if _M_SSE >= 0x401
template<int mask> __forceinline GSVector4 blend32(const GSVector4& a) const
{
return GSVector4(_mm_blend_ps(m, a, mask));
}
#endif
__forceinline GSVector4 blend32(const GSVector4& a, const GSVector4& mask) const
{
#if _M_SSE >= 0x401
return GSVector4(_mm_blendv_ps(m, a, mask));
#else
return GSVector4(_mm_or_ps(_mm_andnot_ps(mask, m), _mm_and_ps(mask, a)));
#endif
}
__forceinline GSVector4 upl(const GSVector4& a) const
{
return GSVector4(_mm_unpacklo_ps(m, a));
}
__forceinline GSVector4 uph(const GSVector4& a) const
{
return GSVector4(_mm_unpackhi_ps(m, a));
}
__forceinline GSVector4 upld(const GSVector4& a) const
{
return GSVector4(_mm_castpd_ps(_mm_unpacklo_pd(_mm_castps_pd(m), _mm_castps_pd(a.m))));
}
__forceinline GSVector4 uphd(const GSVector4& a) const
{
return GSVector4(_mm_castpd_ps(_mm_unpackhi_pd(_mm_castps_pd(m), _mm_castps_pd(a.m))));
}
__forceinline GSVector4 l2h(const GSVector4& a) const
{
return GSVector4(_mm_movelh_ps(m, a));
}
__forceinline GSVector4 h2l(const GSVector4& a) const
{
return GSVector4(_mm_movehl_ps(m, a));
}
__forceinline GSVector4 andnot(const GSVector4& v) const
{
return GSVector4(_mm_andnot_ps(v.m, m));
}
__forceinline int mask() const
{
return _mm_movemask_ps(m);
}
__forceinline bool alltrue() const
{
return mask() == 0xf;
}
__forceinline bool allfalse() const
{
#if _M_SSE >= 0x500
return _mm_testz_ps(m, m) != 0;
#elif _M_SSE >= 0x401
__m128i a = _mm_castps_si128(m);
return _mm_testz_si128(a, a) != 0;
#else
return mask() == 0;
#endif
}
__forceinline GSVector4 replace_nan(const GSVector4& v) const
{
return v.blend32(*this, *this == *this);
}
template<int src, int dst> __forceinline GSVector4 insert32(const GSVector4& v) const
{
// TODO: use blendps when src == dst
#if 0 // _M_SSE >= 0x401
// NOTE: it's faster with shuffles...
return GSVector4(_mm_insert_ps(m, v.m, _MM_MK_INSERTPS_NDX(src, dst, 0)));
#else
switch(dst)
{
case 0:
switch(src)
{
case 0: return yyxx(v).zxzw(*this);
case 1: return yyyy(v).zxzw(*this);
case 2: return yyzz(v).zxzw(*this);
case 3: return yyww(v).zxzw(*this);
default: __assume(0);
}
break;
case 1:
switch(src)
{
case 0: return xxxx(v).xzzw(*this);
case 1: return xxyy(v).xzzw(*this);
case 2: return xxzz(v).xzzw(*this);
case 3: return xxww(v).xzzw(*this);
default: __assume(0);
}
break;
case 2:
switch(src)
{
case 0: return xyzx(wwxx(v));
case 1: return xyzx(wwyy(v));
case 2: return xyzx(wwzz(v));
case 3: return xyzx(wwww(v));
default: __assume(0);
}
break;
case 3:
switch(src)
{
case 0: return xyxz(zzxx(v));
case 1: return xyxz(zzyy(v));
case 2: return xyxz(zzzz(v));
case 3: return xyxz(zzww(v));
default: __assume(0);
}
break;
default:
__assume(0);
}
#endif
}
#ifdef __linux__
#if 0
// Debug build error, _mm_extract_ps is actually a macro that use an anonymous union
// that contains i. I decide to rename the template on linux but it makes windows unhappy
// Hence the nice ifdef
//
// Code extract:
// union { int i; float f; } __tmp;
GSVector.h:2977:40: error: declaration of 'int GSVector4::extract32() const::<anonymous union>::i'
return _mm_extract_ps(m, i);
GSVector.h:2973:15: error: shadows template parm 'int i'
template<int i> __forceinline int extract32() const
#endif
template<int index> __forceinline int extract32() const
{
#if _M_SSE >= 0x401
return _mm_extract_ps(m, index);
#else
return i32[index];
#endif
}
#else
template<int i> __forceinline int extract32() const
{
#if _M_SSE >= 0x401
return _mm_extract_ps(m, i);
#else
return i32[i];
#endif
}
#endif
__forceinline static GSVector4 zero()
{
return GSVector4(_mm_setzero_ps());
}
__forceinline static GSVector4 xffffffff()
{
return zero() == zero();
}
__forceinline static GSVector4 ps0123()
{
return GSVector4(m_ps0123);
}
__forceinline static GSVector4 ps4567()
{
return GSVector4(m_ps4567);
}
__forceinline static GSVector4 loadl(const void* p)
{
return GSVector4(_mm_castpd_ps(_mm_load_sd((double*)p)));
}
__forceinline static GSVector4 load(float f)
{
return GSVector4(_mm_load_ss(&f));
}
__forceinline static GSVector4 load(uint32 u)
{
GSVector4i v = GSVector4i::load((int)u);
return GSVector4(v) + (m_x4f800000 & GSVector4::cast(v.sra32(31)));
}
template<bool aligned> __forceinline static GSVector4 load(const void* p)
{
return GSVector4(aligned ? _mm_load_ps((const float*)p) : _mm_loadu_ps((const float*)p));
}
__forceinline static void storent(void* p, const GSVector4& v)
{
_mm_stream_ps((float*)p, v.m);
}
__forceinline static void storel(void* p, const GSVector4& v)
{
_mm_store_sd((double*)p, _mm_castps_pd(v.m));
}
__forceinline static void storeh(void* p, const GSVector4& v)
{
_mm_storeh_pd((double*)p, _mm_castps_pd(v.m));
}
template<bool aligned> __forceinline static void store(void* p, const GSVector4& v)
{
if(aligned) _mm_store_ps((float*)p, v.m);
else _mm_storeu_ps((float*)p, v.m);
}
__forceinline static void store(float* p, const GSVector4& v)
{
_mm_store_ss(p, v.m);
}
__forceinline static void expand(const GSVector4i& v, GSVector4& a, GSVector4& b, GSVector4& c, GSVector4& d)
{
GSVector4i mask = GSVector4i::x000000ff();
a = GSVector4(v & mask);
b = GSVector4((v >> 8) & mask);
c = GSVector4((v >> 16) & mask);
d = GSVector4((v >> 24));
}
__forceinline static void transpose(GSVector4& a, GSVector4& b, GSVector4& c, GSVector4& d)
{
GSVector4 v0 = a.xyxy(b);
GSVector4 v1 = c.xyxy(d);
GSVector4 e = v0.xzxz(v1);
GSVector4 f = v0.ywyw(v1);
GSVector4 v2 = a.zwzw(b);
GSVector4 v3 = c.zwzw(d);
GSVector4 g = v2.xzxz(v3);
GSVector4 h = v2.ywyw(v3);
a = e;
b = f;
c = g;
d = h;
/*
GSVector4 v0 = a.xyxy(b);
GSVector4 v1 = c.xyxy(d);
GSVector4 v2 = a.zwzw(b);
GSVector4 v3 = c.zwzw(d);
a = v0.xzxz(v1);
b = v0.ywyw(v1);
c = v2.xzxz(v3);
d = v2.ywyw(v3);
*/
/*
GSVector4 v0 = a.upl(b);
GSVector4 v1 = a.uph(b);
GSVector4 v2 = c.upl(d);
GSVector4 v3 = c.uph(d);
a = v0.l2h(v2);
b = v2.h2l(v0);
c = v1.l2h(v3);
d = v3.h2l(v1);
*/ }
__forceinline GSVector4 operator - () const
{
return neg();
}
__forceinline void operator += (const GSVector4& v)
{
m = _mm_add_ps(m, v);
}
__forceinline void operator -= (const GSVector4& v)
{
m = _mm_sub_ps(m, v);
}
__forceinline void operator *= (const GSVector4& v)
{
m = _mm_mul_ps(m, v);
}
__forceinline void operator /= (const GSVector4& v)
{
m = _mm_div_ps(m, v);
}
__forceinline void operator += (float f)
{
*this += GSVector4(f);
}
__forceinline void operator -= (float f)
{
*this -= GSVector4(f);
}
__forceinline void operator *= (float f)
{
*this *= GSVector4(f);
}
__forceinline void operator /= (float f)
{
*this /= GSVector4(f);
}
__forceinline void operator &= (const GSVector4& v)
{
m = _mm_and_ps(m, v);
}
__forceinline void operator |= (const GSVector4& v)
{
m = _mm_or_ps(m, v);
}
__forceinline void operator ^= (const GSVector4& v)
{
m = _mm_xor_ps(m, v);
}
__forceinline friend GSVector4 operator + (const GSVector4& v1, const GSVector4& v2)
{
return GSVector4(_mm_add_ps(v1, v2));
}
__forceinline friend GSVector4 operator - (const GSVector4& v1, const GSVector4& v2)
{
return GSVector4(_mm_sub_ps(v1, v2));
}
__forceinline friend GSVector4 operator * (const GSVector4& v1, const GSVector4& v2)
{
return GSVector4(_mm_mul_ps(v1, v2));
}
__forceinline friend GSVector4 operator / (const GSVector4& v1, const GSVector4& v2)
{
return GSVector4(_mm_div_ps(v1, v2));
}
__forceinline friend GSVector4 operator + (const GSVector4& v, float f)
{
return v + GSVector4(f);
}
__forceinline friend GSVector4 operator - (const GSVector4& v, float f)
{
return v - GSVector4(f);
}
__forceinline friend GSVector4 operator * (const GSVector4& v, float f)
{
return v * GSVector4(f);
}
__forceinline friend GSVector4 operator / (const GSVector4& v, float f)
{
return v / GSVector4(f);
}
__forceinline friend GSVector4 operator & (const GSVector4& v1, const GSVector4& v2)
{
return GSVector4(_mm_and_ps(v1, v2));
}
__forceinline friend GSVector4 operator | (const GSVector4& v1, const GSVector4& v2)
{
return GSVector4(_mm_or_ps(v1, v2));
}
__forceinline friend GSVector4 operator ^ (const GSVector4& v1, const GSVector4& v2)
{
return GSVector4(_mm_xor_ps(v1, v2));
}
__forceinline friend GSVector4 operator == (const GSVector4& v1, const GSVector4& v2)
{
return GSVector4(_mm_cmpeq_ps(v1, v2));
}
__forceinline friend GSVector4 operator != (const GSVector4& v1, const GSVector4& v2)
{
return GSVector4(_mm_cmpneq_ps(v1, v2));
}
__forceinline friend GSVector4 operator > (const GSVector4& v1, const GSVector4& v2)
{
return GSVector4(_mm_cmpgt_ps(v1, v2));
}
__forceinline friend GSVector4 operator < (const GSVector4& v1, const GSVector4& v2)
{
return GSVector4(_mm_cmplt_ps(v1, v2));
}
__forceinline friend GSVector4 operator >= (const GSVector4& v1, const GSVector4& v2)
{
return GSVector4(_mm_cmpge_ps(v1, v2));
}
__forceinline friend GSVector4 operator <= (const GSVector4& v1, const GSVector4& v2)
{
return GSVector4(_mm_cmple_ps(v1, v2));
}
#define VECTOR4_SHUFFLE_4(xs, xn, ys, yn, zs, zn, ws, wn) \
__forceinline GSVector4 xs##ys##zs##ws() const {return GSVector4(_mm_shuffle_ps(m, m, _MM_SHUFFLE(wn, zn, yn, xn)));} \
__forceinline GSVector4 xs##ys##zs##ws(const GSVector4& v) const {return GSVector4(_mm_shuffle_ps(m, v.m, _MM_SHUFFLE(wn, zn, yn, xn)));} \
#define VECTOR4_SHUFFLE_3(xs, xn, ys, yn, zs, zn) \
VECTOR4_SHUFFLE_4(xs, xn, ys, yn, zs, zn, x, 0) \
VECTOR4_SHUFFLE_4(xs, xn, ys, yn, zs, zn, y, 1) \
VECTOR4_SHUFFLE_4(xs, xn, ys, yn, zs, zn, z, 2) \
VECTOR4_SHUFFLE_4(xs, xn, ys, yn, zs, zn, w, 3) \
#define VECTOR4_SHUFFLE_2(xs, xn, ys, yn) \
VECTOR4_SHUFFLE_3(xs, xn, ys, yn, x, 0) \
VECTOR4_SHUFFLE_3(xs, xn, ys, yn, y, 1) \
VECTOR4_SHUFFLE_3(xs, xn, ys, yn, z, 2) \
VECTOR4_SHUFFLE_3(xs, xn, ys, yn, w, 3) \
#define VECTOR4_SHUFFLE_1(xs, xn) \
VECTOR4_SHUFFLE_2(xs, xn, x, 0) \
VECTOR4_SHUFFLE_2(xs, xn, y, 1) \
VECTOR4_SHUFFLE_2(xs, xn, z, 2) \
VECTOR4_SHUFFLE_2(xs, xn, w, 3) \
VECTOR4_SHUFFLE_1(x, 0)
VECTOR4_SHUFFLE_1(y, 1)
VECTOR4_SHUFFLE_1(z, 2)
VECTOR4_SHUFFLE_1(w, 3)
#if _M_SSE >= 0x501
__forceinline GSVector4 broadcast32() const
{
return GSVector4(_mm_broadcastss_ps(m));
}
__forceinline static GSVector4 broadcast32(const GSVector4& v)
{
return GSVector4(_mm_broadcastss_ps(v.m));
}
__forceinline static GSVector4 broadcast32(const void* f)
{
return GSVector4(_mm_broadcastss_ps(_mm_load_ss((const float*)f)));
}
#endif
};
|