Is this make sence? Dynamic assembler for python

G

geremy condra

I found on the forum some discussion about crypting text and one guy
did make assembly implementation of crypting algorithm. He dynamically
generates mashine code and call that from python. Here are impressive
results http://www.daniweb.com/code/snippet216632-5.html

Is this better approach then writing extensions in c?

No, xor cipher is not suitable for general purpose encryption, and what do you
need the speed for? xor is almost certainly not going to be the bottleneck in
your application.

Geremy Condra
 
D

DivX

No, xor cipher is not suitable for general purpose encryption, and what do you
need the speed for? xor is almost certainly not going to be the bottleneck in
your application.

Geremy Condra

Just asking if this approach is good for example quicksort algoriths
or some kind of sorting algorithms, or simulations but the point is of
mixing python and assembler?
 
S

Steven D'Aprano

Just asking if this approach is good for example quicksort algoriths or
some kind of sorting algorithms, or simulations but the point is of
mixing python and assembler?


Ask yourself, why aren't programs written in assembly if it's so good?

(1) It's platform dependent. Do you really need a separate program for
every single hardware platform you want to run Quicksort on?

(2) Writing assembler is hard, really hard. And even harder to debug.

(3) Modern C compilers can produce better (faster, more efficient)
machine code than the best assembly code written by hand.


Honestly, this question has been resolved twenty years ago -- thirty
years ago, maybe there was still a good point in writing general purpose
code in assembly, but now? It's just showing off. Unless you're writing
hardware specific code (e.g. device drivers) it is pointless, in my
opinion.

I think that mixing assembly and python is a gimmick of very little
practical significance. If you really need the extra performance, check
out PyPy, Cython, Pyrex and Psyco.
 
T

Terry Reedy

I found on the forum some discussion about crypting text and one guy
did make assembly implementation of crypting algorithm. He dynamically
generates mashine code and call that from python. Here are impressive
results http://www.daniweb.com/code/snippet216632-5.html

Is this better approach then writing extensions in c?

You have to define 'better'. This approach requires someone to write
template assembler code, which will be machine specific. To be faster
than compiled C on a particular machine, one must be pretty good at
assemblee also.
 
D

Dennis Lee Bieber

You have to define 'better'. This approach requires someone to write
template assembler code, which will be machine specific. To be faster
than compiled C on a particular machine, one must be pretty good at
assemblee also.

Given some of the multi-stage/multi-clock pipeline processors in
use... Just having to keep track of instruction timings so that one
doesn't waste cycles while waiting for a previous instruction to
finish... ugh...
 
D

DivX

Ask yourself, why aren't programs written in assembly if it's so good?

(1) It's platform dependent. Do you really need a separate program for
every single hardware platform you want to run Quicksort on?

(2) Writing assembler is hard, really hard. And even harder to debug.

(3) Modern C compilers can produce better (faster, more efficient)
machine code than the best assembly code written by hand.

Honestly, this question has been resolved twenty years ago -- thirty
years ago, maybe there was still a good point in writing general purpose
code in assembly, but now? It's just showing off. Unless you're writing
hardware specific code (e.g. device drivers) it is pointless, in my
opinion.

I think that mixing assembly and python is a gimmick of very little
practical significance. If you really need the extra performance, check
out PyPy, Cython, Pyrex and Psyco.

I can agree with you about most of the arguments, but why he continues
to developing it. What he sees and we do not see?
If you're interested I found a link http://www.tahir007.com/
 
S

Steven D'Aprano

On 20 lip, 02:52, Steven D'Aprano <st...@REMOVE-THIS-
cybersource.com.au> wrote: [...]
I think that mixing assembly and python is a gimmick of very little
practical significance. If you really need the extra performance, check
out PyPy, Cython, Pyrex and Psyco.

I can agree with you about most of the arguments, but why he continues
to developing it. What he sees and we do not see?

Why ask us? You should ask him.
 
D

DivX

On 20 lip, 02:52, Steven D'Aprano <st...@REMOVE-THIS-
cybersource.com.au> wrote: [...]
I think that mixing assembly and python is a gimmick of very little
practical significance. If you really need the extra performance, check
out PyPy, Cython, Pyrex and Psyco.
I can agree with you about most of the arguments, but why he continues
to developing it. What he sees and we do not see?

Why ask us? You should ask him.

Be sure I will ask him, but before, I wanted to know your opinions
about it. Hear arguments on both sides...
 
L

Lie Ryan

On 20 lip, 02:52, Steven D'Aprano <st...@REMOVE-THIS-
cybersource.com.au> wrote: [...]
I think that mixing assembly and python is a gimmick of very little
practical significance. If you really need the extra performance, check
out PyPy, Cython, Pyrex and Psyco.
I can agree with you about most of the arguments, but why he continues
to developing it. What he sees and we do not see?

Why ask us? You should ask him.

Be sure I will ask him, but before, I wanted to know your opinions
about it. Hear arguments on both sides...

Ever heard of JIT?
 
T

Terry Reedy

52, Steven D'Aprano<st...@REMOVE-THIS-
cybersource.com.au> wrote:
[...]
I think that mixing assembly and python is a gimmick of very little
practical significance. If you really need the extra performance, check
out PyPy, Cython, Pyrex and Psyco.

Of course, Psyco mixes assembly and python, which is why it was
originally (not sure now) limited to x86 machines. It does do
generically, in small chunks, behind the scenes, so the rest of us can
get the benefit without expert assembly knowledge.

I presume because he can and enjoys it. That sort of tinkering is what
led to Psyco.
Ever heard of JIT?

Psyco is one form of JIT. You might enjoy reading about how it works.

Terry Jan Reedy
 
D

Dave Angel

DivX said:
On 20 lip, 02:52, Steven D'Aprano <st...@REMOVE-THIS-
cybersource.com.au> wrote:
[...]

I think that mixing assembly and python is a gimmick of very little
practical significance. If you really need the extra performance, check
out PyPy, Cython, Pyrex and Psyco.

--
Steven

I can agree with you about most of the arguments, but why he continues
to developing it. What he sees and we do not see?
Why ask us? You should ask him.

Be sure I will ask him, but before, I wanted to know your opinions
about it. Hear arguments on both sides...
Something's intrinsically wrong with the argument made in this thread
against generating assembly code. That's exactly what happens every
time you write code in C. The real question is whether the code
generator your friend is writing is better than the ones written by
dozens of C gurus over the years, and better tuned to the requirements
of his particular processor. Naturally, better can be measured in
several ways.


For example, I have a processor for which no C compiler is available.
So if I were to want optimized assembler, I might need to write one
myself, or use the language for which such a code generator has been
written.


DaveA
 
S

Steven D'Aprano

Something's intrinsically wrong with the argument made in this thread
against generating assembly code. That's exactly what happens every
time you write code in C.

I don't know whether C compilers generate assembly mnemonics or direct
machine code, but the distinction for this argument is irrelevant.

The argument in this thread is that it's not worth the *human coder*
writing assembly, not that no assembly code is involved in the process
anywhere.
 
D

Dave Angel

Steven said:
I don't know whether C compilers generate assembly mnemonics or direct
machine code, but the distinction for this argument is irrelevant.

The argument in this thread is that it's not worth the *human coder*
writing assembly, not that no assembly code is involved in the process
anywhere.
But the OP said of his friend:

"He dynamically generates mashine code and call that from python."

I took that to mean he dynamically generated machine code, not that he hired some human to do it.

DaveA
 
C

Carl Banks

But the OP said of his friend:

"He dynamically generates mashine code and call that from python."

I took that to mean he dynamically generated machine code, not that he hired some human to do it.

Well we know what you meant, but he did post a snippet of the code
showing handwritten assembly, from which the machine code is
dynamically generated.

Inline assembly not too useful for general purpose Python programming,
but I'm sure there's a time and place for it.

I wonder how easy it'd be to bundle a small C compiler.


Carl Banks
 
S

Steven D'Aprano

But the OP said of his friend:

"He dynamically generates mashine code and call that from python."

I took that to mean he dynamically generated machine code, not that he
hired some human to do it.


Well, I suppose if his friend is a robot or alien intelligence, you could
very well be right. *wink*

Otherwise, whether his friends writes the assembly, or he hires someone
to do it, what's the difference?

(If you follow the OP's link to the code, it seems fairly clear to me
that it uses hand-written assembly code.)
 
D

DivX

On 20 lip, 02:52, Steven D'Aprano <st...@REMOVE-THIS-
cybersource.com.au> wrote: [...]
I think that mixing assembly and python is a gimmick of very little
practical significance. If you really need the extra performance, check
out PyPy, Cython, Pyrex and Psyco.
Why ask us? You should ask him.

Be sure I will ask him, but before, I wanted to know your opinions
about it. Hear arguments on both sides...

Where I wrote that he was my friend? But that is not the point, I send
him a mail and here is answer:

"I know that writing assembly code is hard but when you want some
simple algorithm like algorithms in image processing or in digital
signal processing you must write functions in C and then write wrapper
to call that from python because it’s slow to do all work from python.
And then if you want to support windows and Linux you will spend more
time about compiling and see if everything works correctly than on
algorithms.

Another thing is that when you have assembler now you can write some
small C compiler so that you don’t have to write assembly language.
It’s doesn’t matter if gcc will produce better code it’s enough to
achieve speed that you are satisfied and you don’t have to worry
about how to write extensions for Python.

Also many people use intrinsic functions to achieve more speed when
they need. I think programming using intrinsic functions is like using
sse instructions directly.

Best regards,

Tahir"

So, thanks people for your opinions and arguments...
 
D

Dave Angel

Steven said:
Well, I suppose if his friend is a robot or alien intelligence, you could
very well be right. *wink*

Otherwise, whether his friends writes the assembly, or he hires someone
to do it, what's the difference?

(If you follow the OP's link to the code, it seems fairly clear to me
that it uses hand-written assembly code.)
My fault. I didn't follow the link. I assumed the words in all those
messages were clear enough. So his acquaintance is writing an
assembler, not a code generator.

DaveA
 
A

alex23

DivX said:
Another thing is that when you have assembler now you can write some
small C compiler so that you don’t have to write assembly language.

That has to be the most paradoxical argument I've ever heard: "when
you use assembler you have the ability to not use assembler" :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,996
Messages
2,570,238
Members
46,826
Latest member
robinsontor

Latest Threads

Top