{"id":19,"date":"2006-07-31T07:52:19","date_gmt":"2006-07-31T15:52:19","guid":{"rendered":"http:\/\/www.pagetable.com\/?p=19"},"modified":"2006-07-31T07:52:19","modified_gmt":"2006-07-31T15:52:19","slug":"redudant-sse-instructions","status":"publish","type":"post","link":"https:\/\/www.pagetable.com\/?p=19","title":{"rendered":"Redundant SSE instructions"},"content":{"rendered":"<p>As we all know the x86-ISA has a lot of redundant instructions (ie. instructions with the same semantic but different opcodes). Sometimes this is unavoidable, sometimes it looks like bad design. But with SSE it gets really weird. Let&#8217;s say we want to perform xmm0 <- xmm0 &#038; xmm1 (ie. bitwise and). Not an uncommon operation; but we have 3 different ways do archive this:\n\n\n<ul>\n<li>andps xmm0, xmm1 (0f 54 c1)<\/li>\n<li>andpd xmm0, xmm1 (66 0f 54 c1)<\/li>\n<li>pand xmm0, xmm1 (66 0f db c1)<\/li>\n<\/ul>\n<p>(Note that andpd\/pand are SSE2 instructions)<br \/>\nRegarding the result in xmm0 these are really the same instructions. Now, why did Intel do this? First we&#8217;re going to inspect andps\/andpd. Looking at the optimization manuals we get a hint: The ps\/pd mark the target register to contain singles or doubles, so they should match the actual data you are operating on.<\/p>\n<p>It looks like the processor internally handles the floats in some &#8220;unpacked&#8221; structure and the ps\/pd is a sort of hint whether it has to repack the number again. Or something like that, at least this is <em>only<\/em> an optimization issue. But that&#8217;s stupid, if the processor already knows the internal format, one &#8220;andp&#8221; instruction would be sufficient &#8212; the processor can peform andps or andpd anyway, depending on which would be faster in the situation. Or, looking at the MMX case, there we have no pandb, pandw, pandd, pandq etc. The same applies to &#8220;movapd\/movdqa memory, xmm&#8221;: Damn, it&#8217;s the processor who knows better than me how to achive this the fastest way.<\/p>\n<p>Finally, let&#8217;s look at pand. After Intel recognized that MMX is a complete mess, they opened the MMX instructions for the xmm registers (0x66 prefix). And now? We have a third way to do the AND&#8230; And it somehow looks like they never had SSE2 in mind, when they designed the SSE1 instructions.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>As we all know the x86-ISA has a lot of redundant instructions (ie. instructions with the same semantic but different opcodes). Sometimes this is unavoidable, sometimes it looks like bad design. But with SSE it gets really weird. Let&#8217;s say we want to perform xmm0<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[36,38],"tags":[],"class_list":["post-19","post","type-post","status-publish","format-standard","hentry","category-whines","category-x86"],"_links":{"self":[{"href":"https:\/\/www.pagetable.com\/index.php?rest_route=\/wp\/v2\/posts\/19","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.pagetable.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.pagetable.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.pagetable.com\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.pagetable.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=19"}],"version-history":[{"count":0,"href":"https:\/\/www.pagetable.com\/index.php?rest_route=\/wp\/v2\/posts\/19\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.pagetable.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=19"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.pagetable.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=19"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.pagetable.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=19"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}