* Added most x86 cryptographic instructions
* Fixed popcnt test
* Fixed asm_ops_x64_2.c3t test
---------
Co-authored-by: Christoffer Lerno <christoffer@aegik.com>
* stdlib: implement `std::compression::zip` and `std::compression::deflate`
- C3 implementation of DEFLATE (RFC 1951) and ZIP archive handling.
- Support for reading and writing archives using STORE and DEFLATE
methods.
- Decompression supports both fixed and dynamic Huffman blocks.
- Compression using greedy LZ77 matching.
- Zero dependencies on libc.
- Stream-based entry reading and writing.
- Full unit test coverage.
NOTE: This is an initial implementation. Future improvements could be:
- Optimization of the LZ77 matching (lazy matching).
- Support for dynamic Huffman blocks in compression.
- ZIP64 support for large files/archives.
- Support for encryption and additional compression methods.
* optimizations+refactoring
deflate:
- replace linear search with hash-based match finding.
- implement support for dynamic Huffman blocks using the Package-Merge
algorithm.
- add streaming decompression.
- add buffered StreamBitReader.
zip:
- add ZIP64 support.
- add CP437 and UTF-8 filename encoding detection.
- add DOS date/time conversion and timestamp preservation.
- add ZipEntryReader for streaming entry reads.
- implement ZipArchive.extract and ZipArchive.recover helpers.
other:
- Add `set_modified_time` to std::io;
- Add benchmarks and a few more unit tests.
* zip: add archive comment support
add tests
* forgot to rename the benchmark :(
* detect utf8 names on weird zips
fix method not passed to open_writer
* another edge case where directory doesn't end with /
* testing utilities
- detect encrypted zip
- `ZipArchive.open_writer` default to DEFLATE
* fix zip64 creation, add tests
* fix ZIP header endianness for big-endian compatibility
Update ZipLFH, ZipCDH, ZipEOCD, Zip64EOCD, and Zip64Locator structs to
use little-endian bitstruct types from std::core::bitorder
* fix ZipEntryReader position tracking and seek logic ZIP_METHOD_STORE
added a test to track this
* add package-merge algorithm attribution
Thanks @konimarti
* standalone deflate_benchmark.c3 against `miniz`
* fix integer overflows, leaks and improve safety
* a few safety for 32-bit systems and tests
* deflate compress optimization
* improve match finding, hash updates, and buffer usage
* use ulong for zip offsets
* style changes (#18)
* style changes
* update tests
* style changes in `deflate.c3`
* fix typo
* Allocator first. Some changes to deflate to use `copy_to`
* Fix missing conversion on 32 bits.
* Fix deflate stream. Formatting. Prefer switch over if-elseif
* - Stream functions now use long/ulong rather than isz/usz for seek/available.
- `instream.seek` is replaced by `set_cursor` and `cursor`.
- `instream.available`, `cursor` etc are long/ulong rather than isz/usz to be correct on 32-bit.
* Update to constdef
* Fix test
---------
Co-authored-by: Book-reader <thevoid@outlook.co.nz>
Co-authored-by: Christoffer Lerno <christoffer@aegik.com>
* fixes for RISC-V ABI Implementation #1567
Fixed RISC-V floating-point ABI by correcting the target triple to
`riscv64-unknown-linux-gnu`, adding the `target-abi` module flag, and
ensuring ABI-required CPU features are enabled.
I tested this with:
```bash
build/c3c compile-only --target linux-riscv64 rv_hello.c3
readelf -h obj/linux-riscv64/rv_hello.o | grep Flags
# Output: Flags: 0x5, RVC, double-float ABI
```
```bash
# and qemu because I don't have a riscv machine :/
qemu-riscv64-static -L /usr/riscv64-linux-gnu ./rv_hello
```
---
@lerno I purposedly left these two failing tests to clearly see the
difference.
`test/test_suite/abi/riscv64-lp64-lp64f-abi-1.c3t`
`test/test_suite/abi/riscv64-lp64-abi.c3t`
* improve Linux cross-compilation, specifically for RISC-V
- Implement automatic sysroot and CRT object discovery for RISC-V.
- Fix dynamic linker paths and emulation flags for LLD.
- Link against libgcc to resolve required arithmetic symbols.
* Update tests.
* fix linker CRT detection by centralizing host arch check
use target_host_arch() in linker.c
move target_host_arch() from hostinfo.c to target.c
* missing debug info
---------
Co-authored-by: Christoffer Lerno <christoffer@aegik.com>
* math: implement discrete and continuous distributions
Implement a comprehensive set of continuous and discrete probability
distributions with support for PDF, CDF, inverse CDF, random sampling,
mean, and variance calculations.
The following distributions are implemented:
* Normal
* Uniform
* Exponential
* Chi-Squared
* F-Distribution
* Student t
* Binomial
* Poisson
* update releasenotes.md
* Formatting
---------
Co-authored-by: Christoffer Lerno <christoffer@aegik.com>
* Optimized adler32 implementations.
- Adapted adler32 implementation from Crypto++ public domain library.
- Added unit tests for adler32 hashing algorithm.
* tabified adler32 implementation to match stdlib.
* Formatting to be consistent. Make unrolling use macro.
---------
Co-authored-by: soerlemans <sebasoerlemans+git@gmail.com>
Co-authored-by: Christoffer Lerno <christoffer@aegik.com>
* split `test_hash_vector_macro` into per-type functions
it went from a single 18367 instructions function, to eleven separate
functions with (1000 to 1600) instructions each
thats 15649 instructions total, 2718 less instructions overall.
```
$ build/c3c compile-test --suppress-run -O1 --print-large-functions -D
SLOW_TESTS test/unit/ 2>&1 | sort -n | grep "test_hash_vector"
1041 instructions found in
std::core::builtins:test_hash_vector_int128
(/home/mb/scripts/c3c/test/unit/stdlib/core/builtintests.c3) - function
is very long.
1041 instructions found in
std::core::builtins:test_hash_vector_uint128
(/home/mb/scripts/c3c/test/unit/stdlib/core/builtintests.c3) - function
is very long.
1305 instructions found in std::core::builtins:test_hash_vector_long
(/home/mb/scripts/c3c/test/unit/stdlib/core/builtintests.c3) - function
is very long.
1305 instructions found in
std::core::builtins:test_hash_vector_ulong
(/home/mb/scripts/c3c/test/unit/stdlib/core/builtintests.c3) - function
is very long.
1453 instructions found in std::core::builtins:test_hash_vector_int
(/home/mb/scripts/c3c/test/unit/stdlib/core/builtintests.c3) - function
is very long.
1453 instructions found in std::core::builtins:test_hash_vector_uint
(/home/mb/scripts/c3c/test/unit/stdlib/core/builtintests.c3) - function
is very long.
1565 instructions found in
std::core::builtins:test_hash_vector_short
(/home/mb/scripts/c3c/test/unit/stdlib/core/builtintests.c3) - function
is very long.
1565 instructions found in
std::core::builtins:test_hash_vector_ushort
(/home/mb/scripts/c3c/test/unit/stdlib/core/builtintests.c3) - function
is very long.
1629 instructions found in std::core::builtins:test_hash_vector_char
(/home/mb/scripts/c3c/test/unit/stdlib/core/builtintests.c3) - function
is very long.
1629 instructions found in
std::core::builtins:test_hash_vector_ichar
(/home/mb/scripts/c3c/test/unit/stdlib/core/builtintests.c3) - function
is very long.
1663 instructions found in std::core::builtins:test_hash_vector_bool
(/home/mb/scripts/c3c/test/unit/stdlib/core/builtintests.c3) - function
is very long.
```
* made the `test_hash_vector_internal` generic
* optimize `test_ct_intlog2` while still covering all 128 bit positions
* refactor whirlpool to reduce code bloat
replaced the fully unrolled round loop with a runtime loop, reducing
instruction count by 80k in `process_block` and yielding aprox 30%
performance boost due to improved cache locality.
* use compile-time arrays for `test_ct_intlog2`
* codepage: add single-byte code page support
Add std::encoding::codepage with a shared engine for converting between
single-byte code pages and UTF-8 using table-driven mappings.
Introduce generated tables and wrappers for several code pages[1] each
exposing encode/decode helpers built on a common CodePageTable
structure.
The mapping data is generated by cpgen[2] from the Unicode Consortium’s
published code page mapping files and follows the Unicode standard’s
interpretation of control characters (abstract characters) rather than
historical VGA glyph shapes.
[1] Code page overview/groups:
DOS/OEM code pages (legacy PC):
cp437 cp737 cp775 cp850 cp852 cp855 cp857 cp860 cp861 cp862 cp863
cp864 cp865 cp866 cp869 cp874
Windows code pages (ANSI/Windows):
cp1250 cp1251 cp1252 cp1253 cp1254 cp1255 cp1256 cp1257 cp1258
ISO/IEC 8859 series (Latin/Regional):
iso_8859_1 iso_8859_2 iso_8859_3 iso_8859_4 iso_8859_5 iso_8859_6
iso_8859_7 iso_8859_8 iso_8859_9 iso_8859_10 iso_8859_11 iso_8859_13
iso_8859_14 iso_8859_15 iso_8859_16
[2] github.com/konimarti/cpgen
Signed-off-by: Koni Marti <koni.marti@gmail.com>
* codepage: change encoding format, streamline api
* Use enum to collect the data.
---------
Signed-off-by: Koni Marti <koni.marti@gmail.com>
Co-authored-by: Christoffer Lerno <christoffer@aegik.com>
* [stdlib] Add PEM Encoding/Decoding Module
* release notes
* Removed some unnecessary macro usages. Fixed memory handling with headers.
* Make end of line a parameter. Internal encode method -> function. Use more tmem. Remove t-functions.
* Update API
---------
Co-authored-by: Christoffer Lerno <christoffer@aegik.com>
Co-authored-by: Christoffer Lerno <christoffer.lerno@gmail.com>