Skip to content

Commit

Permalink
Merge branch 'release/0.2.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
HenrikBengtsson committed May 25, 2023
2 parents 726cc1a + 9e6b2b4 commit e608fd4
Show file tree
Hide file tree
Showing 7 changed files with 480 additions and 39 deletions.
1 change: 1 addition & 0 deletions .github/workflows/shellcheck.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,4 @@ jobs:
- name: ShellCheck
run: |
./shellcheck -- x86-64-level
./shellcheck -- tests/x86-64-level.sh
24 changes: 24 additions & 0 deletions .github/workflows/unit_tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
on: [push, pull_request]

name: unit_tests

jobs:
checks:
if: "! contains(github.event.head_commit.message, '[ci skip]')"

timeout-minutes: 2

runs-on: ubuntu-22.04

name: unit_tests

strategy:
fail-fast: false

steps:
- name: Checkout git repository
uses: actions/checkout@v3

- name: Run unit tests
run: |
PATH=.:$PATH tests/x86-64-level.sh
8 changes: 8 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
all: shellcheck check

shellcheck:
shellcheck x86-64-level
shellcheck tests/x86-64-level.sh

check:
@PATH=.:${PATH} tests/x86-64-level.sh
19 changes: 19 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
# Version 0.2.2 [2023-05-25]

## New Features

* Now `x86-64-level` asserts that the input CPU flags are of the
correct format, which is assumed to be only lower-case letters,
digits, and underscores.

## Bug Fixes

* Calling `x86-64-level --assert=""` would produce error message
`merror: command not found` and not the intended `ERROR: Option
'--assert' must not be empty`.

## Miscellaneous

* Add unit tests.


# Version 0.2.1 [2023-01-18]

* Now `--assert` reports also on the CPU name.
Expand Down
35 changes: 22 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
[![shellcheck](https://github.com/HenrikBengtsson/x86-64-level/actions/workflows/shellcheck.yml/badge.svg)](https://github.com/HenrikBengtsson/x86-64-level/actions/workflows/shellcheck.yml)
[![unit_tests](https://github.com/HenrikBengtsson/x86-64-level/actions/workflows/unit_tests.yml/badge.svg)](https://github.com/HenrikBengtsson/x86-64-level/actions/workflows/unit_tests.yml)

# x86-64-level - Get the x86-64 Microarchitecture Level on the Current Machine

TL;DR: The `x86-64-level` tool identifies the current CPU supports
TL;DR: The `x86-64-level` tool identifies if the current CPU supports
x86-64-v1, x86-64-v2, x86-64-v3, or x86-64-v4, e.g.

```sh
Expand All @@ -14,7 +15,7 @@ $ x86-64-level
# Background

**x86-64** is a 64-bit version of the x86 CPU instruction set
supported by AMD and Intel CPUs among others. Since the first
supported by AMD and Intel CPUs, among others. Since the first
generations of CPUs, more low-level CPU features have been added over
the years. The x86-64 CPU features can be grouped into four [CPU
microarchitecture levels]:
Expand All @@ -28,8 +29,9 @@ microarchitecture levels]:

The x86-64-v1 level is the same as the original, baseline x86-64
level. These levels are subsets of each other, i.e. x86-64-v1 ⊂
x86-64-v2 ⊂ x86-64-v3 ⊂ x86-64-v4.

x86-64-v2 ⊂ x86-64-v3 ⊂ x86-64-v4. For a CPU to support a level, it
must support _all_ CPU features of that version level, and, because
they are subsets of each other, all those of the lower versions.

Software can be written so that they use the most powerful set of CPU
features available. This optimization happens at compile time and
Expand All @@ -44,12 +46,18 @@ might get something like:
address 0x2b3a8b234ccd, cause 'illegal operand'
```

or

```
Illegal instruction (core dumped)
```

This is because the older CPU does not understand one of the CPU
instructions ("operands"). Note that the software might not crash each
time. It will only do so if it reach the part of the code that uses
the never CPU instructions.
instructions ("operands"). Note that the software might not crash
each time. It will only do so if it reaches the part of the code that
uses a CPU instruction that is not recognized by the current CPU.

In contrast, if we compile the software on the older x86-64-v3
In contrast, if we compile the software towards the older x86-64-v3
machine, the produced binary will only use x86-64-v3 instructions and
will therefor also run on the newer x86-64-v4 machine.

Expand All @@ -65,8 +73,8 @@ illegal operation' problem.

## Finding CPU's x86-64 level

This tool, `x86-64-level`, allows you to query the which x86-64 level
the CPU on current machine supports. For example,
This tool, `x86-64-level`, allows you to query which x86-64 level the
CPU on current machine supports. For example,

```sh
$ x86-64-level
Expand All @@ -81,12 +89,13 @@ $ echo "x86-64-v${level}"
x86-64-v3
```

If you want to know an "explanation", specify option `--verbose`, e.g.
If you want to get an explanation for the identified level, specify
option `--verbose`, e.g.

```sh
$ x86-64-level --verbose
Identified x86-64-v3, because x86-64-v4 requires 'avx512f', which
this CPU [Intel(R) Core(TM) i7-8650U CPU @ 1.90GHz] does not support
is not supported by this CPU [Intel(R) Core(TM) i7-8650U CPU @ 1.90GHz]
3
```

Expand Down Expand Up @@ -123,7 +132,7 @@ x86-64-level --assert=4 || exit 1

This will output that error message (to the standard error) and exit
the script with exit code 1, if, and only if, the current machine does
not support x86-64-v4. In all other cases, it continue silently.
not support x86-64-v4. In all other cases, it continues silently.



Expand Down

0 comments on commit e608fd4

Please sign in to comment.