Commit 5d081792 authored by Shenghou Ma's avatar Shenghou Ma

cmd/5a, cmd/dist, runtime: support m/g in the assembler, drop support for R9/R10

to avoid unintentionally clobber R9/R10.
Thanks Lucio for the suggestion.

PS: yes, this could be considered a big change (but not an API change), but
as it turns out even temporarily changes R9/R10 in user code is unsafe and
leads to very hard to diagnose problems later, better to disable using R9/R10
when the user first uses it.
See CL 6300043 and CL 6305100 for two problems caused by misusing R9/R10.

R=golang-dev, khr, rsc
CC=golang-dev
https://golang.org/cl/9840043
parent a307c5c9
...@@ -8,5 +8,7 @@ Please keep the descriptions to a single line, starting with the ...@@ -8,5 +8,7 @@ Please keep the descriptions to a single line, starting with the
package or cmd/xxx directory name, and ending in a CL number. package or cmd/xxx directory name, and ending in a CL number.
Please keep the list sorted (as in sort.Strings of the lines). Please keep the list sorted (as in sort.Strings of the lines).
cmd/5a: removed support for R9/R10 (use m/g instead) (CL 9840043).
fmt: indexed access to arguments in Printf etc. (CL 9680043). fmt: indexed access to arguments in Printf etc. (CL 9680043).
io: Copy prioritizes WriterTo over ReaderFrom (CL 9462044). io: Copy prioritizes WriterTo over ReaderFrom (CL 9462044).
...@@ -191,8 +191,8 @@ struct ...@@ -191,8 +191,8 @@ struct
"R6", LREG, 6, "R6", LREG, 6,
"R7", LREG, 7, "R7", LREG, 7,
"R8", LREG, 8, "R8", LREG, 8,
"R9", LREG, 9, "m", LREG, 9, // avoid unintentionally clobber m/g using R9/R10
"R10", LREG, 10, "g", LREG, 10,
"R11", LREG, 11, "R11", LREG, 11,
"R12", LREG, 12, "R12", LREG, 12,
"R13", LREG, 13, "R13", LREG, 13,
......
...@@ -174,8 +174,6 @@ static struct { ...@@ -174,8 +174,6 @@ static struct {
}, },
{"arm", "", {"arm", "",
"#define g R10\n"
"#define m R9\n"
"#define LR R14\n" "#define LR R14\n"
}, },
}; };
......
...@@ -15,9 +15,9 @@ TEXT crosscall2(SB),7,$-4 ...@@ -15,9 +15,9 @@ TEXT crosscall2(SB),7,$-4
* Additionally, cgo_tls_set_gm will clobber R0, so we need to save R0 * Additionally, cgo_tls_set_gm will clobber R0, so we need to save R0
* nevertheless. * nevertheless.
*/ */
MOVM.WP [R0, R1, R2, R4, R5, R6, R7, R8, R9, R10, R11, R12, R14], (R13) MOVM.WP [R0, R1, R2, R4, R5, R6, R7, R8, m, g, R11, R12, R14], (R13)
MOVW _cgo_load_gm(SB), R0 MOVW _cgo_load_gm(SB), R0
BL (R0) BL (R0)
MOVW PC, R14 MOVW PC, R14
MOVW 0(R13), PC MOVW 0(R13), PC
MOVM.IAW (R13), [R0, R1, R2, R4, R5, R6, R7, R8, R9, R10, R11, R12, PC] MOVM.IAW (R13), [R0, R1, R2, R4, R5, R6, R7, R8, m, g, R11, R12, PC]
...@@ -70,7 +70,7 @@ TEXT _sfloat(SB), 7, $64 // 4 arg + 14*4 saved regs + cpsr ...@@ -70,7 +70,7 @@ TEXT _sfloat(SB), 7, $64 // 4 arg + 14*4 saved regs + cpsr
q = 0 // input d, output q q = 0 // input d, output q
r = 1 // input n, output r r = 1 // input n, output r
s = 2 // three temporary variables s = 2 // three temporary variables
m = 3 M = 3
a = 11 a = 11
// Please be careful when changing this, it is pretty fragile: // Please be careful when changing this, it is pretty fragile:
// 1, don't use unconditional branch as the linker is free to reorder the blocks; // 1, don't use unconditional branch as the linker is free to reorder the blocks;
...@@ -83,31 +83,31 @@ TEXT udiv<>(SB),7,$-4 ...@@ -83,31 +83,31 @@ TEXT udiv<>(SB),7,$-4
begin: begin:
SUB.S $7, R(s) SUB.S $7, R(s)
RSB $0, R(q), R(m) // m = -q RSB $0, R(q), R(M) // M = -q
MOVW.PL R(a)<<R(s), R(q) MOVW.PL R(a)<<R(s), R(q)
// 1st Newton iteration // 1st Newton iteration
MUL.PL R(m), R(q), R(a) // a = -q*d MUL.PL R(M), R(q), R(a) // a = -q*d
BMI udiv_by_large_d BMI udiv_by_large_d
MULAWT R(a), R(q), R(q), R(q) // q approx q-(q*q*d>>32) MULAWT R(a), R(q), R(q), R(q) // q approx q-(q*q*d>>32)
TEQ R(m)->1, R(m) // check for d=0 or d=1 TEQ R(M)->1, R(M) // check for d=0 or d=1
// 2nd Newton iteration // 2nd Newton iteration
MUL.NE R(m), R(q), R(a) MUL.NE R(M), R(q), R(a)
MOVW.NE $0, R(s) MOVW.NE $0, R(s)
MULAL.NE R(q), R(a), (R(q),R(s)) MULAL.NE R(q), R(a), (R(q),R(s))
BEQ udiv_by_0_or_1 BEQ udiv_by_0_or_1
// q now accurate enough for a remainder r, 0<=r<3*d // q now accurate enough for a remainder r, 0<=r<3*d
MULLU R(q), R(r), (R(q),R(s)) // q = (r * q) >> 32 MULLU R(q), R(r), (R(q),R(s)) // q = (r * q) >> 32
ADD R(m), R(r), R(r) // r = n - d ADD R(M), R(r), R(r) // r = n - d
MULA R(m), R(q), R(r), R(r) // r = n - (q+1)*d MULA R(M), R(q), R(r), R(r) // r = n - (q+1)*d
// since 0 <= n-q*d < 3*d; thus -d <= r < 2*d // since 0 <= n-q*d < 3*d; thus -d <= r < 2*d
CMN R(m), R(r) // t = r-d CMN R(M), R(r) // t = r-d
SUB.CS R(m), R(r), R(r) // if (t<-d || t>=0) r=r+d SUB.CS R(M), R(r), R(r) // if (t<-d || t>=0) r=r+d
ADD.CC $1, R(q) ADD.CC $1, R(q)
ADD.PL R(m)<<1, R(r) ADD.PL R(M)<<1, R(r)
ADD.PL $2, R(q) ADD.PL $2, R(q)
// return, can't use RET here or fast_udiv_tab will be dropped during linking // return, can't use RET here or fast_udiv_tab will be dropped during linking
...@@ -119,14 +119,14 @@ udiv_by_large_d: ...@@ -119,14 +119,14 @@ udiv_by_large_d:
RSB $0, R(s), R(s) RSB $0, R(s), R(s)
MOVW R(a)>>R(s), R(q) MOVW R(a)>>R(s), R(q)
MULLU R(q), R(r), (R(q),R(s)) MULLU R(q), R(r), (R(q),R(s))
MULA R(m), R(q), R(r), R(r) MULA R(M), R(q), R(r), R(r)
// q now accurate enough for a remainder r, 0<=r<4*d // q now accurate enough for a remainder r, 0<=r<4*d
CMN R(r)>>1, R(m) // if(r/2 >= d) CMN R(r)>>1, R(M) // if(r/2 >= d)
ADD.CS R(m)<<1, R(r) ADD.CS R(M)<<1, R(r)
ADD.CS $2, R(q) ADD.CS $2, R(q)
CMN R(r), R(m) CMN R(r), R(M)
ADD.CS R(m), R(r) ADD.CS R(M), R(r)
ADD.CS $1, R(q) ADD.CS $1, R(q)
// return, can't use RET here or fast_udiv_tab will be dropped during linking // return, can't use RET here or fast_udiv_tab will be dropped during linking
...@@ -170,7 +170,7 @@ TEXT _divu(SB), 7, $16 ...@@ -170,7 +170,7 @@ TEXT _divu(SB), 7, $16
MOVW R(q), 4(R13) MOVW R(q), 4(R13)
MOVW R(r), 8(R13) MOVW R(r), 8(R13)
MOVW R(s), 12(R13) MOVW R(s), 12(R13)
MOVW R(m), 16(R13) MOVW R(M), 16(R13)
MOVW R(TMP), R(r) /* numerator */ MOVW R(TMP), R(r) /* numerator */
MOVW 0(FP), R(q) /* denominator */ MOVW 0(FP), R(q) /* denominator */
...@@ -179,14 +179,14 @@ TEXT _divu(SB), 7, $16 ...@@ -179,14 +179,14 @@ TEXT _divu(SB), 7, $16
MOVW 4(R13), R(q) MOVW 4(R13), R(q)
MOVW 8(R13), R(r) MOVW 8(R13), R(r)
MOVW 12(R13), R(s) MOVW 12(R13), R(s)
MOVW 16(R13), R(m) MOVW 16(R13), R(M)
RET RET
TEXT _modu(SB), 7, $16 TEXT _modu(SB), 7, $16
MOVW R(q), 4(R13) MOVW R(q), 4(R13)
MOVW R(r), 8(R13) MOVW R(r), 8(R13)
MOVW R(s), 12(R13) MOVW R(s), 12(R13)
MOVW R(m), 16(R13) MOVW R(M), 16(R13)
MOVW R(TMP), R(r) /* numerator */ MOVW R(TMP), R(r) /* numerator */
MOVW 0(FP), R(q) /* denominator */ MOVW 0(FP), R(q) /* denominator */
...@@ -195,14 +195,14 @@ TEXT _modu(SB), 7, $16 ...@@ -195,14 +195,14 @@ TEXT _modu(SB), 7, $16
MOVW 4(R13), R(q) MOVW 4(R13), R(q)
MOVW 8(R13), R(r) MOVW 8(R13), R(r)
MOVW 12(R13), R(s) MOVW 12(R13), R(s)
MOVW 16(R13), R(m) MOVW 16(R13), R(M)
RET RET
TEXT _div(SB),7,$16 TEXT _div(SB),7,$16
MOVW R(q), 4(R13) MOVW R(q), 4(R13)
MOVW R(r), 8(R13) MOVW R(r), 8(R13)
MOVW R(s), 12(R13) MOVW R(s), 12(R13)
MOVW R(m), 16(R13) MOVW R(M), 16(R13)
MOVW R(TMP), R(r) /* numerator */ MOVW R(TMP), R(r) /* numerator */
MOVW 0(FP), R(q) /* denominator */ MOVW 0(FP), R(q) /* denominator */
CMP $0, R(r) CMP $0, R(r)
...@@ -228,7 +228,7 @@ TEXT _mod(SB),7,$16 ...@@ -228,7 +228,7 @@ TEXT _mod(SB),7,$16
MOVW R(q), 4(R13) MOVW R(q), 4(R13)
MOVW R(r), 8(R13) MOVW R(r), 8(R13)
MOVW R(s), 12(R13) MOVW R(s), 12(R13)
MOVW R(m), 16(R13) MOVW R(M), 16(R13)
MOVW R(TMP), R(r) /* numerator */ MOVW R(TMP), R(r) /* numerator */
MOVW 0(FP), R(q) /* denominator */ MOVW 0(FP), R(q) /* denominator */
CMP $0, R(q) CMP $0, R(q)
...@@ -246,5 +246,5 @@ out: ...@@ -246,5 +246,5 @@ out:
MOVW 4(R13), R(q) MOVW 4(R13), R(q)
MOVW 8(R13), R(r) MOVW 8(R13), R(r)
MOVW 12(R13), R(s) MOVW 12(R13), R(s)
MOVW 16(R13), R(m) MOVW 16(R13), R(M)
RET RET
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment