Get uint64_t out of __m128 intrinsic? [duplicate] - sse

This question already has answers here:
C++ SSE Intrinsics: Storing results in variables [closed]
(1 answer)
print a __m128i variable
(4 answers)
SSE: Difference between _mm_load/store vs. using direct pointer access
(3 answers)
How to extract bytes from an SSE2 __m128i structure?
(1 answer)
Is `reinterpret_cast`ing between hardware SIMD vector pointer and the corresponding type an undefined behavior?
(2 answers)
Closed 1 year ago.
I can use _mm_set_epi64 to store two uint64_ts into a __m128 intrinsic. But hunting around, I see various ways to get the values back out: There's reinterpret_cast (and it's evil twin C-style casts), it's sibling union { __m128; uint64[2]; }; and memcpy, there's accessing fields of __m128. There's __m128i _mm_load_si128(__m128i *p);, but I'm not seeing a _mm_get_* function. Am I missing something? If there's a _mm_set_epi64 then there must be a non-cast way to get the uint64_ts back out, right? (Otherwise why would they bother providing _mm_set_epi64?)
I see Get member of __m128 by index? but the "correct answer" has a broken link and implies there's a load function, but all the loads I see map __m128 to __m128. Shouldn't there be a void _mm_get_epi64(__m128, uint64_t* outbuf)?

Related

Creating byte buffers in rust [duplicate]

This question already has answers here:
Creating a vector of zeros for a specific size
(4 answers)
Closed 7 years ago.
What is the most efficient way to get access to &mut [u8]? Right now I'm borrowing from a Vec but it would be easier to just allocate the buffer more directly.
The best I can do right now is to preallocate a vector then push out its length but there is no way this is idiomatic.
let mut points_buf : Vec<u8> = Vec::with_capacity(points.len() * point::POINT_SIZE);
for _ in (0..points_buf.capacity()) {
points_buf.push(0);
}
file.read(&mut points_buf[..]).unwrap();
You could just create the vec with a given size directly:
vec![0; num_points]
Or use iterators:
repeat(0).take(num_points).collect::<Vec<_>>()

Table elements executing a function [duplicate]

This question already has answers here:
Search for an item in a Lua list
(12 answers)
Lua find a key from a value
(3 answers)
Closed 9 years ago.
I have this table:
maps = {4707191, 4747722, 1702169, 3994471, 4708958, 4008546, 4323335, 4516043, 4612295, 3469987, 4337892, 238378, 3088188, 329627, 3526384, 433483}
How can I make a script so if 1702169 (for example) is picked from the table, it prints ''That's the number''?
The easiest way to do what (i think) you want is with pairs() function. This is a stateless iterator which you can read more about here: http://www.lua.org/pil/7.3.html
If you simply want to scan through the entire table and see if it contains a value, then you can use this simple code:
local maps = {4707191, 4747722, 1702169, 3994471, 4708958, 4008546, 4323335, 4516043, 4612295, 3469987, 4337892, 238378, 3088188, 329627, 3526384, 433483}
local picked = 1702169
for i, v in pairs(maps) do
if v == picked then
print("That's the number")
break
end
end
The above code will iterate through the whole table where i is the key and v is the value of the table[key]=value pairs.
I am slightly unclear about your end goal, but you could create this into a function and/or modify it to your actual needs. Feel free to update your original post with more information and I can provide you with a more specific answer.

how to compare if float variable value is infinite? [duplicate]

This question already has an answer here:
Check for inf - Objective-C
(1 answer)
Closed 9 years ago.
debugger says me float value is inf
I just see in debug window section of xcode is this
floatVar1=(float)inf
inf means infinite ?
so how can I compare it ?
something like this:
if (floatVar1==INFITINE){
[self doBlah];
}
To test whether a value is either positive infinity or negative infinity:
if (isinf(floatVar1)) …
To test only whether a value is positive infinity:
if (floatVar1 == INFINITY) …
In either case, use #include <math.h>.
I guess this should work, though it's not objective-c put plain c:
if(isinf(floatVar1)) { ... }
Also, you need to include math.h. For more info see http://www.cplusplus.com/reference/cmath/isinf/

calling c functions in Objective C [duplicate]

This question already has answers here:
Calling C from Objective C
(3 answers)
Closed 9 years ago.
Hi I am trying to use some pure C library in an iOS app, however I have no clue how to call and pass the parameters. Here are 2 functions, Node is a struct:
Node *parse(FILE *f);
void add_subnode(Node *t, Node *parent);
Can someone show me some sample code how to do it? Or point out to me some good books on this topic.
Thanks
Ray
You could call C functions like this:
Node *node = parse(f); // node will hold return value
add_subnode(t, parent);

How to calculate logarithm in iOS? [duplicate]

This question already has answers here:
How do I calculate a logarithm in iOS? [duplicate]
(3 answers)
Closed 9 years ago.
I need to calculate Log (base 10) and Log (base e – Naperian/Natural).
I am now assuming that Log (base 10) is:
double log10 ( double );
And am I correct to assume that Log (base e – Naperian/Natural) is just:
double log ( double );
Thanks
Check man 3 log for man page. In iOS 6 there is also vecLib which has logarithmic functions.

Resources