Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
simde
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
simde
Commits
5e632b09
Commit
5e632b09
authored
May 23, 2023
by
Michael R. Crusoe
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
avx512: naive implementation of fpclass
parent
b71b58c2
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
166 additions
and
0 deletions
+166
-0
simde-math.h
simde-math.h
+85
-0
x86/avx512.h
x86/avx512.h
+1
-0
x86/avx512/fpclass.h
x86/avx512/fpclass.h
+80
-0
No files found.
simde-math.h
View file @
5e632b09
...
@@ -434,6 +434,91 @@ simde_math_fpclassify(double v) {
...
@@ -434,6 +434,91 @@ simde_math_fpclassify(double v) {
#endif
#endif
}
}
#define SIMDE_MATH_FP_QNAN 0x01
#define SIMDE_MATH_FP_PZERO 0x02
#define SIMDE_MATH_FP_NZERO 0x04
#define SIMDE_MATH_FP_PINF 0x08
#define SIMDE_MATH_FP_NINF 0x10
#define SIMDE_MATH_FP_DENORMAL 0x20
#define SIMDE_MATH_FP_NEGATIVE 0x40
#define SIMDE_MATH_FP_SNAN 0x80
static
HEDLEY_INLINE
int8_t
simde_math_fpclassf
(
float
v
,
const
int
imm8
)
{
union
{
float
f
;
uint32_t
u
;
}
fu
;
fu
.
f
=
v
;
uint32_t
bits
=
fu
.
u
;
int8_t
NegNum
=
(
bits
>>
31
)
&
1
;
uint32_t
const
ExpMask
=
0x3F800000
;
// [30:23]
uint32_t
const
MantMask
=
0x007FFFFF
;
// [22:0]
int8_t
ExpAllOnes
=
((
bits
&
ExpMask
)
==
ExpMask
);
int8_t
ExpAllZeros
=
((
bits
&
ExpMask
)
==
0
);
int8_t
MantAllZeros
=
((
bits
&
MantMask
)
==
0
);
int8_t
ZeroNumber
=
ExpAllZeros
&&
MantAllZeros
;
int8_t
SignalingBit
=
(
bits
>>
22
)
&
1
;
int8_t
result
=
0
;
int8_t
qNaN_res
=
ExpAllOnes
&&
!
MantAllZeros
&&
SignalingBit
;
int8_t
Pzero_res
=
!
NegNum
&&
ExpAllZeros
&&
MantAllZeros
;
int8_t
Nzero_res
=
NegNum
&&
ExpAllZeros
&&
MantAllZeros
;
int8_t
Pinf_res
=
!
NegNum
&&
ExpAllOnes
&&
MantAllZeros
;
int8_t
Ninf_res
=
NegNum
&&
ExpAllOnes
&&
MantAllZeros
;
int8_t
Denorm_res
=
ExpAllZeros
&&
!
MantAllZeros
;
int8_t
FinNeg_res
=
NegNum
&&
!
ExpAllOnes
&&
!
ZeroNumber
;
int8_t
sNaN_res
=
ExpAllOnes
&&
!
MantAllZeros
&&
!
SignalingBit
;
result
=
((((
imm8
>>
0
)
&
1
)
&&
qNaN_res
)
||
\
(((
imm8
>>
1
)
&
1
)
&&
Pzero_res
)
||
\
(((
imm8
>>
2
)
&
1
)
&&
Nzero_res
)
||
\
(((
imm8
>>
3
)
&
1
)
&&
Pinf_res
)
||
\
(((
imm8
>>
4
)
&
1
)
&&
Ninf_res
)
||
\
(((
imm8
>>
5
)
&
1
)
&&
Denorm_res
)
||
\
(((
imm8
>>
6
)
&
1
)
&&
FinNeg_res
)
||
\
(((
imm8
>>
7
)
&
1
)
&&
sNaN_res
));
return
result
;
}
static
HEDLEY_INLINE
int8_t
simde_math_fpclass
(
double
v
,
const
int
imm8
)
{
union
{
double
d
;
uint64_t
u
;
}
du
;
du
.
d
=
v
;
uint64_t
bits
=
du
.
u
;
int8_t
NegNum
=
(
bits
>>
63
)
&
1
;
uint64_t
const
ExpMask
=
0x3FF0000000000000
;
// [62:52]
uint64_t
const
MantMask
=
0x000FFFFFFFFFFFFF
;
// [51:0]
int8_t
ExpAllOnes
=
((
bits
&
ExpMask
)
==
ExpMask
);
int8_t
ExpAllZeros
=
((
bits
&
ExpMask
)
==
0
);
int8_t
MantAllZeros
=
((
bits
&
MantMask
)
==
0
);
int8_t
ZeroNumber
=
ExpAllZeros
&&
MantAllZeros
;
int8_t
SignalingBit
=
(
bits
>>
51
)
&
1
;
int8_t
result
=
0
;
int8_t
qNaN_res
=
ExpAllOnes
&&
!
MantAllZeros
&&
SignalingBit
;
int8_t
Pzero_res
=
!
NegNum
&&
ExpAllZeros
&&
MantAllZeros
;
int8_t
Nzero_res
=
NegNum
&&
ExpAllZeros
&&
MantAllZeros
;
int8_t
Pinf_res
=
!
NegNum
&&
ExpAllOnes
&&
MantAllZeros
;
int8_t
Ninf_res
=
NegNum
&&
ExpAllOnes
&&
MantAllZeros
;
int8_t
Denorm_res
=
ExpAllZeros
&&
!
MantAllZeros
;
int8_t
FinNeg_res
=
NegNum
&&
!
ExpAllOnes
&&
!
ZeroNumber
;
int8_t
sNaN_res
=
ExpAllOnes
&&
!
MantAllZeros
&&
!
SignalingBit
;
result
=
((((
imm8
>>
0
)
&
1
)
&&
qNaN_res
)
||
\
(((
imm8
>>
1
)
&
1
)
&&
Pzero_res
)
||
\
(((
imm8
>>
2
)
&
1
)
&&
Nzero_res
)
||
\
(((
imm8
>>
3
)
&
1
)
&&
Pinf_res
)
||
\
(((
imm8
>>
4
)
&
1
)
&&
Ninf_res
)
||
\
(((
imm8
>>
5
)
&
1
)
&&
Denorm_res
)
||
\
(((
imm8
>>
6
)
&
1
)
&&
FinNeg_res
)
||
\
(((
imm8
>>
7
)
&
1
)
&&
sNaN_res
));
return
result
;
}
/*** Manipulation functions ***/
/*** Manipulation functions ***/
#if !defined(simde_math_nextafter)
#if !defined(simde_math_nextafter)
...
...
x86/avx512.h
View file @
5e632b09
...
@@ -71,6 +71,7 @@
...
@@ -71,6 +71,7 @@
#include "avx512/fmsub.h"
#include "avx512/fmsub.h"
#include "avx512/fnmadd.h"
#include "avx512/fnmadd.h"
#include "avx512/fnmsub.h"
#include "avx512/fnmsub.h"
#include "avx512/fpclass.h"
#include "avx512/insert.h"
#include "avx512/insert.h"
#include "avx512/kshift.h"
#include "avx512/kshift.h"
#include "avx512/knot.h"
#include "avx512/knot.h"
...
...
x86/avx512/fpclass.h
0 → 100644
View file @
5e632b09
/* SPDX-License-Identifier: MIT
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use, copy,
* modify, merge, publish, distribute, sublicense, and/or sell copies
* of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* Copyright:
* 2023 Michael R. Crusoe <crusoe@debian.org>
*/
#if !defined(SIMDE_X86_AVX512_FPCLASS_H)
#define SIMDE_X86_AVX512_FPCLASS_H
#include "types.h"
HEDLEY_DIAGNOSTIC_PUSH
SIMDE_DISABLE_UNWANTED_DIAGNOSTICS
SIMDE_BEGIN_DECLS_
SIMDE_FUNCTION_ATTRIBUTES
simde__mmask8
simde_mm256_fpclass_ps_mask
(
simde__m256
a
,
int
imm8
)
SIMDE_REQUIRE_CONSTANT_RANGE
(
imm8
,
0
,
0x88
)
{
simde__mmask8
r
=
0
;
simde__m256_private
a_
=
simde__m256_to_private
(
a
);
for
(
size_t
i
=
0
;
i
<
(
sizeof
(
a_
.
f32
)
/
sizeof
(
a_
.
f32
[
0
]))
;
i
++
)
{
r
|=
simde_math_fpclassf
(
a_
.
f32
[
i
],
imm8
)
?
(
UINT8_C
(
1
)
<<
i
)
:
0
;
}
return
r
;
}
#if defined(SIMDE_X86_AVX512DQ_NATIVE) && defined(SIMDE_X86_AVX512VL_NATIVE)
# define simde_mm256_fpclass_ps_mask(a, imm8) _mm256_fpclass_ps_mask((a), (imm8))
#endif
#if defined(SIMDE_X86_AVX512DQ_ENABLE_NATIVE_ALIASES) && defined(SIMDE_X86_AVX512VL_ENABLE_NATIVE_ALIASES)
# undef _mm256_fpclass_ps_mask
# define _mm256_fpclass_ps_mask(a, imm8) simde_mm256_fpclass_ps_mask((a), (imm8))
#endif
SIMDE_FUNCTION_ATTRIBUTES
simde__mmask8
simde_mm512_fpclass_pd_mask
(
simde__m512d
a
,
int
imm8
)
SIMDE_REQUIRE_CONSTANT_RANGE
(
imm8
,
0
,
0x88
)
{
simde__mmask8
r
=
0
;
simde__m512d_private
a_
=
simde__m512d_to_private
(
a
);
for
(
size_t
i
=
0
;
i
<
(
sizeof
(
a_
.
f64
)
/
sizeof
(
a_
.
f64
[
0
]))
;
i
++
)
{
r
|=
simde_math_fpclass
(
a_
.
f64
[
i
],
imm8
)
?
(
UINT8_C
(
1
)
<<
i
)
:
0
;
}
return
r
;
}
#if defined(SIMDE_X86_AVX512DQ_NATIVE)
# define simde_mm512_fpclass_pd_mask(a, imm8) _mm512_fpclass_pd_mask((a), (imm8))
#endif
#if defined(SIMDE_X86_AVX512DQ_ENABLE_NATIVE_ALIASES)
# undef _mm512_fpclass_pd_mask
# define _mm512_fpclass_pd_mask(a, imm8) simde_mm512_fpclass_pd_mask((a), (imm8))
#endif
SIMDE_END_DECLS_
HEDLEY_DIAGNOSTIC_POP
#endif
/* !defined(SIMDE_X86_AVX512_FPCLASS_H) */
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment