diff options
author | Shenghou Ma <minux.ma@gmail.com> | 2013-05-30 03:03:52 +0800 |
---|---|---|
committer | Shenghou Ma <minux.ma@gmail.com> | 2013-05-30 03:03:52 +0800 |
commit | d3512712a469121491357de0be053966a66a4bcd (patch) | |
tree | b737d065232cb8d387716ffec36fd583a1bf999c /src | |
parent | f2cf612ba57b67f207b245e3195e129e36492406 (diff) | |
download | go-d3512712a469121491357de0be053966a66a4bcd.tar.gz |
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://codereview.appspot.com/9840043
Diffstat (limited to 'src')
-rw-r--r-- | src/cmd/5a/lex.c | 4 | ||||
-rw-r--r-- | src/cmd/dist/buildruntime.c | 2 | ||||
-rw-r--r-- | src/pkg/runtime/cgo/asm_arm.s | 4 | ||||
-rw-r--r-- | src/pkg/runtime/vlop_arm.s | 44 |
4 files changed, 26 insertions, 28 deletions
diff --git a/src/cmd/5a/lex.c b/src/cmd/5a/lex.c index a77e3050d..3ce1bfe95 100644 --- a/src/cmd/5a/lex.c +++ b/src/cmd/5a/lex.c @@ -191,8 +191,8 @@ struct "R6", LREG, 6, "R7", LREG, 7, "R8", LREG, 8, - "R9", LREG, 9, - "R10", LREG, 10, + "m", LREG, 9, // avoid unintentionally clobber m/g using R9/R10 + "g", LREG, 10, "R11", LREG, 11, "R12", LREG, 12, "R13", LREG, 13, diff --git a/src/cmd/dist/buildruntime.c b/src/cmd/dist/buildruntime.c index ee867566f..8f3fc5416 100644 --- a/src/cmd/dist/buildruntime.c +++ b/src/cmd/dist/buildruntime.c @@ -174,8 +174,6 @@ static struct { }, {"arm", "", - "#define g R10\n" - "#define m R9\n" "#define LR R14\n" }, }; diff --git a/src/pkg/runtime/cgo/asm_arm.s b/src/pkg/runtime/cgo/asm_arm.s index a6ea0dc07..e37c506c4 100644 --- a/src/pkg/runtime/cgo/asm_arm.s +++ b/src/pkg/runtime/cgo/asm_arm.s @@ -15,9 +15,9 @@ TEXT crosscall2(SB),7,$-4 * Additionally, cgo_tls_set_gm will clobber R0, so we need to save R0 * 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 BL (R0) MOVW PC, R14 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] diff --git a/src/pkg/runtime/vlop_arm.s b/src/pkg/runtime/vlop_arm.s index 0dedc316a..3a9cac944 100644 --- a/src/pkg/runtime/vlop_arm.s +++ b/src/pkg/runtime/vlop_arm.s @@ -70,7 +70,7 @@ TEXT _sfloat(SB), 7, $64 // 4 arg + 14*4 saved regs + cpsr q = 0 // input d, output q r = 1 // input n, output r s = 2 // three temporary variables -m = 3 +M = 3 a = 11 // 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; @@ -83,31 +83,31 @@ TEXT udiv<>(SB),7,$-4 begin: 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) // 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 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 - MUL.NE R(m), R(q), R(a) + MUL.NE R(M), R(q), R(a) MOVW.NE $0, R(s) MULAL.NE R(q), R(a), (R(q),R(s)) BEQ udiv_by_0_or_1 // 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 - ADD R(m), R(r), R(r) // r = n - d - MULA R(m), R(q), R(r), R(r) // r = n - (q+1)*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 // since 0 <= n-q*d < 3*d; thus -d <= r < 2*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 + CMN R(M), R(r) // t = r-d + SUB.CS R(M), R(r), R(r) // if (t<-d || t>=0) r=r+d ADD.CC $1, R(q) - ADD.PL R(m)<<1, R(r) + ADD.PL R(M)<<1, R(r) ADD.PL $2, R(q) // return, can't use RET here or fast_udiv_tab will be dropped during linking @@ -119,14 +119,14 @@ udiv_by_large_d: RSB $0, R(s), R(s) MOVW R(a)>>R(s), R(q) 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 - CMN R(r)>>1, R(m) // if(r/2 >= d) - ADD.CS R(m)<<1, R(r) + CMN R(r)>>1, R(M) // if(r/2 >= d) + ADD.CS R(M)<<1, R(r) ADD.CS $2, R(q) - CMN R(r), R(m) - ADD.CS R(m), R(r) + CMN R(r), R(M) + ADD.CS R(M), R(r) ADD.CS $1, R(q) // return, can't use RET here or fast_udiv_tab will be dropped during linking @@ -170,7 +170,7 @@ TEXT _divu(SB), 7, $16 MOVW R(q), 4(R13) MOVW R(r), 8(R13) MOVW R(s), 12(R13) - MOVW R(m), 16(R13) + MOVW R(M), 16(R13) MOVW R(TMP), R(r) /* numerator */ MOVW 0(FP), R(q) /* denominator */ @@ -179,14 +179,14 @@ TEXT _divu(SB), 7, $16 MOVW 4(R13), R(q) MOVW 8(R13), R(r) MOVW 12(R13), R(s) - MOVW 16(R13), R(m) + MOVW 16(R13), R(M) RET TEXT _modu(SB), 7, $16 MOVW R(q), 4(R13) MOVW R(r), 8(R13) MOVW R(s), 12(R13) - MOVW R(m), 16(R13) + MOVW R(M), 16(R13) MOVW R(TMP), R(r) /* numerator */ MOVW 0(FP), R(q) /* denominator */ @@ -195,14 +195,14 @@ TEXT _modu(SB), 7, $16 MOVW 4(R13), R(q) MOVW 8(R13), R(r) MOVW 12(R13), R(s) - MOVW 16(R13), R(m) + MOVW 16(R13), R(M) RET TEXT _div(SB),7,$16 MOVW R(q), 4(R13) MOVW R(r), 8(R13) MOVW R(s), 12(R13) - MOVW R(m), 16(R13) + MOVW R(M), 16(R13) MOVW R(TMP), R(r) /* numerator */ MOVW 0(FP), R(q) /* denominator */ CMP $0, R(r) @@ -228,7 +228,7 @@ TEXT _mod(SB),7,$16 MOVW R(q), 4(R13) MOVW R(r), 8(R13) MOVW R(s), 12(R13) - MOVW R(m), 16(R13) + MOVW R(M), 16(R13) MOVW R(TMP), R(r) /* numerator */ MOVW 0(FP), R(q) /* denominator */ CMP $0, R(q) @@ -246,5 +246,5 @@ out: MOVW 4(R13), R(q) MOVW 8(R13), R(r) MOVW 12(R13), R(s) - MOVW 16(R13), R(m) + MOVW 16(R13), R(M) RET |