fpoint.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. // fpoint.h - [2020-04-13 11:57:47]
  2. #ifndef _FPOINT_H_
  3. #define _FPOINT_H_
  4. #include "common_type.h"
  5. #include "log.h"
  6. //-------------------------------------------------------------------------------------------------
  7. enum PointType : uint {
  8. PointType_0,
  9. PointType_14 = 14,
  10. PointType_18 = 18,
  11. PointType_26 = 26,
  12. };
  13. //-------------------------------------------------------------------------------------------------
  14. template <uint t>
  15. class fpoint {
  16. public:
  17. int var_0;
  18. //int test_4;//测试使用
  19. };
  20. //-------------------------------------------------------------------------------------------------
  21. template <PointType t>
  22. class fpoint2 {
  23. public:
  24. int x_0;
  25. int y_4;
  26. };
  27. //-------------------------------------------------------------------------------------------------
  28. template <uint t>
  29. class fpoint3 {
  30. public:
  31. fpoint3() {
  32. //x_0 = y_4 = z_8 = 0;
  33. }
  34. // 0016bea2 //^-^
  35. template <uint t1>
  36. __attribute__((noinline)) fpoint3(const fpoint3<t1>& pt1) {
  37. //这一段不知道为啥优化了
  38. x_0 = 0;
  39. y_4 = 0;
  40. z_8 = 0;
  41. x_0 = pt1.x_0 << 8;
  42. y_4 = pt1.y_4 << 8;
  43. z_8 = pt1.z_8 << 8;
  44. }
  45. int x_0;
  46. int y_4;
  47. int z_8;
  48. };
  49. //-------------------------------------------------------------------------------------------------
  50. template <uint t>
  51. class fpointQ {
  52. public:
  53. // 0016c652 //^_-
  54. fpointQ<t>& __attribute__((noinline)) operator+=(const fpointQ<t>& pt1) {
  55. /*
  56. 这几行赋值语句被优化成向量运算代码了
  57. 原始汇编:ldmia.w r0, {r2, r3, ip, lr}
  58. ldr r4, [r1, #0]
  59. add r2, r4
  60. str r2, [r0, #0]
  61. ...
  62. ldr r1, [r1, #12]
  63. add r1, lr
  64. str r1, [r0, #12]
  65. 自己汇编:adds r1,#36
  66. vld1.32 {d16,d17},[r1]
  67. vld1.32 {d18,d19},[r0]
  68. vadd q8,q9,q8
  69. vst1.32 {d16,d17{,[r0]
  70. */
  71. field_0 += pt1.field_0;
  72. field_4 += pt1.field_4;
  73. field_8 += pt1.field_8;
  74. field_C += pt1.field_C;
  75. return *this;
  76. }
  77. int field_0;
  78. int field_4;
  79. int field_8;
  80. int field_C;
  81. };
  82. //-------------------------------------------------------------------------------------------------
  83. template <uint t>
  84. class fpointQQ {
  85. public:
  86. fpointQQ() {
  87. for (int i = 0; i < 9; ++i)
  88. list_0[i] = 0;
  89. //field_24 = field_28 = field_2C = field_30 = 0;
  90. }
  91. // 0016da5e //^_-
  92. fpointQQ(const fpointQQ<t>& pt1) {
  93. int i = 0;
  94. // 16da6c
  95. for (i = 0; i < 9; ++i)
  96. list_0[i] = pt1.list_0[i];
  97. /*
  98. 这几行赋值语句被优化成向量运算代码了
  99. 原始汇编:ldr r2, [r1, #36]
  100. str r2, [r0, #36]
  101. ...
  102. ldr r1, [r1, #48]
  103. str r1, [r0, #48]
  104. 自己汇编:adds r1,#36
  105. vld1.32 {d16,d17},[r1]
  106. add.w r1,r0,#36
  107. vst1.32 {d16,d17{,[r1]
  108. */
  109. // field_24 = pt1.field_24;
  110. // field_28 = pt1.field_28;
  111. // field_2C = pt1.field_2C;
  112. // field_30 = pt1.field_30;
  113. fpointQ_24=pt1.fpointQ_24;
  114. }
  115. // 0016c4ba //^_-
  116. void Cache() {
  117. LOGE("Cache%x=",(uint)this);
  118. // int tmp_r6 = (int)(((int64)(field_28 * 2) * (int64)field_24) >> 18);
  119. // int tmp_r5 = (int)(((int64)(field_2C * 2) * (int64)field_30) >> 18);
  120. // list_0[1] = tmp_r6 - tmp_r5;
  121. // int tmp_r8 = (int)(((int64)(field_2C * 2) * (int64)field_24) >> 18);
  122. // int tmp_r7 = (int)(((int64)(field_28 * 2) * (int64)field_30) >> 18);
  123. // list_0[3] = tmp_r5 + tmp_r6;
  124. // list_0[2] = tmp_r8 + tmp_r7;
  125. // int tmp_r4 = (int)(((int64)field_30 * (int64)(field_24 * 2)) >> 18);
  126. // int tmp_r1 = 0x40000 - (int)(((int64)(field_24 * 2) * (int64)field_24) >> 18);
  127. // tmp_r5 = (int)(((int64)(field_2C * 2) * (int64)field_28) >> 18);
  128. // list_0[5] = tmp_r5 - tmp_r4;
  129. // list_0[6] = tmp_r7 - tmp_r8;
  130. // list_0[7] = tmp_r4 + tmp_r5;
  131. // tmp_r7 = (int)(((int64)(field_28 * 2) * (int64)field_28) >> 18);
  132. // int tmp_r3 = (int)(((int64)(field_2C * 2) * (int64)field_2C) >> 18);
  133. // list_0[0] = 0x40000 - tmp_r7 - tmp_r3;
  134. // list_0[4] = tmp_r1 - tmp_r3;
  135. // list_0[8] = tmp_r1 - tmp_r7;
  136. }
  137. // 0016c2b8 //^_^
  138. fpointQQ<t> Conj() const {
  139. fpointQQ<t> pt(*this);
  140. pt.field_24 = -pt.field_24;
  141. pt.field_28 = -pt.field_28;
  142. pt.field_2C = -pt.field_2C;
  143. pt.list_0[5] = list_0[7];
  144. pt.list_0[6] = list_0[2];
  145. pt.list_0[7] = list_0[5];
  146. pt.list_0[1] = list_0[3];
  147. pt.list_0[2] = list_0[6];
  148. pt.list_0[3] = list_0[1];
  149. return pt;
  150. }
  151. // 0016c2f0 //^_^
  152. fpoint3<t> Multiply(fpoint3<t>& pt2) const {
  153. fpoint3<t> pt0;
  154. int tmp_r6 = (int)(((int64)list_0[0] * (int64)pt2.x_0) >> 18);
  155. int tmp_r5 = (int)(((int64)list_0[1] * (int64)pt2.y_4) >> 18);
  156. tmp_r6 += tmp_r5;
  157. int tmp_r7 = (int)(((int64)list_0[2] * (int64)pt2.z_8) >> 18);
  158. pt0.x_0 = tmp_r6 + tmp_r7;
  159. tmp_r7 = (int)(((int64)list_0[3] * (int64)pt2.x_0) >> 18);
  160. tmp_r6 = (int)(((int64)list_0[4] * (int64)pt2.y_4) >> 18);
  161. tmp_r7 += tmp_r6;
  162. tmp_r6 = (int)(((int64)list_0[5] * (int64)pt2.z_8) >> 18);
  163. pt0.y_4 = tmp_r7 + tmp_r6;
  164. int tmp_r3 = (int)(((int64)list_0[6] * (int64)pt2.x_0) >> 18);
  165. tmp_r7 = (int)(((int64)list_0[7] * (int64)pt2.y_4) >> 18);
  166. tmp_r3 += tmp_r7;
  167. int tmp_r1 = (int)(((int64)list_0[8] * (int64)pt2.z_8) >> 18);
  168. pt0.z_8 = tmp_r3 + tmp_r1;
  169. return pt0;
  170. }
  171. int list_0[9];
  172. // int field_24;
  173. // int field_28;
  174. // int field_2C;
  175. // int field_30;
  176. fpointQ<t> fpointQ_24;
  177. };
  178. //-------------------------------------------------------------------------------------------------
  179. #endif //_FPOINT_H_