packed

SystemVerilog packed array vs unpacked array memory footprint

风格不统一 提交于 2020-01-05 08:27:34
问题 Is it true that with the contemporary advanced SV RTL simulators, the simulation footprint may increase when using unpacked arrays vs the packed arrays? If so, is this a problem and do verification teams insist on rules to use packed arrays? TIA. Sanjay 回答1: "[Does] the simulation footprint may increase when using unpacked arrays vs the packed arrays?" It depends on the simulator allocates and accesses its memory. Most cases packed arrays will have a smaller memory footprint then unpacked

Size of packed struct with union of bit fields less than 8 bits in C

筅森魡賤 提交于 2019-12-22 08:42:18
问题 Is it possible in C to get the size of the following structure to be 2? #include <stdio.h> struct union_struct { char foo; char bar : 2; union { char foobar1 : 6; char foobar2 : 6; }; }; int main(void) { printf("size of union struct: %d\n", sizeof(struct union_struct)); return 0; } output, compiled with gcc: size of union struct: 3 回答1: If you are relying on implementation defined behavior, then yes, but you have to organize it a bit differently: #ifdef UNNAMED_BITFIELDS_ARE_WELL_DEFINED

Fast list-product sign for PackedArray?

橙三吉。 提交于 2019-12-12 19:58:02
问题 As a continuation of my previous question, Simon's method to find the list product of a PackedArray is fast, but it does not work with negative values. This can be "fixed" by Abs with minimal time penalty, but the sign is lost, so I will need to find the product sign separately. The fastest method that I tried is EvenQ @ Total @ UnitStep[-lst] lst = RandomReal[{-2, 2}, 5000000]; Do[ EvenQ@Total@UnitStep[-lst], {30} ] // Timing Out[]= {3.062, Null} Is there a faster way? 回答1: This is a little

Nothing but “packed” records — should I fix it?

冷暖自知 提交于 2019-12-12 07:17:58
问题 While reviewing some code in our legacy Delphi 7 program, I noticed that everywhere there is a record it is marked with packed . This of course means that the record is stored byte-for-byte and not aligned to be faster for the CPU to access. The packing seems to have been done blindly as an attempt to outsmart the compiler or something -- basically valuing a few bytes of memory instead of faster access An example record: TFooTypeRec = packed record RID : Integer; Description : String;

Why can't I return a reference to a packed field?

有些话、适合烂在心里 提交于 2019-12-06 19:33:15
问题 I use g++ to compile code with packed fields. However, I receive an error when trying to return a reference to a packed field. Example: struct __attribute__((packed)) Foo { int* ptr; uint16_t foo; int*& getPtr(){ return ptr; } }; yields error: test.cpp:22:14: error: cannot bind packed field ‘((Foo*)this)->Foo::ptr’ to ‘int*&’ return ptr; Why can't I return a reference to a packed field? 回答1: There is a gcc bug report Cannot bind packed field that covers this and it says: The C++ spec (C++03,

Size of packed struct with union of bit fields less than 8 bits in C

橙三吉。 提交于 2019-12-05 16:21:52
Is it possible in C to get the size of the following structure to be 2? #include <stdio.h> struct union_struct { char foo; char bar : 2; union { char foobar1 : 6; char foobar2 : 6; }; }; int main(void) { printf("size of union struct: %d\n", sizeof(struct union_struct)); return 0; } output, compiled with gcc: size of union struct: 3 If you are relying on implementation defined behavior, then yes, but you have to organize it a bit differently: #ifdef UNNAMED_BITFIELDS_ARE_WELL_DEFINED #define ANON #else #define ANON3(X) anonymous__## X ##__ #define ANON2(X) ANON3(X) #define ANON ANON2(__LINE__)

Why can't I return a reference to a packed field?

旧巷老猫 提交于 2019-12-05 02:23:57
I use g++ to compile code with packed fields. However, I receive an error when trying to return a reference to a packed field. Example: struct __attribute__((packed)) Foo { int* ptr; uint16_t foo; int*& getPtr(){ return ptr; } }; yields error: test.cpp:22:14: error: cannot bind packed field ‘((Foo*)this)->Foo::ptr’ to ‘int*&’ return ptr; Why can't I return a reference to a packed field? There is a gcc bug report Cannot bind packed field that covers this and it says: The C++ spec (C++03, Sects. 3.9, 3.9.1, 3.9.2) are very clear that T and "pointer to T" have implementation-specific alignment

Is there a fast product operation for PackedArrays?

那年仲夏 提交于 2019-12-03 09:51:11
问题 In Mathematica a vector (or rectangular array) containing all machine size integers or floats may be stored in a packed array. These objects take less memory, and some operations are much faster on them. RandomReal produces a packed array when possible. A packed array can be unpacked with the Developer function FromPackedArray Consider these timings lst = RandomReal[1, 5000000]; Total[lst] // Timing Plus @@ lst // Timing lst = Developer`FromPackedArray[lst]; Total[lst] // Timing Plus @@ lst /

Packed bit fields in c structures - GCC

拈花ヽ惹草 提交于 2019-12-03 08:44:39
问题 I am working with structs in c on linux. I started using bit fields and the "packed" attribute and I came across a wierd behavior: struct t1 { int a:12; int b:32; int c:4; }__attribute__((packed)); struct t2 { int a:12; int b; int c:4; }__attribute__((packed)); void main() { printf("%d\n",sizeof(t1)); //output - 6 printf("%d\n",sizeof(t2)); //output - 7 } How come both structures - that are exactly the same - take diffrent number of bytes? 回答1: Your structures are not "exactly the same". Your

Are packed structs portable?

你离开我真会死。 提交于 2019-12-03 04:43:38
问题 I have some code on a Cortex-M4 microcontroller and'd like to communicate with a PC using a binary protocol. Currently, I'm using packed structs using the GCC-specific packed attribute. Here is a rough outline: struct Sensor1Telemetry { int16_t temperature; uint32_t timestamp; uint16_t voltageMv; // etc... } __attribute__((__packed__)); struct TelemetryPacket { Sensor1Telemetry tele1; Sensor2Telemetry tele2; // etc... } __attribute__((__packed__)); My question is: Assuming that I use the