ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
electrokinetics/generated_kernels/myintrin.h
Go to the documentation of this file.
1/*
2Copyright 2019-2023, Michael Kuron.
3
4Redistribution and use in source and binary forms, with or without
5modification, are permitted provided that the following conditions are
6met:
7
8* Redistributions of source code must retain the above copyright
9 notice, this list of conditions, and the following disclaimer.
10
11* Redistributions in binary form must reproduce the above copyright
12 notice, this list of conditions, and the following disclaimer in the
13 documentation and/or other materials provided with the distribution.
14
15* Neither the name of the copyright holder nor the names of its
16 contributors may be used to endorse or promote products derived from
17 this software without specific prior written permission.
18
19THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30*/
31
32// kernel generated with pystencils v1.4, lbmpy v1.4+1.g3fc1c8f.dirty, sympy
33// v1.12.1, lbmpy_walberla/pystencils_walberla from waLBerla commit
34// 007e77e077ad9d22b5eed6f3d3118240993e553c
35
36/**
37 * @file
38 * Philox counter-based RNG utility functions.
39 * Adapted from the pystencils source file
40 * https://i10git.cs.fau.de/pycodegen/pystencils/-/blob/ca4890a67757f066fc310b94b4b17b9f1b497ac2/src/pystencils/include/myintrin.h
41 */
42
43#pragma once
44
45#if defined(__SSE2__) || (defined(_MSC_VER) && !defined(_M_ARM64))
46QUALIFIERS __m128 _my_cvtepu32_ps(const __m128i v) {
47#if defined(__AVX512VL__) || defined(__AVX10_1__)
48 return _mm_cvtepu32_ps(v);
49#else
50 __m128i v2 = _mm_srli_epi32(v, 1);
51 __m128i v1 = _mm_and_si128(v, _mm_set1_epi32(1));
52 __m128 v2f = _mm_cvtepi32_ps(v2);
53 __m128 v1f = _mm_cvtepi32_ps(v1);
54 return _mm_add_ps(_mm_add_ps(v2f, v2f), v1f);
55#endif
56}
57#endif
58
59#if defined(__SSE4_1__) || (defined(_MSC_VER) && !defined(_M_ARM64))
60#if !defined(__AVX512VL__) && !defined(__AVX10_1__) && defined(__GNUC__) && \
61 __GNUC__ >= 5 && !defined(__clang__) && !defined(__NVCOMPILER)
62__attribute__((optimize("no-associative-math")))
63#endif
64QUALIFIERS __m128d _my_cvtepu64_pd(const __m128i x) {
65#if defined(__AVX512VL__) || defined(__AVX10_1__)
66 return _mm_cvtepu64_pd(x);
67#elif defined(__clang__)
68 return __builtin_convertvector(
69 (uint64_t __attribute__((__vector_size__(16))))x, __m128d);
70#else
71 __m128i xH = _mm_srli_epi64(x, 32);
72 xH = _mm_or_si128(
73 xH, _mm_castpd_si128(_mm_set1_pd(19342813113834066795298816.))); // 2^84
74 __m128i xL = _mm_blend_epi16(
75 x, _mm_castpd_si128(_mm_set1_pd(0x0010000000000000)), 0xcc); // 2^52
76 __m128d f =
77 _mm_sub_pd(_mm_castsi128_pd(xH),
78 _mm_set1_pd(19342813118337666422669312.)); // 2^84 + 2^52
79 return _mm_add_pd(f, _mm_castsi128_pd(xL));
80#endif
81}
82#endif
83
84#ifdef __AVX2__
85QUALIFIERS __m256i _my256_set_m128i(__m128i hi, __m128i lo) {
86#if (!defined(__GNUC__) || __GNUC__ >= 8) || defined(__clang__)
87 return _mm256_set_m128i(hi, lo);
88#else
89 return _mm256_insertf128_si256(_mm256_castsi128_si256(lo), hi, 1);
90#endif
91}
92
93QUALIFIERS __m256d _my256_set_m128d(__m128d hi, __m128d lo) {
94#if (!defined(__GNUC__) || __GNUC__ >= 8) || defined(__clang__)
95 return _mm256_set_m128d(hi, lo);
96#else
97 return _mm256_insertf128_pd(_mm256_castpd128_pd256(lo), hi, 1);
98#endif
99}
100
101QUALIFIERS __m256 _my256_cvtepu32_ps(const __m256i v) {
102#if defined(__AVX512VL__) || defined(__AVX10_1__)
103 return _mm256_cvtepu32_ps(v);
104#else
105 __m256i v2 = _mm256_srli_epi32(v, 1);
106 __m256i v1 = _mm256_and_si256(v, _mm256_set1_epi32(1));
107 __m256 v2f = _mm256_cvtepi32_ps(v2);
108 __m256 v1f = _mm256_cvtepi32_ps(v1);
109 return _mm256_add_ps(_mm256_add_ps(v2f, v2f), v1f);
110#endif
111}
112
113#if !defined(__AVX512VL__) && !defined(__AVX10_1__) && defined(__GNUC__) && \
114 __GNUC__ >= 5 && !defined(__clang__) && !defined(__NVCOMPILER)
115__attribute__((optimize("no-associative-math")))
116#endif
117QUALIFIERS __m256d _my256_cvtepu64_pd(const __m256i x) {
118#if defined(__AVX512VL__) || defined(__AVX10_1__)
119 return _mm256_cvtepu64_pd(x);
120#elif defined(__clang__)
121 return __builtin_convertvector(
122 (uint64_t __attribute__((__vector_size__(32))))x, __m256d);
123#else
124 __m256i xH = _mm256_srli_epi64(x, 32);
125 xH = _mm256_or_si256(xH, _mm256_castpd_si256(_mm256_set1_pd(
126 19342813113834066795298816.))); // 2^84
127 __m256i xL = _mm256_blend_epi16(
128 x, _mm256_castpd_si256(_mm256_set1_pd(0x0010000000000000)),
129 0xcc); // 2^52
130 __m256d f = _mm256_sub_pd(
131 _mm256_castsi256_pd(xH),
132 _mm256_set1_pd(19342813118337666422669312.)); // 2^84 + 2^52
133 return _mm256_add_pd(f, _mm256_castsi256_pd(xL));
134#endif
135}
136#endif
137
138#if defined(__AVX512F__) || defined(__AVX10_512BIT__)
139QUALIFIERS __m512i _my512_set_m128i(__m128i d, __m128i c, __m128i b,
140 __m128i a) {
141 return _mm512_inserti32x4(
142 _mm512_inserti32x4(_mm512_inserti32x4(_mm512_castsi128_si512(a), b, 1), c,
143 2),
144 d, 3);
145}
146
147QUALIFIERS __m512d _my512_set_m256d(__m256d b, __m256d a) {
148 return _mm512_insertf64x4(_mm512_castpd256_pd512(a), b, 1);
149}
150#endif