Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/compile: reconsider zeroing thresholds for arm64 #10981

Closed
josharian opened this issue May 28, 2015 · 4 comments
Closed

cmd/compile: reconsider zeroing thresholds for arm64 #10981

josharian opened this issue May 28, 2015 · 4 comments

Comments

@josharian
Copy link
Contributor

This might be working as intended, but this doesn't smell right to me. Maybe we should use DUFFZERO or something similar here?

package p

func g() int {
    n := [100]int{}
    _ = n
    return 3
}

Assembles to:

"".g t=1 size=464 value=0 args=0x8 locals=0x328 leaf
    0x0000 00000 (/Users/jbleechersnyder/sg.go:9)   TEXT    "".g(SB), $808-8
    0x0000 00000 (/Users/jbleechersnyder/sg.go:9)   MOVD    16(g), R1
    0x0004 00004 (/Users/jbleechersnyder/sg.go:9)   SUB $816, RSP, R2
    0x0008 00008 (/Users/jbleechersnyder/sg.go:9)   CMP R1, R2
    0x000c 00012 (/Users/jbleechersnyder/sg.go:9)   BHI 32
    0x0010 00016 (/Users/jbleechersnyder/sg.go:9)   MOVD    R30, R3
    0x0014 00020 (/Users/jbleechersnyder/sg.go:9)   MOVD    $816, R27
    0x0018 00024 (/Users/jbleechersnyder/sg.go:9)   CALL    runtime.morestack_noctxt(SB)
    0x001c 00028 (/Users/jbleechersnyder/sg.go:9)   JMP 0
    0x0020 00032 (/Users/jbleechersnyder/sg.go:9)   NOP
    0x0020 00032 (/Users/jbleechersnyder/sg.go:9)   SUB $816, RSP
    0x0024 00036 (/Users/jbleechersnyder/sg.go:9)   FUNCDATA    ZR, gclocals·5184031d3a32a42d85027f073f873668(SB)
    0x0024 00036 (/Users/jbleechersnyder/sg.go:9)   FUNCDATA    $1, gclocals·33cdeccccebe80329f1fdbee7f5874cb(SB)
    0x0024 00036 (/Users/jbleechersnyder/sg.go:9)   MOVD    ZR, R0
    0x0028 00040 (/Users/jbleechersnyder/sg.go:10)  MOVD    $"".n-800(SP), R16
    0x002c 00044 (/Users/jbleechersnyder/sg.go:10)  MOVD    ZR, (R16)
    0x0030 00048 (/Users/jbleechersnyder/sg.go:10)  MOVD    ZR, 8(R16)
    0x0034 00052 (/Users/jbleechersnyder/sg.go:10)  MOVD    ZR, 16(R16)
    0x0038 00056 (/Users/jbleechersnyder/sg.go:10)  MOVD    ZR, 24(R16)
    0x003c 00060 (/Users/jbleechersnyder/sg.go:10)  MOVD    ZR, 32(R16)
    0x0040 00064 (/Users/jbleechersnyder/sg.go:10)  MOVD    ZR, 40(R16)
    0x0044 00068 (/Users/jbleechersnyder/sg.go:10)  MOVD    ZR, 48(R16)
    0x0048 00072 (/Users/jbleechersnyder/sg.go:10)  MOVD    ZR, 56(R16)
    0x004c 00076 (/Users/jbleechersnyder/sg.go:10)  MOVD    ZR, 64(R16)
    0x0050 00080 (/Users/jbleechersnyder/sg.go:10)  MOVD    ZR, 72(R16)
    0x0054 00084 (/Users/jbleechersnyder/sg.go:10)  MOVD    ZR, 80(R16)
    0x0058 00088 (/Users/jbleechersnyder/sg.go:10)  MOVD    ZR, 88(R16)
    0x005c 00092 (/Users/jbleechersnyder/sg.go:10)  MOVD    ZR, 96(R16)
    0x0060 00096 (/Users/jbleechersnyder/sg.go:10)  MOVD    ZR, 104(R16)
    0x0064 00100 (/Users/jbleechersnyder/sg.go:10)  MOVD    ZR, 112(R16)
    0x0068 00104 (/Users/jbleechersnyder/sg.go:10)  MOVD    ZR, 120(R16)
    0x006c 00108 (/Users/jbleechersnyder/sg.go:10)  MOVD    ZR, 128(R16)
    0x0070 00112 (/Users/jbleechersnyder/sg.go:10)  MOVD    ZR, 136(R16)
    0x0074 00116 (/Users/jbleechersnyder/sg.go:10)  MOVD    ZR, 144(R16)
    0x0078 00120 (/Users/jbleechersnyder/sg.go:10)  MOVD    ZR, 152(R16)
    0x007c 00124 (/Users/jbleechersnyder/sg.go:10)  MOVD    ZR, 160(R16)
    0x0080 00128 (/Users/jbleechersnyder/sg.go:10)  MOVD    ZR, 168(R16)
    0x0084 00132 (/Users/jbleechersnyder/sg.go:10)  MOVD    ZR, 176(R16)
    0x0088 00136 (/Users/jbleechersnyder/sg.go:10)  MOVD    ZR, 184(R16)
    0x008c 00140 (/Users/jbleechersnyder/sg.go:10)  MOVD    ZR, 192(R16)
    0x0090 00144 (/Users/jbleechersnyder/sg.go:10)  MOVD    ZR, 200(R16)
    0x0094 00148 (/Users/jbleechersnyder/sg.go:10)  MOVD    ZR, 208(R16)
    0x0098 00152 (/Users/jbleechersnyder/sg.go:10)  MOVD    ZR, 216(R16)
    0x009c 00156 (/Users/jbleechersnyder/sg.go:10)  MOVD    ZR, 224(R16)
    0x00a0 00160 (/Users/jbleechersnyder/sg.go:10)  MOVD    ZR, 232(R16)
    0x00a4 00164 (/Users/jbleechersnyder/sg.go:10)  MOVD    ZR, 240(R16)
    0x00a8 00168 (/Users/jbleechersnyder/sg.go:10)  MOVD    ZR, 248(R16)
    0x00ac 00172 (/Users/jbleechersnyder/sg.go:10)  MOVD    ZR, 256(R16)
    0x00b0 00176 (/Users/jbleechersnyder/sg.go:10)  MOVD    ZR, 264(R16)
    0x00b4 00180 (/Users/jbleechersnyder/sg.go:10)  MOVD    ZR, 272(R16)
    0x00b8 00184 (/Users/jbleechersnyder/sg.go:10)  MOVD    ZR, 280(R16)
    0x00bc 00188 (/Users/jbleechersnyder/sg.go:10)  MOVD    ZR, 288(R16)
    0x00c0 00192 (/Users/jbleechersnyder/sg.go:10)  MOVD    ZR, 296(R16)
    0x00c4 00196 (/Users/jbleechersnyder/sg.go:10)  MOVD    ZR, 304(R16)
    0x00c8 00200 (/Users/jbleechersnyder/sg.go:10)  MOVD    ZR, 312(R16)
    0x00cc 00204 (/Users/jbleechersnyder/sg.go:10)  MOVD    ZR, 320(R16)
    0x00d0 00208 (/Users/jbleechersnyder/sg.go:10)  MOVD    ZR, 328(R16)
    0x00d4 00212 (/Users/jbleechersnyder/sg.go:10)  MOVD    ZR, 336(R16)
    0x00d8 00216 (/Users/jbleechersnyder/sg.go:10)  MOVD    ZR, 344(R16)
    0x00dc 00220 (/Users/jbleechersnyder/sg.go:10)  MOVD    ZR, 352(R16)
    0x00e0 00224 (/Users/jbleechersnyder/sg.go:10)  MOVD    ZR, 360(R16)
    0x00e4 00228 (/Users/jbleechersnyder/sg.go:10)  MOVD    ZR, 368(R16)
    0x00e8 00232 (/Users/jbleechersnyder/sg.go:10)  MOVD    ZR, 376(R16)
    0x00ec 00236 (/Users/jbleechersnyder/sg.go:10)  MOVD    ZR, 384(R16)
    0x00f0 00240 (/Users/jbleechersnyder/sg.go:10)  MOVD    ZR, 392(R16)
    0x00f4 00244 (/Users/jbleechersnyder/sg.go:10)  MOVD    ZR, 400(R16)
    0x00f8 00248 (/Users/jbleechersnyder/sg.go:10)  MOVD    ZR, 408(R16)
    0x00fc 00252 (/Users/jbleechersnyder/sg.go:10)  MOVD    ZR, 416(R16)
    0x0100 00256 (/Users/jbleechersnyder/sg.go:10)  MOVD    ZR, 424(R16)
    0x0104 00260 (/Users/jbleechersnyder/sg.go:10)  MOVD    ZR, 432(R16)
    0x0108 00264 (/Users/jbleechersnyder/sg.go:10)  MOVD    ZR, 440(R16)
    0x010c 00268 (/Users/jbleechersnyder/sg.go:10)  MOVD    ZR, 448(R16)
    0x0110 00272 (/Users/jbleechersnyder/sg.go:10)  MOVD    ZR, 456(R16)
    0x0114 00276 (/Users/jbleechersnyder/sg.go:10)  MOVD    ZR, 464(R16)
    0x0118 00280 (/Users/jbleechersnyder/sg.go:10)  MOVD    ZR, 472(R16)
    0x011c 00284 (/Users/jbleechersnyder/sg.go:10)  MOVD    ZR, 480(R16)
    0x0120 00288 (/Users/jbleechersnyder/sg.go:10)  MOVD    ZR, 488(R16)
    0x0124 00292 (/Users/jbleechersnyder/sg.go:10)  MOVD    ZR, 496(R16)
    0x0128 00296 (/Users/jbleechersnyder/sg.go:10)  MOVD    ZR, 504(R16)
    0x012c 00300 (/Users/jbleechersnyder/sg.go:10)  MOVD    ZR, 512(R16)
    0x0130 00304 (/Users/jbleechersnyder/sg.go:10)  MOVD    ZR, 520(R16)
    0x0134 00308 (/Users/jbleechersnyder/sg.go:10)  MOVD    ZR, 528(R16)
    0x0138 00312 (/Users/jbleechersnyder/sg.go:10)  MOVD    ZR, 536(R16)
    0x013c 00316 (/Users/jbleechersnyder/sg.go:10)  MOVD    ZR, 544(R16)
    0x0140 00320 (/Users/jbleechersnyder/sg.go:10)  MOVD    ZR, 552(R16)
    0x0144 00324 (/Users/jbleechersnyder/sg.go:10)  MOVD    ZR, 560(R16)
    0x0148 00328 (/Users/jbleechersnyder/sg.go:10)  MOVD    ZR, 568(R16)
    0x014c 00332 (/Users/jbleechersnyder/sg.go:10)  MOVD    ZR, 576(R16)
    0x0150 00336 (/Users/jbleechersnyder/sg.go:10)  MOVD    ZR, 584(R16)
    0x0154 00340 (/Users/jbleechersnyder/sg.go:10)  MOVD    ZR, 592(R16)
    0x0158 00344 (/Users/jbleechersnyder/sg.go:10)  MOVD    ZR, 600(R16)
    0x015c 00348 (/Users/jbleechersnyder/sg.go:10)  MOVD    ZR, 608(R16)
    0x0160 00352 (/Users/jbleechersnyder/sg.go:10)  MOVD    ZR, 616(R16)
    0x0164 00356 (/Users/jbleechersnyder/sg.go:10)  MOVD    ZR, 624(R16)
    0x0168 00360 (/Users/jbleechersnyder/sg.go:10)  MOVD    ZR, 632(R16)
    0x016c 00364 (/Users/jbleechersnyder/sg.go:10)  MOVD    ZR, 640(R16)
    0x0170 00368 (/Users/jbleechersnyder/sg.go:10)  MOVD    ZR, 648(R16)
    0x0174 00372 (/Users/jbleechersnyder/sg.go:10)  MOVD    ZR, 656(R16)
    0x0178 00376 (/Users/jbleechersnyder/sg.go:10)  MOVD    ZR, 664(R16)
    0x017c 00380 (/Users/jbleechersnyder/sg.go:10)  MOVD    ZR, 672(R16)
    0x0180 00384 (/Users/jbleechersnyder/sg.go:10)  MOVD    ZR, 680(R16)
    0x0184 00388 (/Users/jbleechersnyder/sg.go:10)  MOVD    ZR, 688(R16)
    0x0188 00392 (/Users/jbleechersnyder/sg.go:10)  MOVD    ZR, 696(R16)
    0x018c 00396 (/Users/jbleechersnyder/sg.go:10)  MOVD    ZR, 704(R16)
    0x0190 00400 (/Users/jbleechersnyder/sg.go:10)  MOVD    ZR, 712(R16)
    0x0194 00404 (/Users/jbleechersnyder/sg.go:10)  MOVD    ZR, 720(R16)
    0x0198 00408 (/Users/jbleechersnyder/sg.go:10)  MOVD    ZR, 728(R16)
    0x019c 00412 (/Users/jbleechersnyder/sg.go:10)  MOVD    ZR, 736(R16)
    0x01a0 00416 (/Users/jbleechersnyder/sg.go:10)  MOVD    ZR, 744(R16)
    0x01a4 00420 (/Users/jbleechersnyder/sg.go:10)  MOVD    ZR, 752(R16)
    0x01a8 00424 (/Users/jbleechersnyder/sg.go:10)  MOVD    ZR, 760(R16)
    0x01ac 00428 (/Users/jbleechersnyder/sg.go:10)  MOVD    ZR, 768(R16)
    0x01b0 00432 (/Users/jbleechersnyder/sg.go:10)  MOVD    ZR, 776(R16)
    0x01b4 00436 (/Users/jbleechersnyder/sg.go:10)  MOVD    ZR, 784(R16)
    0x01b8 00440 (/Users/jbleechersnyder/sg.go:10)  MOVD    ZR, 792(R16)
    0x01bc 00444 (/Users/jbleechersnyder/sg.go:12)  MOVD    $3, R0
    0x01c0 00448 (/Users/jbleechersnyder/sg.go:12)  MOVD    R0, "".~r0(FP)
    0x01c4 00452 (/Users/jbleechersnyder/sg.go:12)  ADD $816, RSP
    0x01c8 00456 (/Users/jbleechersnyder/sg.go:12)  RET (R30)
    0x0000 81 0b 40 f9 e2 c3 0c d1 5f 00 01 eb a8 00 00 54  ..@....._......T
    0x0010 e3 03 1e aa 1b 66 80 d2 00 00 00 94 f9 ff ff 17  .....f..........
    0x0020 ff c3 0c d1 00 00 80 d2 f0 43 00 91 1f 02 00 f9  .........C......
    0x0030 1f 06 00 f9 1f 0a 00 f9 1f 0e 00 f9 1f 12 00 f9  ................
    0x0040 1f 16 00 f9 1f 1a 00 f9 1f 1e 00 f9 1f 22 00 f9  ............."..
    0x0050 1f 26 00 f9 1f 2a 00 f9 1f 2e 00 f9 1f 32 00 f9  .&...*.......2..
    0x0060 1f 36 00 f9 1f 3a 00 f9 1f 3e 00 f9 1f 42 00 f9  .6...:...>...B..
    0x0070 1f 46 00 f9 1f 4a 00 f9 1f 4e 00 f9 1f 52 00 f9  .F...J...N...R..
    0x0080 1f 56 00 f9 1f 5a 00 f9 1f 5e 00 f9 1f 62 00 f9  .V...Z...^...b..
    0x0090 1f 66 00 f9 1f 6a 00 f9 1f 6e 00 f9 1f 72 00 f9  .f...j...n...r..
    0x00a0 1f 76 00 f9 1f 7a 00 f9 1f 7e 00 f9 1f 82 00 f9  .v...z...~......
    0x00b0 1f 86 00 f9 1f 8a 00 f9 1f 8e 00 f9 1f 92 00 f9  ................
    0x00c0 1f 96 00 f9 1f 9a 00 f9 1f 9e 00 f9 1f a2 00 f9  ................
    0x00d0 1f a6 00 f9 1f aa 00 f9 1f ae 00 f9 1f b2 00 f9  ................
    0x00e0 1f b6 00 f9 1f ba 00 f9 1f be 00 f9 1f c2 00 f9  ................
    0x00f0 1f c6 00 f9 1f ca 00 f9 1f ce 00 f9 1f d2 00 f9  ................
    0x0100 1f d6 00 f9 1f da 00 f9 1f de 00 f9 1f e2 00 f9  ................
    0x0110 1f e6 00 f9 1f ea 00 f9 1f ee 00 f9 1f f2 00 f9  ................
    0x0120 1f f6 00 f9 1f fa 00 f9 1f fe 00 f9 1f 02 01 f9  ................
    0x0130 1f 06 01 f9 1f 0a 01 f9 1f 0e 01 f9 1f 12 01 f9  ................
    0x0140 1f 16 01 f9 1f 1a 01 f9 1f 1e 01 f9 1f 22 01 f9  ............."..
    0x0150 1f 26 01 f9 1f 2a 01 f9 1f 2e 01 f9 1f 32 01 f9  .&...*.......2..
    0x0160 1f 36 01 f9 1f 3a 01 f9 1f 3e 01 f9 1f 42 01 f9  .6...:...>...B..
    0x0170 1f 46 01 f9 1f 4a 01 f9 1f 4e 01 f9 1f 52 01 f9  .F...J...N...R..
    0x0180 1f 56 01 f9 1f 5a 01 f9 1f 5e 01 f9 1f 62 01 f9  .V...Z...^...b..
    0x0190 1f 66 01 f9 1f 6a 01 f9 1f 6e 01 f9 1f 72 01 f9  .f...j...n...r..
    0x01a0 1f 76 01 f9 1f 7a 01 f9 1f 7e 01 f9 1f 82 01 f9  .v...z...~......
    0x01b0 1f 86 01 f9 1f 8a 01 f9 1f 8e 01 f9 60 00 80 d2  ............`...
    0x01c0 e0 9f 01 f9 ff c3 0c 91 c0 03 5f d6 00 00 00 00  .........._.....
    rel 24+4 t=7 runtime.morestack_noctxt+2483027968
    rel 456+0 t=8 +0
@josharian josharian added this to the Go1.5Maybe milestone May 28, 2015
@minux
Copy link
Member

minux commented May 29, 2015

Are you compiling for darwin/arm64?

Due to ld64 bugs, duffzero is disabled on iOS.

I compiled the example for linux/arm64, and the code
uses duffzero as expected:
"".g t=1 size=80 value=0 args=0x8 locals=0x328
0x0000 00000 (issue10981.go:5) TEXT "".g(SB), $808-8
0x0000 00000 (issue10981.go:5) MOVD 16(g), R1
0x0004 00004 (issue10981.go:5) SUB $816, RSP, R2
0x0008 00008 (issue10981.go:5) CMP R1, R2
0x000c 00012 (issue10981.go:5) BHI 32
0x0010 00016 (issue10981.go:5) MOVD R30, R3
0x0014 00020 (issue10981.go:5) MOVD $816, R27
0x0018 00024 (issue10981.go:5) CALL runtime.morestack_noctxt(SB)
0x001c 00028 (issue10981.go:5) JMP 0
0x0020 00032 (issue10981.go:5) NOP
0x0020 00032 (issue10981.go:5) SUB $576, RSP
0x0024 00036 (issue10981.go:5) MOVD.W R30, -240(RSP)
0x0028 00040 (issue10981.go:5) FUNCDATA ZR,
gclocals·5184031d3a32a42d85027f073f873668(SB)
0x0028 00040 (issue10981.go:5) FUNCDATA $1,
gclocals·33cdeccccebe80329f1fdbee7f5874cb(SB)
0x0028 00040 (issue10981.go:5) MOVD ZR, R0
0x002c 00044 (issue10981.go:6) MOVD $"".n-800(SP), R16
0x0030 00048 (issue10981.go:6) SUB $8, R16
0x0034 00052 (issue10981.go:6) DUFFZERO runtime.duffzero(SB)
0x0038 00056 (issue10981.go:8) MOVD $3, R0
0x003c 00060 (issue10981.go:8) MOVD R0, "".~r0(FP)
0x0040 00064 (issue10981.go:8) MOVD.P 240(RSP), R30
0x0044 00068 (issue10981.go:8) ADD $576, RSP
0x0048 00072 (issue10981.go:8) RET (R30)

But I don't understand why it's not using a loop on darwin/arm64 though.

@josharian
Copy link
Contributor Author

Yes, darwin/arm64. A loop seems better.

@rsc
Copy link
Contributor

rsc commented Jun 29, 2015

Too late for Go 1.5, even for arm64.

@rsc rsc modified the milestones: Unplanned, Go1.5Maybe Jun 29, 2015
@josharian josharian modified the milestones: Go1.6, Unplanned Jun 29, 2015
@josharian josharian self-assigned this Jun 29, 2015
@rsc rsc modified the milestones: Unplanned, Go1.6 Nov 4, 2015
@ALTree
Copy link
Member

ALTree commented Jul 15, 2019

Still no DUFFZERO, but as 1.12 we generate a loop and not 100 MOVDs, so this is fixed. Closing.

@ALTree ALTree closed this as completed Jul 15, 2019
@golang golang locked and limited conversation to collaborators Jul 14, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants