Re: It has been done before




Charles A. Crayne wrote:
> "PortAsm/86 for PowerPC is a source-code translator which converts 80x86
> assembly-language code into efficient and maintainable PowerPC
> assembly-language. It automatically deals with architectural differences
> such as segmented addressing and alignment of memory accesses, and applies
> aggressive optimizations to ensure good performance of translated code."
>
> http://www.microapl.co.uk/Porting/PortAsm86.html

First of all, I am quite aware of this product. I looked at it when
considering an HLA->PPC conversion a couple of years ago. The question
I have is *did you read the manual* at the link you've provided? Let
me quote a few relevant sections:

\
"The translation process is very largely automatic, but not entirely
so. This is because some
assembler constructs cannot be translated automatically because of
fundamental
differences between the 80x86 and PowerPC architectures, or because to
accomodate
some rare types of 80x86 programming would be so inefficient that it is
better to intervene
manually in order to produce good-quality PowerPC code. Where you need
to help
PortAsm with the translation, you usually do so by editing the original
80x86 source file.
You can either change the 80x86 assembler to avoid using the construct
which gave rise to
the problem, or in some cases you can provide a 'hint' which
provides PortAsm with
information about what the program is doing. You can also directly
include PowerPC
assembly-language instructions within the original 80x86 source file.
By using conditional
assembly directives, you can easily maintain one set of source files to
support both the
80x86 family and the PowerPC."

I would also point out the following statement:

"However, the translation carried out by PortAsm is not simply a
substitution of PowerPC
instructions for each 80x86 instruction. Instead, PortAsm carries out a
comprehensive
analysis of the original program, and is thus able to generate an
efficient translation which
does not reproduce irrelevant side-effects of the original code. For
example, many 80x86
instructions automatically affect the 80x86 condition codes, but to
reproduce this behaviour
on the PowerPC takes extra processing time; PortAsm thus analyses the
original program
to determine whether condition codes need to be set by a given
instruction, and generates
code to set condition codes only where it is necessary to do so. There
are many other
examples of this kind. In addition, PortAsm optionally carries out a
number
code, such as translating common sequences
automatically handles the changed runtime conventions
other software in PowerPC-based systems."

As I've said many times in the threads on this subject, the appropriate
way to do the conversion is to build a data flow analyzer and optimizer
to clean up the massive code that you'd have to generate in order to
simulate the x86 instructions. Clearly, MicroAPL has done quite a bit
of this. I cannot overemphasize the amount of work needed to do this
(as Alex points out, it's quite a bit more work than a typical
optimizing compiler). And even so, their conversion is *not* automatic.


You might want to pay particular attention to statements like "In
addition, PortAsm at present does not translate 8087-family
floating-point instructions." (of course, MMX and SSE were developed
*after* this product was written, so it's doubtful there are support
for those instructions, either).


Sorry, this does not qualify anyone for the Turing Award. If it were
automatic, it would. But it's quite a ways away from that.

Do keep in mind that I *never* said this problem was impossible to
solve. Only that it is *very* difficult and well beyond the
capabilities of someone like Rene and the problem is *far* more complex
than you seem to think that it is.

BTW, from Appendix 1:

Supported Instructions
The following 80x86 instructions are supported, subject to restrictions
noted elsewhere in
this manual:
AAA
AAD
AAM
AAS
ADC
ADD
AND
BSWAP
CALL
CBW
CWDE
CLC
CLD
CMC
CMP
CMPSx
CMPXCHG
CWD
CDQ
DAA
DAS
DEC
DIV
ENTER
IDIV
IMUL
INC
INT
Jxx
JMP
LAHF
LDS
LEA
LEAVE
LES
LFS
LGS
LODx
LOOP
LOOPx
LSS
MOV
MOVSX
MOVZX
MUL
NEG
NOT
OR
POP
POPA/POPAD
POPF/POPFD
PUSH
PUSHA/PUSHAD
PUSHF/PUSHFD
RCL/RCR
REP
REPxx
RET
ROL
ROR
SAHF
SAL/SHL
SAR
SBB
SCASxx
SETxx
SHLD
SHR
SHRD
STC
STD
STOSxx
SUB
TEST
XADD
XCHG
XLAT/XLATB
XOR

Unsupported instructions
The following 80x86-family instructions are not currently supported.
Their use will give rise
to an error, unless a macro of the same name has been defined:
ARPL
BOUND
BSF
BSR
BT
BTC
BTR
CLI
CLTS
HLT
IN
INSx
INTO
INVxx
IRET
LAR
LGDT
LIDT
LLDT
LMSW
LOCK
LSL
LTR
OUT
OUTSx
SGDT
SIDT
SLDT
SMSW
STI
STR
VERR
VERW
WAIT
If your code contains one or more of these instructions, you usually
need to include a
small section of PowerPC assembler (inside an ASM...ENDASM section) to
achieve the
desired result on the target system.
In addition, none of the 80x87 floating-point instructions Fxxx are
supported.




Definitely, you'll want to read through the manual to get an idea of
the limitation of this *very good* translator. But it is far from
automatic and far from perfect. It provides the "80% solution" that
you've inferred as being a useful tool. It may even be capable of
handling Rene's "20 or so instructions" that he limits himself to
writing. But this product is not the type of thing Rene (or anyone else
around here, including myself) can bang out in a couple of months.
Cheers,
Randy Hyde

.



Relevant Pages

  • Re: nasm over gas?
    ... > parallel are the instructions that calculate the next address, ... > really good optimizer could, perform a fix-up that, based upon ... > registers, %ebp, or any segment registers so, in the case ... > When I write assembly-language functions I usually do it to ...
    (Linux-Kernel)
  • Re: a history question
    ... >> Picky, picky. ... >> instructions. ... >I'll grant that was a nit. ... However, the differences between PowerPC ...
    (comp.lang.cobol)
  • Re: a history question
    ... >>program code to PPC opcodes would be suboptimal. ... > Picky, picky. ... However, the differences between PowerPC ... > " The MI instructions are translated by SLIC into PowerPC AS machine ...
    (comp.lang.cobol)
  • Re: nasm over gas?
    ... >> execute those two instructions in parallel. ... Just make that optimizer and away you go! ... > registers just like another variables. ... When I write assembly-language functions I usually do it to ...
    (Linux-Kernel)
  • Re: what kind of computer for programmer ?
    ... > PowerPC with 700 MHz would be better? ... aligned instructions, etc. and CISC have other: ... Pentium machines will be available in 2007. ... have a look at the manuals: PowerPC, Pentium and Sparc manuals are all ...
    (comp.programming)