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
5bf57c1b
Commit
5bf57c1b
authored
Jun 02, 2011
by
Robert Griesemer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
big: remove some unnecessary conversions
R=rsc CC=golang-dev
https://golang.org/cl/4529110
parent
2a8ea0d1
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
60 additions
and
42 deletions
+60
-42
src/pkg/big/arith.go
src/pkg/big/arith.go
+2
-2
src/pkg/big/arith_386.s
src/pkg/big/arith_386.s
+4
-4
src/pkg/big/arith_amd64.s
src/pkg/big/arith_amd64.s
+6
-6
src/pkg/big/arith_arm.s
src/pkg/big/arith_arm.s
+9
-3
src/pkg/big/arith_decl.go
src/pkg/big/arith_decl.go
+2
-2
src/pkg/big/arith_test.go
src/pkg/big/arith_test.go
+15
-4
src/pkg/big/nat.go
src/pkg/big/nat.go
+22
-21
No files found.
src/pkg/big/arith.go
View file @
5bf57c1b
...
@@ -188,7 +188,7 @@ func subVW_g(z, x []Word, y Word) (c Word) {
...
@@ -188,7 +188,7 @@ func subVW_g(z, x []Word, y Word) (c Word) {
}
}
func
shlV
W_g
(
z
,
x
[]
Word
,
s
Word
)
(
c
Word
)
{
func
shlV
U_g
(
z
,
x
[]
Word
,
s
uint
)
(
c
Word
)
{
if
n
:=
len
(
z
);
n
>
0
{
if
n
:=
len
(
z
);
n
>
0
{
ŝ
:=
_W
-
s
ŝ
:=
_W
-
s
w1
:=
x
[
n
-
1
]
w1
:=
x
[
n
-
1
]
...
@@ -204,7 +204,7 @@ func shlVW_g(z, x []Word, s Word) (c Word) {
...
@@ -204,7 +204,7 @@ func shlVW_g(z, x []Word, s Word) (c Word) {
}
}
func
shrV
W_g
(
z
,
x
[]
Word
,
s
Word
)
(
c
Word
)
{
func
shrV
U_g
(
z
,
x
[]
Word
,
s
uint
)
(
c
Word
)
{
if
n
:=
len
(
z
);
n
>
0
{
if
n
:=
len
(
z
);
n
>
0
{
ŝ
:=
_W
-
s
ŝ
:=
_W
-
s
w1
:=
x
[
0
]
w1
:=
x
[
0
]
...
...
src/pkg/big/arith_386.s
View file @
5bf57c1b
...
@@ -118,8 +118,8 @@ E4: CMPL BX, BP // i < n
...
@@ -118,8 +118,8 @@ E4: CMPL BX, BP // i < n
RET
RET
//
func
shlV
W
(
z
,
x
[]
Word
,
s
Word
)
(
c
Word
)
//
func
shlV
U
(
z
,
x
[]
Word
,
s
uint
)
(
c
Word
)
TEXT
·
shlV
W
(
SB
),7,$0
TEXT
·
shlV
U
(
SB
),7,$0
MOVL
n
+
4
(
FP
),
BX
//
i
=
n
MOVL
n
+
4
(
FP
),
BX
//
i
=
n
SUBL
$
1
,
BX
//
i
--
SUBL
$
1
,
BX
//
i
--
JL
X8b
//
i
<
0
(
n
<=
0
)
JL
X8b
//
i
<
0
(
n
<=
0
)
...
@@ -153,8 +153,8 @@ X8b: MOVL $0, c+28(FP)
...
@@ -153,8 +153,8 @@ X8b: MOVL $0, c+28(FP)
RET
RET
//
func
shrV
W
(
z
,
x
[]
Word
,
s
Word
)
(
c
Word
)
//
func
shrV
U
(
z
,
x
[]
Word
,
s
uint
)
(
c
Word
)
TEXT
·
shrV
W
(
SB
),7,$0
TEXT
·
shrV
U
(
SB
),7,$0
MOVL
n
+
4
(
FP
),
BP
MOVL
n
+
4
(
FP
),
BP
SUBL
$
1
,
BP
//
n
--
SUBL
$
1
,
BP
//
n
--
JL
X9b
//
n
<
0
(
n
<=
0
)
JL
X9b
//
n
<
0
(
n
<=
0
)
...
...
src/pkg/big/arith_amd64.s
View file @
5bf57c1b
...
@@ -120,8 +120,8 @@ E4: CMPQ BX, R11 // i < n
...
@@ -120,8 +120,8 @@ E4: CMPQ BX, R11 // i < n
RET
RET
//
func
shlV
W
(
z
,
x
[]
Word
,
s
Word
)
(
c
Word
)
//
func
shlV
U
(
z
,
x
[]
Word
,
s
uint
)
(
c
Word
)
TEXT
·
shlV
W
(
SB
),7,$0
TEXT
·
shlV
U
(
SB
),7,$0
MOVL
n
+
8
(
FP
),
BX
//
i
=
n
MOVL
n
+
8
(
FP
),
BX
//
i
=
n
SUBL
$
1
,
BX
//
i
--
SUBL
$
1
,
BX
//
i
--
JL
X8b
//
i
<
0
(
n
<=
0
)
JL
X8b
//
i
<
0
(
n
<=
0
)
...
@@ -129,7 +129,7 @@ TEXT ·shlVW(SB),7,$0
...
@@ -129,7 +129,7 @@ TEXT ·shlVW(SB),7,$0
//
n
>
0
//
n
>
0
MOVQ
z
+
0
(
FP
),
R10
MOVQ
z
+
0
(
FP
),
R10
MOVQ
x
+
16
(
FP
),
R8
MOVQ
x
+
16
(
FP
),
R8
MOV
Q
s
+
32
(
FP
),
CX
MOV
L
s
+
32
(
FP
),
CX
MOVQ
(
R8
)(
BX
*
8
),
AX
//
w1
=
x
[
n
-
1
]
MOVQ
(
R8
)(
BX
*
8
),
AX
//
w1
=
x
[
n
-
1
]
MOVQ
$
0
,
DX
MOVQ
$
0
,
DX
SHLQ
CX
,
DX
:
AX
//
w1
>>
ŝ
SHLQ
CX
,
DX
:
AX
//
w1
>>
ŝ
...
@@ -155,8 +155,8 @@ X8b: MOVQ $0, c+40(FP)
...
@@ -155,8 +155,8 @@ X8b: MOVQ $0, c+40(FP)
RET
RET
//
func
shrV
W
(
z
,
x
[]
Word
,
s
Word
)
(
c
Word
)
//
func
shrV
U
(
z
,
x
[]
Word
,
s
uint
)
(
c
Word
)
TEXT
·
shrV
W
(
SB
),7,$0
TEXT
·
shrV
U
(
SB
),7,$0
MOVL
n
+
8
(
FP
),
R11
MOVL
n
+
8
(
FP
),
R11
SUBL
$
1
,
R11
//
n
--
SUBL
$
1
,
R11
//
n
--
JL
X9b
//
n
<
0
(
n
<=
0
)
JL
X9b
//
n
<
0
(
n
<=
0
)
...
@@ -164,7 +164,7 @@ TEXT ·shrVW(SB),7,$0
...
@@ -164,7 +164,7 @@ TEXT ·shrVW(SB),7,$0
//
n
>
0
//
n
>
0
MOVQ
z
+
0
(
FP
),
R10
MOVQ
z
+
0
(
FP
),
R10
MOVQ
x
+
16
(
FP
),
R8
MOVQ
x
+
16
(
FP
),
R8
MOV
Q
s
+
32
(
FP
),
CX
MOV
L
s
+
32
(
FP
),
CX
MOVQ
(
R8
),
AX
//
w1
=
x
[
0
]
MOVQ
(
R8
),
AX
//
w1
=
x
[
0
]
MOVQ
$
0
,
DX
MOVQ
$
0
,
DX
SHRQ
CX
,
DX
:
AX
//
w1
<<
ŝ
SHRQ
CX
,
DX
:
AX
//
w1
<<
ŝ
...
...
src/pkg/big/arith_arm.s
View file @
5bf57c1b
...
@@ -97,6 +97,7 @@ E3:
...
@@ -97,6 +97,7 @@ E3:
RET
RET
//
func
subVW
(
z
,
x
[]
Word
,
y
Word
)
(
c
Word
)
TEXT
·
subVW
(
SB
),7,$0
TEXT
·
subVW
(
SB
),7,$0
MOVW
z
+
0
(
FP
),
R1
MOVW
z
+
0
(
FP
),
R1
MOVW
x
+
12
(
FP
),
R2
MOVW
x
+
12
(
FP
),
R2
...
@@ -131,8 +132,8 @@ E4:
...
@@ -131,8 +132,8 @@ E4:
RET
RET
//
func
shlV
W
(
z
,
x
[]
Word
,
s
Word
)
(
c
Word
)
//
func
shlV
U
(
z
,
x
[]
Word
,
s
uint
)
(
c
Word
)
TEXT
·
shlV
W
(
SB
),7,$0
TEXT
·
shlV
U
(
SB
),7,$0
MOVW
n
+
4
(
FP
),
R5
MOVW
n
+
4
(
FP
),
R5
CMP
$
0
,
R5
CMP
$
0
,
R5
BEQ
X7
BEQ
X7
...
@@ -180,7 +181,8 @@ X7:
...
@@ -180,7 +181,8 @@ X7:
RET
RET
TEXT
·
shrVW
(
SB
),7,$0
//
func
shrVU
(
z
,
x
[]
Word
,
s
uint
)
(
c
Word
)
TEXT
·
shrVU
(
SB
),7,$0
MOVW
n
+
4
(
FP
),
R5
MOVW
n
+
4
(
FP
),
R5
CMP
$
0
,
R5
CMP
$
0
,
R5
BEQ
X6
BEQ
X6
...
@@ -229,6 +231,7 @@ X6:
...
@@ -229,6 +231,7 @@ X6:
RET
RET
//
func
mulAddVWW
(
z
,
x
[]
Word
,
y
,
r
Word
)
(
c
Word
)
TEXT
·
mulAddVWW
(
SB
),7,$0
TEXT
·
mulAddVWW
(
SB
),7,$0
MOVW
$
0
,
R0
MOVW
$
0
,
R0
MOVW
z
+
0
(
FP
),
R1
MOVW
z
+
0
(
FP
),
R1
...
@@ -256,6 +259,7 @@ E8:
...
@@ -256,6 +259,7 @@ E8:
RET
RET
//
func
addMulVVW
(
z
,
x
[]
Word
,
y
Word
)
(
c
Word
)
TEXT
·
addMulVVW
(
SB
),7,$0
TEXT
·
addMulVVW
(
SB
),7,$0
MOVW
$
0
,
R0
MOVW
$
0
,
R0
MOVW
z
+
0
(
FP
),
R1
MOVW
z
+
0
(
FP
),
R1
...
@@ -286,11 +290,13 @@ E9:
...
@@ -286,11 +290,13 @@ E9:
RET
RET
//
divWVW
(
z
*
Word
,
xn
Word
,
x
[]
Word
,
y
Word
)
(
r
Word
)
TEXT
·
divWVW
(
SB
),7,$0
TEXT
·
divWVW
(
SB
),7,$0
//
ARM
has
no
multiword
division
,
so
use
portable
code
.
//
ARM
has
no
multiword
division
,
so
use
portable
code
.
B
·
divWVW_g
(
SB
)
B
·
divWVW_g
(
SB
)
//
func
divWW
(
x1
,
x0
,
y
Word
)
(
q
,
r
Word
)
TEXT
·
divWW
(
SB
),7,$0
TEXT
·
divWW
(
SB
),7,$0
//
ARM
has
no
multiword
division
,
so
use
portable
code
.
//
ARM
has
no
multiword
division
,
so
use
portable
code
.
B
·
divWW_g
(
SB
)
B
·
divWW_g
(
SB
)
...
...
src/pkg/big/arith_decl.go
View file @
5bf57c1b
...
@@ -11,8 +11,8 @@ func addVV(z, x, y []Word) (c Word)
...
@@ -11,8 +11,8 @@ func addVV(z, x, y []Word) (c Word)
func
subVV
(
z
,
x
,
y
[]
Word
)
(
c
Word
)
func
subVV
(
z
,
x
,
y
[]
Word
)
(
c
Word
)
func
addVW
(
z
,
x
[]
Word
,
y
Word
)
(
c
Word
)
func
addVW
(
z
,
x
[]
Word
,
y
Word
)
(
c
Word
)
func
subVW
(
z
,
x
[]
Word
,
y
Word
)
(
c
Word
)
func
subVW
(
z
,
x
[]
Word
,
y
Word
)
(
c
Word
)
func
shlV
W
(
z
,
x
[]
Word
,
s
Word
)
(
c
Word
)
func
shlV
U
(
z
,
x
[]
Word
,
s
uint
)
(
c
Word
)
func
shrV
W
(
z
,
x
[]
Word
,
s
Word
)
(
c
Word
)
func
shrV
U
(
z
,
x
[]
Word
,
s
uint
)
(
c
Word
)
func
mulAddVWW
(
z
,
x
[]
Word
,
y
,
r
Word
)
(
c
Word
)
func
mulAddVWW
(
z
,
x
[]
Word
,
y
,
r
Word
)
(
c
Word
)
func
addMulVVW
(
z
,
x
[]
Word
,
y
Word
)
(
c
Word
)
func
addMulVVW
(
z
,
x
[]
Word
,
y
Word
)
(
c
Word
)
func
divWVW
(
z
[]
Word
,
xn
Word
,
x
[]
Word
,
y
Word
)
(
r
Word
)
func
divWVW
(
z
[]
Word
,
xn
Word
,
x
[]
Word
,
y
Word
)
(
r
Word
)
src/pkg/big/arith_test.go
View file @
5bf57c1b
...
@@ -185,6 +185,13 @@ func testFunVW(t *testing.T, msg string, f funVW, a argVW) {
...
@@ -185,6 +185,13 @@ func testFunVW(t *testing.T, msg string, f funVW, a argVW) {
}
}
func
makeFunVW
(
f
func
(
z
,
x
[]
Word
,
s
uint
)
(
c
Word
))
funVW
{
return
func
(
z
,
x
[]
Word
,
s
Word
)
(
c
Word
)
{
return
f
(
z
,
x
,
uint
(
s
))
}
}
func
TestFunVW
(
t
*
testing
.
T
)
{
func
TestFunVW
(
t
*
testing
.
T
)
{
for
_
,
a
:=
range
sumVW
{
for
_
,
a
:=
range
sumVW
{
arg
:=
a
arg
:=
a
...
@@ -196,16 +203,20 @@ func TestFunVW(t *testing.T) {
...
@@ -196,16 +203,20 @@ func TestFunVW(t *testing.T) {
testFunVW
(
t
,
"subVW"
,
subVW
,
arg
)
testFunVW
(
t
,
"subVW"
,
subVW
,
arg
)
}
}
shlVW_g
:=
makeFunVW
(
shlVU_g
)
shlVW
:=
makeFunVW
(
shlVU
)
for
_
,
a
:=
range
lshVW
{
for
_
,
a
:=
range
lshVW
{
arg
:=
a
arg
:=
a
testFunVW
(
t
,
"shlV
W
_g"
,
shlVW_g
,
arg
)
testFunVW
(
t
,
"shlV
U
_g"
,
shlVW_g
,
arg
)
testFunVW
(
t
,
"shlV
W
"
,
shlVW
,
arg
)
testFunVW
(
t
,
"shlV
U
"
,
shlVW
,
arg
)
}
}
shrVW_g
:=
makeFunVW
(
shrVU_g
)
shrVW
:=
makeFunVW
(
shrVU
)
for
_
,
a
:=
range
rshVW
{
for
_
,
a
:=
range
rshVW
{
arg
:=
a
arg
:=
a
testFunVW
(
t
,
"shrV
W
_g"
,
shrVW_g
,
arg
)
testFunVW
(
t
,
"shrV
U
_g"
,
shrVW_g
,
arg
)
testFunVW
(
t
,
"shrV
W
"
,
shrVW
,
arg
)
testFunVW
(
t
,
"shrV
U
"
,
shrVW
,
arg
)
}
}
}
}
...
...
src/pkg/big/nat.go
View file @
5bf57c1b
...
@@ -550,14 +550,14 @@ func (z nat) divLarge(u, uIn, v nat) (q, r nat) {
...
@@ -550,14 +550,14 @@ func (z nat) divLarge(u, uIn, v nat) (q, r nat) {
u
.
clear
()
u
.
clear
()
// D1.
// D1.
shift
:=
Word
(
leadingZeros
(
v
[
n
-
1
])
)
shift
:=
leadingZeros
(
v
[
n
-
1
]
)
if
shift
>
0
{
if
shift
>
0
{
// do not modify v, it may be used by another goroutine simultaneously
// do not modify v, it may be used by another goroutine simultaneously
v1
:=
make
(
nat
,
n
)
v1
:=
make
(
nat
,
n
)
shlV
W
(
v1
,
v
,
shift
)
shlV
U
(
v1
,
v
,
shift
)
v
=
v1
v
=
v1
}
}
u
[
len
(
uIn
)]
=
shlV
W
(
u
[
0
:
len
(
uIn
)],
uIn
,
shift
)
u
[
len
(
uIn
)]
=
shlV
U
(
u
[
0
:
len
(
uIn
)],
uIn
,
shift
)
// D2.
// D2.
for
j
:=
m
;
j
>=
0
;
j
--
{
for
j
:=
m
;
j
>=
0
;
j
--
{
...
@@ -596,7 +596,7 @@ func (z nat) divLarge(u, uIn, v nat) (q, r nat) {
...
@@ -596,7 +596,7 @@ func (z nat) divLarge(u, uIn, v nat) (q, r nat) {
}
}
q
=
q
.
norm
()
q
=
q
.
norm
()
shrV
W
(
u
,
u
,
shift
)
shrV
U
(
u
,
u
,
shift
)
r
=
u
.
norm
()
r
=
u
.
norm
()
return
q
,
r
return
q
,
r
...
@@ -824,7 +824,7 @@ func (z nat) shl(x nat, s uint) nat {
...
@@ -824,7 +824,7 @@ func (z nat) shl(x nat, s uint) nat {
n
:=
m
+
int
(
s
/
_W
)
n
:=
m
+
int
(
s
/
_W
)
z
=
z
.
make
(
n
+
1
)
z
=
z
.
make
(
n
+
1
)
z
[
n
]
=
shlV
W
(
z
[
n
-
m
:
n
],
x
,
Word
(
s
%
_W
)
)
z
[
n
]
=
shlV
U
(
z
[
n
-
m
:
n
],
x
,
s
%
_W
)
z
[
0
:
n
-
m
]
.
clear
()
z
[
0
:
n
-
m
]
.
clear
()
return
z
.
norm
()
return
z
.
norm
()
...
@@ -841,7 +841,7 @@ func (z nat) shr(x nat, s uint) nat {
...
@@ -841,7 +841,7 @@ func (z nat) shr(x nat, s uint) nat {
// n > 0
// n > 0
z
=
z
.
make
(
n
)
z
=
z
.
make
(
n
)
shrV
W
(
z
,
x
[
m
-
n
:
],
Word
(
s
%
_W
)
)
shrV
U
(
z
,
x
[
m
-
n
:
],
s
%
_W
)
return
z
.
norm
()
return
z
.
norm
()
}
}
...
@@ -972,25 +972,26 @@ func (x nat) modW(d Word) (r Word) {
...
@@ -972,25 +972,26 @@ func (x nat) modW(d Word) (r Word) {
}
}
// powersOfTwoDecompose finds q and k
such that q * 1<<k = n and q is odd
.
// powersOfTwoDecompose finds q and k
with x = q * 1<<k and q is odd, or q and k are 0
.
func
(
n
nat
)
powersOfTwoDecompose
()
(
q
nat
,
k
Word
)
{
func
(
x
nat
)
powersOfTwoDecompose
()
(
q
nat
,
k
int
)
{
if
len
(
n
)
==
0
{
if
len
(
x
)
==
0
{
return
n
,
0
return
x
,
0
}
}
zeroWords
:=
0
// One of the words must be non-zero by definition,
for
n
[
zeroWords
]
==
0
{
// so this loop will terminate with i < len(x), and
zeroWords
++
// i is the number of 0 words.
i
:=
0
for
x
[
i
]
==
0
{
i
++
}
}
// One of the words must be non-zero by invariant, therefore
n
:=
trailingZeroBits
(
x
[
i
])
// x[i] != 0
// zeroWords < len(n).
x
:=
trailingZeroBits
(
n
[
zeroWords
])
q
=
q
.
make
(
len
(
n
)
-
zeroWords
)
q
=
make
(
nat
,
len
(
x
)
-
i
)
shrVW
(
q
,
n
[
zeroWords
:
],
Word
(
x
))
shrVU
(
q
,
x
[
i
:
],
uint
(
n
))
q
=
q
.
norm
()
k
=
Word
(
_W
*
zeroWords
+
x
)
q
=
q
.
norm
()
k
=
i
*
_W
+
n
return
return
}
}
...
@@ -1161,7 +1162,7 @@ NextRandom:
...
@@ -1161,7 +1162,7 @@ NextRandom:
if
y
.
cmp
(
natOne
)
==
0
||
y
.
cmp
(
nm1
)
==
0
{
if
y
.
cmp
(
natOne
)
==
0
||
y
.
cmp
(
nm1
)
==
0
{
continue
continue
}
}
for
j
:=
Word
(
1
)
;
j
<
k
;
j
++
{
for
j
:=
1
;
j
<
k
;
j
++
{
y
=
y
.
mul
(
y
,
y
)
y
=
y
.
mul
(
y
,
y
)
quotient
,
y
=
quotient
.
div
(
y
,
y
,
n
)
quotient
,
y
=
quotient
.
div
(
y
,
y
,
n
)
if
y
.
cmp
(
nm1
)
==
0
{
if
y
.
cmp
(
nm1
)
==
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