Forums before death by AOL, social media and spammers... "We can't have nice things"
|    comp.lang.asm.x86    |    Ahh, the lost art of x86 assembly    |    4,675 messages    |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
|    Message 3,167 of 4,675    |
|    Terje Mathisen to asetofsymbols@nospicedham.gmail.com    |
|    Re: Palindromic number    |
|    07 Dec 17 20:57:06    |
      From: terje.mathisen@nospicedham.tmsw.no              asetofsymbols@nospicedham.gmail.com wrote:       > The algo would be as this       >       > a:=input       > r:=0       > A: r:=r*10+(a mod 10); a:=a div 10       > if a!=0 then goto A       > if input==r then return true       > return false       >       That algorithm, on a 64-bit machine with a good compiler, will require       one 64x64->128 MUL (and a shift) in order to calculate a div 10, then an       IMUL (64x64->64) and SUB to get a mod 10, while the r*10 part will       probably be handled with a LEA plus a shift, i.e. about 10-15 cycles per       digit.              Multiply by 20 digits and you end up with 300-450 cycles, vs ~60 for my       3-way uint64_t to decimal conversion, plus the final string reciprocal       test which takes about 15-30 cycles for naive code.              OTOH, if input numbers are often relatively small (5 digits or less),       then it would be OK to do it your way.              Terje              --       - |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
(c) 1994, bbs@darkrealms.ca