Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
go
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
go
Commits
5d1d8a82
Commit
5d1d8a82
authored
May 29, 2009
by
Russ Cox
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
integer conversions and test.
R=ken OCL=29577 CL=29589
parent
6e1762c0
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
184 additions
and
27 deletions
+184
-27
src/cmd/8g/gsubr.c
src/cmd/8g/gsubr.c
+44
-27
test/intcvt.go
test/intcvt.go
+140
-0
No files found.
src/cmd/8g/gsubr.c
View file @
5d1d8a82
...
...
@@ -1045,32 +1045,48 @@ gmove(Node *f, Node *t)
case
CASE
(
TUINT16
,
TINT8
):
case
CASE
(
TINT32
,
TINT8
):
case
CASE
(
TUINT32
,
TINT8
):
// case CASE(TINT64, TINT8):
// case CASE(TUINT64, TINT8):
case
CASE
(
TINT16
,
TUINT8
):
case
CASE
(
TUINT16
,
TUINT8
):
case
CASE
(
TINT32
,
TUINT8
):
case
CASE
(
TUINT32
,
TUINT8
):
// case CASE(TINT64, TUINT8):
// case CASE(TUINT64, TUINT8):
a
=
AMOVB
;
break
;
case
CASE
(
TINT64
,
TINT8
):
// truncate low word
case
CASE
(
TUINT64
,
TINT8
):
case
CASE
(
TINT64
,
TUINT8
):
case
CASE
(
TUINT64
,
TUINT8
):
split64
(
f
,
&
flo
,
&
fhi
);
regalloc
(
&
r1
,
t
->
type
,
t
);
gins
(
AMOVB
,
&
flo
,
&
r1
);
gins
(
AMOVB
,
&
r1
,
t
);
regfree
(
&
r1
);
splitclean
();
return
;
case
CASE
(
TINT16
,
TINT16
):
// same size
case
CASE
(
TINT16
,
TUINT16
):
case
CASE
(
TUINT16
,
TINT16
):
case
CASE
(
TUINT16
,
TUINT16
):
case
CASE
(
TINT32
,
TINT16
):
// truncate
case
CASE
(
TUINT32
,
TINT16
):
// case CASE(TINT64, TINT16):
// case CASE(TUINT64, TINT16):
case
CASE
(
TINT32
,
TUINT16
):
case
CASE
(
TUINT32
,
TUINT16
):
// case CASE(TINT64, TUINT16):
// case CASE(TUINT64, TUINT16):
a
=
AMOVW
;
break
;
case
CASE
(
TINT64
,
TINT16
):
// truncate low word
case
CASE
(
TUINT64
,
TINT16
):
case
CASE
(
TINT64
,
TUINT16
):
case
CASE
(
TUINT64
,
TUINT16
):
split64
(
f
,
&
flo
,
&
fhi
);
regalloc
(
&
r1
,
t
->
type
,
t
);
gins
(
AMOVW
,
&
flo
,
&
r1
);
gins
(
AMOVW
,
&
r1
,
t
);
regfree
(
&
r1
);
splitclean
();
return
;
case
CASE
(
TINT32
,
TINT32
):
// same size
case
CASE
(
TINT32
,
TUINT32
):
case
CASE
(
TUINT32
,
TINT32
):
...
...
@@ -1124,10 +1140,10 @@ gmove(Node *f, Node *t)
case
CASE
(
TINT8
,
TUINT32
):
a
=
AMOVBLSX
;
goto
rdst
;
// case CASE(TINT8, TINT64):
//
case CASE(TINT8, TUINT64):
// a = AMOVBQSX
;
// goto rdst
;
case
CASE
(
TINT8
,
TINT64
):
// convert via int32
case
CASE
(
TINT8
,
TUINT64
):
cvt
=
types
[
TINT32
]
;
goto
hard
;
case
CASE
(
TUINT8
,
TINT16
):
// zero extend uint8
case
CASE
(
TUINT8
,
TUINT16
):
...
...
@@ -1137,28 +1153,28 @@ gmove(Node *f, Node *t)
case
CASE
(
TUINT8
,
TUINT32
):
a
=
AMOVBLZX
;
goto
rdst
;
// case CASE(TUINT8, TINT64):
//
case CASE(TUINT8, TUINT64):
// a = AMOVBQZX
;
// goto rdst
;
case
CASE
(
TUINT8
,
TINT64
):
// convert via uint32
case
CASE
(
TUINT8
,
TUINT64
):
cvt
=
types
[
TUINT32
]
;
goto
hard
;
case
CASE
(
TINT16
,
TINT32
):
// sign extend int16
case
CASE
(
TINT16
,
TUINT32
):
a
=
AMOVWLSX
;
goto
rdst
;
// case CASE(TINT16, TINT64):
//
case CASE(TINT16, TUINT64):
// a = AMOVWQSX
;
// goto rdst
;
case
CASE
(
TINT16
,
TINT64
):
// convert via int32
case
CASE
(
TINT16
,
TUINT64
):
cvt
=
types
[
TINT32
]
;
goto
hard
;
case
CASE
(
TUINT16
,
TINT32
):
// zero extend uint16
case
CASE
(
TUINT16
,
TUINT32
):
a
=
AMOVWLZX
;
goto
rdst
;
// case CASE(TUINT16, TINT64):
//
case CASE(TUINT16, TUINT64):
// a = AMOVWQZX
;
// goto rdst
;
case
CASE
(
TUINT16
,
TINT64
):
// convert via uint32
case
CASE
(
TUINT16
,
TUINT64
):
cvt
=
types
[
TUINT32
]
;
goto
hard
;
case
CASE
(
TINT32
,
TINT64
):
// sign extend int32
case
CASE
(
TINT32
,
TUINT64
):
...
...
@@ -1323,15 +1339,16 @@ gmove(Node *f, Node *t)
*/
/*
* float to float
*
*
/
case
CASE
(
TFLOAT32
,
TFLOAT32
):
a = A
MOVSS
;
a
=
A
FMOVF
;
break
;
case
CASE
(
TFLOAT64
,
TFLOAT64
):
a = A
MOVS
D;
a
=
A
FMOV
D
;
break
;
/*
case CASE(TFLOAT32, TFLOAT64):
a = ACVTSS2SD;
goto rdst;
...
...
test/intcvt.go
0 → 100644
View file @
5d1d8a82
// $G $D/$F.go && $L $F.$A && ./$A.out
// Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package
main
const
(
ci8
=
-
1
<<
7
;
ci16
=
-
1
<<
15
+
100
;
ci32
=
-
1
<<
31
+
100000
;
ci64
=
-
1
<<
63
+
10000000001
;
cu8
=
1
<<
8
-
1
;
cu16
=
1
<<
16
-
1234
;
cu32
=
1
<<
32
-
1234567
;
cu64
=
1
<<
64
-
1234567890123
;
cf32
=
1e8
+
0.5
;
cf64
=
-
1e8
+
0.5
;
)
var
(
i8
int8
=
ci8
;
i16
int16
=
ci16
;
i32
int32
=
ci32
;
i64
int64
=
ci64
;
u8
uint8
=
cu8
;
u16
uint16
=
cu16
;
u32
uint32
=
cu32
;
u64
uint64
=
cu64
;
// f32 float32 = 1e8 + 0.5;
// f64 float64 = -1e8 + 0.5;
)
func
chki8
(
i
,
v
int8
)
{
if
i
!=
v
{
panicln
(
i
,
"!="
,
v
)
}
}
func
chki16
(
i
,
v
int16
)
{
if
i
!=
v
{
panicln
(
i
,
"!="
,
v
)
}
}
func
chki32
(
i
,
v
int32
)
{
if
i
!=
v
{
panicln
(
i
,
"!="
,
v
)
}
}
func
chki64
(
i
,
v
int64
)
{
if
i
!=
v
{
panicln
(
i
,
"!="
,
v
)
}
}
func
chku8
(
i
,
v
uint8
)
{
if
i
!=
v
{
panicln
(
i
,
"!="
,
v
)
}
}
func
chku16
(
i
,
v
uint16
)
{
if
i
!=
v
{
panicln
(
i
,
"!="
,
v
)
}
}
func
chku32
(
i
,
v
uint32
)
{
if
i
!=
v
{
panicln
(
i
,
"!="
,
v
)
}
}
func
chku64
(
i
,
v
uint64
)
{
if
i
!=
v
{
panicln
(
i
,
"!="
,
v
)
}
}
//func chkf32(f, v float32) { if f != v { panicln(f, "!=", v) } }
//func chkf64(f, v float64) { if f != v { panicln(f, "!=", v) } }
func
main
()
{
chki8
(
int8
(
i8
),
ci8
&
0xff
-
1
<<
8
);
chki8
(
int8
(
i16
),
ci16
&
0xff
);
chki8
(
int8
(
i32
),
ci32
&
0xff
-
1
<<
8
);
chki8
(
int8
(
i64
),
ci64
&
0xff
);
chki8
(
int8
(
u8
),
cu8
&
0xff
-
1
<<
8
);
chki8
(
int8
(
u16
),
cu16
&
0xff
);
chki8
(
int8
(
u32
),
cu32
&
0xff
);
chki8
(
int8
(
u64
),
cu64
&
0xff
);
// chki8(int8(f32), 0);
// chki8(int8(f64), 0);
chki16
(
int16
(
i8
),
ci8
&
0xffff
-
1
<<
16
);
chki16
(
int16
(
i16
),
ci16
&
0xffff
-
1
<<
16
);
chki16
(
int16
(
i32
),
ci32
&
0xffff
-
1
<<
16
);
chki16
(
int16
(
i64
),
ci64
&
0xffff
-
1
<<
16
);
chki16
(
int16
(
u8
),
cu8
&
0xffff
);
chki16
(
int16
(
u16
),
cu16
&
0xffff
-
1
<<
16
);
chki16
(
int16
(
u32
),
cu32
&
0xffff
);
chki16
(
int16
(
u64
),
cu64
&
0xffff
-
1
<<
16
);
// chki16(int16(f32), 0);
// chki16(int16(f64), 0);
chki32
(
int32
(
i8
),
ci8
&
0xffffffff
-
1
<<
32
);
chki32
(
int32
(
i16
),
ci16
&
0xffffffff
-
1
<<
32
);
chki32
(
int32
(
i32
),
ci32
&
0xffffffff
-
1
<<
32
);
chki32
(
int32
(
i64
),
ci64
&
0xffffffff
);
chki32
(
int32
(
u8
),
cu8
&
0xffffffff
);
chki32
(
int32
(
u16
),
cu16
&
0xffffffff
);
chki32
(
int32
(
u32
),
cu32
&
0xffffffff
-
1
<<
32
);
chki32
(
int32
(
u64
),
cu64
&
0xffffffff
-
1
<<
32
);
// chki32(int32(f32), 0);
// chki32(int32(f64), 0);
chki64
(
int64
(
i8
),
ci8
&
0xffffffffffffffff
-
1
<<
64
);
chki64
(
int64
(
i16
),
ci16
&
0xffffffffffffffff
-
1
<<
64
);
chki64
(
int64
(
i32
),
ci32
&
0xffffffffffffffff
-
1
<<
64
);
chki64
(
int64
(
i64
),
ci64
&
0xffffffffffffffff
-
1
<<
64
);
chki64
(
int64
(
u8
),
cu8
&
0xffffffffffffffff
);
chki64
(
int64
(
u16
),
cu16
&
0xffffffffffffffff
);
chki64
(
int64
(
u32
),
cu32
&
0xffffffffffffffff
);
chki64
(
int64
(
u64
),
cu64
&
0xffffffffffffffff
-
1
<<
64
);
// chki64(int64(f32), 0);
// chki64(int64(f64), 0);
chku8
(
uint8
(
i8
),
ci8
&
0xff
);
chku8
(
uint8
(
i16
),
ci16
&
0xff
);
chku8
(
uint8
(
i32
),
ci32
&
0xff
);
chku8
(
uint8
(
i64
),
ci64
&
0xff
);
chku8
(
uint8
(
u8
),
cu8
&
0xff
);
chku8
(
uint8
(
u16
),
cu16
&
0xff
);
chku8
(
uint8
(
u32
),
cu32
&
0xff
);
chku8
(
uint8
(
u64
),
cu64
&
0xff
);
// chku8(uint8(f32), 0);
// chku8(uint8(f64), 0);
chku16
(
uint16
(
i8
),
ci8
&
0xffff
);
chku16
(
uint16
(
i16
),
ci16
&
0xffff
);
chku16
(
uint16
(
i32
),
ci32
&
0xffff
);
chku16
(
uint16
(
i64
),
ci64
&
0xffff
);
chku16
(
uint16
(
u8
),
cu8
&
0xffff
);
chku16
(
uint16
(
u16
),
cu16
&
0xffff
);
chku16
(
uint16
(
u32
),
cu32
&
0xffff
);
chku16
(
uint16
(
u64
),
cu64
&
0xffff
);
// chku16(uint16(f32), 0);
// chku16(uint16(f64), 0);
chku32
(
uint32
(
i8
),
ci8
&
0xffffffff
);
chku32
(
uint32
(
i16
),
ci16
&
0xffffffff
);
chku32
(
uint32
(
i32
),
ci32
&
0xffffffff
);
chku32
(
uint32
(
i64
),
ci64
&
0xffffffff
);
chku32
(
uint32
(
u8
),
cu8
&
0xffffffff
);
chku32
(
uint32
(
u16
),
cu16
&
0xffffffff
);
chku32
(
uint32
(
u32
),
cu32
&
0xffffffff
);
chku32
(
uint32
(
u64
),
cu64
&
0xffffffff
);
// chku32(uint32(f32), 0);
// chku32(uint32(f64), 0);
chku64
(
uint64
(
i8
),
ci8
&
0xffffffffffffffff
);
chku64
(
uint64
(
i16
),
ci16
&
0xffffffffffffffff
);
chku64
(
uint64
(
i32
),
ci32
&
0xffffffffffffffff
);
chku64
(
uint64
(
i64
),
ci64
&
0xffffffffffffffff
);
chku64
(
uint64
(
u8
),
cu8
&
0xffffffffffffffff
);
chku64
(
uint64
(
u16
),
cu16
&
0xffffffffffffffff
);
chku64
(
uint64
(
u32
),
cu32
&
0xffffffffffffffff
);
chku64
(
uint64
(
u64
),
cu64
&
0xffffffffffffffff
);
// chku64(uint64(f32), 0);
// chku64(uint64(f64), 0);
}
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