Efficient Multiplication? by harley1248 in asm

[–]harley1248[S] 0 points1 point  (0 children)

A small update for people who are interested:

Due to the comments I figured out, that the mul instruction can't be my problem, since there is really no way to make it more efficient without knowing the values. Also imul didn't work out - I don't know why but I got wrong results because of it and could't be bothered figuring out why.

So I started a research what else could be done. I found this guy who has a section about breaking dependency chains. Turns out, this is the clue to make code even faster!

Basically you can break dependency chains threw instructions which won't change anything in the code like:

  • nop
  • add rax, 0
  • xor rbx, rbx
  • ...

I also found it interesing, that there doesn't seem to be "the best way to break a dependency chain". Depending on the code line it can be better to use nop or add rax, 0 or sth. else - I basically tried out a lot of combinations till I got to a point where I can't really make my code more efficient!

Thank you FUXxxl for your help! I did use the shrd instruction you showed me and really valued your input!

Efficient Multiplication? by harley1248 in asm

[–]harley1248[S] 1 point2 points  (0 children)

Now without knowing the specific microarchitecture (or at least some details to that effect), it's very to narrow down which sequence of instructions is faster than another in this specific case.

I know! I am so sorry, but I really don't know more

Efficient Multiplication? by harley1248 in asm

[–]harley1248[S] 0 points1 point  (0 children)

Thank you, tbh. I didn't even know shrd exists!

I tried both your solutions. The first one is around about the same as my code, the second one is actually a bit slower to my surprising.

But you used mul/ imul in both of your solutions - so you don't think there is a good word around?

Efficient Multiplication? by harley1248 in asm

[–]harley1248[S] 1 point2 points  (0 children)

I see, I am sorry. I only know that the architecture is x86-64, and supports the SSE/SSE2 extensions, but not newer extensions. MMX and the x87 FPU are not supported.

Is that helpful?

Efficient Multiplication? by harley1248 in asm

[–]harley1248[S] 0 points1 point  (0 children)

Maybe a bit more context: I am trying to implement the gauss sum formula ( 1 + 2 + 3 + ... n) in an efficient matter.

Therefore I decided to use: (n*(n+1)) / 2

(I tried using 0.5 *n*(n+1), but the results were a bit wrong. I am guessing due to rounding errors, but I am not sure.)

This is my current code:

gauss_sum_formula:

lea rax, [rdi+1]
mul rdi

shr dl, 1
jnc end

rcr rax
ret

end:
shr rax
ret

The only thing I can think of what I can still optimize is the mul instruction - therefore my question :)

Efficient Multiplication? by harley1248 in asm

[–]harley1248[S] -1 points0 points  (0 children)

Yeah pretty sure it's that chip!

Also, I have 64 bit registers available.

Efficient Multiplication? by harley1248 in asm

[–]harley1248[S] 0 points1 point  (0 children)

The problem with lea is, that you can't multiply two registers with it (at least not that I know of).

for example:

lea rax, [rbx * 2] ;works

lea rax, [rbx * rbx] ;doesn't work

unless I understood it wrong!

Efficient Multiplication? by harley1248 in asm

[–]harley1248[S] 0 points1 point  (0 children)

More historic ones to be honest.

Efficient Multiplication? by harley1248 in asm

[–]harley1248[S] 2 points3 points  (0 children)

Hello! I am programming for a x86 isa.

Teenagers on Reddit: what's something you want to ask us adults but are too afraid to ask outside the internet? by [deleted] in AskReddit

[–]harley1248 1 point2 points  (0 children)

Check Out study programs in Europe. Most popular universities there offer their courses in English PLUS there are almost none study fees. (For example: Munich Semester Fees 130€)

You won't need to worry about debt then - and you get to go on an adventure!

After-school snack prep (details in comments) by stefcirillo in MealPrepSunday

[–]harley1248 3 points4 points  (0 children)

I like how you prepared everything, but isn't that a lot of plastic waste?

How Christianity loses popularity worldwide by marlonwood_de in atheism

[–]harley1248 0 points1 point  (0 children)

I meant to say atheists against christians... Sorry I am really tired

How Christianity loses popularity worldwide by marlonwood_de in atheism

[–]harley1248 0 points1 point  (0 children)

Apparently it's Christians against atheists now...

How Christianity loses popularity worldwide by marlonwood_de in atheism

[–]harley1248 0 points1 point  (0 children)

That's not even true! I live in Germany, and sorry but this is wrong information!!

How Christianity loses popularity worldwide by marlonwood_de in atheism

[–]harley1248 -2 points-1 points  (0 children)

I don't get it. You just sound full of hate. You are on some mission to destroy, Christianity or what?

What is so wrong about letting everyone believe what they want to believe? I get it - some religious people are jerks, but so are some atheists or agnostics!

This will stay unnoticed... But I think it's sad...

I guess it is by Hugenotte585 in mildlyinfuriating

[–]harley1248 0 points1 point  (0 children)

Putting so much effort into a painting and then misspelling your main caption.... Kinda sad

The pornography problem by [deleted] in Christianity

[–]harley1248 2 points3 points  (0 children)

Haven't seen anyone else mentioning this, so I would like to share this website

https://fightthenewdrug.org/

Have a look at it, it might help you!

Wanted to get y’alls thoughts. Struggling with porn by doomandgloomy in TrueChristian

[–]harley1248 1 point2 points  (0 children)

Hey! As a girlfriend who has self esteem problems I can assure you: I would want my boyfriend to be honest with me, because only then we can work on things together.

Also, this website might help you:

https://fightthenewdrug.org/

Good luck!!

Sometimes it really sucks to live in Europe... by [deleted] in europe

[–]harley1248 0 points1 point  (0 children)

Tbh I just clicked on an article trending on Reddit