home bbs files messages ]

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,789 of 4,675   
   aen@nospicedham.spamtrap.com to robertwessel2@nospicedham.yahoo.com   
   Re: Primality test with one instruction   
   18 Feb 19 10:45:33   
   
   On Mon, 18 Feb 2019 01:41:25 -0600, Robert Wessel   
    wrote:   
   >   
   >My question is, what exactly is the point?  It's trivial, but you're   
   >stuck needing 512MB of disk and address space, plus the I/O for that   
   >every time the program loads.   
   >   
   I think there isn't much I/O going on at the start.  The way I   
   understand it, the mapping function only stores the address and length   
   of the bitarray and only loads a page when there is an access to that   
   memory and the address space used is only that page.   
      
   >I'd call that two instructions, but that's just me.   
   >   
   the jnc or jc is a reaction to the test.   
      
   >If you don't mind making the test four instructions, you could store   
   >only a bitmap of the odd numbers.   
   >   
   I thought of that, and will try it some later time.   
      
   >Considering the cost of a page I/O, even to SSD, you might well be   
   >better off just testing against the 6542 primes (which, if my   
   >calculations are correct, is the number of primes below sqrt(2**32)).   
   >That would only take a 13kb table to store.  And if there's a fair   
   >fraction of non-primes being tested, that will usually fail after only   
   >the first few tests anyway.   
   >   
   I did some timings, and a run through all 4G numbers took ~10 seconds.   
      
      
   The test was:   
       mov rcx,4294967295   
   L0: bt  [rbx],rcx   
       dec rcx   
       jnz L0   
      
   A sequential run through all the numbers is IMO the worst case test,   
   because all pages need to be loaded.   
      
   In cycles one test takes ~8 cycles, which seems not bad to me, and the   
   test for even numbers could of course be eliminated with a test rcx,1   
   instead of a prime test.   
      
   >Loading a large table might well be the fastest solution if you   
   >actually have a very large number of values to test, but in that case,   
   >you'd be much better off with a sequential read into memory, that sort   
   >of random access into the mmapped file is going to be slow.   
   >   
   sequential read of what?   
      
   PS:   
   I'm only a hobbyist, so any input from the experts here whether the   
   timings I gave might be influenced by other things I don't understand   
   is very welcome.   
   --   
   aen   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca