<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/126383>126383</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Extremely slow integer multiplication and math.pow
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
oittaa
</td>
</tr>
</table>
<pre>
I'm new to Zig so I might have missed something, but the documentation talks about integers being usable up to 65535 bits. But on my machine they become basically unusable long before that.
This relatively simple code for generating an adversarial pseudoprime runs extremely slowly taking over a minute on a M1 Mac. Even in Python it's basically instant. `math.pow` had to be replaced with bit shifts since I think the program just hung up and I had to kill it after 15 minutes. I also tried to put it in godbolt, but it just failed to compile with both 0.13 and trunk.
```zig
const std = @import("std");
pub fn main() !void {
//const pow = std.math.pow;
// const p1 = pow(u4279, 2, 1344) * 0x0000000000000000000000000000083DDA18EB04A7597CA3;
var p1: u8192 = (1 << 1344) * 0x0000000000000000000000000000083DDA18EB04A7597CA3;
p1 += (1 << 1152) * 0xC6BC877DF8A08EEC6725FA0832CBA270C42ADC358BC0CF50;
p1 += (1 << 960) * 0xC82CB10F2733C3FB8875231FC1498A7B14CB675FAC1BF3C5;
p1 += (1 << 768) * 0x127A76FC11E5D20E27940C95CEBA671FE1C4232250B74CBD;
p1 += (1 << 576) * 0xF8448C90321513324C0681AFB4BA003353B1AFB0F1E8B91C;
p1 += (1 << 384) * 0x60AF672A5A6F4D06DD0070A4BC74E425F3EAE90379E57754;
p1 += (1 << 192) * 0x82D26E80E247464A4BB817DFCF7572F89F8B9CACD059B584;
p1 += 0x0E4389C8AF84F6A6EA15A3EA5D62CB994B082731BA4CDE73;
const n: u8192 = p1 * (1013 * (p1 - 1) + 1) * (2053 * (p1 - 1) + 1);
std.debug.print("p1: {d}\n", .{p1});
std.debug.print("n: {d}\n", .{n});
}
```
```
$ time zig run example.zig
...snip...
real 1m32.436s
user 1m31.264s
sys 0m0.394s
$ zig version
0.13.0
```
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJysls1y6yoSx58Gb7qOik-BFl4gJFVlcatmMavZIQvb3EigEsg5uU8_he3c5MyZyWpSKRuj5td_ukU3NiV_Cc4dkWiR6A52z9e4HaPP2drDGKf34wuicoHg3iBH-Je_QIrwAou_XDNc7c3B4lNyE6S4uHz14YKogXHPkK8OpnjaFxeyzT4GyHZ-TWDHuGfwIbuL2xKMzocL7MmOs4N9LV5qIZiA0edUQbtniAGWd1js6eqDK9x3GN0pLg5Gm_zJzvM77OGJmGO4wOjOcSumNlcIa4T1P68-weZmm_3Nze-Q_LLODk5xcnCOG1xccJvNRYsNYKeb25LdvJ1hTW6f4rr5xcG2hwTuZ97ccofM8W1-h2xfy7p4cxtYWHzYsyuiLfxB4A97qqC_uQA-wD_e8zUG8BlRmb6o9yFlG3IFqMaLzddqjW-oxnC1UwnI6GBz62xPboI3n68lNpCu_pwTJB9ODl6gxP71HvR1i5fNLvDnnjJc9xLdFWyY4OWD9-rnGXwGe85uAyKemlMFL2DnFCFv3t0t15Kqki24xGmMc_7Irs8P_tn6-WF6isvqZ_cUGPMVcEXY3XHe9vD6TASq8eP_L39BWJ9iSBlSngCxDhDHflnjlhFViNKUJ0Qpog1i7WP1uo9wDrBYH-4mDSBKbtFPgGQxAQBAdEB0eIDX-HYHpzxVfweW_WoJT1NytywGVO2cyqbslZYPwjh_-NKAf-Lv_hTrOk1U32KupWik0ezT381usBLENOyKNPSxZaqKY4PY_8lP2Qdtf0MTQT_Rpm6NkrIblMaq700tqRg0VoyaVlOJDae6M0yo1mAzCPwtuqnxF7KipiV4oJIxw4ZWKSkoI4MhvFFatoSbtpZi0Ia0AzPiW7Ks1SeZUKllPRhCetFR3FPZcGwaYfpW15IMPTGcMkoFbiU3bfctWcj6kzwozpVpMKNEEMYoN7hWRA8tbzXGjAnWll94IL1qG2K-JTP1JYU11kMtqRa6HniH667DWGLNWyN5z6kYW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