compiler-explorer / compiler-explorer/compiler-explorer

[BUG]: tooltip documentation should change depending on the instruction's operands

Open
#5,961 0 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
TypeScript
Stars
19.1k
Forks
2.1k
Avg merge
3d 15h
Merged PRs (30d)
67

Description

### Describe the bug

The Arm documentation documents some instructions more than once, for example `ADD` is documented 11 times, depending on the type of add. Knowing the correct documentation to show in the tooltip would require parsing the instruction's arguments and extra code to figure out the right one. Currently the (autogenerated) [file](https://raw.githubusercontent.com/compiler-explorer/compiler-explorer/730437464d7900a1f232345db0bc196bfa1bbaeb/lib/asm-docs/generated/asm-docs-aarch64.ts) which is used to provide documentation tooltips for Arm assembly on Compiler Explorer has repeated entries for these instructions and it always just picks the first one, which is not always the correct documentation.

Here's the list of repeated instructions:

```sh
$ curl --silent 'https://raw.githubusercontent.com/compiler-explorer/compiler-explorer/730437464d7900a1f232345db0bc196bfa1bbaeb/lib/asm-docs/generated/asm-docs-aarch64.ts' | grep ' case "' | cut -f 2 -d '"' | sort | uniq --count --repeated | sort -h -r
32 MOV
12 UDOT
12 SDOT
11 ADD
10 SUB
10 MOVA
10 LDR
9 ST1W
9 ST1H
9 ST1D
9 ST1B
9 LD1W
9 LD1H
9 LD1D
9 LD1B
8 STR
8 ORR
8 FMOV
7 USDOT
7 UMIN
7 UMAX
7 STNT1W
7 STNT1H
7 STNT1D
7 STNT1B
7 SMIN
7 SMAX
7 LSR
7 LSL
7 LDNT1W
7 LDNT1H
7 LDNT1D
7 LDNT1B
7 FMUL
7 FMLS
7 FMLA
7 EOR
7 BIC
7 BFDOT
7 ASR
7 AND
6 UCVTF
6 SQDMULH
6 SCVTF
6 MUL
6 FSUB
6 FMINNM
6 FMIN
6 FMAXNM
6 FMAX
6 FCVTZU
6 FCVTZS
6 FADD
5 ZERO
5 UMLSL
5 UMLAL
5 SMLSL
5 SMLAL
5 MOVAZ
5 FMLSL
5 FMLAL
5 FDOT
5 DUP
5 BFMLS
5 BFMLA
4 URSHL
4 U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MEQ
2 CDOT
2 CCMP
2 CCMN
2 BSL
2 BICS
2 BFMOPS
2 BFMOPA
2 BFMMLA
2 BFMLSLT
2 BFMLSLB
2 BFCVTN
2 BFCLAMP
2 BCAX
2 AESMC
2 AESIMC
2 AESE
2 AESD
2 ADR
```

It seems to just pick the first one for the tooltip on the website.

Also, those "`CMP`" and "`FRINT`" instructions could be removed. The predicates are listed out already - `FRINTA FRINTI FRINTM FRINTN FRINTP FRINTX FRINTZ`.

Also it's `"url": "https://developer.arm.com/documentation/ddi0602/latest/Base-Instructions/"` for all the instructions. It should link to the correct thing like https://developer.arm.com/documentation/ddi0596/2021-12/SVE-Instructions/CMP-cc---immediate---Compare-vector-to-immediate-

### Steps to reproduce

1. Visit https://godbolt.org/#g:!((g:!((g:!((h:codeEditor,i:(filename:'1',fontScale:14,fontUsePx:'0',j:1,lang:___c,selection:(endColumn:5,endLineNumber:1,positionColumn:5,positionLineNumber:1,selectionStartColumn:5,selectionStartLineNumber:1,startColumn:5,startLineNumber:1),source:'long+dbl(long+num)+%7B%0A++++return+num+%2B+num%3B%0A%7D'),l:'5',n:'0',o:'C+source+%231',t:'0')),k:44.211430593045975,l:'4',n:'0',o:'',s:0,t:'0'),(g:!((h:compiler,i:(compiler:armv8-cclang1701,filters:(b:'0',binary:'1',binaryObject:'1',commentOnly:'0',debugCalls:'1',demangle:'0',directives:'0',execute:'1',intel:'0',libraryCode:'0',trim:'1'),flagsViewOpen:'1',fontScale:14,fontUsePx:'0',j:2,lang:___c,libs:!(),options:'',overrides:!(),selection:(endColumn:1,endLineNumber:1,positionColumn:1,positionLineNumber:1,selectionStartColumn:1,selectionStartLineNumber:1,startColumn:1,startLineNumber:1),source:1),l:'5',n:'0',o:'+armv8-a+clang+17.0.1+(Editor+%231)',t:'0')),k:55.78856940695404,l:'4',n:'0',o:'',s:0,t:'0')),l:'2',n:'0',o:'',t:'0')),version:4
2. mouse over "`add`" instruction

### Expected behavior

It should display the correct documentation for that specific type of the 11 different documentation options for the ADD instruction.

Instead, it always displays the first one in the file "Add (extended register) adds a register value and a sign or zero-extended register value, followed by an optional left shift amount, and writes the result to the destination register. The argument that is extended from the register can be a byte, halfword, word, or doubleword."

### Reproduction link

https://godbolt.org/#g:!((g:!((g:!((h:codeEditor,i:(filename:'1',fontScale:14,fontUsePx:'0',j:1,lang:___c,selection:(endColumn:5,endLineNumber:1,positionColumn:5,positionLineNumber:1,selectionStartColumn:5,selectionStartLineNumber:1,startColumn:5,startLineNumber:1),source:'long+dbl(long+num)+%7B%0A++++return+num+%2B+num%3B%0A%7D'),l:'5',n:'0',o:'C+source+%231',t:'0')),k:44.211430593045975,l:'4',n:'0',o:'',s:0,t:'0'),(g:!((h:compiler,i:(compiler:armv8-cclang1701,filters:(b:'0',binary:'1',binaryObject:'1',commentOnly:'0',debugCalls:'1',demangle:'0',directives:'0',execute:'1',intel:'0',libraryCode:'0',trim:'1'),flagsViewOpen:'1',fontScale:14,fontUsePx:'0',j:2,lang:___c,libs:!(),options:'',overrides:!(),selection:(endColumn:1,endLineNumber:1,positionColumn:1,positionLineNumber:1,selectionStartColumn:1,selectionStartLineNumber:1,startColumn:1,startLineNumber:1),source:1),l:'5',n:'0',o:'+armv8-a+clang+17.0.1+(Editor+%231)',t:'0')),k:55.78856940695404,l:'4',n:'0',o:'',s:0,t:'0')),l:'2',n:'0',o:'',t:'0')),version:4

### Screenshots

Screenshot 2024-01-09 at 00 15 19

Screenshot 2024-01-09 at 00 19 50

### Operating System

_No response_

### Browser version

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.