Author Topic: A movie about A Turing -- Factor programming language  (Read 12431 times)

0 Members and 1 Guest are viewing this topic.

Charles Pegge

  • Guest
Re: A movie about A Turing -- Factor programming language
« Reply #15 on: October 20, 2014, 08:27:12 AM »
Yes, good point, Mike.

We also have a degree of parallel operation  with CPU and FPU. Maybe we could also do something useful in the SIMD processor at the same time :)
« Last Edit: October 20, 2014, 08:45:33 AM by Charles Pegge »

Mike Lobanovsky

  • Guest
Re: A movie about A Turing -- Factor programming language
« Reply #16 on: October 20, 2014, 08:42:41 AM »
Exactly, Charles.

Pairability of some simple FPU instructions with fxch makes its clock-wise cost 0. At the same time, fxch may bring the latency caused by interdependence of successive FPU instructions down to nil as well. In many cases, and especially in tricky FPU loops similar to Mandel where every clock counts, this can help improve the loop speed by some half a dozen to over a dozen CPU clocks per iteration.

RobbeK

  • Guest
Re: A movie about A Turing -- Factor programming language
« Reply #17 on: October 20, 2014, 10:49:55 AM »
Hi Charles,

"an unfortunate accident"  ..  I use both KCN and the harmless K Fe(III) cyanide for my photography   (gold, platinum, copper etc ... toning) ,   a lethal dose would still be more than 0.5 g (not a few crystals flying around ) .. and even then it seems Rasputin after eating some cyanide biscuits , just walked home.   (there may be a medical reason , the KCN has to be converted in HCN first , and then it will bind the Fe in the hemoglobine of one's blood -- normally the stomac acids are more than strong enough , but ...   ?     (maybe his stomac at that moment was completely saturated with wodka  :o )

(prunes , cherries (and even more their stones) almonds also contain some cyanide , my grand-father long ago told me (he was a forrester ) that no animal sleeps under a "prune hedgerow" , it makes sick ????   


best Rob

JRS

  • Guest
Re: A movie about A Turing -- Factor programming language
« Reply #18 on: October 21, 2014, 12:57:53 AM »
Quote from: Rob
oh, but most people love complexities ( .. and gadgets, it gives a (false) feeling of importance

Here is a good example from one of the PB zombies that thinks Zale thought of him as a peer.

Code: Text
  1. ' ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
  2. '                                        Build with PBCC 6.0
  3. ' ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
  4.  
  5.     #include "\basic\include\win32api.inc"
  6.  
  7.     ' %clockit = 0  ' uncomment to run timing.
  8.  
  9. ' ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
  10.  
  11. FUNCTION PBmain as LONG
  12.  
  13.     #REGISTER NONE
  14.  
  15.     LOCAL src  as DWORD
  16.     LOCAL lcnt as DWORD
  17.     LOCAL pMem as DWORD
  18.     LOCAL tcnt as DWORD
  19.  
  20.     a$ = _
  21.         "Friends, Romans, countrymen, lend me your ears;"+chr$(13,10)+_
  22.         "I come to bury Caesar, not to praise him."+chr$(13,10)+_
  23.         "The evil that men do lives after them;"+chr$(13,10)+_
  24.         "The good is oft interred with their bones;"+chr$(13,10)
  25.  
  26.   #IF %DEF(%clockit)
  27.     Open "lt.txt" for Binary as #1  ' VERY BIG file of your choice
  28.       Get$ #1, lof(1), a$
  29.     Close #1
  30.     tcnt = GetTickCount
  31.   #ENDIF
  32.  
  33.     src = StrPtr(a$)
  34.  
  35.     PREFIX "! "
  36.     push src
  37.     call lines_to_array             ; call the tokenizer
  38.     mov pMem, eax                   ; returned array pointer address in variable
  39.     mov lcnt, ecx                   ; line count in variable
  40.     END PREFIX
  41.  
  42.   #IF %DEF(%clockit)
  43.     tcnt = GetTickCount - tcnt
  44.     StdOut "Timing = "+format$(tcnt)+" milliseconds"
  45.     ! jmp bye
  46.   #ENDIF
  47.  
  48.     PREFIX "! "
  49.     mov esi, pMem                   ; load pointer array into ESI
  50.     mov edi, lcnt                   ; load the line count into EDI
  51.   lbl1:
  52.     push DWORD PTR [esi]            ; write the line of text to the console
  53.     call puts                       ; make MSVCRT useful
  54.     add esi, 4                      ; increment to next pointer
  55.     sub edi, 1                      ; decrement the loop counter
  56.     jnz lbl1
  57.  
  58.     END PREFIX
  59.  
  60.   bye:
  61.     GlobalFree pMem                 ' release pointer memory here
  62.     waitkey$
  63.  
  64. End FUNCTION
  65.  
  66. ' ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
  67.  
  68. FUNCTION lines_to_array(ByVal src as DWORD) as DWORD
  69.  
  70.   ' --------------------------------------------------------------------------
  71.   ' in place tokenize a text file and return an array of pointers to the start
  72.   ' of each line which is terminated at the ascii 13 location with an ascii 0
  73.  
  74.   ' IN     address of source text
  75.   ' OUT 1. array of pointers address in EAX
  76.   '     2. line count in ECX
  77.  
  78.   ' address of pointer array must be released in the scope of the caller
  79.   ' using GlobalFree()
  80.   ' --------------------------------------------------------------------------
  81.  
  82.     #REGISTER NONE
  83.  
  84.     LOCAL lcnt as DWORD
  85.     LOCAL pMem as DWORD
  86.     LOCAL alen as DWORD
  87.  
  88.     PREFIX "! "
  89.  
  90.     push src
  91.     call get_lcnt           ; get the line count
  92.     mov lcnt, eax           ; store line count in variable
  93.     lea eax, [eax*4]        ; set pointer array length
  94.     mov alen, eax           ; store the array size in alen
  95.  
  96.   ; --------------------------
  97.   ; allocate the pointer array
  98.   ; --------------------------
  99.     END PREFIX
  100.     pMem = GlobalAlloc(%GMEM_FIXED or %GMEM_ZEROINIT,alen)
  101.     PREFIX "! "
  102.  
  103.     mov esi, src            ; source address in ESI
  104.     mov ebx, pMem           ; pointer array address in EBX
  105.  
  106.     mov [ebx], esi          ; load array address into 1st member of array
  107.     add ebx, 4
  108.     sub esi, 1
  109.  
  110.   lbl1:
  111.     add esi, 1
  112.     movzx eax, BYTE PTR [esi]
  113.     test eax, eax           ; test for zero
  114.     jz lbl2                 ; exit loop on zero
  115.     cmp eax, 13             ; test for ascii 13
  116.     jne lbl1                ; short loop back if not 13
  117.  
  118.     mov BYTE PTR [esi], 0   ; write terminator at ascii 13 location
  119.     add esi, 2              ; step over ascii 13 and 10
  120.     mov [ebx], esi          ; write the next line start to pointer
  121.     add ebx, 4              ; increment to next pointer
  122.     jmp lbl1                ; long loop after writing pointer
  123.  
  124.   lbl2:
  125.     mov ecx, lcnt           ; return the line count in ECX
  126.     mov eax, pMem           ; the array pointer in EAX
  127.     mov FUNCTION, eax
  128.  
  129.     END PREFIX
  130.  
  131. End FUNCTION
  132.  
  133. ' ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
  134.  
  135. FASTPROC get_lcnt
  136.  
  137.     PREFIX "! "
  138.  
  139.   ; --------------------------------------
  140.   ; count ascii 13 to determine line count
  141.   ; --------------------------------------
  142.     mov edx, [esp+4]                    ; the source address
  143.     sub edx, 1
  144.     xor eax, eax
  145.     jmp lbl1
  146.  
  147.   pre:
  148.     add eax, 1                          ; increment the counter
  149.   lbl1:
  150.   ; -----------
  151.   ; unroll by 4
  152.   ; -----------
  153.     add edx, 1
  154.     movzx ecx, BYTE PTR [edx]
  155.     cmp ecx, 13
  156.     je pre
  157.     test ecx, ecx
  158.     jz lbl2
  159.  
  160.     add edx, 1
  161.     movzx ecx, BYTE PTR [edx]
  162.     cmp ecx, 13
  163.     je pre
  164.     test ecx, ecx
  165.     jz lbl2
  166.  
  167.     add edx, 1
  168.     movzx ecx, BYTE PTR [edx]
  169.     cmp ecx, 13
  170.     je pre
  171.     test ecx, ecx
  172.     jz lbl2
  173.  
  174.     add edx, 1
  175.     movzx ecx, BYTE PTR [edx]
  176.     cmp ecx, 13
  177.     je pre
  178.     test ecx, ecx
  179.     jnz lbl1
  180.  
  181.   lbl2:
  182.     ret 4
  183.  
  184.     END PREFIX
  185.  
  186. END FASTPROC
  187.  
  188. ' ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
  189.  
  190.     DECLARE FUNCTION vcputs CDECL LIB "MSVCRT.DLL" ALIAS "puts" (BYVAL ptxt AS DWORD) AS DWORD
  191.  
  192. ' ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
  193.  
  194. SUB puts(BYVAL ptxt AS DWORD)
  195.  
  196.   vcputs ptxt
  197.  
  198. End SUB
  199.  
  200. ' ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
  201.  


Code: Script BASIC
  1. a = """
  2. Friends, Romans, countrymen, lend me your ears;
  3. I come to bury Caesar, not to praise him.
  4. The evil that men do lives after them;
  5. The good is oft interred with their bones;
  6. """
  7. SPLIT a BY "\n" TO l
  8. FOR x = 0 TO UBOUND(l)
  9.   PRINT l[x],"\n"
  10. NEXT
  11.  

Output


jrs@laptop:~/sb/sb22/test$ time scriba l2a.sb
Friends, Romans, countrymen, lend me your ears;
I come to bury Caesar, not to praise him.
The evil that men do lives after them;
The good is oft interred with their bones;


real   0m0.003s
user   0m0.003s
sys   0m0.000s
jrs@laptop:~/sb/sb22/test$


« Last Edit: October 21, 2014, 01:06:24 AM by John »

Aurel

  • Guest
Re: A movie about A Turing -- Factor programming language
« Reply #19 on: October 21, 2014, 01:38:38 AM »
ha..ha...ha....

Mike Lobanovsky

  • Guest
Re: A movie about A Turing -- Factor programming language
« Reply #20 on: October 21, 2014, 09:49:26 AM »
John,

That mysterious somebody certainly isn't such a noddy as you might think. There is only one thing that can beat assembly in terms of speed, and that thing is some more assembly.

Here are my benchmarks for splitting a 39MB bible.txt file that contains 10 copies of the Holy Bible into a string array using

i) scriba's native SPLIT();
ii) FBSL's native ArrayFromFile(); and
iii) PB's inline assembly as per your PB source.

You're falling into your own trap again. Never trade speed for "efficiency" when dealing with strings.

Code: [Select]
' SB
OPEN "bible.txt" FOR BINARY AS 1
a = INPUT(LOF(1), 1)
CLOSE 1
' Corrected by JRS:
SPLITA a BY "\n" TO l

Code: [Select]
// FBSL
DIM gtc = GetTickCount()
ARRAYFROMFILE("bible.txt", 2048) // MAX permissible length for each line is 2048 bytes
MSGBOX(, GetTickCount() - gtc & " milliseconds", "FBSL",)

.
« Last Edit: October 22, 2014, 12:26:16 AM by Mike Lobanovsky »

JRS

  • Guest
Re: A movie about A Turing -- Factor programming language
« Reply #21 on: October 21, 2014, 10:05:56 AM »
My point was that I didn't spend hours writing a program that saves me a second. You have to put a value on your own time. Once again, use the right tool for the job.

Mike Lobanovsky

  • Guest
Re: A movie about A Turing -- Factor programming language
« Reply #22 on: October 21, 2014, 10:28:21 AM »
Quote from: John
Once again, use the right tool for the job.

The big idea behind the PB code you submitted is here:

Code: [Select]
...............
  #IF %DEF(%clockit)
    tcnt = GetTickCount
    OPEN "bible.txt" FOR BINARY AS #1  ' VERY BIG file of your choice
      GET$ #1, LOF(1), a$
    CLOSE #1
  #ENDIF
...............

Had it really been meant to boil down to the four lines of the verse then the author would've simply used:

Quote from: PB Manual
PARSE start$, target$() [, {[ANY] delim$ | BINARY}]

that can do a lot more than SPLIT() and ARRAYFROMFILE() taken together.
« Last Edit: October 22, 2014, 12:05:48 AM by Mike Lobanovsky »

Aurel

  • Guest
Re: A movie about A Turing -- Factor programming language
« Reply #23 on: October 21, 2014, 09:56:20 PM »
well ...looks interesting...
ARRAYFROMFILE("bible.txt", 2048)
Is this array of char pointers or sort of linked list
i like syntax

JRS

  • Guest
Re: A movie about A Turing -- Factor programming language
« Reply #24 on: October 21, 2014, 11:56:43 PM »
Mike,

There is a typo in your code for SB.

SPLIT should be SPLITA


Mike Lobanovsky

  • Guest
Re: A movie about A Turing -- Factor programming language
« Reply #25 on: October 22, 2014, 12:10:31 AM »
Code: Script BASIC
  1. a = """
  2. Friends, Romans, countrymen, lend me your ears;
  3. I come to bury Caesar, not to praise him.
  4. The evil that men do lives after them;
  5. The good is oft interred with their bones;
  6. """
  7. SPLIT a BY "\n" TO l
  8. FOR x = 0 TO UBOUND(l)
  9.   PRINT l[x],"\n"
  10. NEXT
  11.  

Then it's in fact your typo, John. ;) I didn't intend to print out the ten copies of Holy Bible in my console per each language in question. Actually, I was more interested just in splitting them. :)

(Looks like you'd better have let it go unnoticed... :D)

.
« Last Edit: October 22, 2014, 12:27:39 AM by Mike Lobanovsky »

JRS

  • Guest
Re: A movie about A Turing -- Factor programming language
« Reply #26 on: October 22, 2014, 12:28:01 AM »
Too funny!

Can you print the UBOUND value for each BASIC?

Mike Lobanovsky

  • Guest
Re: A movie about A Turing -- Factor programming language
« Reply #27 on: October 22, 2014, 12:32:51 AM »
I can print out the UBOUNDs for SB and FBSL right away. I don't own a copy of PB though; the exe was compiled by a friend of mine. I can ask him to recompile it for me again in the evening (tomorrow morning your time).

Just gimme a second...

Here you go:

.
« Last Edit: October 22, 2014, 12:41:17 AM by Mike Lobanovsky »

JRS

  • Guest
Re: A movie about A Turing -- Factor programming language
« Reply #28 on: October 22, 2014, 12:46:29 AM »
Thanks!

Quote
I don't own a copy of PB though;

I've seen copies on torrents.  ;D

Mike Lobanovsky

  • Guest
Re: A movie about A Turing -- Factor programming language
« Reply #29 on: October 22, 2014, 12:54:40 AM »
Bob PM-ed me 10 minutes after I registered on Jose's forum. I swore I never owned a copy and wasn't in need of one. (in fact, it was an assembly issue that I was searching qualified advice on)

I don't want to break my promise, John, though I do have a copy of PBWin 10 user manual for my personal reference. :)