Commit graph

83 commits

Author SHA1 Message Date
Ian Johnson
3543f28320 std.math.big.int: fix shiftRight sign handling
Closes #21311

The sign of the result `r` needs to be initialized before the correction
`r.addScalar(r.toConst(), -1)`, or the intended end result could be off
by 2 (depending on the original sign of `r`).
2024-09-06 10:36:12 -07:00
mlugg
0fe3fd01dd
std: update std.builtin.Type fields to follow naming conventions
The compiler actually doesn't need any functional changes for this: Sema
does reification based on the tag indices of `std.builtin.Type` already!
So, no zig1.wasm update is necessary.

This change is necessary to disallow name clashes between fields and
decls on a type, which is a prerequisite of #9938.
2024-08-28 08:39:59 +01:00
Tau
2b99b04285 Fix right shift on negative BigInts
Closes #17662.
2024-07-12 00:46:03 -07:00
poypoyan
aa07366513
std.math.big.int.Managed: adjust size of arg for limbs_buffer in format() 2024-05-21 13:28:05 +00:00
Andrew Kelley
126c9a34af restructure unit test to be easier to debug 2024-05-08 19:37:29 -07:00
Андрей Краевский
7cc0e6d4cd
std: fix big int llshr to respect aliasing (#19612) 2024-04-13 03:06:23 -07:00
tinusgraglin
26e895e3dc math.big.int: fix incorrect bitAnd behavior 2024-03-11 16:52:03 -07:00
Ryan Liptak
16b3d1004e Remove redundant test name prefixes now that test names are fully qualified
Follow up to #19079, which made test names fully qualified.

This fixes tests that now-redundant information in their test names. For example here's a fully qualified test name before the changes in this commit:

"priority_queue.test.std.PriorityQueue: shrinkAndFree"

and the same test's name after the changes in this commit:

"priority_queue.test.shrinkAndFree"
2024-02-26 15:18:31 -08:00
Jacob Young
e27db373ec x86_64: implement @clz and @ctz of big integers 2024-02-12 05:25:07 +01:00
Jacob Young
bcbd49b2a6 x86_64: implement shifts of big integers 2024-02-12 05:25:07 +01:00
mlugg
51595d6b75
lib: correct unnecessary uses of 'var' 2023-11-19 09:55:07 +00:00
Jacob Young
0c6cb8d8c8 x86_64: actually track state during @divFloor of i128
Closes #17998
2023-11-14 22:50:05 -05:00
Jakub Konka
ea3f1d27e0 std: disable failing test 2023-11-14 16:51:38 +01:00
tison
ee47643b6e
std.math.big: fix sqrt with bits > limb_bits
Signed-off-by: tison <wander4096@gmail.com>
2023-11-08 08:39:08 +02:00
David Rubin
03abac3824 fix sqrt(0) 2023-11-07 14:37:43 +02:00
Jacob Young
509be7cf1f x86_64: fix std test failures 2023-11-03 23:18:21 -04:00
Andrew Kelley
3fc6fc6812 std.builtin.Endian: make the tags lower case
Let's take this breaking change opportunity to fix the style of this
enum.
2023-10-31 21:37:35 -04:00
Jacob Young
f6f2708d82 x86_64: fix compiler rt test failures 2023-10-29 07:20:36 -04:00
Jacob Young
b0cf620fe3 x86_64: fix cond_br 2023-10-27 03:33:49 -04:00
Jacob Young
5e83441096 x86_64: implement @divFloor and @mod for i128 2023-10-26 21:45:57 -04:00
Jacob Young
8f69e977f1 x86_64: implement 128-bit builtins
* `@clz`
 * `@ctz`
 * `@popCount`
 * `@byteSwap`
 * `@bitReverse`
 * various encodings used by std
2023-10-23 22:42:18 -04:00
Jacob Young
fe93332ba2 x86_64: implement enough to pass unicode tests
* implement vector comparison
 * implement reduce for bool vectors
 * fix `@memcpy` bug
 * enable passing std tests
2023-10-23 22:42:18 -04:00
Jacob Young
27fe945a00 Revert "Revert "Merge pull request #17637 from jacobly0/x86_64-test-std""
This reverts commit 6f0198cadb.
2023-10-22 15:46:43 -04:00
Andrew Kelley
6f0198cadb Revert "Merge pull request #17637 from jacobly0/x86_64-test-std"
This reverts commit 0c99ba1eab, reversing
changes made to 5f92b070bf.

This caused a CI failure when it landed in master branch due to a
128-bit `@byteSwap` in std.mem.
2023-10-22 12:16:35 -07:00
Jacob Young
32e85d44eb x86_64: disable failing tests, enable test-std testing 2023-10-21 10:55:41 -04:00
Jacob Young
2e6e39a700 x86_64: fix bugs and disable erroring tests 2023-10-21 10:55:41 -04:00
Jacob Young
c880644d92 x86_64: disable difficult std tests and hack around more zero-bit types 2023-10-21 10:55:41 -04:00
Philipp Lühmann
ed19ebc360
std.math.big.int.Const.order 0 == -0 (#17299) 2023-09-29 18:09:47 +13:00
mlugg
283afb50b5 AstGen: disallow '-0' integer literal
The intent here is ambiguous: this resolves to the comptime_int '0', but
it's likely the user meant to use a floating-point literal.

Resolves: #16890
2023-08-21 11:47:31 +03:00
r00ster91
2b8687ba2d std.math.big.int: better name for equal function
All of the std except these few functions call it "eql" instead of "eq".
This has previously tripped me up when I expected the equality check function to be called "eql"
(just like all the rest of the std) instead of "eq".

The motivation is consistency.

If search "eq" on Autodoc, these functions stick out and it looks inconsistent.

I just noticed there are also a few functions spelling it out as "equal" (such as std.mem.allEqual).
Maybe those functions should also spell it "eql" but that can be done in a future PR.
2023-07-03 11:00:13 -07:00
mlugg
f26dda2117 all: migrate code to new cast builtin syntax
Most of this migration was performed automatically with `zig fmt`. There
were a few exceptions which I had to manually fix:

* `@alignCast` and `@addrSpaceCast` cannot be automatically rewritten
* `@truncate`'s fixup is incorrect for vectors
* Test cases are not formatted, and their error locations change
2023-06-24 16:56:39 -07:00
Mizuochi Keita
4422af8be9 std.math.big.int: Add Sqrt
Implemented with reference to Modern Computer Arithmetic, Algorithm 1.13.
https://members.loria.fr/PZimmermann/mca/pub226.html

The below optimization ideas are derived from Go's big package.

* Minimize initial loop value
* Reuse loop values

math/big/int.go: https://cs.opensource.google/go/go/+/refs/tags/go1.20.4:src/math/big/int.go;l=1286
2023-05-29 13:04:32 +03:00
Brett Hill
37f56a4259 Issue 15535. Normalize remainder in math.big.int.Managed.divTrunc 2023-05-10 16:01:17 +03:00
Dominic
5a3eca5d4c
Disallow named test decls with duplicate names 2023-05-08 10:59:06 +03:00
Andrew Kelley
a5c910adb6 change semantics of @memcpy and @memset
Now they use slices or array pointers with any element type instead of
requiring byte pointers.

This is a breaking enhancement to the language.

The safety check for overlapping pointers will be implemented in a
future commit.

closes #14040
2023-04-25 11:23:40 -07:00
Jacob Young
bf6fd9ae3f cbe: enable CI for std tests 2023-04-21 16:36:10 -04:00
Stevie Hryciw
e8fdb249b6 std.math.big.int: Initialize limbs in addWrap
When a big.Int.Mutable had more than two limbs, it was possible for
this function to change the `len` field without zeroing limbs in the
active range. These uninitialized limbs would then be used in
`truncate()` and could cause invalid results.

Closes #13571
2023-04-20 16:00:37 -07:00
IntegratedQuantum
0b4461d97b
Fix tautological big_int tests. 2022-12-14 00:29:25 +00:00
Jacob Young
d9a51648e6 std.big.int.Mutable: fix set(@as(DoubleLimb, 0))
Previously, this would set len to 1 but fail to initialize any limbs.
2022-11-28 07:40:09 -05:00
Stevie Hryciw
5f6f38ff31 std.math.big.int: implement popCount() for Const 2022-11-18 14:31:30 +02:00
Cody Tapscott
3295fee911 stage2: Use mem.readPackedInt etc. for packed bitcasts
Packed memory has a well-defined layout that doesn't require
conversion from an integer to read from. Let's use it :-)

This change means that for bitcasting to/from a packed value that
is N layers deep, we no longer have to create N temporary big-ints
and perform N copies.

Other miscellaneous improvements:
  - Adds support for casting to packed enums and vectors
  - Fixes bitcasting to/from vectors outside of a packed struct
  - Adds a fast path for bitcasting <= u/i64
  - Fixes bug when bitcasting f80 which would clear following fields

This also changes the bitcast memory layout of exotic integers on
big-endian systems to match what's empirically observed on our targets.
Technically, this layout is not guaranteed by LLVM so we should probably
ban bitcasts that reveal these padding bits, but for now this is an
improvement.
2022-10-28 08:41:04 -07:00
Jacob Young
5c49341f09 big.int: add support for non-comptime scalars 2022-10-11 19:51:03 -04:00
Hiroaki Nakamura
d63604b116 Fix std.math.big.int.Managed capacity after mul and sqr 2022-07-16 00:08:55 +09:00
Andrew Kelley
54454fd010 std.math.big.int: breaking API changes to prevent UAF
Many of the Managed methods accepted by-val parameters which could
reference Limb slices that became invalid memory after any
ensureCapacity calls. Now, Managed methods accept `*const Managed`
parameters so that if the function allows aliasing and the
ensure-capacity call resizes the Limb slice, it also affects the
aliased parameters, avoiding use-after-free bugs.

This is a breaking change that reduces the requirement for callsites to
manually make the ensure-capacity changes prior to calling many of the
Managed methods.

Closes #11897
2022-06-29 22:06:27 -04:00
Marc Tiehuis
2e0de0b4e2
math/big: correct fix for divmod (#11271)
Fixes #11166.
2022-03-23 19:24:25 +01:00
Marc Tiehuis
8bab1b405f math: fix big.int div, gcd and bitAnd edge-cases
Fixes #10932.
2022-03-10 13:56:07 -05:00
Cody Tapscott
ef417f19e1 stage2: Implement @bitReverse and @byteSwap
This change implements the above built-ins for Sema and the LLVM
backend. Other backends have had placeholders added for lowering.
2022-02-18 14:28:32 -07:00
Cody Tapscott
c586e3ba1b Add additional tests for @bitCast 2022-02-13 13:28:08 -07:00
Cody Tapscott
7b72fc6bbc Add abi_size parameter to read/writeTwosComplement
Big-int functions were updated to respect the provided abi_size, rather
than inferring a potentially incorrect abi_size implicitly.

In combination with the convention that any required padding bits are
added on the MSB end, this means that exotic integers can potentially
have a well-defined memory layout.
2022-02-13 13:26:59 -07:00
Cody Tapscott
70d7f87be0 Fix up sign handling and add arbitrary-length integer support to @bitCast() 2022-02-11 08:49:19 -07:00