Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
G
golang
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
golang
Commits
937ac13f
Commit
937ac13f
authored
Dec 13, 2008
by
Ken Thompson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
code improvement
R=r OCL=21144 CL=21144
parent
58a320f9
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
155 additions
and
0 deletions
+155
-0
cgen.c
src/cmd/6g/cgen.c
+25
-0
gg.h
src/cmd/6g/gg.h
+1
-0
gsubr.c
src/cmd/6g/gsubr.c
+129
-0
No files found.
src/cmd/6g/cgen.c
View file @
937ac13f
...
@@ -11,6 +11,7 @@ cgen(Node *n, Node *res)
...
@@ -11,6 +11,7 @@ cgen(Node *n, Node *res)
Node
n1
,
n2
;
Node
n1
,
n2
;
int
a
;
int
a
;
Prog
*
p1
,
*
p2
,
*
p3
;
Prog
*
p1
,
*
p2
,
*
p3
;
Addr
addr
;
if
(
debug
[
'g'
])
{
if
(
debug
[
'g'
])
{
dump
(
"
\n
cgen-res"
,
res
);
dump
(
"
\n
cgen-res"
,
res
);
...
@@ -70,6 +71,21 @@ cgen(Node *n, Node *res)
...
@@ -70,6 +71,21 @@ cgen(Node *n, Node *res)
goto
ret
;
goto
ret
;
}
}
if
(
sudoaddable
(
n
,
res
->
type
,
&
addr
))
{
a
=
optoas
(
OAS
,
n
->
type
);
if
(
res
->
op
==
OREGISTER
)
{
p1
=
gins
(
a
,
N
,
res
);
p1
->
from
=
addr
;
}
else
{
regalloc
(
&
n1
,
n
->
type
,
N
);
p1
=
gins
(
a
,
N
,
&
n1
);
p1
->
from
=
addr
;
gins
(
a
,
&
n1
,
res
);
regfree
(
&
n1
);
}
return
;
}
switch
(
n
->
op
)
{
switch
(
n
->
op
)
{
default:
default:
dump
(
"cgen"
,
n
);
dump
(
"cgen"
,
n
);
...
@@ -269,6 +285,15 @@ abop: // asymmetric binary
...
@@ -269,6 +285,15 @@ abop: // asymmetric binary
if
(
nl
->
ullman
>=
nr
->
ullman
)
{
if
(
nl
->
ullman
>=
nr
->
ullman
)
{
regalloc
(
&
n1
,
nl
->
type
,
res
);
regalloc
(
&
n1
,
nl
->
type
,
res
);
cgen
(
nl
,
&
n1
);
cgen
(
nl
,
&
n1
);
if
(
sudoaddable
(
nr
,
nl
->
type
,
&
addr
))
{
p1
=
gins
(
a
,
N
,
&
n1
);
p1
->
from
=
addr
;
gmove
(
&
n1
,
res
);
regfree
(
&
n1
);
goto
ret
;
}
regalloc
(
&
n2
,
nr
->
type
,
N
);
regalloc
(
&
n2
,
nr
->
type
,
N
);
cgen
(
nr
,
&
n2
);
cgen
(
nr
,
&
n2
);
}
else
{
}
else
{
...
...
src/cmd/6g/gg.h
View file @
937ac13f
...
@@ -199,6 +199,7 @@ void tempname(Node*, Type*);
...
@@ -199,6 +199,7 @@ void tempname(Node*, Type*);
Plist
*
newplist
(
void
);
Plist
*
newplist
(
void
);
int
isfat
(
Type
*
);
int
isfat
(
Type
*
);
void
setmaxarg
(
Type
*
);
void
setmaxarg
(
Type
*
);
int
sudoaddable
(
Node
*
,
Type
*
,
Addr
*
);
/*
/*
* list.c
* list.c
...
...
src/cmd/6g/gsubr.c
View file @
937ac13f
...
@@ -1175,6 +1175,37 @@ optoas(int op, Type *t)
...
@@ -1175,6 +1175,37 @@ optoas(int op, Type *t)
a
=
AUCOMISD
;
a
=
AUCOMISD
;
break
;
break
;
case
CASE
(
OAS
,
TBOOL
):
case
CASE
(
OAS
,
TINT8
):
case
CASE
(
OAS
,
TUINT8
):
a
=
AMOVB
;
break
;
case
CASE
(
OAS
,
TINT16
):
case
CASE
(
OAS
,
TUINT16
):
a
=
AMOVW
;
break
;
case
CASE
(
OAS
,
TINT32
):
case
CASE
(
OAS
,
TUINT32
):
case
CASE
(
OAS
,
TPTR32
):
a
=
AMOVL
;
break
;
case
CASE
(
OAS
,
TINT64
):
case
CASE
(
OAS
,
TUINT64
):
case
CASE
(
OAS
,
TPTR64
):
a
=
AMOVQ
;
break
;
case
CASE
(
OAS
,
TFLOAT32
):
a
=
AMOVSS
;
break
;
case
CASE
(
OAS
,
TFLOAT64
):
a
=
AMOVSD
;
break
;
case
CASE
(
OADD
,
TINT8
):
case
CASE
(
OADD
,
TINT8
):
case
CASE
(
OADD
,
TUINT8
):
case
CASE
(
OADD
,
TUINT8
):
a
=
AADDB
;
a
=
AADDB
;
...
@@ -1728,3 +1759,101 @@ setmaxarg(Type *t)
...
@@ -1728,3 +1759,101 @@ setmaxarg(Type *t)
if
(
w
>
maxarg
)
if
(
w
>
maxarg
)
maxarg
=
w
;
maxarg
=
w
;
}
}
/*
* gather series of offsets
* >=0 is direct addressed field
* <0 is pointer to next field (+1)
*/
int
dotoffset
(
Node
*
n
,
int
*
oary
,
Node
**
nn
)
{
int
i
;
switch
(
n
->
op
)
{
case
ODOT
:
i
=
dotoffset
(
n
->
left
,
oary
,
nn
);
if
(
i
>
0
)
{
if
(
oary
[
i
-
1
]
>=
0
)
oary
[
i
-
1
]
+=
n
->
xoffset
;
else
oary
[
i
-
1
]
-=
n
->
xoffset
;
break
;
}
if
(
i
<
10
)
oary
[
i
++
]
=
n
->
xoffset
;
break
;
case
ODOTPTR
:
i
=
dotoffset
(
n
->
left
,
oary
,
nn
);
if
(
i
<
10
)
oary
[
i
++
]
=
-
(
n
->
xoffset
+
1
);
break
;
default:
*
nn
=
n
;
return
0
;
}
if
(
i
>=
10
)
*
nn
=
N
;
return
i
;
}
int
sudoaddable
(
Node
*
n
,
Type
*
t
,
Addr
*
a
)
{
int
et
,
o
,
i
;
int
oary
[
10
];
Node
n1
,
n2
,
*
nn
;
if
(
n
->
type
==
T
||
t
==
T
)
return
0
;
et
=
simtype
[
n
->
type
->
etype
];
if
(
et
!=
simtype
[
t
->
etype
])
return
0
;
switch
(
n
->
op
)
{
default:
return
0
;
case
ODOT
:
case
ODOTPTR
:
o
=
dotoffset
(
n
,
oary
,
&
nn
);
if
(
nn
==
N
)
return
0
;
if
(
0
)
{
dump
(
"
\n
XX"
,
n
);
dump
(
"YY"
,
nn
);
for
(
i
=
0
;
i
<
o
;
i
++
)
print
(
" %d"
,
oary
[
i
]);
print
(
"
\n
"
);
return
0
;
}
regalloc
(
&
n1
,
types
[
tptr
],
N
);
n2
=
n1
;
n2
.
op
=
OINDREG
;
if
(
oary
[
0
]
>=
0
)
{
agen
(
nn
,
&
n1
);
n2
.
xoffset
=
oary
[
0
];
}
else
{
cgen
(
nn
,
&
n1
);
n2
.
xoffset
=
-
(
oary
[
0
]
+
1
);
}
for
(
i
=
1
;
i
<
o
;
i
++
)
{
if
(
oary
[
i
]
>=
0
)
fatal
(
"cant happen"
);
gins
(
AMOVQ
,
&
n2
,
&
n1
);
n2
.
xoffset
=
-
(
oary
[
i
]
+
1
);
}
a
->
type
=
D_NONE
;
a
->
index
=
D_NONE
;
naddr
(
&
n2
,
a
);
regfree
(
&
n1
);
break
;
}
return
1
;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment