• Advertisement
Sign in to follow this  

Unity PUSH ECX faster? Or MOV Count, ECX?

This topic is 4856 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi guys I'm back, back with a stipid question. So which one is faster? Considerin' that both can be used and I have to choose one. Thanks!

Share this post


Link to post
Share on other sites
Advertisement
Unless you're programming a 486 or earlier, it won't make a difference.
I'd probably use the stack directly with push since its more 'assembly-like' imo. Using variables is for sissies =-P

Share this post


Link to post
Share on other sites
Given that (non-register passing) function calls have their parameters passed with PUSHes for every compiler that I've ever seen, rather than a SUB and a bunch of MOVs, I'd say jsut go with PUSH.

Share this post


Link to post
Share on other sites
Thanks guys, that's helpful. I'm goin' with BUSH, I mean, PUSH.

Anyway my friend told me that PUSH is built in, so it only
occupies a single code byte (0x51), whereas "MOV Count, ECX"
occupies three code bytes and it's slower. Yeah and I saw that
in my dissasembly too :)

Share this post


Link to post
Share on other sites
If you have to ask (i.e. can't figure out how to test it for yourself), then you are pretty much automatically not qualified to make use of the answer.

Share this post


Link to post
Share on other sites
Not necessarily. It may be that he could go forth and do a bunch of benchmarks, and infer, from the data gained, which approach is faster. But instead of doing all that stuffing around, he pops the question on GameDev.Net, on the assumption that with so many asm programmers around, someone's probably already done the groundwork and he'd be wasting his time to repeat it.

Linkay. Which may or may not be useful.

Share this post


Link to post
Share on other sites
Quote:
Original post by HaywireGuy
Thanks guys, that's helpful. I'm goin' with BUSH, I mean, PUSH.

Anyway my friend told me that PUSH is built in, so it only
occupies a single code byte (0x51), whereas "MOV Count, ECX"
occupies three code bytes and it's slower. Yeah and I saw that
in my dissasembly too :)


These days pretty much all of the ALU operations (including MOV and PUSH/POP) are hardwired into the chip already. Yes the alternate encoding for PUSH register operand onto the stack is only one byte, and I think a MOV mem/reg operation is two bytes followed by up to a four byte memory value.

The Intel Optimization manual gives PUSH with latency of 1.5 and throughput of 1, while MOV has a latency of 0.5 and throughput of 0.5. Remember that these are just estimates, and what usually matters more on modern processors is memory and cache performance. Either way I doubt you'll get much speed difference between the two.

Share this post


Link to post
Share on other sites
Quote:
Original post by Zahlman
If you have to ask (i.e. can't figure out how to test it for yourself), then you are pretty much automatically not qualified to make use of the answer.
Ain't that the absolute truth!

I was going to somehow say the same thing, but you couldn't have said it better.

Share this post


Link to post
Share on other sites
Zahlman, I was waitin' for a reply like that given by
DukeAtreides076 and the rest, which my test application won't
tell me. So, yah, I'm here.

Cheers fractoid, I'm sure that's gonna be useful :)

Duke, I'm sure that's true, maybe I'm just being a lit'
paranoid when I have these MOVs in a very tight loop that
executes millions of times. But anyway, thanks!

Share this post


Link to post
Share on other sites
FYI: The point I think we were both making is that if it was in an innermost loop then timing it would easily tell you which is faster. If it isn't in an innermoost loop then it doesn't really matter as it isn't being executed very much and will barely make any difference. So there is no need to ask the question either way, at least not without explaining why you needed to ask the question, such as 'I can't get my profiling working'.
On the other hand if you were just too lazy to profile then...

Excuse my beverity btw.

Share this post


Link to post
Share on other sites
Quote:
Original post by iMalc
FYI: The point I think we were both making is that if it was in an innermost loop then timing it would easily tell you which is faster. If it isn't in an innermoost loop then it doesn't really matter as it isn't being executed very much and will barely make any difference. So there is no need to ask the question either way, at least not without explaining why you needed to ask the question, such as 'I can't get my profiling working'.
On the other hand if you were just too lazy to profile then...

Excuse my beverity btw.
Even if it was in an inner loop, it'd have to be executing (MANY * MANY * MANY * MANY)999999 times to be noticable. If the times given by DukeAtreides076 are accurate, it might take ~3 cycles. On a 500MHZ machine, that means it would take 6*10-9 seconds, or 6 nanoseconds. On a modern machine (3.5GHz say) it would take a single nanosecond. You could do that operation a US Billion times per second. Unless you're writing for a REALLY slow machine, the difference is practically 0 and the time you wasted on the 'optimization' could be better spent optimizing the algorithms or implementations of something else..

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
  • Advertisement
  • Popular Tags

  • Advertisement
  • Popular Now

  • Similar Content

    • By Innoc uous
      I'm working on a space game, and I suck at art. I would love to get some help from someone who is more skilled than me. Things I need include modular space ship parts and GUI elements. Nothing too fancy, just functional so I can get a prototype put together. This could potentially become a serious project, but for now this is just a hobby project.
       
      In this video, you can see a few things I already completed
      :2018-02-24 20-08-13.flv2018-02-24 20-08-13.flv
    • By Innoc uous
      If you want to incorporate noise into your shaders, the Turbulance Library has you covered. Using code I gathered from this library, I made a cginc file that contains all you need to easily implement noise into your unity shaders. Who knows how this stuff works, but man, does it work well!
       
      https://pastebin.com/LLCUpJut
       
      Here is an example of what you can create using these noise functions.
       
    • By Nio Martinez
      I'll be buying a new laptop as my workstation for building games, Mostly 3D but not hard core. 
       
      I'm stuck at choosing between these 2 specs below. Does this really matter and if so, can some one tell my how and why it matters. 
      Choice1:
      Intel core i5-8250U (8th gen Kabylake refresh)(6 MB Smart Cache, 1.6 GHz Base with Turbo Boost up to 3.4 GHz) 4 cores 8 threads
      RAM 8 GB DDR4 (2400 MHz)
      GPU 2 GB DDR5 Nvidia MX150 256 bit
      SSD: yes
      Choice2:
      Intel core i7-7500U 2.70GHz Base Processor (4M Cache, up to 3.50 GHz Boost) 2 Cores, 4 Threads
      RAM 4 GB DDR4 (1800 MHz)
      GPU 2 GB DDR5 Nvidia GeForce 940MX 256 bit
      SSD: No
       
    • By Manuel Berger
      Hello fellow devs!
      Once again I started working on an 2D adventure game and right now I'm doing the character-movement/animation. I'm not a big math guy and I was happy about my solution, but soon I realized that it's flawed.
      My player has 5 walking-animations, mirrored for the left side: up, upright, right, downright, down. With the atan2 function I get the angle between player and destination. To get an index from 0 to 4, I divide PI by 5 and see how many times it goes into the player-destination angle.

      In Pseudo-Code:
      angle = atan2(destination.x - player.x, destination.y - player.y) //swapped y and x to get mirrored angle around the y axis
      index = (int) (angle / (PI / 5));
      PlayAnimation(index); //0 = up, 1 = up_right, 2 = right, 3 = down_right, 4 = down

      Besides the fact that when angle is equal to PI it produces an index of 5, this works like a charm. Or at least I thought so at first. When I tested it, I realized that the up and down animation is playing more often than the others, which is pretty logical, since they have double the angle.

      What I'm trying to achieve is something like this, but with equal angles, so that up and down has the same range as all other directions.

      I can't get my head around it. Any suggestions? Is the whole approach doomed?

      Thank you in advance for any input!
       
    • By devbyskc
      Hi Everyone,
      Like most here, I'm a newbie but have been dabbling with game development for a few years. I am currently working full-time overseas and learning the craft in my spare time. It's been a long but highly rewarding adventure. Much of my time has been spent working through tutorials. In all of them, as well as my own attempts at development, I used the audio files supplied by the tutorial author, or obtained from one of the numerous sites online. I am working solo, and will be for a while, so I don't want to get too wrapped up with any one skill set. Regarding audio, the files I've found and used are good for what I was doing at the time. However I would now like to try my hand at customizing the audio more. My game engine of choice is Unity and it has an audio mixer built in that I have experimented with following their tutorials. I have obtained a great book called Game Audio Development with Unity 5.x that I am working through. Half way through the book it introduces using FMOD to supplement the Unity Audio Mixer. Later in the book, the author introduces Reaper (a very popular DAW) as an external program to compose and mix music to be integrated with Unity. I did some research on DAWs and quickly became overwhelmed. Much of what I found was geared toward professional sound engineers and sound designers. I am in no way trying or even thinking about getting to that level. All I want to be able to do is take a music file, and tweak it some to get the sound I want for my game. I've played with Audacity as well, but it didn't seem to fit the bill. So that is why I am looking at a better quality DAW. Since being solo, I am also under a budget contraint. So of all the DAW software out there, I am considering Reaper or Presonus Studio One due to their pricing. My question is, is investing the time to learn about using a DAW to tweak a sound file worth it? Are there any solo developers currently using a DAW as part of their overall workflow? If so, which one? I've also come across Fabric which is a Unity plug-in that enhances the built-in audio mixer. Would that be a better alternative?
      I know this is long, and maybe I haven't communicated well in trying to be brief. But any advice from the gurus/vets would be greatly appreciated. I've leaned so much and had a lot of fun in the process. BTW, I am also a senior citizen (I cut my programming teeth back using punch cards and Structured Basic when it first came out). If anyone needs more clarification of what I am trying to accomplish please let me know.  Thanks in advance for any assistance/advice.
  • Advertisement