#qi-hardware IRC log for Saturday, 2013-03-23

wpwrakif you have signed and unsigned, promotion is to unsigned11:25
wpwrakthat's why things like -1 > 1U yield "true"11:25
kyakwhy does -1+1U yield 0 then, not -2? :)11:48
kyaki mean, maxint/2+211:49
wpwrakbecause 0xfff....+1 is 0+carry :)11:49
wpwrak-1 is not maxuint/2 (or anything nearby) but maxuint-111:49
wpwrakerr, just maxuint of courwe11:50
wpwraki.e., it's 0xff...ff11:50
kyaknot according to wikipedia :)11:51
wpwrakhuh ?11:51
kyak0xff is -011:51
kyak0xff-1 is -111:51
whitequark0xff is -1 in 2's complement machines11:52
wpwrakwell, i'm talking about two's complement11:52
kyakoh, ok, i'm sorry11:52
wpwrakwhich is what almost everything uses. if you can find a machine that used one's complement natively (good luck with that :), then you're right with -011:52
kyakso then -1+1U, promoted to unsigned int, is 0xff+0x01 - should be 0x01?11:53
whitequarkkyak: no. 0xff + 0x01 = 0x100, but it's then truncated to 8 bits11:54
whitequarki.e. 0x0011:54
kyakoh! i see!11:54
kyaknow i understand how it wraps aroudn zero..11:55
kyakwhat is we have a machine where integer size is 8bit?11:56
kyakhow would it be able to hold 0x100?11:57
whitequarkkyak: it doesn't hold 0x10011:57
whitequarkyou can emulate that by using two 8bit integers manually11:58
whitequarkor let your compiler do that11:58
whitequarkthen each arithmetic operation will take more than one instruction. much more, usually11:58
kyakhow would it work without emulation?11:58
whitequarkkyak: it won't11:59
wpwrakthe one extra bit is usually represented by a "carry" flag. so in assembler, you'd just use that if you need to make larger operations. in C, the carry flag is not accessible.12:00
whitequark0x100 is not stored anywhere12:00
whitequark^ that12:00
kyakwpwrak: does this carry flag essentially lets us use 9-bit integers or what?12:01
wpwraksort of, yes12:01
kyakcan we use two carry flags? :)12:01
wpwrake.g., you'd implement a 16 bit addition on an 8 bit cpu like this:12:01
wpwrakmov r0, a_low; mov r1, a_high; mov r2, b_low; mov r3, b_high12:02
wpwrakadd r4, r0, r2; addc r5, r1, r312:02
wpwrakmov result_low, r4; mov result_high, r512:03
wpwrak"add" would be addition without carry while "addc" would be addition with carry. i.e., "add" does A+B while "addc" does A+B+C, where A and B are the summands and C is the carry bit.12:04
wpwrakboth add and addc would set the carry bit if the result wraps around 0xff12:04
wpwrakthe same concept applies to larger word sizes. i.e., if your cpu is 32 bits and you want to implement uint64_t addition, you'd use exactly the same algorithm12:05
kyakyep, that's clear. .This is something you would do if you want to keep your result and not to overflow12:05
kyakso if i do a -1+1U, and compile it for a machine with 8-bit integer size, i would suddenly get all of this extra code?12:08
kyakwhat would happend if r0 holds 0xff, r1 holds 0x01, and i do add r3, r2, r1?12:09
kyakhat's going to be in r3?12:10
wpwrakkyak: r3 would be 0x00 (0xff+0x01 is  255 + 1 = 0 (mod 256))14:59
wpwrakthings would be a little different if you do this in C. e.g., int x = (unsigned char ) -1+1; would result in 25615:01
kyakwpwrak: how is (mod 256) calculated if 256 (0x100) is not stored anywhere according to whitequark?15:44
wpwrakin the assembler example ? well, it's implicit. (mod 256) means that you only have 8 bits15:57
wpwrakmaybe it becomes clearer if you picture it as an adder: each bit of the adder has three inputs and two outputs. the inputs are A and B, plus the Carry from the previous bit16:05
wpwrakthe outputs are the sum (just one bit) and the carry to the next bit16:05
wpwrakthe output is result = (A+B+Cin) & 1; carry_out = (A+B+Cin) >> 1;16:06
wpwrakyou have an adder for each bit, with the carry bits connected from LSB to MSB. Cin of LSB is either 0 or the carry flag, depending on whether you have an "add" or an "add-with-carry" operation16:07
wpwrakthis is what it looks like: http://en.wikipedia.org/wiki/Adder_(electronics)16:07
larscif it helps think of it as AND 0xff rather than mod 25616:12
wpwrakor just a bit falling off the edge of the world :)16:13
wpwraka sacrifice to entropy16:14
larscthe lemming bit16:14
wpwrakwe should patent the carry as "lemming-bit catching aparatus". then sure intel, arm, etc. for a few cubic-gazillions16:16
kyakheh :)16:21
kyakwpwrak: thanks for explanation16:22
wpwraki hope i made it clearer :)16:25
kyakyou did16:25
kyakand and found some pictures of 8 bit adders16:25
DocScrutinizer05((<wpwrak> this is what it looks like: http://en.wikipedia.org/wiki/Adder_(electronics) )) which is what I built with Braun Lectron for our 150 year aniversary at my highshcool, been 13 y o iirc16:50
DocScrutinizer05I built if from memory/designing it realtime in my mind16:51
DocScrutinizer05and I actually used simple NAND /NOR gates only16:51
DocScrutinizer05actually been a 4bit adder16:52
DocScrutinizer05oops, I think I also had XOR16:56
DocScrutinizer05and I must've been 15 already16:57
DocScrutinizer05or 1416:57
kyakdid you mean you were 0xE? :)16:58
DocScrutinizer05there are only 10 kind of people16:59
DocScrutinizer05those who know binary and those who don't17:00
DocScrutinizer05kyak: it should be mentioned maybe that you usually have only one ALU wide carry flag (and one sign flag), it gets used for all ADDC (and SUBC, and a few others) operations, no matter which registers are the operands and which the result17:19
wpwrakat 13 you had your 150th anniversary ? are you a very small dog ? :)17:21
DocScrutinizer05my highschool had 15017:21
DocScrutinizer05ding says "secondary school"17:23
DocScrutinizer05while "highschool" seems to be no english but a german word X-P17:23
DocScrutinizer05and gymnasium is for sure a false friend :-P17:24
DocScrutinizer05I prepared some show-off stuff for physics, in chemistry section a mad teacher made a ~10ml of trinitroglycerene17:26
DocScrutinizer05my adder went mad each time the van-der-graaf nearby went "BANG" with a one meter spark. In chemistry all clothes trembled each time the teacher did a BANG with one drop of his stuff17:28
DocScrutinizer05the highlight of the day been when I watched this teacher burning down the remaining 9.5ml of nitro17:29
DocScrutinizer05at end of the day17:30
wpwrakthat was when they started building the new school ?17:30
DocScrutinizer05I probably thought exactly same in that moment, but amazingly enough nothing specacular happened17:30
DocScrutinizer05he poured the whole shit into a white ceramic bowl and burned it down with a bunsen17:32
DocScrutinizer05about as spectacular as a candle with a slightly wet wick17:32
wpwraki'm sure the pouring needed a steady hand, though :)17:33
DocScrutinizer05I think he didn't pour it from extreme height into that bowl, yeah17:33
DocScrutinizer05but actually that stuff is quite inpredictable but usually less critical than urban legends suggest. In even younger years I tried to produce nitro maybe 50 times, and I was *sooo* sure this time it worked, everything exactly as it should, reaction observed, result like it should. Alas (or luckily) it _never_ exploded when I had a drop of it fall from 1st floor to stone pavement17:36
DocScrutinizer05so every single time the content of the glaspipe ended in the bathroom sink and got flushed by plenty of tap water ;-)17:37
wpwraksometimes, failure can keep you out of juvenile jail :)17:37
DocScrutinizer05yeah :-)17:37
larscor out of the hospital17:38
DocScrutinizer05some austrian ashole here shipped letters with nitro and electric ignition some years ago17:39
DocScrutinizer05none of them exploded prematurely17:39
DocScrutinizer05some neonazi asshole17:40
DocScrutinizer05several people lost fingers or a hand17:41
DocScrutinizer05usually the secretary of those he meant to hurt17:41
DocScrutinizer05>>However she did not open the letter; this being done by her assistant who was subsequently injured by the bomb<<17:44
DocScrutinizer05those were nitro in a macdonalds straw17:45
DocScrutinizer05CR2023 and some small electr(on)ics, and a spark device plugged into one end of straw17:50
wpwrakdid they ever catch him ?17:58
DocScrutinizer05I seem to recall he even had an "accident" with one of his creations ;-P18:06
DocScrutinizer05ooh, no. http://de.wikipedia.org/wiki/Franz_Fuchs_(Attentäter)18:07
whitequarkwhoever wrote the http://de.wikipedia.org/wiki/Rohrbombe page is a terrible person18:10
Action: whitequark just financed the extortioners in ISO: http://imgur.com/tATMmEs18:11
wpwrakDocScrutinizer05: attempted suicide, followed a few years later by a successful one. not too bad in terms of poetic justice.18:16
wpwraknice ... xpdf is broken in ubuntu 12.10, too (was in 12.04 as well). i suppose the whole QA department of ubuntu was reassigned to work on their "value-added" gadgets ...18:21
DocScrutinizer05who's using buntkuh? :-o18:21
wpwrak(fortunately, building xpdf from source does solve the problem)18:22
wpwrakwell, it used to be quite good. but recently they seem to be confused.18:23
DocScrutinizer05I wholeheartedly agree with xkcd here, regarding buntkuh18:23
whitequarkworst of all... I don't even see how is that (proprietary services / stupid forking / mobile devices) going to help them18:24
wpwrak;-) naw, once you apt-get remove consolekit it's almost clean :)18:24
whitequarkhuh? what's up with consolekit?18:25
wpwrakremoving it gets rid of a number of things i don't want :)18:36
whitequarkoh, the dependency hell18:36
whitequarkthe person who wrote ruby's parse.y was on some serious drugs.18:37
wpwrakmy preferred session goes like this: boot, log in at the /bin/login prompt, startx, ... weeks pass18:37
whitequarkI think I've poured around 2 weeks into rewriting it in a sane way already18:37
whitequark(why? need precise location reporter, otherwise type inferencer's error messages are unreadable)18:37
wpwrakmessy grammar ? or just poor implementation ?18:38
whitequarkthese two, combined18:38
whitequarkthe grammar is incredibly overloaded, { for example has four distinct context-specific meanings18:38
whitequarkplus the implementation is utterly insane18:38
wpwraksounds like fun :)18:38
whitequarkit depends on bison actions with side effects changing stacked state in the lexer in some way I *still* do not really understand18:39
whitequarkI even bought the ISO standard in a hope that it would clear some of this mess18:39
whitequarkwell, it kinda helped, but not enough18:39
whitequarkworst of all18:40
whitequarkI think I began to understand this stuff ~today. and do you know why is it all needed?18:40
whitequarkto handle two special cases of really, really screwed up syntactic combinations which are so utterly inconvenient, apart from being bad practice, that I think they weren't written by anyone ever once18:41
whitequarkand I mean things like a while..do (not just while) loop in the condition (not body!) clause of which there is another while..do loop18:42
whitequarkI mean I didn't even *know* ruby has while..do loops before I started hacking its parser.18:42
whitequarkneither did anyone I have asked since18:42
wpwrakwriting a parser, compiler, or similar often furthers your understanding of the language ;-)18:43
whitequark... reverse-engineering a parser.18:44
whitequarkreverse-engineering a frikkin open-source parser.18:44
whitequarkit is easier to just treat it as a black box...18:44
whitequarkthe C lexer has three nested levels of switches with fallthoughs and breaks and continues *and* plenty of gotos18:45
whitequarkthis could serve as a poster example of why you should never, ever, use C to write complex software.18:46
lekernelwhitequark, if you need standards, I¬¬¬ publications etc. send me an email. I have access to many of those.20:06
whitequarklekernel: too late in this case, but thanks for the offer!20:09
whitequarkI'll keep that in mind20:09
lekernelthey're also available for free at your local (physical) library, sometimes20:15
whitequarkdoubt so20:15
whitequarkwell, a !" will probably be available.20:16
whitequark(a CIS international standard.)20:16
whitequarkaka GOST.20:16
--- Sun Mar 24 201300:00

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