News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Python anyone?

Started by raymond, November 28, 2023, 11:30:19 AM

Previous topic - Next topic

jj2007

Quote from: GoneFishing on November 29, 2023, 04:43:20 AMI prefer pure MASM32.

The SetDllFolder macro is pure Masm32. You are working with MASM, where the first M stands for "MACRO". Get used to it.

Has anybody succeeded in running Ray's code?

from decimal import *
from time import time

def sq(n, pr):
 start = time()
 getcontext().prec = pr
 print(Decimal(n).sqrt()
 print(time() - start)
 sq(5, 10000)

C:\Python>python.exe jjTest.py
  File "jjTest.py", line 8
    print(time() - start)
    ^
SyntaxError: invalid syntax

This is after eliminating the unexpected indent crap.

Edit: I found the reason, and will never seriously touch a language that has such horrible error handling.

GoneFishing

Quote from: jj2007 on November 29, 2023, 07:27:04 AMHas anybody succeeded in running Ray's code?

As you could guess I've succeeded:
Quoteprint(Decimal(n).sqrt())

Unindent last line:

from decimal import *
from time import time

def sq(n, pr):
 start = time()
 getcontext().prec = pr
 print(Decimal(n).sqrt())
 print(time() - start)
sq(5, 10000)

jack

#17
just one last post of mine, here's a 64-bit exe plus source for testing
<the exe should work as is but I discovered a bug in my fp to string conversion that I need to track down>

<edit; got rid of non-working code and compiled without -march=native, should work on older CPU>

jj2007

Quote from: jack on November 29, 2023, 07:54:22 AMhere's a 64-bit exe

Well done, it compiles "out of the box" and it's a factor 5 faster than the Python version :thumbsup:

TimoVJL

Quote from: jack on November 29, 2023, 07:54:22 AMjust one last post of mine, here's a 64-bit exe plus source for testing
<the exe should work as is but I discovered a bug in my fp to string conversion that I need to track down>
Crash in Windows 7  :sad:

Just a problem with an old AMD
00000001`3f520a51 c5f829b424d0000000 vmovaps xmmword ptr [rsp+0D0h],xmm6 ss:00000000`0052fca0=00000000000000000000000000000000
May the source be with you

jack

thanks for testing jj and TimoVJL
@TimoVJL, would try again?
I recompiled without the -march=native so it should work on older CPU's but probably not as fast

TimoVJL

Same problem00000001`3fe4f891 c5f829b424d0000000 vmovaps xmmword ptr [rsp+0D0h],xmm6 ss:00000000`0055f7f0=00000000000000000000000000000000
May the source be with you

jack

TimoVJL, one last try please, I recompiled on a Windows 7 VM

TimoVJL

time per loop =  0.0642072000756571  :thumbsup:
May the source be with you

jack

hi TimoVJL, looks like I forgot to change the time message but at least it runs
how does the time compare with python?

TimoVJL

from post #2

With x64 version:
0.18700003623962402
May the source be with you

jj2007

#26
Attached a list of the 1600 functions exported by Python38.dll (direct link)
Note you get a similar list from Python3.dll, which grabs about 800 functions from *38.dll; they probably keep it for backwards compatibility.

I noticed strange behaviour of PySys_WriteStdout: it writes 0D0D0Ah sequences, see Assembly uses Python (warning, that's MasmBasic :biggrin: )

PySys_WriteStdout(cfm$("%i\t%s\n"), ecx, PyList_GetItem(edi, ecx))
I'm not sure whether it's Python's fault, or if the console plays tricks.

raymond

Quote from: GoneFishing on November 29, 2023, 06:41:37 AMhi Raymond,
QuoteA self-contained working program would certainly be useful
In theory the small python script in your post can be converted to exe format.
I've used Pyinstaller for that purpose but the result doesn't look "debuggable" because of its size :
exe = 1018KB + dependency folder = 10.2MB

WOW Talk about BLOATING to simply extract a square root!!!! :skrewy:  :dazzled:  :eusa_dance:  :eusa_boohoo:
Whenever you assume something, you risk being wrong half the time.
https://masm32.com/masmcode/rayfil/index.html

raymond

Quote from: jack on November 29, 2023, 07:54:22 AMjust one last post of mine, here's a 64-bit exe plus source for testing
<the exe should work as is but I discovered a bug in my fp to string conversion that I need to track down>

<edit; got rid of non-working code and compiled without -march=native, should work on older CPU>

D/L, unzipped & ran without problem (except for one minor detail: it "prints" some extra 100 or so blank pages).

0.022 sec on my old 10-year old laptop under Win10. Almost 100 times faster than my BCD algo at 1.5 second. All 10,000 digits of the square root of 5 seem to be the same with both programs.

Is there something similar as the 32-bit Ollydbg to study this 64-bit program?
Whenever you assume something, you risk being wrong half the time.
https://masm32.com/masmcode/rayfil/index.html

jj2007

Quote from: raymond on November 30, 2023, 08:14:34 AMIs there something similar as the 32-bit Ollydbg to study this 64-bit program?

x64Dbg has the typical Olly interface, and it works fine.