|
b0lt posted:
code:
|
# ? Mar 20, 2013 21:58 |
|
|
# ? May 17, 2024 14:51 |
|
b0lt posted:
C code:
|
# ? Mar 20, 2013 21:59 |
|
Doctor w-rw-rw- posted:
Nope; if retflag is 10, we want to store 0, not 2. I'm not sure there's a clever bitwise way to do this. Edit: retflag = !((retflag >> 2) || (retflag << 30))*2 maybe? Volmarias fucked around with this message at 22:07 on Mar 20, 2013 |
# ? Mar 20, 2013 22:03 |
|
Doctor w-rw-rw- posted:
code:
|
# ? Mar 20, 2013 22:09 |
|
baquerd posted:Other than readability, I just don't see a huge problem here. Volmarias posted:Edit:
|
# ? Mar 20, 2013 22:11 |
|
Once again, we are the horror. This discussion should have happened 8 pages ago.
|
# ? Mar 20, 2013 22:28 |
|
Presto posted:What have I done? I'm honestly curious if there's a good way to do this using dumb bit twiddling and no ==
|
# ? Mar 20, 2013 22:32 |
|
Volmarias posted:I'm honestly curious if there's a good way to do this using dumb bit twiddling and no == If you want to do a == comparison use XOR not AND. If you XOR two numbers you'll get all 0's if and only if they're equal. ... I'm 99% sure - bit manipulation always makes me double check my results because you can screw stuff up really fast.
|
# ? Mar 20, 2013 22:55 |
|
Suspicious Dish posted:You wrote your own OS? Yikes. No, that was my fault for not providing the whole context. He did specify they had no third-party code from the database layer on up. We implement stuff that usually goes on top of an existing Oracle, MySQL or Microsoft DB. The database drivers in our code, though, well, here's a paraphrase from my training manual: "The following is the syntax for calling SQL statements within the code. You should only consider using it when our existing drivers cannot perform the necessary query."
|
# ? Mar 20, 2013 22:59 |
|
code:
someone actually did this on the codebase i'm on except it was with a (similarly broken) xor swap. The commit message is verbatim. e: probably better without context. code:
bucketmouse fucked around with this message at 06:10 on Mar 21, 2013 |
# ? Mar 20, 2013 23:15 |
|
code:
|
# ? Mar 20, 2013 23:49 |
|
return retflag
|
# ? Mar 21, 2013 05:31 |
|
I like that it can be either 2 or 0.
|
# ? Mar 21, 2013 06:19 |
|
bucketmouse posted:
Is there ever a reason to use an XOR swap if you're not writing an optimizing compiler?
|
# ? Mar 21, 2013 06:24 |
|
No, and I'm pretty sure gcc is smart enough to optimize divisions into right shifts as well.
|
# ? Mar 21, 2013 06:26 |
|
hobbesmaster posted:Is there ever a reason to use an XOR swap if you're not writing an optimizing compiler? Even then, you probably shouldn't be writing or generating a xor swap in most cases. With all your optimizations on and no debugging aids left in the generated code, an assignment from one local variable to another should result in zero additional instructions being generated. The register allocator should just say "Okay so after this point the variable iButtes is in ecx instead of ebx, and ebx is now free for me to put something else in". Copying ecx to ebx just so the variable is always in the same register is pretty much a waste of time and register space1. And if you're talking about xor-swapping the contents of two memory addresses, you also have to ensure that they don't alias, otherwise you really gently caress things up. [1] Unless you're in the middle of a loop - but even then you'd still want to do any patching up at the end of each loop iteration, as that's more amenable to other optimizations - or potentially don't even do it at all if you're also unrolling the loop. Also note that a bunch of platforms have a straight-up "swap" instruction, which is far faster than doing three successive bitwise operations that all depend on the previous one.
|
# ? Mar 21, 2013 08:14 |
|
yaoi prophet posted:No, and I'm pretty sure gcc is smart enough to optimize divisions into right shifts as well.
|
# ? Mar 21, 2013 14:49 |
|
code:
|
# ? Mar 21, 2013 18:03 |
|
PrBacterio posted:That's not actually possible for it to do that, due to a right-shift having slightly different semantics from a division by a power of two. A(n arithmetic) right-shift is equivalent to a division rounding down (towards negative infinity), whereas a regular integer divide will round towards zero. Most compilers will therefore generate a sequence of instructions for a division by a constant power of two, that includes a right-shift plus some patching-up code to fix the rounding. Do flags like unsafe-math remove those checks?
|
# ? Mar 21, 2013 18:15 |
|
PrBacterio posted:That's not actually possible for it to do that, due to a right-shift having slightly different semantics from a division by a power of two. A(n arithmetic) right-shift is equivalent to a division rounding down (towards negative infinity), whereas a regular integer divide will round towards zero. Most compilers will therefore generate a sequence of instructions for a division by a constant power of two, that includes a right-shift plus some patching-up code to fix the rounding. This shouldn't be necessary for an unsigned type.
|
# ? Mar 21, 2013 20:43 |
|
hobbesmaster posted:Do flags like unsafe-math remove those checks? No, unsafe-math doesn't change the semantics of signed division. It's more about permitting floating-point transforms that potentially change the precision of results.
|
# ? Mar 21, 2013 21:09 |
|
That Turkey Story posted:This shouldn't be necessary for an unsigned type.
|
# ? Mar 21, 2013 22:23 |
|
Sedro posted:And bit shifts are implementation defined for negative integers anyway, right? They technically are, but virtually every implementation will bit-shift a negative integer by doing whatever the underlying platform does most efficiently. It's not particularly relevant to compiler optimizations anyway - note that converting a source-level division by a power of two into a source-level right shift doesn't actually buy you anything on its own - you only improve anything if you can replace a division in the generated code with something more efficient.
|
# ? Mar 21, 2013 23:55 |
|
The best part about the xor-swap story is that it didn't slip by unnoticed and was reverted quickly. Anyone have planning horrors? A friend who does rich media site prototypes/mockups forwarded me this.. uh, whatever it is, as provided by the client. Thankfully they talked him down into something sensible with tabs.
|
# ? Mar 21, 2013 23:56 |
|
You're just too educated stupid to understand information cube.
|
# ? Mar 22, 2013 00:19 |
|
VRML's comeback begins now!
|
# ? Mar 22, 2013 00:24 |
|
Thinking xor swap at a high level is an optimization on modern machines and modern compilers is a horror.
|
# ? Mar 22, 2013 04:39 |
|
bucketmouse posted:The best part about the xor-swap story is that it didn't slip by unnoticed and was reverted quickly. Is this for a time cube redesign?
|
# ? Mar 22, 2013 06:06 |
|
hobbesmaster posted:Is this for a time cube redesign? yaoi prophet already made the joke.
|
# ? Mar 22, 2013 06:46 |
|
bucketmouse posted:The best part about the xor-swap story is that it didn't slip by unnoticed and was reverted quickly. I love that they're so enamored by the metaphor that they don't see that they break it several times. "Creation" tasks in the Information cube, Archive coin actually has 3 different tasks. Seems the pyramid was originally just for Proposals too.
|
# ? Mar 22, 2013 07:25 |
|
bucketmouse posted:The best part about the xor-swap story is that it didn't slip by unnoticed and was reverted quickly. Holy hell.
|
# ? Mar 22, 2013 12:48 |
|
Carthag posted:I love that they're so enamored by the metaphor that they don't see that they break it several times. "Creation" tasks in the Information cube, Archive coin actually has 3 different tasks. Seems the pyramid was originally just for Proposals too. The coin has three faces, what's the problem?
|
# ? Mar 22, 2013 18:24 |
|
pokeyman posted:The coin has three faces, what's the problem? Heads, tails, and 'file not found'?
|
# ? Mar 22, 2013 18:30 |
|
https://code.google.com/p/go/issues/detail?id=5107 posted:
I think he's upset about javadoc?
|
# ? Mar 22, 2013 19:10 |
|
pokeyman posted:The coin has three faces, what's the problem? Someone took part of a Discworld novel a little too seriously, obviously.
|
# ? Mar 22, 2013 19:41 |
|
Volmarias posted:I think he's upset about javadoc? Check out gomang.org - he clearly wants go to better adhere to the teachings of the Buddha as explained by Je Tsong Khapa. Deep poo poo, man.
|
# ? Mar 22, 2013 19:52 |
|
I just repurposed PUT as DELETE because Google App Engine doesn't support DELETE and PUT wasn't being used for anything else.
|
# ? Mar 22, 2013 20:51 |
|
Coding horror following a teaching horror (neither mine): C++ Design and define an interface called card.h that exports the following interface functionality: A type Rank that allows you to represent the rank of a card A type Suit that allows you to represent the suit of a card A type Card that combines (consists of) a rank and a suit. A function Card NewCard(Rank rank, Suit suit) that creates a Card from the rank and suit values Two functions, Rank GetRank(Card card) and Suit GetSuit(Card card), that allow the client to get the rank and suit of a Card value. A function string CardName(Card card) that returns a string identifying the card. Design Decisions Rank and Suit should be defined as enumerations. Card should be defined as a struct (record).
|
# ? Mar 23, 2013 06:11 |
|
Murodese posted:Coding horror following a teaching horror (neither mine): What are the horrors?
|
# ? Mar 23, 2013 06:16 |
|
|
# ? May 17, 2024 14:51 |
|
Can't use numeric constants as enumerated values, for one thing.
|
# ? Mar 23, 2013 07:37 |