Anonymous
THEY ARE NICE
Anonymous
beacause time complexity and space complexity is better
Anonymous
TAKE THAT BACK
where u write the code swapping
Anonymous
i am finishing it up
Anonymous
ya
Anonymous
beacause time complexity and space complexity is better
firstly you want to use xor not addition or subtraction
Anonymous
for some architectures you should use mov actually
Anonymous
the reason for this is due to the fact that there are 0 instruction moves
Anonymous
the reason for this is due to the fact that there are 0 instruction moves
where several moves are done in one instruction cycle
Anonymous
so in the time it takes to do an addition you do like 6 moves
Anonymous
Anonymous
born in US grew up in Ukraine and Russia now i live in Canada
Anonymous
so the most effective code for most CPUs so far was this one
but i am sad that this person did not use the more common way to do this
Anonymous
ya but executions time more
no it is actually not
Anonymous
that is the faster execution time
Dima
lol
Anonymous
it is faster to do 3 moves then to do one addition
Anonymous
for MOST CPUs
Dima
I am from india
lol that comparisement
Talula
I'm groot
Anonymous
but why
because of zero instruction moves
Anonymous
you can do a move in less time then it takes to actually execute a function
Anonymous
for example let's say we decode 2 instructions
Anonymous
one is a move and the other is an addition
Anonymous
for the move we just have to swap the 2 register values
Anonymous
this is quite easy to do or you can do a push operation back onto the stack
Anonymous
so you move your stack pointer to the location of one of them
Anonymous
and just push both registers
Anonymous
no
but why?
Anonymous
LDM r1, {r1-r4}
Anonymous
this does 1 thing which is load multiple registers starting at the offset given in r1
Anonymous
this is for arm asm
Anonymous
then you can do the same thing and push everything
Anonymous
PUSH {r1-r4, lr}
Anonymous
you can also do STRM
Anonymous
and this is 1 instruction to decode
Anonymous
and can be done by 1 circuit
Anonymous
what is STRM
Anonymous
i mean STM
Anonymous
store multiple registers
Anonymous
this is for ARM v7?
Anonymous
i forget but this is the most recent ASM in my mind after x86_64
Anonymous
which i am doing now for my swap program
Anonymous
however the issue with x86_64 is that it looks like it is more instructions but it is really not
Anonymous
which i am doing now for my swap program
Any Note available in c++ giving me
Anonymous
they do a bunch of moves because these can be done within 1 third of a clock cycle or faster
Anonymous
which makes it faster then an addition
Anonymous
basic concept of programming language
Anonymous
because addition requires waiting for the ALU to free up
Anonymous
then to actually go and do the addition
Anonymous
for your algorithm the CPU does, decode instruction move registers to ALU ALU synchronizes inputs decodes instruction to ALU for which unit to use use adder to add inputs move back to register decode next instruction move registers to ALU ALU synchronizes inputs decodes instruction to ALU for which unit to use use complementor to do 2s complement on one of the inputs use adder to add inputs move back to register
Anonymous
🙏🙏
Anonymous
now there is something called super scalar that says some of these steps happen at the same time
Anonymous
however in comparision to the pop and push onto the stack
Anonymous
now the other trick that people like to use is xors
Anonymous
xors are easy to use and fast
Anonymous
however in comparision to the pop and push onto the stack
how to problem solve tower of hanoi in c++
Anonymous
let me explain deeply
Anonymous
and what you do is: xor x, x, y xor y, x, y xor x, x, y
Anonymous
this requires a larger footprint on the code
Anonymous
however a smaller one in terms of memory
Anonymous
and xor is typically a smaller instruction to decode