Mercurial > vec
comparison src/impl/x86/sse3.c @ 28:c6c99ab1088a
*: add min/max functions and a big big refactor (again)
agh, this time I added a few more implementations (and generally
made the code just a little faster...)
author | Paper <paper@tflc.us> |
---|---|
date | Thu, 24 Apr 2025 00:54:02 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
27:d00b95f95dd1 | 28:c6c99ab1088a |
---|---|
1 /** | |
2 * vec - a tiny SIMD vector library in C99 | |
3 * | |
4 * Copyright (c) 2024 Paper | |
5 * | |
6 * Permission is hereby granted, free of charge, to any person obtaining a copy | |
7 * of this software and associated documentation files (the "Software"), to deal | |
8 * in the Software without restriction, including without limitation the rights | |
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
10 * copies of the Software, and to permit persons to whom the Software is | |
11 * furnished to do so, subject to the following conditions: | |
12 * | |
13 * The above copyright notice and this permission notice shall be included in all | |
14 * copies or substantial portions of the Software. | |
15 * | |
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
22 * SOFTWARE. | |
23 **/ | |
24 | |
25 #include "vec/impl/x86/sse3.h" | |
26 | |
27 #include <pmmintrin.h> | |
28 | |
29 /* SSE3 has a slightly more optimized load function */ | |
30 | |
31 #define VEC_SSE2_DEFINE_OPERATIONS_SIGN(sign, bits, size) \ | |
32 union v##sign##int##bits##x##size##_impl_data { \ | |
33 v##sign##int##bits##x##size vec; \ | |
34 __m128i sse; \ | |
35 }; \ | |
36 \ | |
37 VEC_STATIC_ASSERT(VEC_ALIGNOF(__m128i) <= VEC_ALIGNOF(v##sign##int##bits##x##size), "vec: v" #sign "int" #bits "x" #size " alignment needs to be expanded to fit intrinsic type size"); \ | |
38 VEC_STATIC_ASSERT(sizeof(__m128i) <= sizeof(v##sign##int##bits##x##size), "vec: v" #sign "int" #bits "x" #size " needs to be expanded to fit intrinsic type size"); \ | |
39 \ | |
40 VEC_FUNC_IMPL v##sign##int##bits##x##size v##sign##int##bits##x##size##_sse2_load(const vec_##sign##int##bits in[size]) \ | |
41 { \ | |
42 union v##sign##int##bits##x##size##_impl_data vec; \ | |
43 vec.sse = _mm_lddqu_si128((const __m128i *)in); \ | |
44 return vec.vec; \ | |
45 } \ | |
46 \ | |
47 const v##sign##int##bits##x##size##_impl v##sign##int##bits##x##size##_impl_sse3 = { \ | |
48 .load = v##sign##int##bits##x##size##_sse2_load, \ | |
49 }; | |
50 | |
51 #define VEC_SSE2_DEFINE_OPERATIONS(bits, size) \ | |
52 VEC_SSE2_DEFINE_OPERATIONS_SIGN(u, bits, size) \ | |
53 VEC_SSE2_DEFINE_OPERATIONS_SIGN( , bits, size) | |
54 | |
55 VEC_SSE2_DEFINE_OPERATIONS(8, 16) | |
56 VEC_SSE2_DEFINE_OPERATIONS(16, 8) | |
57 VEC_SSE2_DEFINE_OPERATIONS(32, 4) | |
58 VEC_SSE2_DEFINE_OPERATIONS(64, 2) |