Skip to content

Commit

Permalink
Update Soup
Browse files Browse the repository at this point in the history
  • Loading branch information
Sainan committed Jan 23, 2025
1 parent 0b87965 commit 501d157
Show file tree
Hide file tree
Showing 88 changed files with 1,174 additions and 1,212 deletions.
6 changes: 6 additions & 0 deletions src/vendor/Soup/soup/Asn1Sequence.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ NAMESPACE_SOUP
return fromDer(r);
}

Asn1Sequence Asn1Sequence::fromDer(const char* data, size_t size)
{
MemoryRefReader r(data, size);
return fromDer(r);
}

Asn1Sequence Asn1Sequence::fromDer(Reader& r) SOUP_EXCAL
{
SOUP_IF_UNLIKELY (readIdentifier(r).type != ASN1_SEQUENCE)
Expand Down
1 change: 1 addition & 0 deletions src/vendor/Soup/soup/Asn1Sequence.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ NAMESPACE_SOUP
explicit Asn1Sequence(const std::string& data) SOUP_EXCAL; // expects DER-encoded data without prefix

[[nodiscard]] static Asn1Sequence fromDer(const std::string& str) SOUP_EXCAL; // expects DER-encoded data with prefix
[[nodiscard]] static Asn1Sequence fromDer(const char* data, size_t size) SOUP_EXCAL; // expects DER-encoded data with prefix
[[nodiscard]] static Asn1Sequence fromDer(Reader& r) SOUP_EXCAL; // expects DER-encoded data with prefix

[[nodiscard]] size_t countChildren() const;
Expand Down
8 changes: 4 additions & 4 deletions src/vendor/Soup/soup/Bigint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -760,7 +760,7 @@ NAMESPACE_SOUP
return res;
}

void Bigint::divide(const Bigint& divisor, Bigint& outQuotient, Bigint& outRemainder) const SOUP_EXCAL
void Bigint::divide(const Bigint& divisor, Bigint& SOUP_UNIQADDR outQuotient, Bigint& SOUP_UNIQADDR outRemainder) const SOUP_EXCAL
{
outQuotient.reset();
outRemainder.reset();
Expand Down Expand Up @@ -800,7 +800,7 @@ NAMESPACE_SOUP
return res;
}

void Bigint::divideUnsigned(const Bigint& divisor, Bigint& remainder) SOUP_EXCAL
void Bigint::divideUnsigned(const Bigint& divisor, Bigint& SOUP_UNIQADDR remainder) SOUP_EXCAL
{
remainder.reset();
SOUP_IF_LIKELY (!divisor.isZero())
Expand Down Expand Up @@ -1727,9 +1727,9 @@ NAMESPACE_SOUP

const Bigint two = (chunk_t)2u;
Bigint y = (*this / two);
Bigint x_over_y;
Bigint x_over_y, remainder;

while (x_over_y = (*this / y), y > x_over_y)
while (this->divide(y, x_over_y, remainder), y > x_over_y)
{
y = (x_over_y + y) / two;
}
Expand Down
4 changes: 2 additions & 2 deletions src/vendor/Soup/soup/Bigint.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,9 @@ NAMESPACE_SOUP
void operator/=(const Bigint& divisor) SOUP_EXCAL;
void operator%=(const Bigint& divisor) SOUP_EXCAL;
[[nodiscard]] std::pair<Bigint, Bigint> divide(const Bigint& divisor) const SOUP_EXCAL; // (Quotient, Remainder)
void divide(const Bigint& divisor, Bigint& outQuotient, Bigint& outRemainder) const SOUP_EXCAL;
void divide(const Bigint& divisor, Bigint& SOUP_UNIQADDR outQuotient, Bigint& SOUP_UNIQADDR outRemainder) const SOUP_EXCAL;
[[nodiscard]] std::pair<Bigint, Bigint> divideUnsigned(const Bigint& divisor) const SOUP_EXCAL; // (Quotient, Remainder)
void divideUnsigned(const Bigint& divisor, Bigint& remainder) SOUP_EXCAL;
void divideUnsigned(const Bigint& divisor, Bigint& SOUP_UNIQADDR remainder) SOUP_EXCAL;
[[nodiscard]] chunk_t divideUnsignedSmall(chunk_t divisor) noexcept;
[[nodiscard]] Bigint mod(const Bigint& m) const SOUP_EXCAL;
[[nodiscard]] Bigint modUnsigned(const Bigint& m) const SOUP_EXCAL;
Expand Down
17 changes: 9 additions & 8 deletions src/vendor/Soup/soup/BufferRefWriter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,29 @@ NAMESPACE_SOUP
public:
Buffer& buf;

BufferRefWriter(Buffer& buf, Endian endian = ENDIAN_LITTLE)
: Writer(endian), buf(buf)
BufferRefWriter(Buffer& buf)
: Writer(), buf(buf)
{
}

~BufferRefWriter() final = default;

bool raw(void* data, size_t size) noexcept final
{
#if SOUP_EXCEPTIONS
try
#endif
SOUP_TRY
{
buf.append(data, size);
}
#if SOUP_EXCEPTIONS
catch (...)
SOUP_CATCH_ANY
{
return false;
}
#endif
return true;
}

[[nodiscard]] size_t getPosition() final
{
return buf.size();
}
};
}
22 changes: 9 additions & 13 deletions src/vendor/Soup/soup/BufferWriter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,33 +11,29 @@ NAMESPACE_SOUP
public:
Buffer buf{};

BufferWriter(Endian endian = ENDIAN_LITTLE)
: Writer(endian)
{
}

BufferWriter(bool little_endian)
: Writer(little_endian)
BufferWriter()
: Writer()
{
}

~BufferWriter() final = default;

bool raw(void* data, size_t size) noexcept final
{
#if SOUP_EXCEPTIONS
try
#endif
SOUP_TRY
{
buf.append(data, size);
}
#if SOUP_EXCEPTIONS
catch (...)
SOUP_CATCH_ANY
{
return false;
}
#endif
return true;
}

[[nodiscard]] size_t getPosition() final
{
return buf.size();
}
};
}
36 changes: 18 additions & 18 deletions src/vendor/Soup/soup/Canvas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -497,23 +497,23 @@ NAMESPACE_SOUP
Canvas c;

uint16_t sig;
SOUP_IF_LIKELY (r.u16(sig) && sig == 0x4D42)
SOUP_IF_LIKELY (r.u16le(sig) && sig == 0x4D42)
{
uint32_t data_start, header_size, palette_size;
int32_t width, height;
int16_t bits_per_pixel;
SOUP_IF_LIKELY ((r.seek(0x0A), r.u32(data_start))
&& r.u32(header_size)
SOUP_IF_LIKELY ((r.seek(0x0A), r.u32le(data_start))
&& r.u32le(header_size)
&& header_size == 40 // BITMAPINFOHEADER
&& r.i32(width)
&& r.i32(height)
&& r.i32le(width)
&& r.i32le(height)
&& r.skip(2) // planes
&& r.i16(bits_per_pixel)
&& r.i16le(bits_per_pixel)
&& r.skip(4) // compression method
&& r.skip(4) // image size
&& r.skip(4) // horizontal resolution
&& r.skip(4) // vertical resolution
&& r.u32(palette_size)
&& r.u32le(palette_size)
&& r.skip(4) // important colours
)
{
Expand Down Expand Up @@ -547,7 +547,7 @@ NAMESPACE_SOUP
for (size_t i = 0; i != c.pixels.size(); )
{
uint32_t dw;
SOUP_IF_UNLIKELY (!r.u32(dw))
SOUP_IF_UNLIKELY (!r.u32le(dw))
{
break;
}
Expand Down Expand Up @@ -672,17 +672,17 @@ NAMESPACE_SOUP
{
uint16_t s;
uint32_t i;
SOUP_IF_UNLIKELY (!(s = 0x4D42, w.u16(s))
|| !(i = static_cast<uint32_t>(40 + (3 * pixels.size())), w.u32(i))
SOUP_IF_UNLIKELY (!(s = 0x4D42, w.u16le(s))
|| !(i = static_cast<uint32_t>(40 + (3 * pixels.size())), w.u32le(i))
|| !w.skip(4)
|| !(i = (14 + 40), w.u32(i))
|| !(i = 40, w.u32(i))
|| !(i = width, w.u32(i))
|| !(i = height * -1, w.u32(i))
|| !(s = 1, w.u16(s))
|| !(s = 24, w.u16(s))
|| !(i = 0, w.u32(i))
|| !(i = static_cast<uint32_t>(3 * pixels.size()), w.u32(i))
|| !(i = (14 + 40), w.u32le(i))
|| !(i = 40, w.u32le(i))
|| !(i = width, w.u32le(i))
|| !(i = height * -1, w.u32le(i))
|| !(s = 1, w.u16le(s))
|| !(s = 24, w.u16le(s))
|| !(i = 0, w.u32le(i))
|| !(i = static_cast<uint32_t>(3 * pixels.size()), w.u32le(i))
|| !w.skip(4 + 4 + 4 + 4)
)
{
Expand Down
67 changes: 43 additions & 24 deletions src/vendor/Soup/soup/CpuInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,15 @@ NAMESPACE_SOUP
if (cpuid_max_eax >= 0x07)
{
invokeCpuid(arr, 0x07, 0);
extended_features_max_ecx = EAX;
extended_features_0_ebx = EBX;

if (extended_features_max_ecx >= 1)
{
invokeCpuid(arr, 0x07, 1);
extended_features_1_eax = EAX;
}

if (cpuid_max_eax >= 0x16)
{
invokeCpuid(arr, 0x16);
Expand All @@ -65,7 +72,7 @@ NAMESPACE_SOUP
if (cpuid_extended_max_eax >= 0x80000001)
{
invokeCpuid(arr, 0x80000001);
extended_features_1_ecx = ECX;
extended_flags_1_ecx = ECX;
}

#undef EAX
Expand Down Expand Up @@ -114,30 +121,43 @@ NAMESPACE_SOUP
str.append("\nStepping ID: ").append(std::to_string(stepping_id));
str.append("\nModel: ").append(std::to_string(model));
str.append("\nFamily: ").append(std::to_string(family));
str.append("\nFeature Flags 1: ").append(string::hex(feature_flags_ecx));
str.append("\nFeature Flags 2: ").append(string::hex(feature_flags_edx));

if (cpuid_max_eax >= 0x07)
if (base_frequency || max_frequency || bus_frequency)
{
str.append("\nFeature Flags 3: ").append(string::hex(extended_features_0_ebx));

if (cpuid_max_eax >= 0x16)
{
str.append("\nBase Frequency: ").append(std::to_string(base_frequency)).append(
" MHz\n"
"Max. Frequency: "
).append(std::to_string(max_frequency)).append(
" MHz\n"
"Bus (Reference) Frequency: "
).append(std::to_string(bus_frequency)).append(" MHz");
}
str.append("\nBase Frequency: ").append(std::to_string(base_frequency)).append(
" MHz\n"
"Max. Frequency: "
).append(std::to_string(max_frequency)).append(
" MHz\n"
"Bus (Reference) Frequency: "
).append(std::to_string(bus_frequency)).append(" MHz");
}
}

if (cpuid_extended_max_eax >= 0x80000001)
{
str.append("\nExtended Feature Flags: ").append(string::hex(extended_features_1_ecx));
}
str.append("\nSSE Support: ");
if (supportsSSE4_2()) { str.append("SSE4.2"); }
else if (supportsSSE4_1()) { str.append("SSE4.1"); }
else if (supportsSSSE3()) { str.append("SSSE3"); }
else if (supportsSSE3()) { str.append("SSE3"); }
else if (supportsSSE2()) { str.append("SSE2"); }
else if (supportsSSE()) { str.append("SSE"); }
else { str.append("None"); }

str.append("\nAVX Support: ");
if (supportsAVX512F()) { str.append("AVX512F"); }
else if (supportsAVX2()) { str.append("AVX2"); }
else if (supportsAVX()) { str.append("AVX"); }
else { str.append("None"); }

std::string misc_features{};
if (supportsPCLMULQDQ()) { string::listAppend(misc_features, "PCLMULQDQ"); }
if (supportsAESNI()) { string::listAppend(misc_features, "AESNI"); }
if (supportsRDRAND()) { string::listAppend(misc_features, "RDRAND"); }
if (supportsRDSEED()) { string::listAppend(misc_features, "RDSEED"); }
if (supportsSHA()) { string::listAppend(misc_features, "SHA"); }
if (supportsSHA512()) { string::listAppend(misc_features, "SHA512"); }
if (supportsXOP()) { string::listAppend(misc_features, "supportsXOP"); }
str.append("\nOther Known Features: ").append(misc_features);

return str;
#elif SOUP_ARM
Expand All @@ -163,12 +183,11 @@ NAMESPACE_SOUP

void CpuInfo::invokeCpuid(void* out, uint32_t eax, uint32_t ecx) noexcept
{
#if defined(__GNUC__)
((uint32_t*)out)[3] = ecx;
__get_cpuid(eax, &((uint32_t*)out)[0], &((uint32_t*)out)[1], &((uint32_t*)out)[3], &((uint32_t*)out)[2]);
#else
#if defined(_MSC_VER) && !defined(__clang__)
__cpuidex(((int*)out), eax, ecx);
std::swap(((int*)out)[2], ((int*)out)[3]);
#else
__cpuid_count(eax, ecx, ((int*)out)[0], ((int*)out)[1], ((int*)out)[3], ((int*)out)[2]);
#endif
}
#endif
Expand Down
42 changes: 29 additions & 13 deletions src/vendor/Soup/soup/CpuInfo.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,30 @@ NAMESPACE_SOUP

#if SOUP_X86
uint32_t cpuid_max_eax;
uint64_t cpuid_extended_max_eax;
uint32_t cpuid_extended_max_eax;
ShortString<16> vendor_id;

uint8_t stepping_id;
uint8_t model;
uint8_t family;
uint32_t feature_flags_ecx;
uint32_t feature_flags_edx;
// EAX=1
uint8_t stepping_id = 0;
uint8_t model = 0;
uint8_t family = 0;
uint32_t feature_flags_ecx = 0;
uint32_t feature_flags_edx = 0;

// EAX=7, ECX=0
uint32_t extended_features_0_ebx;
uint32_t extended_features_max_ecx = 0;
uint32_t extended_features_0_ebx = 0;

// EAX=80000001h
uint64_t extended_features_1_ecx;
// EAX=7, ECX=1
uint32_t extended_features_1_eax = 0;

// EAX=16h
uint16_t base_frequency = 0;
uint16_t max_frequency = 0;
uint16_t bus_frequency = 0;

uint16_t base_frequency;
uint16_t max_frequency;
uint16_t bus_frequency;
// EAX=80000001h
uint32_t extended_flags_1_ecx = 0;

[[nodiscard]] bool supportsSSE() const noexcept
{
Expand Down Expand Up @@ -87,6 +93,11 @@ NAMESPACE_SOUP
return (feature_flags_ecx >> 25) & 1;
}

[[nodiscard]] bool supportsAVX() const noexcept
{
return (feature_flags_ecx >> 28) & 1;
}

[[nodiscard]] bool supportsRDRAND() const noexcept
{
return (feature_flags_ecx >> 30) & 1;
Expand All @@ -112,9 +123,14 @@ NAMESPACE_SOUP
return (extended_features_0_ebx >> 29) & 1;
}

[[nodiscard]] bool supportsSHA512() const noexcept
{
return (extended_features_1_eax >> 0) & 1;
}

[[nodiscard]] bool supportsXOP() const noexcept
{
return (extended_features_1_ecx >> 11) & 1;
return (extended_flags_1_ecx >> 11) & 1;
}

static void invokeCpuid(void* out, uint32_t eax) noexcept;
Expand Down
2 changes: 1 addition & 1 deletion src/vendor/Soup/soup/DetachedScheduler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ NAMESPACE_SOUP
closeReusableSockets();
}

void DetachedScheduler::addWorker(SharedPtr<Worker>&& w) SOUP_EXCAL
void DetachedScheduler::addWorker(SharedPtr<Worker>&& w)
{
Scheduler::addWorker(std::move(w));
if (!thrd.isRunning())
Expand Down
Loading

0 comments on commit 501d157

Please sign in to comment.