Post ASSLK16MLAjpGhDrRQ by arrdem@macaw.social
(DIR) More posts by arrdem@macaw.social
(DIR) Post #ASSKtc8uVx6OKYpHe4 by mjg59@nondeterministic.computer
2023-02-08T02:44:05Z
0 likes, 0 repeats
Will CPUs typically take a speculative branch that points to an illegal instruction, or will they actually perform some analysis of what's going to happen beforehand?
(DIR) Post #ASSLK16MLAjpGhDrRQ by arrdem@macaw.social
2023-02-08T02:51:16Z
0 likes, 0 repeats
@mjg59 Extremely depends. Runahead branch predictors are a thing which can and does do this, and predicting cold branches is an entire art form. Usually optimization/prediction effort goes into ensuring that previously taken branches are correctly re-predicted, but there are speculative structures beyond static predictors for guessing at untaken branches. AFAIK most of them don't care about what's on the other side of the branch, the PC and any faults are observable effects that must happen
(DIR) Post #ASSLcGUZrD8ADKFfiC by chandlerc@hachyderm.io
2023-02-08T02:54:22Z
0 likes, 0 repeats
@mjg59 I believe some of the work on Spectre provides strong evidence that all modern x86 CPUs and high end ARM CPUs I'm aware of will speculate (at least) until they reach the illegal instruction in at least some cases.
(DIR) Post #ASSNTeckxwSGMN6DgW by johnlogic@mastodon.social
2023-02-08T03:15:24Z
0 likes, 0 repeats
@mjg59 I expect that type of analysis to be done by the compiler or optimizer, where it's much cheaper to add than into hardware.
(DIR) Post #ASSNfJxfcBmHkbRdA0 by shac@ioc.exchange
2023-02-08T03:17:31Z
0 likes, 0 repeats
@mjg59 There’s no way for it to know it’s illegal until it did a mapping lookup and then decoded it.
(DIR) Post #ASSNo65Ga35bJhBNWi by mjg59@nondeterministic.computer
2023-02-08T03:18:00Z
0 likes, 0 repeats
@johnlogic if you're doing a runtime check for whether an instruction is valid before executing it, no way for the compiler to know whether it's illegal or not!
(DIR) Post #ASSOMuD0ivWucdP2Ce by johnlogic@mastodon.social
2023-02-08T03:25:20Z
0 likes, 0 repeats
@mjg59 the compiler should be able to avoid generating illegal opcodes, jumps to nonsensical entry points, and memory access violations. (I don't expect the MMU to help with branch prediction, only throwing exceptions when violations occur.)
(DIR) Post #ASSTPlaliUtMXMhOiG by mjg59@nondeterministic.computer
2023-02-08T04:22:02Z
0 likes, 0 repeats
@johnlogic If I tell the compiler to target a machine that supports avx512, and then have a branch protection that looks at cpuid before taking that branch, and then run that binary on a machine that doesn't have avx512, there's a potential branch to an illegal instruction
(DIR) Post #ASSVdHo1SRUg7STN4q by johnlogic@mastodon.social
2023-02-08T04:46:17Z
0 likes, 0 repeats
@mjg59 yeah, that's a tough nut for branch prediction hardware.
(DIR) Post #ASSnlI1ML9YIHIg1z6 by ekg@social.librem.one
2023-02-08T08:09:54Z
0 likes, 0 repeats
@mjg59 @johnlogic my understanding is that most morden cups (at leat zen 3) can jump anywhere at anytime, so I wouldn't worry about it.
(DIR) Post #ASTBkOb4npkVHeURE0 by DocBohn@techhub.social
2023-02-08T12:38:14Z
0 likes, 0 repeats
@mjg59 My instinct tells me that it would, for two reasons:- If the processor pre-examined the branch before speculatively executing it, how far does it look ahead? 5 instructions? 20? 100? Pick any number, and I can place the illegal instruction farther ahead than that.- What would you expect it to do if it found an illegal instruction? If it tries to process one, it should abort. But there's really no alternative if it finds that it will eventually encounter one.