Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re^3: Help me to understand increment / decrement operator behavior in perl

by ikegami (Patriarch)
on Mar 04, 2015 at 17:11 UTC ( [id://1118764]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Help me to understand increment / decrement operator behavior in perl
in thread Help me to understand increment / decrement operator behavior in perl

Whether the stack or a register is used depends on a number of factors. Whether the stack or a register is used is not important here. Fixed.

Replies are listed 'Best First'.
Re^4: Help me to understand increment / decrement operator behavior in perl
by BrowserUk (Patriarch) on Mar 04, 2015 at 17:28 UTC
    Whether the stack or a register is used depends on a number of factors.

    Can you show me one example of C pushing a integer any numeric argument onto the stack in order to compare it to another integer numeric argument?


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority". I'm with torvalds on this
    In the absence of evidence, opinion is indistinguishable from prejudice. Agile (and TDD) debunked
      How about machine without registers? How about values retrieved early in the sub and compared late in the sub?
        How about machine without registers?

        After a couple of hours of looking, beyond the like of purely theoretical entities, like the nicely named, but non-existent PERL-a registerless architecture, I can find no indication that a register-less CPU does, has, or ever will exist.

        But assuming, just for a moment, that such a thing did exist, why would it put arguments on a "stack", when it effectively has unlimited registers in the form of the entire address space to work with?

        And, how would it implement a "stack", without a 'stack pointer'?

        And what benefit would there be to transferring a value from one memory address (the variable) to another memory address (a stack slot) in order to compare it against a value located at another memory address (whether the variable's address, or that of some location on the stack)?

        How about values retrieved early in the sub and compared late in the sub?

        "retrieved" from where? The variable's (named) location? Ie. a memory address -- which conventionally would already be some place on the stack for local variables.

        If the sub has access to it, it must know its address. What would be the point in moving it from that address, to another address (on the stack) at an early point in the code, before comparing it later in the code?


        With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority". I'm with torvalds on this
        In the absence of evidence, opinion is indistinguishable from prejudice. Agile (and TDD) debunked

      Try compiling with -O0, that usually forces auto variables to stack (may be useful when debugging).

      Intels icc with -Os (size optimized) may load small constants like so: pushq $18; popq %rdi.

        Try compiling with -O0

        (On MSVC) /O0 is the same as /Od and results in the same assembler output shown above right down to the annotation: ; Function compile flags: /Odtp.

        that usually forces auto variables to stack

        On (Windows) X64, the ABI designates that the first 4 args are passed in registers and the others on the stack.

        But that requires that there would be arguments passed. Whilst == is implemented as a (kind of) function call in Perl; it is not in C -- on any platform/compiler I am aware of.

        Even the integer C interpreter I had back in the day loaded one value into a register and the did a cmp reg, mem; instruction.

        may load small constants like so: pushq $18; popq %rdi.

        I'm not familiar with those style of opcodes -- they don't appear in my Intel manuals -- but assuming the 'q' in pushq/popq stands for quad (in 64-bit mode that's the only push/pop available), and this is a "small constant"; why does it store that small constant in a 64-bit memory location, then move it into a 64-bit register by moving it through another 64-bit memory location (on the stack) first?

        Why not use (in Intel Asm syntax) mov rdi, $18; (register to memory 64-bit move)?

        Or better yet, mov reg8/16/32/64, imm8/16/32/64;?

        Ie. store the small constant directly in the opcode itself; per this from the listing above: sub    eax, 1;

        (Note:I've never used Intel's compiler.)


        With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority". I'm with torvalds on this
        In the absence of evidence, opinion is indistinguishable from prejudice. Agile (and TDD) debunked

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1118764]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (5)
As of 2024-03-29 12:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found