• (nodebb)

    The lower performance might be because of performance differences between the old NPX (x87) instructions used in the assembly version compared to what the compiler generates (if it's capable of generating SSE instructions instead).

  • LCrawford (unregistered)

    Even the optimized version has a buffer overrun vulnerability since the arguments weren't frist validated (afrom could be negative or ato could go beyond the array limits).

  • Prime Mover (unregistered) in reply to LCrawford

    I've heard arguments from people who refuse to sanity-check the in put parameters along the lines "Not my responsibility -- if idiots want to pass invalid parameters into my routine, it's on them."

    If the programmer in question is desperate to save CPU cycles, then there's a possible argument in favour of that -- but cautious old me does worry a little about that attitude.

  • Foo AKA Fooo (unregistered) in reply to Prime Mover

    I don't know about Delphi, but Pascal has range-checking on array indexing (a[i]). So an additional check in this routine would be redundant (and possibly worse if it adds a different way of reporting range violations).

    Now if it doesn't actually have those checks, or the programmer has disabled them, they're in a caller-beware situation anyway for any array indexing, so putting this routine in the same category won't make things worse, either.

    So I don't think the fixed code needs any validation -- unlike the pessimized assembly code which would behave wrongly even with valid input (empty range).

  • RLB (unregistered)

    Repeat after me: "premature optimization is the root of all evil".

  • Tim Ward (unregistered)

    I've certainly seen compiler generated code that was much faster than anything that could have been hand coded - because the compiler is allowed all sorts of cheats that would fail every conceivable style guide or code review if hand coded.

  • (nodebb)

    Peaceful assembly is protected by the first amendment of 🇺🇸 constitution.

  • Tom (unregistered)

    Could be Delphi, but it could just as well be plain old Pascal. I remember playing with asm blocks in Turbo Pascal to make the keyboard LEDs blink... Good times!

  • Foo AKA Fooo (unregistered) in reply to Mr. TA

    But this assembly is more like the Jan 6 version, running over all safeguards, thrashing everything in its way, and based on a very flawed premise in the first place.

  • Sole Purpose Of Visit (unregistered) in reply to Mr. TA

    I think the second amendment is of more use in this case.

  • Thomas J. (unregistered)

    Even without SSE, the assembly shown does not use any of the tricks compilers do easily like e.g. loop unrolling for increased instruction level parallelism.

  • WTFGuy (unregistered)

    Sanity check all parameters at your public API points. Debug.Assert() your parameter checks at all your internal calls.

    The "bad input is all on the caller of my public API" mindset became utterly obsolete once we had malicious code in the world.

  • (nodebb) in reply to Tom
    Could be Delphi, but it could just as well be plain old Pascal. I remember playing with asm blocks in Turbo Pascal to make the keyboard LEDs blink... Good times!
    It's probably just old Pascal, but could be Delphi as you can still write ASM in Delphi and even modern Delphi. And for what it's worth I'm doing mobile development in Delphi as this very moment.
  • Randal L. Schwartz (google) in reply to Tim Ward

    This is definitely true in Dart, with sound typing and now not-null-by-default. Whether the target is native instructions or JavaScript, it seems to be beating a lot of benchmarked handwritten code.

  • Loren Pechtel (unregistered)

    I believe that code has to be Delphi, I don't think the old Turbo Pascal supported the 32-bit registers.

    I used to really like Turbo Pascal & Delphi but when they were years behind on 32-bit support they showed they couldn't be trusted to support their users and I decided I would never start anything new in Delphi. The company I used to write Delphi for collapsed, I never even got around to reinstalling Delphi the last time I rebuilt my machine.

    As for range checking--by default it's turned on. You can turn it off for performance, and I once wrote a routine that had to have it off--back in the 16-bit days I had an array taking exactly 64k of memory that would cause false positives from the range checking. (And, no, you can't allocate that. You can, however, request such a block from the DPMI memory manager and make a pointer to it.)

    Since then I've switched to C#, almost everything I miss from Delphi has been fixed.

  • (nodebb) in reply to Loren Pechtel
    Since then I've switched to C#, almost everything I miss from Delphi has been fixed.

    Delphi was fixed, however the issue was that Anders Hejlsberg was stolen from Borland by Microsoft as well as many of their other programmers. I imagine it took some time to recover from that. He went on to create C#/.net for them as well as TypeScript. It's one of the reasons C# has a lot of Delphi DNA ... and why it's not as bad as Java.

  • MiserableOldGit (unregistered) in reply to CodeJunkie

    Much as I have no particular feelings either way on Pascal or Delphi (OK I quite liked Pascal, but it was stuck in academia for a reason). Nevertheless, we know through bitter experience in this industry, common sense will always fail to prevail.

    https://books.google.nl/books?id=WMyTANSaI0wC&lpg=PA125&dq=verity%20stop%20inprise&pg=PA123#v=onepage&q=verity%20stop%20inprise&f=false

  • asdf (unregistered)

    This code almost looks like someone found Michael Abrash's Graphics Programming Black Book articles on performance tricks using the FPU - on the original Pentium.

  • Ann Onymous (unregistered)

    I love how the Lo and Hi members of the LongRec type are used in the single most counterintuitive way. Please make it stop.

  • anonymous coward (unregistered)

    they could use fld qword ptr [rdi + 8rax] fadd qword ptr [rsi + 8rax] fstp qword ptr [rdi + 8*rax] add rax, 1

    also succ() means +1, so cx supposed to be 1 for an empty range.

  • (nodebb)

    That was one of the nice things about Turbo Pascal, you could drop in and out of assembly language at will to Get Stuff Done, and it was directly integrated into the language, none of the incomprehensible gibberish that gcc/gas force you to write just to get a value into/out of a register. Under DOS this was more or less essential since it was often the only way to do things with the hardware or OS. Of course now there's a proper API for all of this stuff so it hasn't been needed for a looooong time.

  • JustaLurker (unregistered) in reply to CodeJunkie

    Yes, Delphi is not dead (maintained by Embarcadero). But it is still ridiculously expensive to purchase a licenced version.

    https://www.embarcadero.com/products/delphi

  • 516052 (unregistered)

    Ah, assembly. My old friend. How I miss you. You who made short nights long and work days short.

    You whose smile brought men to tears, and cost my lifespan many years.

    You for whom my hair groes gray, whose name I cursed in every way.

    And yet whose smile I can't resist. And in my dreams you still persist.

  • 🤷 (unregistered) in reply to CodeJunkie

    Delphi was fixed

    Yes, it was fixed by being abandoned. I come from a C# background but inherited a Delphi project at my first job. Can't say I liked it very much. Maybe part of the reason was that the project had been developed for over 20syears, had grown to over 100,000 LOC and the only comment was "up yours!", hidden all the way to the right (I used a 21:9 screen and had to scroll to the right to see it), on a line that dealt with bank code numbers.

  • Gummy Gus (unregistered)

    That looks like old stack-based FPU assembly code. These days with vector instructions and multiple floating-point units it could be by hand or with a smart compiler to be very fast.

  • Supersonic Tumbleweed (unregistered)

    Classic typo:

    he used integers INTsead.

  • (nodebb) in reply to Foo AKA Fooo

    Or any one of the antifa/BLM events before that: running over all safeguards, thrashing everything in its way, and based on a very flawed premise in the first place.

  • Gerry (unregistered) in reply to Loren Pechtel

    32bit Delphi 2 was released on 10th February 1996. Not exactly "years and years" behind the release of Windows 95

    If you meant 64bit, it was released as part of Delphi XE2 on 2nd September 2011 - so yeah, a bit slow, even for a product focused on desktop software. That been said, the ERP application I work on is still 32 bit, because it doesn't need to use large amounts of memory.

  • Gerry (unregistered) in reply to 🤷

    Only 100K LOC? I work on a 1M LOC Delphi codebase...

  • Gerry (unregistered) in reply to 🤷

    Abandoned? The version I'm using was released less than a year ago.

  • Foo AKA Fooo (unregistered) in reply to Mr. TA

    And here, ladies and gentlemen, we see the full pathetic glory of a remaining Trumper, taking 2 days to post an unoriginal comment (copying mine almost verbatim), drawing a false equivalence (long disproved), while making factually wrong statements (some BLM protests were violent, many were not), and utterly failing to understand the words he copied, especially about the flawed premise (police racism on the one side vs. made-up claims about election fraud without any base in reality), confusing legitimate disagreement about opinions and values with disagreement about facts, i.e. lies.

  • 516052 (unregistered) in reply to Foo AKA Fooo

    You americans are hopeless. Not only can't you keep your politics civilized like the rest of us civilized nations but you can't even keep your politics out of coding. Seriously, like, just learn to deal with it.

    Riots are just the natural way crowds of annoyed people destress. And riot police exist to break them up with water cannons, tear gas and other such nice things when they go too far. It's just a release valve that gets triggered once in a while.

    What matters is that you remain civilized and agree that no matter how many cars you set on fire or how many rubber bullets you eat to the face it's all in good fun. And that after you've done your afternoon of rioting you come back relaxed and civil and continue the political conversation as if nothing happened knowing that you are all on the same side.

    Because you are on the same side. At least in a civilized country.

  • (nodebb) in reply to 516052

    Hey hey, don't put me and these socialists in the same category. They aren't American, they hate America, and no, I'm not on the same side with socialists in any country. You know, 100 million deaths and all that.

  • Like It Is (unregistered) in reply to Foo AKA Fooo

    'Foools' like you burped 'muh Russia' for 4 years straight and now have the gall to say an unprecedentedly mail-based election was safe, sound, and secure. There's ample evidence online, including damning footage of crooked election workers in critical counties, symmetric addition/subtraction (switching) of votes for president on live TV, etc.

    It doesn't matter how many burn loot murder protests were peaceful. A great many were violent, enough to rack up $1-2 billion in damages... vs. one Capitol protest which was hijacked by the same thugs. For example, the Viking dude and John Sullivan in disguise were outed as antifa.

    In a very rich act of dissonance, the anti-wall party wasted no time to erect a barrier around the Capitol to keep out We the Peasants. By the way, May's bodycam footage came out last year and clearly shows the cops weren't even responsible for Floyd's death. The broken/unsealed bag of fentanyl up his rectum was. The police racism narrative is BS.

    With your thinking so rigid and flawed, I shudder at the thought of what your code looks like.

  • Foo AKA Fooo (unregistered) in reply to Like It Is

    You forgot the reptiloids, Kenyan-Indonesian Obama, flat earth and faked moon landings!

    What else is there to say if your echo chamber apparently knows better than various courts, including SC (which shattered down basically all of Trump's allegations), the Mueller report (which did find evidence of Russian interference, even if no conspiracy by Trump's campaign), two autopsies (which both found homicide of Floyd), the Viking's dude own statement of being pro QAnon and anti BLM and antifa, etc.

  • 516052 (unregistered) in reply to Mr. TA

    I find it very sad indeed that you think "socialism" is a bad thing. I find it even sadder that you think it has anything to do with the antifa terrorists that inhabit your country. I find it disturbing that you americans don't think they are something new and some sort of big threat to humanity. Those people are the direct descendant of our old European friend the anarchist bomber. And let us not forget one such idiot started WW1.

    Also keep your bleeping politics off my programming forum. You can go sling poop at one another like uncivilized apes some place else.

  • (nodebb) in reply to 516052

    I'm not going to discuss politics. I posted a completely non-political pun joke. Then Foo went into a diatribe about Trump and etc.

    And you telling me to "keep my bleeping politics off your programming forum" is super rich, given how you yourself wrote 2 completely political posts.

Leave a comment on “Optimized”

Log In or post as a guest

Replying to comment #:

« Return to Article