Skip to content

Commit 295f6c4

Browse files
bvisnessZak Strange
authored andcommitted
Rename Rows to Columns on hmm_mat4 (#91)
1 parent e095aef commit 295f6c4

3 files changed

Lines changed: 39 additions & 32 deletions

File tree

HandmadeMath.h

Lines changed: 34 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
HandmadeMath.h v1.6.0
2+
HandmadeMath.h v1.7.0
33
44
This is a single header file with a bunch of useful functions for game and
55
graphics math operations.
@@ -172,6 +172,10 @@
172172
(*) Added array subscript operators for vector and matrix types in
173173
C++. This is provided as a convenience, but be aware that it may
174174
incur an extra function call in unoptimized builds.
175+
1.7.0
176+
(*) Renamed the 'Rows' member of hmm_mat4 to 'Columns'. Since our
177+
matrices are column-major, this should have been named 'Columns'
178+
from the start. 'Rows' is still present, but has been deprecated.
175179
176180
177181
LICENSE
@@ -447,6 +451,10 @@ typedef union hmm_mat4
447451
float Elements[4][4];
448452

449453
#ifdef HANDMADE_MATH__USE_SSE
454+
__m128 Columns[4];
455+
456+
// DEPRECATED. Our matrices are column-major, so this was named
457+
// incorrectly. Use Columns instead.
450458
__m128 Rows[4];
451459
#endif
452460

@@ -1129,10 +1137,10 @@ HMM_INLINE hmm_vec4 HMM_NormalizeVec4(hmm_vec4 A)
11291137
HMM_INLINE __m128 HMM_LinearCombineSSE(__m128 Left, hmm_mat4 Right)
11301138
{
11311139
__m128 Result;
1132-
Result = _mm_mul_ps(_mm_shuffle_ps(Left, Left, 0x00), Right.Rows[0]);
1133-
Result = _mm_add_ps(Result, _mm_mul_ps(_mm_shuffle_ps(Left, Left, 0x55), Right.Rows[1]));
1134-
Result = _mm_add_ps(Result, _mm_mul_ps(_mm_shuffle_ps(Left, Left, 0xaa), Right.Rows[2]));
1135-
Result = _mm_add_ps(Result, _mm_mul_ps(_mm_shuffle_ps(Left, Left, 0xff), Right.Rows[3]));
1140+
Result = _mm_mul_ps(_mm_shuffle_ps(Left, Left, 0x00), Right.Columns[0]);
1141+
Result = _mm_add_ps(Result, _mm_mul_ps(_mm_shuffle_ps(Left, Left, 0x55), Right.Columns[1]));
1142+
Result = _mm_add_ps(Result, _mm_mul_ps(_mm_shuffle_ps(Left, Left, 0xaa), Right.Columns[2]));
1143+
Result = _mm_add_ps(Result, _mm_mul_ps(_mm_shuffle_ps(Left, Left, 0xff), Right.Columns[3]));
11361144

11371145
return (Result);
11381146
}
@@ -1167,7 +1175,7 @@ HMM_INLINE hmm_mat4 HMM_Transpose(hmm_mat4 Matrix)
11671175
{
11681176
hmm_mat4 Result = Matrix;
11691177

1170-
_MM_TRANSPOSE4_PS(Result.Rows[0], Result.Rows[1], Result.Rows[2], Result.Rows[3]);
1178+
_MM_TRANSPOSE4_PS(Result.Columns[0], Result.Columns[1], Result.Columns[2], Result.Columns[3]);
11711179

11721180
return (Result);
11731181
}
@@ -1180,10 +1188,10 @@ HMM_INLINE hmm_mat4 HMM_AddMat4(hmm_mat4 Left, hmm_mat4 Right)
11801188
{
11811189
hmm_mat4 Result;
11821190

1183-
Result.Rows[0] = _mm_add_ps(Left.Rows[0], Right.Rows[0]);
1184-
Result.Rows[1] = _mm_add_ps(Left.Rows[1], Right.Rows[1]);
1185-
Result.Rows[2] = _mm_add_ps(Left.Rows[2], Right.Rows[2]);
1186-
Result.Rows[3] = _mm_add_ps(Left.Rows[3], Right.Rows[3]);
1191+
Result.Columns[0] = _mm_add_ps(Left.Columns[0], Right.Columns[0]);
1192+
Result.Columns[1] = _mm_add_ps(Left.Columns[1], Right.Columns[1]);
1193+
Result.Columns[2] = _mm_add_ps(Left.Columns[2], Right.Columns[2]);
1194+
Result.Columns[3] = _mm_add_ps(Left.Columns[3], Right.Columns[3]);
11871195

11881196
return (Result);
11891197
}
@@ -1196,10 +1204,10 @@ HMM_INLINE hmm_mat4 HMM_SubtractMat4(hmm_mat4 Left, hmm_mat4 Right)
11961204
{
11971205
hmm_mat4 Result;
11981206

1199-
Result.Rows[0] = _mm_sub_ps(Left.Rows[0], Right.Rows[0]);
1200-
Result.Rows[1] = _mm_sub_ps(Left.Rows[1], Right.Rows[1]);
1201-
Result.Rows[2] = _mm_sub_ps(Left.Rows[2], Right.Rows[2]);
1202-
Result.Rows[3] = _mm_sub_ps(Left.Rows[3], Right.Rows[3]);
1207+
Result.Columns[0] = _mm_sub_ps(Left.Columns[0], Right.Columns[0]);
1208+
Result.Columns[1] = _mm_sub_ps(Left.Columns[1], Right.Columns[1]);
1209+
Result.Columns[2] = _mm_sub_ps(Left.Columns[2], Right.Columns[2]);
1210+
Result.Columns[3] = _mm_sub_ps(Left.Columns[3], Right.Columns[3]);
12031211

12041212
return (Result);
12051213
}
@@ -1215,10 +1223,10 @@ HMM_INLINE hmm_mat4 HMM_MultiplyMat4f(hmm_mat4 Matrix, float Scalar)
12151223
hmm_mat4 Result;
12161224

12171225
__m128 SSEScalar = _mm_set1_ps(Scalar);
1218-
Result.Rows[0] = _mm_mul_ps(Matrix.Rows[0], SSEScalar);
1219-
Result.Rows[1] = _mm_mul_ps(Matrix.Rows[1], SSEScalar);
1220-
Result.Rows[2] = _mm_mul_ps(Matrix.Rows[2], SSEScalar);
1221-
Result.Rows[3] = _mm_mul_ps(Matrix.Rows[3], SSEScalar);
1226+
Result.Columns[0] = _mm_mul_ps(Matrix.Columns[0], SSEScalar);
1227+
Result.Columns[1] = _mm_mul_ps(Matrix.Columns[1], SSEScalar);
1228+
Result.Columns[2] = _mm_mul_ps(Matrix.Columns[2], SSEScalar);
1229+
Result.Columns[3] = _mm_mul_ps(Matrix.Columns[3], SSEScalar);
12221230

12231231
return (Result);
12241232
}
@@ -1234,10 +1242,10 @@ HMM_INLINE hmm_mat4 HMM_DivideMat4f(hmm_mat4 Matrix, float Scalar)
12341242
hmm_mat4 Result;
12351243

12361244
__m128 SSEScalar = _mm_set1_ps(Scalar);
1237-
Result.Rows[0] = _mm_div_ps(Matrix.Rows[0], SSEScalar);
1238-
Result.Rows[1] = _mm_div_ps(Matrix.Rows[1], SSEScalar);
1239-
Result.Rows[2] = _mm_div_ps(Matrix.Rows[2], SSEScalar);
1240-
Result.Rows[3] = _mm_div_ps(Matrix.Rows[3], SSEScalar);
1245+
Result.Columns[0] = _mm_div_ps(Matrix.Columns[0], SSEScalar);
1246+
Result.Columns[1] = _mm_div_ps(Matrix.Columns[1], SSEScalar);
1247+
Result.Columns[2] = _mm_div_ps(Matrix.Columns[2], SSEScalar);
1248+
Result.Columns[3] = _mm_div_ps(Matrix.Columns[3], SSEScalar);
12411249

12421250
return (Result);
12431251
}
@@ -2252,10 +2260,10 @@ hmm_mat4 HMM_MultiplyMat4(hmm_mat4 Left, hmm_mat4 Right)
22522260

22532261
#ifdef HANDMADE_MATH__USE_SSE
22542262

2255-
Result.Rows[0] = HMM_LinearCombineSSE(Right.Rows[0], Left);
2256-
Result.Rows[1] = HMM_LinearCombineSSE(Right.Rows[1], Left);
2257-
Result.Rows[2] = HMM_LinearCombineSSE(Right.Rows[2], Left);
2258-
Result.Rows[3] = HMM_LinearCombineSSE(Right.Rows[3], Left);
2263+
Result.Columns[0] = HMM_LinearCombineSSE(Right.Columns[0], Left);
2264+
Result.Columns[1] = HMM_LinearCombineSSE(Right.Columns[1], Left);
2265+
Result.Columns[2] = HMM_LinearCombineSSE(Right.Columns[2], Left);
2266+
Result.Columns[3] = HMM_LinearCombineSSE(Right.Columns[3], Left);
22592267

22602268
#else
22612269
int Columns;

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ To get started, go download [the latest release](https://github.com/HandmadeMath
1010

1111
Version | Changes |
1212
----------------|----------------|
13+
**1.7.0** | Renamed the 'Rows' member of hmm_mat4 to 'Columns'. Since our matrices are column-major, this should have been named 'Columns' from the start. 'Rows' is still present, but has been deprecated.
1314
**1.6.0** | Added array subscript operators for vector and matrix types in C++. This is provided as a convenience, but be aware that it may incur an extra function call in unoptimized builds.
1415
**1.5.1** | Fixed a bug with uninitialized elements in HMM_LookAt.
1516
**1.5.0** | Changed internal structure for better performance and inlining. As a result, `HANDMADE_MATH_NO_INLINE` has been removed and no longer has any effect.

test/categories/SSE.h

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ TEST(SSE, LinearCombine)
88
hmm_mat4 MatrixTwo = HMM_Mat4d(4.0f);
99
hmm_mat4 Result;
1010

11-
Result.Rows[0] = HMM_LinearCombineSSE(MatrixOne.Rows[0], MatrixTwo);
12-
Result.Rows[1] = HMM_LinearCombineSSE(MatrixOne.Rows[1], MatrixTwo);
13-
Result.Rows[2] = HMM_LinearCombineSSE(MatrixOne.Rows[2], MatrixTwo);
14-
Result.Rows[3] = HMM_LinearCombineSSE(MatrixOne.Rows[3], MatrixTwo);
11+
Result.Columns[0] = HMM_LinearCombineSSE(MatrixOne.Columns[0], MatrixTwo);
12+
Result.Columns[1] = HMM_LinearCombineSSE(MatrixOne.Columns[1], MatrixTwo);
13+
Result.Columns[2] = HMM_LinearCombineSSE(MatrixOne.Columns[2], MatrixTwo);
14+
Result.Columns[3] = HMM_LinearCombineSSE(MatrixOne.Columns[3], MatrixTwo);
1515

1616
{
1717
EXPECT_FLOAT_EQ(Result.Elements[0][0], 8.0f);
@@ -23,14 +23,12 @@ TEST(SSE, LinearCombine)
2323
EXPECT_FLOAT_EQ(Result.Elements[1][1], 8.0f);
2424
EXPECT_FLOAT_EQ(Result.Elements[1][2], 0.0f);
2525
EXPECT_FLOAT_EQ(Result.Elements[1][3], 0.0f);
26-
2726

2827
EXPECT_FLOAT_EQ(Result.Elements[2][0], 0.0f);
2928
EXPECT_FLOAT_EQ(Result.Elements[2][1], 0.0f);
3029
EXPECT_FLOAT_EQ(Result.Elements[2][2], 8.0f);
3130
EXPECT_FLOAT_EQ(Result.Elements[2][3], 0.0f);
3231

33-
3432
EXPECT_FLOAT_EQ(Result.Elements[3][0], 0.0f);
3533
EXPECT_FLOAT_EQ(Result.Elements[3][1], 0.0f);
3634
EXPECT_FLOAT_EQ(Result.Elements[3][2], 0.0f);

0 commit comments

Comments
 (0)