zerotest | Lazy guy 's testing tool | Mock library
kandi X-RAY | zerotest Summary
kandi X-RAY | zerotest Summary
Zerotest makes it easy to test API server, start a micro proxy, send requests, and generate test code by these behaviours.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of zerotest
zerotest Key Features
zerotest Examples and Code Snippets
Community Discussions
Trending Discussions on zerotest
QUESTION
- What is the purpose or intention of a MoveMask?
- What's the best place to learn how to use x86/x86-64 assembly/SSE/AVX?
- Could I have written my code more efficiently?
I have an function written in F# for .NET that uses SSE2. I've written the same thing using AVX2 but the underlying question is the same. What is the intended purpose of a MoveMask
? I know that it works for my purposes, I want to know why.
I am iterating through two 64-bit float arrays, a
and b
, testing that all of their values match. I am using the CompareEqual
method (which I believe is wrapping a call to __m128d _mm_cmpeq_pd
) to compare several values at a time. I then compare that result with a Vector128
of 0.0
64-bit float. My reasoning is that the result of CompareEqual
will give a 0.0
value in the cases where the values don't match. Up to this point, it makes sense.
I then use the Sse2.MoveMask
method on the result of the comparison with the zero vector. I've previously worked on using SSE
and AVX
for matching and I saw examples of people using MoveMask
for the purpose for testing for non-zero values. I believe this method is using the int _mm_movemask_epi8
Intel intrinsic. I have included the F# code and the assembly that is JITed.
Is this really the intention of a MoveMask
or is it just a happy coincidence it works for these purposes. I know my code works, I want to know WHY it works.
ANSWER
Answered 2021-Nov-08 at 05:02MoveMask
just extracts the high bit of each element into an integer bitmap. You have 3 element-size options: movmskpd
(64-bit), movmskps
(32-bit), and pmovmskb
(8-bit).
This works well with SIMD compares, which produce an output that has all-zero when the predicate is false, all-one bits in elements where the predicate is true. All-ones is a bit-pattern for -QNaN
if interpreted as an IEEE-FP floating-point value, but normally you don't do that. Instead movemask, or AND, (or AND / ANDN / OR or _mm_blend_pd
) or things like that with a compare result.
movemask(v) != 0
, movemask(v) == 0x3
, or movemask(v) == 0
is how you check conditions like at least one element in a compare matched, or all matched, or none matched, respectively, where v
is the result of _mm_cmpeq_pd
or whatever. (Or just to extract signs directly without a compare).
For other element sizes, 0xf
or 0xffff
to match all four or all 16 bits. Or for AVX 256-bit vectors, twice as many bits, up to filling a whole 32-bit integer with vpmovmskb eax, ymm0
.
What you're doing is really weird, using a 0.0 / NaN compare result as the input to another compare with vcmpeqpd xmm1, xmm1, xmm2
/ vcmpeqpd xmm1, xmm1, xmm0
. For the 2nd comparison, that can only be true for elements that are == 0.0
(i.e. +-0.0), because x == NaN
is false for every x
.
If the second vector is a constant zero (let zeroTest = Sse2.CompareEqual (comparison, zeroVector)
, that's pointless, you're just inverting the compare result which you could have done by checking a different integer condition or against a different constant, not doing runtime comparisons. (0.0 == 0.0
is true, producing an all-ones output, 0.0 == -NaN
is false, producing an all-zero output.)
To learn more about intrinsics and SIMD, see for example Agner Fog's optimization guide; his asm guide has a chapter on SIMD. Also, his VectorClass library for C++ has some useful wrappers, and for learning purposes seeing how those wrapper functions implement some basic things could be useful.
To learn what things actually do, see Intel's intrinsics guide. You can search by asm instruction or C++ intrinsic name.
I think MS has docs for their C# System.Runtime.Intrinsics.X86, and I assume F# uses the same intrinsics, but I don't use either language myself.
Related re: comparisons:
Get the last line separator - pcmpeqb -> pmovmskb ->
bsr
to find the position of the last match element in a vector of compare results. Bit-scan reverse on the compare mask. Often you want to scan forward to find the first match (or invert and find first mismatch, like formemcmp
). e.g. Compare 16 byte strings with SSE
Or popcount them if you're counting occurrences by matching against a loop-invariant vector of a broadcasted character: How can I count the occurrence of a byte in array using SIMD? - instead of movemask, use the compare result as integer 0 / -1. SIMD subtract from a vector accumulator in the inner loop, then horizontal sum of integer elements in an outer loop.SIMD instructions for floating point equality comparison (with NaN == NaN) - useful exercise in understanding how NaNs work.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install zerotest
Start a local proxy to capture http traffic zerotest server https://api.github.com -f octocat.data. Make few requests curl -i http://localhost:7000/users/octocat. Press C-c to exit local proxy. Generate test code zerotest generate octocat.data --ignore-all-headers > test_octocat.py. Type py.test test_octocat.py to run test.
Start a local proxy to capture http traffic zerotest server https://api.github.com -f octocat.data
Make few requests curl -i http://localhost:7000/users/octocat
Press C-c to exit local proxy
Generate test code zerotest generate octocat.data --ignore-all-headers > test_octocat.py
Type py.test test_octocat.py to run test
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page