Skip to content

Instantly share code, notes, and snippets.

@tsuna
Created September 24, 2011 08:23
Show Gist options
  • Save tsuna/1239113 to your computer and use it in GitHub Desktop.
Save tsuna/1239113 to your computer and use it in GitHub Desktop.
RE2's BitState::ShouldVisit disassembled manually
/*./re2/prog.h:100*/ 0x0000000000411f0b <+523>: mov 0x50(%rbx),%rdi # rdi = visited_
/*./re2/prog.h:100*/ 0x0000000000411f0f <+527>: add $0x1,%edx # edx = text_.size() + 1
/*re2/bitstate.cc:97*/ 0x0000000000411f12 <+530>: imul %esi,%edx # esi = id, edx = id * (text_.size() + 1)
/*re2/bitstate.cc:97*/ 0x0000000000411f15 <+533>: add %r14d,%edx # r14d = p, edx = id * (text_.size() + 1) + p
/*re2/bitstate.cc:97*/ 0x0000000000411f18 <+536>: sub %eax,%edx # eax = text_.begin(), edx = n
/*re2/bitstate.cc:98*/ 0x0000000000411f1a <+538>: mov %edx,%eax # eax = n
/*re2/bitstate.cc:98*/ 0x0000000000411f1c <+540>: mov %edx,%ecx # ecx = n
/*re2/bitstate.cc:98*/ 0x0000000000411f1e <+542>: shr $0x5,%eax # eax = n >> 5 = n / VisitedBits
/*re2/bitstate.cc:98*/ 0x0000000000411f21 <+545>: and $0x1f,%ecx # ecx = n & (VisitedBits - 1)
/*re2/bitstate.cc:98*/ 0x0000000000411f24 <+548>: mov %eax,%eax # nop
/*re2/bitstate.cc:98*/ 0x0000000000411f26 <+550>: lea (%rdi,%rax,4),%rdi # rdi = visited_[n / VisitedBits]
/*re2/bitstate.cc:98*/ 0x0000000000411f2a <+554>: mov $0x1,%eax # eax = 1
/*re2/bitstate.cc:98*/ 0x0000000000411f2f <+559>: shl %cl,%eax # eax = 1 << (n & (VisitedBits - 1))
/*re2/bitstate.cc:98*/ 0x0000000000411f31 <+561>: mov (%rdi),%r8d # r8d = *visited_[n / VisitedBits]
/*re2/bitstate.cc:98*/ 0x0000000000411f34 <+564>: test %r8d,%eax # if (visited_[n / VisitedBits] & 1 << (n & (VisitedBits - 1))
/*re2/bitstate.cc:98*/ 0x0000000000411f37 <+567>: jne 0x411db2 <_ZN3re28BitState9TrySearchEiPKc+178> # return false
/*re2/bitstate.cc:100*/ 0x0000000000411f3d <+573>: or %r8d,%eax # eax = visited_[n / VisitedBits] | 1 << (n & (VisitedBits - 1))
/*re2/bitstate.cc:100*/ 0x0000000000411f40 <+576>: mov %eax,(%rdi) # visited_[n / VisitedBits] = eax
/*re2/bitstate.cc:100*/ 0x0000000000411f42 <+578>: jmpq 0x411dd7 <_ZN3re28BitState9TrySearchEiPKc+215> # return true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment