digitalmars.D.learn - Why is this happening to my software? An illegal instruction error.
- Murilo (9/9) Jun 18 I've created a software which performs the Fermat's Primality
- H. S. Teoh (23/32) Jun 18 [...]
- Murilo (4/7) Jun 19 Thank you, I will try this software on other computers to see if
- ryuukk_ (5/15) Jun 19 ```D
- Murilo (3/4) Jun 19 My mistake, I thought BigInt() only took strings, I've corrected
- Basile B. (5/15) Jun 20 That has to be an assertion failure happening at runtime. IIRC
- Timon Gehr (9/20) Jun 26 Looking at the code, this is probably the cause:
- Sergey (4/14) Jun 26 Another point.. never use std.bigint for something serious.
I've created a software which performs the Fermat's Primality Test, however if I input a very big number it causes an error saying "Illegal instruction (core dumped)". Does anyone know why? I've used GDB and here is the message: Program received signal SIGILL, Illegal instruction. 0x00005555555e40b0 in _D3std8internal4math11biguintcore7BigUint3powFNaNbNfNkMSQCcQCbQBvQBtQBjmZQs () Here is the link to the source code: https://github.com/MuriloMir/Fermat-primality-test
Jun 18
On Tue, Jun 18, 2024 at 11:07:47PM +0000, Murilo via Digitalmars-d-learn wrote:I've created a software which performs the Fermat's Primality Test, however if I input a very big number it causes an error saying "Illegal instruction (core dumped)". Does anyone know why? I've used GDB and here is the message: Program received signal SIGILL, Illegal instruction. 0x00005555555e40b0 in _D3std8internal4math11biguintcore7BigUint3powFNaNbNfNkMSQCcQCbQBvQBtQBjmZQs ()[...] There are a few possible causes: 1) There's a pointer bug in your program that corrupted some memory, causing a function pointer to point to something that isn't a function, and when the CPU tried to execute instructions from there it triggered a fault. 2) The optimized assembly code in std.bigint may contain an instruction that's incompatible with your CPU, so a fault is triggered when the CPU tried to execute it. 3) Your program may have been incorrectly linked, and the ABI incompatibility could have triggered this fault. 4) You may be using std.bigint for numbers far bigger than the range it's designed for. While this is unlikely to be the cause of this error (I've tested std.bigint with numbers up to 100,000+ digits without any crashes), using an unusually large number may cause the code to do something unexpected that may trigger the crash. The chances are pretty low that this is actually the case, though. Among the above causes, I'd say (1) is the most likely, (2) is the 2nd most likely if (1) isn't the cause. T -- Truth, Sir, is a cow which will give [skeptics] no more milk, and so they are gone to milk the bull. -- Sam. Johnson
Jun 18
On Wednesday, 19 June 2024 at 00:02:38 UTC, H. S. Teoh wrote:Among the above causes, I'd say (1) is the most likely, (2) is the 2nd most likely if (1) isn't the cause.Thank you, I will try this software on other computers to see if it's number 2. I've reviewed the code and I don't think it could be number 1.
Jun 19
On Tuesday, 18 June 2024 at 23:07:47 UTC, Murilo wrote:I've created a software which performs the Fermat's Primality Test, however if I input a very big number it causes an error saying "Illegal instruction (core dumped)". Does anyone know why? I've used GDB and here is the message: Program received signal SIGILL, Illegal instruction. 0x00005555555e40b0 in _D3std8internal4math11biguintcore7BigUint3powFNaNbNfNkMSQCcQCbQBvQBtQBjmZQs () Here is the link to the source code: https://github.com/MuriloMir/Fermat-primality-test```D else if (BigInt(to!string(tester)) ^^ number % number != tester) ``` why do you convert the number to string?
Jun 19
On Wednesday, 19 June 2024 at 07:46:07 UTC, ryuukk_ wrote:why do you convert the number to string?My mistake, I thought BigInt() only took strings, I've corrected the code.
Jun 19
On Tuesday, 18 June 2024 at 23:07:47 UTC, Murilo wrote:I've created a software which performs the Fermat's Primality Test, however if I input a very big number it causes an error saying "Illegal instruction (core dumped)". Does anyone know why? I've used GDB and here is the message: Program received signal SIGILL, Illegal instruction. 0x00005555555e40b0 in _D3std8internal4math11biguintcore7BigUint3powFNaNbNfNkMSQCcQCbQBvQBtQBjmZQs () Here is the link to the source code: https://github.com/MuriloMir/Fermat-primality-testThat has to be an assertion failure happening at runtime. IIRC the `ud2` instruction (causing SIGILL) is used in -betterC mode. If you look at biguintcore.d you'll see a couple of them, e.g https://github.com/dlang/phobos/blob/master/std/internal/math/biguintcore.d#L1042.
Jun 20
On 6/19/24 01:07, Murilo wrote:I've created a software which performs the Fermat's Primality Test, however if I input a very big number it causes an error saying "Illegal instruction (core dumped)". Does anyone know why? I've used GDB and here is the message: Program received signal SIGILL, Illegal instruction. 0x00005555555e40b0 in _D3std8internal4math11biguintcore7BigUint3powFNaNbNfNkMSQCcQCbQBvQBtQBjmZQs () Here is the link to the source code: https://github.com/MuriloMir/Fermat-primality-testLooking at the code, this is probably the cause: ``` if (BigInt(tester) ^^ number % number != tester) ``` This uses roughly as much memory as `number` is big, times the `log` of `tester`. You'd have to implement your own modular exponentiation that does not compute the full intermediate result, the you use only roughly `log` of `number` memory.
Jun 26
On Tuesday, 18 June 2024 at 23:07:47 UTC, Murilo wrote:I've created a software which performs the Fermat's Primality Test, however if I input a very big number it causes an error saying "Illegal instruction (core dumped)". Does anyone know why? I've used GDB and here is the message: Program received signal SIGILL, Illegal instruction. 0x00005555555e40b0 in _D3std8internal4math11biguintcore7BigUint3powFNaNbNfNkMSQCcQCbQBvQBtQBjmZQs () Here is the link to the source code: https://github.com/MuriloMir/Fermat-primality-testAnother point.. never use std.bigint for something serious. At first you can try to use https://code.dlang.org/packages/gmp-d and see if the problem is still presented
Jun 26