From 5f7eaaecad38940a4b5697f3ad14bd7013436f71 Mon Sep 17 00:00:00 2001 From: Olivia Appleton Date: Thu, 15 Aug 2024 00:23:07 -0500 Subject: [PATCH] Update c/cplusplus docs --- .gitattributes | 15 ++--------- cplusplus/src/include/macros.h | 19 +++++-------- cplusplus/src/tests/test_compiler_macros.cpp | 4 +-- cplusplus/test_euler.py | 8 +++--- docs/src/c/lib/bcd.rst | 28 ++++++++++++-------- docs/src/c/lib/digits.rst | 7 +++++ docs/src/c/lib/factors.rst | 6 +++++ docs/src/c/lib/fibonacci.rst | 6 +++++ docs/src/c/lib/iterator.rst | 10 +++++++ docs/src/c/lib/macros.rst | 11 +++----- docs/src/c/lib/math.rst | 9 +++++-- docs/src/c/lib/primes.rst | 7 +++++ docs/src/cplusplus/lib/macros.rst | 16 +++++------ docs/src/cplusplus/lib/math.rst | 5 ++++ 14 files changed, 86 insertions(+), 65 deletions(-) diff --git a/.gitattributes b/.gitattributes index 378eda94..fb88970a 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,4 +1,6 @@ c/Unity/* linguist-vendored +c/wasi-libc/* linguist-vendored +cplusplus/Unity/* linguist-vendored c/*.c linguist-language=c c/*.h linguist-language=c @@ -9,16 +11,3 @@ cplusplus/*.cpp linguist-language=c++ cplusplus/*.h linguist-language=c++ cplusplus/*/*.cpp linguist-language=c++ cplusplus/*/*.h linguist-language=c++ - -*.rst linguist-language=reStructuredText -*/*.rst linguist-language=reStructuredText -*/*/*.rst linguist-language=reStructuredText - -*.yml linguist-language=yaml -*.yaml linguist-language=yaml -*/*.yml linguist-language=yaml -*/*.yaml linguist-language=yaml -*/*/*.yml linguist-language=yaml -*/*/*.yaml linguist-language=yaml - -javascript/index.html linguist-vendored diff --git a/cplusplus/src/include/macros.h b/cplusplus/src/include/macros.h index 0737cd00..d56923ac 100644 --- a/cplusplus/src/include/macros.h +++ b/cplusplus/src/include/macros.h @@ -8,27 +8,16 @@ #else #define CL_COMPILER 0 #endif -#if (defined(__clang__) && (!defined(AMD_COMPILER) || !AMD_COMPILER)) +#if (defined(__clang__)) #define CLANG_COMPILER 1 #else #define CLANG_COMPILER 0 #endif -#if (defined(__GNUC__) && !defined(__clang__)) && !defined(__INTEL_COMPILER) +#if (defined(__GNUC__) && !defined(__clang__)) #define GCC_COMPILER 1 #else #define GCC_COMPILER 0 #endif -#ifdef __INTEL_COMPILER - #define INTEL_COMPILER 1 -#else - #define INTEL_COMPILER 0 -#endif -#ifndef AMD_COMPILER - #if CLANG_COMPILER - #warning "This suite can't detect the difference between clang and aocc. You need to specify -DAMD_COMPILER={0 or 1}" - #endif - #define AMD_COMPILER 0 -#endif #if (defined(_M_X64) || defined(_M_AMD64) || defined(__amd64__) || defined(__amd64) || defined(__x86_64__) || defined(__x86_64)) #define X64_COMPILER 1 @@ -53,6 +42,10 @@ // helper macro function section +#ifndef swap + #define swap(x, y) do { typeof(x) SWAP = x; x = y; y = SWAP; } while (0) +#endif + #if !(CL_COMPILER) #define likely(x) __builtin_expect(!!(x), 1) #define unlikely(x) __builtin_expect(!!(x), 0) diff --git a/cplusplus/src/tests/test_compiler_macros.cpp b/cplusplus/src/tests/test_compiler_macros.cpp index eaa4aec5..0c273b78 100644 --- a/cplusplus/src/tests/test_compiler_macros.cpp +++ b/cplusplus/src/tests/test_compiler_macros.cpp @@ -3,12 +3,10 @@ int main(int argc, char const *argv[]) { printf( - "%d %d %d %d %d %d %d %d", + "%d %d %d %d %d %d", CL_COMPILER, CLANG_COMPILER, GCC_COMPILER, - INTEL_COMPILER, - AMD_COMPILER, X86_COMPILER, X64_COMPILER, ARM_COMPILER diff --git a/cplusplus/test_euler.py b/cplusplus/test_euler.py index 2f2bccfc..2e6b33cb 100644 --- a/cplusplus/test_euler.py +++ b/cplusplus/test_euler.py @@ -211,11 +211,9 @@ def test_compiler_macros(compiler): assert flags[0] == compiler.startswith("CL+") assert flags[1] == compiler.startswith("CLANG") assert flags[2] == compiler.startswith("GCC") - assert flags[3] == compiler.startswith("ICC") - assert flags[4] == compiler.startswith("AOCC") - assert flags[5] == (EXE_EXT == "x86" or expect_32) - assert flags[6] == (EXE_EXT == "x86_64" and not expect_32) - assert flags[7] == (EXE_EXT not in ("x86", "x86_64", "exe")) + assert flags[3] == (EXE_EXT == "x86" or expect_32) + assert flags[4] == (EXE_EXT == "x86_64" and not expect_32) + assert flags[5] == (EXE_EXT not in ("x86", "x86_64", "exe")) # @mark.skipif('NO_OPTIONAL_TESTS or ONLY_SLOW') diff --git a/docs/src/c/lib/bcd.rst b/docs/src/c/lib/bcd.rst index 982d332d..e29c813d 100644 --- a/docs/src/c/lib/bcd.rst +++ b/docs/src/c/lib/bcd.rst @@ -3,6 +3,12 @@ bcd.h View source code :source:`c/src/include/bcd.h` +Includes +-------- + +- `macros.h <./macros.html>`__ +- `math.h <./math.html>`__ (if compiled on PCC) + This library implements a `Binary Coded Decimal `__ object in C. Mostly this is done to prove that I could, but also because it allows for incredibly easy printing of arbitrary-sized integers. It was also a good exercise in x86 assembly, as several portions are accellerated by handcrafted assembly. @@ -26,7 +32,7 @@ It was also a good exercise in x86 assembly, as several portions are accellerate .. c:member:: size_t decimal_digits - This field indicates the number of decimal digits encoded. It should be within 1 of ``2*bcd_digits``. + This field indicates the number of decimal digits encoded. It should be within 1 of :c:expr:`2*bcd_digits`. .. c:member:: bool negative : 1 @@ -51,45 +57,45 @@ It was also a good exercise in x86 assembly, as several portions are accellerate .. c:function:: BCD_int add_bcd(BCD_int x, BCD_int y) - Returns ``x + y``. + Returns :c:expr:`x + y`. .. c:function:: BCD_int sub_bcd(BCD_int x, BCD_int y) - Returns ``x - y``. + Returns :c:expr:`x - y`. .. c:function:: BCD_int mul_bcd_cuint(BCD_int x, uintmax_t y) - Returns ``x * y``, handling type conversion for you. + Returns :c:expr:`x * y`, handling type conversion for you. .. c:function:: BCD_int pow_cuint_cuint(uintmax_t x, uintmax_t y) - Returns ``x ** y``, handling type conversion for you. + Returns :c:expr:`pow(x, y)`, handling type conversion for you. .. c:function:: BCD_int mul_bcd(BCD_int x, BCD_int y) - Returns ``x * y``. + Returns :c:expr:`x * y`. .. c:function:: BCD_int pow_bcd(BCD_int x, BCD_int y) - Returns ``x ** y``. + Returns :c:expr:`pow(x, y)`. .. c:function:: BCD_int mul_bcd_pow_10(BCD_int x, uintmax_t tens) BCD_int shift_bcd_left(BCD_int x, uintmax_t tens) - Returns ``x * 10**tens``. + Returns :c:expr:`x * pow(10, tens)`. .. c:function:: BCD_int div_bcd_pow_10(BCD_int a, uintmax_t tens) BCD_int shift_bcd_right(BCD_int a, uintmax_t tens) - Returns ``x // 10**tens``. + Returns :c:expr:`x / pow(10, tens)`. .. c:function:: void iadd_bcd(BCD_int *const x, const BCD_int y) - Transforms ``x`` to be ``x + y`` without needing to make a new assignment. + Transforms :c:expr:`x` to be :c:expr:`x + y` without needing to make a new assignment. .. c:function:: signed char cmp_bcd(BCD_int x, BCD_int y) - Returns 1 if ``x > y``, -1 if ``y > x``, and otherwise 0. + Returns 1 if :c:expr:`x > y`, -1 if :c:expr:`y > x`, and otherwise 0. .. c:function:: void print_bcd(BCD_int x) void print_bcd_ln(BCD_int x) diff --git a/docs/src/c/lib/digits.rst b/docs/src/c/lib/digits.rst index 15de049a..66510bb9 100644 --- a/docs/src/c/lib/digits.rst +++ b/docs/src/c/lib/digits.rst @@ -3,6 +3,13 @@ digits.h View source code :source:`c/src/include/digits.h` +Includes +-------- + +- `iterator.h <./iterator.html>`__ +- `macros.h <./macros.html>`__ +- `math.h <./math.html>`__ (if compiled on PCC) + .. c:namespace-push:: digits .. c:type:: digit_counter diff --git a/docs/src/c/lib/factors.rst b/docs/src/c/lib/factors.rst index 9fb7c72c..be762491 100644 --- a/docs/src/c/lib/factors.rst +++ b/docs/src/c/lib/factors.rst @@ -3,6 +3,12 @@ factors.h View source code :source:`c/src/include/factors.h` +Includes +-------- + +- `iterator.h <./iterator.html>`__ +- `macros.h <./macros.html>`__ (implicitly) + This file implements an :c:macro:`Iterator ` that yields proper factors for a given number. It is generally used by first calling :c:func:`proper_divisor_count` and the :c:macro:`next`/:c:macro:`next_p` functions. diff --git a/docs/src/c/lib/fibonacci.rst b/docs/src/c/lib/fibonacci.rst index 66822e08..82509d0a 100644 --- a/docs/src/c/lib/fibonacci.rst +++ b/docs/src/c/lib/fibonacci.rst @@ -3,6 +3,12 @@ fibonacci.h View source code :source:`c/src/include/fibonacci.h` +Includes +-------- + +- `iterator.h <./iterator.html>`__ +- `macros.h <./macros.html>`__ (implicitly) + .. c:namespace-push:: fibonacci .. c:type:: fibonacci diff --git a/docs/src/c/lib/iterator.rst b/docs/src/c/lib/iterator.rst index 699cccbc..e9fbfb75 100644 --- a/docs/src/c/lib/iterator.rst +++ b/docs/src/c/lib/iterator.rst @@ -3,6 +3,16 @@ iterator.h View source code :source:`c/src/include/iterator.h` +Includes +-------- + +- `macros.h <./macros.html>`__ + +Includes +-------- + +- `macros.h <./macros.html>`__ + .. c:namespace-push:: iterator .. c:macro:: IteratorHead(return_type, struct_type) diff --git a/docs/src/c/lib/macros.rst b/docs/src/c/lib/macros.rst index 77162ce4..9bec649d 100644 --- a/docs/src/c/lib/macros.rst +++ b/docs/src/c/lib/macros.rst @@ -14,12 +14,6 @@ View source code :source:`c/src/include/macros.h` These macros detect which compiler the program is being made with. They will be 1 if it is that compiler, and 0 otherwise. - .. warning:: - - This suite is not able to detect the difference between ``clang`` and ``aocc`` - without assistance. Please define :c:macro:`AMD_COMPILER` manually if on - ``clang`` or ``aocc``. - .. c:macro:: X64_COMPILER X86_COMPILER ARM_COMPILER @@ -39,8 +33,9 @@ View source code :source:`c/src/include/macros.h` .. c:macro:: likely(x) unlikely(x) - These macros implement the ``likely()`` and ``unlikely()`` flags, as in the Linux kernel to - assist in branch prediction. On ``tcc`` and ``cl`` it has no effect. + These macros implement the ``likely()`` and ``unlikely()`` flags, as in the + `Linux kernel `__ to assist in branch prediction. On ``tcc`` and ``cl`` it has + no effect. .. c:macro:: MAX_FACTORIAL_64 MAX_FACTORIAL_128 diff --git a/docs/src/c/lib/math.rst b/docs/src/c/lib/math.rst index f67fc13d..bf60c7d6 100644 --- a/docs/src/c/lib/math.rst +++ b/docs/src/c/lib/math.rst @@ -3,6 +3,11 @@ math.h View source code :source:`c/src/include/math.h` +Includes +-------- + +- `macros.h <./macros.html>`__ + .. c:namespace-push:: math .. c:function:: uintmax_t factorial(unsigned int n) @@ -11,7 +16,7 @@ View source code :source:`c/src/include/math.h` This function only works for numbers smaller than :c:macro:`MAX_FACTORIAL_64` or :c:macro:`MAX_FACTORIAL_128`, - depending on the size of ``uintmax_t``. + depending on the size of :c:expr:`uintmax_t`. .. c:function:: uintmax_t n_choose_r(unsigned int n, unsigned int r) @@ -21,7 +26,7 @@ View source code :source:`c/src/include/math.h` This function only works for numbers smaller than :c:macro:`MAX_FACTORIAL_64` or :c:macro:`MAX_FACTORIAL_128`, - depending on the size of ``uintmax_t``. + depending on the size of :c:expr:`uintmax_t`. .. note:: diff --git a/docs/src/c/lib/primes.rst b/docs/src/c/lib/primes.rst index fa75770a..4c96f628 100644 --- a/docs/src/c/lib/primes.rst +++ b/docs/src/c/lib/primes.rst @@ -3,6 +3,13 @@ primes.h View source code :source:`c/src/include/primes.h` +Includes +-------- + +- `iterator.h <./iterator.html>`__ +- `macros.h <./macros.html>`__ +- `math.h <./math.html>`__ (if compiled on PCC) + .. c:namespace-push:: primes .. c:type:: prime_counter diff --git a/docs/src/cplusplus/lib/macros.rst b/docs/src/cplusplus/lib/macros.rst index d82c4751..0390947e 100644 --- a/docs/src/cplusplus/lib/macros.rst +++ b/docs/src/cplusplus/lib/macros.rst @@ -8,18 +8,10 @@ View source code :source:`cplusplus/src/include/macros.h` .. c:macro:: CL_COMPILER CLANG_COMPILER GCC_COMPILER - INTEL_COMPILER - AMD_COMPILER These macros detect which compiler the program is being made with. They will be 1 if it is that compiler, and 0 otherwise. - .. warning:: - - This suite is not able to detect the difference between ``clang`` and ``aocc`` - without assistance. Please define :c:macro:`AMD_COMPILER` manually if on - ``clang`` or ``aocc``. - .. c:macro:: X64_COMPILER X86_COMPILER ARM_COMPILER @@ -30,8 +22,12 @@ View source code :source:`cplusplus/src/include/macros.h` .. c:macro:: likely(x) unlikely(x) - These macros implement the ``likely()`` and ``unlikely()`` flags, as in the Linux kernel to - assist in branch prediction. On ``tcc`` and ``cl`` it has no effect. + These macros implement the ``likely()`` and ``unlikely()`` flags, as in the + `Linux kernel `__ to assist in branch prediction. On ``cl`` it has no effect. + +.. c:macro:: swap(x, y) + + Swap the names of two variables of the same type. .. c:macro:: MAX_FACTORIAL_64 MAX_FACTORIAL_128 diff --git a/docs/src/cplusplus/lib/math.rst b/docs/src/cplusplus/lib/math.rst index 8e059967..80b3673f 100644 --- a/docs/src/cplusplus/lib/math.rst +++ b/docs/src/cplusplus/lib/math.rst @@ -3,6 +3,11 @@ math.h View source code :source:`cplusplus/src/include/math.h` +Includes +-------- + +- `macros.h <./macros.html>`__ + .. c:namespace-push:: math .. c:function:: uintmax_t factorial(unsigned int n)