2

How can the pcmpestri instruction be used to write a function similar to strpos function in C++? I can use g++ compiler.

pcmpestri is a new instruction that is found in SSE4

Drew Dormann
  • 59,987
  • 13
  • 123
  • 180
I'll-Be-Back
  • 10,530
  • 37
  • 110
  • 213
  • Can you show an attempt - or add some details? The way it is right now, this question is structurally very similar to all those "write me a function in Java that reverses a string" questions, even if at a somewhat higher level... – us2012 Feb 11 '13 at 00:05
  • 1
    I thought it was "lower level", since it involves assembler instructions? ;) – Mats Petersson Feb 11 '13 at 00:10
  • `pcmpistri` is faster and can probably do it too. Look at EQUAL_ORDERED. I would give a better answer, but I don't have a CPU that supports SSE 4.2 so I can't test anything. – harold Feb 11 '13 at 18:46

1 Answers1

-3

Before using the SSE instructions you have to store away the floating point stack, and restore afterwards. That is costly, unless your strings are huge it won't be worth it. And for huge strings, better algorithms are the way to go (Boyer-Moore or such).

vonbrand
  • 11,412
  • 8
  • 32
  • 52
  • This was true for MMX. It is not the case with SSE (that you need to do EMMS; obviously one should still consider sub-quadratic algorithms) – Stephen Canon Feb 11 '13 at 04:15