Commit graph

3612 commits

Author SHA1 Message Date
Sönke Holz
ddd9ab21e6 LibDeviceTree: Add functions for getting and translating addresses
I created this test file by running the following command:

    dtc -o address-translation.dtb <<EOF
    /dts-v1/;

    / {
        compatible = "serenity,address-translation-test";
        #address-cells = <2>;
        #size-cells = <1>;

        soc {
            compatible = "simple-bus";
            #address-cells = <1>;
            #size-cells = <1>;
            ranges = <0xa0000000 0xfe 0xd0000000 0x40000000>;

            usb@a0010000 {
                reg = <0xa0010000 0x100000>;
            };

            some-bus@b0000000 {
                compatible = "simple-bus";
                #address-cells = <2>;
                #size-cells = <2>;
                ranges = <0x02 0x00 0xb0000000 0x00 0x200000>;

                leds@200100000 {
                    reg = <0x02 0x100000 0x00 0x1000>;
                };
            };
        };
    };
    EOF
2024-12-10 16:25:46 +01:00
Pavel Shliak
4f6f65d1f9 AK: Fix InsertionSort to respect specified bounds
Previously, it ignored 'start', sorting from the array's
beginning. This caused unintended changes and slower
performance. Fix ensures sorting stays within 'start'
and 'end' indices only.

(cherry picked from commit 356016c626546aeb51722fe9ca5bb6a769bfe762)
2024-12-08 13:24:15 -05:00
Sönke Holz
240db03a27 AK: Make to_array work with zero-sized arrays
The other overload doesn't work for zero-sized arrays.

Co-authored-by: Timothy Flynn <trflynn89@pm.me>
2024-12-07 16:56:12 +01:00
Andreas Kling
073b3b992d AK: Make String::number() infallible
This API will always succeed in creating a String representing the
provided number in base-10.

(cherry picked from commit dd419b5a8df3b9a32478c4a8f0ea9f70334214cd;
amended to update the rest of the system. No conflicts though!)
2024-11-29 16:03:30 -05:00
Gingeh
a630c67a32 AK: Avoid returning null StringViews instead of empty views
This was error-prone and most users were just checking the length anyway

(cherry picked from commit 57ba720fb184ddf59fb09d3290e07cd425be450e)
2024-11-25 09:21:14 -05:00
Nico Weber
b00cfb54e8 AK: Don't define IsFloatingPoint and the FloatingPoint concept in KERNEL
We build KERNEL without floats, so that context switches don't have
to save float registers. As a side effect of that, _Float16 results
in a "_Float16 is not supported on this target" diagnostic.

Having IsFloatingPoint<> be false for the upcoming f16 type but
true for other floating point types seems strange, so just stop
having these concepts in kernel code altogether.
2024-11-19 19:20:44 -05:00
Andreas Kling
e1ba881587 AK+LibWeb: Add {Fly,}String::to_ascii_{upper,lower}_case()
These don't have to worry about the input not being valid UTF-8 and
so can be infallible (and can even return self if no changes needed.)

We use this instead of Infra::to_ascii_{upper,lower}_case in LibWeb.

(cherry picked from commit 073bcfd3866852a4c4bcca2bd131bd65ae53541f)
2024-11-18 20:22:45 -05:00
Timothy Flynn
814f13db04 AK: Add a comparison operator for Utf32View
(cherry picked from commit 0703ba118b56aaa924346ae36c8826764dadd409)
2024-11-17 11:03:57 -05:00
Timothy Flynn
d0f3347017 AK: Allow constructing Utf32 from a span of u32
(cherry picked from commit cf9693169cabfd23fe6b638fc7e9fcde1c3ecad8)
2024-11-17 11:03:57 -05:00
Sam Atkins
b647a74557 AK: Add Utf8View::for_each_split_view() method
Returns one Utf8View at a time, using a callback function to identify
code points to split on.

(cherry picked from commit 3f10a5701d9634e47111203b837283bdfc2d8b18)
2024-11-15 23:09:44 -05:00
Sam Atkins
4548cd6e5f AK: Ensure empty StringViews all compare as equal
Before this change, a StringView with a character-data pointer would
never compare as equal to one with a null pointer, even if they were
both length 0. This could happen for example if one is
default-initialized, and the other is created as a substring.

(cherry picked from commit ec5101a1d3cc7bc9068fa4863e16aa482536929a)
2024-11-15 23:09:44 -05:00
Jonne Ransijn
9614721bde AK: Pass (Deprecated)FlyString::is_one_of arguments by reference
This avoid unnecessairy reference counting.

(cherry picked from commit 22a66bb1c2afde93096d9866d6386e2bca955f71)
2024-11-14 23:38:18 -05:00
Timothy Flynn
60782cb219 AK: Do not coerce i64 and u64 values to i32 and u32
First, this isn't actually helpful, as we no longer store 32-bit values
in JsonValue. They are stored as 64-bit values anyways.

But more imporatantly, there was a bug here when trying to coerce an i64
to an i32. All negative values were cast to an i32, without checking if
the value is below NumericLimits<i32>::min.

(cherry picked from commit 7b3b608cafbed8049ac7a34104c66622c1445ffc)
2024-11-14 19:52:23 -05:00
Jonne Ransijn
de1ecc17ce AK: Add ASCII fast path for Utf8View::contains
This also makes `Utf8View::trim` significantly faster, since most
strings start and end with ASCII.

(cherry picked from commit 7f3269fb025051c3eb2794b15e785b85b0ce37f3)
2024-11-12 07:14:25 -05:00
Andreas Kling
b57e502d21 AK: Add ASCII fast path in StringBuilder::append(Utf16View)
And let's at least try to pre-allocate an appropriate amount of
buffer space in the builder instead of appending and growing one
code point at a time.

(cherry picked from commit b6e28ff80779520ccb49e6c15ae1866bbc8713a7)
2024-11-12 07:14:25 -05:00
Ali Mohammad Pur
bc9e03ea38 AK: Cache all the line positions in LineTrackingLexer
Also updates a LibWeb text test that used to report the wrong line
number.

(cherry picked from commit 02b50d463b174e5d525c7ab8ce8dd173d550de28;
amended to exclude LineTrackingLexer from KERNEL, since that now use
make<>)
2024-11-12 04:25:50 -05:00
Ali Mohammad Pur
2502b5713d AK: Make TemporaryChange not copy the old value twice
This is necessary for the next commit (and might even help performance
in some very weird cases).

(cherry picked from commit e5f87eb12bdad9dfbf8a825461ac17fdb8457f50;
amended to add a missing include of StdLibExtras.h for move())
2024-11-12 04:25:50 -05:00
Andreas Kling
f670b2ca32 AK: Use getrlimit() to find the correct main thread stack size on macOS
This is what JavaScriptCore does as well.

(cherry picked from commit 11458f0d91654feed9b4e225c4e6ac8528057355)
2024-11-10 19:39:05 -05:00
Andreas Kling
1030034130 LibWeb: Put CSS transitions debug spam behind CSS_TRANSITIONS_DEBUG
(cherry picked from commit 42a1a0bd73fecd22452e224859d27221588c3f5f;
amended to fix conflicts in Debug.h.in and all_the_debug_macros.cmake)
2024-11-04 13:15:58 -05:00
Andreas Kling
1733d84cf6 AK+LibURL: Move CopyOnWrite<T> from LibURL to AK
(cherry picked from commit af68771dda8e28a27d93933d25f141e4752d35ad)
2024-10-20 16:38:41 -04:00
Andreas Kling
1b73445f55 LibWeb: Note what's causing a style invalidation to happen
You can now build with STYLE_INVALIDATION_DEBUG and get a debug stream
of reasons why style invalidations are happening and where.

I've rewritten this code many times, so instead of throwing it away once
again, I figured we should at least have it behind a flag.

(cherry picked from commit ddbfac38b0074819470766846fca08fd78630eb0;
minorly amended for conflicts in AK/Debug.h.in and
Meta/CMake/all_the_debug_macros.cmake due to us having more debug
macros. Also, downstream got alphabetical order for
STYLE_INVALIDATION_DEBUG wrong.)
2024-10-20 01:32:53 -04:00
Timothy Flynn
59040d9bb8 AK: Add a method to compute UTF-16 length from a UTF-8 string
(cherry picked from commit 7a17c654d293c4afaf3086dc94e8cd4bceac48b1;
amended to resolve minor conflict in TestUtf16.cpp due to us not
(yet?) having `TEST_CASE(null_view)`. Also amended to make the new
method not call simdutf -- it's now also inefficient, but at least
the inefficient code is now only in one place instead of in several)
2024-10-18 18:21:18 -04:00
Shannon Booth
bcdb23ba3e AK: Add BOM handling to String::from_utf8_with_replacement_character
(cherry picked from commit b3bf5c4ea84bfbd0ba14fdbc3a86e5d54e053702)
2024-10-16 23:56:40 -04:00
Shannon Booth
6a9222ffd3 AK: Add fast-path in from_utf8_with_replacement_character for utf-8
This ports the same optimization which was made in
1a46d8df5fc81eb2c320d5c8a5597285d3d8fb3a to this function as well.

(cherry picked from commit 1e8cc97b731871409316c121e637c32806135122)
2024-10-16 23:56:40 -04:00
Shannon Booth
997ce4644f AK: Add String::from_utf8_with_replacement_character
This takes a byte sequence and converts it to a UTF-8 string with the
replacement character.

(cherry picked from commit 033ea0e7fb0f72338ae95aa0413da838206440bb)
2024-10-16 23:56:40 -04:00
Shannon Booth
fbb1db21b9 AK: Add is_ascii_c0_control_or_space
(cherry picked from commit cfa8a8cea25dfdc620ab1162ad853197014526ff)
2024-10-15 12:08:50 -04:00
kleines Filmröllchen
f23a1c6e97 AK: Use fast exponentiation for pow()
Whatever we were doing beforehand is *really*
slow.
2024-10-13 03:44:49 +02:00
kleines Filmröllchen
1fcb1d81cc AK: Avoid UB from pow() integer fast path
Only take this fast path if the power actually fits in an integer type.
Also, use 64-bit integers in all cases so that the fast path can be
taken more often.
2024-10-13 03:44:49 +02:00
Ali Mohammad Pur
6ac71a6623 AK: Don't show '0 seconds' unless seconds is the only available element 2024-10-02 08:10:54 +02:00
Ali Mohammad Pur
9a80f2f9ff AK: Add a fallible try_resolve() function to JsonPath
The existing version simply crashed if the expected layout wasn't in
line with reality.
2024-10-02 08:10:54 +02:00
Tim Ledbetter
d11ca444d0 AK: Assert that is<T>() input and output types are not the same
This makes it a compile error to use is<T>() where the input and output
types are known to be the same at compile time.

(cherry picked from commit 82a63e350cb9a67cbd3aa659d909ae9e6599e93f)
2024-09-28 14:14:28 -04:00
kleines Filmröllchen
a3077203fe AK: Don't implicitly convert Optional<T&> to Optional<T>
C++ will jovially select the implicit conversion operator, even if it's
complete bogus, such as for unknown-size types or non-destructible
types. Therefore, all such conversions (which incur a copy) must
(unfortunately) be explicit so that non-copyable types continue to work.
2024-09-14 13:30:27 +02:00
kleines Filmröllchen
dfe3cfa0ba AK: Use StringView as its own peek type
StringView is already a reference type, and copying it is cheap, so we
should use it as its own peek type.
2024-09-14 13:30:27 +02:00
kleines Filmröllchen
d21ee3206e AK: Add IPv6 subnet and address category handling
IPv6Address can now determine the broad address
categories as defined in various RFCs, and check
if addresses belong to certain subnets.
2024-09-08 18:27:55 -04:00
Dan Klishch
500ff2a7ed AK: Declare AK::Coroutine<T>::CoroutinePromiseBase::unhandled_exception
For some reason, Clang wants AK to work with exceptions enabled so much
that it produces a very annoying warning complaining about the absence
of (completely useless in our setup) unhandled_exception method in
promise type for every coroutine declared. We work around this during
build by suppressing -Wcoroutine-missing-unhandled-exception in
Meta/CMake/common_compile_options.cmake. However, the flag is only added
if build is using Clang. If one builds coroutine code with GCC but still
uses clangd, clangd, obviously, doesn't pick up warning suppression and
annoys user with a squiggly yellow line under each coroutine function
declaration.
2024-08-29 13:28:42 +02:00
Dan Klishch
3d3dd46618 AK: Rename AsyncStreamBuffer -> StreamBuffer
There is not nearly enough async-specific stuff in AsyncStreamBuffer for
it to carry "Async" prefix.
2024-08-29 13:28:42 +02:00
Dan Klishch
c3e13ce420 AK: Do not return value from void must_sync<void>(...) 2024-08-29 13:28:42 +02:00
Dan Klishch
3ead8e8f4f AK: Make workaround for broken coroutine type deduction more specific
This bug was fixed on GCC trunk.
2024-08-26 17:47:03 +02:00
Lucas CHOLLET
3fc784c442 AK/FuzzyMatch: Return the best possible score in case of equality
This fixes cases where fuzzy matching would return a better score for
a different pattern than a needle perfectly matching the haystack.

As an example, when searching for "fire" in emojis, "Fire Engine" would
have scored 168, while "Fire" was giving only 160.
This patch makes the latter have the best possible score.
2024-08-23 14:14:05 -04:00
Lucas CHOLLET
79431198ac AK/FuzzyMatch: Const qualify a u8 pointer 2024-08-23 14:14:05 -04:00
Lucas CHOLLET
dff57085ef AK/FuzzyMatch: Remove unnecessary const qualifier
These variables are already `constexpr`.
2024-08-23 14:14:05 -04:00
Marek Knápek
07a58d2707 LibCrypto: Implement AES by using x86 intrinsics 2024-08-21 08:19:35 -04:00
Nico Weber
3cb83860fa LibGfx/PNGWriter+AK: SIMDify paeth predictor more
Takes

    (cd Tests/LibGfx; ../../Build/lagom/bin/BenchmarkPNG)

from 59ms to 32ms on my system.

Adds AK::SIMD::bitselect() (modeled after the wasm SIMD equivalent),
and AK::SIMD::abs() implemented on top of it.

No behavior change.
2024-08-10 13:07:01 -04:00
Hendiadyoin1
832b5ff603 AK: Add simd_cast<T> and replace to_TxN with it 2024-08-08 22:43:53 -04:00
Nico Weber
34a4d16776 AK: Add AK::SIMD::to_i8x4() 2024-08-06 23:00:32 -04:00
Dennis Camera
b367479d00 AK: Fix {:c} formatter for big-endian 2024-08-06 23:03:10 +02:00
Diego Frias
3fe206d44f AK/SIMDExtras: Fix masking logic in shuffle_or_0
(cherry picked from commit a168bec7efcb26ef7e27cd5294fdefa1ff9e4ca9)
2024-07-29 14:34:01 +02:00
Diego Frias
2b708f791b AK/LEB128: Speed up reading unsigned LEB128 values
Unroll the first byte as a fast path, and remove a branch. This speeds
up the instantiation of spidermonkey by 10ms.

(cherry picked from commit a6ebd100ecd9ed633e290153f61466362e63b73a)
2024-07-29 14:34:01 +02:00
Diego Frias
519d3674fa LibWasm: Fix SIMD shuffle and swizzle
`swizzle` had the wrong operands, and the vector masking boolean logic
was incorrect in the internal `shuffle_or_0` implementation. `shuffle`
was previously implemented as a dynamic swizzle, when it uses an
immediate operand for lane indices in the spec.

(cherry picked from commit 9cc3e7d32d150dd30d683c1a8cf0bd59676f14ab)
2024-07-29 14:34:01 +02:00
Liav A.
1c6cf62c4a AK: Add is_canonical method for LexicalPath
Similarly to KLexicalPath, we might need to check if a path is canonical
or not.
2024-07-21 11:44:23 +02:00