bitfield | : cake : bit field diagram renderer
kandi X-RAY | bitfield Summary
kandi X-RAY | bitfield Summary
:cake: bit field diagram renderer
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Replaces a Bitfield
bitfield Key Features
bitfield Examples and Code Snippets
Community Discussions
Trending Discussions on bitfield
QUESTION
I'm trying to make sure gcc vectorizes my loops. It turns out, that by using -march=znver1
(or -march=native
) gcc skips some loops even though they can be vectorized. Why does this happen?
In this code, the second loop, which multiplies each element by a scalar is not vectorised:
...ANSWER
Answered 2022-Apr-10 at 02:47The default -mtune=generic
has -mprefer-vector-width=256
, and -mavx2
doesn't change that.
znver1 implies -mprefer-vector-width=128
, because that's all the native width of the HW. An instruction using 32-byte YMM vectors decodes to at least 2 uops, more if it's a lane-crossing shuffle. For simple vertical SIMD like this, 32-byte vectors would be ok; the pipeline handles 2-uop instructions efficiently. (And I think is 6 uops wide but only 5 instructions wide, so max front-end throughput isn't available using only 1-uop instructions). But when vectorization would require shuffling, e.g. with arrays of different element widths, GCC code-gen can get messier with 256-bit or wider.
And vmovdqa ymm0, ymm1
mov-elimination only works on the low 128-bit half on Zen1. Also, normally using 256-bit vectors would imply one should use vzeroupper
afterwards, to avoid performance problems on other CPUs (but not Zen1).
I don't know how Zen1 handles misaligned 32-byte loads/stores where each 16-byte half is aligned but in separate cache lines. If that performs well, GCC might want to consider increasing the znver1 -mprefer-vector-width
to 256. But wider vectors means more cleanup code if the size isn't known to be a multiple of the vector width.
Ideally GCC would be able to detect easy cases like this and use 256-bit vectors there. (Pure vertical, no mixing of element widths, constant size that's am multiple of 32 bytes.) At least on CPUs where that's fine: znver1, but not bdver2 for example where 256-bit stores are always slow due to a CPU design bug.
You can see the result of this choice in the way it vectorizes your first loop, the memset-like loop, with a vmovdqu [rdx], xmm0
. https://godbolt.org/z/E5Tq7Gfzc
So given that GCC has decided to only use 128-bit vectors, which can only hold two uint64_t
elements, it (rightly or wrongly) decides it wouldn't be worth using vpsllq
/ vpaddd
to implement qword *5
as (v<<2) + v
, vs. doing it with integer in one LEA instruction.
Almost certainly wrongly in this case, since it still requires a separate load and store for every element or pair of elements. (And loop overhead since GCC's default is not to unroll except with PGO, -fprofile-use
. SIMD is like loop unrolling, especially on a CPU that handles 256-bit vectors as 2 separate uops.)
I'm not sure exactly what GCC means by "not vectorized: unsupported data-type". x86 doesn't have a SIMD uint64_t
multiply instruction until AVX-512, so perhaps GCC assigns it a cost based on the general case of having to emulate it with multiple 32x32 => 64-bit pmuludq
instructions and a bunch of shuffles. And it's only after it gets over that hump that it realizes that it's actually quite cheap for a constant like 5
with only 2 set bits?
That would explain GCC's decision-making process here, but I'm not sure it's exactly the right explanation. Still, these kinds of factors are what happen in a complex piece of machinery like a compiler. A skilled human can easily make smarter choices, but compilers just do sequences of optimization passes that don't always consider the big picture and all the details at the same time.
-mprefer-vector-width=256
doesn't help:
Not vectorizing uint64_t *= 5
seems to be a GCC9 regression
(The benchmarks in the question confirm that an actual Zen1 CPU gets a nearly 2x speedup, as expected from doing 2x uint64 in 6 uops vs. 1x in 5 uops with scalar. Or 4x uint64_t in 10 uops with 256-bit vectors, including two 128-bit stores which will be the throughput bottleneck along with the front-end.)
Even with -march=znver1 -O3 -mprefer-vector-width=256
, we don't get the *= 5
loop vectorized with GCC9, 10, or 11, or current trunk. As you say, we do with -march=znver2
. https://godbolt.org/z/dMTh7Wxcq
We do get vectorization with those options for uint32_t
(even leaving the vector width at 128-bit). Scalar would cost 4 operations per vector uop (not instruction), regardless of 128 or 256-bit vectorization on Zen1, so this doesn't tell us whether *=
is what makes the cost-model decide not to vectorize, or just the 2 vs. 4 elements per 128-bit internal uop.
With uint64_t
, changing to arr[i] += arr[i]<<2;
still doesn't vectorize, but arr[i] <<= 1;
does. (https://godbolt.org/z/6PMn93Y5G). Even arr[i] <<= 2;
and arr[i] += 123
in the same loop vectorize, to the same instructions that GCC thinks aren't worth it for vectorizing *= 5
, just different operands, constant instead of the original vector again. (Scalar could still use one LEA). So clearly the cost-model isn't looking as far as final x86 asm machine instructions, but I don't know why arr[i] += arr[i]
would be considered more expensive than arr[i] <<= 1;
which is exactly the same thing.
GCC8 does vectorize your loop, even with 128-bit vector width: https://godbolt.org/z/5o6qjc7f6
QUESTION
I have a struct
as follows.
ANSWER
Answered 2022-Apr-02 at 07:00The first question, you can add an alignment, but this will affect the execution efficiency:
QUESTION
I'm getting RangeError [BITFIELD_INVALID]: Invalid bitfield flag or number: undefined.
with this code. Can someone help me with what's undefined
here?
I'm using discord.js v13.6.0.
...ANSWER
Answered 2022-Mar-14 at 17:35In discord.js v13 Intents.ALL
, Intents.NON_PRIVILEGED
, and Intents.PRIVILEGED
have all been removed to discourage bad practices. It means you need to remove Intents.NON_PRIVILEGED
.
Also, there is no Intents.GUILD_MEMBERS
, it should be Intents.FLAGS.GUILD_MEMBERS
. So you'll need to update your code like this:
QUESTION
I have the following code :
...ANSWER
Answered 2022-Feb-22 at 19:50The result you are looking for can be obtained by making the structure union
instead, with two bit-fields overlapping. The bits "used" by the first bitfield will be marked as "reserved" in the second one:
QUESTION
I am trying to work with flash memory on MPC5748G - a microcontroller from NXP running FreeRTOS 10.0.1, and I get some behaviour that I can't understand.
I am allocating memory manually, and the assignment seems not to work. However, I can reach the value at the address when using 'printf' - but only from the same function. (I'm using the copy of a pointer, to make sure that some sore of compiler optimisation doesn't take place)
...ANSWER
Answered 2022-Feb-16 at 16:50The problem was writing to FLASH memory - it hasn't been correctly initialized.
The proper way to write to flash on MPC5748g using the SDK 3.0.3 is following:
- save flash controller cache
- initialise flash
- check and protect UT block
- unblock an address space
- erase a block in this space
- check if the space block is blank
- program the block
- verify if the block is programmed correctly
- check sum of the programmed data
- restore flash controller cache
The strange behaviour of printf and pointer was due to compiler optimization. After changing the compiler flags to -O0 (no optimization), the error was consistent.
The same consistent error can be achieved when marking the pointers as 'volatile'.
QUESTION
I'm wondering what value a bit-field class member variable will have if it is not explicitly initialized.
Using an example from unreal engine 4.27:
...ANSWER
Answered 2022-Jan-24 at 10:06Dug a little bit deeper, so I'll try to answer this myself. I believe that for a normal C++ class it would be undefined behaviour as I cannot find any info suggesting otherwise for bit-fields specifically.
For the UE4 example, most objects in the engine including the cited UPrimitiveComponent
example are derived from UObject
, and I did find deep in the documentation that these are automatically zero initialized:
Automatic Property Initialization UObjects are automatically zeroed on initialization, before the constructor is called. This happens for the whole class, UProperties and native members alike. Members can subsequently be initialized with custom values in the class constructor.
In the code this will happen in StaticAllocateObject
in UObjectGlobals.cpp
, the memory is earlier malloc
'd and then FMemory::Memzero
is called which ultimately uses memset
to zero the memory
QUESTION
I have this bit of code console.log(newVoiceState.channel)
inside client.on("voiceStateUpdate", async (oldVoiceState, newVoiceState) => {
that returns:
ANSWER
Answered 2022-Jan-09 at 11:20The voiceStateUpdate
is emitted whenever a member changes their voice state. In some cases, e.g. when someone leaves a voice channel, newVoiceState.channel
will be null
and if you try to read a property of this, it will throw a TypeError
.
You'll need to compare the voiceState
s before and after the update to figure out what triggered the voiceStateUpdate
event. I've just added some code below with a few examples. The following code logs if someone joined/left/switched channels, or if there are other changes like muted/unmuted themselves, started sharing their screen, etc.:
QUESTION
I'm trying to get all role permissions as list, but using ...roles.cache.get("910908545124413500").permissions
leads me to this result: Permissions { bitfield: 104320585 }
and ...roles.cache.get("910908545124413500").permissions.toString()
returns [object Object]
!
What can I use to get all roles perms as list (without using permissions.has()
for each permission)?
ANSWER
Answered 2021-Dec-29 at 20:49Took me some time to look through the documentation but found that the method toArray()
returns an array of strings with the permissions.
QUESTION
I've started taking a look at Nim for hobby game modding purposes.
Intro
Yet, I found it difficult to work with Nim compared to C when it comes to machine-specific low-level memory layout and would like to know if Nim actually has better support here.
I need to control byte order and be able to de/serialize arbitrary Plain-Old-Datatype objects to binary custom file formats. I didn't directly find a Nim library which allows flexible storage options like representing enum
and pointers
with Big-Endian 32-bit. Or maybe I just don't know how to use the feature.
- std/marshal : just JSON, i.e. no efficient, flexible nor binary format but cross-compatible
- nim-serialization : seems like being made for human readable formats
- nesm : flexible cross-compatibility? (It has some options and has a good interface)
- flatty : no flexible cross-compatibility, no byte order?
- msgpack4nim : no flexible cross-compatibility, byte order?
- bingo : ?
Flexible cross-compatibility means, it must be able to de/serialize fields independently of Nim's ABI but with customization options.
Maybe "Kaitai Struct" is more what I look for, a file parser with experimental Nim support.
TL;DRAs a workaround for a serialization library I tried myself at a recursive "member fields reverser" that makes use of std/endians
which is almost sufficient.
But I didn't succeed with implementing byte reversal of arbitrarily long objects in Nim. Not practically relevant but I still wonder if Nim has a solution.
I found reverse()
and reversed()
from std/algorithm
but I need a byte array to reverse it and turn it back into the original object type. In C++ there would be reinterprete_cast
, in C there is void*
-cast, in D there is a void[]
cast (D allows defining array slices from pointers) but I couldn't get it working with Nim.
I tried cast[ptr array[value.sizeof, byte]](unsafeAddr value)[]
but I can't assign it to a new variable. Maybe there was a different problem.
How to "byte reverse" arbitrary long Plain-Old-Datatype objects?
How to serialize to binary files with byte order, member field size, pointer as file "offset - start offset"? Are there bitfield options in Nim?
...ANSWER
Answered 2021-Dec-25 at 15:48Bit fields are supported in Nim as a set of enums:
QUESTION
I'm using Discord v13 and I'm following the docs here in order to verify if the user that sent a DM message to the bot has the Admin
role or not.
ANSWER
Answered 2021-Dec-12 at 21:57Your intents and partials look okay to me. However, in DMs the properties guild
, guildId
, and member
are null
. You can see that by reading the docs.
If you know the guild ID, you can fetch the member by its ID. You can get this user ID from message.author
.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install bitfield
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