Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Doctor w-rw-rw-
Jun 24, 2008

b0lt posted:

code:
retflag = (retflag == 2) * 2;

code:
return retflag & 2;

Adbot
ADBOT LOVES YOU

Cocoa Crispies
Jul 20, 2001

Vehicular Manslaughter!

Pillbug

b0lt posted:

code:
retflag = (retflag == 2) * 2;

C code:
if (retflag != 2) retflag = 0;

Volmarias
Dec 31, 2002

EMAIL... THE INTERNET... SEARCH ENGINES...

Doctor w-rw-rw- posted:

code:
return retflag & 2;

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

b0lt
Apr 29, 2005

Doctor w-rw-rw- posted:

code:
return retflag & 2;

code:
return (retflag == 2) << 1;

Presto
Nov 22, 2002

Keep calm and Harry on.

baquerd posted:

Other than readability, I just don't see a huge problem here.
It's not a big problem, just pretty dumb.

Volmarias posted:

Edit:
retflag = !((retflag >> 2) || (retflag << 30))*2 maybe?
What have I done? :ohdear:

Blotto Skorzany
Nov 7, 2008

He's a PSoC, loose and runnin'
came the whisper from each lip
And he's here to do some business with
the bad ADC on his chip
bad ADC on his chiiiiip
Once again, we are the horror. This discussion should have happened 8 pages ago.

Volmarias
Dec 31, 2002

EMAIL... THE INTERNET... SEARCH ENGINES...

Presto posted:

What have I done? :ohdear:

I'm honestly curious if there's a good way to do this using dumb bit twiddling and no ==

Goreld
May 8, 2002

"Identity Crisis" MurdererWild Guess Bizarro #1Bizarro"Me am first one I suspect!"

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.

bewilderment
Nov 22, 2007
man what



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."

bucketmouse
Aug 16, 2004

we con-trol the ho-ri-zon-tal
we con-trol the verrr-ti-cal
code:
retflag = (retflag == 2) << 2;
git add .; git commit -a -m 'fixed major bottleneck in the thing'; git push; break for food

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:
// list of all possible objects to use as wife
$wifeList = array( 1010, 1011, 1012, 1013 );

bucketmouse fucked around with this message at 06:10 on Mar 21, 2013

No Safe Word
Feb 26, 2005

code:
try {
    1 / (retflag - 2);
    retflag = 0;
} catch (DivideByZeroException) {
    
} 

ChickenOfTomorrow
Nov 11, 2012

god damn it, you've got to be kind

return :airquote:retflag:airquote:

evensevenone
May 12, 2001
Glass is a solid.
I like that it can be either 2 or 0.

hobbesmaster
Jan 28, 2008

bucketmouse posted:

code:
retflag = (retflag == 2) << 2;

git add .; git commit -a -m 'fixed major bottleneck in the thing'; git push; break for food

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:

// list of all possible objects to use as wife
$wifeList = array( 1010, 1011, 1012, 1013 );

Is there ever a reason to use an XOR swap if you're not writing an optimizing compiler?

Opinion Haver
Apr 9, 2007

No, and I'm pretty sure gcc is smart enough to optimize divisions into right shifts as well.

Jabor
Jul 16, 2010

#1 Loser at SpaceChem

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.

PrBacterio
Jul 19, 2000

yaoi prophet posted:

No, and I'm pretty sure gcc is smart enough to optimize divisions into right shifts as well.
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.

ChickenOfTomorrow
Nov 11, 2012

god damn it, you've got to be kind

code:
for (s = (char *)h + hlen - blen; s >= h; --s){
        if (strncmp(s, b, blen) == 0){
          return s;
        } // found it
    } // keep looking
    // THERE MAY BE PROBLEMS WITH THIS but at this point IDK, so watch out for segmentation faults
oh, ok, thanks for the warning

hobbesmaster
Jan 28, 2008

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?

That Turkey Story
Mar 30, 2003

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.

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe

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.

Sedro
Dec 31, 2008

That Turkey Story posted:

This shouldn't be necessary for an unsigned type.
And bit shifts are implementation defined for negative integers anyway, right?

Jabor
Jul 16, 2010

#1 Loser at SpaceChem

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.

bucketmouse
Aug 16, 2004

we con-trol the ho-ri-zon-tal
we con-trol the verrr-ti-cal
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.

Opinion Haver
Apr 9, 2007

You're just too educated stupid to understand information cube.

Contra Duck
Nov 4, 2004

#1 DAD
VRML's comeback begins now!

comedyblissoption
Mar 15, 2006

Thinking xor swap at a high level is an optimization on modern machines and modern compilers is a horror.

hobbesmaster
Jan 28, 2008

bucketmouse posted:

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.



Is this for a time cube redesign?

shrughes
Oct 11, 2008

(call/cc call/cc)

hobbesmaster posted:

Is this for a time cube redesign?

yaoi prophet already made the joke.

Carthag Tuek
Oct 15, 2005

Tider skal komme,
tider skal henrulle,
slægt skal følge slægters gang



bucketmouse posted:

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.



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.

Volmarias
Dec 31, 2002

EMAIL... THE INTERNET... SEARCH ENGINES...

bucketmouse posted:

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.



Holy hell. :psyduck:

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

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?

Kilson
Jan 16, 2003

I EAT LITTLE CHILDREN FOR BREAKFAST !!11!!1!!!!111!

pokeyman posted:

The coin has three faces, what's the problem?

Heads, tails, and 'file not found'?

Volmarias
Dec 31, 2002

EMAIL... THE INTERNET... SEARCH ENGINES...

https://code.google.com/p/go/issues/detail?id=5107 posted:


Reported by pedromor...@gmail.com, Today (92 minutes ago)

Ok ok lets put a nil into things we dont have to do it like

First question for any coder..

Is that all we want to do is explain bits of code, and its runningz what it does..
Hopefully there is a lot of coders looking at it cos we can auto gen documentation..

Now there are a few ways to do this..
The first concept is to..
For the doco manager is to
create the file that explain and do things and a manual

The nexxt concept is to interlink into stuff

What developers want
?
NOrmally the developer is do busy coding u have to interupt It whet


I better explain how this works and all langs work different ways
Java
/* Is Documentated
*/
this(


What GoLand should be


Is a simple commentrty and link
Aas we gonna use gomang.org aaas our voerifier..
Si all the comment we spend our tiimes will come into fuitiion


We expectsimple markup eg
/* This IS IT
*/

Its pissing me off bigtimer.. I waanna wrie code

I think he's upset about javadoc?

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



pokeyman posted:

The coin has three faces, what's the problem?

Someone took part of a Discworld novel a little too seriously, obviously.

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



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.

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed
I just repurposed PUT as DELETE because Google App Engine doesn't support DELETE and PUT wasn't being used for anything else.

Murodese
Mar 6, 2007

Think you've got what it takes?
We're looking for fine Men & Women to help Protect the Australian Way of Life.

Become part of the Legend. Defence Jobs.
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).

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

Murodese posted:

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).



What are the horrors?

Adbot
ADBOT LOVES YOU

Bongo Bill
Jan 17, 2012

Can't use numeric constants as enumerated values, for one thing.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply