Re: [PATCH BlueZ] mesh: Correctly generate NetKey list

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, 2020-01-09 at 22:29 +0100, michal.lowas-rzechonek@xxxxxxxxxxx
wrote:
> On 01/09, Stotland, Inga wrote:
> > > Please don't use bit shifts for division.
> > Why?
> 
> Because it's a different operation, and is less readable.  It's a
> formula, so use math operators for numbers and bit operators for bits.
> 
> For example, idx_pair <<= 12 is fine, because the *context* is
> bit-packing. Noone sane would write this as idx_pair *= 4096. This
> reasoning applies the other way as well: don't write foo >> 2 where you
> mean foo / 4.

Well, shift is a less expensive operation than a division (I believe,
some compilers may substitute integer division by 2 with a shift).

I don't see any reason not to use >> in this particular case, but I can
change if this is not readable...

> 
> > > Also, I think it's clearer to write this as:
> > >     req_size = num_keys * 3 - num_keys % 2
> > 
> > No, this is not how I read the spec. We need to pack 2 key indices in 3 octets.
> > For example, 4 keys are packed in 6 octets and 5 keys are packed in 8 octets.
> 
> Yes, you're right. Sorry.
> 




[Index of Archives]     [Bluez Devel]     [Linux Wireless Networking]     [Linux Wireless Personal Area Networking]     [Linux ATH6KL]     [Linux USB Devel]     [Linux Media Drivers]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Big List of Linux Books]

  Powered by Linux