|
From a test I recently corrected. __m128 y = _mm_mul_ps(x, _mm_set1_ps(1.0f)); This is an SSE y = x*1; __m128 rcp = _mm_rcp_ps(_mm_set1_ps(1.0f)); rcp = 1/1; Wait, there's worse __m128 rcp = rcp_nr(_mm_set1_ps(1.0f)); Hrmm. SSE reciprocal is not very accurate. I know, let's use a newtown rhapson iteration to increase the accuracy of our 1/1 calculation!
|
# ¿ Jun 14, 2008 16:35 |
|
|
# ¿ Apr 25, 2024 12:15 |
|
ZorbaTHut posted:I wrote a 3000-line function once. It included a "goto". 3000 lines is , but there's nothing wrong with using the occasional goto. "Never ever use goto" is generally promulgated by people who've heard of Dijkstra's article but never read the drat thing.
|
# ¿ Jun 15, 2008 01:26 |
|
ehnus posted:Two that come immediately to mind are breaking out of nested loops in C/C++/C# and cleaning up/freeing resources upon failure in environments that do not provide exceptions. I've used them when I've written parsers too as there was no other clear way of providing similar functionality. DING DING DING.
|
# ¿ Jun 15, 2008 01:51 |
|
Ugg boots posted:The one thing I did like about PHP was that they offer the break X construct that lets you break out of nested loops as far as you want. Until you add another loop and WHOOPS, you're not where you think you should be.
|
# ¿ Jun 15, 2008 02:27 |
|
floWenoL posted:Here's a nickel, kid, go buy yourself a C book. break my_label is no different than goto my_label as far as breaking out of loops is concerned. It just removes the functionality of one "evil" and sticks it in another.
|
# ¿ Jun 15, 2008 14:20 |
|
zootm posted:This is largely correct but the essential point here is that goto should be limited to the point where execution paths can be easily determined. Gotos within local scope for breaking out of loops and the like are theoretically fine, but jumping between functions, jumping to arbitrary points to emulate flow control, and so on is craziness. There's definitely valid uses within C from what I've seen, though. Agreed. Here's another coding horror. A student of mine refused to use a for loop. He wrote everything as a while loop for(int i=0; i<5; ++i){ do_stuff(i); } was int i=0; while(i<5){ do_stuff(i); ++i; } Now they'll compile down to the same code 99.99% of the time, but it takes up more space, reads strangely to anyone else and the iterator now has scope outside of the loop. I never got a satisfactory answer from him as to why he did this.
|
# ¿ Jun 15, 2008 14:58 |
|
3rd year college level CS course, not a general programming course I'm afraid. The kid was very bright, but I got an air of "self-taught programmer" from him which would probably explain why he did things that way. The same course, although not the same person, yielded the above SIMD 1/1 and y=x*1 code snippets. I know I've been guilty of the same thing. When learning C years ago (self taught) I had a habit of using (*foo).bar rather than foo->bar which some people would call horrific.
|
# ¿ Jun 15, 2008 22:46 |
|
boost tuples http://www.boost.org/doc/libs/1_36_0/libs/tuple/doc/tuple_users_guide.html TR1 has tuples, but that poo poo isn't really official of course. Roll on 0x
|
# ¿ Sep 2, 2008 03:33 |
|
A colleague and I were looking through a ray-tracer that someone released as we were implementing one of our own algorithms in it in order to see if the gains we were seeing were peculair to our own code. We came across a piece of code like this... code:
|
# ¿ Nov 26, 2008 20:02 |
|
beer_war posted:
That's a shooting offense. If you know enough to use the ternary operator then I expect you not to write code like that. Students that I give grinds to have a habit of doing this when they come to me first. I beat it out of them. code:
code:
|
# ¿ Jan 4, 2009 22:09 |
|
ih8ualot posted:I know I'm in the minority here, but I find I'm with you, but perhaps for different reasons. If it's a boolean expression I don't use == true. If however the expression would rely on integral promotion to be boolean I'll use a comparison like the following code:
The same goes for checking pointers. I always use code:
code:
(= vs ==)
|
# ¿ Jan 5, 2009 02:27 |
|
*Whoops* was trying to think of a simple case where I could drop a comparison. You get my point though replace 1 with 0 on that code. Changing it to is_even means you can't just drop the comp.
|
# ¿ Jan 5, 2009 03:57 |
|
minato posted:
That's not a horror, that's an extreme optimisation for an operation done a lot in many renderers. Low accuracy bitwise hack combined with one Newton-Raphson iteration.
|
# ¿ Jan 7, 2009 17:26 |
|
ehnus posted:It's a coding horror for any x86 (post-1999) or PowerPC based computer. In the context in which it was originally written it's not a coding horror which is what counts. Today of course I would (and do) use SSE for such things.
|
# ¿ Jan 7, 2009 19:12 |
|
heeen posted:Can you elaborate on the why and how you do things nowadays? My research is on RTRT (real-time ray-tracing). Packet tracing (Google Keywords: Ingo Wald ICRT Packet Tracing) at its simplest involves tracing 4 rays at a time in SSE. Other related techniques such as MLRTA, frustum culling etc. all benefit from using SSE. Here's a reciprocal SSE sqrt from my code. code:
|
# ¿ Jan 7, 2009 19:43 |
|
btw, here's something I found out recently. Here's that line from the above code to access the bits in a float. code:
code:
|
# ¿ Jan 7, 2009 19:55 |
|
Sartak posted:Nope I'd say you're in the right place. Optimisation when relevant is not a coding horror.
|
# ¿ Jan 7, 2009 19:59 |
|
hexadecimal posted:Can you explain why this is faster than doing int i = (int)x Uhh because what you posted doesn't work?
|
# ¿ Jan 7, 2009 20:02 |
|
dancavallaro posted:I'm not a big C guy, so I'm kind of guessing here, but just doing (int)x will cast x to an integer, and chop off anything after the decimal. But (int&)x or *(int*)&x preserves all of the bits of the float, but as an integer. This is what you need, because the point is to be able to do bit operations on the bits of the float. correct
|
# ¿ Jan 7, 2009 20:08 |
|
hexadecimal posted:I just tried it and it did It compiles, but it doesn't do what we want to do (access the bits in a float). Taking 5 to get some food sounds like a good idea.
|
# ¿ Jan 7, 2009 20:12 |
|
Ugg boots posted:Where in the C standard does it specify that unioned elements will occupy the same space in memory? Wait, don't unions by definition start at the same point in memory. If the types have the same length they completely overlap each other. Am I missing something here? Edit: Wagammama's ramen is delicious.
|
# ¿ Jan 7, 2009 20:41 |
|
Wait isn't that a correct fix for erasing based on an iterator so you don't invalidate the iterator itself? forgive me if I'm wrong here as it's nearly 2am
|
# ¿ Jan 17, 2009 02:48 |
|
Otto Skorzeny posted:Did you ever get your drat Anschuetz working Yeah the last 200 rounds I ran through her popped out nicely I was going to go down to the range tonight and put a box or two of Eley Sport through her, but I got stuck late fixing some code for a paper. on topic: from a colleague's code earlier on today //This should not be an odd number! const int static num_photons = 53;
|
# ¿ Jan 17, 2009 04:30 |
|
shrughes posted:Everything on this page: http://www.xsharp.org/samples/ Jesus Christ. I don't know what to say. The site's too detailed to be a joke. The most hilaroius thing is the tag-line "Code is poetry". Yes, and X# is Jabberwocky
|
# ¿ Jan 21, 2009 23:41 |
|
One time pads are bad how edit: Whoops, missed the "encrypt passwords" bit Zakalwe fucked around with this message at 03:52 on Feb 5, 2009 |
# ¿ Feb 5, 2009 03:48 |
|
GrumpyDoctor posted:check out this sweet container (DynamicArray is a homegrown resizable array that's basically std::vector without bounds checking and the added bonus of being completely inscrutable to the visual c++ debugger) home-grown wheel reinvention, difficult to debug, the lack of reference parameters/returns and an always O(n^2) bubble sort. Beautiful
|
# ¿ Feb 13, 2009 00:47 |
|
Captain Cool posted:Well, it means you're using public class members Not necessarily a coding horror. Full encapsulation doesn't always make sense in the context of the problem. I once had a friend who returned non-const references in getters argue against public class members.
|
# ¿ Apr 24, 2009 20:51 |
|
From the Bullet SDK User Manualquote:Often it is necessary to maintain an array of objects. Originally the Bullet library used a STL std::vector data structure for arrays, but for portability and compatibility reasons we switched to our own array class.
|
# ¿ Jun 26, 2009 18:49 |
|
Vinterstum posted:Looks like it was for Visual Studio compatibility: http://bulletphysics.com/Bullet/phpBB3/viewtopic.php?f=9&t=3638&p=13749&hilit=std%3A%3Avector#p13749 I have a really hard time believing that VS2008 has a broken implementation of something as pervasive in C++ code as std::vector. Instead I'm inclined to believe they're doing something dumb and out of spec that works in GCC and therefore "VS2008 is broken". Bullet's Demos are also the most convoluted pieces of code. Whole bunches of similar classes are constructed via Macros. Each demo inherits from a huge Demo class. Each demo shares random files with other demos. Heaven forbid examples and demos are easy to understand. Another WTF: The multithreaded implementation was first realised on the Cell. The more generic Linux/Windows code is a *direct* port of this. Each worker thread operates with a 256k local store that it has to populate via memcopy() from the main pool
|
# ¿ Jul 1, 2009 00:16 |
|
Vinterstum posted:Something dumb like wanting some of their internal data types to be 16 byte aligned, which the VS STL implementation can't handle (We actually had problems with this at work as well, I remember). They claimed VS was buggy. This is not a bug and therefore std::vector in Visual Studio's STL implementation is not broken in this regard. Perhaps the real WTF is the cheap LOL MS shot for no other reason than VS is not GCC.
|
# ¿ Jul 2, 2009 01:37 |
|
mr_jim posted:Why? It's not. Some people have "OMG goto is evil" beaten into them by idiots who should know better.
|
# ¿ Jul 27, 2009 03:37 |
|
fletcher posted:I can't imagine why they even put something like that in. Are people really that lazy that they can't keep their code formatted properly as they write it? I spend most of my "coding time" thinking through algorithms or optimizing code. Typing is the tedious part. I've set up my indenter to format my code in the style I like. I use autocomplete. It's a tool. Do you use an IDE?
|
# ¿ Aug 7, 2009 21:08 |
|
fletcher posted:Yeah, I use autocomplete all the time, I couldn't live without it. I have my indenter setup the way I like as well, and it will add curly braces for me at convenient times. None of that has to do with what I was talking about. I use eclipse. Sorry dude, read you completely wrong. Thought you were pulling out that "real programmers do X" bullshit.
|
# ¿ Aug 7, 2009 21:28 |
|
Lexical Unit posted:an unholy abomination. Jesus H Christ. I think I need to lie down for a minute.
|
# ¿ Aug 11, 2009 20:57 |
|
ryanmfw posted:Am I just a bad programmer or is something like this bad: output(i) returns a reference to the i'th element of an internal array I'd guess. If so I'd personally overload[] and use output[i] = device_read(i) myself; It's a stylistic choice.
|
# ¿ Aug 19, 2009 18:47 |
|
yaoi prophet posted:oh god my eyes (?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])
|
# ¿ Oct 7, 2009 04:36 |
|
yaoi prophet posted:vvvv is that the regex for matching all valid e-mail addresses? Ding ding ding.
|
# ¿ Oct 7, 2009 04:52 |
|
Janin posted:Why is it so much shorter than Mail::RFC822::Address? Different RFC. I posted RFC2822
|
# ¿ Oct 7, 2009 04:59 |
|
|
# ¿ Apr 25, 2024 12:15 |
|
shrughes posted:Especially since a feature has been built into C99 for this very purpose. Perhaps he means the zero size data array? It's a trick used in a lot of header structs where the data size is variable. The actual size of the data member is actually 0, but of course using it as an array allows you to access the data past the header.
|
# ¿ Jun 19, 2010 02:33 |