{"id":23773025,"url":"https://github.com/awl-s/builtin-documentation","last_synced_at":"2026-04-30T19:32:28.880Z","repository":{"id":269244899,"uuid":"906841492","full_name":"Awl-S/builtin-documentation","owner":"Awl-S","description":" builtin documentation. This project showcases the usage of GCC/Clang built-in functions (__builtin_*) for performing low-level operations such as bit counting, memory manipulation, and overflow checking. Examples of function calls with explanations are provided. //  Этот проект демонстрирует использование встроенных функций GCC/Clang (__builtin_*)","archived":false,"fork":false,"pushed_at":"2024-12-22T04:36:45.000Z","size":17,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-21T05:15:41.470Z","etag":null,"topics":["arithmetic-overflow","bit-manipulation","built-in-functions","c","c-programming","clang","compiler-optimizations","cpp","cpp-programming","gcc","low-level-programming","memory-management"],"latest_commit_sha":null,"homepage":"https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Awl-S.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-12-22T04:15:11.000Z","updated_at":"2024-12-22T04:36:49.000Z","dependencies_parsed_at":"2024-12-22T05:30:12.944Z","dependency_job_id":null,"html_url":"https://github.com/Awl-S/builtin-documentation","commit_stats":null,"previous_names":["awl-s/bultin","awl-s/builtin"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Awl-S%2Fbuiltin-documentation","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Awl-S%2Fbuiltin-documentation/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Awl-S%2Fbuiltin-documentation/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Awl-S%2Fbuiltin-documentation/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Awl-S","download_url":"https://codeload.github.com/Awl-S/builtin-documentation/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239958308,"owners_count":19724926,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["arithmetic-overflow","bit-manipulation","built-in-functions","c","c-programming","clang","compiler-optimizations","cpp","cpp-programming","gcc","low-level-programming","memory-management"],"created_at":"2025-01-01T05:22:03.428Z","updated_at":"2026-04-02T08:30:17.184Z","avatar_url":"https://github.com/Awl-S.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"#### Перевод на русский [README_RU.md](README_RU.md)\n\n# GCC/Clang Built-in Functions Documentation\n\n## Introduction\nGCC and Clang compilers provide a set of built-in functions (`__builtin_*`) that allow programmers to directly utilize low-level operations, optimize code, and access processor-specific features. These functions are often mapped to hardware instructions or implemented in an efficient manner by the compiler.\n\n---\n\n## 1. Bit Manipulation Functions\nThese functions operate on bit-level representations of integers.\n\n### `__builtin_popcount`\n- **Description**: Counts the number of set bits (1s) in the binary representation of an `unsigned int`.\n- **Parameters**:\n  - `unsigned int x`: The input number.\n- **Return Value**: The number of 1s in the binary representation of `x`.\n\n### `__builtin_popcountl`\n- **Description**: Counts the number of set bits in an `unsigned long`.\n- **Parameters**:\n  - `unsigned long x`: The input number.\n- **Return Value**: The number of 1s in the binary representation of `x`.\n\n### `__builtin_popcountll`\n- **Description**: Counts the number of set bits in an `unsigned long long`.\n- **Parameters**:\n  - `unsigned long long x`: The input number.\n- **Return Value**: The number of 1s in the binary representation of `x`.\n\n### `__builtin_ctz`\n- **Description**: Counts the number of trailing zeros in an `unsigned int`.\n- **Parameters**:\n  - `unsigned int x`: The input number.\n- **Return Value**: The number of trailing zeros in the binary representation of `x`. Returns undefined if `x` is 0.\n\n### `__builtin_ctzl`\n- **Description**: Counts the number of trailing zeros in an `unsigned long`.\n- **Parameters**:\n  - `unsigned long x`: The input number.\n- **Return Value**: The number of trailing zeros in the binary representation of `x`. Returns undefined if `x` is 0.\n\n### `__builtin_ctzll`\n- **Description**: Counts the number of trailing zeros in an `unsigned long long`.\n- **Parameters**:\n  - `unsigned long long x`: The input number.\n- **Return Value**: The number of trailing zeros in the binary representation of `x`. Returns undefined if `x` is 0.\n\n### `__builtin_clz`\n- **Description**: Counts the number of leading zeros in an `unsigned int`.\n- **Parameters**:\n  - `unsigned int x`: The input number.\n- **Return Value**: The number of leading zeros in the binary representation of `x`. Returns undefined if `x` is 0.\n\n### `__builtin_clzl`\n- **Description**: Counts the number of leading zeros in an `unsigned long`.\n- **Parameters**:\n  - `unsigned long x`: The input number.\n- **Return Value**: The number of leading zeros in the binary representation of `x`. Returns undefined if `x` is 0.\n\n### `__builtin_clzll`\n- **Description**: Counts the number of leading zeros in an `unsigned long long`.\n- **Parameters**:\n  - `unsigned long long x`: The input number.\n- **Return Value**: The number of leading zeros in the binary representation of `x`. Returns undefined if `x` is 0.\n\n### `__builtin_parity`\n- **Description**: Returns the parity of the number of 1s in an `unsigned int`. Returns 1 if the number of 1s is odd, otherwise 0.\n- **Parameters**:\n  - `unsigned int x`: The input number.\n- **Return Value**: `1` if the number of 1s is odd, `0` otherwise.\n\n### `__builtin_parityl`\n- **Description**: Returns the parity of the number of 1s in an `unsigned long`.\n- **Parameters**:\n  - `unsigned long x`: The input number.\n- **Return Value**: `1` if the number of 1s is odd, `0` otherwise.\n\n### `__builtin_parityll`\n- **Description**: Returns the parity of the number of 1s in an `unsigned long long`.\n- **Parameters**:\n  - `unsigned long long x`: The input number.\n- **Return Value**: `1` if the number of 1s is odd, `0` otherwise.\n\n---\n\n## 2. Arithmetic Overflow Functions\nThese functions detect overflow conditions during arithmetic operations.\n\n### `__builtin_add_overflow`\n- **Description**: Performs addition and checks for overflow.\n- **Parameters**:\n  - `T x`: The first operand.\n  - `T y`: The second operand.\n  - `T* result`: Pointer to store the result.\n- **Return Value**: Returns `1` if overflow occurred, `0` otherwise.\n\n### `__builtin_sub_overflow`\n- **Description**: Performs subtraction and checks for overflow.\n- **Parameters**:\n  - `T x`: The first operand.\n  - `T y`: The second operand.\n  - `T* result`: Pointer to store the result.\n- **Return Value**: Returns `1` if overflow occurred, `0` otherwise.\n\n### `__builtin_mul_overflow`\n- **Description**: Performs multiplication and checks for overflow.\n- **Parameters**:\n  - `T x`: The first operand.\n  - `T y`: The second operand.\n  - `T* result`: Pointer to store the result.\n- **Return Value**: Returns `1` if overflow occurred, `0` otherwise.\n\n---\n\n## 3. Memory Manipulation Functions\nThese functions provide efficient ways to manipulate memory blocks.\n\n### `__builtin_memcpy`\n- **Description**: Copies a block of memory from the source to the destination.\n- **Parameters**:\n  - `void* dest`: Destination pointer.\n  - `const void* src`: Source pointer.\n  - `size_t n`: Number of bytes to copy.\n- **Return Value**: Returns a pointer to the destination (`dest`).\n\n### `__builtin_memset`\n- **Description**: Fills a block of memory with a specific value.\n- **Parameters**:\n  - `void* dest`: Pointer to the memory block to fill.\n  - `int c`: The value to fill.\n  - `size_t n`: Number of bytes to fill.\n- **Return Value**: Returns a pointer to the destination (`dest`).\n\n### `__builtin_memmove`\n- **Description**: Moves a block of memory from the source to the destination. Handles overlapping memory safely.\n- **Parameters**:\n  - `void* dest`: Destination pointer.\n  - `const void* src`: Source pointer.\n  - `size_t n`: Number of bytes to move.\n- **Return Value**: Returns a pointer to the destination (`dest`).\n\n---\n\n## 4. Control Flow Optimization\nThese functions provide hints to the compiler for optimizing control flow.\n\n### `__builtin_expect`\n- **Description**: Provides the compiler with branch prediction information.\n- **Parameters**:\n  - `long exp`: The expression to evaluate.\n  - `long c`: The expected value of the expression.\n- **Return Value**: Returns the value of `exp`. The compiler optimizes for the assumption that `exp == c`.\n\n---\n\n## 5. Type Checking and Constants\nThese functions help in type checking and constant evaluation.\n\n### `__builtin_types_compatible_p`\n- **Description**: Checks whether two types are compatible.\n- **Parameters**:\n  - `T1`: The first type.\n  - `T2`: The second type.\n- **Return Value**: Returns `1` if the types are compatible, otherwise `0`.\n\n### `__builtin_constant_p`\n- **Description**: Checks if a value is a compile-time constant.\n- **Parameters**:\n  - `exp`: The expression to check.\n- **Return Value**: Returns `1` if the expression is a compile-time constant, otherwise `0`.\n\n---\n\n## 6. Math and Utility Functions\nThese functions provide basic mathematical and utility operations.\n\n### `__builtin_abs`\n- **Description**: Returns the absolute value of an integer.\n- **Parameters**:\n  - `int x`: The input integer.\n- **Return Value**: The absolute value of `x`.\n\n### `__builtin_labs`\n- **Description**: Returns the absolute value of a `long` integer.\n- **Parameters**:\n  - `long x`: The input integer.\n- **Return Value**: The absolute value of `x`.\n\n### `__builtin_llabs`\n- **Description**: Returns the absolute value of a `long long` integer.\n- **Parameters**:\n  - `long long x`: The input integer.\n- **Return Value**: The absolute value of `x`.\n\n---\n\n## Notes\n1. These built-in functions are platform-specific and optimized by the compiler.\n2. Some functions, such as `__builtin_expect`, may not provide runtime benefits on all platforms but assist in compiler optimization.\n3. Functions like `__builtin_popcount` may leverage hardware instructions (e.g., POPCNT) if supported by the CPU.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fawl-s%2Fbuiltin-documentation","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fawl-s%2Fbuiltin-documentation","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fawl-s%2Fbuiltin-documentation/lists"}