tag:blogger.com,1999:blog-5448070124223377418.post6005933895803008423..comments2023-10-17T12:16:59.390+02:00Comments on FastC++: Coding Cpp Efficiently: Vector Cross Product using SSE Codetheowl84http://www.blogger.com/profile/13389929931380273586noreply@blogger.comBlogger5125tag:blogger.com,1999:blog-5448070124223377418.post-81447350950686792282014-07-20T18:26:19.384+02:002014-07-20T18:26:19.384+02:00@Waldemar just swap the two operands. @Waldemar just swap the two operands. Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-5448070124223377418.post-3270157456736744452014-06-12T06:32:57.931+02:002014-06-12T06:32:57.931+02:00No, it is correct. You got your shuffles wrong: Th...No, it is correct. You got your shuffles wrong: The parameters of the _MM_SHUFFLE macro, from LEFT to RIGHT, select the source words for the result's HIGHEST to LOWEST word.<br /><br />Since you use low to high notation (B0, B1, B2, B3), you also have to write (A1, A2, A0, A3) (i.e.: low word comes first, high word comes last)<br /><br />More info on the shuffle macro can be found here:<br />http://msdn.microsoft.com/en-us/library/4d3eabky%28v=vs.90%29.aspxAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-5448070124223377418.post-88465221299945983882014-03-28T05:54:21.945+01:002014-03-28T05:54:21.945+01:00I don't know what the other anonymous guy who ...I don't know what the other anonymous guy who came on here was smoking, but his code does not produce a proper 3D cross product... like at all... Here's what the original code would have done with two vectors, A, and B:<br /><br />(A3, A0, A2, A1) * (B3, B1, B0, B2) - (A3, A1, A0, A2) * (B3, B0, B2, B1)<br /><br />Since the multiplications go straight through, slot by slot, the resulting two vector is:<br /><br />(0, (A0B1 - A1B0), (A2B0 - A0B2), (A1B2 - A2B1))<br /><br />Here's what the code the anonymous person posted does:<br /><br />(B0, B1, B2, B3) * (A3, A0, A2, A1) - (A0, A1, A2, A3) * (B3, B0, B2, B1)<br /><br />Which results in the vector:<br /><br />((B2A2 - A2B2), (B0A3 - A0B3), (B3A1 - A3B1), (B1A0 - A1B0))<br /><br />These are clearly not the same (to anyone who understands anything about... well... numbers... or variables... so anyone who would ever be interested in this sort of thing, anyway :P)Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-5448070124223377418.post-86612478860401867052013-11-11T21:53:23.079+01:002013-11-11T21:53:23.079+01:00This code produces (1, 0, 0) X (0, 1, 0) = (0, 0, ...This code produces (1, 0, 0) X (0, 1, 0) = (0, 0, -1) so we don't have a right-handed coordinate system.Waldemar Bancewiczhttp://www.waldemarb.comnoreply@blogger.comtag:blogger.com,1999:blog-5448070124223377418.post-3146328080025442682013-08-12T13:02:32.827+02:002013-08-12T13:02:32.827+02:00Was looking for a simd cross product implementatio...Was looking for a simd cross product implementation and found your nice post. I eventually discovered that you can do it with only 3 shuffle instructions:<br /><br />inline __m128 CrossProduct( __m128 a, __m128 b )<br />{<br />__m128 result = _mm_sub_ps( <br />_mm_mul_ps(b, _mm_shuffle_ps(a, a, _MM_SHUFFLE(3, 0, 2, 1))), <br />_mm_mul_ps(a, _mm_shuffle_ps(b, b, _MM_SHUFFLE(3, 0, 2, 1))) <br />);<br />return _mm_shuffle_ps(result, result, _MM_SHUFFLE(3, 0, 2, 1 ));<br />}Anonymousnoreply@blogger.com