├── .eslintrc.js ├── .github └── workflows │ ├── ci.yml │ └── lint.yml ├── LICENSE ├── README.md ├── binding.gyp ├── buildcheck.js ├── deps └── cpu_features │ ├── .clang-format │ ├── .dockerignore │ ├── .github │ └── workflows │ │ ├── Dockerfile │ │ ├── aarch64_linux_cmake.yml │ │ ├── amd64_freebsd_cmake.yml │ │ ├── amd64_linux_bazel.yml │ │ ├── amd64_linux_cmake.yml │ │ ├── amd64_macos_cmake.yml │ │ ├── amd64_windows_cmake.yml │ │ ├── arm_linux_cmake.yml │ │ ├── clang_format.yml │ │ ├── mips_linux_cmake.yml │ │ ├── power_linux_cmake.yml │ │ ├── riscv_linux_cmake.yml │ │ └── s390x_linux_cmake.yml │ ├── .gitignore │ ├── .grenrc.yml │ ├── BUILD.bazel │ ├── CMakeLists.txt │ ├── CONTRIBUTING.md │ ├── LICENSE │ ├── README.md │ ├── WORKSPACE │ ├── bazel │ ├── ci │ │ └── README.md │ └── platforms.bzl │ ├── cmake │ ├── CpuFeaturesConfig.cmake.in │ ├── CpuFeaturesNdkCompatConfig.cmake.in │ ├── README.md │ ├── ci │ │ ├── Makefile │ │ ├── README.md │ │ ├── doc │ │ │ ├── docker.dot │ │ │ ├── docker.svg │ │ │ └── generate_image.sh │ │ ├── docker │ │ │ ├── amd64 │ │ │ │ └── Dockerfile │ │ │ └── toolchain │ │ │ │ └── Dockerfile │ │ ├── sample │ │ │ ├── CMakeLists.txt │ │ │ └── main.cpp │ │ └── vagrant │ │ │ └── freebsd │ │ │ └── Vagrantfile │ └── googletest.CMakeLists.txt.in │ ├── cpu_features.gyp │ ├── include │ ├── cpu_features_cache_info.h │ ├── cpu_features_macros.h │ ├── cpuinfo_aarch64.h │ ├── cpuinfo_arm.h │ ├── cpuinfo_mips.h │ ├── cpuinfo_ppc.h │ ├── cpuinfo_riscv.h │ ├── cpuinfo_s390x.h │ ├── cpuinfo_x86.h │ └── internal │ │ ├── bit_utils.h │ │ ├── cpuid_x86.h │ │ ├── filesystem.h │ │ ├── hwcaps.h │ │ ├── stack_line_reader.h │ │ ├── string_view.h │ │ └── windows_utils.h │ ├── ndk_compat │ ├── CMakeLists.txt │ ├── README.md │ ├── cpu-features.c │ ├── cpu-features.h │ └── ndk-compat-test.c │ ├── patches │ └── 0001-Add-Apple-Silicon-Support.patch │ ├── scripts │ ├── generate_badges.d │ ├── make_release.sh │ ├── run_integration.sh │ └── test_integration.sh │ ├── src │ ├── copy.inl │ ├── define_introspection.inl │ ├── define_introspection_and_hwcaps.inl │ ├── equals.inl │ ├── filesystem.c │ ├── hwcaps.c │ ├── impl_aarch64__base_implementation.inl │ ├── impl_aarch64_linux_or_android.c │ ├── impl_aarch64_macos_or_iphone.c │ ├── impl_aarch64_windows.c │ ├── impl_arm_linux_or_android.c │ ├── impl_mips_linux_or_android.c │ ├── impl_ppc_linux.c │ ├── impl_riscv_linux.c │ ├── impl_s390x_linux.c │ ├── impl_x86__base_implementation.inl │ ├── impl_x86_freebsd.c │ ├── impl_x86_linux_or_android.c │ ├── impl_x86_macos.c │ ├── impl_x86_windows.c │ ├── stack_line_reader.c │ ├── string_view.c │ └── utils │ │ └── list_cpu_features.c │ └── test │ ├── CMakeLists.txt │ ├── bit_utils_test.cc │ ├── cpuinfo_aarch64_test.cc │ ├── cpuinfo_arm_test.cc │ ├── cpuinfo_mips_test.cc │ ├── cpuinfo_ppc_test.cc │ ├── cpuinfo_riscv_test.cc │ ├── cpuinfo_s390x_test.cc │ ├── cpuinfo_x86_test.cc │ ├── filesystem_for_testing.cc │ ├── filesystem_for_testing.h │ ├── hwcaps_for_testing.cc │ ├── hwcaps_for_testing.h │ ├── stack_line_reader_test.cc │ └── string_view_test.cc ├── lib └── index.js ├── package.json ├── src └── binding.cc └── test └── test.js /.eslintrc.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | module.exports = { 4 | extends: '@mscdex/eslint-config', 5 | }; 6 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | 3 | on: 4 | pull_request: 5 | push: 6 | branches: [ master ] 7 | 8 | jobs: 9 | tests-linux: 10 | runs-on: ubuntu-latest 11 | strategy: 12 | fail-fast: false 13 | matrix: 14 | node-version: [10.x, 12.x, 14.x, 16.x, 18.x, 20.x, 22.x] 15 | steps: 16 | - uses: actions/checkout@v4 17 | with: 18 | persist-credentials: false 19 | - name: Use Node.js ${{ matrix.node-version }} 20 | uses: actions/setup-node@v4 21 | with: 22 | node-version: ${{ matrix.node-version }} 23 | - name: Check Node.js version 24 | run: node -pe process.versions 25 | - name: Check npm version 26 | run: npm -v 27 | - name: Install Python 2.7 (node <16.x) 28 | if: ${{ contains(fromJSON('["10.x", "12.x", "14.x"]'), matrix.node-version) }} 29 | uses: LizardByte/setup-python-action@v2024.1105.190605 30 | with: 31 | python-version: '2.7' 32 | - name: Use Python 2.7 (node <16.x) 33 | if: ${{ contains(fromJSON('["10.x", "12.x", "14.x"]'), matrix.node-version) }} 34 | run: echo "PYTHON=$(which python2.7)" >> "$GITHUB_ENV" 35 | - name: Install module 36 | run: npm install 37 | - name: Run tests 38 | run: npm test 39 | tests-macos: 40 | runs-on: macos-latest 41 | strategy: 42 | fail-fast: false 43 | matrix: 44 | node-version: [16.x, 18.x, 20.x, 22.x] 45 | env: 46 | PIP_DISABLE_PIP_VERSION_CHECK: 1 47 | steps: 48 | - uses: actions/checkout@v4 49 | with: 50 | persist-credentials: false 51 | - name: Use Node.js ${{ matrix.node-version }} 52 | uses: actions/setup-node@v4 53 | with: 54 | node-version: ${{ matrix.node-version }} 55 | - name: Install Python 3.10 56 | uses: actions/setup-python@v5 57 | with: 58 | python-version: '3.10' 59 | - name: Check Node.js version 60 | run: node -pe process.versions 61 | - name: Check npm version 62 | run: npm -v 63 | - name: Install module 64 | run: npm install 65 | - name: Run tests 66 | run: npm test 67 | tests-windows: 68 | runs-on: windows-2019 69 | strategy: 70 | fail-fast: false 71 | matrix: 72 | node-version: [10.x, 12.x, 14.x, 16.x, 18.x, 20.x, 22.x] 73 | steps: 74 | - uses: actions/checkout@v4 75 | with: 76 | persist-credentials: false 77 | - name: Use Node.js ${{ matrix.node-version }} 78 | uses: actions/setup-node@v4 79 | with: 80 | node-version: ${{ matrix.node-version }} 81 | - name: Check Node.js version 82 | run: node -pe process.versions 83 | - name: Check npm version 84 | run: npm -v 85 | - name: Install module 86 | run: npm install 87 | - name: Run tests 88 | run: npm test 89 | -------------------------------------------------------------------------------- /.github/workflows/lint.yml: -------------------------------------------------------------------------------- 1 | name: lint 2 | 3 | on: 4 | pull_request: 5 | push: 6 | branches: [ master ] 7 | 8 | env: 9 | NODE_VERSION: 20.x 10 | 11 | jobs: 12 | lint-js: 13 | runs-on: ubuntu-latest 14 | steps: 15 | - uses: actions/checkout@v4 16 | with: 17 | persist-credentials: false 18 | - name: Use Node.js ${{ env.NODE_VERSION }} 19 | uses: actions/setup-node@v4 20 | with: 21 | node-version: ${{ env.NODE_VERSION }} 22 | - name: Check Node.js version 23 | run: node -pe process.versions 24 | - name: Install ESLint + ESLint configs/plugins 25 | run: npm install 26 | - name: Lint files 27 | run: npm run lint 28 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright Brian White. All rights reserved. 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to 5 | deal in the Software without restriction, including without limitation the 6 | rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | sell copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | IN THE SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | Description 3 | =========== 4 | 5 | A simple [node.js](https://nodejs.org) binding to [cpu_features](https://github.com/google/cpu_features) for obtaining information about installed CPU(s). 6 | 7 | 8 | Requirements 9 | ============ 10 | 11 | * [node.js](http://nodejs.org/) -- v10.0.0 or newer 12 | * An appropriate build environment -- see [node-gyp's documentation](https://github.com/nodejs/node-gyp/blob/master/README.md) 13 | 14 | 15 | Install 16 | ======= 17 | 18 | npm install cpu-features 19 | 20 | 21 | Example 22 | ======= 23 | 24 | ```js 25 | // Generally it's a good idea to just call this once and 26 | // reuse the result since `cpu-features` does not cache 27 | // the result itself. 28 | const features = require('cpu-features')(); 29 | 30 | console.log(features); 31 | // example output: 32 | // { arch: 'x86', 33 | // brand: 'Intel(R) Core(TM) i7-3770K CPU @ 3.50GHz', 34 | // family: 6, 35 | // model: 58, 36 | // stepping: 9, 37 | // uarch: 'INTEL_IVB', 38 | // flags: 39 | // { fpu: true, 40 | // tsc: true, 41 | // cx8: true, 42 | // clfsh: true, 43 | // mmx: true, 44 | // aes: true, 45 | // erms: true, 46 | // f16c: true, 47 | // sse: true, 48 | // sse2: true, 49 | // sse3: true, 50 | // ssse3: true, 51 | // sse4_1: true, 52 | // sse4_2: true, 53 | // avx: true, 54 | // pclmulqdq: true, 55 | // cx16: true, 56 | // popcnt: true, 57 | // rdrnd: true, 58 | // ss: true } } 59 | ``` 60 | -------------------------------------------------------------------------------- /binding.gyp: -------------------------------------------------------------------------------- 1 | { 2 | 'targets': [ 3 | { 4 | 'target_name': 'cpufeatures', 5 | 'dependencies': [ 'deps/cpu_features/cpu_features.gyp:cpu_features' ], 6 | 'include_dirs': [ 7 | 'src', 8 | " bazel.gpg 20 | sudo mv bazel.gpg /etc/apt/trusted.gpg.d/ 21 | echo "deb [arch=amd64] https://storage.googleapis.com/bazel-apt stable jdk1.8" | sudo tee /etc/apt/sources.list.d/bazel.list 22 | sudo apt-get update 23 | sudo apt-get install bazel 24 | bazel --version 25 | - name: Test 26 | run: bazel test -s --verbose_failures //... 27 | -------------------------------------------------------------------------------- /deps/cpu_features/.github/workflows/amd64_linux_cmake.yml: -------------------------------------------------------------------------------- 1 | name: amd64 Linux CMake 2 | 3 | on: 4 | push: 5 | pull_request: 6 | schedule: 7 | # min hours day(month) month day(week) 8 | - cron: '0 0 7,22 * *' 9 | 10 | jobs: 11 | # Building using the github runner environement directly. 12 | make: 13 | runs-on: ubuntu-latest 14 | steps: 15 | - uses: actions/checkout@v2 16 | - name: Env 17 | run: make --directory=cmake/ci amd64_env 18 | - name: Devel 19 | run: make --directory=cmake/ci amd64_devel 20 | - name: Build 21 | run: make --directory=cmake/ci amd64_build 22 | - name: Test 23 | run: make --directory=cmake/ci amd64_test 24 | - name: Install Env 25 | run: make --directory=cmake/ci amd64_install_env 26 | - name: Install Devel 27 | run: make --directory=cmake/ci amd64_install_devel 28 | - name: Install Build 29 | run: make --directory=cmake/ci amd64_install_build 30 | - name: Install Test 31 | run: make --directory=cmake/ci amd64_install_test 32 | -------------------------------------------------------------------------------- /deps/cpu_features/.github/workflows/amd64_macos_cmake.yml: -------------------------------------------------------------------------------- 1 | name: amd64 MacOS CMake 2 | 3 | on: 4 | push: 5 | pull_request: 6 | schedule: 7 | # min hours day(month) month day(week) 8 | - cron: '0 0 7,22 * *' 9 | 10 | jobs: 11 | # Building using the github runner environement directly. 12 | xcode: 13 | runs-on: macos-latest 14 | env: 15 | CTEST_OUTPUT_ON_FAILURE: 1 16 | steps: 17 | - uses: actions/checkout@v2 18 | - name: Check cmake 19 | run: cmake --version 20 | - name: Configure 21 | run: cmake -S. -Bbuild -G "Xcode" -DCMAKE_CONFIGURATION_TYPES=Release 22 | - name: Build 23 | run: cmake --build build --config Release --target ALL_BUILD -v 24 | - name: Test 25 | run: cmake --build build --config Release --target RUN_TESTS -v 26 | - name: Install 27 | run: cmake --build build --config Release --target install -v 28 | make: 29 | runs-on: macos-latest 30 | env: 31 | CTEST_OUTPUT_ON_FAILURE: 1 32 | steps: 33 | - uses: actions/checkout@v2 34 | - name: Check cmake 35 | run: cmake --version 36 | - name: Configure 37 | run: cmake -S. -Bbuild -DCMAKE_BUILD_TYPE=Release 38 | - name: Build 39 | run: cmake --build build --target all -v 40 | - name: Test 41 | run: cmake --build build --target test -v 42 | - name: Install 43 | run: cmake --build build --target install -v 44 | -------------------------------------------------------------------------------- /deps/cpu_features/.github/workflows/amd64_windows_cmake.yml: -------------------------------------------------------------------------------- 1 | name: amd64 Windows CMake 2 | 3 | on: 4 | push: 5 | pull_request: 6 | schedule: 7 | # min hours day(month) month day(week) 8 | - cron: '0 0 7,22 * *' 9 | 10 | jobs: 11 | # Building using the github runner environement directly. 12 | msvc: 13 | runs-on: windows-latest 14 | env: 15 | CTEST_OUTPUT_ON_FAILURE: 1 16 | steps: 17 | - uses: actions/checkout@v2 18 | - name: Configure 19 | run: cmake -S. -Bbuild -G "Visual Studio 17 2022" -DCMAKE_CONFIGURATION_TYPES=Release 20 | - name: Build 21 | run: cmake --build build --config Release --target ALL_BUILD -- /maxcpucount 22 | - name: Test 23 | run: cmake --build build --config Release --target RUN_TESTS -- /maxcpucount 24 | - name: Install 25 | run: cmake --build build --config Release --target INSTALL -- /maxcpucount 26 | -------------------------------------------------------------------------------- /deps/cpu_features/.github/workflows/arm_linux_cmake.yml: -------------------------------------------------------------------------------- 1 | name: ARM Linux CMake 2 | 3 | on: 4 | push: 5 | pull_request: 6 | schedule: 7 | # min hours day(month) month day(week) 8 | - cron: '0 0 7,22 * *' 9 | 10 | jobs: 11 | # Building using the github runner environement directly. 12 | make: 13 | runs-on: ubuntu-latest 14 | strategy: 15 | matrix: 16 | targets: [ 17 | [arm-linux-gnueabihf], 18 | [armv8l-linux-gnueabihf], 19 | [arm-linux-gnueabi], 20 | [armeb-linux-gnueabihf], 21 | [armeb-linux-gnueabi] 22 | ] 23 | fail-fast: false 24 | env: 25 | TARGET: ${{ matrix.targets[0] }} 26 | steps: 27 | - uses: actions/checkout@v2 28 | - name: Build 29 | run: make --directory=cmake/ci ${TARGET}_build 30 | - name: Test 31 | run: make --directory=cmake/ci ${TARGET}_test 32 | -------------------------------------------------------------------------------- /deps/cpu_features/.github/workflows/clang_format.yml: -------------------------------------------------------------------------------- 1 | name: clang-format Check 2 | 3 | on: [push, pull_request] 4 | 5 | jobs: 6 | # Building using the github runner environement directly. 7 | clang-format: 8 | runs-on: ubuntu-latest 9 | steps: 10 | - uses: actions/checkout@v2 11 | - name: Fetch origin/main 12 | run: git fetch origin main 13 | - name: List of changed file(s) 14 | run: git diff --name-only FETCH_HEAD 15 | 16 | - name: Build clang-format docker 17 | run: cd .github/workflows && docker build --tag=linter . 18 | - name: Check clang-format 19 | run: docker run --rm --init -v $(pwd):/repo linter:latest clang-format --version 20 | - name: clang-format help 21 | run: docker run --rm --init -v $(pwd):/repo linter:latest clang-format --help 22 | 23 | - name: Check current commit 24 | run: docker run --rm --init -v $(pwd):/repo -w /repo linter:latest sh -c "git diff --diff-filter=d --name-only FETCH_HEAD | grep '\.c$\|\.h$\|\.cc$' | xargs clang-format --style=file --dry-run --Werror " 25 | -------------------------------------------------------------------------------- /deps/cpu_features/.github/workflows/mips_linux_cmake.yml: -------------------------------------------------------------------------------- 1 | name: MIPS Linux CMake 2 | 3 | on: 4 | push: 5 | pull_request: 6 | schedule: 7 | # min hours day(month) month day(week) 8 | - cron: '0 0 7,22 * *' 9 | 10 | jobs: 11 | # Building using the github runner environement directly. 12 | make: 13 | runs-on: ubuntu-latest 14 | strategy: 15 | matrix: 16 | targets: [ 17 | [mips32], 18 | [mips32el], 19 | [mips64], 20 | [mips64el] 21 | ] 22 | fail-fast: false 23 | env: 24 | TARGET: ${{ matrix.targets[0] }} 25 | steps: 26 | - uses: actions/checkout@v2 27 | - name: Build 28 | run: make --directory=cmake/ci ${TARGET}_build 29 | - name: Test 30 | run: make --directory=cmake/ci ${TARGET}_test 31 | -------------------------------------------------------------------------------- /deps/cpu_features/.github/workflows/power_linux_cmake.yml: -------------------------------------------------------------------------------- 1 | name: POWER Linux CMake 2 | 3 | on: 4 | push: 5 | pull_request: 6 | schedule: 7 | # min hours day(month) month day(week) 8 | - cron: '0 0 7,22 * *' 9 | 10 | jobs: 11 | # Building using the github runner environement directly. 12 | make: 13 | runs-on: ubuntu-latest 14 | strategy: 15 | matrix: 16 | targets: [ 17 | [ppc], 18 | [ppc64], 19 | [ppc64le], 20 | ] 21 | fail-fast: false 22 | env: 23 | TARGET: ${{ matrix.targets[0] }} 24 | steps: 25 | - uses: actions/checkout@v2 26 | - name: Build 27 | run: make --directory=cmake/ci ${TARGET}_build 28 | - name: Test 29 | run: make --directory=cmake/ci ${TARGET}_test 30 | -------------------------------------------------------------------------------- /deps/cpu_features/.github/workflows/riscv_linux_cmake.yml: -------------------------------------------------------------------------------- 1 | name: RISCV Linux CMake 2 | 3 | on: 4 | push: 5 | pull_request: 6 | schedule: 7 | # min hours day(month) month day(week) 8 | - cron: '0 0 7,22 * *' 9 | 10 | jobs: 11 | # Building using the github runner environement directly. 12 | make: 13 | runs-on: ubuntu-latest 14 | strategy: 15 | matrix: 16 | targets: [ 17 | [riscv32], 18 | [riscv64], 19 | ] 20 | fail-fast: false 21 | env: 22 | TARGET: ${{ matrix.targets[0] }} 23 | steps: 24 | - uses: actions/checkout@v2 25 | - name: Build 26 | run: make --directory=cmake/ci ${TARGET}_build 27 | - name: Test 28 | run: make --directory=cmake/ci ${TARGET}_test 29 | -------------------------------------------------------------------------------- /deps/cpu_features/.github/workflows/s390x_linux_cmake.yml: -------------------------------------------------------------------------------- 1 | name: s390x Linux CMake 2 | 3 | on: 4 | push: 5 | pull_request: 6 | schedule: 7 | # min hours day(month) month day(week) 8 | - cron: '0 0 7,22 * *' 9 | 10 | jobs: 11 | # Building using the github runner environement directly. 12 | make: 13 | runs-on: ubuntu-latest 14 | strategy: 15 | matrix: 16 | targets: [ 17 | [s390x], 18 | ] 19 | fail-fast: false 20 | env: 21 | TARGET: ${{ matrix.targets[0] }} 22 | steps: 23 | - uses: actions/checkout@v2 24 | - name: Build 25 | run: make --directory=cmake/ci ${TARGET}_build 26 | - name: Test 27 | run: make --directory=cmake/ci ${TARGET}_test 28 | -------------------------------------------------------------------------------- /deps/cpu_features/.gitignore: -------------------------------------------------------------------------------- 1 | # Build folders 2 | build/ 3 | cmake_build/ 4 | build_cross/ 5 | cmake-build-*/ 6 | out/ 7 | 8 | # IDEs / CI temp files 9 | .idea/ 10 | .vagrant/ 11 | .vscode/ 12 | .vs/ 13 | *.swp 14 | 15 | # Bazel artifacts 16 | **/bazel-* 17 | 18 | # Per-user bazelrc files 19 | user.bazelrc 20 | -------------------------------------------------------------------------------- /deps/cpu_features/.grenrc.yml: -------------------------------------------------------------------------------- 1 | --- 2 | dataSource: "prs" 3 | ignoreLabels: 4 | - "Apple M1" 5 | - "duplicate" 6 | - "help wanted" 7 | - "invalid" 8 | - "question" 9 | - "wontfix" 10 | onlyMilestones: false 11 | groupBy: 12 | "API Change": 13 | - "API Change" 14 | "New features / Enhancements": 15 | - "enhancement" 16 | - "internal" 17 | "Bug Fixes": 18 | - "bug" 19 | "Misc": 20 | - "misc" 21 | changelogFilename: "CHANGELOG.md" 22 | -------------------------------------------------------------------------------- /deps/cpu_features/CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # How to Contribute 2 | 3 | We'd love to accept your patches and contributions to this project. There are 4 | just a few small guidelines you need to follow. 5 | 6 | ## Contributor License Agreement 7 | 8 | Contributions to this project must be accompanied by a Contributor License 9 | Agreement. You (or your employer) retain the copyright to your contribution; 10 | this simply gives us permission to use and redistribute your contributions as 11 | part of the project. Head over to to see 12 | your current agreements on file or to sign a new one. 13 | 14 | You generally only need to submit a CLA once, so if you've already submitted one 15 | (even if it was for a different project), you probably don't need to do it 16 | again. 17 | 18 | ## Code reviews 19 | 20 | All submissions, including submissions by project members, require review. We 21 | use GitHub pull requests for this purpose. Consult 22 | [GitHub Help](https://help.github.com/articles/about-pull-requests/) for more 23 | information on using pull requests. 24 | -------------------------------------------------------------------------------- /deps/cpu_features/WORKSPACE: -------------------------------------------------------------------------------- 1 | workspace(name = "com_google_cpufeatures") 2 | 3 | load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository") 4 | 5 | git_repository( 6 | name = "com_google_googletest", 7 | tag = "release-1.11.0", 8 | remote = "https://github.com/google/googletest.git", 9 | ) 10 | 11 | git_repository( 12 | name = "bazel_skylib", 13 | tag = "1.2.0", 14 | remote = "https://github.com/bazelbuild/bazel-skylib.git", 15 | ) 16 | 17 | load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace") 18 | 19 | bazel_skylib_workspace() 20 | -------------------------------------------------------------------------------- /deps/cpu_features/bazel/ci/README.md: -------------------------------------------------------------------------------- 1 | ## Usage 2 | To build tests with bazel 3 | ```sh 4 | bazel test -s --verbose_failures //... 5 | ``` 6 | -------------------------------------------------------------------------------- /deps/cpu_features/bazel/platforms.bzl: -------------------------------------------------------------------------------- 1 | """Defines global variables that lists target cpus""" 2 | 3 | PLATFORM_CPU_X86_64 = ("@platforms//cpu:x86_64") 4 | 5 | PLATFORM_CPU_ARM = ("@platforms//cpu:arm") 6 | 7 | PLATFORM_CPU_ARM64 = ("@platforms//cpu:arm64") 8 | 9 | PLATFORM_CPU_MIPS = ("@platforms//cpu:mips64") 10 | 11 | PLATFORM_CPU_PPC = ("@platforms//cpu:ppc") 12 | -------------------------------------------------------------------------------- /deps/cpu_features/cmake/CpuFeaturesConfig.cmake.in: -------------------------------------------------------------------------------- 1 | # CpuFeatures CMake configuration file 2 | 3 | include("${CMAKE_CURRENT_LIST_DIR}/CpuFeaturesTargets.cmake") 4 | -------------------------------------------------------------------------------- /deps/cpu_features/cmake/CpuFeaturesNdkCompatConfig.cmake.in: -------------------------------------------------------------------------------- 1 | # CpuFeaturesNdkCompat CMake configuration file 2 | 3 | include("${CMAKE_CURRENT_LIST_DIR}/CpuFeaturesNdkCompatTargets.cmake") 4 | -------------------------------------------------------------------------------- /deps/cpu_features/cmake/README.md: -------------------------------------------------------------------------------- 1 | # CMake build instructions 2 | 3 | ## Recommended usage : Incorporating cpu_features into a CMake project 4 | 5 | For API / ABI compatibility reasons, it is recommended to build and use 6 | cpu_features in a subdirectory of your project or as an embedded dependency. 7 | 8 | This is similar to the recommended usage of the googletest framework 9 | ( https://github.com/google/googletest/blob/main/googletest/README.md ) 10 | 11 | Build and use step-by-step 12 | 13 | 14 | 1- Download cpu_features and copy it in a sub-directory in your project. 15 | or add cpu_features as a git-submodule in your project 16 | 17 | 2- You can then use the cmake command `add_subdirectory()` to include 18 | cpu_features directly and use the `cpu_features` target in your project. 19 | 20 | 3- Add the `CpuFeature::cpu_features` target to the `target_link_libraries()` section of 21 | your executable or of your library. 22 | 23 | ## Disabling tests 24 | 25 | CMake default options for cpu_features is `Release` built type with tests 26 | enabled. To disable testing set cmake `BUILD_TESTING` variable to `OFF`. 27 | e.g. 28 | ```sh 29 | cmake -S. -Bbuild -DBUILD_TESTING=OFF 30 | ``` 31 | -------------------------------------------------------------------------------- /deps/cpu_features/cmake/ci/README.md: -------------------------------------------------------------------------------- 1 | ## Makefile/Docker testing 2 | To test the build on various distro, we are using docker containers and a Makefile for orchestration. 3 | 4 | pros: 5 | * You are independent of third party CI runner config 6 | (e.g. [github action virtual-environnments](https://github.com/actions/virtual-environments)). 7 | * You can run it locally on your linux system. 8 | * Most CI provide runners with docker and Makefile installed. 9 | 10 | cons: 11 | * Only GNU/Linux distro supported. 12 | 13 | ### Usage 14 | To get the help simply type: 15 | ```sh 16 | make 17 | ``` 18 | 19 | note: you can also use from top directory 20 | ```sh 21 | make --directory=cmake/ci 22 | ``` 23 | 24 | ### Example 25 | For example to test mips32 inside an container: 26 | ```sh 27 | make mips32_test 28 | ``` 29 | 30 | ### Docker layers 31 | Dockerfile is splitted in several stages. 32 | 33 | ![docker](doc/docker.svg) 34 | 35 | 36 | ## Makefile/Vagrant testing 37 | To test build for FreeBSD we are using Vagrant and VirtualBox box. 38 | 39 | This is similar to the docker stuff but use `vagrant` as `docker` cli and 40 | VirtuaBox to replace the docker engine daemon. 41 | -------------------------------------------------------------------------------- /deps/cpu_features/cmake/ci/doc/docker.dot: -------------------------------------------------------------------------------- 1 | @startdot 2 | digraph DockerDeps { 3 | //rankdir=BT; 4 | rankdir=TD; 5 | node [shape=cylinder, style="rounded,filled", color=black, fillcolor=royalblue]; 6 | DISTRO_IMG [label="ubuntu:latest"]; 7 | PKG [label="packages\ne.g. cmake, g++", shape=box3d]; 8 | SRC [label="git repo", shape=folder]; 9 | SPL [label="sample", shape=folder]; 10 | 11 | subgraph clusterDockerfile { 12 | ENV_IMG [label="cpu_features:amd64_env\nenv"]; 13 | DEVEL_IMG [label="cpu_features:amd64_devel\ndevel"]; 14 | BUILD_IMG [label="cpu_features:amd64_build\nbuild"]; 15 | TEST_IMG [label="cpu_features:amd64_test\ntest"]; 16 | INSTALL_ENV_IMG [label="cpu_features:amd64_install_env\ninstall_env"]; 17 | INSTALL_DEVEL_IMG [label="cpu_features:amd64_install_devel\ninstall_devel"]; 18 | INSTALL_BUILD_IMG [label="cpu_features:amd64_install_build\ninstall_build"]; 19 | INSTALL_TEST_IMG [label="cpu_features:amd64_install_test\ninstall_test"]; 20 | 21 | ENV_IMG -> DEVEL_IMG; 22 | DEVEL_IMG -> BUILD_IMG; 23 | BUILD_IMG -> TEST_IMG; 24 | 25 | ENV_IMG -> INSTALL_ENV_IMG; 26 | BUILD_IMG -> INSTALL_ENV_IMG [label="copy install", style="dashed"]; 27 | INSTALL_ENV_IMG -> INSTALL_DEVEL_IMG; 28 | SPL -> INSTALL_DEVEL_IMG [label="copy", style="dashed"]; 29 | INSTALL_DEVEL_IMG -> INSTALL_BUILD_IMG; 30 | INSTALL_BUILD_IMG -> INSTALL_TEST_IMG; 31 | 32 | color=royalblue; 33 | label = "docker/amd64/Dockerfile"; 34 | } 35 | DISTRO_IMG -> ENV_IMG; 36 | PKG -> ENV_IMG [label="install", style="dashed"]; 37 | SRC -> DEVEL_IMG [label="copy", style="dashed"]; 38 | 39 | subgraph clusterCache { 40 | node [shape=note, style="rounded,filled", color=black, fillcolor=royalblue]; 41 | ENV_TAR [label="docker_amd64_env.tar"]; 42 | DEVEL_TAR [label="docker_amd64_devel.tar"]; 43 | BUILD_TAR [label="docker_amd64_build.tar"]; 44 | TEST_TAR [label="docker_amd64_test.tar"]; 45 | INSTALL_ENV_TAR [label="docker_amd64_install_env.tar"]; 46 | INSTALL_DEVEL_TAR [label="docker_amd64_install_devel.tar"]; 47 | INSTALL_BUILD_TAR [label="docker_amd64_install_build.tar"]; 48 | INSTALL_TEST_TAR [label="docker_amd64_install_test.tar"]; 49 | 50 | edge [color=red]; 51 | ENV_IMG -> ENV_TAR [label="make save_amd64_env"]; 52 | DEVEL_IMG -> DEVEL_TAR [label="make save_amd64_devel"]; 53 | BUILD_IMG -> BUILD_TAR [label="make save_amd64_build"]; 54 | TEST_IMG -> TEST_TAR [label="make save_amd64_test"]; 55 | INSTALL_ENV_IMG -> INSTALL_ENV_TAR [label="make save_amd64_install_env"]; 56 | INSTALL_DEVEL_IMG -> INSTALL_DEVEL_TAR [label="make save_amd64_install_devel"]; 57 | INSTALL_BUILD_IMG -> INSTALL_BUILD_TAR [label="make save_amd64_install_build"]; 58 | INSTALL_TEST_IMG -> INSTALL_TEST_TAR [label="make save_amd64_install_test"]; 59 | 60 | color=royalblue; 61 | label = "cache/amd64/"; 62 | } 63 | } 64 | @enddot 65 | -------------------------------------------------------------------------------- /deps/cpu_features/cmake/ci/doc/generate_image.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -ex 3 | 4 | rm -f ./*.svg ./*.png 5 | for i in *.dot; do 6 | plantuml -Tsvg "$i"; 7 | done 8 | -------------------------------------------------------------------------------- /deps/cpu_features/cmake/ci/docker/amd64/Dockerfile: -------------------------------------------------------------------------------- 1 | # Create a virtual environment with all tools installed 2 | # ref: https://hub.docker.com/_/ubuntu 3 | FROM ubuntu:latest AS env 4 | LABEL maintainer="corentinl@google.com" 5 | # Install system build dependencies 6 | ENV PATH=/usr/local/bin:$PATH 7 | RUN apt-get update -qq \ 8 | && DEBIAN_FRONTEND=noninteractive apt-get install -yq git wget libssl-dev build-essential \ 9 | ninja-build python3 pkgconf libglib2.0-dev \ 10 | && apt-get clean \ 11 | && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* 12 | ENTRYPOINT ["/usr/bin/bash", "-c"] 13 | CMD ["/usr/bin/bash"] 14 | 15 | # Install CMake 3.21.3 16 | RUN wget "https://cmake.org/files/v3.21/cmake-3.21.3-linux-x86_64.sh" \ 17 | && chmod a+x cmake-3.21.3-linux-x86_64.sh \ 18 | && ./cmake-3.21.3-linux-x86_64.sh --prefix=/usr/local/ --skip-license \ 19 | && rm cmake-3.21.3-linux-x86_64.sh 20 | 21 | FROM env AS devel 22 | WORKDIR /home/project 23 | COPY . . 24 | 25 | FROM devel AS build 26 | RUN cmake -version 27 | RUN cmake -S. -Bbuild 28 | RUN cmake --build build --target all -v 29 | RUN cmake --build build --target install -v 30 | 31 | FROM build AS test 32 | ENV CTEST_OUTPUT_ON_FAILURE=1 33 | RUN cmake --build build --target test -v 34 | 35 | # Test install rules 36 | FROM env AS install_env 37 | COPY --from=build /usr/local /usr/local/ 38 | 39 | FROM install_env AS install_devel 40 | WORKDIR /home/sample 41 | COPY cmake/ci/sample . 42 | 43 | FROM install_devel AS install_build 44 | RUN cmake -S. -Bbuild 45 | RUN cmake --build build --target all -v 46 | 47 | FROM install_build AS install_test 48 | RUN cmake --build build --target test 49 | -------------------------------------------------------------------------------- /deps/cpu_features/cmake/ci/docker/toolchain/Dockerfile: -------------------------------------------------------------------------------- 1 | # Create a virtual environment with all tools installed 2 | # ref: https://hub.docker.com/_/ubuntu 3 | FROM ubuntu:latest AS env 4 | LABEL maintainer="corentinl@google.com" 5 | # Install system build dependencies 6 | ENV PATH=/usr/local/bin:$PATH 7 | RUN apt-get update -qq \ 8 | && DEBIAN_FRONTEND=noninteractive apt-get install -yq git wget libssl-dev build-essential \ 9 | ninja-build python3 pkgconf libglib2.0-dev \ 10 | && apt-get clean \ 11 | && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* 12 | ENTRYPOINT ["/usr/bin/bash", "-c"] 13 | CMD ["/usr/bin/bash"] 14 | 15 | # Install CMake 3.21.3 16 | RUN wget "https://cmake.org/files/v3.21/cmake-3.21.3-linux-x86_64.sh" \ 17 | && chmod a+x cmake-3.21.3-linux-x86_64.sh \ 18 | && ./cmake-3.21.3-linux-x86_64.sh --prefix=/usr/local/ --skip-license \ 19 | && rm cmake-3.21.3-linux-x86_64.sh 20 | 21 | FROM env AS devel 22 | WORKDIR /home/project 23 | COPY . . 24 | 25 | ARG TARGET 26 | ENV TARGET ${TARGET:-unknown} 27 | 28 | FROM devel AS build 29 | RUN cmake -version 30 | RUN ./scripts/run_integration.sh build 31 | 32 | FROM build AS test 33 | RUN ./scripts/run_integration.sh qemu 34 | RUN ./scripts/run_integration.sh test 35 | -------------------------------------------------------------------------------- /deps/cpu_features/cmake/ci/sample/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.15) 2 | project(Sample VERSION 1.0.0 LANGUAGES CXX) 3 | 4 | include(CTest) 5 | find_package(CpuFeatures REQUIRED) 6 | 7 | add_executable(sample main.cpp) 8 | target_compile_features(sample PUBLIC cxx_std_11) 9 | set_target_properties(sample PROPERTIES 10 | CXX_STANDARD 11 11 | CXX_STANDARD_REQUIRED ON 12 | VERSION ${PROJECT_VERSION}) 13 | target_link_libraries(sample PRIVATE CpuFeatures::cpu_features) 14 | 15 | if(BUILD_TESTING) 16 | add_test(NAME sample_test COMMAND sample) 17 | endif() 18 | 19 | include(GNUInstallDirs) 20 | install(TARGETS sample 21 | EXPORT SampleTargets 22 | DESTINATION ${CMAKE_INSTALL_BIN_DIR}) 23 | -------------------------------------------------------------------------------- /deps/cpu_features/cmake/ci/sample/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "cpuinfo_x86.h" 4 | 5 | using namespace cpu_features; 6 | 7 | int main(int /*argc*/, char** /*argv*/) { 8 | static const X86Features features = GetX86Info().features; 9 | std::cout << std::endl; 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /deps/cpu_features/cmake/ci/vagrant/freebsd/Vagrantfile: -------------------------------------------------------------------------------- 1 | # -*- mode: ruby -*- 2 | # vi: set ft=ruby : 3 | 4 | # All Vagrant configuration is done below. The "2" in Vagrant.configure 5 | # configures the configuration version (we support older styles for 6 | # backwards compatibility). Please don't change it unless you know what 7 | # you're doing. 8 | Vagrant.configure("2") do |config| 9 | # The most common configuration options are documented and commented below. 10 | # For a complete reference, please see the online documentation at 11 | # https://docs.vagrantup.com. 12 | 13 | # Every Vagrant development environment requires a box. You can search for 14 | # boxes at https://vagrantcloud.com/search. 15 | config.vm.guest = :freebsd 16 | config.vm.box = "generic/freebsd12" 17 | 18 | config.ssh.shell = "sh" 19 | 20 | # Disable automatic box update checking. If you disable this, then 21 | # boxes will only be checked for updates when the user runs 22 | # `vagrant box outdated`. This is not recommended. 23 | # config.vm.box_check_update = false 24 | 25 | # Create a forwarded port mapping which allows access to a specific port 26 | # within the machine from a port on the host machine. In the example below, 27 | # accessing "localhost:8080" will access port 80 on the guest machine. 28 | # NOTE: This will enable public access to the opened port 29 | # config.vm.network "forwarded_port", guest: 80, host: 8080 30 | 31 | # Create a forwarded port mapping which allows access to a specific port 32 | # within the machine from a port on the host machine and only allow access 33 | # via 127.0.0.1 to disable public access 34 | # config.vm.network "forwarded_port", guest: 80, host: 8080, host_ip: "127.0.0.1" 35 | 36 | # Create a private network, which allows host-only access to the machine 37 | # using a specific IP. 38 | # config.vm.network "private_network", ip: "192.168.33.10" 39 | 40 | # Create a public network, which generally matched to bridged network. 41 | # Bridged networks make the machine appear as another physical device on 42 | # your network. 43 | # config.vm.network "public_network" 44 | 45 | # Share an additional folder to the guest VM. The first argument is 46 | # the path on the host to the actual folder. The second argument is 47 | # the path on the guest to mount the folder. And the optional third 48 | # argument is a set of non-required options. 49 | #config.vm.synced_folder "../../..", "/home/vagrant/project" 50 | config.vm.synced_folder ".", "/vagrant", id: "vagrant-root", disabled: true 51 | 52 | config.vm.provision "file", source: "../../../../CMakeLists.txt", destination: "$HOME/project/" 53 | config.vm.provision "file", source: "../../../../cmake", destination: "$HOME/project/" 54 | config.vm.provision "file", source: "../../../../include", destination: "$HOME/project/" 55 | config.vm.provision "file", source: "../../../../src", destination: "$HOME/project/" 56 | config.vm.provision "file", source: "../../../../test", destination: "$HOME/project/" 57 | 58 | # Provider-specific configuration so you can fine-tune various 59 | # backing providers for Vagrant. These expose provider-specific options. 60 | # Example for VirtualBox: 61 | # 62 | # config.vm.provider "virtualbox" do |vb| 63 | # # Display the VirtualBox GUI when booting the machine 64 | # vb.gui = true 65 | # 66 | # # Customize the amount of memory on the VM: 67 | # vb.memory = "1024" 68 | # end 69 | # 70 | # View the documentation for the provider you are using for more 71 | # information on available options. 72 | 73 | # Enable provisioning with a shell script. Additional provisioners such as 74 | # Ansible, Chef, Docker, Puppet and Salt are also available. Please see the 75 | # documentation for more information about their specific syntax and use. 76 | # note: clang installed by default 77 | config.vm.provision "env", type: "shell", inline:<<-SHELL 78 | set -x 79 | pkg update -f 80 | pkg install -y git cmake 81 | SHELL 82 | config.vm.provision "devel", type: "shell", inline:<<-SHELL 83 | set -x 84 | cd project 85 | ls 86 | SHELL 87 | config.vm.provision "configure", type: "shell", inline:<<-SHELL 88 | set -x 89 | cd project 90 | cmake -S. -Bbuild -DBUILD_TESTING=ON 91 | SHELL 92 | config.vm.provision "build", type: "shell", inline:<<-SHELL 93 | set -x 94 | cd project 95 | cmake --build build -v 96 | SHELL 97 | config.vm.provision "test", type: "shell", inline:<<-SHELL 98 | set -x 99 | cd project 100 | cmake --build build --target test -v 101 | SHELL 102 | config.vm.provision "test", type: "shell", inline:<<-SHELL 103 | set -x 104 | cd project 105 | cmake --build build --target install -v 106 | SHELL 107 | end 108 | -------------------------------------------------------------------------------- /deps/cpu_features/cmake/googletest.CMakeLists.txt.in: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.8.2) 2 | 3 | project(googletest-download NONE) 4 | 5 | include(ExternalProject) 6 | ExternalProject_Add(googletest 7 | GIT_REPOSITORY https://github.com/google/googletest.git 8 | GIT_TAG main 9 | SOURCE_DIR "${CMAKE_BINARY_DIR}/googletest-src" 10 | BINARY_DIR "${CMAKE_BINARY_DIR}/googletest-build" 11 | CONFIGURE_COMMAND "" 12 | BUILD_COMMAND "" 13 | INSTALL_COMMAND "" 14 | TEST_COMMAND "" 15 | ) -------------------------------------------------------------------------------- /deps/cpu_features/cpu_features.gyp: -------------------------------------------------------------------------------- 1 | { 2 | 'targets': [ 3 | { 4 | 'target_name': 'cpu_features', 5 | 'type': 'static_library', 6 | 7 | 'cflags': [ '-O3' ], 8 | 9 | 'include_dirs': [ 10 | 'include', 11 | 'include/internal', 12 | ], 13 | 'sources': [ 14 | 'include/cpu_features_cache_info.h', 15 | 'include/cpu_features_macros.h', 16 | 17 | # platform-specific cpu checking implementations 18 | 'src/impl_aarch64_linux_or_android.c', 19 | 'src/impl_aarch64_macos_or_iphone.c', 20 | 'src/impl_aarch64_windows.c', 21 | 'src/impl_arm_linux_or_android.c', 22 | 'src/impl_mips_linux_or_android.c', 23 | 'src/impl_ppc_linux.c', 24 | 'src/impl_x86_freebsd.c', 25 | 'src/impl_x86_linux_or_android.c', 26 | 'src/impl_x86_macos.c', 27 | 'src/impl_x86_windows.c', 28 | 29 | # utils 30 | 'include/internal/bit_utils.h', 31 | 'include/internal/filesystem.h', 32 | 'include/internal/stack_line_reader.h', 33 | 'include/internal/string_view.h', 34 | 'src/filesystem.c', 35 | 'src/stack_line_reader.c', 36 | 'src/string_view.c', 37 | ], 38 | 'conditions': [ 39 | ['target_arch in "mips mipsel mips64 mips64el"', { 40 | 'sources': [ 41 | 'include/cpuinfo_mips.h', 42 | ], 43 | }], 44 | ['target_arch=="arm"', { 45 | 'sources': [ 46 | 'include/cpuinfo_arm.h', 47 | ], 48 | }], 49 | ['target_arch=="arm64"', { 50 | 'sources': [ 51 | 'include/cpuinfo_aarch64.h', 52 | 'include/internal/windows_utils.h', 53 | ], 54 | }], 55 | ['target_arch in "ia32 x32 x64"', { 56 | 'sources': [ 57 | 'include/internal/cpuid_x86.h', 58 | 'include/cpuinfo_x86.h', 59 | 'include/internal/windows_utils.h', 60 | ], 61 | }], 62 | ['target_arch in "ppc ppc64"', { 63 | 'sources': [ 64 | 'include/cpuinfo_ppc.h', 65 | ], 66 | }], 67 | ['target_arch in "s390x"', { 68 | 'sources': [ 69 | 'include/cpuinfo_s390x.h', 70 | ], 71 | }], 72 | ['target_arch in "riscv64"', { 73 | 'sources': [ 74 | 'include/cpuinfo_riscv.h', 75 | ], 76 | }], 77 | 78 | ['OS=="mac" and target_arch in "ia32 x32 x64 arm64"', { 79 | 'defines': [ 80 | 'HAVE_SYSCTLBYNAME=1', 81 | ], 82 | }], 83 | ], 84 | 'defines': [ 85 | 'NDEBUG', 86 | 'STACK_LINE_READER_BUFFER_SIZE=1024', 87 | ], 88 | 89 | # Use generated config 90 | 'includes': [ 91 | '../../buildcheck.gypi', 92 | ], 93 | 94 | 'direct_dependent_settings': { 95 | 'include_dirs': [ 96 | 'include', 97 | ], 98 | 'defines': [ 99 | # Manually-tracked git revision 100 | 'CPU_FEATURES_VERSION_REV=8a494eb1e158ec2050e5f699a504fbc9b896a43b', 101 | ], 102 | }, 103 | }, 104 | ], 105 | } 106 | -------------------------------------------------------------------------------- /deps/cpu_features/include/cpu_features_cache_info.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef CPU_FEATURES_INCLUDE_CPUINFO_COMMON_H_ 16 | #define CPU_FEATURES_INCLUDE_CPUINFO_COMMON_H_ 17 | 18 | #include "cpu_features_macros.h" 19 | 20 | CPU_FEATURES_START_CPP_NAMESPACE 21 | 22 | typedef enum { 23 | CPU_FEATURE_CACHE_NULL = 0, 24 | CPU_FEATURE_CACHE_DATA = 1, 25 | CPU_FEATURE_CACHE_INSTRUCTION = 2, 26 | CPU_FEATURE_CACHE_UNIFIED = 3, 27 | CPU_FEATURE_CACHE_TLB = 4, 28 | CPU_FEATURE_CACHE_DTLB = 5, 29 | CPU_FEATURE_CACHE_STLB = 6, 30 | CPU_FEATURE_CACHE_PREFETCH = 7 31 | } CacheType; 32 | 33 | typedef struct { 34 | int level; 35 | CacheType cache_type; 36 | int cache_size; // Cache size in bytes 37 | int ways; // Associativity, 0 undefined, 0xFF fully associative 38 | int line_size; // Cache line size in bytes 39 | int tlb_entries; // number of entries for TLB 40 | int partitioning; // number of lines per sector 41 | } CacheLevelInfo; 42 | 43 | // Increase this value if more cache levels are needed. 44 | #ifndef CPU_FEATURES_MAX_CACHE_LEVEL 45 | #define CPU_FEATURES_MAX_CACHE_LEVEL 10 46 | #endif 47 | typedef struct { 48 | int size; 49 | CacheLevelInfo levels[CPU_FEATURES_MAX_CACHE_LEVEL]; 50 | } CacheInfo; 51 | 52 | CPU_FEATURES_END_CPP_NAMESPACE 53 | 54 | #endif // CPU_FEATURES_INCLUDE_CPUINFO_COMMON_H_ 55 | -------------------------------------------------------------------------------- /deps/cpu_features/include/cpuinfo_arm.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef CPU_FEATURES_INCLUDE_CPUINFO_ARM_H_ 16 | #define CPU_FEATURES_INCLUDE_CPUINFO_ARM_H_ 17 | 18 | #include // uint32_t 19 | 20 | #include "cpu_features_cache_info.h" 21 | #include "cpu_features_macros.h" 22 | 23 | CPU_FEATURES_START_CPP_NAMESPACE 24 | 25 | typedef struct { 26 | int swp : 1; // SWP instruction (atomic read-modify-write) 27 | int half : 1; // Half-word loads and stores 28 | int thumb : 1; // Thumb (16-bit instruction set) 29 | int _26bit : 1; // "26 Bit" Model (Processor status register folded into 30 | // program counter) 31 | int fastmult : 1; // 32x32->64-bit multiplication 32 | int fpa : 1; // Floating point accelerator 33 | int vfp : 1; // Vector Floating Point. 34 | int edsp : 1; // DSP extensions (the 'e' variant of the ARM9 CPUs, and all 35 | // others above) 36 | int java : 1; // Jazelle (Java bytecode accelerator) 37 | int iwmmxt : 1; // Intel Wireless MMX Technology. 38 | int crunch : 1; // MaverickCrunch coprocessor 39 | int thumbee : 1; // ThumbEE 40 | int neon : 1; // Advanced SIMD. 41 | int vfpv3 : 1; // VFP version 3 42 | int vfpv3d16 : 1; // VFP version 3 with 16 D-registers 43 | int tls : 1; // TLS register 44 | int vfpv4 : 1; // VFP version 4 with fast context switching 45 | int idiva : 1; // SDIV and UDIV hardware division in ARM mode. 46 | int idivt : 1; // SDIV and UDIV hardware division in Thumb mode. 47 | int vfpd32 : 1; // VFP with 32 D-registers 48 | int lpae : 1; // Large Physical Address Extension (>4GB physical memory on 49 | // 32-bit architecture) 50 | int evtstrm : 1; // kernel event stream using generic architected timer 51 | int aes : 1; // Hardware-accelerated Advanced Encryption Standard. 52 | int pmull : 1; // Polynomial multiply long. 53 | int sha1 : 1; // Hardware-accelerated SHA1. 54 | int sha2 : 1; // Hardware-accelerated SHA2-256. 55 | int crc32 : 1; // Hardware-accelerated CRC-32. 56 | 57 | // Make sure to update ArmFeaturesEnum below if you add a field here. 58 | } ArmFeatures; 59 | 60 | typedef struct { 61 | ArmFeatures features; 62 | int implementer; 63 | int architecture; 64 | int variant; 65 | int part; 66 | int revision; 67 | } ArmInfo; 68 | 69 | // TODO(user): Add macros to know which features are present at compile 70 | // time. 71 | 72 | ArmInfo GetArmInfo(void); 73 | 74 | // Compute CpuId from ArmInfo. 75 | uint32_t GetArmCpuId(const ArmInfo* const info); 76 | 77 | //////////////////////////////////////////////////////////////////////////////// 78 | // Introspection functions 79 | 80 | typedef enum { 81 | ARM_SWP, 82 | ARM_HALF, 83 | ARM_THUMB, 84 | ARM_26BIT, 85 | ARM_FASTMULT, 86 | ARM_FPA, 87 | ARM_VFP, 88 | ARM_EDSP, 89 | ARM_JAVA, 90 | ARM_IWMMXT, 91 | ARM_CRUNCH, 92 | ARM_THUMBEE, 93 | ARM_NEON, 94 | ARM_VFPV3, 95 | ARM_VFPV3D16, 96 | ARM_TLS, 97 | ARM_VFPV4, 98 | ARM_IDIVA, 99 | ARM_IDIVT, 100 | ARM_VFPD32, 101 | ARM_LPAE, 102 | ARM_EVTSTRM, 103 | ARM_AES, 104 | ARM_PMULL, 105 | ARM_SHA1, 106 | ARM_SHA2, 107 | ARM_CRC32, 108 | ARM_LAST_, 109 | } ArmFeaturesEnum; 110 | 111 | int GetArmFeaturesEnumValue(const ArmFeatures* features, ArmFeaturesEnum value); 112 | 113 | const char* GetArmFeaturesEnumName(ArmFeaturesEnum); 114 | 115 | CPU_FEATURES_END_CPP_NAMESPACE 116 | 117 | #if !defined(CPU_FEATURES_ARCH_ARM) 118 | #error "Including cpuinfo_arm.h from a non-arm target." 119 | #endif 120 | 121 | #endif // CPU_FEATURES_INCLUDE_CPUINFO_ARM_H_ 122 | -------------------------------------------------------------------------------- /deps/cpu_features/include/cpuinfo_mips.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef CPU_FEATURES_INCLUDE_CPUINFO_MIPS_H_ 16 | #define CPU_FEATURES_INCLUDE_CPUINFO_MIPS_H_ 17 | 18 | #include "cpu_features_cache_info.h" 19 | #include "cpu_features_macros.h" 20 | 21 | CPU_FEATURES_START_CPP_NAMESPACE 22 | 23 | typedef struct { 24 | int msa : 1; // MIPS SIMD Architecture 25 | // https://www.mips.com/products/architectures/ase/simd/ 26 | int eva : 1; // Enhanced Virtual Addressing 27 | // https://www.mips.com/products/architectures/mips64/ 28 | int r6 : 1; // True if is release 6 of the processor. 29 | int mips16 : 1; // Compressed instructions 30 | int mdmx : 1; // MIPS Digital Media Extension 31 | int mips3d : 1; // 3D graphics acceleration 32 | // MIPS(r) Architecture for Programmers, Volume IV-c 33 | int smart : 1; // Smart-card cryptography 34 | // MIPS(r) Architecture for Programmers, Volume IV-d 35 | int dsp : 1; // Digital Signal Processing 36 | // MIPS(r) Architecture for Programmers, Volume IV-e 37 | // https://www.mips.com/products/architectures/ase/dsp/ 38 | 39 | // Make sure to update MipsFeaturesEnum below if you add a field here. 40 | } MipsFeatures; 41 | 42 | typedef struct { 43 | MipsFeatures features; 44 | } MipsInfo; 45 | 46 | MipsInfo GetMipsInfo(void); 47 | 48 | //////////////////////////////////////////////////////////////////////////////// 49 | // Introspection functions 50 | 51 | typedef enum { 52 | MIPS_MSA, 53 | MIPS_EVA, 54 | MIPS_R6, 55 | MIPS_MIPS16, 56 | MIPS_MDMX, 57 | MIPS_MIPS3D, 58 | MIPS_SMART, 59 | MIPS_DSP, 60 | MIPS_LAST_, 61 | } MipsFeaturesEnum; 62 | 63 | int GetMipsFeaturesEnumValue(const MipsFeatures* features, 64 | MipsFeaturesEnum value); 65 | 66 | const char* GetMipsFeaturesEnumName(MipsFeaturesEnum); 67 | 68 | CPU_FEATURES_END_CPP_NAMESPACE 69 | 70 | #if !defined(CPU_FEATURES_ARCH_MIPS) 71 | #error "Including cpuinfo_mips.h from a non-mips target." 72 | #endif 73 | 74 | #endif // CPU_FEATURES_INCLUDE_CPUINFO_MIPS_H_ 75 | -------------------------------------------------------------------------------- /deps/cpu_features/include/cpuinfo_ppc.h: -------------------------------------------------------------------------------- 1 | // Copyright 2018 IBM 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef CPU_FEATURES_INCLUDE_CPUINFO_PPC_H_ 16 | #define CPU_FEATURES_INCLUDE_CPUINFO_PPC_H_ 17 | 18 | #include "cpu_features_cache_info.h" 19 | #include "cpu_features_macros.h" 20 | 21 | CPU_FEATURES_START_CPP_NAMESPACE 22 | 23 | typedef struct { 24 | int ppc32 : 1; 25 | int ppc64 : 1; 26 | int ppc601 : 1; 27 | int altivec : 1; 28 | int fpu : 1; 29 | int mmu : 1; 30 | int mac_4xx : 1; 31 | int unifiedcache : 1; 32 | int spe : 1; 33 | int efpsingle : 1; 34 | int efpdouble : 1; 35 | int no_tb : 1; 36 | int power4 : 1; 37 | int power5 : 1; 38 | int power5plus : 1; 39 | int cell : 1; 40 | int booke : 1; 41 | int smt : 1; 42 | int icachesnoop : 1; 43 | int arch205 : 1; 44 | int pa6t : 1; 45 | int dfp : 1; 46 | int power6ext : 1; 47 | int arch206 : 1; 48 | int vsx : 1; 49 | int pseries_perfmon_compat : 1; 50 | int truele : 1; 51 | int ppcle : 1; 52 | int arch207 : 1; 53 | int htm : 1; 54 | int dscr : 1; 55 | int ebb : 1; 56 | int isel : 1; 57 | int tar : 1; 58 | int vcrypto : 1; 59 | int htm_nosc : 1; 60 | int arch300 : 1; 61 | int ieee128 : 1; 62 | int darn : 1; 63 | int scv : 1; 64 | int htm_no_suspend : 1; 65 | 66 | // Make sure to update PPCFeaturesEnum below if you add a field here. 67 | } PPCFeatures; 68 | 69 | typedef struct { 70 | PPCFeatures features; 71 | } PPCInfo; 72 | 73 | PPCInfo GetPPCInfo(void); 74 | 75 | typedef struct { 76 | char platform[64]; // 0 terminated string 77 | char base_platform[64]; // 0 terminated string 78 | } PPCPlatformTypeStrings; 79 | 80 | typedef struct { 81 | char platform[64]; // 0 terminated string 82 | char model[64]; // 0 terminated string 83 | char machine[64]; // 0 terminated string 84 | char cpu[64]; // 0 terminated string 85 | PPCPlatformTypeStrings type; 86 | } PPCPlatformStrings; 87 | 88 | PPCPlatformStrings GetPPCPlatformStrings(void); 89 | 90 | //////////////////////////////////////////////////////////////////////////////// 91 | // Introspection functions 92 | 93 | typedef enum { 94 | PPC_32, /* 32 bit mode execution */ 95 | PPC_64, /* 64 bit mode execution */ 96 | PPC_601_INSTR, /* Old POWER ISA */ 97 | PPC_HAS_ALTIVEC, /* SIMD Unit*/ 98 | PPC_HAS_FPU, /* Floating Point Unit */ 99 | PPC_HAS_MMU, /* Memory management unit */ 100 | PPC_HAS_4xxMAC, 101 | PPC_UNIFIED_CACHE, /* Unified instruction and data cache */ 102 | PPC_HAS_SPE, /* Signal processing extention unit */ 103 | PPC_HAS_EFP_SINGLE, /* SPE single precision fpu */ 104 | PPC_HAS_EFP_DOUBLE, /* SPE double precision fpu */ 105 | PPC_NO_TB, /* No timebase */ 106 | PPC_POWER4, 107 | PPC_POWER5, 108 | PPC_POWER5_PLUS, 109 | PPC_CELL, /* Cell broadband engine */ 110 | PPC_BOOKE, /* Embedded ISA */ 111 | PPC_SMT, /* Simultaneous multi-threading */ 112 | PPC_ICACHE_SNOOP, 113 | PPC_ARCH_2_05, /* ISA 2.05 - POWER6 */ 114 | PPC_PA6T, /* PA Semi 6T core ISA */ 115 | PPC_HAS_DFP, /* Decimal floating point unit */ 116 | PPC_POWER6_EXT, 117 | PPC_ARCH_2_06, /* ISA 2.06 - POWER7 */ 118 | PPC_HAS_VSX, /* Vector-scalar extension */ 119 | PPC_PSERIES_PERFMON_COMPAT, /* Set of backwards compatibile performance 120 | monitoring events */ 121 | PPC_TRUE_LE, 122 | PPC_PPC_LE, 123 | PPC_ARCH_2_07, /* ISA 2.07 - POWER8 */ 124 | PPC_HTM, /* Hardware Transactional Memory */ 125 | PPC_DSCR, /* Data stream control register */ 126 | PPC_EBB, /* Event base branching */ 127 | PPC_ISEL, /* Integer select instructions */ 128 | PPC_TAR, /* Target address register */ 129 | PPC_VEC_CRYPTO, /* Vector cryptography instructions */ 130 | PPC_HTM_NOSC, /* Transactions aborted when syscall made*/ 131 | PPC_ARCH_3_00, /* ISA 3.00 - POWER9 */ 132 | PPC_HAS_IEEE128, /* VSX IEEE Binary Float 128-bit */ 133 | PPC_DARN, /* Deliver a random number instruction */ 134 | PPC_SCV, /* scv syscall */ 135 | PPC_HTM_NO_SUSPEND, /* TM w/out suspended state */ 136 | PPC_LAST_, 137 | } PPCFeaturesEnum; 138 | 139 | int GetPPCFeaturesEnumValue(const PPCFeatures* features, PPCFeaturesEnum value); 140 | 141 | const char* GetPPCFeaturesEnumName(PPCFeaturesEnum); 142 | 143 | CPU_FEATURES_END_CPP_NAMESPACE 144 | 145 | #if !defined(CPU_FEATURES_ARCH_PPC) 146 | #error "Including cpuinfo_ppc.h from a non-ppc target." 147 | #endif 148 | 149 | #endif // CPU_FEATURES_INCLUDE_CPUINFO_PPC_H_ 150 | -------------------------------------------------------------------------------- /deps/cpu_features/include/cpuinfo_riscv.h: -------------------------------------------------------------------------------- 1 | // Copyright 2022 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef CPU_FEATURES_INCLUDE_CPUINFO_RISCV_H_ 16 | #define CPU_FEATURES_INCLUDE_CPUINFO_RISCV_H_ 17 | 18 | #include "cpu_features_cache_info.h" 19 | #include "cpu_features_macros.h" 20 | 21 | #if !defined(CPU_FEATURES_ARCH_RISCV) 22 | #error "Including cpuinfo_riscv.h from a non-riscv target." 23 | #endif 24 | 25 | CPU_FEATURES_START_CPP_NAMESPACE 26 | 27 | typedef struct { 28 | // Base 29 | int RV32I : 1; // Base Integer Instruction Set, 32-bit 30 | int RV64I : 1; // Base Integer Instruction Set, 64-bit 31 | 32 | // Extension 33 | int M : 1; // Standard Extension for Integer Multiplication/Division 34 | int A : 1; // Standard Extension for Atomic Instructions 35 | int F : 1; // Standard Extension for Single-Precision Floating-Point 36 | int D : 1; // Standard Extension for Double-Precision Floating-Point 37 | int Q : 1; // Standard Extension for Quad-Precision Floating-Point 38 | int C : 1; // Standard Extension for Compressed Instructions 39 | int V : 1; // Standard Extension for Vector Instructions 40 | int Zicsr : 1; // Control and Status Register (CSR) 41 | int Zifencei : 1; // Instruction-Fetch Fence 42 | } RiscvFeatures; 43 | 44 | typedef struct { 45 | RiscvFeatures features; 46 | char uarch[64]; // 0 terminated string 47 | char vendor[64]; // 0 terminated string 48 | } RiscvInfo; 49 | 50 | typedef enum { 51 | RISCV_RV32I, 52 | RISCV_RV64I, 53 | RISCV_M, 54 | RISCV_A, 55 | RISCV_F, 56 | RISCV_D, 57 | RISCV_Q, 58 | RISCV_C, 59 | RISCV_V, 60 | RISCV_Zicsr, 61 | RISCV_Zifencei, 62 | RISCV_LAST_, 63 | } RiscvFeaturesEnum; 64 | 65 | RiscvInfo GetRiscvInfo(void); 66 | int GetRiscvFeaturesEnumValue(const RiscvFeatures* features, 67 | RiscvFeaturesEnum value); 68 | const char* GetRiscvFeaturesEnumName(RiscvFeaturesEnum); 69 | 70 | CPU_FEATURES_END_CPP_NAMESPACE 71 | 72 | #endif // CPU_FEATURES_INCLUDE_CPUINFO_RISCV_H_ 73 | -------------------------------------------------------------------------------- /deps/cpu_features/include/cpuinfo_s390x.h: -------------------------------------------------------------------------------- 1 | // Copyright 2022 IBM 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef CPU_FEATURES_INCLUDE_CPUINFO_S390X_H_ 16 | #define CPU_FEATURES_INCLUDE_CPUINFO_S390X_H_ 17 | 18 | #include "cpu_features_cache_info.h" 19 | #include "cpu_features_macros.h" 20 | 21 | CPU_FEATURES_START_CPP_NAMESPACE 22 | 23 | typedef struct { 24 | int esan3: 1; // instructions named N3, "backported" to esa-mode 25 | int zarch: 1; // z/Architecture mode active 26 | int stfle: 1; // store-facility-list-extended 27 | int msa: 1; // message-security assist 28 | int ldisp: 1; // long-displacement 29 | int eimm: 1; // extended-immediate 30 | int dfp: 1; // decimal floating point & perform floating point operation 31 | int edat: 1; // huge page support 32 | int etf3eh: 1; // extended-translation facility 3 enhancement 33 | int highgprs: 1; // 64-bit register support for 31-bit processes 34 | int te: 1; // transactional execution 35 | int vx: 1; // vector extension facility 36 | int vxd: 1; // vector-packed-decimal facility 37 | int vxe: 1; // vector-enhancement facility 1 38 | int gs: 1; // guarded-storage facility 39 | int vxe2: 1; // vector-enhancements facility 2 40 | int vxp: 1; // vector-packed-decimal-enhancement facility 41 | int sort: 1; // enhanced-sort facility 42 | int dflt: 1; // deflate-conversion facility 43 | int vxp2: 1; // vector-packed-decimal-enhancement facility 2 44 | int nnpa: 1; // neural network processing assist facility 45 | int pcimio: 1; // PCI mio facility 46 | int sie: 1; // virtualization support 47 | 48 | // Make sure to update S390XFeaturesEnum below if you add a field here. 49 | } S390XFeatures; 50 | 51 | typedef struct { 52 | S390XFeatures features; 53 | } S390XInfo; 54 | 55 | S390XInfo GetS390XInfo(void); 56 | 57 | typedef struct { 58 | char platform[64]; // 0 terminated string 59 | } S390XPlatformTypeStrings; 60 | 61 | typedef struct { 62 | int num_processors; // -1 if N/A 63 | S390XPlatformTypeStrings type; 64 | } S390XPlatformStrings; 65 | 66 | S390XPlatformStrings GetS390XPlatformStrings(void); 67 | 68 | //////////////////////////////////////////////////////////////////////////////// 69 | // Introspection functions 70 | 71 | typedef enum { 72 | S390_ESAN3, 73 | S390_ZARCH, 74 | S390_STFLE, 75 | S390_MSA, 76 | S390_LDISP, 77 | S390_EIMM, 78 | S390_DFP, 79 | S390_EDAT, 80 | S390_ETF3EH, 81 | S390_HIGHGPRS, 82 | S390_TE, 83 | S390_VX, 84 | S390_VXD, 85 | S390_VXE, 86 | S390_GS, 87 | S390_VXE2, 88 | S390_VXP, 89 | S390_SORT, 90 | S390_DFLT, 91 | S390_VXP2, 92 | S390_NNPA, 93 | S390_PCIMIO, 94 | S390_SIE, 95 | S390X_LAST_, 96 | } S390XFeaturesEnum; 97 | 98 | int GetS390XFeaturesEnumValue(const S390XFeatures* features, S390XFeaturesEnum value); 99 | 100 | const char* GetS390XFeaturesEnumName(S390XFeaturesEnum); 101 | 102 | CPU_FEATURES_END_CPP_NAMESPACE 103 | 104 | #if !defined(CPU_FEATURES_ARCH_S390X) 105 | #error "Including cpuinfo_s390x.h from a non-s390x target." 106 | #endif 107 | 108 | #endif // CPU_FEATURES_INCLUDE_CPUINFO_S390X_H_ 109 | -------------------------------------------------------------------------------- /deps/cpu_features/include/internal/bit_utils.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef CPU_FEATURES_INCLUDE_INTERNAL_BIT_UTILS_H_ 16 | #define CPU_FEATURES_INCLUDE_INTERNAL_BIT_UTILS_H_ 17 | 18 | #include 19 | #include 20 | #include 21 | 22 | #include "cpu_features_macros.h" 23 | 24 | CPU_FEATURES_START_CPP_NAMESPACE 25 | 26 | inline static bool IsBitSet(uint32_t reg, uint32_t bit) { 27 | return (reg >> bit) & 0x1; 28 | } 29 | 30 | inline static uint32_t ExtractBitRange(uint32_t reg, uint32_t msb, 31 | uint32_t lsb) { 32 | const uint64_t bits = msb - lsb + 1ULL; 33 | const uint64_t mask = (1ULL << bits) - 1ULL; 34 | assert(msb >= lsb); 35 | return (reg >> lsb) & mask; 36 | } 37 | 38 | CPU_FEATURES_END_CPP_NAMESPACE 39 | 40 | #endif // CPU_FEATURES_INCLUDE_INTERNAL_BIT_UTILS_H_ 41 | -------------------------------------------------------------------------------- /deps/cpu_features/include/internal/cpuid_x86.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef CPU_FEATURES_INCLUDE_INTERNAL_CPUID_X86_H_ 16 | #define CPU_FEATURES_INCLUDE_INTERNAL_CPUID_X86_H_ 17 | 18 | #include 19 | 20 | #include "cpu_features_macros.h" 21 | 22 | CPU_FEATURES_START_CPP_NAMESPACE 23 | 24 | // A struct to hold the result of a call to cpuid. 25 | typedef struct { 26 | uint32_t eax, ebx, ecx, edx; 27 | } Leaf; 28 | 29 | // Returns the result of a call to the cpuid instruction. 30 | Leaf GetCpuidLeaf(uint32_t leaf_id, int ecx); 31 | 32 | // Returns the eax value of the XCR0 register. 33 | uint32_t GetXCR0Eax(void); 34 | 35 | CPU_FEATURES_END_CPP_NAMESPACE 36 | 37 | #endif // CPU_FEATURES_INCLUDE_INTERNAL_CPUID_X86_H_ 38 | -------------------------------------------------------------------------------- /deps/cpu_features/include/internal/filesystem.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // An interface for the filesystem that allows mocking the filesystem in 16 | // unittests. 17 | #ifndef CPU_FEATURES_INCLUDE_INTERNAL_FILESYSTEM_H_ 18 | #define CPU_FEATURES_INCLUDE_INTERNAL_FILESYSTEM_H_ 19 | 20 | #include 21 | #include 22 | 23 | #include "cpu_features_macros.h" 24 | 25 | CPU_FEATURES_START_CPP_NAMESPACE 26 | 27 | // Same as linux "open(filename, O_RDONLY)", retries automatically on EINTR. 28 | int CpuFeatures_OpenFile(const char* filename); 29 | 30 | // Same as linux "read(file_descriptor, buffer, buffer_size)", retries 31 | // automatically on EINTR. 32 | int CpuFeatures_ReadFile(int file_descriptor, void* buffer, size_t buffer_size); 33 | 34 | // Same as linux "close(file_descriptor)". 35 | void CpuFeatures_CloseFile(int file_descriptor); 36 | 37 | CPU_FEATURES_END_CPP_NAMESPACE 38 | 39 | #endif // CPU_FEATURES_INCLUDE_INTERNAL_FILESYSTEM_H_ 40 | -------------------------------------------------------------------------------- /deps/cpu_features/include/internal/stack_line_reader.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Reads a file line by line and stores the data on the stack. This allows 16 | // parsing files in one go without allocating. 17 | #ifndef CPU_FEATURES_INCLUDE_INTERNAL_STACK_LINE_READER_H_ 18 | #define CPU_FEATURES_INCLUDE_INTERNAL_STACK_LINE_READER_H_ 19 | 20 | #include 21 | 22 | #include "cpu_features_macros.h" 23 | #include "internal/string_view.h" 24 | 25 | CPU_FEATURES_START_CPP_NAMESPACE 26 | 27 | typedef struct { 28 | char buffer[STACK_LINE_READER_BUFFER_SIZE]; 29 | StringView view; 30 | int fd; 31 | bool skip_mode; 32 | } StackLineReader; 33 | 34 | // Initializes a StackLineReader. 35 | void StackLineReader_Initialize(StackLineReader* reader, int fd); 36 | 37 | typedef struct { 38 | StringView line; // A view of the line. 39 | bool eof; // Nothing more to read, we reached EOF. 40 | bool full_line; // If false the line was truncated to 41 | // STACK_LINE_READER_BUFFER_SIZE. 42 | } LineResult; 43 | 44 | // Reads the file pointed to by fd and tries to read a full line. 45 | LineResult StackLineReader_NextLine(StackLineReader* reader); 46 | 47 | CPU_FEATURES_END_CPP_NAMESPACE 48 | 49 | #endif // CPU_FEATURES_INCLUDE_INTERNAL_STACK_LINE_READER_H_ 50 | -------------------------------------------------------------------------------- /deps/cpu_features/include/internal/string_view.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // A view over a piece of string. The view is not 0 terminated. 16 | #ifndef CPU_FEATURES_INCLUDE_INTERNAL_STRING_VIEW_H_ 17 | #define CPU_FEATURES_INCLUDE_INTERNAL_STRING_VIEW_H_ 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | #include "cpu_features_macros.h" 24 | 25 | CPU_FEATURES_START_CPP_NAMESPACE 26 | 27 | typedef struct { 28 | const char* ptr; 29 | size_t size; 30 | } StringView; 31 | 32 | #ifdef __cplusplus 33 | static const StringView kEmptyStringView = {NULL, 0}; 34 | #else 35 | static const StringView kEmptyStringView; 36 | #endif 37 | 38 | // Returns a StringView from the provided string. 39 | // Passing NULL is valid only if size is 0. 40 | static inline StringView view(const char* str, const size_t size) { 41 | StringView view; 42 | view.ptr = str; 43 | view.size = size; 44 | return view; 45 | } 46 | 47 | static inline StringView str(const char* str) { return view(str, strlen(str)); } 48 | 49 | // Returns the index of the first occurrence of c in view or -1 if not found. 50 | int CpuFeatures_StringView_IndexOfChar(const StringView view, char c); 51 | 52 | // Returns the index of the first occurrence of sub_view in view or -1 if not 53 | // found. 54 | int CpuFeatures_StringView_IndexOf(const StringView view, 55 | const StringView sub_view); 56 | 57 | // Returns whether a is equal to b (same content). 58 | bool CpuFeatures_StringView_IsEquals(const StringView a, const StringView b); 59 | 60 | // Returns whether a starts with b. 61 | bool CpuFeatures_StringView_StartsWith(const StringView a, const StringView b); 62 | 63 | // Removes count characters from the beginning of view or kEmptyStringView if 64 | // count if greater than view.size. 65 | StringView CpuFeatures_StringView_PopFront(const StringView str_view, 66 | size_t count); 67 | 68 | // Removes count characters from the end of view or kEmptyStringView if count if 69 | // greater than view.size. 70 | StringView CpuFeatures_StringView_PopBack(const StringView str_view, 71 | size_t count); 72 | 73 | // Keeps the count first characters of view or view if count if greater than 74 | // view.size. 75 | StringView CpuFeatures_StringView_KeepFront(const StringView str_view, 76 | size_t count); 77 | 78 | // Retrieves the first character of view. If view is empty the behavior is 79 | // undefined. 80 | char CpuFeatures_StringView_Front(const StringView view); 81 | 82 | // Retrieves the last character of view. If view is empty the behavior is 83 | // undefined. 84 | char CpuFeatures_StringView_Back(const StringView view); 85 | 86 | // Removes leading and tailing space characters. 87 | StringView CpuFeatures_StringView_TrimWhitespace(StringView view); 88 | 89 | // Convert StringView to positive integer. e.g. "42", "0x2a". 90 | // Returns -1 on error. 91 | int CpuFeatures_StringView_ParsePositiveNumber(const StringView view); 92 | 93 | // Copies src StringView to dst buffer. 94 | void CpuFeatures_StringView_CopyString(const StringView src, char* dst, 95 | size_t dst_size); 96 | 97 | // Checks if line contains the specified whitespace separated word. 98 | bool CpuFeatures_StringView_HasWord(const StringView line, 99 | const char* const word, 100 | const char separator); 101 | 102 | // Get key/value from line. key and value are separated by ": ". 103 | // key and value are cleaned up from leading and trailing whitespaces. 104 | bool CpuFeatures_StringView_GetAttributeKeyValue(const StringView line, 105 | StringView* key, 106 | StringView* value); 107 | 108 | CPU_FEATURES_END_CPP_NAMESPACE 109 | 110 | #endif // CPU_FEATURES_INCLUDE_INTERNAL_STRING_VIEW_H_ 111 | -------------------------------------------------------------------------------- /deps/cpu_features/include/internal/windows_utils.h: -------------------------------------------------------------------------------- 1 | // Copyright 2022 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef CPU_FEATURES_INCLUDE_INTERNAL_WINDOWS_UTILS_H_ 16 | #define CPU_FEATURES_INCLUDE_INTERNAL_WINDOWS_UTILS_H_ 17 | 18 | #include "cpu_features_macros.h" 19 | 20 | #ifdef CPU_FEATURES_OS_WINDOWS 21 | 22 | #include // IsProcessorFeaturePresent 23 | 24 | // modern WinSDK winnt.h contains newer features detection definitions 25 | #if !defined(PF_SSSE3_INSTRUCTIONS_AVAILABLE) 26 | #define PF_SSSE3_INSTRUCTIONS_AVAILABLE 36 27 | #endif 28 | 29 | #if !defined(PF_SSE4_1_INSTRUCTIONS_AVAILABLE) 30 | #define PF_SSE4_1_INSTRUCTIONS_AVAILABLE 37 31 | #endif 32 | 33 | #if !defined(PF_SSE4_2_INSTRUCTIONS_AVAILABLE) 34 | #define PF_SSE4_2_INSTRUCTIONS_AVAILABLE 38 35 | #endif 36 | 37 | #if !defined(PF_ARM_VFP_32_REGISTERS_AVAILABLE) 38 | #define PF_ARM_VFP_32_REGISTERS_AVAILABLE 18 39 | #endif 40 | 41 | #if !defined(PF_ARM_NEON_INSTRUCTIONS_AVAILABLE) 42 | #define PF_ARM_NEON_INSTRUCTIONS_AVAILABLE 19 43 | #endif 44 | 45 | #if !defined(PF_ARM_V8_CRYPTO_INSTRUCTIONS_AVAILABLE) 46 | #define PF_ARM_V8_CRYPTO_INSTRUCTIONS_AVAILABLE 30 47 | #endif 48 | 49 | #if !defined(PF_ARM_V8_CRC32_INSTRUCTIONS_AVAILABLE) 50 | #define PF_ARM_V8_CRC32_INSTRUCTIONS_AVAILABLE 31 51 | #endif 52 | 53 | #if !defined(PF_ARM_V81_ATOMIC_INSTRUCTIONS_AVAILABLE) 54 | #define PF_ARM_V81_ATOMIC_INSTRUCTIONS_AVAILABLE 34 55 | #endif 56 | 57 | #if !defined(PF_ARM_V82_DP_INSTRUCTIONS_AVAILABLE) 58 | #define PF_ARM_V82_DP_INSTRUCTIONS_AVAILABLE 43 59 | #endif 60 | 61 | #if !defined(PF_ARM_V83_JSCVT_INSTRUCTIONS_AVAILABLE) 62 | #define PF_ARM_V83_JSCVT_INSTRUCTIONS_AVAILABLE 44 63 | #endif 64 | 65 | #if !defined(PF_ARM_V83_LRCPC_INSTRUCTIONS_AVAILABLE) 66 | #define PF_ARM_V83_LRCPC_INSTRUCTIONS_AVAILABLE 45 67 | #endif 68 | 69 | #endif // CPU_FEATURES_OS_WINDOWS 70 | #endif // CPU_FEATURES_INCLUDE_INTERNAL_WINDOWS_UTILS_H_ 71 | -------------------------------------------------------------------------------- /deps/cpu_features/ndk_compat/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | # 3 | # library : NDK compat 4 | # 5 | find_package(Threads REQUIRED) 6 | set (NDK_COMPAT_HDRS cpu-features.h) 7 | set (NDK_COMPAT_SRCS 8 | cpu-features.c 9 | $ 10 | $ 11 | ) 12 | # Note that following `add_cpu_features_headers_and_sources` will use 13 | # NDK_COMPAT_SRCS in lieu of NDK_COMPAT_HDRS because we don't want cpu_features 14 | # headers to be installed alongside ndk_compat. 15 | add_cpu_features_headers_and_sources(NDK_COMPAT_SRCS NDK_COMPAT_SRCS) 16 | add_library(ndk_compat ${NDK_COMPAT_HDRS} ${NDK_COMPAT_SRCS}) 17 | setup_include_and_definitions(ndk_compat) 18 | target_include_directories(ndk_compat PUBLIC $) 19 | target_link_libraries(ndk_compat PUBLIC ${CMAKE_DL_LIBS} ${CMAKE_THREAD_LIBS_INIT}) 20 | set_target_properties(ndk_compat PROPERTIES PUBLIC_HEADER "${NDK_COMPAT_HDRS}") 21 | 22 | include(GNUInstallDirs) 23 | install(TARGETS ndk_compat 24 | EXPORT CpuFeaturesNdkCompatTargets 25 | PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/ndk_compat 26 | ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} 27 | LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} 28 | RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} 29 | ) 30 | install(EXPORT CpuFeaturesNdkCompatTargets 31 | NAMESPACE CpuFeatures:: 32 | DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/CpuFeaturesNdkCompat 33 | COMPONENT Devel 34 | ) 35 | include(CMakePackageConfigHelpers) 36 | configure_package_config_file(${PROJECT_SOURCE_DIR}/cmake/CpuFeaturesNdkCompatConfig.cmake.in 37 | "${PROJECT_BINARY_DIR}/CpuFeaturesNdkCompatConfig.cmake" 38 | INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/CpuFeaturesNdkCompat" 39 | NO_SET_AND_CHECK_MACRO 40 | NO_CHECK_REQUIRED_COMPONENTS_MACRO 41 | ) 42 | write_basic_package_version_file( 43 | "${PROJECT_BINARY_DIR}/CpuFeaturesNdkCompatConfigVersion.cmake" 44 | COMPATIBILITY SameMajorVersion 45 | ) 46 | install( 47 | FILES 48 | "${PROJECT_BINARY_DIR}/CpuFeaturesNdkCompatConfig.cmake" 49 | "${PROJECT_BINARY_DIR}/CpuFeaturesNdkCompatConfigVersion.cmake" 50 | DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/CpuFeaturesNdkCompat" 51 | COMPONENT Devel 52 | ) 53 | 54 | # 55 | # program : NDK compat test program 56 | # 57 | if(BUILD_TESTING) 58 | add_executable(ndk-compat-test ndk-compat-test.c) 59 | target_link_libraries(ndk-compat-test PRIVATE ndk_compat) 60 | endif() 61 | -------------------------------------------------------------------------------- /deps/cpu_features/ndk_compat/README.md: -------------------------------------------------------------------------------- 1 | Provides a header compatible with [android's NDK cpu-features.h](https://android.googlesource.com/platform/ndk/+/master/sources/android/cpufeatures/cpu-features.h). 2 | 3 | It is intended to be a drop in replacement for this header and help users 4 | transition from the NDK to [Google's cpu_features library](https://github.com/google/cpu_features). 5 | -------------------------------------------------------------------------------- /deps/cpu_features/ndk_compat/cpu-features.c: -------------------------------------------------------------------------------- 1 | #include "cpu-features.h" 2 | 3 | #include 4 | 5 | #include "cpu_features_macros.h" 6 | #include "internal/filesystem.h" 7 | #include "internal/stack_line_reader.h" 8 | #include "internal/string_view.h" 9 | 10 | #if defined(CPU_FEATURES_ARCH_ARM) 11 | #include "cpuinfo_arm.h" 12 | #elif defined(CPU_FEATURES_ARCH_X86) 13 | #include "cpuinfo_x86.h" 14 | #elif defined(CPU_FEATURES_ARCH_MIPS) 15 | #include "cpuinfo_mips.h" 16 | #elif defined(CPU_FEATURES_ARCH_AARCH64) 17 | #include "cpuinfo_aarch64.h" 18 | #endif 19 | 20 | static pthread_once_t g_once; 21 | static int g_inited; 22 | static uint64_t g_cpuFeatures; 23 | static int g_cpuCount; 24 | 25 | #ifdef CPU_FEATURES_ARCH_ARM 26 | static uint32_t g_cpuIdArm; 27 | #endif 28 | 29 | static void set_cpu_mask_bit(uint32_t index, uint32_t* cpu_mask) { 30 | *cpu_mask |= 1UL << index; 31 | } 32 | 33 | // Examples of valid inputs: "31", "4-31" 34 | static void parse_cpu_mask(const StringView text, uint32_t* cpu_mask) { 35 | int separator_index = CpuFeatures_StringView_IndexOfChar(text, '-'); 36 | if (separator_index < 0) { // A single cpu index 37 | int cpu_index = CpuFeatures_StringView_ParsePositiveNumber(text); 38 | if (cpu_index < 0) return; 39 | set_cpu_mask_bit(cpu_index, cpu_mask); 40 | } else { 41 | int cpu_index_a = CpuFeatures_StringView_ParsePositiveNumber( 42 | CpuFeatures_StringView_KeepFront(text, separator_index)); 43 | int cpu_index_b = CpuFeatures_StringView_ParsePositiveNumber( 44 | CpuFeatures_StringView_PopFront(text, separator_index + 1)); 45 | int i; 46 | if (cpu_index_a < 0 || cpu_index_b < 0) return; 47 | for (i = cpu_index_a; i <= cpu_index_b; ++i) { 48 | if (i < 32) { 49 | set_cpu_mask_bit(i, cpu_mask); 50 | } 51 | } 52 | } 53 | } 54 | 55 | // Format specification from 56 | // https://www.kernel.org/doc/Documentation/cputopology.txt 57 | // Examples of valid inputs: "31", "2,4-31,32-63", "0-1,3" 58 | static void parse_cpu_mask_line(const LineResult result, uint32_t* cpu_mask) { 59 | if (!result.full_line || result.eof) return; 60 | StringView line = result.line; 61 | for (; line.size > 0;) { 62 | int next_entry_index = CpuFeatures_StringView_IndexOfChar(line, ','); 63 | if (next_entry_index < 0) { 64 | parse_cpu_mask(line, cpu_mask); 65 | break; 66 | } 67 | StringView entry = CpuFeatures_StringView_KeepFront(line, next_entry_index); 68 | parse_cpu_mask(entry, cpu_mask); 69 | line = CpuFeatures_StringView_PopFront(line, next_entry_index + 1); 70 | } 71 | } 72 | 73 | static void update_cpu_mask_from_file(const char* filename, 74 | uint32_t* cpu_mask) { 75 | const int fd = CpuFeatures_OpenFile(filename); 76 | if (fd >= 0) { 77 | StackLineReader reader; 78 | StackLineReader_Initialize(&reader, fd); 79 | parse_cpu_mask_line(StackLineReader_NextLine(&reader), cpu_mask); 80 | CpuFeatures_CloseFile(fd); 81 | } 82 | } 83 | 84 | static int get_cpu_count(void) { 85 | uint32_t cpu_mask = 0; 86 | update_cpu_mask_from_file("/sys/devices/system/cpu/present", &cpu_mask); 87 | update_cpu_mask_from_file("/sys/devices/system/cpu/possible", &cpu_mask); 88 | return __builtin_popcount(cpu_mask); 89 | } 90 | 91 | static void android_cpuInit(void) { 92 | g_cpuFeatures = 0; 93 | g_cpuCount = 1; 94 | g_inited = 1; 95 | 96 | g_cpuCount = get_cpu_count(); 97 | if (g_cpuCount == 0) { 98 | g_cpuCount = 1; 99 | } 100 | #if defined(CPU_FEATURES_ARCH_ARM) 101 | ArmInfo info = GetArmInfo(); 102 | if (info.architecture == 7) g_cpuFeatures |= ANDROID_CPU_ARM_FEATURE_ARMv7; 103 | if (info.features.vfpv3) g_cpuFeatures |= ANDROID_CPU_ARM_FEATURE_VFPv3; 104 | if (info.features.neon) { 105 | g_cpuFeatures |= ANDROID_CPU_ARM_FEATURE_NEON; 106 | g_cpuFeatures |= ANDROID_CPU_ARM_FEATURE_VFP_D32; 107 | } 108 | if (info.features.vfpv3d16) g_cpuFeatures |= ANDROID_CPU_ARM_FEATURE_VFP_FP16; 109 | if (info.features.idiva) g_cpuFeatures |= ANDROID_CPU_ARM_FEATURE_IDIV_ARM; 110 | if (info.features.idivt) g_cpuFeatures |= ANDROID_CPU_ARM_FEATURE_IDIV_THUMB2; 111 | if (info.features.iwmmxt) g_cpuFeatures |= ANDROID_CPU_ARM_FEATURE_iWMMXt; 112 | if (info.features.aes) g_cpuFeatures |= ANDROID_CPU_ARM_FEATURE_AES; 113 | if (info.features.pmull) g_cpuFeatures |= ANDROID_CPU_ARM_FEATURE_PMULL; 114 | if (info.features.sha1) g_cpuFeatures |= ANDROID_CPU_ARM_FEATURE_SHA1; 115 | if (info.features.sha2) g_cpuFeatures |= ANDROID_CPU_ARM_FEATURE_SHA2; 116 | if (info.features.crc32) g_cpuFeatures |= ANDROID_CPU_ARM_FEATURE_CRC32; 117 | if (info.architecture >= 6) 118 | g_cpuFeatures |= ANDROID_CPU_ARM_FEATURE_LDREX_STREX; 119 | if (info.features.vfp) g_cpuFeatures |= ANDROID_CPU_ARM_FEATURE_VFPv2; 120 | if (info.features.vfpv4) { 121 | g_cpuFeatures |= ANDROID_CPU_ARM_FEATURE_VFP_FMA; 122 | g_cpuFeatures |= ANDROID_CPU_ARM_FEATURE_NEON_FMA; 123 | } 124 | g_cpuIdArm = GetArmCpuId(&info); 125 | #elif defined(CPU_FEATURES_ARCH_X86) 126 | X86Info info = GetX86Info(); 127 | if (info.features.ssse3) g_cpuFeatures |= ANDROID_CPU_X86_FEATURE_SSSE3; 128 | if (info.features.popcnt) g_cpuFeatures |= ANDROID_CPU_X86_FEATURE_POPCNT; 129 | if (info.features.movbe) g_cpuFeatures |= ANDROID_CPU_X86_FEATURE_MOVBE; 130 | if (info.features.sse4_1) g_cpuFeatures |= ANDROID_CPU_X86_FEATURE_SSE4_1; 131 | if (info.features.sse4_2) g_cpuFeatures |= ANDROID_CPU_X86_FEATURE_SSE4_2; 132 | if (info.features.aes) g_cpuFeatures |= ANDROID_CPU_X86_FEATURE_AES_NI; 133 | if (info.features.avx) g_cpuFeatures |= ANDROID_CPU_X86_FEATURE_AVX; 134 | if (info.features.rdrnd) g_cpuFeatures |= ANDROID_CPU_X86_FEATURE_RDRAND; 135 | if (info.features.avx2) g_cpuFeatures |= ANDROID_CPU_X86_FEATURE_AVX2; 136 | if (info.features.sha) g_cpuFeatures |= ANDROID_CPU_X86_FEATURE_SHA_NI; 137 | #elif defined(CPU_FEATURES_ARCH_MIPS) 138 | MipsInfo info = GetMipsInfo(); 139 | if (info.features.r6) g_cpuFeatures |= ANDROID_CPU_MIPS_FEATURE_R6; 140 | if (info.features.msa) g_cpuFeatures |= ANDROID_CPU_MIPS_FEATURE_MSA; 141 | #elif defined(CPU_FEATURES_ARCH_AARCH64) 142 | Aarch64Info info = GetAarch64Info(); 143 | if (info.features.fp) g_cpuFeatures |= ANDROID_CPU_ARM64_FEATURE_FP; 144 | if (info.features.asimd) g_cpuFeatures |= ANDROID_CPU_ARM64_FEATURE_ASIMD; 145 | if (info.features.aes) g_cpuFeatures |= ANDROID_CPU_ARM64_FEATURE_AES; 146 | if (info.features.pmull) g_cpuFeatures |= ANDROID_CPU_ARM64_FEATURE_PMULL; 147 | if (info.features.sha1) g_cpuFeatures |= ANDROID_CPU_ARM64_FEATURE_SHA1; 148 | if (info.features.sha2) g_cpuFeatures |= ANDROID_CPU_ARM64_FEATURE_SHA2; 149 | if (info.features.crc32) g_cpuFeatures |= ANDROID_CPU_ARM64_FEATURE_CRC32; 150 | #endif 151 | } 152 | 153 | AndroidCpuFamily android_getCpuFamily(void) { 154 | #if defined(CPU_FEATURES_ARCH_ARM) 155 | return ANDROID_CPU_FAMILY_ARM; 156 | #elif defined(CPU_FEATURES_ARCH_X86_32) 157 | return ANDROID_CPU_FAMILY_X86; 158 | #elif defined(CPU_FEATURES_ARCH_MIPS64) 159 | return ANDROID_CPU_FAMILY_MIPS64; 160 | #elif defined(CPU_FEATURES_ARCH_MIPS32) 161 | return ANDROID_CPU_FAMILY_MIPS; 162 | #elif defined(CPU_FEATURES_ARCH_AARCH64) 163 | return ANDROID_CPU_FAMILY_ARM64; 164 | #elif defined(CPU_FEATURES_ARCH_X86_64) 165 | return ANDROID_CPU_FAMILY_X86_64; 166 | #else 167 | return ANDROID_CPU_FAMILY_UNKNOWN; 168 | #endif 169 | } 170 | 171 | uint64_t android_getCpuFeatures(void) { 172 | pthread_once(&g_once, android_cpuInit); 173 | return g_cpuFeatures; 174 | } 175 | 176 | int android_getCpuCount(void) { 177 | pthread_once(&g_once, android_cpuInit); 178 | return g_cpuCount; 179 | } 180 | 181 | static void android_cpuInitDummy(void) { g_inited = 1; } 182 | 183 | int android_setCpu(int cpu_count, uint64_t cpu_features) { 184 | /* Fail if the library was already initialized. */ 185 | if (g_inited) return 0; 186 | g_cpuCount = (cpu_count <= 0 ? 1 : cpu_count); 187 | g_cpuFeatures = cpu_features; 188 | pthread_once(&g_once, android_cpuInitDummy); 189 | return 1; 190 | } 191 | 192 | #ifdef CPU_FEATURES_ARCH_ARM 193 | 194 | uint32_t android_getCpuIdArm(void) { 195 | pthread_once(&g_once, android_cpuInit); 196 | return g_cpuIdArm; 197 | } 198 | 199 | int android_setCpuArm(int cpu_count, uint64_t cpu_features, uint32_t cpu_id) { 200 | if (!android_setCpu(cpu_count, cpu_features)) return 0; 201 | g_cpuIdArm = cpu_id; 202 | return 1; 203 | } 204 | 205 | #endif // CPU_FEATURES_ARCH_ARM 206 | -------------------------------------------------------------------------------- /deps/cpu_features/ndk_compat/ndk-compat-test.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "cpu-features.h" 4 | 5 | int main() { 6 | printf("android_getCpuFamily()=%d\n", android_getCpuFamily()); 7 | printf("android_getCpuFeatures()=0x%08llx\n", android_getCpuFeatures()); 8 | printf("android_getCpuCount()=%d\n", android_getCpuCount()); 9 | #ifdef __arm__ 10 | printf("android_getCpuIdArm()=0x%04x\n", android_getCpuIdArm()); 11 | #endif //__arm__ 12 | } 13 | -------------------------------------------------------------------------------- /deps/cpu_features/scripts/generate_badges.d: -------------------------------------------------------------------------------- 1 | import std.algorithm : each, map, cartesianProduct, filter, joiner, sort, uniq; 2 | import std.array : array; 3 | import std.conv : to; 4 | import std.format; 5 | import std.range : chain, only; 6 | import std.stdio; 7 | import std.traits : EnumMembers; 8 | 9 | enum BuildSystem 10 | { 11 | CMake, 12 | Bazel 13 | } 14 | 15 | enum Cpu 16 | { 17 | amd64, 18 | AArch64, 19 | ARM, 20 | MIPS, 21 | POWER, 22 | RISCV, 23 | s390x, 24 | } 25 | 26 | enum Os 27 | { 28 | Linux, 29 | FreeBSD, 30 | MacOS, 31 | Windows, 32 | } 33 | 34 | struct Badge 35 | { 36 | const: 37 | 38 | Cpu cpu; 39 | Os os; 40 | BuildSystem build_system; 41 | 42 | string id() 43 | { 44 | return format("%d%c%d", cast(uint)(os) + 1, cast(char)('a' + cpu), cast(uint)(build_system)); 45 | } 46 | 47 | string disabled_image_ref() 48 | { 49 | return format("[d%d]", cast(uint)(build_system)); 50 | } 51 | 52 | string link_ref() 53 | { 54 | return format("[l%s]", id()); 55 | } 56 | 57 | string image_ref() 58 | { 59 | return format("[i%s]", id()); 60 | } 61 | 62 | bool enabled() 63 | { 64 | final switch (build_system) 65 | { 66 | case BuildSystem.CMake: 67 | return os == Os.Linux || cpu == Cpu.amd64; 68 | case BuildSystem.Bazel: 69 | return os == Os.Linux && cpu == Cpu.amd64; 70 | } 71 | } 72 | 73 | string text() 74 | { 75 | if (enabled()) 76 | return format("[![]%s]%s", image_ref, link_ref); 77 | return format("![]%s", disabled_image_ref); 78 | } 79 | 80 | string disabled_image_link() 81 | { 82 | return format("%s: https://img.shields.io/badge/%s-N%%2FA-lightgrey", disabled_image_ref, build_system); 83 | } 84 | 85 | string filename() 86 | { 87 | import std.uni : toLower; 88 | 89 | return toLower(format("%s_%s_%s.yml", cpu, os, build_system)); 90 | } 91 | 92 | string link_decl() 93 | { 94 | return format("%s: https://github.com/google/cpu_features/actions/workflows/%s", link_ref, filename()); 95 | } 96 | 97 | string image_decl() 98 | { 99 | return format( 100 | "%s: https://img.shields.io/github/actions/workflow/status/google/cpu_features/%s?branch=main&label=%s", image_ref, filename(), build_system); 101 | } 102 | } 103 | 104 | auto tableHeader(in Cpu[] cpus) 105 | { 106 | return chain(only("Os"), cpus.map!(to!string)).array; 107 | } 108 | 109 | auto tableAlignment(in Cpu[] cpus) 110 | { 111 | return chain(only(":--"), cpus.map!(v => "--:")).array; 112 | } 113 | 114 | auto tableCell(Range)(in Os os, in Cpu cpu, Range badges) 115 | { 116 | return badges 117 | .filter!(b => b.cpu == cpu && b.os == os) 118 | .map!(b => b.text()) 119 | .joiner("
") 120 | .to!string; 121 | } 122 | 123 | auto tableRow(Range)(in Os os, in Cpu[] cpus, Range badges) 124 | { 125 | return chain(only(os.to!string), cpus.map!(cpu => tableCell(os, cpu, badges))).array; 126 | } 127 | 128 | auto tableRows(Range)(in Os[] oses, in Cpu[] cpus, Range badges) 129 | { 130 | return oses.map!(os => tableRow(os, cpus, badges)).array; 131 | } 132 | 133 | auto table(Range)(in Os[] oses, in Cpu[] cpus, Range badges) 134 | { 135 | return chain(only(tableHeader(cpus)), only(tableAlignment(cpus)), tableRows(oses, cpus, badges)); 136 | } 137 | 138 | void main() 139 | { 140 | immutable allCpus = [EnumMembers!Cpu]; 141 | immutable allOses = [EnumMembers!Os]; 142 | immutable allBuildSystems = [EnumMembers!BuildSystem]; 143 | 144 | auto badges = cartesianProduct(allCpus, allOses, allBuildSystems).map!( 145 | t => Badge(t[0], t[1], t[2])); 146 | 147 | writefln("%(|%-( %s |%) |\n%) |", table(allOses, allCpus, badges)); 148 | writeln(); 149 | badges 150 | .filter!(b => !b.enabled) 151 | .map!(b => b.disabled_image_link()) 152 | .array 153 | .sort 154 | .uniq 155 | .each!writeln; 156 | 157 | badges 158 | .filter!(b => b.enabled) 159 | .map!(b => [b.link_decl(), b.image_decl()]) 160 | .joiner() 161 | .array 162 | .sort 163 | .uniq 164 | .each!writeln; 165 | } 166 | -------------------------------------------------------------------------------- /deps/cpu_features/scripts/make_release.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -e # Fail on error 4 | set -u # Treat unset variables as an error and exit immediately 5 | 6 | ACTION='\033[1;90m' 7 | FINISHED='\033[1;96m' 8 | NOCOLOR='\033[0m' 9 | ERROR='\033[0;31m' 10 | 11 | echo -e "${ACTION}Checking environnement${NOCOLOR}" 12 | if [[ ! $1 =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]] 13 | then 14 | echo -e "${ERROR}Invalid version number. Aborting. ${NOCOLOR}" 15 | exit 1 16 | fi 17 | 18 | declare -r VERSION=$1 19 | declare -r GIT_TAG="v$1" 20 | 21 | BRANCH=$(git rev-parse --abbrev-ref HEAD) 22 | if [[ "${BRANCH}" != "main" ]] 23 | then 24 | echo -e "${ERROR}Not on main. Aborting. ${NOCOLOR}" 25 | echo 26 | exit 1 27 | fi 28 | 29 | git fetch 30 | HEADHASH=$(git rev-parse HEAD) 31 | UPSTREAMHASH=$(git rev-parse main@{upstream}) 32 | 33 | if [[ "${HEADHASH}" != "${UPSTREAMHASH}" ]] 34 | then 35 | echo -e "${ERROR}Not up to date with origin. Aborting.${NOCOLOR}" 36 | echo 37 | exit 1 38 | fi 39 | 40 | git update-index -q --refresh 41 | if ! git diff-index --quiet HEAD -- 42 | then 43 | echo -e "${ERROR}Branch has uncommited changes. Aborting.${NOCOLOR}" 44 | exit 1 45 | fi 46 | 47 | if [ ! -z "$(git ls-files --exclude-standard --others)" ] 48 | then 49 | echo -e "${ERROR}Branch has untracked files. Aborting.${NOCOLOR}" 50 | exit 1 51 | fi 52 | 53 | declare -r LATEST_GIT_TAG=$(git describe --tags --abbrev=0) 54 | declare -r LATEST_VERSION=${LATEST_GIT_TAG#"v"} 55 | 56 | if ! dpkg --compare-versions "${VERSION}" "gt" "${LATEST_VERSION}" 57 | then 58 | echo -e "${ERROR}Invalid version ${VERSION} <= ${LATEST_VERSION} (latest). Aborting.${NOCOLOR}" 59 | exit 1 60 | fi 61 | 62 | echo -e "${ACTION}Modifying CMakeLists.txt${NOCOLOR}" 63 | sed -i "s/CpuFeatures VERSION ${LATEST_VERSION}/CpuFeatures VERSION ${VERSION}/g" CMakeLists.txt 64 | 65 | echo -e "${ACTION}Commit new revision${NOCOLOR}" 66 | git add CMakeLists.txt 67 | git commit -m"Release ${GIT_TAG}" 68 | 69 | echo -e "${ACTION}Create new tag${NOCOLOR}" 70 | git tag ${GIT_TAG} 71 | 72 | echo -e "${FINISHED}Manual steps:${NOCOLOR}" 73 | echo -e "${FINISHED} - Push the tag upstream 'git push origin ${GIT_TAG}'${NOCOLOR}" 74 | echo -e "${FINISHED} - Create a new release https://github.com/google/cpu_features/releases/new${NOCOLOR}" 75 | echo -e "${FINISHED} - Update the Release Notes 'gren release --override'${NOCOLOR}" 76 | -------------------------------------------------------------------------------- /deps/cpu_features/scripts/test_integration.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Toolchains for little-endian, 64-bit ARMv8 for GNU/Linux systems 4 | function set_aarch64-linux-gnu() { 5 | export TARGET=aarch64-linux-gnu 6 | } 7 | 8 | # Toolchains for little-endian, hard-float, 32-bit ARMv7 (and earlier) for GNU/Linux systems 9 | function set_arm-linux-gnueabihf() { 10 | export TARGET=arm-linux-gnueabihf 11 | } 12 | 13 | # Toolchains for little-endian, 32-bit ARMv8 for GNU/Linux systems 14 | function set_armv8l-linux-gnueabihf() { 15 | export TARGET=armv8l-linux-gnueabihf 16 | } 17 | 18 | # Toolchains for little-endian, soft-float, 32-bit ARMv7 (and earlier) for GNU/Linux systems 19 | function set_arm-linux-gnueabi() { 20 | export TARGET=arm-linux-gnueabi 21 | } 22 | 23 | # Toolchains for big-endian, 64-bit ARMv8 for GNU/Linux systems 24 | function set_aarch64_be-linux-gnu() { 25 | export TARGET=aarch64_be-linux-gnu 26 | } 27 | 28 | # Toolchains for big-endian, hard-float, 32-bit ARMv7 (and earlier) for GNU/Linux systems 29 | function set_armeb-linux-gnueabihf() { 30 | export TARGET=armeb-linux-gnueabihf 31 | } 32 | 33 | # Toolchains for big-endian, soft-float, 32-bit ARMv7 (and earlier) for GNU/Linux systems 34 | function set_armeb-linux-gnueabi() { 35 | export TARGET=armeb-linux-gnueabi 36 | } 37 | 38 | function set_mips32() { 39 | export TARGET=mips32 40 | } 41 | 42 | function set_mips32el() { 43 | export TARGET=mips32el 44 | } 45 | 46 | function set_mips64() { 47 | export TARGET=mips64 48 | } 49 | 50 | function set_mips64el() { 51 | export TARGET=mips64el 52 | } 53 | 54 | function set_x86_64() { 55 | export TARGET=x86_64 56 | } 57 | 58 | ENVIRONMENTS=" 59 | set_aarch64-linux-gnu 60 | set_arm-linux-gnueabihf 61 | set_armv8l-linux-gnueabihf 62 | set_arm-linux-gnueabi 63 | set_aarch64_be-linux-gnu 64 | set_armeb-linux-gnueabihf 65 | set_armeb-linux-gnueabi 66 | set_mips32 67 | set_mips32el 68 | set_mips64 69 | set_mips64el 70 | set_x86_64 71 | " 72 | 73 | set -e 74 | 75 | for SET_ENVIRONMENT in ${ENVIRONMENTS}; do 76 | echo "testing ${SET_ENVIRONMENT}" 77 | ${SET_ENVIRONMENT} 78 | ./"$(dirname -- "$0")"/run_integration.sh 79 | done 80 | -------------------------------------------------------------------------------- /deps/cpu_features/src/copy.inl: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include 16 | 17 | static void copy(char *__restrict dst, const char *src, size_t count) { 18 | for (size_t i = 0; i < count; ++i) dst[i] = src[i]; 19 | } 20 | -------------------------------------------------------------------------------- /deps/cpu_features/src/define_introspection.inl: -------------------------------------------------------------------------------- 1 | // Copyright 2017 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef INTROSPECTION_PREFIX 16 | #error "missing INTROSPECTION_PREFIX" 17 | #endif 18 | #ifndef INTROSPECTION_ENUM_PREFIX 19 | #error "missing INTROSPECTION_ENUM_PREFIX" 20 | #endif 21 | #ifndef INTROSPECTION_TABLE 22 | #error "missing INTROSPECTION_TABLE" 23 | #endif 24 | 25 | #include 26 | 27 | #define STRINGIZE_(s) #s 28 | #define STRINGIZE(s) STRINGIZE_(s) 29 | 30 | #define FEAT_TYPE_NAME__(X) X##Features 31 | #define FEAT_TYPE_NAME_(X) FEAT_TYPE_NAME__(X) 32 | #define FEAT_TYPE_NAME FEAT_TYPE_NAME_(INTROSPECTION_PREFIX) 33 | 34 | #define FEAT_ENUM_NAME__(X) X##FeaturesEnum 35 | #define FEAT_ENUM_NAME_(X) FEAT_ENUM_NAME__(X) 36 | #define FEAT_ENUM_NAME FEAT_ENUM_NAME_(INTROSPECTION_PREFIX) 37 | 38 | #define GET_FEAT_ENUM_VALUE__(X) Get##X##FeaturesEnumValue 39 | #define GET_FEAT_ENUM_VALUE_(X) GET_FEAT_ENUM_VALUE__(X) 40 | #define GET_FEAT_ENUM_VALUE GET_FEAT_ENUM_VALUE_(INTROSPECTION_PREFIX) 41 | 42 | #define GET_FEAT_ENUM_NAME__(X) Get##X##FeaturesEnumName 43 | #define GET_FEAT_ENUM_NAME_(X) GET_FEAT_ENUM_NAME__(X) 44 | #define GET_FEAT_ENUM_NAME GET_FEAT_ENUM_NAME_(INTROSPECTION_PREFIX) 45 | 46 | #define FEAT_ENUM_LAST__(X) X##_LAST_ 47 | #define FEAT_ENUM_LAST_(X) FEAT_ENUM_LAST__(X) 48 | #define FEAT_ENUM_LAST FEAT_ENUM_LAST_(INTROSPECTION_ENUM_PREFIX) 49 | 50 | // Generate individual getters and setters. 51 | #define LINE(ENUM, NAME, A, B, C) \ 52 | static void set_##ENUM(FEAT_TYPE_NAME* features, bool value) { \ 53 | features->NAME = value; \ 54 | } \ 55 | static int get_##ENUM(const FEAT_TYPE_NAME* features) { \ 56 | return features->NAME; \ 57 | } 58 | INTROSPECTION_TABLE 59 | #undef LINE 60 | 61 | // Generate getters table 62 | #define LINE(ENUM, NAME, A, B, C) [ENUM] = get_##ENUM, 63 | static int (*const kGetters[])(const FEAT_TYPE_NAME*) = {INTROSPECTION_TABLE}; 64 | #undef LINE 65 | 66 | // Generate setters table 67 | #define LINE(ENUM, NAME, A, B, C) [ENUM] = set_##ENUM, 68 | static void (*const kSetters[])(FEAT_TYPE_NAME*, bool) = {INTROSPECTION_TABLE}; 69 | #undef LINE 70 | 71 | // Implements the `GetXXXFeaturesEnumValue` API. 72 | int GET_FEAT_ENUM_VALUE(const FEAT_TYPE_NAME* features, FEAT_ENUM_NAME value) { 73 | if (value >= FEAT_ENUM_LAST) return false; 74 | return kGetters[value](features); 75 | } 76 | 77 | // Generate feature name table. 78 | #define LINE(ENUM, NAME, A, B, C) [ENUM] = STRINGIZE(NAME), 79 | static const char* kFeatureNames[] = {INTROSPECTION_TABLE}; 80 | #undef LINE 81 | 82 | // Implements the `GetXXXFeaturesEnumName` API. 83 | const char* GET_FEAT_ENUM_NAME(FEAT_ENUM_NAME value) { 84 | if (value >= FEAT_ENUM_LAST) return "unknown_feature"; 85 | return kFeatureNames[value]; 86 | } 87 | -------------------------------------------------------------------------------- /deps/cpu_features/src/define_introspection_and_hwcaps.inl: -------------------------------------------------------------------------------- 1 | // Copyright 2017 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "define_introspection.inl" 16 | #include "internal/hwcaps.h" 17 | 18 | #define LINE(ENUM, NAME, CPUINFO_FLAG, HWCAP, HWCAP2) \ 19 | [ENUM] = (HardwareCapabilities){HWCAP, HWCAP2}, 20 | static const HardwareCapabilities kHardwareCapabilities[] = { 21 | INTROSPECTION_TABLE}; 22 | #undef LINE 23 | 24 | #define LINE(ENUM, NAME, CPUINFO_FLAG, HWCAP, HWCAP2) [ENUM] = CPUINFO_FLAG, 25 | static const char* kCpuInfoFlags[] = {INTROSPECTION_TABLE}; 26 | #undef LINE 27 | -------------------------------------------------------------------------------- /deps/cpu_features/src/equals.inl: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include 16 | #include 17 | 18 | static bool equals(const char *lhs, const char *rhs, size_t count) { 19 | for (size_t i = 0; i < count; ++i) 20 | if (lhs[i] != rhs[i]) return false; 21 | return true; 22 | } 23 | -------------------------------------------------------------------------------- /deps/cpu_features/src/filesystem.c: -------------------------------------------------------------------------------- 1 | // Copyright 2017 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "internal/filesystem.h" 16 | 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | #if defined(CPU_FEATURES_MOCK_FILESYSTEM) 24 | // Implementation will be provided by test/filesystem_for_testing.cc. 25 | #elif defined(_MSC_VER) 26 | #include 27 | int CpuFeatures_OpenFile(const char* filename) { 28 | int fd = -1; 29 | _sopen_s(&fd, filename, _O_RDONLY, _SH_DENYWR, _S_IREAD); 30 | return fd; 31 | } 32 | 33 | void CpuFeatures_CloseFile(int file_descriptor) { _close(file_descriptor); } 34 | 35 | int CpuFeatures_ReadFile(int file_descriptor, void* buffer, 36 | size_t buffer_size) { 37 | return _read(file_descriptor, buffer, (unsigned int)buffer_size); 38 | } 39 | 40 | #else 41 | #include 42 | 43 | int CpuFeatures_OpenFile(const char* filename) { 44 | int result; 45 | do { 46 | result = open(filename, O_RDONLY); 47 | } while (result == -1L && errno == EINTR); 48 | return result; 49 | } 50 | 51 | void CpuFeatures_CloseFile(int file_descriptor) { close(file_descriptor); } 52 | 53 | int CpuFeatures_ReadFile(int file_descriptor, void* buffer, 54 | size_t buffer_size) { 55 | int result; 56 | do { 57 | result = read(file_descriptor, buffer, buffer_size); 58 | } while (result == -1L && errno == EINTR); 59 | return result; 60 | } 61 | 62 | #endif 63 | -------------------------------------------------------------------------------- /deps/cpu_features/src/hwcaps.c: -------------------------------------------------------------------------------- 1 | // Copyright 2017 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "internal/hwcaps.h" 16 | 17 | #include 18 | #include 19 | 20 | #include "cpu_features_macros.h" 21 | #include "internal/filesystem.h" 22 | #include "internal/string_view.h" 23 | 24 | static bool IsSet(const uint32_t mask, const uint32_t value) { 25 | if (mask == 0) return false; 26 | return (value & mask) == mask; 27 | } 28 | 29 | bool CpuFeatures_IsHwCapsSet(const HardwareCapabilities hwcaps_mask, 30 | const HardwareCapabilities hwcaps) { 31 | return IsSet(hwcaps_mask.hwcaps, hwcaps.hwcaps) || 32 | IsSet(hwcaps_mask.hwcaps2, hwcaps.hwcaps2); 33 | } 34 | 35 | #ifdef CPU_FEATURES_TEST 36 | // In test mode, hwcaps_for_testing will define the following functions. 37 | HardwareCapabilities CpuFeatures_GetHardwareCapabilities(void); 38 | const char* CpuFeatures_GetPlatformPointer(void); 39 | const char* CpuFeatures_GetBasePlatformPointer(void); 40 | #else 41 | 42 | // Debug facilities 43 | #if defined(NDEBUG) 44 | #define D(...) 45 | #else 46 | #include 47 | #define D(...) \ 48 | do { \ 49 | printf(__VA_ARGS__); \ 50 | fflush(stdout); \ 51 | } while (0) 52 | #endif 53 | 54 | //////////////////////////////////////////////////////////////////////////////// 55 | // Implementation of GetElfHwcapFromGetauxval 56 | //////////////////////////////////////////////////////////////////////////////// 57 | 58 | #define AT_HWCAP 16 59 | #define AT_HWCAP2 26 60 | #define AT_PLATFORM 15 61 | #define AT_BASE_PLATFORM 24 62 | 63 | #if defined(HAVE_STRONG_GETAUXVAL) 64 | #include 65 | static unsigned long GetElfHwcapFromGetauxval(uint32_t hwcap_type) { 66 | return getauxval(hwcap_type); 67 | } 68 | #elif defined(HAVE_DLFCN_H) 69 | // On Android we probe the system's C library for a 'getauxval' function and 70 | // call it if it exits, or return 0 for failure. This function is available 71 | // since API level 18. 72 | // 73 | // Note that getauxval() can't really be re-implemented here, because its 74 | // implementation does not parse /proc/self/auxv. Instead it depends on values 75 | // that are passed by the kernel at process-init time to the C runtime 76 | // initialization layer. 77 | 78 | #include 79 | 80 | typedef unsigned long getauxval_func_t(unsigned long); 81 | 82 | static uint32_t GetElfHwcapFromGetauxval(uint32_t hwcap_type) { 83 | uint32_t ret = 0; 84 | void *libc_handle = NULL; 85 | getauxval_func_t *func = NULL; 86 | 87 | dlerror(); // Cleaning error state before calling dlopen. 88 | libc_handle = dlopen("libc.so", RTLD_NOW); 89 | if (!libc_handle) { 90 | D("Could not dlopen() C library: %s\n", dlerror()); 91 | return 0; 92 | } 93 | func = (getauxval_func_t *)dlsym(libc_handle, "getauxval"); 94 | if (!func) { 95 | D("Could not find getauxval() in C library\n"); 96 | } else { 97 | // Note: getauxval() returns 0 on failure. Doesn't touch errno. 98 | ret = (uint32_t)(*func)(hwcap_type); 99 | } 100 | dlclose(libc_handle); 101 | return ret; 102 | } 103 | #else 104 | #error "This platform does not provide hardware capabilities." 105 | #endif 106 | 107 | // Implementation of GetHardwareCapabilities for OS that provide 108 | // GetElfHwcapFromGetauxval(). 109 | 110 | // Fallback when getauxval is not available, retrieves hwcaps from 111 | // "/proc/self/auxv". 112 | static uint32_t GetElfHwcapFromProcSelfAuxv(uint32_t hwcap_type) { 113 | struct { 114 | uint32_t tag; 115 | uint32_t value; 116 | } entry; 117 | uint32_t result = 0; 118 | const char filepath[] = "/proc/self/auxv"; 119 | const int fd = CpuFeatures_OpenFile(filepath); 120 | if (fd < 0) { 121 | D("Could not open %s\n", filepath); 122 | return 0; 123 | } 124 | for (;;) { 125 | const int ret = CpuFeatures_ReadFile(fd, (char *)&entry, sizeof entry); 126 | if (ret < 0) { 127 | D("Error while reading %s\n", filepath); 128 | break; 129 | } 130 | // Detect end of list. 131 | if (ret == 0 || (entry.tag == 0 && entry.value == 0)) { 132 | break; 133 | } 134 | if (entry.tag == hwcap_type) { 135 | result = entry.value; 136 | break; 137 | } 138 | } 139 | CpuFeatures_CloseFile(fd); 140 | return result; 141 | } 142 | 143 | // Retrieves hardware capabilities by first trying to call getauxval, if not 144 | // available falls back to reading "/proc/self/auxv". 145 | static unsigned long GetHardwareCapabilitiesFor(uint32_t type) { 146 | unsigned long hwcaps = GetElfHwcapFromGetauxval(type); 147 | if (!hwcaps) { 148 | D("Parsing /proc/self/auxv to extract ELF hwcaps!\n"); 149 | hwcaps = GetElfHwcapFromProcSelfAuxv(type); 150 | } 151 | return hwcaps; 152 | } 153 | 154 | HardwareCapabilities CpuFeatures_GetHardwareCapabilities(void) { 155 | HardwareCapabilities capabilities; 156 | capabilities.hwcaps = GetHardwareCapabilitiesFor(AT_HWCAP); 157 | capabilities.hwcaps2 = GetHardwareCapabilitiesFor(AT_HWCAP2); 158 | return capabilities; 159 | } 160 | 161 | const char *CpuFeatures_GetPlatformPointer(void) { 162 | return (const char *)GetHardwareCapabilitiesFor(AT_PLATFORM); 163 | } 164 | 165 | const char *CpuFeatures_GetBasePlatformPointer(void) { 166 | return (const char *)GetHardwareCapabilitiesFor(AT_BASE_PLATFORM); 167 | } 168 | 169 | #endif // CPU_FEATURES_TEST 170 | -------------------------------------------------------------------------------- /deps/cpu_features/src/impl_aarch64__base_implementation.inl: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include 16 | 17 | #include "cpuinfo_aarch64.h" 18 | #include "internal/bit_utils.h" 19 | #include "internal/filesystem.h" 20 | #include "internal/stack_line_reader.h" 21 | #include "internal/string_view.h" 22 | 23 | #if !defined(CPU_FEATURES_ARCH_AARCH64) 24 | #error "Cannot compile aarch64_base on a non aarch64 platform." 25 | #endif 26 | 27 | //////////////////////////////////////////////////////////////////////////////// 28 | // Definitions for introspection. 29 | //////////////////////////////////////////////////////////////////////////////// 30 | #define INTROSPECTION_TABLE \ 31 | LINE(AARCH64_FP, fp, "fp", AARCH64_HWCAP_FP, 0) \ 32 | LINE(AARCH64_ASIMD, asimd, "asimd", AARCH64_HWCAP_ASIMD, 0) \ 33 | LINE(AARCH64_EVTSTRM, evtstrm, "evtstrm", AARCH64_HWCAP_EVTSTRM, 0) \ 34 | LINE(AARCH64_AES, aes, "aes", AARCH64_HWCAP_AES, 0) \ 35 | LINE(AARCH64_PMULL, pmull, "pmull", AARCH64_HWCAP_PMULL, 0) \ 36 | LINE(AARCH64_SHA1, sha1, "sha1", AARCH64_HWCAP_SHA1, 0) \ 37 | LINE(AARCH64_SHA2, sha2, "sha2", AARCH64_HWCAP_SHA2, 0) \ 38 | LINE(AARCH64_CRC32, crc32, "crc32", AARCH64_HWCAP_CRC32, 0) \ 39 | LINE(AARCH64_ATOMICS, atomics, "atomics", AARCH64_HWCAP_ATOMICS, 0) \ 40 | LINE(AARCH64_FPHP, fphp, "fphp", AARCH64_HWCAP_FPHP, 0) \ 41 | LINE(AARCH64_ASIMDHP, asimdhp, "asimdhp", AARCH64_HWCAP_ASIMDHP, 0) \ 42 | LINE(AARCH64_CPUID, cpuid, "cpuid", AARCH64_HWCAP_CPUID, 0) \ 43 | LINE(AARCH64_ASIMDRDM, asimdrdm, "asimdrdm", AARCH64_HWCAP_ASIMDRDM, 0) \ 44 | LINE(AARCH64_JSCVT, jscvt, "jscvt", AARCH64_HWCAP_JSCVT, 0) \ 45 | LINE(AARCH64_FCMA, fcma, "fcma", AARCH64_HWCAP_FCMA, 0) \ 46 | LINE(AARCH64_LRCPC, lrcpc, "lrcpc", AARCH64_HWCAP_LRCPC, 0) \ 47 | LINE(AARCH64_DCPOP, dcpop, "dcpop", AARCH64_HWCAP_DCPOP, 0) \ 48 | LINE(AARCH64_SHA3, sha3, "sha3", AARCH64_HWCAP_SHA3, 0) \ 49 | LINE(AARCH64_SM3, sm3, "sm3", AARCH64_HWCAP_SM3, 0) \ 50 | LINE(AARCH64_SM4, sm4, "sm4", AARCH64_HWCAP_SM4, 0) \ 51 | LINE(AARCH64_ASIMDDP, asimddp, "asimddp", AARCH64_HWCAP_ASIMDDP, 0) \ 52 | LINE(AARCH64_SHA512, sha512, "sha512", AARCH64_HWCAP_SHA512, 0) \ 53 | LINE(AARCH64_SVE, sve, "sve", AARCH64_HWCAP_SVE, 0) \ 54 | LINE(AARCH64_ASIMDFHM, asimdfhm, "asimdfhm", AARCH64_HWCAP_ASIMDFHM, 0) \ 55 | LINE(AARCH64_DIT, dit, "dit", AARCH64_HWCAP_DIT, 0) \ 56 | LINE(AARCH64_USCAT, uscat, "uscat", AARCH64_HWCAP_USCAT, 0) \ 57 | LINE(AARCH64_ILRCPC, ilrcpc, "ilrcpc", AARCH64_HWCAP_ILRCPC, 0) \ 58 | LINE(AARCH64_FLAGM, flagm, "flagm", AARCH64_HWCAP_FLAGM, 0) \ 59 | LINE(AARCH64_SSBS, ssbs, "ssbs", AARCH64_HWCAP_SSBS, 0) \ 60 | LINE(AARCH64_SB, sb, "sb", AARCH64_HWCAP_SB, 0) \ 61 | LINE(AARCH64_PACA, paca, "paca", AARCH64_HWCAP_PACA, 0) \ 62 | LINE(AARCH64_PACG, pacg, "pacg", AARCH64_HWCAP_PACG, 0) \ 63 | LINE(AARCH64_DCPODP, dcpodp, "dcpodp", 0, AARCH64_HWCAP2_DCPODP) \ 64 | LINE(AARCH64_SVE2, sve2, "sve2", 0, AARCH64_HWCAP2_SVE2) \ 65 | LINE(AARCH64_SVEAES, sveaes, "sveaes", 0, AARCH64_HWCAP2_SVEAES) \ 66 | LINE(AARCH64_SVEPMULL, svepmull, "svepmull", 0, AARCH64_HWCAP2_SVEPMULL) \ 67 | LINE(AARCH64_SVEBITPERM, svebitperm, "svebitperm", 0, \ 68 | AARCH64_HWCAP2_SVEBITPERM) \ 69 | LINE(AARCH64_SVESHA3, svesha3, "svesha3", 0, AARCH64_HWCAP2_SVESHA3) \ 70 | LINE(AARCH64_SVESM4, svesm4, "svesm4", 0, AARCH64_HWCAP2_SVESM4) \ 71 | LINE(AARCH64_FLAGM2, flagm2, "flagm2", 0, AARCH64_HWCAP2_FLAGM2) \ 72 | LINE(AARCH64_FRINT, frint, "frint", 0, AARCH64_HWCAP2_FRINT) \ 73 | LINE(AARCH64_SVEI8MM, svei8mm, "svei8mm", 0, AARCH64_HWCAP2_SVEI8MM) \ 74 | LINE(AARCH64_SVEF32MM, svef32mm, "svef32mm", 0, AARCH64_HWCAP2_SVEF32MM) \ 75 | LINE(AARCH64_SVEF64MM, svef64mm, "svef64mm", 0, AARCH64_HWCAP2_SVEF64MM) \ 76 | LINE(AARCH64_SVEBF16, svebf16, "svebf16", 0, AARCH64_HWCAP2_SVEBF16) \ 77 | LINE(AARCH64_I8MM, i8mm, "i8mm", 0, AARCH64_HWCAP2_I8MM) \ 78 | LINE(AARCH64_BF16, bf16, "bf16", 0, AARCH64_HWCAP2_BF16) \ 79 | LINE(AARCH64_DGH, dgh, "dgh", 0, AARCH64_HWCAP2_DGH) \ 80 | LINE(AARCH64_RNG, rng, "rng", 0, AARCH64_HWCAP2_RNG) \ 81 | LINE(AARCH64_BTI, bti, "bti", 0, AARCH64_HWCAP2_BTI) \ 82 | LINE(AARCH64_MTE, mte, "mte", 0, AARCH64_HWCAP2_MTE) \ 83 | LINE(AARCH64_ECV, ecv, "ecv", 0, AARCH64_HWCAP2_ECV) \ 84 | LINE(AARCH64_AFP, afp, "afp", 0, AARCH64_HWCAP2_AFP) \ 85 | LINE(AARCH64_RPRES, rpres, "rpres", 0, AARCH64_HWCAP2_RPRES) 86 | #define INTROSPECTION_PREFIX Aarch64 87 | #define INTROSPECTION_ENUM_PREFIX AARCH64 88 | #include "define_introspection_and_hwcaps.inl" 89 | -------------------------------------------------------------------------------- /deps/cpu_features/src/impl_aarch64_linux_or_android.c: -------------------------------------------------------------------------------- 1 | // Copyright 2017 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "cpu_features_macros.h" 16 | 17 | #ifdef CPU_FEATURES_ARCH_AARCH64 18 | #if defined(CPU_FEATURES_OS_LINUX) || defined(CPU_FEATURES_OS_ANDROID) 19 | 20 | #include "impl_aarch64__base_implementation.inl" 21 | 22 | static bool HandleAarch64Line(const LineResult result, 23 | Aarch64Info* const info) { 24 | StringView line = result.line; 25 | StringView key, value; 26 | if (CpuFeatures_StringView_GetAttributeKeyValue(line, &key, &value)) { 27 | if (CpuFeatures_StringView_IsEquals(key, str("Features"))) { 28 | for (size_t i = 0; i < AARCH64_LAST_; ++i) { 29 | kSetters[i](&info->features, CpuFeatures_StringView_HasWord( 30 | value, kCpuInfoFlags[i], ' ')); 31 | } 32 | } else if (CpuFeatures_StringView_IsEquals(key, str("CPU implementer"))) { 33 | info->implementer = CpuFeatures_StringView_ParsePositiveNumber(value); 34 | } else if (CpuFeatures_StringView_IsEquals(key, str("CPU variant"))) { 35 | info->variant = CpuFeatures_StringView_ParsePositiveNumber(value); 36 | } else if (CpuFeatures_StringView_IsEquals(key, str("CPU part"))) { 37 | info->part = CpuFeatures_StringView_ParsePositiveNumber(value); 38 | } else if (CpuFeatures_StringView_IsEquals(key, str("CPU revision"))) { 39 | info->revision = CpuFeatures_StringView_ParsePositiveNumber(value); 40 | } 41 | } 42 | return !result.eof; 43 | } 44 | 45 | static void FillProcCpuInfoData(Aarch64Info* const info) { 46 | const int fd = CpuFeatures_OpenFile("/proc/cpuinfo"); 47 | if (fd >= 0) { 48 | StackLineReader reader; 49 | StackLineReader_Initialize(&reader, fd); 50 | for (;;) { 51 | if (!HandleAarch64Line(StackLineReader_NextLine(&reader), info)) { 52 | break; 53 | } 54 | } 55 | CpuFeatures_CloseFile(fd); 56 | } 57 | } 58 | 59 | static const Aarch64Info kEmptyAarch64Info; 60 | 61 | Aarch64Info GetAarch64Info(void) { 62 | // capabilities are fetched from both getauxval and /proc/cpuinfo so we can 63 | // have some information if the executable is sandboxed (aka no access to 64 | // /proc/cpuinfo). 65 | Aarch64Info info = kEmptyAarch64Info; 66 | 67 | FillProcCpuInfoData(&info); 68 | const HardwareCapabilities hwcaps = CpuFeatures_GetHardwareCapabilities(); 69 | for (size_t i = 0; i < AARCH64_LAST_; ++i) { 70 | if (CpuFeatures_IsHwCapsSet(kHardwareCapabilities[i], hwcaps)) { 71 | kSetters[i](&info.features, true); 72 | } 73 | } 74 | 75 | return info; 76 | } 77 | 78 | #endif // defined(CPU_FEATURES_OS_LINUX) || defined(CPU_FEATURES_OS_ANDROID) 79 | #endif // CPU_FEATURES_ARCH_AARCH64 80 | -------------------------------------------------------------------------------- /deps/cpu_features/src/impl_aarch64_macos_or_iphone.c: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "cpu_features_macros.h" 16 | 17 | #ifdef CPU_FEATURES_ARCH_AARCH64 18 | #if defined(CPU_FEATURES_OS_MACOS) || defined(CPU_FEATURES_OS_IPHONE) 19 | 20 | #include "impl_aarch64__base_implementation.inl" 21 | 22 | #if !defined(HAVE_SYSCTLBYNAME) 23 | #error "Darwin needs support for sysctlbyname" 24 | #endif 25 | #include 26 | 27 | #if defined(CPU_FEATURES_MOCK_SYSCTL_AARCH64) 28 | extern bool GetDarwinSysCtlByName(const char*); 29 | extern int GetDarwinSysCtlByNameValue(const char* name); 30 | #else 31 | static int GetDarwinSysCtlByNameValue(const char* name) { 32 | int enabled; 33 | size_t enabled_len = sizeof(enabled); 34 | const int failure = sysctlbyname(name, &enabled, &enabled_len, NULL, 0); 35 | return failure ? 0 : enabled; 36 | } 37 | 38 | static bool GetDarwinSysCtlByName(const char* name) { 39 | return GetDarwinSysCtlByNameValue(name) != 0; 40 | } 41 | #endif 42 | 43 | static const Aarch64Info kEmptyAarch64Info; 44 | 45 | Aarch64Info GetAarch64Info(void) { 46 | Aarch64Info info = kEmptyAarch64Info; 47 | 48 | // Handling Darwin platform through sysctlbyname. 49 | info.implementer = GetDarwinSysCtlByNameValue("hw.cputype"); 50 | info.variant = GetDarwinSysCtlByNameValue("hw.cpusubtype"); 51 | info.part = GetDarwinSysCtlByNameValue("hw.cpufamily"); 52 | info.revision = GetDarwinSysCtlByNameValue("hw.cpusubfamily"); 53 | 54 | info.features.fp = GetDarwinSysCtlByName("hw.optional.floatingpoint"); 55 | info.features.asimd = GetDarwinSysCtlByName("hw.optional.AdvSIMD"); 56 | info.features.aes = GetDarwinSysCtlByName("hw.optional.arm.FEAT_AES"); 57 | info.features.pmull = GetDarwinSysCtlByName("hw.optional.arm.FEAT_PMULL"); 58 | info.features.sha1 = GetDarwinSysCtlByName("hw.optional.arm.FEAT_SHA1"); 59 | info.features.sha2 = GetDarwinSysCtlByName("hw.optional.arm.FEAT_SHA2"); 60 | info.features.crc32 = GetDarwinSysCtlByName("hw.optional.armv8_crc32"); 61 | info.features.atomics = GetDarwinSysCtlByName("hw.optional.armv8_1_atomics"); 62 | info.features.fphp = GetDarwinSysCtlByName("hw.optional.neon_hpfp"); 63 | info.features.jscvt = GetDarwinSysCtlByName("hw.optional.arm.FEAT_JSCVT"); 64 | info.features.fcma = GetDarwinSysCtlByName("hw.optional.arm.FEAT_FCMA"); 65 | info.features.lrcpc = GetDarwinSysCtlByName("hw.optional.arm.FEAT_LRCPC"); 66 | info.features.sha3 = GetDarwinSysCtlByName("hw.optional.armv8_2_sha3"); 67 | info.features.sha512 = GetDarwinSysCtlByName("hw.optional.armv8_2_sha512"); 68 | info.features.asimdfhm = GetDarwinSysCtlByName("hw.optional.armv8_2_fhm"); 69 | info.features.flagm = GetDarwinSysCtlByName("hw.optional.arm.FEAT_FLAGM"); 70 | info.features.flagm2 = GetDarwinSysCtlByName("hw.optional.arm.FEAT_FLAGM2"); 71 | info.features.ssbs = GetDarwinSysCtlByName("hw.optional.arm.FEAT_SSBS"); 72 | info.features.sb = GetDarwinSysCtlByName("hw.optional.arm.FEAT_SB"); 73 | info.features.i8mm = GetDarwinSysCtlByName("hw.optional.arm.FEAT_I8MM"); 74 | info.features.bf16 = GetDarwinSysCtlByName("hw.optional.arm.FEAT_BF16"); 75 | info.features.bti = GetDarwinSysCtlByName("hw.optional.arm.FEAT_BTI"); 76 | info.features.ecv = GetDarwinSysCtlByName("hw.optional.arm.FEAT_ECV"); 77 | 78 | return info; 79 | } 80 | 81 | #endif // defined(CPU_FEATURES_OS_MACOS) || defined(CPU_FEATURES_OS_IPHONE) 82 | #endif // CPU_FEATURES_ARCH_AARCH64 83 | -------------------------------------------------------------------------------- /deps/cpu_features/src/impl_aarch64_windows.c: -------------------------------------------------------------------------------- 1 | // Copyright 2023 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "cpu_features_macros.h" 16 | 17 | #ifdef CPU_FEATURES_ARCH_AARCH64 18 | #ifdef CPU_FEATURES_OS_WINDOWS 19 | 20 | #include "cpuinfo_aarch64.h" 21 | 22 | //////////////////////////////////////////////////////////////////////////////// 23 | // Definitions for introspection. 24 | //////////////////////////////////////////////////////////////////////////////// 25 | #define INTROSPECTION_TABLE \ 26 | LINE(AARCH64_FP, fp, , , ) \ 27 | LINE(AARCH64_ASIMD, asimd, , , ) \ 28 | LINE(AARCH64_EVTSTRM, evtstrm, , , ) \ 29 | LINE(AARCH64_AES, aes, , , ) \ 30 | LINE(AARCH64_PMULL, pmull, , , ) \ 31 | LINE(AARCH64_SHA1, sha1, , , ) \ 32 | LINE(AARCH64_SHA2, sha2, , , ) \ 33 | LINE(AARCH64_CRC32, crc32, , , ) \ 34 | LINE(AARCH64_ATOMICS, atomics, , , ) \ 35 | LINE(AARCH64_FPHP, fphp, , , ) \ 36 | LINE(AARCH64_ASIMDHP, asimdhp, , , ) \ 37 | LINE(AARCH64_CPUID, cpuid, , , ) \ 38 | LINE(AARCH64_ASIMDRDM, asimdrdm, , , ) \ 39 | LINE(AARCH64_JSCVT, jscvt, , , ) \ 40 | LINE(AARCH64_FCMA, fcma, , , ) \ 41 | LINE(AARCH64_LRCPC, lrcpc, , , ) \ 42 | LINE(AARCH64_DCPOP, dcpop, , , ) \ 43 | LINE(AARCH64_SHA3, sha3, , , ) \ 44 | LINE(AARCH64_SM3, sm3, , , ) \ 45 | LINE(AARCH64_SM4, sm4, , , ) \ 46 | LINE(AARCH64_ASIMDDP, asimddp, , , ) \ 47 | LINE(AARCH64_SHA512, sha512, , , ) \ 48 | LINE(AARCH64_SVE, sve, , , ) \ 49 | LINE(AARCH64_ASIMDFHM, asimdfhm, , , ) \ 50 | LINE(AARCH64_DIT, dit, , , ) \ 51 | LINE(AARCH64_USCAT, uscat, , , ) \ 52 | LINE(AARCH64_ILRCPC, ilrcpc, , , ) \ 53 | LINE(AARCH64_FLAGM, flagm, , , ) \ 54 | LINE(AARCH64_SSBS, ssbs, , , ) \ 55 | LINE(AARCH64_SB, sb, , , ) \ 56 | LINE(AARCH64_PACA, paca, , , ) \ 57 | LINE(AARCH64_PACG, pacg, , , ) \ 58 | LINE(AARCH64_DCPODP, dcpodp, , , ) \ 59 | LINE(AARCH64_SVE2, sve2, , , ) \ 60 | LINE(AARCH64_SVEAES, sveaes, , , ) \ 61 | LINE(AARCH64_SVEPMULL, svepmull, , , ) \ 62 | LINE(AARCH64_SVEBITPERM, svebitperm, , , ) \ 63 | LINE(AARCH64_SVESHA3, svesha3, , , ) \ 64 | LINE(AARCH64_SVESM4, svesm4, , , ) \ 65 | LINE(AARCH64_FLAGM2, flagm2, , , ) \ 66 | LINE(AARCH64_FRINT, frint, , , ) \ 67 | LINE(AARCH64_SVEI8MM, svei8mm, , , ) \ 68 | LINE(AARCH64_SVEF32MM, svef32mm, , , ) \ 69 | LINE(AARCH64_SVEF64MM, svef64mm, , , ) \ 70 | LINE(AARCH64_SVEBF16, svebf16, , , ) \ 71 | LINE(AARCH64_I8MM, i8mm, , , ) \ 72 | LINE(AARCH64_BF16, bf16, , , ) \ 73 | LINE(AARCH64_DGH, dgh, , , ) \ 74 | LINE(AARCH64_RNG, rng, , , ) \ 75 | LINE(AARCH64_BTI, bti, , , ) \ 76 | LINE(AARCH64_MTE, mte, , , ) \ 77 | LINE(AARCH64_ECV, ecv, , , ) \ 78 | LINE(AARCH64_AFP, afp, , , ) \ 79 | LINE(AARCH64_RPRES, rpres, , , ) 80 | #define INTROSPECTION_PREFIX Aarch64 81 | #define INTROSPECTION_ENUM_PREFIX AARCH64 82 | #include "define_introspection.inl" 83 | 84 | //////////////////////////////////////////////////////////////////////////////// 85 | // Implementation. 86 | //////////////////////////////////////////////////////////////////////////////// 87 | 88 | #include 89 | 90 | #include "internal/windows_utils.h" 91 | 92 | #ifdef CPU_FEATURES_MOCK_CPUID_AARCH64 93 | extern bool GetWindowsIsProcessorFeaturePresent(DWORD); 94 | extern WORD GetWindowsNativeSystemInfoProcessorRevision(); 95 | #else // CPU_FEATURES_MOCK_CPUID_AARCH64 96 | static bool GetWindowsIsProcessorFeaturePresent(DWORD dwProcessorFeature) { 97 | return IsProcessorFeaturePresent(dwProcessorFeature); 98 | } 99 | 100 | static WORD GetWindowsNativeSystemInfoProcessorRevision() { 101 | SYSTEM_INFO system_info; 102 | GetNativeSystemInfo(&system_info); 103 | return system_info.wProcessorRevision; 104 | } 105 | #endif 106 | 107 | static const Aarch64Info kEmptyAarch64Info; 108 | 109 | Aarch64Info GetAarch64Info(void) { 110 | Aarch64Info info = kEmptyAarch64Info; 111 | info.revision = GetWindowsNativeSystemInfoProcessorRevision(); 112 | info.features.fp = 113 | GetWindowsIsProcessorFeaturePresent(PF_ARM_VFP_32_REGISTERS_AVAILABLE); 114 | info.features.asimd = 115 | GetWindowsIsProcessorFeaturePresent(PF_ARM_NEON_INSTRUCTIONS_AVAILABLE); 116 | info.features.crc32 = GetWindowsIsProcessorFeaturePresent( 117 | PF_ARM_V8_CRC32_INSTRUCTIONS_AVAILABLE); 118 | info.features.asimddp = 119 | GetWindowsIsProcessorFeaturePresent(PF_ARM_V82_DP_INSTRUCTIONS_AVAILABLE); 120 | info.features.jscvt = GetWindowsIsProcessorFeaturePresent( 121 | PF_ARM_V83_JSCVT_INSTRUCTIONS_AVAILABLE); 122 | info.features.lrcpc = GetWindowsIsProcessorFeaturePresent( 123 | PF_ARM_V83_LRCPC_INSTRUCTIONS_AVAILABLE); 124 | info.features.atomics = GetWindowsIsProcessorFeaturePresent( 125 | PF_ARM_V81_ATOMIC_INSTRUCTIONS_AVAILABLE); 126 | 127 | 128 | bool is_crypto_available = GetWindowsIsProcessorFeaturePresent( 129 | PF_ARM_V8_CRYPTO_INSTRUCTIONS_AVAILABLE); 130 | info.features.aes = is_crypto_available; 131 | info.features.sha1 = is_crypto_available; 132 | info.features.sha2 = is_crypto_available; 133 | info.features.pmull = is_crypto_available; 134 | return info; 135 | } 136 | 137 | #endif // CPU_FEATURES_OS_WINDOWS 138 | #endif // CPU_FEATURES_ARCH_AARCH64 139 | -------------------------------------------------------------------------------- /deps/cpu_features/src/impl_mips_linux_or_android.c: -------------------------------------------------------------------------------- 1 | // Licensed under the Apache License, Version 2.0 (the "License"); 2 | // you may not use this file except in compliance with the License. 3 | // You may obtain a copy of the License at 4 | // 5 | // http://www.apache.org/licenses/LICENSE-2.0 6 | // 7 | // Unless required by applicable law or agreed to in writing, software 8 | // distributed under the License is distributed on an "AS IS" BASIS, 9 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | // See the License for the specific language governing permissions and 11 | // limitations under the License. 12 | 13 | #include "cpu_features_macros.h" 14 | 15 | #ifdef CPU_FEATURES_ARCH_MIPS 16 | #if defined(CPU_FEATURES_OS_LINUX) || defined(CPU_FEATURES_OS_ANDROID) 17 | 18 | #include "cpuinfo_mips.h" 19 | 20 | //////////////////////////////////////////////////////////////////////////////// 21 | // Definitions for introspection. 22 | //////////////////////////////////////////////////////////////////////////////// 23 | #define INTROSPECTION_TABLE \ 24 | LINE(MIPS_MSA, msa, "msa", MIPS_HWCAP_MSA, 0) \ 25 | LINE(MIPS_EVA, eva, "eva", 0, 0) \ 26 | LINE(MIPS_R6, r6, "r6", MIPS_HWCAP_R6, 0) \ 27 | LINE(MIPS_MIPS16, mips16, "mips16", MIPS_HWCAP_MIPS16, 0) \ 28 | LINE(MIPS_MDMX, mdmx, "mdmx", MIPS_HWCAP_MDMX, 0) \ 29 | LINE(MIPS_MIPS3D, mips3d, "mips3d", MIPS_HWCAP_MIPS3D, 0) \ 30 | LINE(MIPS_SMART, smart, "smartmips", MIPS_HWCAP_SMARTMIPS, 0) \ 31 | LINE(MIPS_DSP, dsp, "dsp", MIPS_HWCAP_DSP, 0) 32 | #define INTROSPECTION_PREFIX Mips 33 | #define INTROSPECTION_ENUM_PREFIX MIPS 34 | #include "define_introspection_and_hwcaps.inl" 35 | 36 | //////////////////////////////////////////////////////////////////////////////// 37 | // Implementation. 38 | //////////////////////////////////////////////////////////////////////////////// 39 | 40 | #include "internal/filesystem.h" 41 | #include "internal/hwcaps.h" 42 | #include "internal/stack_line_reader.h" 43 | #include "internal/string_view.h" 44 | 45 | static bool HandleMipsLine(const LineResult result, 46 | MipsFeatures* const features) { 47 | StringView key, value; 48 | // See tests for an example. 49 | if (CpuFeatures_StringView_GetAttributeKeyValue(result.line, &key, &value)) { 50 | if (CpuFeatures_StringView_IsEquals(key, str("ASEs implemented"))) { 51 | for (size_t i = 0; i < MIPS_LAST_; ++i) { 52 | kSetters[i](features, CpuFeatures_StringView_HasWord( 53 | value, kCpuInfoFlags[i], ' ')); 54 | } 55 | } 56 | } 57 | return !result.eof; 58 | } 59 | 60 | static void FillProcCpuInfoData(MipsFeatures* const features) { 61 | const int fd = CpuFeatures_OpenFile("/proc/cpuinfo"); 62 | if (fd >= 0) { 63 | StackLineReader reader; 64 | StackLineReader_Initialize(&reader, fd); 65 | for (;;) { 66 | if (!HandleMipsLine(StackLineReader_NextLine(&reader), features)) { 67 | break; 68 | } 69 | } 70 | CpuFeatures_CloseFile(fd); 71 | } 72 | } 73 | 74 | static const MipsInfo kEmptyMipsInfo; 75 | 76 | MipsInfo GetMipsInfo(void) { 77 | // capabilities are fetched from both getauxval and /proc/cpuinfo so we can 78 | // have some information if the executable is sandboxed (aka no access to 79 | // /proc/cpuinfo). 80 | MipsInfo info = kEmptyMipsInfo; 81 | 82 | FillProcCpuInfoData(&info.features); 83 | const HardwareCapabilities hwcaps = CpuFeatures_GetHardwareCapabilities(); 84 | for (size_t i = 0; i < MIPS_LAST_; ++i) { 85 | if (CpuFeatures_IsHwCapsSet(kHardwareCapabilities[i], hwcaps)) { 86 | kSetters[i](&info.features, true); 87 | } 88 | } 89 | return info; 90 | } 91 | 92 | #endif // defined(CPU_FEATURES_OS_LINUX) || defined(CPU_FEATURES_OS_ANDROID) 93 | #endif // CPU_FEATURES_ARCH_MIPS 94 | -------------------------------------------------------------------------------- /deps/cpu_features/src/impl_ppc_linux.c: -------------------------------------------------------------------------------- 1 | // Copyright 2018 IBM. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "cpu_features_macros.h" 16 | 17 | #ifdef CPU_FEATURES_ARCH_PPC 18 | #ifdef CPU_FEATURES_OS_LINUX 19 | 20 | #include "cpuinfo_ppc.h" 21 | 22 | //////////////////////////////////////////////////////////////////////////////// 23 | // Definitions for introspection. 24 | //////////////////////////////////////////////////////////////////////////////// 25 | #define INTROSPECTION_TABLE \ 26 | LINE(PPC_32, ppc32, "ppc32", PPC_FEATURE_32, 0) \ 27 | LINE(PPC_64, ppc64, "ppc64", PPC_FEATURE_64, 0) \ 28 | LINE(PPC_601_INSTR, ppc601, "ppc601", PPC_FEATURE_601_INSTR, 0) \ 29 | LINE(PPC_HAS_ALTIVEC, altivec, "altivec", PPC_FEATURE_HAS_ALTIVEC, 0) \ 30 | LINE(PPC_HAS_FPU, fpu, "fpu", PPC_FEATURE_HAS_FPU, 0) \ 31 | LINE(PPC_HAS_MMU, mmu, "mmu", PPC_FEATURE_HAS_MMU, 0) \ 32 | LINE(PPC_HAS_4xxMAC, mac_4xx, "4xxmac", PPC_FEATURE_HAS_4xxMAC, 0) \ 33 | LINE(PPC_UNIFIED_CACHE, unifiedcache, "ucache", PPC_FEATURE_UNIFIED_CACHE, \ 34 | 0) \ 35 | LINE(PPC_HAS_SPE, spe, "spe", PPC_FEATURE_HAS_SPE, 0) \ 36 | LINE(PPC_HAS_EFP_SINGLE, efpsingle, "efpsingle", PPC_FEATURE_HAS_EFP_SINGLE, \ 37 | 0) \ 38 | LINE(PPC_HAS_EFP_DOUBLE, efpdouble, "efpdouble", PPC_FEATURE_HAS_EFP_DOUBLE, \ 39 | 0) \ 40 | LINE(PPC_NO_TB, no_tb, "notb", PPC_FEATURE_NO_TB, 0) \ 41 | LINE(PPC_POWER4, power4, "power4", PPC_FEATURE_POWER4, 0) \ 42 | LINE(PPC_POWER5, power5, "power5", PPC_FEATURE_POWER5, 0) \ 43 | LINE(PPC_POWER5_PLUS, power5plus, "power5+", PPC_FEATURE_POWER5_PLUS, 0) \ 44 | LINE(PPC_CELL, cell, "cellbe", PPC_FEATURE_CELL, 0) \ 45 | LINE(PPC_BOOKE, booke, "booke", PPC_FEATURE_BOOKE, 0) \ 46 | LINE(PPC_SMT, smt, "smt", PPC_FEATURE_SMT, 0) \ 47 | LINE(PPC_ICACHE_SNOOP, icachesnoop, "ic_snoop", PPC_FEATURE_ICACHE_SNOOP, 0) \ 48 | LINE(PPC_ARCH_2_05, arch205, "arch_2_05", PPC_FEATURE_ARCH_2_05, 0) \ 49 | LINE(PPC_PA6T, pa6t, "pa6t", PPC_FEATURE_PA6T, 0) \ 50 | LINE(PPC_HAS_DFP, dfp, "dfp", PPC_FEATURE_HAS_DFP, 0) \ 51 | LINE(PPC_POWER6_EXT, power6ext, "power6x", PPC_FEATURE_POWER6_EXT, 0) \ 52 | LINE(PPC_ARCH_2_06, arch206, "arch_2_06", PPC_FEATURE_ARCH_2_06, 0) \ 53 | LINE(PPC_HAS_VSX, vsx, "vsx", PPC_FEATURE_HAS_VSX, 0) \ 54 | LINE(PPC_PSERIES_PERFMON_COMPAT, pseries_perfmon_compat, "archpmu", \ 55 | PPC_FEATURE_PSERIES_PERFMON_COMPAT, 0) \ 56 | LINE(PPC_TRUE_LE, truele, "true_le", PPC_FEATURE_TRUE_LE, 0) \ 57 | LINE(PPC_PPC_LE, ppcle, "ppcle", PPC_FEATURE_PPC_LE, 0) \ 58 | LINE(PPC_ARCH_2_07, arch207, "arch_2_07", 0, PPC_FEATURE2_ARCH_2_07) \ 59 | LINE(PPC_HTM, htm, "htm", 0, PPC_FEATURE2_HTM) \ 60 | LINE(PPC_DSCR, dscr, "dscr", 0, PPC_FEATURE2_DSCR) \ 61 | LINE(PPC_EBB, ebb, "ebb", 0, PPC_FEATURE2_EBB) \ 62 | LINE(PPC_ISEL, isel, "isel", 0, PPC_FEATURE2_ISEL) \ 63 | LINE(PPC_TAR, tar, "tar", 0, PPC_FEATURE2_TAR) \ 64 | LINE(PPC_VEC_CRYPTO, vcrypto, "vcrypto", 0, PPC_FEATURE2_VEC_CRYPTO) \ 65 | LINE(PPC_HTM_NOSC, htm_nosc, "htm-nosc", 0, PPC_FEATURE2_HTM_NOSC) \ 66 | LINE(PPC_ARCH_3_00, arch300, "arch_3_00", 0, PPC_FEATURE2_ARCH_3_00) \ 67 | LINE(PPC_HAS_IEEE128, ieee128, "ieee128", 0, PPC_FEATURE2_HAS_IEEE128) \ 68 | LINE(PPC_DARN, darn, "darn", 0, PPC_FEATURE2_DARN) \ 69 | LINE(PPC_SCV, scv, "scv", 0, PPC_FEATURE2_SCV) \ 70 | LINE(PPC_HTM_NO_SUSPEND, htm_no_suspend, "htm-no-suspend", 0, \ 71 | PPC_FEATURE2_HTM_NO_SUSPEND) 72 | #undef PPC // Remove conflict with compiler generated preprocessor 73 | #define INTROSPECTION_PREFIX PPC 74 | #define INTROSPECTION_ENUM_PREFIX PPC 75 | #include "define_introspection_and_hwcaps.inl" 76 | 77 | //////////////////////////////////////////////////////////////////////////////// 78 | // Implementation. 79 | //////////////////////////////////////////////////////////////////////////////// 80 | 81 | #include 82 | 83 | #include "internal/bit_utils.h" 84 | #include "internal/filesystem.h" 85 | #include "internal/hwcaps.h" 86 | #include "internal/stack_line_reader.h" 87 | #include "internal/string_view.h" 88 | 89 | static bool HandlePPCLine(const LineResult result, 90 | PPCPlatformStrings* const strings) { 91 | StringView line = result.line; 92 | StringView key, value; 93 | if (CpuFeatures_StringView_GetAttributeKeyValue(line, &key, &value)) { 94 | if (CpuFeatures_StringView_HasWord(key, "platform", ' ')) { 95 | CpuFeatures_StringView_CopyString(value, strings->platform, 96 | sizeof(strings->platform)); 97 | } else if (CpuFeatures_StringView_IsEquals(key, str("model"))) { 98 | CpuFeatures_StringView_CopyString(value, strings->model, 99 | sizeof(strings->platform)); 100 | } else if (CpuFeatures_StringView_IsEquals(key, str("machine"))) { 101 | CpuFeatures_StringView_CopyString(value, strings->machine, 102 | sizeof(strings->platform)); 103 | } else if (CpuFeatures_StringView_IsEquals(key, str("cpu"))) { 104 | CpuFeatures_StringView_CopyString(value, strings->cpu, 105 | sizeof(strings->platform)); 106 | } 107 | } 108 | return !result.eof; 109 | } 110 | 111 | static void FillProcCpuInfoData(PPCPlatformStrings* const strings) { 112 | const int fd = CpuFeatures_OpenFile("/proc/cpuinfo"); 113 | if (fd >= 0) { 114 | StackLineReader reader; 115 | StackLineReader_Initialize(&reader, fd); 116 | for (;;) { 117 | if (!HandlePPCLine(StackLineReader_NextLine(&reader), strings)) { 118 | break; 119 | } 120 | } 121 | CpuFeatures_CloseFile(fd); 122 | } 123 | } 124 | 125 | static const PPCInfo kEmptyPPCInfo; 126 | 127 | PPCInfo GetPPCInfo(void) { 128 | /* 129 | * On Power feature flags aren't currently in cpuinfo so we only look at 130 | * the auxilary vector. 131 | */ 132 | PPCInfo info = kEmptyPPCInfo; 133 | const HardwareCapabilities hwcaps = CpuFeatures_GetHardwareCapabilities(); 134 | for (size_t i = 0; i < PPC_LAST_; ++i) { 135 | if (CpuFeatures_IsHwCapsSet(kHardwareCapabilities[i], hwcaps)) { 136 | kSetters[i](&info.features, true); 137 | } 138 | } 139 | return info; 140 | } 141 | 142 | static const PPCPlatformStrings kEmptyPPCPlatformStrings; 143 | 144 | PPCPlatformStrings GetPPCPlatformStrings(void) { 145 | PPCPlatformStrings strings = kEmptyPPCPlatformStrings; 146 | const char* platform = CpuFeatures_GetPlatformPointer(); 147 | const char* base_platform = CpuFeatures_GetBasePlatformPointer(); 148 | 149 | FillProcCpuInfoData(&strings); 150 | 151 | if (platform != NULL) 152 | CpuFeatures_StringView_CopyString(str(platform), strings.type.platform, 153 | sizeof(strings.type.platform)); 154 | if (base_platform != NULL) 155 | CpuFeatures_StringView_CopyString(str(base_platform), 156 | strings.type.base_platform, 157 | sizeof(strings.type.base_platform)); 158 | 159 | return strings; 160 | } 161 | 162 | #endif // CPU_FEATURES_OS_LINUX 163 | #endif // CPU_FEATURES_ARCH_PPC 164 | -------------------------------------------------------------------------------- /deps/cpu_features/src/impl_riscv_linux.c: -------------------------------------------------------------------------------- 1 | // Copyright 2022 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "cpu_features_macros.h" 16 | 17 | #ifdef CPU_FEATURES_ARCH_RISCV 18 | #if defined(CPU_FEATURES_OS_LINUX) 19 | 20 | #include "cpuinfo_riscv.h" 21 | 22 | // According to 23 | // https://elixir.bootlin.com/linux/latest/source/Documentation/devicetree/bindings/riscv/cpus.yaml 24 | // isa string should match the following regex 25 | // ^rv(?:64|32)imaf?d?q?c?b?v?k?h?(?:_[hsxz](?:[a-z])+)*$ 26 | // 27 | // This means we can test for features in this exact order except for Z 28 | // extensions. 29 | 30 | //////////////////////////////////////////////////////////////////////////////// 31 | // Definitions for introspection. 32 | //////////////////////////////////////////////////////////////////////////////// 33 | #define INTROSPECTION_TABLE \ 34 | LINE(RISCV_RV32I, RV32I, "rv32i", RISCV_HWCAP_32, 0) \ 35 | LINE(RISCV_RV64I, RV64I, "rv64i", RISCV_HWCAP_64, 0) \ 36 | LINE(RISCV_M, M, "m", RISCV_HWCAP_M, 0) \ 37 | LINE(RISCV_A, A, "a", RISCV_HWCAP_A, 0) \ 38 | LINE(RISCV_F, F, "f", RISCV_HWCAP_F, 0) \ 39 | LINE(RISCV_D, D, "d", RISCV_HWCAP_D, 0) \ 40 | LINE(RISCV_Q, Q, "q", RISCV_HWCAP_Q, 0) \ 41 | LINE(RISCV_C, C, "c", RISCV_HWCAP_C, 0) \ 42 | LINE(RISCV_V, V, "v", RISCV_HWCAP_V, 0) \ 43 | LINE(RISCV_Zicsr, Zicsr, "_zicsr", 0, 0) \ 44 | LINE(RISCV_Zifencei, Zifencei, "_zifencei", 0, 0) 45 | #define INTROSPECTION_PREFIX Riscv 46 | #define INTROSPECTION_ENUM_PREFIX RISCV 47 | #include "define_introspection_and_hwcaps.inl" 48 | 49 | //////////////////////////////////////////////////////////////////////////////// 50 | // Implementation. 51 | //////////////////////////////////////////////////////////////////////////////// 52 | 53 | #include 54 | #include 55 | 56 | #include "internal/filesystem.h" 57 | #include "internal/stack_line_reader.h" 58 | 59 | static const RiscvInfo kEmptyRiscvInfo; 60 | 61 | static void HandleRiscVIsaLine(StringView line, RiscvFeatures* const features) { 62 | for (size_t i = 0; i < RISCV_LAST_; ++i) { 63 | StringView flag = str(kCpuInfoFlags[i]); 64 | int index_of_flag = CpuFeatures_StringView_IndexOf(line, flag); 65 | bool is_set = index_of_flag != -1; 66 | kSetters[i](features, is_set); 67 | if (is_set) 68 | line = CpuFeatures_StringView_PopFront(line, index_of_flag + flag.size); 69 | } 70 | } 71 | 72 | static bool HandleRiscVLine(const LineResult result, RiscvInfo* const info) { 73 | StringView line = result.line; 74 | StringView key, value; 75 | if (CpuFeatures_StringView_GetAttributeKeyValue(line, &key, &value)) { 76 | if (CpuFeatures_StringView_IsEquals(key, str("isa"))) { 77 | HandleRiscVIsaLine(value, &info->features); 78 | } else if (CpuFeatures_StringView_IsEquals(key, str("uarch"))) { 79 | int index = CpuFeatures_StringView_IndexOfChar(value, ','); 80 | if (index == -1) return true; 81 | StringView vendor = CpuFeatures_StringView_KeepFront(value, index); 82 | StringView uarch = CpuFeatures_StringView_PopFront(value, index + 1); 83 | CpuFeatures_StringView_CopyString(vendor, info->vendor, 84 | sizeof(info->vendor)); 85 | CpuFeatures_StringView_CopyString(uarch, info->uarch, 86 | sizeof(info->uarch)); 87 | } 88 | } 89 | return !result.eof; 90 | } 91 | 92 | static void FillProcCpuInfoData(RiscvInfo* const info) { 93 | const int fd = CpuFeatures_OpenFile("/proc/cpuinfo"); 94 | if (fd >= 0) { 95 | StackLineReader reader; 96 | StackLineReader_Initialize(&reader, fd); 97 | for (;;) { 98 | if (!HandleRiscVLine(StackLineReader_NextLine(&reader), info)) break; 99 | } 100 | CpuFeatures_CloseFile(fd); 101 | } 102 | } 103 | 104 | RiscvInfo GetRiscvInfo(void) { 105 | RiscvInfo info = kEmptyRiscvInfo; 106 | FillProcCpuInfoData(&info); 107 | return info; 108 | } 109 | 110 | #endif // defined(CPU_FEATURES_OS_LINUX) || defined(CPU_FEATURES_OS_ANDROID) 111 | #endif // CPU_FEATURES_ARCH_RISCV 112 | -------------------------------------------------------------------------------- /deps/cpu_features/src/impl_s390x_linux.c: -------------------------------------------------------------------------------- 1 | // Copyright 2022 IBM. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "cpu_features_macros.h" 16 | 17 | #ifdef CPU_FEATURES_ARCH_S390X 18 | #ifdef CPU_FEATURES_OS_LINUX 19 | 20 | #include "cpuinfo_s390x.h" 21 | 22 | //////////////////////////////////////////////////////////////////////////////// 23 | // Definitions for introspection. 24 | //////////////////////////////////////////////////////////////////////////////// 25 | #define INTROSPECTION_TABLE \ 26 | LINE(S390_ESAN3, esan3, "esan3", HWCAP_S390_ESAN3, 0) \ 27 | LINE(S390_ZARCH, zarch, "zarch", HWCAP_S390_ZARCH, 0) \ 28 | LINE(S390_STFLE, stfle, "stfle", HWCAP_S390_STFLE, 0) \ 29 | LINE(S390_MSA, msa, "msa", HWCAP_S390_MSA, 0) \ 30 | LINE(S390_LDISP, ldisp, "ldisp", HWCAP_S390_LDISP, 0) \ 31 | LINE(S390_EIMM, eimm, "eimm", HWCAP_S390_EIMM, 0) \ 32 | LINE(S390_DFP, dfp, "dfp", HWCAP_S390_DFP, 0) \ 33 | LINE(S390_EDAT, edat, "edat", HWCAP_S390_HPAGE, 0) \ 34 | LINE(S390_ETF3EH, etf3eh, "etf3eh", HWCAP_S390_ETF3EH, 0) \ 35 | LINE(S390_HIGHGPRS, highgprs, "highgprs", HWCAP_S390_HIGH_GPRS, 0) \ 36 | LINE(S390_TE, te, "te", HWCAP_S390_TE, 0) \ 37 | LINE(S390_VX, vx, "vx", HWCAP_S390_VXRS, 0) \ 38 | LINE(S390_VXD, vxd, "vxd", HWCAP_S390_VXRS_BCD, 0) \ 39 | LINE(S390_VXE, vxe, "vxe", HWCAP_S390_VXRS_EXT, 0) \ 40 | LINE(S390_GS, gs, "gs", HWCAP_S390_GS, 0) \ 41 | LINE(S390_VXE2, vxe2, "vxe2", HWCAP_S390_VXRS_EXT2, 0) \ 42 | LINE(S390_VXP, vxp, "vxp", HWCAP_S390_VXRS_PDE, 0) \ 43 | LINE(S390_SORT, sort, "sort", HWCAP_S390_SORT, 0) \ 44 | LINE(S390_DFLT, dflt, "dflt", HWCAP_S390_DFLT, 0) \ 45 | LINE(S390_VXP2, vxp2, "vxp2", HWCAP_S390_VXRS_PDE2, 0) \ 46 | LINE(S390_NNPA, nnpa, "nnpa", HWCAP_S390_NNPA, 0) \ 47 | LINE(S390_PCIMIO, pcimio, "pcimio", HWCAP_S390_PCI_MIO, 0) \ 48 | LINE(S390_SIE, sie, "sie", HWCAP_S390_SIE, 0) 49 | #define INTROSPECTION_PREFIX S390X 50 | #define INTROSPECTION_ENUM_PREFIX S390X 51 | #include "define_introspection_and_hwcaps.inl" 52 | 53 | //////////////////////////////////////////////////////////////////////////////// 54 | // Implementation. 55 | //////////////////////////////////////////////////////////////////////////////// 56 | 57 | #include 58 | 59 | #include "internal/bit_utils.h" 60 | #include "internal/filesystem.h" 61 | #include "internal/hwcaps.h" 62 | #include "internal/stack_line_reader.h" 63 | #include "internal/string_view.h" 64 | 65 | static bool HandleS390XLine(const LineResult result, 66 | S390XPlatformStrings* const strings) { 67 | StringView line = result.line; 68 | StringView key, value; 69 | if (CpuFeatures_StringView_GetAttributeKeyValue(line, &key, &value)) { 70 | if (CpuFeatures_StringView_IsEquals(key, str("# processors"))) { 71 | strings->num_processors = CpuFeatures_StringView_ParsePositiveNumber(value); 72 | } 73 | } 74 | return !result.eof; 75 | } 76 | 77 | static void FillProcCpuInfoData(S390XPlatformStrings* const strings) { 78 | const int fd = CpuFeatures_OpenFile("/proc/cpuinfo"); 79 | if (fd >= 0) { 80 | StackLineReader reader; 81 | StackLineReader_Initialize(&reader, fd); 82 | for (;;) { 83 | if (!HandleS390XLine(StackLineReader_NextLine(&reader), strings)) { 84 | break; 85 | } 86 | } 87 | CpuFeatures_CloseFile(fd); 88 | } 89 | } 90 | 91 | static const S390XInfo kEmptyS390XInfo; 92 | 93 | S390XInfo GetS390XInfo(void) { 94 | S390XInfo info = kEmptyS390XInfo; 95 | const HardwareCapabilities hwcaps = CpuFeatures_GetHardwareCapabilities(); 96 | for (size_t i = 0; i < S390X_LAST_; ++i) { 97 | if (CpuFeatures_IsHwCapsSet(kHardwareCapabilities[i], hwcaps)) { 98 | kSetters[i](&info.features, true); 99 | } 100 | } 101 | return info; 102 | } 103 | 104 | static const S390XPlatformStrings kEmptyS390XPlatformStrings; 105 | 106 | S390XPlatformStrings GetS390XPlatformStrings(void) { 107 | S390XPlatformStrings strings = kEmptyS390XPlatformStrings; 108 | const char* platform = CpuFeatures_GetPlatformPointer(); 109 | 110 | FillProcCpuInfoData(&strings); 111 | 112 | if (platform != NULL) 113 | CpuFeatures_StringView_CopyString(str(platform), strings.type.platform, 114 | sizeof(strings.type.platform)); 115 | 116 | return strings; 117 | } 118 | 119 | #endif // CPU_FEATURES_OS_LINUX 120 | #endif // CPU_FEATURES_ARCH_S390X 121 | -------------------------------------------------------------------------------- /deps/cpu_features/src/impl_x86_freebsd.c: -------------------------------------------------------------------------------- 1 | // Copyright 2017 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "cpu_features_macros.h" 16 | 17 | #ifdef CPU_FEATURES_ARCH_X86 18 | #ifdef CPU_FEATURES_OS_FREEBSD 19 | 20 | #include "impl_x86__base_implementation.inl" 21 | 22 | static void OverrideOsPreserves(OsPreserves* os_preserves) { 23 | (void)os_preserves; 24 | // No override 25 | } 26 | 27 | #include "internal/filesystem.h" 28 | #include "internal/stack_line_reader.h" 29 | #include "internal/string_view.h" 30 | 31 | static void DetectFeaturesFromOs(X86Info* info, X86Features* features) { 32 | (void)info; 33 | // Handling FreeBSD platform through parsing /var/run/dmesg.boot. 34 | const int fd = CpuFeatures_OpenFile("/var/run/dmesg.boot"); 35 | if (fd >= 0) { 36 | StackLineReader reader; 37 | StackLineReader_Initialize(&reader, fd); 38 | for (bool stop = false; !stop;) { 39 | const LineResult result = StackLineReader_NextLine(&reader); 40 | if (result.eof) stop = true; 41 | const StringView line = result.line; 42 | if (!CpuFeatures_StringView_StartsWith(line, str(" Features"))) continue; 43 | // Lines of interests are of the following form: 44 | // " Features=0x1783fbff" 45 | // We first extract the comma separated values between angle brackets. 46 | StringView csv = result.line; 47 | int index = CpuFeatures_StringView_IndexOfChar(csv, '<'); 48 | if (index >= 0) csv = CpuFeatures_StringView_PopFront(csv, index + 1); 49 | if (csv.size > 0 && CpuFeatures_StringView_Back(csv) == '>') 50 | csv = CpuFeatures_StringView_PopBack(csv, 1); 51 | if (CpuFeatures_StringView_HasWord(csv, "SSE", ',')) features->sse = true; 52 | if (CpuFeatures_StringView_HasWord(csv, "SSE2", ',')) 53 | features->sse2 = true; 54 | if (CpuFeatures_StringView_HasWord(csv, "SSE3", ',')) 55 | features->sse3 = true; 56 | if (CpuFeatures_StringView_HasWord(csv, "SSSE3", ',')) 57 | features->ssse3 = true; 58 | if (CpuFeatures_StringView_HasWord(csv, "SSE4.1", ',')) 59 | features->sse4_1 = true; 60 | if (CpuFeatures_StringView_HasWord(csv, "SSE4.2", ',')) 61 | features->sse4_2 = true; 62 | } 63 | CpuFeatures_CloseFile(fd); 64 | } 65 | } 66 | 67 | #endif // CPU_FEATURES_OS_FREEBSD 68 | #endif // CPU_FEATURES_ARCH_X86 69 | -------------------------------------------------------------------------------- /deps/cpu_features/src/impl_x86_linux_or_android.c: -------------------------------------------------------------------------------- 1 | // Copyright 2017 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "cpu_features_macros.h" 16 | 17 | #ifdef CPU_FEATURES_ARCH_X86 18 | #if defined(CPU_FEATURES_OS_LINUX) || defined(CPU_FEATURES_OS_ANDROID) 19 | 20 | #include "impl_x86__base_implementation.inl" 21 | 22 | static void OverrideOsPreserves(OsPreserves* os_preserves) { 23 | (void)os_preserves; 24 | // No override 25 | } 26 | 27 | #include "internal/filesystem.h" 28 | #include "internal/stack_line_reader.h" 29 | #include "internal/string_view.h" 30 | static void DetectFeaturesFromOs(X86Info* info, X86Features* features) { 31 | (void)info; 32 | // Handling Linux platform through /proc/cpuinfo. 33 | const int fd = CpuFeatures_OpenFile("/proc/cpuinfo"); 34 | if (fd >= 0) { 35 | StackLineReader reader; 36 | StackLineReader_Initialize(&reader, fd); 37 | for (bool stop = false; !stop;) { 38 | const LineResult result = StackLineReader_NextLine(&reader); 39 | if (result.eof) stop = true; 40 | const StringView line = result.line; 41 | StringView key, value; 42 | if (!CpuFeatures_StringView_GetAttributeKeyValue(line, &key, &value)) 43 | continue; 44 | if (!CpuFeatures_StringView_IsEquals(key, str("flags"))) continue; 45 | features->sse = CpuFeatures_StringView_HasWord(value, "sse", ' '); 46 | features->sse2 = CpuFeatures_StringView_HasWord(value, "sse2", ' '); 47 | features->sse3 = CpuFeatures_StringView_HasWord(value, "pni", ' '); 48 | features->ssse3 = CpuFeatures_StringView_HasWord(value, "ssse3", ' '); 49 | features->sse4_1 = CpuFeatures_StringView_HasWord(value, "sse4_1", ' '); 50 | features->sse4_2 = CpuFeatures_StringView_HasWord(value, "sse4_2", ' '); 51 | break; 52 | } 53 | CpuFeatures_CloseFile(fd); 54 | } 55 | } 56 | 57 | #endif // defined(CPU_FEATURES_OS_LINUX) || defined(CPU_FEATURES_OS_ANDROID) 58 | #endif // CPU_FEATURES_ARCH_X86 59 | -------------------------------------------------------------------------------- /deps/cpu_features/src/impl_x86_macos.c: -------------------------------------------------------------------------------- 1 | // Copyright 2017 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "cpu_features_macros.h" 16 | 17 | #ifdef CPU_FEATURES_ARCH_X86 18 | #ifdef CPU_FEATURES_OS_MACOS 19 | 20 | #include "impl_x86__base_implementation.inl" 21 | 22 | #if !defined(HAVE_SYSCTLBYNAME) 23 | #error "Darwin needs support for sysctlbyname" 24 | #endif 25 | #include 26 | 27 | #if defined(CPU_FEATURES_MOCK_CPUID_X86) 28 | extern bool GetDarwinSysCtlByName(const char*); 29 | #else // CPU_FEATURES_MOCK_CPUID_X86 30 | static bool GetDarwinSysCtlByName(const char* name) { 31 | int enabled; 32 | size_t enabled_len = sizeof(enabled); 33 | const int failure = sysctlbyname(name, &enabled, &enabled_len, NULL, 0); 34 | return failure ? false : enabled; 35 | } 36 | #endif 37 | 38 | static void OverrideOsPreserves(OsPreserves* os_preserves) { 39 | // On Darwin AVX512 support is On-demand. 40 | // We have to query the OS instead of querying the Zmm save/restore state. 41 | // https://github.com/apple/darwin-xnu/blob/8f02f2a044b9bb1ad951987ef5bab20ec9486310/osfmk/i386/fpu.c#L173-L199 42 | os_preserves->avx512_registers = GetDarwinSysCtlByName("hw.optional.avx512f"); 43 | } 44 | 45 | static void DetectFeaturesFromOs(X86Info* info, X86Features* features) { 46 | (void)info; 47 | // Handling Darwin platform through sysctlbyname. 48 | features->sse = GetDarwinSysCtlByName("hw.optional.sse"); 49 | features->sse2 = GetDarwinSysCtlByName("hw.optional.sse2"); 50 | features->sse3 = GetDarwinSysCtlByName("hw.optional.sse3"); 51 | features->ssse3 = GetDarwinSysCtlByName("hw.optional.supplementalsse3"); 52 | features->sse4_1 = GetDarwinSysCtlByName("hw.optional.sse4_1"); 53 | features->sse4_2 = GetDarwinSysCtlByName("hw.optional.sse4_2"); 54 | } 55 | 56 | #endif // CPU_FEATURES_OS_MACOS 57 | #endif // CPU_FEATURES_ARCH_X86 58 | -------------------------------------------------------------------------------- /deps/cpu_features/src/impl_x86_windows.c: -------------------------------------------------------------------------------- 1 | // Copyright 2017 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "cpu_features_macros.h" 16 | 17 | #ifdef CPU_FEATURES_ARCH_X86 18 | #ifdef CPU_FEATURES_OS_WINDOWS 19 | 20 | #include "impl_x86__base_implementation.inl" 21 | 22 | static void OverrideOsPreserves(OsPreserves* os_preserves) { 23 | (void)os_preserves; 24 | // No override 25 | } 26 | 27 | #include "internal/windows_utils.h" 28 | 29 | #if defined(CPU_FEATURES_MOCK_CPUID_X86) 30 | extern bool GetWindowsIsProcessorFeaturePresent(DWORD); 31 | #else // CPU_FEATURES_MOCK_CPUID_X86 32 | static bool GetWindowsIsProcessorFeaturePresent(DWORD ProcessorFeature) { 33 | return IsProcessorFeaturePresent(ProcessorFeature); 34 | } 35 | #endif 36 | 37 | static void DetectFeaturesFromOs(X86Info* info, X86Features* features) { 38 | // Handling Windows platform through IsProcessorFeaturePresent. 39 | // https://docs.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-isprocessorfeaturepresent 40 | features->sse = 41 | GetWindowsIsProcessorFeaturePresent(PF_XMMI_INSTRUCTIONS_AVAILABLE); 42 | features->sse2 = 43 | GetWindowsIsProcessorFeaturePresent(PF_XMMI64_INSTRUCTIONS_AVAILABLE); 44 | features->sse3 = 45 | GetWindowsIsProcessorFeaturePresent(PF_SSE3_INSTRUCTIONS_AVAILABLE); 46 | features->ssse3 = 47 | GetWindowsIsProcessorFeaturePresent(PF_SSSE3_INSTRUCTIONS_AVAILABLE); 48 | features->sse4_1 = 49 | GetWindowsIsProcessorFeaturePresent(PF_SSE4_1_INSTRUCTIONS_AVAILABLE); 50 | features->sse4_2 = 51 | GetWindowsIsProcessorFeaturePresent(PF_SSE4_2_INSTRUCTIONS_AVAILABLE); 52 | 53 | // do not bother checking PF_AVX* 54 | // cause AVX enabled processor will have XCR0 be exposed and this function will be skipped at all 55 | } 56 | 57 | #endif // CPU_FEATURES_OS_WINDOWS 58 | #endif // CPU_FEATURES_ARCH_X86 59 | -------------------------------------------------------------------------------- /deps/cpu_features/src/stack_line_reader.c: -------------------------------------------------------------------------------- 1 | // Copyright 2017 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "internal/stack_line_reader.h" 16 | 17 | #include 18 | #include 19 | #include 20 | 21 | #include "internal/filesystem.h" 22 | 23 | void StackLineReader_Initialize(StackLineReader* reader, int fd) { 24 | reader->view.ptr = reader->buffer; 25 | reader->view.size = 0; 26 | reader->skip_mode = false; 27 | reader->fd = fd; 28 | } 29 | 30 | // Replaces the content of buffer with bytes from the file. 31 | static int LoadFullBuffer(StackLineReader* reader) { 32 | const int read = CpuFeatures_ReadFile(reader->fd, reader->buffer, 33 | STACK_LINE_READER_BUFFER_SIZE); 34 | assert(read >= 0); 35 | reader->view.ptr = reader->buffer; 36 | reader->view.size = read; 37 | return read; 38 | } 39 | 40 | // Appends with bytes from the file to buffer, filling the remaining space. 41 | static int LoadMore(StackLineReader* reader) { 42 | char* const ptr = reader->buffer + reader->view.size; 43 | const size_t size_to_read = STACK_LINE_READER_BUFFER_SIZE - reader->view.size; 44 | const int read = CpuFeatures_ReadFile(reader->fd, ptr, size_to_read); 45 | assert(read >= 0); 46 | assert(read <= (int)size_to_read); 47 | reader->view.size += read; 48 | return read; 49 | } 50 | 51 | static int IndexOfEol(StackLineReader* reader) { 52 | return CpuFeatures_StringView_IndexOfChar(reader->view, '\n'); 53 | } 54 | 55 | // Relocate buffer's pending bytes at the beginning of the array and fills the 56 | // remaining space with bytes from the file. 57 | static int BringToFrontAndLoadMore(StackLineReader* reader) { 58 | if (reader->view.size && reader->view.ptr != reader->buffer) { 59 | memmove(reader->buffer, reader->view.ptr, reader->view.size); 60 | } 61 | reader->view.ptr = reader->buffer; 62 | return LoadMore(reader); 63 | } 64 | 65 | // Loads chunks of buffer size from disks until it contains a newline character 66 | // or end of file. 67 | static void SkipToNextLine(StackLineReader* reader) { 68 | for (;;) { 69 | const int read = LoadFullBuffer(reader); 70 | if (read == 0) { 71 | break; 72 | } else { 73 | const int eol_index = IndexOfEol(reader); 74 | if (eol_index >= 0) { 75 | reader->view = 76 | CpuFeatures_StringView_PopFront(reader->view, eol_index + 1); 77 | break; 78 | } 79 | } 80 | } 81 | } 82 | 83 | static LineResult CreateLineResult(bool eof, bool full_line, StringView view) { 84 | LineResult result; 85 | result.eof = eof; 86 | result.full_line = full_line; 87 | result.line = view; 88 | return result; 89 | } 90 | 91 | // Helper methods to provide clearer semantic in StackLineReader_NextLine. 92 | static LineResult CreateEOFLineResult(StringView view) { 93 | return CreateLineResult(true, true, view); 94 | } 95 | 96 | static LineResult CreateTruncatedLineResult(StringView view) { 97 | return CreateLineResult(false, false, view); 98 | } 99 | 100 | static LineResult CreateValidLineResult(StringView view) { 101 | return CreateLineResult(false, true, view); 102 | } 103 | 104 | LineResult StackLineReader_NextLine(StackLineReader* reader) { 105 | if (reader->skip_mode) { 106 | SkipToNextLine(reader); 107 | reader->skip_mode = false; 108 | } 109 | { 110 | const bool can_load_more = 111 | reader->view.size < STACK_LINE_READER_BUFFER_SIZE; 112 | int eol_index = IndexOfEol(reader); 113 | if (eol_index < 0 && can_load_more) { 114 | const int read = BringToFrontAndLoadMore(reader); 115 | if (read == 0) { 116 | return CreateEOFLineResult(reader->view); 117 | } 118 | eol_index = IndexOfEol(reader); 119 | } 120 | if (eol_index < 0) { 121 | reader->skip_mode = true; 122 | return CreateTruncatedLineResult(reader->view); 123 | } 124 | { 125 | StringView line = 126 | CpuFeatures_StringView_KeepFront(reader->view, eol_index); 127 | reader->view = 128 | CpuFeatures_StringView_PopFront(reader->view, eol_index + 1); 129 | return CreateValidLineResult(line); 130 | } 131 | } 132 | } 133 | -------------------------------------------------------------------------------- /deps/cpu_features/src/string_view.c: -------------------------------------------------------------------------------- 1 | // Copyright 2017 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "internal/string_view.h" 16 | 17 | #include 18 | #include 19 | 20 | #include "copy.inl" 21 | #include "equals.inl" 22 | 23 | static const char* CpuFeatures_memchr(const char* const ptr, const size_t size, 24 | const char c) { 25 | for (size_t i = 0; ptr && ptr[i] != '\0' && i < size; ++i) 26 | if (ptr[i] == c) return ptr + i; 27 | return NULL; 28 | } 29 | 30 | int CpuFeatures_StringView_IndexOfChar(const StringView view, char c) { 31 | if (view.ptr && view.size) { 32 | const char* const found = CpuFeatures_memchr(view.ptr, view.size, c); 33 | if (found) { 34 | return (int)(found - view.ptr); 35 | } 36 | } 37 | return -1; 38 | } 39 | 40 | int CpuFeatures_StringView_IndexOf(const StringView view, 41 | const StringView sub_view) { 42 | if (sub_view.size) { 43 | StringView remainder = view; 44 | while (remainder.size >= sub_view.size) { 45 | const int found_index = 46 | CpuFeatures_StringView_IndexOfChar(remainder, sub_view.ptr[0]); 47 | if (found_index < 0) break; 48 | remainder = CpuFeatures_StringView_PopFront(remainder, found_index); 49 | if (CpuFeatures_StringView_StartsWith(remainder, sub_view)) { 50 | return (int)(remainder.ptr - view.ptr); 51 | } 52 | remainder = CpuFeatures_StringView_PopFront(remainder, 1); 53 | } 54 | } 55 | return -1; 56 | } 57 | 58 | bool CpuFeatures_StringView_IsEquals(const StringView a, const StringView b) { 59 | if (a.size == b.size) { 60 | return a.ptr == b.ptr || equals(a.ptr, b.ptr, b.size); 61 | } 62 | return false; 63 | } 64 | 65 | bool CpuFeatures_StringView_StartsWith(const StringView a, const StringView b) { 66 | return a.ptr && b.ptr && b.size && a.size >= b.size 67 | ? equals(a.ptr, b.ptr, b.size) 68 | : false; 69 | } 70 | 71 | StringView CpuFeatures_StringView_PopFront(const StringView str_view, 72 | size_t count) { 73 | if (count > str_view.size) { 74 | return kEmptyStringView; 75 | } 76 | return view(str_view.ptr + count, str_view.size - count); 77 | } 78 | 79 | StringView CpuFeatures_StringView_PopBack(const StringView str_view, 80 | size_t count) { 81 | if (count > str_view.size) { 82 | return kEmptyStringView; 83 | } 84 | return view(str_view.ptr, str_view.size - count); 85 | } 86 | 87 | StringView CpuFeatures_StringView_KeepFront(const StringView str_view, 88 | size_t count) { 89 | return count <= str_view.size ? view(str_view.ptr, count) : str_view; 90 | } 91 | 92 | char CpuFeatures_StringView_Front(const StringView view) { 93 | assert(view.size); 94 | assert(view.ptr); 95 | return view.ptr[0]; 96 | } 97 | 98 | char CpuFeatures_StringView_Back(const StringView view) { 99 | assert(view.size); 100 | return view.ptr[view.size - 1]; 101 | } 102 | 103 | StringView CpuFeatures_StringView_TrimWhitespace(StringView view) { 104 | while (view.size && isspace(CpuFeatures_StringView_Front(view))) 105 | view = CpuFeatures_StringView_PopFront(view, 1); 106 | while (view.size && isspace(CpuFeatures_StringView_Back(view))) 107 | view = CpuFeatures_StringView_PopBack(view, 1); 108 | return view; 109 | } 110 | 111 | static int HexValue(const char c) { 112 | if (c >= '0' && c <= '9') return c - '0'; 113 | if (c >= 'a' && c <= 'f') return c - 'a' + 10; 114 | if (c >= 'A' && c <= 'F') return c - 'A' + 10; 115 | return -1; 116 | } 117 | 118 | // Returns -1 if view contains non digits. 119 | static int ParsePositiveNumberWithBase(const StringView view, int base) { 120 | int result = 0; 121 | StringView remainder = view; 122 | for (; remainder.size; 123 | remainder = CpuFeatures_StringView_PopFront(remainder, 1)) { 124 | const int value = HexValue(CpuFeatures_StringView_Front(remainder)); 125 | if (value < 0 || value >= base) return -1; 126 | result = (result * base) + value; 127 | } 128 | return result; 129 | } 130 | 131 | int CpuFeatures_StringView_ParsePositiveNumber(const StringView view) { 132 | if (view.size) { 133 | const StringView hex_prefix = str("0x"); 134 | if (CpuFeatures_StringView_StartsWith(view, hex_prefix)) { 135 | const StringView span_no_prefix = 136 | CpuFeatures_StringView_PopFront(view, hex_prefix.size); 137 | return ParsePositiveNumberWithBase(span_no_prefix, 16); 138 | } 139 | return ParsePositiveNumberWithBase(view, 10); 140 | } 141 | return -1; 142 | } 143 | 144 | void CpuFeatures_StringView_CopyString(const StringView src, char* dst, 145 | size_t dst_size) { 146 | if (dst_size > 0) { 147 | const size_t max_copy_size = dst_size - 1; 148 | const size_t copy_size = 149 | src.size > max_copy_size ? max_copy_size : src.size; 150 | copy(dst, src.ptr, copy_size); 151 | dst[copy_size] = '\0'; 152 | } 153 | } 154 | 155 | bool CpuFeatures_StringView_HasWord(const StringView line, 156 | const char* const word_str, 157 | const char separator) { 158 | const StringView word = str(word_str); 159 | StringView remainder = line; 160 | for (;;) { 161 | const int index_of_word = CpuFeatures_StringView_IndexOf(remainder, word); 162 | if (index_of_word < 0) { 163 | return false; 164 | } else { 165 | const StringView before = 166 | CpuFeatures_StringView_KeepFront(line, index_of_word); 167 | const StringView after = 168 | CpuFeatures_StringView_PopFront(line, index_of_word + word.size); 169 | const bool valid_before = 170 | before.size == 0 || CpuFeatures_StringView_Back(before) == separator; 171 | const bool valid_after = 172 | after.size == 0 || CpuFeatures_StringView_Front(after) == separator; 173 | if (valid_before && valid_after) return true; 174 | remainder = 175 | CpuFeatures_StringView_PopFront(remainder, index_of_word + word.size); 176 | } 177 | } 178 | return false; 179 | } 180 | 181 | bool CpuFeatures_StringView_GetAttributeKeyValue(const StringView line, 182 | StringView* key, 183 | StringView* value) { 184 | const StringView sep = str(": "); 185 | const int index_of_separator = CpuFeatures_StringView_IndexOf(line, sep); 186 | if (index_of_separator < 0) return false; 187 | *value = CpuFeatures_StringView_TrimWhitespace( 188 | CpuFeatures_StringView_PopFront(line, index_of_separator + sep.size)); 189 | *key = CpuFeatures_StringView_TrimWhitespace( 190 | CpuFeatures_StringView_KeepFront(line, index_of_separator)); 191 | return true; 192 | } 193 | -------------------------------------------------------------------------------- /deps/cpu_features/test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # 2 | # libraries for tests 3 | # 4 | 5 | include_directories(../include) 6 | add_definitions(-DCPU_FEATURES_TEST) 7 | 8 | ##------------------------------------------------------------------------------ 9 | add_library(string_view ../src/string_view.c) 10 | ##------------------------------------------------------------------------------ 11 | add_library(filesystem_for_testing filesystem_for_testing.cc) 12 | target_compile_definitions(filesystem_for_testing PUBLIC CPU_FEATURES_MOCK_FILESYSTEM) 13 | ##------------------------------------------------------------------------------ 14 | add_library(hwcaps_for_testing hwcaps_for_testing.cc) 15 | target_link_libraries(hwcaps_for_testing filesystem_for_testing) 16 | ##------------------------------------------------------------------------------ 17 | add_library(stack_line_reader ../src/stack_line_reader.c) 18 | target_compile_definitions(stack_line_reader PUBLIC STACK_LINE_READER_BUFFER_SIZE=1024) 19 | target_link_libraries(stack_line_reader string_view) 20 | ##------------------------------------------------------------------------------ 21 | add_library(stack_line_reader_for_test ../src/stack_line_reader.c) 22 | target_compile_definitions(stack_line_reader_for_test PUBLIC STACK_LINE_READER_BUFFER_SIZE=16) 23 | target_link_libraries(stack_line_reader_for_test string_view filesystem_for_testing) 24 | ##------------------------------------------------------------------------------ 25 | add_library(all_libraries ../src/hwcaps.c ../src/stack_line_reader.c) 26 | target_link_libraries(all_libraries hwcaps_for_testing stack_line_reader string_view) 27 | 28 | # 29 | # tests 30 | # 31 | link_libraries(gtest gmock_main) 32 | 33 | ## bit_utils_test 34 | add_executable(bit_utils_test bit_utils_test.cc) 35 | target_link_libraries(bit_utils_test) 36 | add_test(NAME bit_utils_test COMMAND bit_utils_test) 37 | ##------------------------------------------------------------------------------ 38 | ## string_view_test 39 | add_executable(string_view_test string_view_test.cc ../src/string_view.c) 40 | target_link_libraries(string_view_test string_view) 41 | add_test(NAME string_view_test COMMAND string_view_test) 42 | ##------------------------------------------------------------------------------ 43 | ## stack_line_reader_test 44 | add_executable(stack_line_reader_test stack_line_reader_test.cc) 45 | target_link_libraries(stack_line_reader_test stack_line_reader_for_test) 46 | add_test(NAME stack_line_reader_test COMMAND stack_line_reader_test) 47 | ##------------------------------------------------------------------------------ 48 | ## cpuinfo_x86_test 49 | if(PROCESSOR_IS_X86) 50 | add_executable(cpuinfo_x86_test 51 | cpuinfo_x86_test.cc 52 | ../src/impl_x86_freebsd.c 53 | ../src/impl_x86_linux_or_android.c 54 | ../src/impl_x86_macos.c 55 | ../src/impl_x86_windows.c 56 | ) 57 | target_compile_definitions(cpuinfo_x86_test PUBLIC CPU_FEATURES_MOCK_CPUID_X86) 58 | if(APPLE) 59 | target_compile_definitions(cpuinfo_x86_test PRIVATE HAVE_SYSCTLBYNAME) 60 | endif() 61 | target_link_libraries(cpuinfo_x86_test all_libraries) 62 | add_test(NAME cpuinfo_x86_test COMMAND cpuinfo_x86_test) 63 | endif() 64 | ##------------------------------------------------------------------------------ 65 | ## cpuinfo_arm_test 66 | if(PROCESSOR_IS_ARM) 67 | add_executable(cpuinfo_arm_test cpuinfo_arm_test.cc ../src/impl_arm_linux_or_android.c) 68 | target_link_libraries(cpuinfo_arm_test all_libraries) 69 | add_test(NAME cpuinfo_arm_test COMMAND cpuinfo_arm_test) 70 | endif() 71 | ##------------------------------------------------------------------------------ 72 | ## cpuinfo_aarch64_test 73 | if(PROCESSOR_IS_AARCH64) 74 | add_executable(cpuinfo_aarch64_test 75 | cpuinfo_aarch64_test.cc 76 | ../src/impl_aarch64_linux_or_android.c 77 | ../src/impl_aarch64_macos_or_iphone.c 78 | ../src/impl_aarch64_windows.c) 79 | if(APPLE) 80 | target_compile_definitions(cpuinfo_aarch64_test PUBLIC CPU_FEATURES_MOCK_SYSCTL_AARCH64) 81 | target_compile_definitions(cpuinfo_aarch64_test PRIVATE HAVE_SYSCTLBYNAME) 82 | endif() 83 | target_compile_definitions(cpuinfo_aarch64_test PUBLIC CPU_FEATURES_MOCK_CPUID_AARCH64) 84 | target_link_libraries(cpuinfo_aarch64_test all_libraries) 85 | add_test(NAME cpuinfo_aarch64_test COMMAND cpuinfo_aarch64_test) 86 | endif() 87 | ##------------------------------------------------------------------------------ 88 | ## cpuinfo_mips_test 89 | if(PROCESSOR_IS_MIPS) 90 | add_executable(cpuinfo_mips_test cpuinfo_mips_test.cc ../src/impl_mips_linux_or_android.c) 91 | target_link_libraries(cpuinfo_mips_test all_libraries) 92 | add_test(NAME cpuinfo_mips_test COMMAND cpuinfo_mips_test) 93 | endif() 94 | ##------------------------------------------------------------------------------ 95 | ## cpuinfo_ppc_test 96 | if(PROCESSOR_IS_POWER) 97 | add_executable(cpuinfo_ppc_test cpuinfo_ppc_test.cc ../src/impl_ppc_linux.c) 98 | target_link_libraries(cpuinfo_ppc_test all_libraries) 99 | add_test(NAME cpuinfo_ppc_test COMMAND cpuinfo_ppc_test) 100 | endif() 101 | ##------------------------------------------------------------------------------ 102 | ## cpuinfo_s390x_test 103 | if(PROCESSOR_IS_S390X) 104 | add_executable(cpuinfo_s390x_test cpuinfo_s390x_test.cc ../src/impl_s390x_linux.c) 105 | target_link_libraries(cpuinfo_s390x_test all_libraries) 106 | add_test(NAME cpuinfo_s390x_test COMMAND cpuinfo_s390x_test) 107 | endif() 108 | ##------------------------------------------------------------------------------ 109 | ## cpuinfo_riscv_test 110 | if(PROCESSOR_IS_RISCV) 111 | add_executable(cpuinfo_riscv_test cpuinfo_riscv_test.cc ../src/impl_riscv_linux.c) 112 | target_link_libraries(cpuinfo_riscv_test all_libraries) 113 | add_test(NAME cpuinfo_riscv_test COMMAND cpuinfo_riscv_test) 114 | endif() 115 | -------------------------------------------------------------------------------- /deps/cpu_features/test/bit_utils_test.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2017 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "internal/bit_utils.h" 16 | 17 | #include "gtest/gtest.h" 18 | 19 | namespace cpu_features { 20 | namespace { 21 | 22 | TEST(UtilsTest, IsBitSet) { 23 | for (size_t bit_set = 0; bit_set < 32; ++bit_set) { 24 | const uint32_t value = 1UL << bit_set; 25 | for (uint32_t i = 0; i < 32; ++i) { 26 | EXPECT_EQ(IsBitSet(value, i), i == bit_set); 27 | } 28 | } 29 | 30 | // testing 0, all bits should be 0. 31 | for (uint32_t i = 0; i < 32; ++i) { 32 | EXPECT_FALSE(IsBitSet(0, i)); 33 | } 34 | 35 | // testing ~0, all bits should be 1. 36 | for (uint32_t i = 0; i < 32; ++i) { 37 | EXPECT_TRUE(IsBitSet(-1, i)); 38 | } 39 | } 40 | 41 | TEST(UtilsTest, ExtractBitRange) { 42 | // Extracting all bits gives the same number. 43 | EXPECT_EQ(ExtractBitRange(123, 31, 0), 123); 44 | // Extracting 1 bit gives parity. 45 | EXPECT_EQ(ExtractBitRange(123, 0, 0), 1); 46 | EXPECT_EQ(ExtractBitRange(122, 0, 0), 0); 47 | 48 | EXPECT_EQ(ExtractBitRange(0xF0, 7, 4), 0xF); 49 | EXPECT_EQ(ExtractBitRange(0x42 << 2, 10, 2), 0x42); 50 | } 51 | 52 | } // namespace 53 | } // namespace cpu_features 54 | -------------------------------------------------------------------------------- /deps/cpu_features/test/cpuinfo_mips_test.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2017 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "cpuinfo_mips.h" 16 | 17 | #include "filesystem_for_testing.h" 18 | #include "gtest/gtest.h" 19 | #include "hwcaps_for_testing.h" 20 | #include "internal/stack_line_reader.h" 21 | #include "internal/string_view.h" 22 | 23 | namespace cpu_features { 24 | 25 | namespace { 26 | 27 | TEST(CpuinfoMipsTest, MipsFeaturesEnum) { 28 | const char *last_name = GetMipsFeaturesEnumName(MIPS_LAST_); 29 | EXPECT_STREQ(last_name, "unknown_feature"); 30 | for (int i = static_cast(MIPS_MSA); i != static_cast(MIPS_LAST_); ++i) { 31 | const auto feature = static_cast(i); 32 | const char *name = GetMipsFeaturesEnumName(feature); 33 | ASSERT_FALSE(name == nullptr); 34 | EXPECT_STRNE(name, ""); 35 | EXPECT_STRNE(name, last_name); 36 | } 37 | } 38 | 39 | TEST(CpuinfoMipsTest, FromHardwareCapBoth) { 40 | ResetHwcaps(); 41 | SetHardwareCapabilities(MIPS_HWCAP_MSA | MIPS_HWCAP_R6, 0); 42 | GetEmptyFilesystem(); // disabling /proc/cpuinfo 43 | const auto info = GetMipsInfo(); 44 | EXPECT_TRUE(info.features.msa); 45 | EXPECT_FALSE(info.features.eva); 46 | EXPECT_TRUE(info.features.r6); 47 | } 48 | 49 | TEST(CpuinfoMipsTest, FromHardwareCapOnlyOne) { 50 | ResetHwcaps(); 51 | SetHardwareCapabilities(MIPS_HWCAP_MSA, 0); 52 | GetEmptyFilesystem(); // disabling /proc/cpuinfo 53 | const auto info = GetMipsInfo(); 54 | EXPECT_TRUE(info.features.msa); 55 | EXPECT_FALSE(info.features.eva); 56 | } 57 | 58 | TEST(CpuinfoMipsTest, Ci40) { 59 | ResetHwcaps(); 60 | auto& fs = GetEmptyFilesystem(); 61 | fs.CreateFile("/proc/cpuinfo", R"(system type : IMG Pistachio SoC (B0) 62 | machine : IMG Marduk – Ci40 with cc2520 63 | processor : 0 64 | cpu model : MIPS interAptiv (multi) V2.0 FPU V0.0 65 | BogoMIPS : 363.72 66 | wait instruction : yes 67 | microsecond timers : yes 68 | tlb_entries : 64 69 | extra interrupt vector : yes 70 | hardware watchpoint : yes, count: 4, address/irw mask: [0x0ffc, 0x0ffc, 0x0ffb, 0x0ffb] 71 | isa : mips1 mips2 mips32r1 mips32r2 72 | ASEs implemented : mips16 dsp mt eva 73 | shadow register sets : 1 74 | kscratch registers : 0 75 | package : 0 76 | core : 0 77 | VCED exceptions : not available 78 | VCEI exceptions : not available 79 | VPE : 0 80 | )"); 81 | const auto info = GetMipsInfo(); 82 | EXPECT_FALSE(info.features.msa); 83 | EXPECT_TRUE(info.features.eva); 84 | EXPECT_FALSE(info.features.r6); 85 | EXPECT_TRUE(info.features.mips16); 86 | EXPECT_FALSE(info.features.mdmx); 87 | EXPECT_FALSE(info.features.mips3d); 88 | EXPECT_FALSE(info.features.smart); 89 | EXPECT_TRUE(info.features.dsp); 90 | } 91 | 92 | TEST(CpuinfoMipsTest, AR7161) { 93 | ResetHwcaps(); 94 | auto& fs = GetEmptyFilesystem(); 95 | fs.CreateFile("/proc/cpuinfo", 96 | R"(system type : Atheros AR7161 rev 2 97 | machine : NETGEAR WNDR3700/WNDR3800/WNDRMAC 98 | processor : 0 99 | cpu model : MIPS 24Kc V7.4 100 | BogoMIPS : 452.19 101 | wait instruction : yes 102 | microsecond timers : yes 103 | tlb_entries : 16 104 | extra interrupt vector : yes 105 | hardware watchpoint : yes, count: 4, address/irw mask: [0x0000, 0x0f98, 0x0f78, 0x0df8] 106 | ASEs implemented : mips16 107 | shadow register sets : 1 108 | kscratch registers : 0 109 | core : 0 110 | VCED exceptions : not available 111 | VCEI exceptions : not available 112 | )"); 113 | const auto info = GetMipsInfo(); 114 | EXPECT_FALSE(info.features.msa); 115 | EXPECT_FALSE(info.features.eva); 116 | EXPECT_TRUE(info.features.mips16); 117 | } 118 | 119 | TEST(CpuinfoMipsTest, Goldfish) { 120 | ResetHwcaps(); 121 | auto& fs = GetEmptyFilesystem(); 122 | fs.CreateFile("/proc/cpuinfo", R"(system type : MIPS-Goldfish 123 | Hardware : goldfish 124 | Revison : 1 125 | processor : 0 126 | cpu model : MIPS 24Kc V0.0 FPU V0.0 127 | BogoMIPS : 1042.02 128 | wait instruction : yes 129 | microsecond timers : yes 130 | tlb_entries : 16 131 | extra interrupt vector : yes 132 | hardware watchpoint : yes, count: 1, address/irw mask: [0x0ff8] 133 | ASEs implemented : 134 | shadow register sets : 1 135 | core : 0 136 | VCED exceptions : not available 137 | VCEI exceptions : not available 138 | )"); 139 | const auto info = GetMipsInfo(); 140 | EXPECT_FALSE(info.features.msa); 141 | EXPECT_FALSE(info.features.eva); 142 | } 143 | 144 | TEST(CpuinfoMipsTest, BCM1250) { 145 | ResetHwcaps(); 146 | auto& fs = GetEmptyFilesystem(); 147 | fs.CreateFile("/proc/cpuinfo", R"(system type : SiByte BCM91250A (SWARM) 148 | processor : 0 149 | cpu model : SiByte SB1 V0.2 FPU V0.2 150 | BogoMIPS : 532.48 151 | wait instruction : no 152 | microsecond timers : yes 153 | tlb_entries : 64 154 | extra interrupt vector : yes 155 | hardware watchpoint : yes, count: 1, address/irw mask: [0x0ff8] 156 | isa : mips1 mips2 mips3 mips4 mips5 mips32r1 mips32r2 mips64r1 mips64r2 157 | ASEs implemented : mdmx mips3d 158 | shadow register sets : 1 159 | kscratch registers : 0 160 | package : 0 161 | core : 0 162 | VCED exceptions : not available 163 | VCEI exceptions : not available 164 | )"); 165 | const auto info = GetMipsInfo(); 166 | EXPECT_FALSE(info.features.msa); 167 | EXPECT_FALSE(info.features.eva); 168 | EXPECT_FALSE(info.features.mips16); 169 | EXPECT_TRUE(info.features.mdmx); 170 | EXPECT_TRUE(info.features.mips3d); 171 | EXPECT_FALSE(info.features.smart); 172 | EXPECT_FALSE(info.features.dsp); 173 | } 174 | 175 | } // namespace 176 | } // namespace cpu_features 177 | -------------------------------------------------------------------------------- /deps/cpu_features/test/cpuinfo_ppc_test.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2018 IBM. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "cpuinfo_ppc.h" 16 | 17 | #include "filesystem_for_testing.h" 18 | #include "gtest/gtest.h" 19 | #include "hwcaps_for_testing.h" 20 | #include "internal/string_view.h" 21 | 22 | namespace cpu_features { 23 | namespace { 24 | 25 | TEST(CpustringsPPCTest, PPCFeaturesEnum) { 26 | const char *last_name = GetPPCFeaturesEnumName(PPC_LAST_); 27 | EXPECT_STREQ(last_name, "unknown_feature"); 28 | for (int i = static_cast(PPC_32); i != static_cast(PPC_LAST_); ++i) { 29 | const auto feature = static_cast(i); 30 | const char *name = GetPPCFeaturesEnumName(feature); 31 | ASSERT_FALSE(name == nullptr); 32 | EXPECT_STRNE(name, ""); 33 | EXPECT_STRNE(name, last_name); 34 | } 35 | } 36 | 37 | TEST(CpustringsPPCTest, FromHardwareCap) { 38 | ResetHwcaps(); 39 | SetHardwareCapabilities(PPC_FEATURE_HAS_FPU | PPC_FEATURE_HAS_VSX, 40 | PPC_FEATURE2_ARCH_3_00); 41 | GetEmptyFilesystem(); // disabling /proc/cpuinfo 42 | const auto info = GetPPCInfo(); 43 | EXPECT_TRUE(info.features.fpu); 44 | EXPECT_FALSE(info.features.mmu); 45 | EXPECT_TRUE(info.features.vsx); 46 | EXPECT_TRUE(info.features.arch300); 47 | EXPECT_FALSE(info.features.power4); 48 | EXPECT_FALSE(info.features.altivec); 49 | EXPECT_FALSE(info.features.vcrypto); 50 | EXPECT_FALSE(info.features.htm); 51 | } 52 | 53 | TEST(CpustringsPPCTest, Blade) { 54 | ResetHwcaps(); 55 | auto& fs = GetEmptyFilesystem(); 56 | fs.CreateFile("/proc/cpuinfo", 57 | R"(processor : 14 58 | cpu : POWER7 (architected), altivec supported 59 | clock : 3000.000000MHz 60 | revision : 2.1 (pvr 003f 0201) 61 | 62 | processor : 15 63 | cpu : POWER7 (architected), altivec supported 64 | clock : 3000.000000MHz 65 | revision : 2.1 (pvr 003f 0201) 66 | 67 | timebase : 512000000 68 | platform : pSeries 69 | model : IBM,8406-70Y 70 | machine : CHRP IBM,8406-70Y)"); 71 | SetPlatformPointer("power7"); 72 | SetBasePlatformPointer("power8"); 73 | const auto strings = GetPPCPlatformStrings(); 74 | ASSERT_STREQ(strings.platform, "pSeries"); 75 | ASSERT_STREQ(strings.model, "IBM,8406-70Y"); 76 | ASSERT_STREQ(strings.machine, "CHRP IBM,8406-70Y"); 77 | ASSERT_STREQ(strings.cpu, "POWER7 (architected), altivec supported"); 78 | ASSERT_STREQ(strings.type.platform, "power7"); 79 | ASSERT_STREQ(strings.type.base_platform, "power8"); 80 | } 81 | 82 | TEST(CpustringsPPCTest, Firestone) { 83 | ResetHwcaps(); 84 | auto& fs = GetEmptyFilesystem(); 85 | fs.CreateFile("/proc/cpuinfo", 86 | R"(processor : 126 87 | cpu : POWER8 (raw), altivec supported 88 | clock : 2061.000000MHz 89 | revision : 2.0 (pvr 004d 0200) 90 | 91 | processor : 127 92 | cpu : POWER8 (raw), altivec supported 93 | clock : 2061.000000MHz 94 | revision : 2.0 (pvr 004d 0200) 95 | 96 | timebase : 512000000 97 | platform : PowerNV 98 | model : 8335-GTA 99 | machine : PowerNV 8335-GTA 100 | firmware : OPAL v3)"); 101 | const auto strings = GetPPCPlatformStrings(); 102 | ASSERT_STREQ(strings.platform, "PowerNV"); 103 | ASSERT_STREQ(strings.model, "8335-GTA"); 104 | ASSERT_STREQ(strings.machine, "PowerNV 8335-GTA"); 105 | ASSERT_STREQ(strings.cpu, "POWER8 (raw), altivec supported"); 106 | } 107 | 108 | TEST(CpustringsPPCTest, w8) { 109 | ResetHwcaps(); 110 | auto& fs = GetEmptyFilesystem(); 111 | fs.CreateFile("/proc/cpuinfo", 112 | R"(processor : 143 113 | cpu : POWER9, altivec supported 114 | clock : 2300.000000MHz 115 | revision : 2.2 (pvr 004e 1202) 116 | 117 | timebase : 512000000 118 | platform : PowerNV 119 | model : 0000000000000000 120 | machine : PowerNV 0000000000000000 121 | firmware : OPAL 122 | MMU : Radix)"); 123 | const auto strings = GetPPCPlatformStrings(); 124 | ASSERT_STREQ(strings.platform, "PowerNV"); 125 | ASSERT_STREQ(strings.model, "0000000000000000"); 126 | ASSERT_STREQ(strings.machine, "PowerNV 0000000000000000"); 127 | ASSERT_STREQ(strings.cpu, "POWER9, altivec supported"); 128 | } 129 | 130 | } // namespace 131 | } // namespace cpu_features 132 | -------------------------------------------------------------------------------- /deps/cpu_features/test/cpuinfo_riscv_test.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2022 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "cpuinfo_riscv.h" 16 | 17 | #include "filesystem_for_testing.h" 18 | #include "gtest/gtest.h" 19 | #include "hwcaps_for_testing.h" 20 | 21 | namespace cpu_features { 22 | namespace { 23 | 24 | TEST(CpuinfoRiscvTest, Sipeed_Lichee_RV_FromCpuInfo) { 25 | ResetHwcaps(); 26 | auto& fs = GetEmptyFilesystem(); 27 | fs.CreateFile("/proc/cpuinfo", R"(processor : 0 28 | hart : 0 29 | isa : rv64imafdc 30 | mmu : sv39 31 | uarch : thead,c906)"); 32 | const auto info = GetRiscvInfo(); 33 | EXPECT_STREQ(info.uarch, "c906"); 34 | EXPECT_STREQ(info.vendor, "thead"); 35 | 36 | EXPECT_FALSE(info.features.RV32I); 37 | EXPECT_TRUE(info.features.RV64I); 38 | EXPECT_TRUE(info.features.M); 39 | EXPECT_TRUE(info.features.A); 40 | EXPECT_TRUE(info.features.F); 41 | EXPECT_TRUE(info.features.D); 42 | EXPECT_FALSE(info.features.Q); 43 | EXPECT_TRUE(info.features.C); 44 | EXPECT_FALSE(info.features.V); 45 | } 46 | 47 | // https://github.com/ThomasKaiser/sbc-bench/blob/284e82b016ec1beeac42a5fcbe556b670f68441a/results/Kendryte-K510-4.17.0.cpuinfo 48 | TEST(CpuinfoRiscvTest, Kendryte_K510_FromCpuInfo) { 49 | ResetHwcaps(); 50 | auto& fs = GetEmptyFilesystem(); 51 | fs.CreateFile("/proc/cpuinfo", R"( 52 | hart : 0 53 | isa : rv64i2p0m2p0a2p0f2p0d2p0c2p0xv5-0p0 54 | mmu : sv39 55 | 56 | hart : 1 57 | isa : rv64i2p0m2p0a2p0f2p0d2p0c2p0xv5-0p0 58 | mmu : sv39"); 59 | const auto info = GetRiscvInfo(); 60 | EXPECT_STREQ(info.uarch, ""); 61 | EXPECT_STREQ(info.vendor, ""); 62 | 63 | EXPECT_FALSE(info.features.RV32I); 64 | EXPECT_TRUE(info.features.RV64I); 65 | EXPECT_TRUE(info.features.M); 66 | EXPECT_TRUE(info.features.A); 67 | EXPECT_TRUE(info.features.F); 68 | EXPECT_TRUE(info.features.D); 69 | EXPECT_FALSE(info.features.Q); 70 | EXPECT_TRUE(info.features.C); 71 | EXPECT_FALSE(info.features.V); 72 | } 73 | 74 | // https://github.com/ThomasKaiser/sbc-bench/blob/284e82b016ec1beeac42a5fcbe556b670f68441a/results/T-Head-C910-5.10.4.cpuinfo 75 | TEST(CpuinfoRiscvTest, T_Head_C910_FromCpuInfo) { 76 | ResetHwcaps(); 77 | auto& fs = GetEmptyFilesystem(); 78 | fs.CreateFile("/proc/cpuinfo", R"( 79 | processor : 0 80 | hart : 0 81 | isa : rv64imafdcsu 82 | mmu : sv39 83 | cpu-freq : 1.2Ghz 84 | cpu-icache : 64KB 85 | cpu-dcache : 64KB 86 | cpu-l2cache : 2MB 87 | cpu-tlb : 1024 4-ways 88 | cpu-cacheline : 64Bytes 89 | cpu-vector : 0.7.1 90 | 91 | processor : 1 92 | hart : 1 93 | isa : rv64imafdcsu 94 | mmu : sv39 95 | cpu-freq : 1.2Ghz 96 | cpu-icache : 64KB 97 | cpu-dcache : 64KB 98 | cpu-l2cache : 2MB 99 | cpu-tlb : 1024 4-ways 100 | cpu-cacheline : 64Bytes 101 | cpu-vector : 0.7.1"); 102 | const auto info = GetRiscvInfo(); 103 | EXPECT_STREQ(info.uarch, ""); 104 | EXPECT_STREQ(info.vendor, ""); 105 | 106 | EXPECT_FALSE(info.features.RV32I); 107 | EXPECT_TRUE(info.features.RV64I); 108 | EXPECT_TRUE(info.features.M); 109 | EXPECT_TRUE(info.features.A); 110 | EXPECT_TRUE(info.features.F); 111 | EXPECT_TRUE(info.features.D); 112 | EXPECT_FALSE(info.features.Q); 113 | EXPECT_TRUE(info.features.C); 114 | EXPECT_FALSE(info.features.V); 115 | } 116 | 117 | TEST(CpuinfoRiscvTest, UnknownFromCpuInfo) { 118 | ResetHwcaps(); 119 | auto& fs = GetEmptyFilesystem(); 120 | fs.CreateFile("/proc/cpuinfo", R"( 121 | processor : 0 122 | hart : 2 123 | isa : rv64imafdc 124 | mmu : sv39 125 | uarch : sifive,bullet0 126 | 127 | processor : 1 128 | hart : 1 129 | isa : rv64imafdc 130 | mmu : sv39 131 | uarch : sifive,bullet0 132 | 133 | processor : 2 134 | hart : 3 135 | isa : rv64imafdc 136 | mmu : sv39 137 | uarch : sifive,bullet0 138 | 139 | processor : 3 140 | hart : 4 141 | isa : rv64imafdc 142 | mmu : sv39 143 | uarch : sifive,bullet0)"); 144 | const auto info = GetRiscvInfo(); 145 | EXPECT_STREQ(info.uarch, "bullet0"); 146 | EXPECT_STREQ(info.vendor, "sifive"); 147 | 148 | EXPECT_FALSE(info.features.RV32I); 149 | EXPECT_TRUE(info.features.RV64I); 150 | EXPECT_TRUE(info.features.M); 151 | EXPECT_TRUE(info.features.A); 152 | EXPECT_TRUE(info.features.F); 153 | EXPECT_TRUE(info.features.D); 154 | EXPECT_FALSE(info.features.Q); 155 | EXPECT_TRUE(info.features.C); 156 | EXPECT_FALSE(info.features.V); 157 | } 158 | 159 | TEST(CpuinfoRiscvTest, QemuCpuInfo) { 160 | ResetHwcaps(); 161 | auto& fs = GetEmptyFilesystem(); 162 | fs.CreateFile("/proc/cpuinfo", R"( 163 | processor : 0 164 | hart : 0 165 | isa : rv64imafdcvh_zba_zbb_zbc_zbs 166 | mmu : sv48)"); 167 | const auto info = GetRiscvInfo(); 168 | EXPECT_FALSE(info.features.RV32I); 169 | EXPECT_TRUE(info.features.RV64I); 170 | EXPECT_TRUE(info.features.M); 171 | EXPECT_TRUE(info.features.A); 172 | EXPECT_TRUE(info.features.F); 173 | EXPECT_TRUE(info.features.D); 174 | EXPECT_FALSE(info.features.Q); 175 | EXPECT_TRUE(info.features.C); 176 | EXPECT_TRUE(info.features.V); 177 | } 178 | 179 | } // namespace 180 | } // namespace cpu_features 181 | -------------------------------------------------------------------------------- /deps/cpu_features/test/cpuinfo_s390x_test.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2022 IBM. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "cpuinfo_s390x.h" 16 | #include "filesystem_for_testing.h" 17 | #include "gtest/gtest.h" 18 | #include "hwcaps_for_testing.h" 19 | 20 | namespace cpu_features { 21 | namespace { 22 | 23 | TEST(CpustringsS390XTest, S390XFeaturesEnum) { 24 | const char *last_name = GetS390XFeaturesEnumName(S390X_LAST_); 25 | EXPECT_STREQ(last_name, "unknown_feature"); 26 | for (int i = static_cast(S390_ZARCH); i != static_cast(S390X_LAST_); ++i) { 27 | const auto feature = static_cast(i); 28 | const char *name = GetS390XFeaturesEnumName(feature); 29 | ASSERT_FALSE(name == nullptr); 30 | EXPECT_STRNE(name, ""); 31 | EXPECT_STRNE(name, last_name); 32 | } 33 | } 34 | 35 | TEST(CpustringsS390XTest, FromHardwareCap) { 36 | ResetHwcaps(); 37 | SetHardwareCapabilities(HWCAP_S390_ESAN3 | HWCAP_S390_HPAGE | 38 | HWCAP_S390_NNPA | HWCAP_S390_SIE, 0); 39 | GetEmptyFilesystem(); // disabling /proc/cpuinfo 40 | const auto info = GetS390XInfo(); 41 | EXPECT_TRUE(info.features.esan3); 42 | EXPECT_TRUE(info.features.edat); 43 | EXPECT_TRUE(info.features.nnpa); 44 | EXPECT_TRUE(info.features.sie); 45 | EXPECT_FALSE(info.features.msa); 46 | EXPECT_FALSE(info.features.stfle); 47 | EXPECT_FALSE(info.features.vxp2); 48 | EXPECT_FALSE(info.features.pcimio); 49 | } 50 | 51 | TEST(CpustringsS390XTest, z16) { 52 | ResetHwcaps(); 53 | auto& fs = GetEmptyFilesystem(); 54 | fs.CreateFile("/proc/cpuinfo", 55 | R"(vendor_id : IBM/S390 56 | # processors : 24 57 | bogomips per cpu: 26315.00 58 | max thread id : 1 59 | features : esan3 zarch stfle msa ldisp eimm dfp edat etf3eh highgprs te vx vxd vxe gs vxe2 vxp sort dflt vxp2 nnpa pcimio sie )"); 60 | SetPlatformPointer("z16"); 61 | const auto strings = GetS390XPlatformStrings(); 62 | EXPECT_EQ(strings.num_processors, 24); 63 | ASSERT_STREQ(strings.type.platform, "z16"); 64 | } 65 | 66 | TEST(CpustringsS390XTest, z15) { 67 | ResetHwcaps(); 68 | auto& fs = GetEmptyFilesystem(); 69 | fs.CreateFile("/proc/cpuinfo", 70 | R"(vendor_id : IBM/S390 71 | # processors : 2 72 | bogomips per cpu: 24038.00 73 | max thread id : 1 74 | features : esan3 zarch stfle msa ldisp eimm dfp edat etf3eh highgprs te vx vxd vxe gs vxe2 vxp sort dflt sie)"); 75 | SetPlatformPointer("z15"); 76 | const auto strings = GetS390XPlatformStrings(); 77 | EXPECT_EQ(strings.num_processors, 2); 78 | ASSERT_STREQ(strings.type.platform, "z15"); 79 | } 80 | 81 | } // namespace 82 | } // namespace cpu_features 83 | -------------------------------------------------------------------------------- /deps/cpu_features/test/filesystem_for_testing.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2017 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "filesystem_for_testing.h" 16 | 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | namespace cpu_features { 24 | 25 | FakeFile::FakeFile(int file_descriptor, const char* content) 26 | : file_descriptor_(file_descriptor), content_(content) {} 27 | 28 | FakeFile::~FakeFile() { assert(!opened_); } 29 | 30 | void FakeFile::Open() { 31 | assert(!opened_); 32 | opened_ = true; 33 | } 34 | 35 | void FakeFile::Close() { 36 | assert(opened_); 37 | opened_ = false; 38 | } 39 | 40 | int FakeFile::Read(int fd, void* buf, size_t count) { 41 | assert(count < INT_MAX); 42 | assert(fd == file_descriptor_); 43 | const size_t remainder = content_.size() - head_index_; 44 | const size_t read = count > remainder ? remainder : count; 45 | memcpy(buf, content_.data() + head_index_, read); 46 | head_index_ += read; 47 | assert(read < INT_MAX); 48 | return (int)read; 49 | } 50 | 51 | void FakeFilesystem::Reset() { files_.clear(); } 52 | 53 | FakeFile* FakeFilesystem::CreateFile(const std::string& filename, 54 | const char* content) { 55 | auto& file = files_[filename]; 56 | file = 57 | std::unique_ptr(new FakeFile(next_file_descriptor_++, content)); 58 | return file.get(); 59 | } 60 | 61 | FakeFile* FakeFilesystem::FindFileOrNull(const std::string& filename) const { 62 | const auto itr = files_.find(filename); 63 | return itr == files_.end() ? nullptr : itr->second.get(); 64 | } 65 | 66 | FakeFile* FakeFilesystem::FindFileOrDie(const int file_descriptor) const { 67 | for (const auto& filename_file_pair : files_) { 68 | FakeFile* const file_ptr = filename_file_pair.second.get(); 69 | if (file_ptr->GetFileDescriptor() == file_descriptor) { 70 | return file_ptr; 71 | } 72 | } 73 | assert(false); 74 | return nullptr; 75 | } 76 | 77 | static FakeFilesystem* kFilesystem = new FakeFilesystem(); 78 | 79 | FakeFilesystem& GetEmptyFilesystem() { 80 | kFilesystem->Reset(); 81 | return *kFilesystem; 82 | } 83 | 84 | extern "C" int CpuFeatures_OpenFile(const char* filename) { 85 | auto* const file = kFilesystem->FindFileOrNull(filename); 86 | if (file) { 87 | file->Open(); 88 | return file->GetFileDescriptor(); 89 | } 90 | return -1; 91 | } 92 | 93 | extern "C" void CpuFeatures_CloseFile(int file_descriptor) { 94 | kFilesystem->FindFileOrDie(file_descriptor)->Close(); 95 | } 96 | 97 | extern "C" int CpuFeatures_ReadFile(int file_descriptor, void* buffer, 98 | size_t buffer_size) { 99 | return kFilesystem->FindFileOrDie(file_descriptor) 100 | ->Read(file_descriptor, buffer, buffer_size); 101 | } 102 | 103 | } // namespace cpu_features 104 | -------------------------------------------------------------------------------- /deps/cpu_features/test/filesystem_for_testing.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Implements a fake filesystem, useful for tests. 16 | #ifndef CPU_FEATURES_TEST_FILESYSTEM_FOR_TESTING_H_ 17 | #define CPU_FEATURES_TEST_FILESYSTEM_FOR_TESTING_H_ 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | #include "internal/filesystem.h" 24 | 25 | namespace cpu_features { 26 | 27 | class FakeFile { 28 | public: 29 | explicit FakeFile(int file_descriptor, const char* content); 30 | ~FakeFile(); 31 | 32 | void Open(); 33 | void Close(); 34 | int Read(int fd, void* buf, size_t count); 35 | 36 | int GetFileDescriptor() const { return file_descriptor_; } 37 | 38 | private: 39 | const int file_descriptor_; 40 | const std::string content_; 41 | bool opened_ = false; 42 | size_t head_index_ = 0; 43 | }; 44 | 45 | class FakeFilesystem { 46 | public: 47 | void Reset(); 48 | FakeFile* CreateFile(const std::string& filename, const char* content); 49 | FakeFile* FindFileOrDie(const int file_descriptor) const; 50 | FakeFile* FindFileOrNull(const std::string& filename) const; 51 | 52 | private: 53 | int next_file_descriptor_ = 0; 54 | std::unordered_map> files_; 55 | }; 56 | 57 | FakeFilesystem& GetEmptyFilesystem(); 58 | 59 | } // namespace cpu_features 60 | 61 | #endif // CPU_FEATURES_TEST_FILESYSTEM_FOR_TESTING_H_ 62 | -------------------------------------------------------------------------------- /deps/cpu_features/test/hwcaps_for_testing.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2017 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "hwcaps_for_testing.h" 16 | 17 | #include 18 | 19 | #include "internal/string_view.h" 20 | 21 | namespace cpu_features { 22 | 23 | namespace { 24 | static auto* const g_hardware_capabilities = new HardwareCapabilities(); 25 | static const char* g_platform_pointer = nullptr; 26 | static const char* g_base_platform_pointer = nullptr; 27 | } // namespace 28 | 29 | void SetHardwareCapabilities(uint32_t hwcaps, uint32_t hwcaps2) { 30 | g_hardware_capabilities->hwcaps = hwcaps; 31 | g_hardware_capabilities->hwcaps2 = hwcaps2; 32 | } 33 | void SetPlatformPointer(const char* string) { g_platform_pointer = string; } 34 | void SetBasePlatformPointer(const char* string) { 35 | g_base_platform_pointer = string; 36 | } 37 | 38 | void ResetHwcaps() { 39 | SetHardwareCapabilities(0, 0); 40 | SetPlatformPointer(nullptr); 41 | SetBasePlatformPointer(nullptr); 42 | } 43 | 44 | HardwareCapabilities CpuFeatures_GetHardwareCapabilities(void) { 45 | return *g_hardware_capabilities; 46 | } 47 | const char* CpuFeatures_GetPlatformPointer(void) { return g_platform_pointer; } 48 | const char* CpuFeatures_GetBasePlatformPointer(void) { 49 | return g_base_platform_pointer; 50 | } 51 | 52 | } // namespace cpu_features 53 | -------------------------------------------------------------------------------- /deps/cpu_features/test/hwcaps_for_testing.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef CPU_FEATURES_TEST_HWCAPS_FOR_TESTING_H_ 16 | #define CPU_FEATURES_TEST_HWCAPS_FOR_TESTING_H_ 17 | 18 | #include "internal/hwcaps.h" 19 | 20 | namespace cpu_features { 21 | 22 | void SetHardwareCapabilities(uint32_t hwcaps, uint32_t hwcaps2); 23 | void SetPlatformPointer(const char* string); 24 | void SetBasePlatformPointer(const char* string); 25 | 26 | // To be called before each test. 27 | void ResetHwcaps(); 28 | 29 | } // namespace cpu_features 30 | 31 | #endif // CPU_FEATURES_TEST_HWCAPS_FOR_TESTING_H_ 32 | -------------------------------------------------------------------------------- /deps/cpu_features/test/stack_line_reader_test.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2017 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "internal/stack_line_reader.h" 16 | 17 | #include "filesystem_for_testing.h" 18 | #include "gtest/gtest.h" 19 | 20 | namespace cpu_features { 21 | 22 | bool operator==(const StringView& a, const StringView& b) { 23 | return CpuFeatures_StringView_IsEquals(a, b); 24 | } 25 | 26 | namespace { 27 | 28 | std::string ToString(StringView view) { return {view.ptr, view.size}; } 29 | 30 | TEST(StackLineReaderTest, Empty) { 31 | auto& fs = GetEmptyFilesystem(); 32 | auto* file = fs.CreateFile("/proc/cpuinfo", ""); 33 | StackLineReader reader; 34 | StackLineReader_Initialize(&reader, file->GetFileDescriptor()); 35 | { 36 | const auto result = StackLineReader_NextLine(&reader); 37 | EXPECT_TRUE(result.eof); 38 | EXPECT_TRUE(result.full_line); 39 | EXPECT_EQ(result.line, str("")); 40 | } 41 | } 42 | 43 | TEST(StackLineReaderTest, ManySmallLines) { 44 | auto& fs = GetEmptyFilesystem(); 45 | auto* file = fs.CreateFile("/proc/cpuinfo", "a\nb\nc"); 46 | 47 | StackLineReader reader; 48 | StackLineReader_Initialize(&reader, file->GetFileDescriptor()); 49 | { 50 | const auto result = StackLineReader_NextLine(&reader); 51 | EXPECT_FALSE(result.eof); 52 | EXPECT_TRUE(result.full_line); 53 | EXPECT_EQ(result.line, str("a")); 54 | } 55 | { 56 | const auto result = StackLineReader_NextLine(&reader); 57 | EXPECT_FALSE(result.eof); 58 | EXPECT_TRUE(result.full_line); 59 | EXPECT_EQ(result.line, str("b")); 60 | } 61 | { 62 | const auto result = StackLineReader_NextLine(&reader); 63 | EXPECT_TRUE(result.eof); 64 | EXPECT_TRUE(result.full_line); 65 | EXPECT_EQ(result.line, str("c")); 66 | } 67 | } 68 | 69 | TEST(StackLineReaderTest, TruncatedLine) { 70 | auto& fs = GetEmptyFilesystem(); 71 | auto* file = fs.CreateFile("/proc/cpuinfo", R"(First 72 | Second 73 | More than 16 characters, this will be truncated. 74 | last)"); 75 | 76 | StackLineReader reader; 77 | StackLineReader_Initialize(&reader, file->GetFileDescriptor()); 78 | { 79 | const auto result = StackLineReader_NextLine(&reader); 80 | EXPECT_FALSE(result.eof); 81 | EXPECT_TRUE(result.full_line); 82 | EXPECT_EQ(result.line, str("First")); 83 | } 84 | { 85 | const auto result = StackLineReader_NextLine(&reader); 86 | EXPECT_FALSE(result.eof); 87 | EXPECT_TRUE(result.full_line); 88 | EXPECT_EQ(result.line, str("Second")); 89 | } 90 | { 91 | const auto result = StackLineReader_NextLine(&reader); 92 | EXPECT_FALSE(result.eof); 93 | EXPECT_FALSE(result.full_line); 94 | EXPECT_EQ(result.line, str("More than 16 cha")); 95 | } 96 | { 97 | const auto result = StackLineReader_NextLine(&reader); 98 | EXPECT_TRUE(result.eof); 99 | EXPECT_TRUE(result.full_line); 100 | EXPECT_EQ(result.line, str("last")); 101 | } 102 | } 103 | 104 | TEST(StackLineReaderTest, TruncatedLines) { 105 | auto& fs = GetEmptyFilesystem(); 106 | auto* file = fs.CreateFile("/proc/cpuinfo", R"(More than 16 characters 107 | Another line that is too long)"); 108 | 109 | StackLineReader reader; 110 | StackLineReader_Initialize(&reader, file->GetFileDescriptor()); 111 | { 112 | const auto result = StackLineReader_NextLine(&reader); 113 | EXPECT_FALSE(result.eof); 114 | EXPECT_FALSE(result.full_line); 115 | EXPECT_EQ(result.line, str("More than 16 cha")); 116 | } 117 | { 118 | const auto result = StackLineReader_NextLine(&reader); 119 | EXPECT_FALSE(result.eof); 120 | EXPECT_FALSE(result.full_line); 121 | EXPECT_EQ(result.line, str("Another line tha")); 122 | } 123 | { 124 | const auto result = StackLineReader_NextLine(&reader); 125 | EXPECT_TRUE(result.eof); 126 | EXPECT_TRUE(result.full_line); 127 | EXPECT_EQ(result.line, str("")); 128 | } 129 | } 130 | 131 | } // namespace 132 | } // namespace cpu_features 133 | -------------------------------------------------------------------------------- /lib/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const binding = require('../build/Release/cpufeatures.node'); 4 | 5 | module.exports = binding.getCPUInfo; 6 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "cpu-features", 3 | "version": "0.0.10", 4 | "author": "Brian White ", 5 | "description": "A simple binding to Google's cpu_features library for obtaining information about installed CPU(s)", 6 | "main": "./lib/index", 7 | "dependencies": { 8 | "buildcheck": "~0.0.6", 9 | "nan": "^2.22.1" 10 | }, 11 | "devDependencies": { 12 | "@mscdex/eslint-config": "^1.1.0", 13 | "eslint": "^7.0.0" 14 | }, 15 | "scripts": { 16 | "install": "node buildcheck.js > buildcheck.gypi && node-gyp rebuild", 17 | "test": "node test/test.js", 18 | "lint": "eslint --cache --report-unused-disable-directives --ext=.js .eslintrc.js lib test", 19 | "lint:fix": "npm run lint -- --fix" 20 | }, 21 | "engines": { 22 | "node": ">=10.0.0" 23 | }, 24 | "keywords": [ 25 | "cpu", 26 | "detect", 27 | "detection", 28 | "features" 29 | ], 30 | "licenses": [ 31 | { 32 | "type": "MIT", 33 | "url": "https://github.com/mscdex/cpu-features/raw/master/LICENSE" 34 | } 35 | ], 36 | "repository": { 37 | "type": "git", 38 | "url": "https://github.com/mscdex/cpu-features.git" 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/binding.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include // isspace 5 | 6 | #include "cpu_features_macros.h" 7 | 8 | #if defined(CPU_FEATURES_ARCH_X86) 9 | # include "cpuinfo_x86.h" 10 | # define GetFeatureName GetX86FeaturesEnumName 11 | # define GetFeatureValue GetX86FeaturesEnumValue 12 | # define FeatureType X86Features 13 | # define FeatureEnumType X86FeaturesEnum 14 | # define LastFeature X86_LAST_ 15 | #elif defined(CPU_FEATURES_ARCH_ARM) 16 | # include "cpuinfo_arm.h" 17 | # define GetFeatureName GetArmFeaturesEnumName 18 | # define GetFeatureValue GetArmFeaturesEnumValue 19 | # define FeatureType ArmFeatures 20 | # define FeatureEnumType ArmFeaturesEnum 21 | # define LastFeature ARM_LAST_ 22 | #elif defined(CPU_FEATURES_ARCH_AARCH64) 23 | # include "cpuinfo_aarch64.h" 24 | # define GetFeatureName GetAarch64FeaturesEnumName 25 | # define GetFeatureValue GetAarch64FeaturesEnumValue 26 | # define FeatureType Aarch64Features 27 | # define FeatureEnumType Aarch64FeaturesEnum 28 | # define LastFeature AARCH64_LAST_ 29 | #elif defined(CPU_FEATURES_ARCH_MIPS) 30 | # include "cpuinfo_mips.h" 31 | # define GetFeatureName GetMipsFeaturesEnumName 32 | # define GetFeatureValue GetMipsFeaturesEnumValue 33 | # define FeatureType MipsFeatures 34 | # define FeatureEnumType MipsFeaturesEnum 35 | # define LastFeature MIPS_LAST_ 36 | #elif defined(CPU_FEATURES_ARCH_PPC) 37 | # include "cpuinfo_ppc.h" 38 | # define GetFeatureName GetPPCFeaturesEnumName 39 | # define GetFeatureValue GetPPCFeaturesEnumValue 40 | # define FeatureType PPCFeatures 41 | # define FeatureEnumType PPCFeaturesEnum 42 | # define LastFeature PPC_LAST_ 43 | #endif 44 | 45 | #define SET_FLAG(key) \ 46 | Nan::Set(ret, Nan::New(key).ToLocalChecked(), Nan::New(true)) 47 | 48 | #define SET_STR(key, val) \ 49 | Nan::Set(ret, \ 50 | Nan::New(key).ToLocalChecked(), \ 51 | Nan::New(trim(val)).ToLocalChecked()) 52 | 53 | #define SET_NUM(key, val) \ 54 | Nan::Set(ret, Nan::New(key).ToLocalChecked(), Nan::New(val)) 55 | 56 | #define SET_VAL(key, val) \ 57 | Nan::Set(ret, Nan::New(key).ToLocalChecked(), val) 58 | 59 | using namespace node; 60 | using namespace v8; 61 | using namespace cpu_features; 62 | using namespace std; 63 | 64 | static inline void ltrim(string& s) { 65 | s.erase(s.begin(), find_if(s.begin(), s.end(), [](int ch) { 66 | return !isspace(ch); 67 | })); 68 | } 69 | 70 | static inline void rtrim(string& s) { 71 | s.erase(find_if(s.rbegin(), s.rend(), [](int ch) { 72 | return !isspace(ch); 73 | }).base(), s.end()); 74 | } 75 | 76 | static inline string trim(const char* str) { 77 | string ret = str; 78 | ltrim(ret); 79 | rtrim(ret); 80 | return ret; 81 | } 82 | 83 | #if defined(LastFeature) 84 | Local GenerateFlags(const FeatureType* features) { 85 | const auto ret = Nan::New(); 86 | for (size_t i = 0; i < LastFeature; ++i) { 87 | const auto enum_val = static_cast(i); 88 | if (GetFeatureValue(features, enum_val)) 89 | SET_FLAG(GetFeatureName(enum_val)); 90 | } 91 | return ret; 92 | } 93 | #endif 94 | 95 | NAN_METHOD(GetCPUInfo) { 96 | const auto ret = Nan::New(); 97 | #if defined(CPU_FEATURES_ARCH_X86) 98 | const X86Info details = GetX86Info(); 99 | SET_STR("arch", "x86"); 100 | SET_STR("brand", details.brand_string); 101 | SET_NUM("family", details.family); 102 | SET_NUM("model", details.model); 103 | SET_NUM("stepping", details.stepping); 104 | SET_STR("uarch", 105 | GetX86MicroarchitectureName(GetX86Microarchitecture(&details))); 106 | SET_VAL("flags", GenerateFlags(&details.features)); 107 | #elif defined(CPU_FEATURES_ARCH_ARM) 108 | const ArmInfo details = GetArmInfo(); 109 | SET_STR("arch", "arm"); 110 | SET_NUM("implementer", details.implementer); 111 | SET_NUM("architecture", details.architecture); 112 | SET_NUM("variant", details.variant); 113 | SET_NUM("part", details.part); 114 | SET_NUM("revision", details.revision); 115 | SET_VAL("flags", GenerateFlags(&details.features)); 116 | #elif defined(CPU_FEATURES_ARCH_AARCH64) 117 | const Aarch64Info details = GetAarch64Info(); 118 | SET_STR("arch", "aarch64"); 119 | SET_NUM("implementer", details.implementer); 120 | SET_NUM("variant", details.variant); 121 | SET_NUM("part", details.part); 122 | SET_NUM("revision", details.revision); 123 | SET_VAL("flags", GenerateFlags(&details.features)); 124 | #elif defined(CPU_FEATURES_ARCH_MIPS) 125 | const MipsInfo details = GetMipsInfo(); 126 | SET_STR("arch", "mips"); 127 | SET_VAL("flags", GenerateFlags(&details.features)); 128 | #elif defined(CPU_FEATURES_ARCH_PPC) 129 | const PPCInfo details = GetPPCInfo(); 130 | const PPCPlatformStrings strings = GetPPCPlatformStrings(); 131 | SET_STR("arch", "ppc"); 132 | SET_STR("platform", strings.platform); 133 | SET_STR("model", strings.model); 134 | SET_STR("machine", strings.machine); 135 | SET_STR("cpu", strings.cpu); 136 | SET_STR("instruction set", strings.type.platform); 137 | SET_STR("microarchitecture", strings.type.base_platform); 138 | SET_VAL("flags", GenerateFlags(&details.features)); 139 | #else 140 | SET_STR("arch", "unknown"); 141 | SET_VAL("flags", Nan::New()); 142 | #endif 143 | info.GetReturnValue().Set(ret); 144 | } 145 | 146 | NAN_MODULE_INIT(init) { 147 | Nan::Set(target, Nan::New("getCPUInfo").ToLocalChecked(), 148 | Nan::GetFunction(Nan::New(GetCPUInfo)).ToLocalChecked()); 149 | } 150 | 151 | NODE_MODULE(cpufeatures, init) 152 | -------------------------------------------------------------------------------- /test/test.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const assert = require('assert'); 4 | 5 | const info = require('../lib/index.js')(); 6 | 7 | console.log(info); 8 | assert(typeof info === 'object' && info !== null); 9 | assert(typeof info.arch === 'string' && info.arch); 10 | assert(typeof info.flags === 'object' && info.flags !== null); 11 | if (process.platform !== 'darwin' && process.arch !== 'arm64') 12 | assert(Object.keys(info).length > 2); // Assume we are on a known platform 13 | --------------------------------------------------------------------------------