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
d14baee9
Commit
d14baee9
authored
May 24, 2010
by
Russ Cox
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
6g: avoid unnecessary conversion in shift bounds check
R=ken2 CC=golang-dev
https://golang.org/cl/1278042
parent
426fef55
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
4 deletions
+15
-4
ggen.c
src/cmd/6g/ggen.c
+15
-4
No files found.
src/cmd/6g/ggen.c
View file @
d14baee9
...
...
@@ -888,6 +888,7 @@ cgen_shift(int op, Node *nl, Node *nr, Node *res)
int
a
,
rcx
;
Prog
*
p1
;
uvlong
sc
;
Type
*
tcount
;
a
=
optoas
(
op
,
nl
->
type
);
...
...
@@ -920,8 +921,16 @@ cgen_shift(int op, Node *nl, Node *nr, Node *res)
rcx
=
reg
[
D_CX
];
nodreg
(
&
n1
,
types
[
TUINT32
],
D_CX
);
// Allow either uint32 or uint64 as shift type,
// to avoid unnecessary conversion from uint32 to uint64
// just to do the comparison.
tcount
=
types
[
simtype
[
nr
->
type
->
etype
]];
if
(
tcount
->
etype
<
TUINT32
)
tcount
=
types
[
TUINT32
];
regalloc
(
&
n1
,
nr
->
type
,
&
n1
);
// to hold the shift type in CX
regalloc
(
&
n3
,
t
ypes
[
TUINT64
]
,
&
n1
);
// to clear high bits of CX
regalloc
(
&
n3
,
t
count
,
&
n1
);
// to clear high bits of CX
nodreg
(
&
cx
,
types
[
TUINT64
],
D_CX
);
memset
(
&
oldcx
,
0
,
sizeof
oldcx
);
...
...
@@ -929,6 +938,7 @@ cgen_shift(int op, Node *nl, Node *nr, Node *res)
regalloc
(
&
oldcx
,
types
[
TUINT64
],
N
);
gmove
(
&
cx
,
&
oldcx
);
}
cx
.
type
=
tcount
;
if
(
samereg
(
&
cx
,
res
))
regalloc
(
&
n2
,
nl
->
type
,
N
);
...
...
@@ -946,9 +956,9 @@ cgen_shift(int op, Node *nl, Node *nr, Node *res)
regfree
(
&
n3
);
// test and fix up large shifts
nodconst
(
&
n3
,
t
ypes
[
TUINT64
]
,
nl
->
type
->
width
*
8
);
gins
(
optoas
(
OCMP
,
t
ypes
[
TUINT64
]
),
&
n1
,
&
n3
);
p1
=
gbranch
(
optoas
(
OLT
,
t
ypes
[
TUINT64
]
),
T
);
nodconst
(
&
n3
,
t
count
,
nl
->
type
->
width
*
8
);
gins
(
optoas
(
OCMP
,
t
count
),
&
n1
,
&
n3
);
p1
=
gbranch
(
optoas
(
OLT
,
t
count
),
T
);
if
(
op
==
ORSH
&&
issigned
[
nl
->
type
->
etype
])
{
nodconst
(
&
n3
,
types
[
TUINT32
],
nl
->
type
->
width
*
8
-
1
);
gins
(
a
,
&
n3
,
&
n2
);
...
...
@@ -960,6 +970,7 @@ cgen_shift(int op, Node *nl, Node *nr, Node *res)
gins
(
a
,
&
n1
,
&
n2
);
if
(
oldcx
.
op
!=
0
)
{
cx
.
type
=
types
[
TUINT64
];
gmove
(
&
oldcx
,
&
cx
);
regfree
(
&
oldcx
);
}
...
...
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