cleanup in vec4
This commit is contained in:
@@ -50,18 +50,34 @@ class Vec4 {
|
|||||||
/** Initialize Vec4 with float[4] values */
|
/** Initialize Vec4 with float[4] values */
|
||||||
explicit Vec4(const float* v) { copy(this, v); }
|
explicit Vec4(const float* v) { copy(this, v); }
|
||||||
|
|
||||||
Vec4 operator+(const Vec4& v) const;
|
/** copy */
|
||||||
Vec4 operator-(const Vec4& v) const;
|
|
||||||
/** Cross product */
|
|
||||||
Vec4 operator*(const Vec4& v) const;
|
|
||||||
Vec4 operator*(const float& v) const;
|
|
||||||
Vec4 operator/(const float& v) const;
|
|
||||||
Vec4 operator/(const Vec4& v) const;
|
|
||||||
Vec4 operator-(void) const;
|
|
||||||
void operator=(const Vec4& v);
|
void operator=(const Vec4& v);
|
||||||
|
|
||||||
|
/** negate xyz */
|
||||||
|
Vec4 operator-(void) const;
|
||||||
|
|
||||||
|
/** xyz + xyz */
|
||||||
|
Vec4 operator+(const Vec4& v) const;
|
||||||
void operator+=(const Vec4& v);
|
void operator+=(const Vec4& v);
|
||||||
void operator*=(const float& v);
|
|
||||||
|
/** xyz - xyz */
|
||||||
|
Vec4 operator-(const Vec4& v) const;
|
||||||
|
void operator-=(const Vec4& v);
|
||||||
|
|
||||||
|
/** xyzw * xyzw */
|
||||||
|
Vec4 operator*(const Vec4& v) const;
|
||||||
void operator*=(const Vec4& v);
|
void operator*=(const Vec4& v);
|
||||||
|
|
||||||
|
/** xyzw / xyzw */
|
||||||
|
Vec4 operator/(const Vec4& v) const;
|
||||||
|
void operator/=(const Vec4& v);
|
||||||
|
|
||||||
|
/** xyz * v */
|
||||||
|
Vec4 operator*(const float& v) const;
|
||||||
|
void operator*=(const float& v);
|
||||||
|
|
||||||
|
/** xyz / v */
|
||||||
|
Vec4 operator/(const float& v) const;
|
||||||
void operator/=(const float& v);
|
void operator/=(const float& v);
|
||||||
|
|
||||||
/** (0,0,0,1) */
|
/** (0,0,0,1) */
|
||||||
|
|||||||
+52
-41
@@ -23,6 +23,10 @@ void Vec4::set(const float& t_x, const float& t_y, const float& t_z,
|
|||||||
w = t_w;
|
w = t_w;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Vec4::operator=(const Vec4& v) { copy(this, v); }
|
||||||
|
|
||||||
|
Vec4 Vec4::operator-(void) const { return Vec4(-x, -y, -z, w); }
|
||||||
|
|
||||||
Vec4 Vec4::operator+(const Vec4& v) const {
|
Vec4 Vec4::operator+(const Vec4& v) const {
|
||||||
Vec4 res;
|
Vec4 res;
|
||||||
asm volatile(
|
asm volatile(
|
||||||
@@ -35,6 +39,16 @@ Vec4 Vec4::operator+(const Vec4& v) const {
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Vec4::operator+=(const Vec4& v) {
|
||||||
|
asm volatile(
|
||||||
|
"lqc2 $vf4, 0x0(%0) \n\t"
|
||||||
|
"lqc2 $vf5, 0x0(%1) \n\t"
|
||||||
|
"vadd.xyz $vf4, $vf4, $vf5 \n\t"
|
||||||
|
"sqc2 $vf4, 0x0(%0) \n\t"
|
||||||
|
:
|
||||||
|
: "r"(this->xyzw), "r"(v.xyzw));
|
||||||
|
}
|
||||||
|
|
||||||
Vec4 Vec4::operator-(const Vec4& v) const {
|
Vec4 Vec4::operator-(const Vec4& v) const {
|
||||||
Vec4 res;
|
Vec4 res;
|
||||||
asm volatile(
|
asm volatile(
|
||||||
@@ -47,6 +61,16 @@ Vec4 Vec4::operator-(const Vec4& v) const {
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Vec4::operator-=(const Vec4& v) {
|
||||||
|
asm volatile(
|
||||||
|
"lqc2 $vf4, 0x0(%0) \n\t"
|
||||||
|
"lqc2 $vf5, 0x0(%1) \n\t"
|
||||||
|
"vsub.xyz $vf4, $vf4, $vf5 \n\t"
|
||||||
|
"sqc2 $vf4, 0x0(%0) \n\t"
|
||||||
|
:
|
||||||
|
: "r"(this->xyzw), "r"(v.xyzw));
|
||||||
|
}
|
||||||
|
|
||||||
Vec4 Vec4::operator*(const Vec4& v) const {
|
Vec4 Vec4::operator*(const Vec4& v) const {
|
||||||
Vec4 res;
|
Vec4 res;
|
||||||
asm volatile(
|
asm volatile(
|
||||||
@@ -59,38 +83,6 @@ Vec4 Vec4::operator*(const Vec4& v) const {
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
Vec4 Vec4::operator*(const float& v) const {
|
|
||||||
Vec4 res;
|
|
||||||
asm volatile(
|
|
||||||
"lqc2 $vf4, 0x0(%1) \n\t"
|
|
||||||
"mfc1 $8, %2 \n\t"
|
|
||||||
"qmtc2 $8, $vf5 \n\t"
|
|
||||||
"vmulx.xyz $vf6, $vf4, $vf5 \n\t"
|
|
||||||
"sqc2 $vf6, 0x0(%0) \n\t"
|
|
||||||
:
|
|
||||||
: "r"(res.xyzw), "r"(this->xyzw), "f"(v));
|
|
||||||
res.w = w;
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
Vec4 Vec4::operator/(const float& v) const {
|
|
||||||
return Vec4(x / v, y / v, z / v, w);
|
|
||||||
}
|
|
||||||
|
|
||||||
Vec4 Vec4::operator/(const Vec4& v) const {
|
|
||||||
return Vec4(x / v.x, y / v.y, z / v.z, w);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Vec4::operator+=(const Vec4& v) {
|
|
||||||
asm volatile(
|
|
||||||
"lqc2 $vf4, 0x0(%0) \n\t"
|
|
||||||
"lqc2 $vf5, 0x0(%1) \n\t"
|
|
||||||
"vadd.xyz $vf4, $vf4, $vf5 \n\t"
|
|
||||||
"sqc2 $vf4, 0x0(%0) \n\t"
|
|
||||||
:
|
|
||||||
: "r"(this->xyzw), "r"(v.xyzw));
|
|
||||||
}
|
|
||||||
|
|
||||||
void Vec4::operator*=(const Vec4& v) {
|
void Vec4::operator*=(const Vec4& v) {
|
||||||
asm volatile(
|
asm volatile(
|
||||||
"lqc2 $vf4, 0x0(%0) \n\t"
|
"lqc2 $vf4, 0x0(%0) \n\t"
|
||||||
@@ -101,11 +93,32 @@ void Vec4::operator*=(const Vec4& v) {
|
|||||||
: "r"(this->xyzw), "r"(v.xyzw));
|
: "r"(this->xyzw), "r"(v.xyzw));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Vec4::operator*=(const float& v) {
|
Vec4 Vec4::operator/(const Vec4& v) const {
|
||||||
// Hmm... we don't want to modify W in most of the cases
|
return Vec4(x / v.x, y / v.y, z / v.z, w / v.w);
|
||||||
// It should be touched only during rendering process
|
}
|
||||||
auto tempW = w;
|
|
||||||
|
|
||||||
|
void Vec4::operator/=(const Vec4& v) {
|
||||||
|
x /= v.x;
|
||||||
|
y /= v.y;
|
||||||
|
z /= v.z;
|
||||||
|
w /= v.w;
|
||||||
|
}
|
||||||
|
|
||||||
|
Vec4 Vec4::operator*(const float& v) const {
|
||||||
|
Vec4 res;
|
||||||
|
asm volatile(
|
||||||
|
"lqc2 $vf4, 0x0(%1) \n\t"
|
||||||
|
"mfc1 $8, %2 \n\t"
|
||||||
|
"qmtc2 $8, $vf5 \n\t"
|
||||||
|
"vmulx.xyz $vf6, $vf4, $vf5 \n\t"
|
||||||
|
"vmove.w $vf6, $vf4 \n\t"
|
||||||
|
"sqc2 $vf6, 0x0(%0) \n\t"
|
||||||
|
:
|
||||||
|
: "r"(res.xyzw), "r"(this->xyzw), "f"(v));
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Vec4::operator*=(const float& v) {
|
||||||
asm volatile(
|
asm volatile(
|
||||||
"lqc2 $vf4, 0x0(%0) \n\t"
|
"lqc2 $vf4, 0x0(%0) \n\t"
|
||||||
"mfc1 $8, %1 \n\t"
|
"mfc1 $8, %1 \n\t"
|
||||||
@@ -114,8 +127,10 @@ void Vec4::operator*=(const float& v) {
|
|||||||
"sqc2 $vf4, 0x0(%0) \n\t"
|
"sqc2 $vf4, 0x0(%0) \n\t"
|
||||||
:
|
:
|
||||||
: "r"(this->xyzw), "f"(v));
|
: "r"(this->xyzw), "f"(v));
|
||||||
|
}
|
||||||
|
|
||||||
w = tempW;
|
Vec4 Vec4::operator/(const float& v) const {
|
||||||
|
return Vec4(x / v, y / v, z / v, w);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Vec4::operator/=(const float& v) {
|
void Vec4::operator/=(const float& v) {
|
||||||
@@ -124,10 +139,6 @@ void Vec4::operator/=(const float& v) {
|
|||||||
z /= v;
|
z /= v;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Vec4::operator=(const Vec4& v) { copy(this, v); }
|
|
||||||
|
|
||||||
Vec4 Vec4::operator-(void) const { return Vec4(-x, -y, -z); }
|
|
||||||
|
|
||||||
void Vec4::unit() {
|
void Vec4::unit() {
|
||||||
asm volatile("sqc2 $vf0, 0x00(%0) \n" : : "r"(this->xyzw));
|
asm volatile("sqc2 $vf0, 0x00(%0) \n" : : "r"(this->xyzw));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user