update primes32.tal to new math32.tal

This commit is contained in:
Erik Osheim 2024-11-21 11:41:43 -05:00
parent f36254f7bc
commit 966c87a144
1 changed files with 5 additions and 5 deletions

View File

@ -43,20 +43,20 @@
( works for x >= 2 ) ( works for x >= 2 )
@is-prime32 ( x** -> bool^ ) @is-prime32 ( x** -> bool^ )
DUP4 ,&x1 STR2 ,&x0 STR2 ( x** ; store x ) DUP4 ,&x1 STR2 ,&x0 STR2 ( x** ; store x )
DUP4 #0000 #0002 ne32 ?{ POP4 #01 JMP2r } ( x** ; return if 2 ) DUP4 #0000 #0002 u32-ne ?{ POP4 #01 JMP2r } ( x** ; return if 2 )
DUP #01 AND ?{ POP4 #00 JMP2r } ( x** ; return if even ) DUP #01 AND ?{ POP4 #00 JMP2r } ( x** ; return if even )
DUP4 #0000 #0003 ne32 ?{ POP4 #01 JMP2r } ( x** ; return if 3 ) DUP4 #0000 #0003 u32-ne ?{ POP4 #01 JMP2r } ( x** ; return if 3 )
#0002 ,&inc STR2 ( x** ; inc<-2 ) #0002 ,&inc STR2 ( x** ; inc<-2 )
#0000 #0005 DUP4 ,&i1 STR2 ,&i0 STR2 ( x** i** ; i<-5 ) #0000 #0005 DUP4 ,&i1 STR2 ,&i0 STR2 ( x** i** ; i<-5 )
&loop ( x** i** ) &loop ( x** i** )
LIT2 [ &x0 $2 ] LIT2 [ &x1 $2 ] ( x** i** x** ) LIT2 [ &x0 $2 ] LIT2 [ &x1 $2 ] ( x** i** x** )
LIT2 [ &i0 $2 ] LIT2 [ &i1 $2 ] ( x** i** x** i** ) LIT2 [ &i0 $2 ] LIT2 [ &i1 $2 ] ( x** i** x** i** )
DUP4 mul32 lt32 ( x** i** x<ii^ ) DUP4 u32-mul u32-lt ( x** i** x<ii^ )
STH DUP2 #ffff EQU2 STHr ORA ( x** i** x<ii|i=0xffff^ ) STH DUP2 #ffff EQU2 STHr ORA ( x** i** x<ii|i=0xffff^ )
?{ ( x** i** ) ?{ ( x** i** )
,&x0 LDR2 ,&x1 LDR2 ,&i0 LDR2 ,&i1 LDR2 ( x** i** x** i** ) ,&x0 LDR2 ,&x1 LDR2 ,&i0 LDR2 ,&i1 LDR2 ( x** i** x** i** )
mod32 is-zero32 ( x** i** x//i^ ) u32-mod u32-is-zero ( x** i** x//i^ )
STH #0000 ,&inc LDR2 add32 ( x** i+2** [x//i^] ) STH #0000 ,&inc LDR2 u32-add ( x** i+2** [x//i^] )
LIT2 [ &inc $2 ] #0006 EOR2 ,&inc STR2 ( x** i+2** [x//i^] ; inc<-inc^6 ) LIT2 [ &inc $2 ] #0006 EOR2 ,&inc STR2 ( x** i+2** [x//i^] ; inc<-inc^6 )
DUP4 ,&i1 STR2 ,&i0 STR2 STHr ( x** i+2** x//i^ ; i<-i+2 ) DUP4 ,&i1 STR2 ,&i0 STR2 STHr ( x** i+2** x//i^ ; i<-i+2 )
?{ !&loop } ( x** i+2** ; if x<j*j, loop ) ?{ !&loop } ( x** i+2** ; if x<j*j, loop )