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
fc010adc
Commit
fc010adc
authored
Feb 19, 2010
by
Ken Thompson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
complex constant multiply and divide
R=rsc CC=golang-dev
https://golang.org/cl/217041
parent
d17ffb97
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
92 additions
and
10 deletions
+92
-10
builtin.c.boot
src/cmd/gc/builtin.c.boot
+1
-0
const.c
src/cmd/gc/const.c
+78
-6
runtime.go
src/cmd/gc/runtime.go
+1
-0
typecheck.c
src/cmd/gc/typecheck.c
+4
-0
walk.c
src/cmd/gc/walk.c
+8
-4
No files found.
src/cmd/gc/builtin.c.boot
View file @
fc010adc
...
...
@@ -9,6 +9,7 @@ char *runtimeimport =
"func \"\".printfloat (? float64)\n"
"func \"\".printint (? int64)\n"
"func \"\".printuint (? uint64)\n"
"func \"\".printcomplex (? complex128)\n"
"func \"\".printstring (? string)\n"
"func \"\".printpointer (? any)\n"
"func \"\".printiface (? any)\n"
...
...
src/cmd/gc/const.c
View file @
fc010adc
...
...
@@ -5,10 +5,12 @@
#include "go.h"
#define TUP(x,y) (((x)<<16)|(y))
static
Val
tocplx
(
Val
);
static
Val
toflt
(
Val
);
static
Val
tostr
(
Val
);
static
Val
copyval
(
Val
);
static
Val
tocplx
(
Val
);
static
Val
toflt
(
Val
);
static
Val
tostr
(
Val
);
static
Val
copyval
(
Val
);
static
void
cmplxmpy
(
Mpcplx
*
v
,
Mpcplx
*
rv
);
static
void
cmplxdiv
(
Mpcplx
*
v
,
Mpcplx
*
rv
);
/*
* truncate float literal fv to 32-bit or 64-bit precision
...
...
@@ -614,9 +616,10 @@ evconst(Node *n)
mpsubfltflt
(
&
v
.
u
.
cval
->
imag
,
&
rv
.
u
.
cval
->
imag
);
break
;
case
TUP
(
OMUL
,
CTCPLX
):
goto
illegal
;
// TODO
cmplxmpy
(
v
.
u
.
cval
,
rv
.
u
.
cval
);
break
;
case
TUP
(
ODIV
,
CTCPLX
):
goto
illegal
;
// TODO
cmplxdiv
(
v
.
u
.
cval
,
rv
.
u
.
cval
);
break
;
case
TUP
(
OEQ
,
CTNIL
):
...
...
@@ -793,6 +796,13 @@ unary:
mpnegflt
(
v
.
u
.
fval
);
break
;
case
TUP
(
OPLUS
,
CTCPLX
):
break
;
case
TUP
(
OMINUS
,
CTCPLX
):
mpnegflt
(
&
v
.
u
.
cval
->
real
);
mpnegflt
(
&
v
.
u
.
cval
->
imag
);
break
;
case
TUP
(
ONOT
,
CTBOOL
):
if
(
!
v
.
u
.
bval
)
goto
settrue
;
...
...
@@ -1187,3 +1197,65 @@ convconst(Node *con, Type *t, Val *val)
fatal
(
"convconst %lT constant"
,
t
);
}
// complex multiply v *= rv
// (a, b) * (c, d) = (a*c - b*d, b*c + a*d)
static
void
cmplxmpy
(
Mpcplx
*
v
,
Mpcplx
*
rv
)
{
Mpflt
ac
,
bd
,
bc
,
ad
;
mpmovefltflt
(
&
ac
,
&
v
->
real
);
mpmulfltflt
(
&
ac
,
&
rv
->
real
);
// ac
mpmovefltflt
(
&
bd
,
&
v
->
imag
);
mpmulfltflt
(
&
bd
,
&
rv
->
imag
);
// bd
mpmovefltflt
(
&
bc
,
&
v
->
imag
);
mpmulfltflt
(
&
bc
,
&
rv
->
real
);
// bc
mpmovefltflt
(
&
ad
,
&
v
->
real
);
mpmulfltflt
(
&
ad
,
&
rv
->
imag
);
// ad
mpmovefltflt
(
&
v
->
real
,
&
ac
);
mpsubfltflt
(
&
v
->
real
,
&
bd
);
// ac-bd
mpmovefltflt
(
&
v
->
imag
,
&
bc
);
mpaddfltflt
(
&
v
->
imag
,
&
ad
);
// bc+ad
}
// complex divide v /= rv
// (a, b) / (c, d) = ((a*c + b*d), (b*c - a*d))/(c*c + d*d)
static
void
cmplxdiv
(
Mpcplx
*
v
,
Mpcplx
*
rv
)
{
Mpflt
ac
,
bd
,
bc
,
ad
,
cc_plus_dd
;
mpmovefltflt
(
&
cc_plus_dd
,
&
rv
->
real
);
mpmulfltflt
(
&
cc_plus_dd
,
&
rv
->
real
);
// cc
mpmovefltflt
(
&
ac
,
&
rv
->
imag
);
mpmulfltflt
(
&
ac
,
&
rv
->
imag
);
// dd
mpaddfltflt
(
&
cc_plus_dd
,
&
ac
);
// cc+dd
mpmovefltflt
(
&
ac
,
&
v
->
real
);
mpmulfltflt
(
&
ac
,
&
rv
->
real
);
// ac
mpmovefltflt
(
&
bd
,
&
v
->
imag
);
mpmulfltflt
(
&
bd
,
&
rv
->
imag
);
// bd
mpmovefltflt
(
&
bc
,
&
v
->
imag
);
mpmulfltflt
(
&
bc
,
&
rv
->
real
);
// bc
mpmovefltflt
(
&
ad
,
&
v
->
real
);
mpmulfltflt
(
&
ad
,
&
rv
->
imag
);
// ad
mpmovefltflt
(
&
v
->
real
,
&
ac
);
mpaddfltflt
(
&
v
->
real
,
&
bd
);
// ac+bd
mpdivfltflt
(
&
v
->
real
,
&
cc_plus_dd
);
// (ac+bd)/(cc+dd)
mpmovefltflt
(
&
v
->
imag
,
&
bc
);
mpsubfltflt
(
&
v
->
imag
,
&
ad
);
// bc-ad
mpdivfltflt
(
&
v
->
imag
,
&
cc_plus_dd
);
// (bc+ad)/(cc+dd)
}
src/cmd/gc/runtime.go
View file @
fc010adc
...
...
@@ -20,6 +20,7 @@ func printbool(bool)
func
printfloat
(
float64
)
func
printint
(
int64
)
func
printuint
(
uint64
)
func
printcomplex
(
complex128
)
func
printstring
(
string
)
func
printpointer
(
any
)
func
printiface
(
any
)
...
...
src/cmd/gc/typecheck.c
View file @
fc010adc
...
...
@@ -1370,6 +1370,10 @@ checkconv(Type *nt, Type *t, int explicit, int *op, int *et, char *desc)
if
(
isint
[
nt
->
etype
]
||
isfloat
[
nt
->
etype
])
return
1
;
// between versions of complex
if
(
iscomplex
[
t
->
etype
]
||
iscomplex
[
nt
->
etype
])
return
1
;
// to string
if
(
istype
(
t
,
TSTRING
))
{
// integer rune
...
...
src/cmd/gc/walk.c
View file @
fc010adc
...
...
@@ -794,11 +794,13 @@ walkexpr(Node **np, NodeList **init)
case
OCONV
:
case
OCONVNOP
:
if
(
thechar
==
'5'
)
{
if
(
isfloat
[
n
->
left
->
type
->
etype
]
&&
(
n
->
type
->
etype
==
TINT64
||
n
->
type
->
etype
==
TUINT64
))
{
if
(
isfloat
[
n
->
left
->
type
->
etype
]
&&
(
n
->
type
->
etype
==
TINT64
||
n
->
type
->
etype
==
TUINT64
))
{
n
=
mkcall
(
"float64toint64"
,
n
->
type
,
init
,
conv
(
n
->
left
,
types
[
TFLOAT64
]));
goto
ret
;
}
if
((
n
->
left
->
type
->
etype
==
TINT64
||
n
->
left
->
type
->
etype
==
TUINT64
)
&&
isfloat
[
n
->
type
->
etype
])
{
if
((
n
->
left
->
type
->
etype
==
TINT64
||
n
->
left
->
type
->
etype
==
TUINT64
)
&&
isfloat
[
n
->
type
->
etype
])
{
n
=
mkcall
(
"int64tofloat64"
,
n
->
type
,
init
,
conv
(
n
->
left
,
types
[
TINT64
]));
goto
ret
;
}
...
...
@@ -1727,7 +1729,7 @@ walkprint(Node *nn, NodeList **init, int defer)
}
else
if
(
iscomplex
[
et
])
{
if
(
defer
)
{
fmtprint
(
&
fmt
,
"%%f"
);
t
=
types
[
T
FLOAT64
];
t
=
types
[
T
COMPLEX128
];
}
else
on
=
syslook
(
"printcomplex"
,
0
);
}
else
if
(
et
==
TBOOL
)
{
...
...
@@ -2036,8 +2038,10 @@ convas(Node *n, NodeList **init)
if
(
lt
==
T
||
rt
==
T
)
goto
out
;
if
(
isblank
(
n
->
left
))
if
(
isblank
(
n
->
left
))
{
defaultlit
(
&
n
->
right
,
T
);
goto
out
;
}
if
(
n
->
left
->
op
==
OINDEXMAP
)
{
n
=
mkcall1
(
mapfn
(
"mapassign1"
,
n
->
left
->
left
->
type
),
T
,
init
,
...
...
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