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
Jo
Jan 24, 2005

:allears:
Soiled Meat

JawnV6 posted:

Ugh what a stupid unreadable hack to zero out a register. I despise this 'xor trick'

I believe the xor trick is vestigial. Moves use to cost a lot more CPU than exclusive or in the early Pentium/AMD days, so it was very neat at the time.

EDIT: And apparently still is! \/\/ I'm not crazy!

Jo fucked around with this message at 07:47 on Sep 1, 2008

Adbot
ADBOT LOVES YOU

Scaevolus
Apr 16, 2007

Jo posted:

I believe the xor trick is vestigial. Moves use to cost a lot more CPU than exclusive or in the early Pentium/AMD days, so it was very neat at the time.

xor eax, eax is still faster than mov eax, 0

POKEMAN SAM
Jul 8, 2004

Scaevolus posted:

xor eax, eax is still faster than mov eax, 0

I have no problem with xor eax, eax. Maybe it's just from staring at it repeatedly, because when I see it I immediately think "eax = 0;"

Runaway Five
Dec 31, 2007
I hate gays almost as much as I hate good posting. Also, God is good. Amen
This is going to be a theory type of question.

I've always wanted to know how ID Software "did" the graphics for Wolfenstein3D.

http://www.youtube.com/watch?v=C00n4rDUMNo

There's a video of the game in action for those who have never played this amazing game. According to one website, it says they did it using Ray Tracing. However, I always thought ray tracing was a very expensive algorithm, and that Wolfenstein3D wasn't "real 3D" at all.

So, how did they pull it off using early 1990s DOS technology? I'm familiar with how graphics are done today. Is there a dumbed down version of Ray Tracing they used? How do you think they "stored" the contents of the world?

Did they literally shoot a ray for each pixel of the screen to see what got displayed?

KaeseEs
Feb 23, 2007

by Fragmaster
No. Wolf3d used 'ray-casting' to figure out how to scale 2d sprites in a 2.5d world; this involved (very roughly) shooting one ray per horizontal pixel on the screen (on period hardware, this would be between 320 and 640 rays), seeing when it hit something, and drawing the appropriate sprite(s) at the correct scale for the depth at which the ray hit. This is nowhere near as computationally intense as real raytracing.

JawnV6
Jul 4, 2004

So hot ...

Ugg boots posted:

Ugh, now I started posting on StackOverflow. It's not bad, but they're going to want to make a better "front page" because just listing off a bunch of seemingly random questions is kind of a clusterfuck.

I like the achievement style badges :D


Edit: What the gently caress does reputation represent? Is there some sort of formula based on badges and tags and stuff?

Edit 2: Found the formula.
Top rated article on the front pager, with 33 votes, 48 answers, 562 views:
Recommended Fonts for Programming?

Thank god, with this sort of crucial information I can finally ditch experts exchange.

tef
May 30, 2004

-> some l-system crap ->

JawnV6 posted:

Thank god, with this sort of crucial information I can finally ditch experts exchange.

http://beta.stackoverflow.com/questions/35185/finding-a-single-number-in-a-list#35190

quote:

Memory isn't always free, you know, so just because your time complexity is O(N) and mine is O(N*lgN) it doesn't mean that yours is better.

JawnV6
Jul 4, 2004

So hot ...

:suicide: There is so much wrong with the discussion on that page.

edit: I can't vote up or down without reputation? How do I get that? Do I want that?

edit2: I figured out how to get reputation: http://beta.stackoverflow.com/questions/36906/what-is-the-fastest-way-to-swap-values-in-c

JawnV6 fucked around with this message at 16:13 on Aug 31, 2008

Rabbi Dan
Oct 26, 2005

ASK ME ABOUT MY CREEPY FACEBOOK APP FOR STALKING GIRLS I DON'T KNOW
I'm trying to write some assembly language using an instruction set that only does 8-bit x 8-bit multiplication. The issue is, there are some situations where I'll have to multiply a small number (i.e. <= 255 base 10) by a bigger number (i.e. one that takes up 16 bits) and store the result in two 8-bit registers. I think it has to do with multiplying the 8-bit number by each byte of the 16-bit number and then adding something, but I'm not sure and I can't get it to work out.

Can anyone please help me out with this? Thanks.

Runaway Five
Dec 31, 2007
I hate gays almost as much as I hate good posting. Also, God is good. Amen

Rabbi Dan posted:

I'm trying to write some assembly language using an instruction set that only does 8-bit x 8-bit multiplication. The issue is, there are some situations where I'll have to multiply a small number (i.e. <= 255 base 10) by a bigger number (i.e. one that takes up 16 bits) and store the result in two 8-bit registers. I think it has to do with multiplying the 8-bit number by each byte of the 16-bit number and then adding something, but I'm not sure and I can't get it to work out.

Can anyone please help me out with this? Thanks.

I think this might help. It shows you how to multiply an 8 bit by a 16 bit and seems well documented.

http://www.dreamincode.net/code/snippet2205.htm

Rabbi Dan
Oct 26, 2005

ASK ME ABOUT MY CREEPY FACEBOOK APP FOR STALKING GIRLS I DON'T KNOW

Runaway Five posted:

I think this might help. It shows you how to multiply an 8 bit by a 16 bit and seems well documented.

http://www.dreamincode.net/code/snippet2205.htm

Thanks so much. Problem solved.

Jo
Jan 24, 2005

:allears:
Soiled Meat
I remember a lengthy discussion in these forums from some time ago about the merits of constant/static/final variables versus using #defines in a language.

Correct me if I'm mistaken: #define or set_name or whatever for a compiled language makes its way into the executable code while constant final static makes its way into a register. Is there really any performance difference in the grand scheme of things?

Scaevolus
Apr 16, 2007

Jo posted:

Correct me if I'm mistaken: #define or set_name or whatever for a compiled language makes its way into the executable code while constant final static makes its way into a register. Is there really any performance difference in the grand scheme of things?
:what: Usually when you compile things they "make their way" into the executable.

floWenoL
Oct 23, 2002

Jo posted:

Correct me if I'm mistaken: #define or set_name or whatever for a compiled language makes its way into the executable code while constant final static makes its way into a register. Is there really any performance difference in the grand scheme of things?

Nothing in this paragraph is correct.

pseudopresence
Mar 3, 2005

I want to get online...
I need a computer!

Jo posted:

I remember a lengthy discussion in these forums from some time ago about the merits of constant/static/final variables versus using #defines in a language.

Correct me if I'm mistaken: #define or set_name or whatever for a compiled language makes its way into the executable code while constant final static makes its way into a register. Is there really any performance difference in the grand scheme of things?

This is correct. #defines never make it past the L1 cache, due to register pressure.

Mustach
Mar 2, 2003

In this long line, there's been some real strange genes. You've got 'em all, with some extras thrown in.
Aw man, I'm under so much register pressure these days, I can hardly get it up.

TSDK
Nov 24, 2003

I got a wooden uploading this one

Jo posted:

Correct me if I'm mistaken: #define or set_name or whatever for a compiled language makes its way into the executable code while constant final static makes its way into a register. Is there really any performance difference in the grand scheme of things?
As others have said, this is very much the 'wrong' question to be asking. But the answer to the 'right' version of the question you're asking is that there should* be essentially no difference in performance between whatever form of final/const that your language provides, and whatever form of #define that your language provides.

The difference is that, in C++ for example, #defines don't respect type or scope and so are generally a much poorer alternative to using const variables.




* The relative truth of this statement may vary from language to language.

Jo
Jan 24, 2005

:allears:
Soiled Meat
Glad to get my daily dose of retardation out of the way. Thank you to those who responded.

I was suspicious that a #define would result in assembler like
code:
addq $400, %eax
while a constant would result in
code:
movq $400, %r1
addq %r1, %eax
but I'm glad to be mistaken.

Scaevolus
Apr 16, 2007

Jo posted:

code:
addq $400, %eax
code:
movq $400, %r1
addq %r1, %eax

AT&T syntax is gross

POKEMAN SAM
Jul 8, 2004

Jo posted:

I was suspicious that a #define would result in assembler like
code:
addq $400, %eax
while a constant would result in
code:
movq $400, %r1
addq %r1, %eax
but I'm glad to be mistaken.

This is what the optimizer is for.

Triple Tech
Jul 28, 2006

So what, are you quitting to join Homo Explosion?
Can you give any examples of the following scenario?

Let's someone/company/group makes an artificial intelligence-related technology. It learns and stores/saves its intelligence somehow. And it gets smarter, and does all these amazing things. Yay, everyone celebrates.

What does the intelligence look like? Like if you data dump that structure and reverse engineer it, would it look like the most mathematically sound solution? Or does it look like someone designed it? Or is it a nonsensical mishmash?

Know what I'm saying? Wasn't there an article on Slashdot about a helicopter learning how to fly... The flying routines it invents, are they as good as ones made by real people? Or do they do techniques that people never would have thought of?

csammis
Aug 26, 2003

Mental Institution
Evolutionary algorithms come up with extremely efficient solutions that often look batshit and inelegant compared to human designs. Take rotor's recently posted radio antenna, designed using an evolutionary algorithm.



edit: The thread in which rotor posted this

csammis fucked around with this message at 22:19 on Sep 3, 2008

Jsquared
Feb 13, 2008

by The Finn
#include <iostream>
#include <string>
using namespace std;

int main()

{
double month1Rainfall,
month2Rainfall;

string str;
cout << "First month, " << endl;
getline (cin,str);
cout << "First months rainfall, " << endl;
cin >> month1Rainfall;

string str2;
cout << "Second month, " << endl;
getline (cin,str2);
cout << "Second months rainfall, " << endl;
cin >> month2Rainfall;
return 0;
}


Im trying to store second months rainfall and month for a later period. However when I run this it allows me only to enter numbers for first months rainfall and letters for first month but when it comes to the second month it just "couts" everything and I cant enter anything. Why is this?

Lexical Unit
Sep 16, 2003

Hi there Jsquared. I know someone told you in the other thread that we have a thread for small questions. And this is indead a small questions thread... but we also have a thread for c++ related small questions ;)

The problem is the second cin is not removing the end line character from the buffer. Then getline() reads from the buffer until it reaches the end of the line, which is right there, so str2 becomes "" without stopping for user input.

[code] And put your code between code tags please, it looks nicer. [/code]

Jsquared
Feb 13, 2008

by The Finn

Lexical Unit posted:

Hi there Jsquared. I know someone told you in the other thread that we have a thread for small questions. And this is indead a small questions thread... but we also have a thread for c++ related small questions ;)

The problem is the second cin is not removing the end line character from the buffer. Then getline() reads from the buffer until it reaches the end of the line, which is right there, so str2 becomes "" without stopping for user input.

[code] And put your code between code tags please, it looks nicer. [/code]

Ok I'll post in there from now on. But this is what I came up with

code:
#include <iostream>
#include <string>
using namespace std;

int main()

{
	double month1Rainfall, 
		   month2Rainfall,
		   averageRainfall,
		   month3Rainfall;
string str1;
string str2;
string str3;

	cout << "First month, " << endl;
	cin >> str1;
	cout << "First months rainfall, " << endl;
	cin >> month1Rainfall;
	

	cout << "Second month, " << endl;
	cin >> str2;
	cout << "Second months rainfall, " << endl;
	cin >> month2Rainfall;

	cout << "Third month, " << endl;
	cin >> str3;
	cout << "Third months rainfall, " << endl;
	cin >> month3Rainfall;

	averageRainfall = (month1Rainfall + month2Rainfall + month3Rainfall) / 3;
		cout << "The average rainfall for "; cout << str1; cout << ", "; cout << str2; cout << ",and "; cout << str3; cout << " is "; cout << averageRainfall; "inches";


return 0;
}
seems to work although it may not be efficient.

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh

Jsquared posted:

code:
cout << "The average rainfall for ";
cout << str1;
cout << ", ";
cout << str2;
cout << ",and ";
cout << str3;
cout << " is ";
cout << averageRainfall; 
"inches"; // What

You're allowed to do all that in one statement. E.g. cout << foo << bar << baz << quux << endl;

unknown
Nov 16, 2002
Ain't got no stinking title yet!


I've got a small code segment that's overflowing a string with the following:

code:
(void)sprintf(buff, "%d", pagecount++);
(void)strcat(p->messageid, buff);
and my quick rewrite:

code:
(void)sprintf(buff, "%s%d", p->messageid, pagecount++);
p->messageid = buff;
Not being a programmer, I've got to ask: Is there a better way of stopping the overflow?

more falafel please
Feb 26, 2005

forums poster

unknown posted:

I've got a small code segment that's overflowing a string with the following:

code:
(void)sprintf(buff, "%d", pagecount++);
(void)strcat(p->messageid, buff);
and my quick rewrite:

code:
(void)sprintf(buff, "%s%d", p->messageid, pagecount++);
p->messageid = buff;
Not being a programmer, I've got to ask: Is there a better way of stopping the overflow?

You're not freeing the memory pointed to by p->messageid (assuming it was malloc()'d)

code:
size_t len = strlen(p->messageid) + sprintf(buff, "%d", pagecount++);
char* messageid = (char*)malloc(len+1);
strcpy(messageid, p->messageid);
strcat(messageid, buff);
free(p->messageid);
p->messageid = messageid;

Standish
May 21, 2001

unknown posted:

I've got a small code segment that's overflowing a string with the following:

code:
(void)sprintf(buff, "%d", pagecount++);
(void)strcat(p->messageid, buff);
and my quick rewrite:

code:
(void)sprintf(buff, "%s%d", p->messageid, pagecount++);
p->messageid = buff;
Is this leaking p->messageid?

quote:

Not being a programmer, I've got to ask: Is there a better way of stopping the overflow?
use snprintf instead:
code:
#define BUFF_SIZE 256 // or whatever
char buff[BUFF_SIZE];
snprintf(buff, BUFF_SIZE, "%s%d", p->messageid, pagecount++);
Also remember that if "buff" is a local array then you'll need to make a copy of it on the heap before you return from the function:
code:
free(p->messageid);
p->messageid = strdup(buff); // error checking omitted

Standish fucked around with this message at 15:23 on Sep 5, 2008

Mustach
Mar 2, 2003

In this long line, there's been some real strange genes. You've got 'em all, with some extras thrown in.
oops, ignore me

unknown
Nov 16, 2002
Ain't got no stinking title yet!


Standish posted:

Is this leaking p->messageid?

Yes - it overflows by a character (pushing a null into the beginning of the next string in memory, therefore basically making it null). Of course, it compiles cleanly on a different OS version.

p->messageid was created using a strdup() call earlier on in the code.

Anyways, thanks for the tips/fixes!

Mask
Jun 8, 2003
Quis Custodiet Custodes Ipsos?
I don't know if their is currently a thread on this and if there is I am sorry. I am just breaking into programming, currently taking Intro to C Programming, and as I am sure you can guess I run into a whole lot of errors. I don't know if any goons are at all up for the challenge of helping me through AIM; realistically, I could just keep posting in the C thread but I would poo poo it up with several pages on my own accord; but if anyone is up to help me out over AIM that would be great. My screen name is BboyExom, any and all help in C would be appreciated.

more falafel please
Feb 26, 2005

forums poster

unknown posted:

Yes - it overflows by a character (pushing a null into the beginning of the next string in memory, therefore basically making it null). Of course, it compiles cleanly on a different OS version.

p->messageid was created using a strdup() call earlier on in the code.

Anyways, thanks for the tips/fixes!

strdup() internally uses malloc() (or something equivalent), so the memory pointed to by the return value of strdup() is the burden of the caller to free. So you still need to free() p->messageid before you assign something else to it.

Mustach
Mar 2, 2003

In this long line, there's been some real strange genes. You've got 'em all, with some extras thrown in.
Just use realloc()
code:
size_t len = strlen(p->messageid) + sprintf(buff, "%d", pagecount++);
char* messageid = realloc(p->messageid, len+1);
if(!messageid) oops();
p->messageid = strcat(messageid, buff);
edit: made it warning-free and less lines to boot

Mustach fucked around with this message at 04:24 on Sep 6, 2008

katkillad2
Aug 30, 2004

Awake and unreal, off to nowhere
The excel thread is archived so I hope this is the right spot for this...

So i'm trying to make a spreadsheet to keep track of my diet and workout routine. All I want to do is assign words a value...is this possible?

For example, I created a drop down list with the fruits I eat such as banana, apple, grapefruit and so forth. So for Breakfast I would select Banana for instance. Whenever "Banana" is inserted into a cell I want it to have a value of 105, for an estimate of how many calories it has.

With the ultimate end result being I've got 3 drop down lists for breakfast, lunch, and dinner and then I can do a sum of these words I want to assign values to giving me my calorie intake for the day.

Is this possible? I'm probably trying to make it harder than it is.

Edit: I'm using excel 2007 if this makes a difference.

katkillad2 fucked around with this message at 06:40 on Sep 6, 2008

POKEMAN SAM
Jul 8, 2004

katkillad2 posted:

The excel thread is archived so I hope this is the right spot for this...

So i'm trying to make a spreadsheet to keep track of my diet and workout routine. All I want to do is assign words a value...is this possible?

For example, I created a drop down list with the fruits I eat such as banana, apple, grapefruit and so forth. So for Breakfast I would select Banana for instance. Whenever "Banana" is inserted into a cell I want it to have a value of 105, for an estimate of how many calories it has.

With the ultimate end result being I've got 3 drop down lists for breakfast, lunch, and dinner and then I can do a sum of these words I want to assign values to giving me my calorie intake for the day.

Is this possible? I'm probably trying to make it harder than it is.

Edit: I'm using excel 2007 if this makes a difference.

You'll probably want one Worksheet tab being a two column table, with the left hand side the names of items like Banana and the right column containing their caloric values. Then, in your main Worksheet (your log) you'd set the formula/code for the food entry lines to look up the food in the second sheet and use that value. I don't know the exact code, but it's definitely doable :)

Plastic Jesus
Aug 26, 2006

I'm cranky most of the time.

Mustach posted:

Just use realloc()
code:
size_t len = strlen(p->messageid) + sprintf(buff, "%d", pagecount++);
char* messageid = realloc(p->messageid, len+1);
if(!messageid) oops();
p->messageid = strcat(messageid, buff);
edit: made it warning-free and less lines to boot

You can't re-use a pointer passed to realloc (that's why it returns a pointer) and your call to sprintf() could still overflow buff.

Also, this is very silly stuff. The dude asking the question isn't splitting the atom, he's creating a string. I have no idea why this is so confusing to people, but it scares the hell out of me to think that people get such basic things wrong.

code:
#define MAX_UINT32_AS_STR_LEN      strlen("4294967295") + 1
...
char buff[MAX_UINT32_AS_STR_LEN]; 
...

if(p == NULL)
    return;

if(p->messageid == NULL)
    return;

snprintf(buff, "%d", MAX_UINT32_AS_STR_LEN, pagecount++);
strncat(p->messageid, buff, (MAX_MESSAGEID_LEN - 1));
You didn't talk about the format of messageid so I have no idea what MAX_MESSAGEID_LEN would be, but strncat() will append the specified number of character then append a NULL. This is different from snprintf() which expects the length specifier to include the NULL terminator.

Mustach
Mar 2, 2003

In this long line, there's been some real strange genes. You've got 'em all, with some extras thrown in.

Plastic Jesus posted:

You can't re-use a pointer passed to realloc (that's why it returns a pointer)
I assigned the result of realloc to another variable.

quote:

#define MAX_UINT32_AS_STR_LEN strlen("4294967295") + 1
...
char buff[MAX_UINT32_AS_STR_LEN];
This won't work in C89, and even in C99 and C++ it has the added problems of re-calculating the length of a non-portable string literal in every spot the macro is used. If you really just gotta be sure buff is big enough to hold the string representation of page count:
code:
char *buff = malloc(floor(log10(pagecount)) + 2);
but really you'd be pretty safe with something like
code:
char buff[124];

Mustach fucked around with this message at 15:27 on Sep 6, 2008

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh

Plastic Jesus posted:

You can't re-use a pointer passed to realloc (that's why it returns a pointer) and your call to sprintf() could still overflow buff.

Also, this is very silly stuff. The dude asking the question isn't splitting the atom, he's creating a string. I have no idea why this is so confusing to people, but it scares the hell out of me to think that people get such basic things wrong.

This is a troll, right?

Adbot
ADBOT LOVES YOU

The Mechanical Hand
May 21, 2007

as this blessed evening falls don't forget the alcohol
I want to learn .NET basically and I'm not sure where to start. Is there any poo poo I gotta get down pat before jumping in or is it feasible to pick up a book that tells you from scratch "Hey, here's where to get started, beginners!" and learn from that? Any thoughts?

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