 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Gordon Cowie Guest
|
Posted: Thu Feb 16, 2006 12:03 am Post subject: softwire for basm? |
|
|
Anyone remember softwire?
It was an awesome sourceforge project with some impressive demos.
Basically it was a class to make dynamically generating code much easier.
For example you would do something like this..
sw.mov(eax,ebx);
sw.imul;
etc
calling the methods simply appends the appropriate code to a buffer.
@sp := sw.AllocProc gives you the actual method pointer of function pointer.
I'm just stabbing at what the syntax would look like in delphi. The
original project was for C++.
So the original project isn't around anymore because a company called
transgaming adopted it into a product similarly named swiftshader. They
hired the main developer from the softwire project and insisted that he
remove the project from sourceforge.
Anyways. Is anyone interested in starting a similar project for delphi?
It would be a great way to support cpu specific instructions or
optimizations without having to have the entire compiled versions for
each cpu. |
|
| Back to top |
|
 |
Nicholas Sherlock Guest
|
Posted: Thu Feb 16, 2006 3:03 am Post subject: Re: softwire for basm? |
|
|
Gordon Cowie wrote:
| Quote: | Basically it was a class to make dynamically generating code much easier.
For example you would do something like this..
sw.mov(eax,ebx);
sw.imul;
etc
[...]
Anyways. Is anyone interested in starting a similar project for delphi?
It would be a great way to support cpu specific instructions or
optimizations without having to have the entire compiled versions for
each cpu.
|
This sounds really neat and it's certainly a tool that I want in my
toolkit. I'd be happy to help out.
Cheers,
Nicholas Sherlock
--
http://www.sherlocksoftware.org |
|
| Back to top |
|
 |
Eric Grange Guest
|
Posted: Thu Feb 16, 2006 8:03 am Post subject: Re: softwire for basm? |
|
|
| Quote: | For example you would do something like this..
sw.mov(eax,ebx);
sw.imul;
|
Wouldn't something like
sw('mov(eax, ebx)');
sw('imul');
actually be preferable? This way your ASM can be generated at runtime, based on
parameterization, some code generators or templates, etc.
While with the
sw.mov(eax,ebx);
sw.imul;
syntax, asm instructions are actually hardwired at compile-time, and this will
behave like BASM maintainance-wise the only thing that can be softwired being
the low-level implementation (which wouldn't be really useful either, as ASM is
CPU-specific, you would just get suboptimal ASM, ie. get no better than what
regular, non-ASM code, could have given you).
Eric |
|
| Back to top |
|
 |
Nicholas Sherlock Guest
|
Posted: Thu Feb 16, 2006 9:03 am Post subject: Re: softwire for basm? |
|
|
Eric Grange wrote:
| Quote: | with the
sw.mov(eax,ebx);
sw.imul;
syntax, asm instructions are actually hardwired at compile-time, and
this will behave like BASM maintainance-wise the only thing that can be
softwired being the low-level implementation (which wouldn't be really
useful either, as ASM is CPU-specific, you would just get suboptimal
ASM, ie. get no better than what regular, non-ASM code, could have given
you).
|
Yes, but there are situations where this is useful, especially when you
are patching code and creating stubs for calling other methods. I could
replace records like this:
tthiscalljumpstruct = packed record
d1, d2, d3, d4, d5, d6: byte;
push1: byte;
oldaddress: pointer;
pusheax: byte;
push2: byte;
newaddress: pointer;
ret: byte;
end;
And associated ugly, write-only code:
j.d1 := $8B;
j.d2 := $04;
j.d3 := $24;
j.d4 := $89;
j.d5 := $0C;
j.d6 := $24;
j.push1 := ipush;
j.oldaddress := oldaddress;
j.pusheax := ipusheax;
j.push2 := ipush;
j.newaddress := newaddress;
j.ret := iret;
With code like this:
sw.mov(eax,[esp]);
sw.mov([esp],ecx);
sw.push(oldaddress);
sw.push(eax);
sw.push(newaddress);
sw.ret;
Cheers,
Nicholas Sherlock
--
http://www.sherlocksoftware.org |
|
| Back to top |
|
 |
Gordon Cowie Guest
|
Posted: Thu Feb 16, 2006 1:03 pm Post subject: Re: softwire for basm? |
|
|
| Quote: | Wouldn't something like
sw('mov(eax, ebx)');
sw('imul');
|
I think you're missing the idea of the class. It acts as a run-time
assembler. The methods are not to be executed in place. Just building a
page of code (optimized code for whatever circumstance) then call the
resulting function pointer from the inner loop.
In the actual softwire project, each x86 instruction was wrapped with a
method.. overloaded with all the possible combinations of parameters and
even some helpful reference in the popup hint. The method just appends
the right sequence of bytes to a memory buffer (later to be referenced
by your function ptr). |
|
| Back to top |
|
 |
Eric Grange Guest
|
Posted: Fri Feb 17, 2006 12:03 pm Post subject: Re: softwire for basm? |
|
|
| Quote: | I think you're missing the idea of the class. It acts as a run-time
assembler.
|
I understood that, but it's a runtime assembler based on a set of method
calls that were fixed at runtime (the code that makes the calls to the
class methods is compiled and cannot change), thus the ASM that you'll
be assembling is determined at compile-time.
| Quote: | The methods are not to be executed in place. Just building a
page of code (optimized code for whatever circumstance) then call the
resulting function pointer from the inner loop.
|
....but the page of code you're building has a content determined at
compile time, by the code that will invoke the class, so your ASM is as
hardwired as if you had used BASM...
I can see the rationale behind that for languages that don't have much
or any inline assembly capability, but if you have one, you're just
exchanging one assembler for another, instead of hardwiring the opcodes,
you're hardwiring the calls that will generate the opcodes.
Eric |
|
| Back to top |
|
 |
Lord Crc Guest
|
Posted: Fri Feb 17, 2006 3:03 pm Post subject: Re: softwire for basm? |
|
|
On Thu, 16 Feb 2006 08:28:35 +0100, Eric Grange
<egrangeNO (AT) SPAMglscene (DOT) org> wrote:
| Quote: | Wouldn't something like
sw('mov(eax, ebx)');
sw('imul');
actually be preferable? This way your ASM can be generated at runtime, based on
parameterization, some code generators or templates, etc.
|
If you implement the original proposal, couldn't you simply implement
a parser on top of it, allowing for expressions like you're
suggesting?
- Asbjørn |
|
| Back to top |
|
 |
Eric Grange Guest
|
Posted: Fri Feb 17, 2006 3:03 pm Post subject: Re: softwire for basm? |
|
|
| Quote: | If you implement the original proposal, couldn't you simply implement
a parser on top of it, allowing for expressions like you're
suggesting?
|
You could, but 'simply' and 'parser' in the same sentence do not usually
turn out so simple in the end ;)
And in that particular case, parsing to generate as
sw.mov(eax, ebx)
from
'mov eax, ebx'
would be at least as complex as assembling it directly into an opcode in
the first place, and likely turn out even more complex as asm
instructions can be tabulated (cf. my x86asm unit), and their assembly
streamlined, while tabulating and streamlining method invokations isn't
as straightforward.
There is also the issue of composite instructions parameters, such as
mov eax, [esi+edx*2+4]
or qualifiers as in with f.i.
fld dword ptr [eax+edx]
fld qword ptr [esp-4]
etc.
which do not lend themselves to being expressed as method calls.
Eric |
|
| Back to top |
|
 |
Gordon Cowie Guest
|
Posted: Fri Feb 17, 2006 9:03 pm Post subject: Re: softwire for basm? |
|
|
| Quote: | I understood that, but it's a runtime assembler based on a set of method
calls that were fixed at runtime (the code that makes the calls to the
class methods is compiled and cannot change), thus the ASM that you'll
be assembling is determined at compile-time.
....
I can see the rationale behind that for languages that don't have much
or any inline assembly capability, but if you have one, you're just
exchanging one assembler for another, instead of hardwiring the opcodes,
you're hardwiring the calls that will generate the opcodes.
Eric
|
Perhaps my example was too simple.
If you were to use the softwire class without any conditional logic (to
dynamically generate code), then yes, there is no point in using it at
all. However, the softwire class makes using conditional logic a cinch:
if( mmx in cpu.capabilities ) then
begin
sw.psubw(...)
sw.pmullw(...)
..
end else
//non mmx code...
This is just for the sake of example as I'm sure you will argue the
practicality of such an approach to supporting mmx (how is this easier
than just writing an mmx version and a non mmx version?). Although, it
is an alternative to writing an mmx version, sse version, 3dnow version,
amd, pentium, 486. One function instead of 10.. for extremely common RTL
routines with plenty of optimized paths it's probably a nice way to
offer the best performance on any cpu without the bloat.
Other uses could be simpler. For instance shift functions on the pentium
are much faster when given immediate data.. but it's rare we can write
such code without it being extremely optimized for a certain case.
However, with softwire you can write a function which takes your
parameters and generates the optimized function for you with immediate
data. I'm sure I don't have to explain the benefits of dynamically
generating code. |
|
| Back to top |
|
 |
Gordon Cowie Guest
|
Posted: Fri Feb 17, 2006 9:03 pm Post subject: Re: softwire for basm? |
|
|
| Quote: | Wouldn't something like
sw('mov(eax, ebx)');
sw('imul');
actually be preferable? This way your ASM can be generated at runtime, based on
parameterization, some code generators or templates, etc.
If you implement the original proposal, couldn't you simply implement
a parser on top of it, allowing for expressions like you're
suggesting?
- Asbjørn
|
Yes. And instead of a syntax identical to asm (what's the point?) you
could be parsing a regular expression and generating compiled code. This
is close to what ultimately became of the original softwire project..
except instead of parsing regular expressions it is being used to parse
a type of shader expression. |
|
| Back to top |
|
 |
Gordon Cowie Guest
|
Posted: Fri Feb 17, 2006 9:03 pm Post subject: Re: softwire for basm? |
|
|
| Quote: | There is also the issue of composite instructions parameters, such as
mov eax, [esi+edx*2+4]
or qualifiers as in with f.i.
fld dword ptr [eax+edx]
fld qword ptr [esp-4]
etc.
which do not lend themselves to being expressed as method calls.
Eric
|
The original softwire project handled things like this. You would add
variables and/or memory locations and reference them later. The methods
were overloaded to take parameters for registers immediate data or
memorylocation "variables". |
|
| Back to top |
|
 |
Benjamin Rosseaux Guest
|
Posted: Sat Feb 18, 2006 2:03 am Post subject: Re: softwire for basm? |
|
|
| And that would be only some hours to be to work for me. |
|
| Back to top |
|
 |
Benjamin Rosseaux Guest
|
Posted: Sat Feb 18, 2006 2:03 am Post subject: Re: softwire for basm? |
|
|
I could extend my assembler ( http://bero.0ok.de/page/index.php?p=27 )
to a runtime assembler, if you want. T0A supports all known x86-16 and
x86-32 opcodes. |
|
| Back to top |
|
 |
Lord Crc Guest
|
Posted: Sat Feb 18, 2006 3:03 pm Post subject: Re: softwire for basm? |
|
|
On Fri, 17 Feb 2006 15:31:30 +0100, Eric Grange
<egrangeNO (AT) SPAMglscene (DOT) org> wrote:
| Quote: | You could, but 'simply' and 'parser' in the same sentence do not usually
turn out so simple in the end
|
Well, I agree that there are easier things around
However, the asm language is much more restricted/limited than say
Pascal. For me the hard part would be the "construction" of the
resulting bytes.
I agree about the "compound" statements though. And thinking a bit
more, i think the other way around would be preferable. Ie have the
core take strings and parse them, and then if needed, extend it to
having an object that takes fixed parameters.
- Asbjørn |
|
| Back to top |
|
 |
Alan Garny Guest
|
Posted: Sat Feb 18, 2006 7:03 pm Post subject: Re: softwire for basm? |
|
|
"Lord Crc" <lordcrc (AT) hotmail (DOT) com> wrote in message
news:4gaev1dhvdk3qmeav1r3huruh2a9g2mpj1 (AT) 4ax (DOT) com...
| Quote: | On Fri, 17 Feb 2006 15:31:30 +0100, Eric Grange
egrangeNO (AT) SPAMglscene (DOT) org> wrote:
You could, but 'simply' and 'parser' in the same sentence do not usually
turn out so simple in the end
Well, I agree that there are easier things around
However, the asm language is much more restricted/limited than say
Pascal. For me the hard part would be the "construction" of the
resulting bytes.
|
If all you are doing is to convert some asm statements into opcode, then
it's relatively simple. That's, in fact, what I do for my project, where I
convert mathematical equations into opcode (it allows one to edit a
mathematical model, parse it and then run it by 'compiling it' rather than
interpreting it or generating some Pascal/C/C++/etc. code that is then
compiled and dynamically linked back to the project).
| Quote: | I agree about the "compound" statements though. And thinking a bit
more, i think the other way around would be preferable. Ie have the
core take strings and parse them, and then if needed, extend it to
having an object that takes fixed parameters.
|
That's becoming a bit more complex, but still feasible indeed...
Alan. |
|
| 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
|
|