#qi-hardware IRC log for Thursday, 2014-07-17

wpwrakwolfspraul: downloads.qi-hardware.com has amnesia again :(  (volume not mounted)00:02
wpwrakheh. i have root there ! fixed ;-)00:04
-:#qi-hardware- [freenode-info] why register and identify? your IRC nick is how people know you. http://freenode.net/faq.shtml#nicksetup06:33
DocScrutinizer05haha :-)07:22
larsctwo functions in the kernel, round_down() and rounddown() both behave differently...07:26
kyakdifferent results or different algorithms?07:31
kyakif the results are different, i would argue that one of these functions is incorrect :)07:31
larscone of them only works correctly when the divisor is a power of two07:33
larscbut now try to rememeber which is which07:33
larscand then there is also ALIGN()07:33
larscwhich does the same, but also only works with a power of two07:33
kyaktalking about quality in linux kernel..07:35
larscI've given up on that long time ago ;)07:36
larscthe 'good' news is the BSDs which pride themselves in quality are usually worse07:36
larscyea, now that I'm using the right function my driver works again07:38
kyaki suppose that they may pay more attention to quality, but then they just have fewer eyes to look at their code.. So despite that there is no "real" quality control in linux development, there are more eyes (like yours) that catch things that don't suppose to happen07:39
kyakare you going to bug report this? :)07:39
larscfixing this will take some time, but a quick grep revealed that there are other places that use round_down with non-power-of-twos07:41
kyak..and probably rely on incorrect behaviour07:44
larscsometimes the incorrect behaviour just goes unoticed. e.g. in my case the divisor could be 4 or 3, if it was 4 everything works fine07:51
DocScrutinizer05((<larsc> yea, now that I'm using the right function my driver works again)) hehe :-)07:53
eintopfguys, read this http://lists.infradead.org/pipermail/barebox/2014-July/020065.html07:54
eintopfround_up/round_down are optimized to (and only work with)07:54
eintopfpower-of-2 arguments.07:54
DocScrutinizer05yep, that's what I'd expect, hearing the story above07:55
kyakoh, so it's "documented"!07:55
kyakvery well :)07:56
eintopfnote: that's not the linux kernel :-)07:56
DocScrutinizer05and a general rule: never replace a function in a lib or kernel, particularly not with a "bugfixed" version. Somebody might rely and depend on that particular bug07:56
larsckyak: It is documented for barebox07:57
larscnot in the kernel07:57
eintopfin the kernel also07:58
eintopfinclude/linux/kernel.h07:58
eintopfhttps://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/include/linux/kernel.h?id=refs/tags/v3.16-rc5#n5607:59
eintopfbarebox adapt kernel driver interface, so it's mostly copy&paste do add a new driver to the bootloader08:00
eintopfbut barebox has no irq framework :/08:00
kyakthe implementation of round_* is interesting. How does it work?08:01
eintopfpower-of to are always 1 and followed by many zeros08:01
eintopfso you get a mask if you substract one08:02
eintopfand then do a little bit magic :/08:02
kyaklet me think about it :)08:03
eintopfI mean, all 4 divided numbers are 0xXXXXX408:03
eintopfand all 0x400 divided numbers are 0xXXXX40008:03
eintopfand all POWER_OF_TWO divided numbers are 0xXXXXPOWER_OF_TWO08:03
eintopfsomething like that08:04
Action: eintopf can't explain it08:04
larsckyak: round_down() basically set the ilog2(n) lower bits in the word to zero08:04
larscround_up() sets them to one and then adds one08:04
larscround_up is a bit ineffcient though, it uses 3 arithmetic instructions while it can be done in two08:06
eintopflarsc: send-patches08:06
larscmaybe08:06
kyakok, i take 2^3 = 8 (1000) for example as y. Then y-1 is 0111. ~(y-1) is 1000 (that is, y) - so what's the point?08:07
larsckyak: it is ...11111111100008:08
kyakah.. you are ight.. because it is casted to type of x?08:08
eintopf~ is xor08:09
larscno08:09
larscit's not08:09
larscit's 'not'08:09
larsckyak: ~ inverts all bits in the word08:10
eintopfyes :-)08:10
whitequarkthat's not xor08:10
eintopfyes :(08:10
eintopfI mean it's like setting register bits reg &= ~(foo)08:11
kyakyep, so the word is type of x in this case, not type of y, therefore we get extra "ones" 08:11
eintopfehm, clearing register bits08:11
larsckyak: by default in C the type of 8 is int08:12
larscso ~(8-1) != 8, even without a typecast08:13
kyakright, but what about uint4_t a=8; ~(a-1) ? :)08:14
DocScrutinizer054= 0x100, next larger power of 2 is 8= 0x1000. So all < 8 = 5,6, 7 become 4 on round down. 0x101, 0x110 and 0x111 -> 0x10008:14
kyaki have a feeling there should be an easier way to zero down the set amount of lower bits...08:15
DocScrutinizer058 = 0x1000   -1= 0x111,  mask lower 1s: 0x100; 0x100 & 0x1xx -> 0x10008:15
DocScrutinizer05some CPUs even have an opcode for this08:17
kyakfor rounding down to nearest power of two?08:18
kyakwait, that raises a question08:18
kyakwhy would anyone require the second argument, y?08:19
larscit's not the nearest power of two08:19
kyakwhat is the use case of rounding down to an arbitraty powwer of two?08:19
larscit's the power of two you specify for y08:19
kyakcould it be that the sole reason of argument y is because it is used in calculations?08:20
larsce.g. if you hardware is only able to process objects which size is a multiple of a certain power of two08:21
DocScrutinizer05err sorry. I actually don't get it what "round down X to 2^n" is useful for. Isn't the result always 2^n unless X < 2^n?08:24
kyakok, i see. But if you round down "further away" than the nearest power of two, you are loosing to much information. It would mean that your implementation is probably wronf08:24
kyakyou might as well just always output that required power of two and not calculate anything :)08:25
DocScrutinizer05my point08:25
DocScrutinizer05unless X < 2^n#08:26
DocScrutinizer05-#08:26
kyakmy guess is that the 'y' is an argument because it is used to calculate the mask08:26
DocScrutinizer05so round_down is actually a range limiting aka clipping function08:27
kyakand than my another point that there should be an easier implemention of round_down08:27
kyakwithout requiring y and round to nearest power of two08:27
DocScrutinizer05for a 16bit argument X make sure it's 0< X<2^n08:27
kyakyep08:28
kyakit should be called range_lim08:28
kyakor whatever08:28
DocScrutinizer05with n anything between 15 and 108:28
DocScrutinizer05err 15 and 0 actually08:29
DocScrutinizer05kyak: exactly08:29
DocScrutinizer05for a round_down I'd expect 5->4 and 3->208:30
kyakreally the question is whether this behaviour is intended by round_down() authors or it is just an effect of their implementation08:30
DocScrutinizer05actually 7,6,5->408:31
DocScrutinizer05clipping functions are widely used, and as I said are available as opcode in several ISA08:32
eintopf:o08:32
DocScrutinizer05can't recall the usual name of c/whatever high level language of that function08:33
DocScrutinizer05it's prolly not max()08:33
DocScrutinizer05language name of that function. Pardon my french08:35
kyaki wonder how round_down() would behave if we supply y > x...08:35
larscreturns 008:35
larscas it should08:35
Action: eintopf used round_down() in some kernel code08:36
kyakanyway, i conclude that this function is weird :)08:36
kyakeintopf: do you use it to round down to nearest power of two or to arbitraty power of two?08:36
DocScrutinizer05I guess usually the compiler converts that functio (let's call it max(x, y) ) into code rather than a function call08:36
kyakand the question is - how do you know what's that 'nearest' in advance?08:37
DocScrutinizer05but actually I wonder how compiler would know that y is always a power of 2 so it can create optinized code08:38
eintopfI use it for the nearest 08:38
kyakto use this function, the developer must know in advance the value he wants to round down to.. that's weird08:38
eintopfsome RFC payload attributes use the nearest divide by 808:38
DocScrutinizer05kyak: the value you want to round down to is your upper limit of range08:39
larsckyak: round_down() returns the nearest value that is smaller or equal to x and is also a multiple of y08:39
DocScrutinizer05e.g. clip values calculated in a 32bit register to 16bit08:40
DocScrutinizer05or 15 bit when the target is a signed int1608:40
larscDocScrutinizer05: that would be clamp()08:40
DocScrutinizer05sounds good08:41
DocScrutinizer05aiui round_down is doing exactly that08:41
kyakok, it's more clear now08:41
DocScrutinizer05actually a clamp diode does exactly that for a voltage on an input pin :-)08:42
larscDocScrutinizer05: round_down() does something else08:43
DocScrutinizer05then I didn't get the explanation what round_down is doing08:43
larscround_down(x, y) return a value z for which x >= z > x-y and z is a multiple of y08:44
DocScrutinizer05ooh08:44
DocScrutinizer05thanks!08:44
larscround_up(x, y) return a value z for which x <= z < x+y and z is a multiple of y08:45
DocScrutinizer05that makes sense08:46
DocScrutinizer05though for y=2^n...08:47
DocScrutinizer05I can't find a non-negative value x for arbitrary y=2^n where round_down(x, 2^n) is _not_ identical to clip(x, 2^n)08:51
DocScrutinizer05maybe lack of coffee08:52
eintopfsend patches, somebody of the global review will scream if it's not identical08:53
DocScrutinizer05err clamp08:53
eintopf:-)08:53
larscDocScrutinizer05: x=5 y=208:53
larscround_down(5, 2) = 408:54
larscclamp(5,2) = 208:54
DocScrutinizer05lack of coffee, evidently08:54
DocScrutinizer05thanks, and sorry for the noise08:54
DocScrutinizer05ok, to correct myself: I never seen round_down() in any ISA08:58
larscif y is a constant the compiler will internally compute ~(y - 1) so the whole operation boils down to a simple and08:59
DocScrutinizer05:nod:09:00
Action: DocScrutinizer05 ponders more coffee09:00
DocScrutinizer05maybe I'm simply over the top with coffee, and rather need a walk and sth to eat09:01
kyakround_down(56,8) is 5609:49
kyaknow i'm confused again09:49
kyakah, because 56 is multiple of 809:50
kyakor, in other words, 56 already has it's 3 lower bits cleared09:53
kyaklarsc: what's your use case for this function?09:53
larsconly reading whole data sets from a sample fifo09:56
larscin the fifo I have X,Y and Z data09:56
larscand I want to make sure that I only read complete sets of data09:56
larscso I read the number of samples in the fifo and then rounddown() to the nearest multiple of 309:57
kyaki see, so you only grab XYZ, XYZ, XYZ. But what happens to the remaining X or XY, if they are in fifo?09:58
kyaki mean, do you discard those samples by rounding?09:58
kyaklinux.h is a treasury of things like that :)10:06
kyakwhy the hell they need a do-while loop in swap()?10:06
eintopfmaybe because to turn off compiler optimization10:07
eintopfif it's a do { } while (0);10:07
kyakyes , so the while loop basically doesn't exist10:08
kyakwhat would compiler try to optimize here and what would be the consequences of this optimization?10:09
eintopfit's not optimization10:09
eintopfit's more turn off compiler weird things :-)10:09
eintopfI don't know it exactly10:10
kyaki can only hope that they know :)10:10
eintopfmaybe generate assembler code10:10
eintopfwith and without10:10
eintopfthen you know more10:10
kyakthere are separate macros for max and max3 (for three arguments), and same for min/min3. Wouldn't it be possible to create a universal macro for any number of arguments?10:10
kyakeintopf: or maybe just a line of comment in source code would help. Maybe this is some stupid workaround for gcc v 1.010:11
eintopfi am not a compiler expert, sry10:11
kyak99.99% of people aren't. So leave a sensible comment, god damn them10:12
eintopfcomment is the code :-)10:12
eintopf:X10:12
kyakmin_not_zero - return the minimum that is _not_ zero, unless both are zero10:13
kyakoh, common!10:13
kyakare they going to come up with a separate function for every unpossible use case?10:13
kyaklike the family of clamp_* functions10:13
kyakactually, i have troubles understanding this phrase even in human language "minimum that is _not_ zero, unless both are zero"10:14
kyakthis requires some thinking :)10:14
kyakand i imaging one day i would require such function, and then i would have no fucking clue that such exists in priceless linux.h10:15
larscit is acutally a quite useful function which helps to eliminate a lot of boilderplate code10:24
larscit is not that rare that for settings where 0 does not make sense it is regarded as infinity10:25
kyakbut this function can still return 0, despite of it's name10:27
kyakand despite that you treat 0 as infinity10:28
larsconly if both a and b is 010:28
kyakyes, sure10:28
larscwhich is correct10:28
larscmin_zero_is_infitiy() is a guly name ;)10:28
larscmin_but_zero_counts_as_infinity()10:28
kyakanyway, i'm just too far away from this.. if you say it's useful, i trust you :)10:28
kyakmin_not_zero_except_both_zeros()10:30
kyak--)10:30
kyaklarsc: so what happens to data in fifo that didn't fit into your multiple of three series?10:32
kyakalso, would it be possible to just read() from fifo in series of three?10:33
ysionneau12:06 < kyak> why the hell they need a do-while loop in swap()? < http://kernelnewbies.org/FAQ/DoWhile010:37
kyakysionneau: oh, thanks@10:40
larsckyak: the data stays in the fifo until a full set is available10:41
kyaklarsc: but if you've already read the data from fifo (including the incomplete set), how do you put it back in fifo?10:45
larscI read the number of samples from the hardware10:45
larscthen round that down to the nearest multiple of three10:45
larscand read that many samples from the fifo10:45
kyakok, i got it10:45
DocScrutinizer05((<kyak> i mean, do you discard those samples by rounding?)) those stay in FIFO for next time10:51
kyakyep, that's clear now10:51
DocScrutinizer05oops, seen larsc answered it a few lines up10:54
kyakhe did :)10:54
DocScrutinizer05a FIFO usually implemented as ring buffer, with a pointer to data start and one to data end10:55
DocScrutinizer05you fill the FIFO by incrementing pointer to end, and after reading n from pointer to start, you increment the pointer to start accordingly10:56
DocScrutinizer05hw does same11:00
--- Fri Jul 18 201400:00

Generated by irclog2html.py 2.9.2 by Marius Gedminas - find it at mg.pov.lt!