flat assembler
Message board for the users of flat assembler.

flat assembler > Test Area > Producing Sequential Primes (without a cache miss)...

Author
Thread Post new topic Reply to topic
bitRAKE



Joined: 21 Jul 2003
Posts: 2672
Location: dank orb
Do you think there is an algorithm to produce the primes sequentially? Using no multiplication/division? Well here it is...
Code:
    mov ecx,1
    mov ebx,1
    mov rax,1
    mov edx,25
FindPrimes:
    add rcx,2           ; next odd number
    add rbx,1           ; next integer
    add rax,rcx         ; next square
.Check:
    cmp rax,rdx
    jz .Prime
    jc .notPrime
    add rdx,24
    jmp .Check
.Prime:
    push rbx ; output RBX as prime, or (RCX+1)/2 is prime
.notPrime:
    jmp FindPrimes    
Very Happy

_________________
unlicense.org
Post 21 Nov 2018, 05:59
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 16128
Location: Hyperborea
I assume you mean no Icache miss?

Does it produce all primes from 2 onwards? I can't see how it outputs 2.
Post 21 Nov 2018, 06:45
View user's profile Send private message Visit poster's website Reply with quote
tthsqe



Joined: 20 May 2009
Posts: 720
This code outputs numbers > 1 that have no factor in common with 24. This is the same as the sequence of primes only in the first few cases. Razz
It also does so rather inefficiently, rdx is on the order of rbx squared.
In summary a big disappointment Sad
Post 21 Nov 2018, 21:36
View user's profile Send private message Reply with quote
redsock



Joined: 09 Oct 2009
Posts: 293
Location: Australia
Agreed, useless ... 25 is not prime Smile

Not to mention, even if the algorithm were correct, a naive increment+trial by division is better than this ...

I had fun taking a few moments and headscratching it anyway, thanks bitRAKE, the fact that you put it in "Test Area" would normally have been a red flag for me not to bother but the code looked plausible hahah Smile Smile

_________________
2 Ton Digital - https://2ton.com.au/
Post 21 Nov 2018, 21:58
View user's profile Send private message Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 2672
Location: dank orb
Just testing... Very Happy

Number theory would fall apart if it were possible.
Hopefully, the disappointment was not too big.
Post 22 Nov 2018, 01:21
View user's profile Send private message Visit poster's website Reply with quote
tthsqe



Joined: 20 May 2009
Posts: 720
I'm sure I'm not the only one who though your fasm account got hijacked. Usually these types of things are saved for April.
Post 22 Nov 2018, 15:40
View user's profile Send private message Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 2672
Location: dank orb
It is only a matter of time (for the hacking). Sorry, for the confusion then.
Post 26 Nov 2018, 10:58
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2018, Tomasz Grysztar.

Powered by rwasa.