https://github.com/wojciechmula/ternarylogiccli
CLI utilty to work out proper constants for vpternlogic instruction
https://github.com/wojciechmula/ternarylogiccli
assembly avx512 cli tools
Last synced: 3 months ago
JSON representation
CLI utilty to work out proper constants for vpternlogic instruction
- Host: GitHub
- URL: https://github.com/wojciechmula/ternarylogiccli
- Owner: WojciechMula
- Created: 2019-11-25T16:41:44.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2023-01-22T14:02:32.000Z (over 2 years ago)
- Last Synced: 2025-02-27T03:11:18.324Z (4 months ago)
- Topics: assembly, avx512, cli, tools
- Language: Python
- Size: 4.88 KB
- Stars: 12
- Watchers: 5
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.rst
Awesome Lists containing this project
README
================================================================================
Ternary logic CLI
================================================================================AVX512__ has got the instruction ``VPTERN`` (``_mm512_ternarylogic_epi{32,64}``
which evaluates arbitrary `three-argument boolean`__ function. A programmer
gives three input argument and an 8-bit constant which defines the function.This CLI program lets you provide a function in textual form and obtain
appropriate constant. C++ programmers may use `contsexpr-based library`__
by **Samuel Neves**.__ https://en.wikipedia.org/wiki/AVX-512
__ http://0x80.pl/articles/avx512-ternary-functions.html
__ https://github.com/sneves/avx512-utilsExpressions may contain parentheses and operators ``and``/``&``, ``or``/``|``,
``xor``/``^``, ``not``/``~``. There might be up to three variables, their
names are derived from the expression. By default, the first variable that
appears in an expression becomes the most significant; the order of variables
can be explicitly set with ``--vars`` argument (see example 5).See also a `programming library `_
that gives similar API, but works with SSE, AVX, AVX2 and x86 instruction sets.Example 1
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Tautology::
$ ./ternarylogiccli.py "x & ~x"
# | x | - | - | x & ~x
---+---+---+---+--------
0 | 0 | 0 | 0 | 0
1 | 0 | 0 | 1 | 0
2 | 0 | 1 | 0 | 0
3 | 0 | 1 | 1 | 0
4 | 1 | 0 | 0 | 0
5 | 1 | 0 | 1 | 0
6 | 1 | 1 | 0 | 0
7 | 1 | 1 | 1 | 0_mm512_ternarylogic_epi32(x, -, -, 0x00)
Example 2
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Condition expression::
$ ./ternarylogiccli.py "(cond and true_val) or (~cond and false_val)"
# | cond | true_val | false_val | (cond & true_val) | (~cond & false_val)
---+------+----------+-----------+-----------------------------------------
0 | 0 | 0 | 0 | 0
1 | 0 | 0 | 1 | 1
2 | 0 | 1 | 0 | 0
3 | 0 | 1 | 1 | 1
4 | 1 | 0 | 0 | 0
5 | 1 | 0 | 1 | 0
6 | 1 | 1 | 0 | 1
7 | 1 | 1 | 1 | 1_mm512_ternarylogic_epi32(cond, true_val, false_val, 0xca)
Example 3
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~::
$ ./ternarylogiccli.py "a and b or c"
# | a | b | c | a & b | c
---+---+---+---+-----------
0 | 0 | 0 | 0 | 0
1 | 0 | 0 | 1 | 1
2 | 0 | 1 | 0 | 0
3 | 0 | 1 | 1 | 1
4 | 1 | 0 | 0 | 0
5 | 1 | 0 | 1 | 1
6 | 1 | 1 | 0 | 1
7 | 1 | 1 | 1 | 1_mm512_ternarylogic_epi32(a, b, c, 0xea)
Example 4
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~::
./ternarylogiccli.py "x ^ (y & ~z)"
# | x | y | z | x ^ (y & ~z)
---+---+---+---+--------------
0 | 0 | 0 | 0 | 0
1 | 0 | 0 | 1 | 0
2 | 0 | 1 | 0 | 1
3 | 0 | 1 | 1 | 0
4 | 1 | 0 | 0 | 1
5 | 1 | 0 | 1 | 1
6 | 1 | 1 | 0 | 0
7 | 1 | 1 | 1 | 1_mm512_ternarylogic_epi32(x, y, z, 0xb4)
Example 5 --- variables order
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~::
$ ternary "a or b and c" --vars b,c,a
# | b | c | a | a | b & c
---+---+---+---+-----------
0 | 0 | 0 | 0 | 0
1 | 0 | 0 | 1 | 1
2 | 0 | 1 | 0 | 0
3 | 0 | 1 | 1 | 1
4 | 1 | 0 | 0 | 0
5 | 1 | 0 | 1 | 1
6 | 1 | 1 | 0 | 1
7 | 1 | 1 | 1 | 1_mm512_ternarylogic_epi32(b, c, a, 0xea)
$ ternary "a or b and c" --vars c,a,b
# | c | a | b | a | b & c
---+---+---+---+-----------
0 | 0 | 0 | 0 | 0
1 | 0 | 0 | 1 | 0
2 | 0 | 1 | 0 | 1
3 | 0 | 1 | 1 | 1
4 | 1 | 0 | 0 | 0
5 | 1 | 0 | 1 | 1
6 | 1 | 1 | 0 | 1
7 | 1 | 1 | 1 | 1_mm512_ternarylogic_epi32(c, a, b, 0xec)
$ ternary "a or b and c" --vars a,c,b
# | a | c | b | a | b & c
---+---+---+---+-----------
0 | 0 | 0 | 0 | 0
1 | 0 | 0 | 1 | 0
2 | 0 | 1 | 0 | 0
3 | 0 | 1 | 1 | 1
4 | 1 | 0 | 0 | 1
5 | 1 | 0 | 1 | 1
6 | 1 | 1 | 0 | 1
7 | 1 | 1 | 1 | 1_mm512_ternarylogic_epi32(a, c, b, 0xf8)