DocScrutinizer05 changed the topic of #qi-hardware to: Copyleft hardware - http://qi-hardware.com | hardware hackers join here to discuss Ben NanoNote, atben / atusb 802.15.4 wireless, and other community driven hw projects | public logging at http://en.qi-hardware.com/irclogs and http://irclog.whitequark.org/qi-hardware
wolfspraul has joined #qi-hardware
<wpwrak> wolfspraul: downloads.qi-hardware.com has amnesia again :( (volume not mounted)
<wpwrak> heh. i have root there ! fixed ;-)
dandon has joined #qi-hardware
pcercuei has quit [Quit: dodo]
Textmode has joined #qi-hardware
nicksydney has joined #qi-hardware
dandon_ has joined #qi-hardware
kanzure_ has joined #qi-hardware
qi-bot6 has joined #qi-hardware
idundidit has quit [Ping timeout: 240 seconds]
kanzure has quit [Ping timeout: 240 seconds]
wpwrak has quit [Ping timeout: 240 seconds]
jow_lapt1p has joined #qi-hardware
dandon has quit [Ping timeout: 240 seconds]
jow_laptop has quit [Ping timeout: 240 seconds]
qi-bot has quit [Ping timeout: 240 seconds]
zear has quit [Ping timeout: 240 seconds]
dandon_ is now known as dandon
wpwrak has joined #qi-hardware
idundidit has joined #qi-hardware
zear has joined #qi-hardware
qi-bot6 is now known as qi-bot
wej_ has joined #qi-hardware
wej has quit [Ping timeout: 250 seconds]
jekhor has joined #qi-hardware
xiangfu has joined #qi-hardware
<DocScrutinizer05> haha :-)
<larsc> two functions in the kernel, round_down() and rounddown() both behave differently...
<kyak> different results or different algorithms?
<kyak> if the results are different, i would argue that one of these functions is incorrect :)
<larsc> one of them only works correctly when the divisor is a power of two
<larsc> but now try to rememeber which is which
<larsc> and then there is also ALIGN()
<larsc> which does the same, but also only works with a power of two
<kyak> talking about quality in linux kernel..
<larsc> I've given up on that long time ago ;)
<larsc> the 'good' news is the BSDs which pride themselves in quality are usually worse
<larsc> yea, now that I'm using the right function my driver works again
<kyak> i 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 happen
<kyak> are you going to bug report this? :)
<larsc> fixing this will take some time, but a quick grep revealed that there are other places that use round_down with non-power-of-twos
<kyak> ..and probably rely on incorrect behaviour
<larsc> sometimes the incorrect behaviour just goes unoticed. e.g. in my case the divisor could be 4 or 3, if it was 4 everything works fine
<DocScrutinizer05> ((<larsc> yea, now that I'm using the right function my driver works again)) hehe :-)
<eintopf> round_up/round_down are optimized to (and only work with)
<eintopf> power-of-2 arguments.
<DocScrutinizer05> yep, that's what I'd expect, hearing the story above
<kyak> oh, so it's "documented"!
<kyak> very well :)
<eintopf> note: that's not the linux kernel :-)
<DocScrutinizer05> and 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 bug
<larsc> kyak: It is documented for barebox
<larsc> not in the kernel
<eintopf> in the kernel also
<eintopf> include/linux/kernel.h
<eintopf> barebox adapt kernel driver interface, so it's mostly copy&paste do add a new driver to the bootloader
<eintopf> but barebox has no irq framework :/
<kyak> the implementation of round_* is interesting. How does it work?
<eintopf> power-of to are always 1 and followed by many zeros
<eintopf> so you get a mask if you substract one
<eintopf> and then do a little bit magic :/
<kyak> let me think about it :)
<eintopf> I mean, all 4 divided numbers are 0xXXXXX4
<eintopf> and all 0x400 divided numbers are 0xXXXX400
<eintopf> and all POWER_OF_TWO divided numbers are 0xXXXXPOWER_OF_TWO
<eintopf> something like that
* eintopf can't explain it
<larsc> kyak: round_down() basically set the ilog2(n) lower bits in the word to zero
<larsc> round_up() sets them to one and then adds one
<larsc> round_up is a bit ineffcient though, it uses 3 arithmetic instructions while it can be done in two
<eintopf> larsc: send-patches
<larsc> maybe
<kyak> ok, 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?
<larsc> kyak: it is ...111111111000
<kyak> ah.. you are ight.. because it is casted to type of x?
<eintopf> ~ is xor
<larsc> no
<larsc> it's not
<larsc> it's 'not'
<larsc> kyak: ~ inverts all bits in the word
<eintopf> yes :-)
<whitequark> that's not xor
<eintopf> yes :(
<eintopf> I mean it's like setting register bits reg &= ~(foo)
<kyak> yep, so the word is type of x in this case, not type of y, therefore we get extra "ones"
<eintopf> ehm, clearing register bits
<larsc> kyak: by default in C the type of 8 is int
<larsc> so ~(8-1) != 8, even without a typecast
<kyak> right, but what about uint4_t a=8; ~(a-1) ? :)
<DocScrutinizer05> 4= 0x100, next larger power of 2 is 8= 0x1000. So all < 8 = 5,6, 7 become 4 on round down. 0x101, 0x110 and 0x111 -> 0x100
<kyak> i have a feeling there should be an easier way to zero down the set amount of lower bits...
<DocScrutinizer05> 8 = 0x1000 -1= 0x111, mask lower 1s: 0x100; 0x100 & 0x1xx -> 0x100
<DocScrutinizer05> some CPUs even have an opcode for this
<kyak> for rounding down to nearest power of two?
<kyak> wait, that raises a question
<kyak> why would anyone require the second argument, y?
<larsc> it's not the nearest power of two
<kyak> what is the use case of rounding down to an arbitraty powwer of two?
<larsc> it's the power of two you specify for y
<kyak> could it be that the sole reason of argument y is because it is used in calculations?
<larsc> e.g. if you hardware is only able to process objects which size is a multiple of a certain power of two
<DocScrutinizer05> err 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?
<kyak> ok, 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 wronf
<kyak> you might as well just always output that required power of two and not calculate anything :)
<DocScrutinizer05> my point
<DocScrutinizer05> unless X < 2^n#
<DocScrutinizer05> -#
<kyak> my guess is that the 'y' is an argument because it is used to calculate the mask
<DocScrutinizer05> so round_down is actually a range limiting aka clipping function
<kyak> and than my another point that there should be an easier implemention of round_down
<kyak> without requiring y and round to nearest power of two
<DocScrutinizer05> for a 16bit argument X make sure it's 0< X<2^n
<kyak> yep
<kyak> it should be called range_lim
<kyak> or whatever
<DocScrutinizer05> with n anything between 15 and 1
<DocScrutinizer05> err 15 and 0 actually
<DocScrutinizer05> kyak: exactly
<DocScrutinizer05> for a round_down I'd expect 5->4 and 3->2
<kyak> really the question is whether this behaviour is intended by round_down() authors or it is just an effect of their implementation
<DocScrutinizer05> actually 7,6,5->4
<DocScrutinizer05> clipping functions are widely used, and as I said are available as opcode in several ISA
<eintopf> :o
jow_lapt1p is now known as jow_laptop
<DocScrutinizer05> can't recall the usual name of c/whatever high level language of that function
<DocScrutinizer05> it's prolly not max()
<DocScrutinizer05> language name of that function. Pardon my french
<kyak> i wonder how round_down() would behave if we supply y > x...
<larsc> returns 0
<larsc> as it should
* eintopf used round_down() in some kernel code
<kyak> anyway, i conclude that this function is weird :)
<kyak> eintopf: do you use it to round down to nearest power of two or to arbitraty power of two?
<DocScrutinizer05> I guess usually the compiler converts that functio (let's call it max(x, y) ) into code rather than a function call
<kyak> and the question is - how do you know what's that 'nearest' in advance?
<DocScrutinizer05> but actually I wonder how compiler would know that y is always a power of 2 so it can create optinized code
<eintopf> I use it for the nearest
<kyak> to use this function, the developer must know in advance the value he wants to round down to.. that's weird
<eintopf> some RFC payload attributes use the nearest divide by 8
<DocScrutinizer05> kyak: the value you want to round down to is your upper limit of range
<larsc> kyak: round_down() returns the nearest value that is smaller or equal to x and is also a multiple of y
<DocScrutinizer05> e.g. clip values calculated in a 32bit register to 16bit
<DocScrutinizer05> or 15 bit when the target is a signed int16
<larsc> DocScrutinizer05: that would be clamp()
<DocScrutinizer05> sounds good
<DocScrutinizer05> aiui round_down is doing exactly that
<kyak> ok, it's more clear now
<DocScrutinizer05> actually a clamp diode does exactly that for a voltage on an input pin :-)
<larsc> DocScrutinizer05: round_down() does something else
<DocScrutinizer05> then I didn't get the explanation what round_down is doing
<larsc> round_down(x, y) return a value z for which x >= z > x-y and z is a multiple of y
<DocScrutinizer05> ooh
<DocScrutinizer05> thanks!
<larsc> round_up(x, y) return a value z for which x <= z < x+y and z is a multiple of y
jekhor has quit [Ping timeout: 256 seconds]
<DocScrutinizer05> that makes sense
<DocScrutinizer05> though for y=2^n...
pcercuei has joined #qi-hardware
<DocScrutinizer05> I 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)
<DocScrutinizer05> maybe lack of coffee
<eintopf> send patches, somebody of the global review will scream if it's not identical
<DocScrutinizer05> err clamp
<eintopf> :-)
<larsc> DocScrutinizer05: x=5 y=2
<larsc> round_down(5, 2) = 4
<larsc> clamp(5,2) = 2
<DocScrutinizer05> lack of coffee, evidently
<DocScrutinizer05> thanks, and sorry for the noise
<DocScrutinizer05> ok, to correct myself: I never seen round_down() in any ISA
<larsc> if y is a constant the compiler will internally compute ~(y - 1) so the whole operation boils down to a simple and
<DocScrutinizer05> :nod:
* DocScrutinizer05 ponders more coffee
<DocScrutinizer05> maybe I'm simply over the top with coffee, and rather need a walk and sth to eat
nicksydney has quit [Remote host closed the connection]
xiangfu has quit [Remote host closed the connection]
jekhor has joined #qi-hardware
<kyak> round_down(56,8) is 56
<kyak> now i'm confused again
<kyak> ah, because 56 is multiple of 8
Textmode has quit [Quit: "It was one dev, naked in a room with a carton of cigarettes, a thermos full of coffee and bourbon, and all his summoned angels."]
<kyak> or, in other words, 56 already has it's 3 lower bits cleared
<kyak> larsc: what's your use case for this function?
<larsc> only reading whole data sets from a sample fifo
<larsc> in the fifo I have X,Y and Z data
<larsc> and I want to make sure that I only read complete sets of data
<larsc> so I read the number of samples in the fifo and then rounddown() to the nearest multiple of 3
<kyak> i see, so you only grab XYZ, XYZ, XYZ. But what happens to the remaining X or XY, if they are in fifo?
<kyak> i mean, do you discard those samples by rounding?
jekhor has quit [Ping timeout: 250 seconds]
<kyak> linux.h is a treasury of things like that :)
jekhor has joined #qi-hardware
<kyak> why the hell they need a do-while loop in swap()?
<eintopf> maybe because to turn off compiler optimization
<eintopf> if it's a do { } while (0);
<kyak> yes , so the while loop basically doesn't exist
<kyak> what would compiler try to optimize here and what would be the consequences of this optimization?
<eintopf> it's not optimization
<eintopf> it's more turn off compiler weird things :-)
<eintopf> I don't know it exactly
<kyak> i can only hope that they know :)
<eintopf> maybe generate assembler code
<eintopf> with and without
<eintopf> then you know more
<kyak> there 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?
<kyak> eintopf: or maybe just a line of comment in source code would help. Maybe this is some stupid workaround for gcc v 1.0
<eintopf> i am not a compiler expert, sry
<kyak> 99.99% of people aren't. So leave a sensible comment, god damn them
<eintopf> comment is the code :-)
<eintopf> :X
<kyak> min_not_zero - return the minimum that is _not_ zero, unless both are zero
<kyak> oh, common!
<kyak> are they going to come up with a separate function for every unpossible use case?
<kyak> like the family of clamp_* functions
<kyak> actually, i have troubles understanding this phrase even in human language "minimum that is _not_ zero, unless both are zero"
<kyak> this requires some thinking :)
<kyak> and i imaging one day i would require such function, and then i would have no fucking clue that such exists in priceless linux.h
<larsc> it is acutally a quite useful function which helps to eliminate a lot of boilderplate code
<larsc> it is not that rare that for settings where 0 does not make sense it is regarded as infinity
<kyak> but this function can still return 0, despite of it's name
<kyak> and despite that you treat 0 as infinity
<larsc> only if both a and b is 0
<kyak> yes, sure
<larsc> which is correct
<larsc> min_zero_is_infitiy() is a guly name ;)
<larsc> min_but_zero_counts_as_infinity()
<kyak> anyway, i'm just too far away from this.. if you say it's useful, i trust you :)
<kyak> min_not_zero_except_both_zeros()
<kyak> --)
<kyak> larsc: so what happens to data in fifo that didn't fit into your multiple of three series?
<kyak> also, would it be possible to just read() from fifo in series of three?
<ysionneau> 12:06 < kyak> why the hell they need a do-while loop in swap()? < http://kernelnewbies.org/FAQ/DoWhile0
<kyak> ysionneau: oh, thanks@
<larsc> kyak: the data stays in the fifo until a full set is available
Jay7 has quit [Ping timeout: 240 seconds]
<kyak> larsc: but if you've already read the data from fifo (including the incomplete set), how do you put it back in fifo?
<larsc> I read the number of samples from the hardware
<larsc> then round that down to the nearest multiple of three
<larsc> and read that many samples from the fifo
<kyak> ok, i got it
<DocScrutinizer05> ((<kyak> i mean, do you discard those samples by rounding?)) those stay in FIFO for next time
<kyak> yep, that's clear now
<DocScrutinizer05> oops, seen larsc answered it a few lines up
<kyak> he did :)
Jay7 has joined #qi-hardware
<DocScrutinizer05> a FIFO usually implemented as ring buffer, with a pointer to data start and one to data end
<DocScrutinizer05> you fill the FIFO by incrementing pointer to end, and after reading n from pointer to start, you increment the pointer to start accordingly
<DocScrutinizer05> hw does same
jekhor has quit [Read error: Connection reset by peer]
jekhor has joined #qi-hardware
jekhor has quit [Ping timeout: 256 seconds]
jekhor has joined #qi-hardware
jekhor_ has joined #qi-hardware
jekhor has quit [Read error: Connection reset by peer]
jow_lapt1p has joined #qi-hardware
jow_laptop has quit [*.net *.split]
rz2k has joined #qi-hardware
jekhor has joined #qi-hardware
jekhor_ has quit [Ping timeout: 250 seconds]
jekhor has quit [Ping timeout: 245 seconds]
jow_lapt1p has quit [Ping timeout: 264 seconds]
jow_laptop has joined #qi-hardware
wej_ has quit [Ping timeout: 245 seconds]
wej has joined #qi-hardware
qwebirc49265 has joined #qi-hardware
wolfspraul has quit [Ping timeout: 264 seconds]
qwebirc49265 has quit [Ping timeout: 246 seconds]
wolfspraul has joined #qi-hardware
pcercuei has quit [Quit: leaving]
pcercuei has joined #qi-hardware
newcup has joined #qi-hardware
Textmode has joined #qi-hardware
pcercuei has quit [*.net *.split]
wolfspraul has quit [*.net *.split]
rozzin has quit [*.net *.split]
uwe_mobile has quit [*.net *.split]
Textmode has quit [*.net *.split]
zear has quit [*.net *.split]
tumdedum has quit [*.net *.split]
Ornotermes has quit [*.net *.split]
apelete has quit [*.net *.split]
DocScrutinizer05 has quit [*.net *.split]
DocScrutinizer51 has quit [*.net *.split]
ysionneau has quit [*.net *.split]
rz2k has quit [*.net *.split]
newcup has quit [*.net *.split]
dos1 has quit [*.net *.split]
rodgort has quit [*.net *.split]
jow_laptop has quit [*.net *.split]
qi-bot has quit [*.net *.split]
Guest53419 has quit [*.net *.split]
hozer has quit [*.net *.split]
kyak has quit [*.net *.split]
uwe_ has quit [*.net *.split]
panda|z has quit [*.net *.split]
lindi- has quit [*.net *.split]
roh has quit [*.net *.split]
eintopf has quit [*.net *.split]
freespace has quit [*.net *.split]
whitequark has quit [*.net *.split]
mirko has quit [*.net *.split]
ChanServ has quit [*.net *.split]
wej has quit [*.net *.split]
idundidit has quit [*.net *.split]
larsc has quit [*.net *.split]
dandon has quit [*.net *.split]
Luke-Jr has quit [*.net *.split]
kanzure_ has quit [*.net *.split]
mth has quit [*.net *.split]
porchao has quit [*.net *.split]
woakas has quit [*.net *.split]
newcup has joined #qi-hardware
jow_laptop has joined #qi-hardware
Textmode has joined #qi-hardware
wej has joined #qi-hardware
kanzure_ has joined #qi-hardware
qi-bot has joined #qi-hardware
zear has joined #qi-hardware
rz2k has joined #qi-hardware
mth has joined #qi-hardware
dandon has joined #qi-hardware
idundidit has joined #qi-hardware
lindi- has joined #qi-hardware
Luke-Jr has joined #qi-hardware
hozer has joined #qi-hardware
Guest53419 has joined #qi-hardware
panda|z has joined #qi-hardware
uwe_ has joined #qi-hardware
kyak has joined #qi-hardware
dos1 has joined #qi-hardware
rodgort has joined #qi-hardware
mirko has joined #qi-hardware
whitequark has joined #qi-hardware
freespace has joined #qi-hardware
eintopf has joined #qi-hardware
roh has joined #qi-hardware
porchao has joined #qi-hardware
larsc has joined #qi-hardware
ChanServ has joined #qi-hardware
apelete has joined #qi-hardware
ysionneau has joined #qi-hardware
DocScrutinizer05 has joined #qi-hardware
DocScrutinizer51 has joined #qi-hardware
tumdedum has joined #qi-hardware
woakas has joined #qi-hardware
Ornotermes has joined #qi-hardware
pcercuei has joined #qi-hardware
wolfspraul has joined #qi-hardware
uwe_mobile has joined #qi-hardware
rozzin has joined #qi-hardware
dandon has quit [*.net *.split]
Luke-Jr has quit [*.net *.split]
kanzure_ has quit [*.net *.split]
mth has quit [*.net *.split]
porchao has quit [*.net *.split]
woakas has quit [*.net *.split]
dos1 has quit [Read error: Connection reset by peer]
dandon has joined #qi-hardware
Luke-Jr has joined #qi-hardware
kanzure_ has joined #qi-hardware
mth has joined #qi-hardware
woakas has joined #qi-hardware
porchao has joined #qi-hardware
jow_lapt1p has joined #qi-hardware
jow_laptop has quit [Write error: Broken pipe]
dos1 has joined #qi-hardware
nicksydney has joined #qi-hardware
pcercuei has quit [Quit: dodo]
wolfspraul has quit [Ping timeout: 245 seconds]
wolfspraul has joined #qi-hardware