Commit graph

3599 commits

Author SHA1 Message Date
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
Dan Klishch
645a220f3b LibCrypto: Use static member function pointer to choose SHA1 SIMD kernel
It turns out we cannot use function multi-versioning with "sha" feature
or even just plain ifunc resolvers without preprocessor guards. So,
instead of feeding ifdef-soup monster, we just use static member
function pointer.

Moving the kernel into the SHA1 class makes it possible to not pass
class members as parameters to it. This, however, requires us to
disambiguate different target "clones" of the kernel using some kind
of template.
2024-07-12 18:30:07 -04:00
Dan Klishch
aa2f5df0a9 AK: Add a helper to detect which CPU features are supported
The helper doesn't use __builtin_cpu_supports (and instead makes raw
cpuid calls) because of three reasons:

 - __builtin_cpu_supports only works on x86_64, so its usage need to be
   guarded with the preprocessor similarly to the current code.
   Moreover, we will have to use custom mechanisms to detect features on
   ARM, since there isn't such thing as cpuid there (and __builtin_cpu_*
   are not provided).

 - __builtin_cpu_supports doesn't support "sha" feature on all targeted
   toolchains currently.

 - And, of course, NIH.
2024-07-12 18:30:07 -04:00
Dan Klishch
225d9a2c1a AK: Introduce AK_CAN_CODEGEN_FOR_<FEATURE> macros
These replace `#if ARCH(...)` macros that were added to conditionally
include different hand-vectorized SIMD-implementations.
2024-07-12 18:30:07 -04:00
Dan Klishch
2b65b62c6e AK: Use bit_cast in SIMDExtras.h/AK::Detail::byte_reverse_impl
This necessitates marking bit_cast as ALWAYS_INLINE since emitting it as
a function call there will create an unnecessary potential SSE
registers -> plain registers/memory round-trip.
2024-07-12 18:30:07 -04:00
Dan Klishch
56b7f9e404 Meta: Globally disable -Wpsabi
This warning is triggered when one accepts or returns vectors from a
function (that is not marked with [[gnu::target(...)]]) which would have
been otherwise passed in register if the current translation unit had
been compiled with more permissive flags wrt instruction selection (i.
e. if one adds -mavx2 to cmdline). This will never be a problem for us
since we (a) never use different instruction selection options across
ABI boundaries; (b) most of the affected functions are actually
TU-local.

Moreover, even if we somehow properly annotated all of the SIMD helpers,
calling them across ABI (or target) boundaries would still be very
dangerous because of inconsistent and bogus handling of
[[gnu::target(...)]] across compilers. See
https://github.com/llvm/llvm-project/issues/64706 and
https://www.reddit.com/r/cpp/comments/17qowl2/comment/k8j2odi .
2024-07-12 18:30:07 -04:00
Dan Klishch
02c66c8696 AK: Add links to relevant coroutine bugs on GCC bugzilla
Fixes #24630.
2024-07-10 05:02:05 -04:00
Diego
7712ca1eb3 AK: Add remaining method to ConstrainedStream
Simply returns how many bytes can be read from the stream.

(cherry picked from commit aee2f25929157a4e6c7f391584c4839a40beadc8)
2024-07-10 01:10:12 +02:00
Timothy Flynn
8adcbd7136 AK: Decode paired UTF-16 surrogates in a JSON string
For example, such use is seen on Twitter.

(cherry picked from commit 698a95d2dee0ba7e9a3f1c39af5459ba506c445f)
2024-07-07 18:47:09 +02:00
Timothy Flynn
c56a965126 AK: Make a couple of GenericLexer helper methods protected
We will want to use the exact behavior of these methods in JsonParser.

(cherry picked from commit c39a3fef17e913da944c35d57541298232bcea53)
2024-07-07 18:47:09 +02:00
sdomi
6403468f09 AK: Re-enable execinfo for GNU Hurd
Adds an explicit check for Hurd due to previous regression.
2024-07-05 09:24:53 -06:00
sdomi
4cc93cf80f AK: Do not build against libexecinfo on non-glibc systems
It seems that libexecinfo was broken on musl (and possibly other libcs)
for quite a while now (resulting in a segfault, or returning 0 frames).
Hence, we shouldn't include it there because it doesn't provide any
added functionality.
2024-07-05 13:50:55 +02:00
Hendiadyoin1
1b8fd5c35a AK: Add generic SIMD shuffle/reverse functions 2024-07-05 00:52:30 +02:00
Hendiadyoin1
27c386797d AK: Add generic SIMD vector load/store functions 2024-07-05 00:52:30 +02:00