~ubuntu-branches/ubuntu/maverick/radare/maverick

« back to all changes in this revision

Viewing changes to src/rsc/pool/mmx2ls2f.pl

  • Committer: Bazaar Package Importer
  • Author(s): SevenMachines
  • Date: 2010-09-07 15:44:27 UTC
  • mfrom: (1.1.3 upstream) (2.1.4 sid)
  • Revision ID: james.westby@ubuntu.com-20100907154427-37u92vu12tqabqqz
Tags: 1:1.5.2-3ubuntu1
* Merge from debian testing (LP: #621016)
* debian/control:
     + libvala-dev transition to libval-0.10-dev (LP: #618809) 

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/perl
 
2
#
 
3
# mmx2ls2f
 
4
#
 
5
#   Intel x86-MMX assembly code translator to MIPS Loongson2{E,F}
 
6
#
 
7
# License: GPL
 
8
#
 
9
# author: pancake <youterm.com>
 
10
#
 
11
 
 
12
my %regs = ();
 
13
 
 
14
# MMX
 
15
$regs{"mm0"} = "f0";
 
16
$regs{"mm1"} = "f2";
 
17
$regs{"mm2"} = "f4";
 
18
$regs{"mm3"} = "f6";
 
19
$regs{"mm4"} = "f8";
 
20
$regs{"mm5"} = "f10";
 
21
$regs{"mm6"} = "f12";
 
22
$regs{"mm7"} = "f14";
 
23
 
 
24
# GP
 
25
$regs{"ebx"} = "f0";
 
26
$regs{"ecx"} = "t3"; # counter
 
27
$regs{"esi"} = "t4";
 
28
$regs{"edi"} = "t5";
 
29
 
 
30
 
 
31
while(<STDIN>)
 
32
{
 
33
        chomp(my $str = $_);
 
34
 
 
35
        $str=~s/%%/%/g;
 
36
        for $a (keys(%regs)) {
 
37
                if ($str=~/$a/) {
 
38
                        eval ("\$str=~s/$a/$regs{$a}/gei;");
 
39
                }
 
40
        }
 
41
 
 
42
        # instructions
 
43
        $str=~s/movd\s+\(%(.+)\)\s*,\s*%([^\s]+)/"ldc1 \$$1, \$$2"/ge;
 
44
        #$str=~s/psrad\s+\$(.+)\s*,\s*%([^\s]+)/li \$t1, \$f18, \$t1psraw \$$2, \$$2, \$$1"/ge;
 
45
        $str=~s/jnz/bnez/ge;
 
46
        $str=~s/ret/jr \$ra\nnop/g;
 
47
        $str=~s/movq\s+(\d+)\(%(.+)\)\s*,\s*%([^\s]+)/ldc1 \$$3, $1 (\$$2)/g;
 
48
        $str=~s/movq\s+%\[(.+)\]\s*,\s*%([^\s]+)/ldc1 \$$2, 0($1)/g;
 
49
        $str=~s/movq\s+%(.+)\s*,\s*%\[([^\s]+)\]/sdc1 \$$1, 0($2)/g;
 
50
        $str=~s/movq\s+%(.+)\s*,\s*(\d+)\(%([^\s]+)\)/sdc1 \$$1, $2(\$$3)/g;
 
51
        $str=~s/movq\s+%(.+)\s*,\s*%([^\s]+)/mov\.d \$$2, \$$1/g;
 
52
        $str=~s/pmullw\s+%\[(.+)\]\s*,\s*%([^\s]+)/ldc1 \$f20, 0($1)\npmullh \$$2, \$$2, \$f20/g;
 
53
        $str=~s/pmullw\s+%(.+)\s*,\s*%([^\s]+)/pmullh \$$2, \$$2, \$$1/g; ## IS THIS OK ?
 
54
        $str=~s/psraw\s+\$(.+)\s*,\s*%([^\s]+)/li \$t2, $1\ndmtc1 \$t2, \$f18\npsrah \$$2, \$$2, \$f18/g;
 
55
        $str=~s/psubw\s+%(.+)\s*,\s*%([^\s]+)/psubh \$$2, \$$2, \$$1/g;
 
56
        $str=~s/paddw\s+%(.+)\s*,\s*%([^\s]+)/paddh \$$2, \$$2, \$$1/g;
 
57
        $str=~s/movl\s+\$(\d+)\s*,\s*%([^\s]+)/li \$$2, $1/g;
 
58
        $str=~s/psllw\s+\$(\d+)\s*,\s*%([^\s]+)/li \$t1, $1\ndmtc1 \$t1, \$f18\npsllh \$$2, \$$2, \$f18/g;
 
59
        $str=~s/punpcklwd\s+%(.+)\s*,\s*%([^\s]+)/punpcklhw \$$2, \$$2, \$$1/g;
 
60
        $str=~s/punpckhwd\s+%(.+)\s*,\s*%([^\s]+)/punpckhhw \$$2, \$$2, \$$1/g;
 
61
        $str=~s/punpckldq\s+%(.+)\s*,\s*%([^\s]+)/punpcklwd \$$2, \$$2, \$$1/g;
 
62
        $str=~s/punpckhdq\s+%(.+)\s*,\s*%([^\s]+)/punpckhwd \$$2, \$$2, \$$1/g;
 
63
        $str=~s/packssdw\s+%(.+)\s*,\s*%([^\s]+)/packsswh \$$2, \$$2, \$$1/g;
 
64
        $str=~s/packuswb\s+%(.+)\s*,\s*%([^\s]+)/packushb \$$2, \$$2, \$$1/g;
 
65
        $str=~s/addl\s+\$(\d+), %([^\s]+)/addi \$$2, \$$2, $1/g;
 
66
        $str=~s/subl\s+\$(\d+), %([^\s]+)/addi \$$2, \$$2, -$1/g;
 
67
        $str=~s/[^\d]0\((.*)\)/$1/g;
 
68
        $str=~s/\%f/\$f/g;
 
69
 
 
70
# TODO
 
71
# punpckldq    %mm7, %mm1
 
72
# punpckhdq    %mm7, %mm1
 
73
 
 
74
        $str=~s/^\s+//g;
 
75
        $str=~s/^\t+//g;
 
76
 
 
77
        print "$str\n" if ($str);
 
78
}