Skip to content

Commit

Permalink
Update c/cplusplus docs
Browse files Browse the repository at this point in the history
  • Loading branch information
LivInTheLookingGlass committed Aug 15, 2024
1 parent 2ff9811 commit 5f7eaae
Show file tree
Hide file tree
Showing 14 changed files with 86 additions and 65 deletions.
15 changes: 2 additions & 13 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
19 changes: 6 additions & 13 deletions cplusplus/src/include/macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
4 changes: 1 addition & 3 deletions cplusplus/src/tests/test_compiler_macros.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 3 additions & 5 deletions cplusplus/test_euler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
28 changes: 17 additions & 11 deletions docs/src/c/lib/bcd.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://en.wikipedia.org/wiki/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.
Expand All @@ -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
Expand All @@ -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)
Expand Down
7 changes: 7 additions & 0 deletions docs/src/c/lib/digits.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions docs/src/c/lib/factors.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 <IteratorHead>` 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.
Expand Down
6 changes: 6 additions & 0 deletions docs/src/c/lib/fibonacci.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions docs/src/c/lib/iterator.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
11 changes: 3 additions & 8 deletions docs/src/c/lib/macros.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 <https://stackoverflow.com/q/109710>`__ to assist in branch prediction. On ``tcc`` and ``cl`` it has
no effect.
.. c:macro:: MAX_FACTORIAL_64
MAX_FACTORIAL_128
Expand Down
9 changes: 7 additions & 2 deletions docs/src/c/lib/math.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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::
Expand Down
7 changes: 7 additions & 0 deletions docs/src/c/lib/primes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 6 additions & 10 deletions docs/src/cplusplus/lib/macros.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 <https://stackoverflow.com/q/109710>`__ 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
Expand Down
5 changes: 5 additions & 0 deletions docs/src/cplusplus/lib/math.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 5f7eaae

Please sign in to comment.