- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi there, sorry if this question is too easy :)
Has the addition of a negative constant better or same performance than the substraction of the positive constant?
In other words, does the ALU need to perform the ~2 or it resolves it by truth-table, so exactly the same clocktics are required?
Thanks!
Daniel.
Link Copied
4 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
This looks very hypothetical. Since you appear to be expecting the compiler to treat both k and -k equally as constants, it's unlikely to make a difference. I can imagine related situations where the negation might be an additional operation, or where it might pay off by enabling commutation optimizations.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Tim, I'm not using the compiler for this one, just plain assembly.
My question is whether the SUB requires additional uops for the 2-complement (ie performs negation and then a regular ADD), or the SUB has own silicon in the ALU.
Thanks,
Daniel.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
As far as I know, the number of micro-ops, clock cycles, etc are identical in your cases. If you're working at such a low level, and don't want to rely on documents, you ought to be able to time things and find out if there's any measurable difference. If there isn't, why would anyone care?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Dear Daniel,
On the P4, instructions ADD and SUB both have a latency and throughput of 0.5cycle (executing on the ALU), which implies that no penalty is paid for subtractingvs. adding (constants or otherwise).
Aart
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page