- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Does Intel has a fast routine for converting a 4 byteint and 4 byte float to a 4 byte byte array
and back?
Thanks in advance,
Constantine
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Does Intel has a fast routine for converting a 4 byteint and 4 byte float to a 4 byte byte array
and back?
Thanks in advance,
Constantine
Hi Constantine,
I'm probably missing something, but why not use the old fashioned memcpy ? E.g. :
int i = 0x12345678;
BYTE B[4];
memcpy(B, &i, 4);
Regards,
Rob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The reason I need this is thatI am creating buffered in memoryLZO compression which to be flushed to disk when needed. To do that I have to store the length of the uncompressed source
and also the length of compressed source.
Here is the problem. ippsEncodeLZO_8u uses byte array to store the compressed information.
I know the source length in advance, ippsEncodeLZO_8u returns destination (compressed)
length which has to be stored in the beginning of the byte array so the decompression to be able
to work later: ippsDecodeLZO_8u. EncodeLZO and DecodeLZO need these 2 lengths as Ipp32utypes - e.g. 4 bytes.
What follows I need to store in beginning of the buffertwo Ipp32u valuesof 4 bytes each and be able to read them later as Ipp32u. The difficulties I see is there is not easy way to save these Ipp32u values as 4 separate bytes as is andread them back directly as Ipp32u. I wroteBig Endian Split routine for splitting the Ipp32u to 4 separate bytes and then again use Big Endian Unsplit routine to read and interpret them back as Ipp32u.
But this adds additional compexyty. What I need is to be able to write and read directly in Ipp32u.
For example writing to file this is possible:
Ipp32u srcLen;
size=
size=
sizeof(srcLen);
fwrite(&srcLen, 1, size, pOutBin);
As you see you can save Ipp32u value directly to the file which is actually a byte array.
You can read this value back later as Ipp32u directly.
Ipp32u srcLen;
size=sizeof(srcLen);
fread(&srcLen, 1, size, pIn);
Best,
Constantine
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
So - the bottom line - how is the best way to write/read
Ipp32u type as a byte array on Intel machines?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
fread and fwrite is disk related. With fread and fwrite I can specify howto interpret these 4 bytes. In my case I interpret them as Ipp32u, but really they are saved as 4 bytes.I want to do the same in the memory.
e.g. the variable is Ipp32u = 4 bytes. The question is how to store these 4 bytes in Ipp8u
memory array, so to be able to readthese 4 byteslater directly as Ipp32u variable.
This Ipp8u memory array can be saved as a binary file and the first 4 bytes read later
with fread as an Ipp32u variable.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
With fread you can't specify to read 4-bytes varaible as big-endian or little-endian value. So you have to think on arhitecture you are running on and on format of the data you read (and how to interpret them) by yourself.
Vladimir
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
What follows I need to store in beginning of the buffertwo Ipp32u valuesof 4 bytes each and be able to read them later as Ipp32u.
Constantine, there are so many ways to implement this... Below is an example with "unsigned int". The same will be with Ipp32u.
unsigned char buffer[1000];
unsigned int *size1 = (unsigned int*)buffer;
unsigned int *size2 = (unsigned int*)(buffer+sizeof(unsigned int));
*size1 = 100;
*size2 = 200;
unsigned char *myStorage=buffer+2*sizeof(unsigned int);
unsigned int myLength = (unsigned int)(sizeof(buffer)-(myStorage-buffer));
You can use memcpy:
unsigned int size1 = 100;
unsigned int size2 = 200;
memcpy(buffer, &size1, sizeof(unsigned int));
memcpy(buffer+sizeof(unsigned int), &size2, sizeof(unsigned int));
Exotic:
union {
unsigned char buffer[1000];
struct {
unsigned int _size1;
unsigned int _size2;
} sizes;
} myStruct;
myStruct.sizes._size1 = 100;
myStruct.sizes._size2 = 200;
unsigned char *myStorage=myStruct.buffer+2*sizeof(unsigned int);
unsigned int myLength = (unsigned int)(sizeof(myStruct.buffer)-sizeof(myStruct.sizes));
You can use structures with sizes at structure head instead of plain buffer. So, many and many :)
Regards,
Sergey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
With fread you can't specify to read 4-bytes varaible as big-endian or little-endian value. So you have to think on arhitecture you are running on and on format of the data you read (and how to interpret them) by yourself.
Vladimir
The point is not to be little-endian or big-endian. I am using Intel architecture and want it as simple as possible.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Constantine, there are so many ways to implement this... Below is an example with "unsigned int". The same will be with Ipp32u.
unsigned char buffer[1000];
unsigned int *size1 = (unsigned int*)buffer;
unsigned int *size2 = (unsigned int*)(buffer+sizeof(unsigned int));
*size1 = 100;
*size2 = 200;
unsigned char *myStorage=buffer+2*sizeof(unsigned int);
unsigned int myLength = (unsigned int)(sizeof(buffer)-(myStorage-buffer));
You can use memcpy:
unsigned int size1 = 100;
unsigned int size2 = 200;
memcpy(buffer, &size1, sizeof(unsigned int));
memcpy(buffer+sizeof(unsigned int), &size2, sizeof(unsigned int));
Exotic:
union {
unsigned char buffer[1000];
struct {
unsigned int _size1;
unsigned int _size2;
} sizes;
} myStruct;
myStruct.sizes._size1 = 100;
myStruct.sizes._size2 = 200;
unsigned char *myStorage=myStruct.buffer+2*sizeof(unsigned int);
unsigned int myLength = (unsigned int)(sizeof(myStruct.buffer)-sizeof(myStruct.sizes));
You can use structures with sizes at structure head instead of plain buffer. So, many and many :)
Regards,
Sergey
Thanks for the example. The whole point of my question was how easily can READ back the values of Ipp32u
variable, without intermediate routine. I know there many ways to store the information in memory bytewise, the question is how easily to get it back directly. Because in my application compression is made 1 time, but decopression is made thousand times and each conversion takes time. Microsoft has BitConverter doing this but it is for .NET. the question was does Intel has more efficient procedure for the low level C.
Here is a code in C#:
byte[] bytes = { 0, 0, 0, 25 };
int i = BitConverter.ToInt32(bytes, 0);
As you see the storage is in byte array, but the BitConverter gets 4 bytes, combines them and returns
integer.
Now the question is how to do that most efficiently in Standard C.
Thanks in advance,
Konstantin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I suppose this is in the right direction, how to apply this routine to byte array? Endianness is not a question, it does not matter.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
simple loop might help I believe.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
simple loop might help I believe.
Does Intel has more efficient way of performing Array left shift for example? E.g. having an array(vector) to perform << on entire vector? This is more efficient than a loop.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
By efficiency I mean coding efficiency. Codingloops is not a solution, it is much simpler andefficient to code it asthe Intel IPPvector functions do. If there are vector left shift finction for example LeftShift(Src,Dst), I will get all Src vector elements left shifted with just one command.
By the way I am reading Fixed-Accuracy
Arithmetic Functions Chapter 12 of Intel IPP Signal Processing. 32f is by definition floating point, how they are intepreted as fixed point in Fixed-Accuracy Arithmetic Functions?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Because in my application compression is made 1 time, but decopression is made thousand times and each conversion takes time.
You may use any of conversion methods, looking only at method's esthetics. This conversion's burden - comparing to compression/decompression times - anyway will be negligible.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Correction:
Ipp32u abcd = 1234;
Ipp8u arr[4];
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page