 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Nicholas Sherlock Guest
|
Posted: Sun Jan 29, 2006 2:32 am Post subject: Delphi based Assembler? |
|
|
Hey all,
I want my Superoptimizer to be able to assemble the valid candidate
functions that it creates so that it can benchmark them to decide which
candidates are the best.
Would I be better off writing a small assembler myself for this problem,
or is there a Delphi based assembler already available? Calling an
external application will be *way* too slow.
Cheers,
Nicholas Sherlock
|
|
| Back to top |
|
 |
Per Larsen Guest
|
Posted: Sun Jan 29, 2006 11:45 am Post subject: Re: Delphi based Assembler? |
|
|
By 'an assembler' I assume you mean code that transforms text containing
instruction mnemonics with arguments into binary code?
I'm not aware of any for use within Delphi apps, but that doesn't mean there
isn't anything out there.
I'm curious why you would need that, though. Isn't it just a matter of
writing a small string of (more or less random)bytes into a chunk of memory,
then executing it via a proc ptr within a try...except frame, or something,
to see it if produces the desired result?
- Per
|
|
| Back to top |
|
 |
Avatar Zondertau Guest
|
Posted: Sun Jan 29, 2006 11:54 am Post subject: Re: Delphi based Assembler? |
|
|
| Quote: | By 'an assembler' I assume you mean code that transforms text
containing instruction mnemonics with arguments into binary code?
I'm not aware of any for use within Delphi apps, but that doesn't
mean there isn't anything out there.
I'm curious why you would need that, though. Isn't it just a matter
of writing a small string of (more or less random)bytes into a chunk
of memory, then executing it via a proc ptr within a try...except
frame, or something, to see it if produces the desired result?
|
This is not a useful approach. Not only does it vastly increase the
search space, but it is also dangerous. A try..except construct cannot
catch everything, and certain code constructs might be dangerous.
--
The Fastcode Project: http://www.fastcodeproject.org/
|
|
| Back to top |
|
 |
Avatar Zondertau Guest
|
Posted: Sun Jan 29, 2006 12:02 pm Post subject: Re: Delphi based Assembler? |
|
|
| Quote: | I want my Superoptimizer to be able to assemble the valid candidate
functions that it creates so that it can benchmark them to decide
which candidates are the best.
Would I be better off writing a small assembler myself for this
problem, or is there a Delphi based assembler already available?
Calling an external application will be way too slow.
|
I am not aware of Delphi components which do this and finding them on
Google seems difficult (no way to get around the many pages about
inline asm programming in Delphi).
However this shouldn't be hard to make. I assume your program already
has some internal representation of the assembly, so parsing will not
be needed. This means you'll only have to be able to translate a few
opcodes and the ModR/M byte.
There is a link to the relevant Intel documents on the FastCode page
(for which there is a link in my sig below). This document:
IA-32 Intel Architecture Software Developer's Manual Volume 2:
Instruction Set Reference
shows you how machine code works and lists the opcodes. It should be
easy to create an assembler from this, especially if parsing is not
needed.
--
The Fastcode Project: http://www.fastcodeproject.org/
|
|
| Back to top |
|
 |
Adem Guest
|
Posted: Sun Jan 29, 2006 1:34 pm Post subject: Re: Delphi based Assembler? |
|
|
Let me get this out straight: I have no idea what you're
trying to do. It is well beyond me; though/hence it does
sound very impressive to me :-)
Encouraged/armed with that ignorance, I was wondering if
you couldn't tweak, say, FASM to do those optimizations.
http://flatassembler.net/docs.php?article=design
If, at the end, FASM's output is some form of .obj file
that I can use in my app without worrying about the DLL
hell, it is fine with me.
I mean, for most people, reading stuff written asm is as
good as reading object code, so while I would like the asm
sources be available, I wouldn't really care if it were
Delphi that compiled it or something else --that is, as
long as I can use it in Delphi (or, FreePascal) in .obj
form.
FASM seems to be a good tool, IMVVHO, because it unlike
(or, is it?) Delphi's it is good for both x86-32 and
x86-64 which means foreseable future would be covered.
Cheers,
Adem
|
|
| Back to top |
|
 |
Per Larsen Guest
|
Posted: Sun Jan 29, 2006 2:43 pm Post subject: Re: Delphi based Assembler? |
|
|
"Avatar Zondertau" <avatarzt (AT) gmail (DOT) com (please reply to newsgroup)> wrote in
message news:43dcadf7$1 (AT) newsgroups (DOT) borland.com...
| Quote: | This is not a useful approach. Not only does it vastly increase the
search space, but it is also dangerous. A try..except construct cannot
catch everything, and certain code constructs might be dangerous.
|
I wasn't really imagining that he used random bytes - rather, just a table
of the byte sequences that are known to map to simple instructions (no
memory access, calls, jumps, and so on).
- Per
|
|
| Back to top |
|
 |
Mattias Andersson Guest
|
Posted: Sun Jan 29, 2006 8:56 pm Post subject: Re: Delphi based Assembler? |
|
|
Nicholas Sherlock wrote:
| Quote: | I want my Superoptimizer to be able to assemble the valid candidate
functions that it creates so that it can benchmark them to decide
which candidates are the best.
Would I be better off writing a small assembler myself for this
problem, or is there a Delphi based assembler already available?
Calling an external application will be *way* too slow.
|
This sounds like a very interesting project. Are you using some kind of
genetic algorithm for this (i.e. survival of the fittest)?
Maybe you could use the X86 code generator in Inno Pascal
([url]http://other.jrsoftware.org/ip)[/url]. However, I think you would probably need
to extend it.
Cheers,
Mattias
|
|
| Back to top |
|
 |
Nicholas Sherlock Guest
|
Posted: Sun Jan 29, 2006 10:40 pm Post subject: Re: Delphi based Assembler? |
|
|
Avatar Zondertau wrote:
| Quote: | I want my Superoptimizer to be able to assemble the valid candidate
functions that it creates so that it can benchmark them to decide
which candidates are the best.
[...] this shouldn't be hard to make. I assume your program already
has some internal representation of the assembly, so parsing will not
be needed. This means you'll only have to be able to translate a few
opcodes and the ModR/M byte.
|
Yes, this sounds like a good solution. Thanks!
Cheers,
Nicholas Sherlock
|
|
| Back to top |
|
 |
Nicholas Sherlock Guest
|
Posted: Sun Jan 29, 2006 10:43 pm Post subject: Re: Delphi based Assembler? |
|
|
Mattias Andersson wrote:
| Quote: | Nicholas Sherlock wrote:
I want my Superoptimizer to be able to assemble the valid candidate
functions that it creates so that it can benchmark them to decide
which candidates are the best.
Would I be better off writing a small assembler myself for this
problem, or is there a Delphi based assembler already available?
Calling an external application will be *way* too slow.
This sounds like a very interesting project. Are you using some kind of
genetic algorithm for this (i.e. survival of the fittest)?
Maybe you could use the X86 code generator in Inno Pascal
([url]http://other.jrsoftware.org/ip)[/url]. However, I think you would probably need
to extend it.
|
No, the Superoptimizer is simply brute force code generation - try every
sensible combination of instructions and see if they work. I can't think
that a genetic algorithm would work because there are no half measures
when it comes to code - either it works or it doesn't. AFAICS, it'd
therefore be impossible to have a "fitness" metric to choose your
candidates by.
Cheers,
Nicholas Sherlock
|
|
| Back to top |
|
 |
Mattias Andersson Guest
|
Posted: Mon Jan 30, 2006 12:39 am Post subject: Re: Delphi based Assembler? |
|
|
Nicholas Sherlock wrote:
| Quote: | Mattias Andersson wrote:
Nicholas Sherlock wrote:
This sounds like a very interesting project. Are you using some kind
of genetic algorithm for this (i.e. survival of the fittest)?
No, the Superoptimizer is simply brute force code generation - try
every sensible combination of instructions and see if they work. I
can't think that a genetic algorithm would work because there are no
half measures when it comes to code - either it works or it doesn't.
AFAICS, it'd therefore be impossible to have a "fitness" metric to
choose your candidates by.
|
What I meant was that you could use the benchmark results as a fitness
metric (for these instruction sequences that actually work).
Mattias
|
|
| Back to top |
|
 |
Eric Grange Guest
|
Posted: Mon Jan 30, 2006 8:27 am Post subject: Re: Delphi based Assembler? |
|
|
Re-posted egASM.zip to the attachments, it includes source and within
X86ASM.pas you'll find a basic assembler.
Been using it to assemble SIMD opcodes for older Delphi versions and a
FPU compiler experiment. Doesn't support all instructions - only those I
ever needed - but can be reasonnably easily extended ("reasonnably"
means "assuming you already understand modRM and SIB stuff" ^_^)
Eric
| Quote: | Hey all,
I want my Superoptimizer to be able to assemble the valid candidate
functions that it creates so that it can benchmark them to decide which
candidates are the best.
Would I be better off writing a small assembler myself for this problem,
or is there a Delphi based assembler already available? Calling an
external application will be *way* too slow.
Cheers,
Nicholas Sherlock
|
|
|
| Back to top |
|
 |
Simon Kissel Guest
|
Posted: Tue Jan 31, 2006 5:55 pm Post subject: Re: Delphi based Assembler? |
|
|
| Quote: | Would I be better off writing a small assembler myself for this problem,
or is there a Delphi based assembler already available? Calling an
external application will be *way* too slow.
|
http://bero.0ok.de/page/index.php?p=27 is written in Delphi. I'll page
the author and point him to this thread.
Simon
|
|
| Back to top |
|
 |
Nicholas Sherlock Guest
|
Posted: Wed Feb 01, 2006 12:23 am Post subject: Re: Delphi based Assembler? |
|
|
Eric Grange wrote:
| Quote: | Re-posted egASM.zip to the attachments, it includes source and within
X86ASM.pas you'll find a basic assembler.
Been using it to assemble SIMD opcodes for older Delphi versions and a
FPU compiler experiment. Doesn't support all instructions - only those I
ever needed - but can be reasonnably easily extended ("reasonnably"
means "assuming you already understand modRM and SIB stuff" ^_^)
|
Thanks all, I've decided to close my eyes tightly when third-party
assemblers float by, and code it myself from scratch, I think it'll be
more fun that way .
Cheers,
Nicholas Sherlock
|
|
| Back to top |
|
 |
Benjamin Rosseaux Guest
|
Posted: Wed Feb 01, 2006 10:16 am Post subject: Re: Delphi based Assembler? |
|
|
If you want use my T0A ( http://bero.0ok.de/page/index.php?p=27 ) ,
write me a mail.
Nicholas Sherlock schrieb:
| Quote: | Eric Grange wrote:
Re-posted egASM.zip to the attachments, it includes source and within
X86ASM.pas you'll find a basic assembler.
Been using it to assemble SIMD opcodes for older Delphi versions and a
FPU compiler experiment. Doesn't support all instructions - only those
I ever needed - but can be reasonnably easily extended ("reasonnably"
means "assuming you already understand modRM and SIB stuff" ^_^)
Thanks all, I've decided to close my eyes tightly when third-party
assemblers float by, and code it myself from scratch, I think it'll be
more fun that way .
Cheers,
Nicholas Sherlock
|
|
|
| Back to top |
|
 |
|
|
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
|
|