All Projects → WojciechMula → ternary-logic

WojciechMula / ternary-logic

Licence: other
Support for ternary logic in SSE, XOP, AVX2 and x86 programs

Programming Languages

C++
36643 projects - #6 most used programming language
python
139335 projects - #7 most used programming language
Makefile
30231 projects

Projects that are alternatives of or similar to ternary-logic

Vc
SIMD Vector Classes for C++
Stars: ✭ 985 (+4590.48%)
Mutual labels:  avx, sse, simd, avx2, avx512
Simd
C++ image processing and machine learning library with using of SIMD: SSE, SSE2, SSE3, SSSE3, SSE4.1, SSE4.2, AVX, AVX2, AVX-512, VMX(Altivec) and VSX(Power7), NEON for ARM.
Stars: ✭ 1,263 (+5914.29%)
Mutual labels:  avx, sse, simd, avx2, avx512
Quadray Engine
Realtime raytracer using SIMD on ARM, MIPS, PPC and x86
Stars: ✭ 13 (-38.1%)
Mutual labels:  avx, sse, simd, avx2, avx512
Libxsmm
Library for specialized dense and sparse matrix operations, and deep learning primitives.
Stars: ✭ 518 (+2366.67%)
Mutual labels:  avx, sse, simd, avx2, avx512
Unisimd Assembler
SIMD macro assembler unified for ARM, MIPS, PPC and x86
Stars: ✭ 63 (+200%)
Mutual labels:  avx, sse, simd, avx2, avx512
Boost.simd
Boost SIMD
Stars: ✭ 238 (+1033.33%)
Mutual labels:  avx, sse, simd, avx2, avx512
Simde
Implementations of SIMD instruction sets for systems which don't natively support them.
Stars: ✭ 1,012 (+4719.05%)
Mutual labels:  avx, sse, simd, avx2, avx512
Corrfunc
⚡️⚡️⚡️Blazing fast correlation functions on the CPU.
Stars: ✭ 114 (+442.86%)
Mutual labels:  avx, simd, avx2, avx512
Libsimdpp
Portable header-only C++ low level SIMD library
Stars: ✭ 914 (+4252.38%)
Mutual labels:  sse, simd, avx2, avx512
Xsimd
C++ wrappers for SIMD intrinsics and parallelized, optimized mathematical functions (SSE, AVX, NEON, AVX512)
Stars: ✭ 964 (+4490.48%)
Mutual labels:  avx, sse, simd, avx512
Base64simd
Base64 coding and decoding with SIMD instructions (SSE/AVX2/AVX512F/AVX512BW/AVX512VBMI/ARM Neon)
Stars: ✭ 115 (+447.62%)
Mutual labels:  sse, simd, avx2, avx512
Directxmath
DirectXMath is an all inline SIMD C++ linear algebra library for use in games and graphics apps
Stars: ✭ 859 (+3990.48%)
Mutual labels:  avx, sse, simd, avx2
simd-byte-lookup
SIMDized check which bytes are in a set
Stars: ✭ 23 (+9.52%)
Mutual labels:  sse, simd, avx2, avx512
Std Simd
std::experimental::simd for GCC [ISO/IEC TS 19570:2018]
Stars: ✭ 275 (+1209.52%)
Mutual labels:  avx, sse, simd, avx512
Umesimd
UME::SIMD A library for explicit simd vectorization.
Stars: ✭ 66 (+214.29%)
Mutual labels:  avx, simd, avx2, avx512
cpuwhat
Nim utilities for advanced CPU operations: CPU identification, ISA extension detection, bindings to assorted intrinsics
Stars: ✭ 25 (+19.05%)
Mutual labels:  avx, sse, simd, avx2
Nsimd
Agenium Scale vectorization library for CPUs and GPUs
Stars: ✭ 138 (+557.14%)
Mutual labels:  avx, simd, avx2, avx512
Kfr
Fast, modern C++ DSP framework, FFT, Sample Rate Conversion, FIR/IIR/Biquad Filters (SSE, AVX, AVX-512, ARM NEON)
Stars: ✭ 985 (+4590.48%)
Mutual labels:  avx, simd, avx512
Osaca
Open Source Architecture Code Analyzer
Stars: ✭ 162 (+671.43%)
Mutual labels:  avx, avx2, avx512
Sleef
SIMD Library for Evaluating Elementary Functions, vectorized libm and DFT
Stars: ✭ 353 (+1580.95%)
Mutual labels:  avx, simd, avx512

Ternary functions for SSE and AVX2

Introduction

AVX512F introduced instruction vpternlog (intrinsic _mm512_ternarylogic_epi{32,64}), which evaluates a three-argument boolean function for each bit of operands. The function is given as an integer number from 0 to 255.

This repository contains a kind of library which allows a programmer to use ternary functions in SSE, XOP, AVX2 and x86 in similar manner, by choosing the function by its number.

In native AVX512F code you would write:

// 0x96 = A xor B xor C
const __m512i res = _mm512_ternarylogic_epi32(A, B, C, 0x96);

With help of the library you can write an AVX2 program:

const __m256i res = ternarylogic::avx2::ternary<0x96>(A, B, C);

or a SSE program:

const __m128i res = ternarylogic::sse::ternary<0x96>(A, B, C);

Details

The function number comes from the result column of the function's truth table. The number is formed from bits a, b, ... h. You can find more details and examples in my article.

A B C function
0 0 0 a
0 0 1 b
0 1 0 c
0 1 1 d
1 0 0 e
1 0 1 f
1 1 0 g
1 1 1 h

Intel has published list of all functions in form of logical expression in their monumental document "Intel® 64 and IA-32 Architectures Software Developer’s Manual Volume 2 (2A, 2B, 2C & 2D): Instruction Set Reference, A-Z".

I extracted these functions and created application which generates SSE and AVX2 code. List of function is in the file py/data/intel.txt, I also put there more details. Later I manually optimized some of these function. And in the end I developed a program which found many better representations of functions for both Intel and AMD flavours of SIMD ISA.

Usage

You need python and make.

Type make, then following files will be generated:

  • ternary_sse.cpp,
  • ternary_avx2.cpp,
  • ternary_avx512.cpp (use only two-argument logic instructions),
  • ternary_xop.cpp,
  • ternary_x86_32.cpp,
  • ternary_x86_64.cpp.

You can include them directly into your application.

Programs validate_sse, validate_avx2 and validate_xop test if all generated functions are correct.

See also

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].