Message from @M4Gunner

Discord ID: 429489320915763218


2018-03-31 03:35:14 UTC  

the line correspondence is trippy here

2018-03-31 03:36:10 UTC  

This is x86-64, so it's using the MMX/SSE registers for the floating point.

2018-03-31 03:36:34 UTC  

Call convention allows the arguments to come in as registers instead of the stack.

2018-03-31 03:36:42 UTC  

xmm0, xmm1, xmm2

2018-03-31 03:37:24 UTC  

First 3 lines multiplies each register by itself, which squares the value.

2018-03-31 03:37:34 UTC  

Then 2 lines to add them.

2018-03-31 03:38:36 UTC  

Then `pxor` a register with itself, it always generates a zero. It's the fastest way to load a zero into a register, in Intel/AMD processors.

2018-03-31 03:38:45 UTC  

okay so in the beginning he doesnt manually move your variables into the first 3 registers

2018-03-31 03:41:55 UTC  

I'm not too familiar with amd64/x86-64 ABI, I'm guessing it can assume the first few arguments are both on the stack and on the XMM registers.

2018-03-31 03:42:13 UTC  

ok

2018-03-31 03:42:25 UTC  
2018-03-31 03:42:58 UTC  

Most of the other commands are somewhat familiar

2018-03-31 03:46:49 UTC  

it's using single-precision floating point, so if you typed in different numbers it may have automatically chosen a format with more precision?

2018-03-31 03:47:30 UTC  

That's governed by how basic types arithmetic works in C++.

2018-03-31 03:48:18 UTC  

Replace the `float` by `double`, and call `::sqrt()` to see it use different instructions.

2018-03-31 03:49:12 UTC  

https://cdn.discordapp.com/attachments/423219052849397773/429487300972380160/sqrt-test-2.png

2018-03-31 03:51:50 UTC  

The `pxor`, `ucomis` and `ja` serve to check if the argument is positive; if so, it can just use the `sqrt` instruction; otherwise, it needs to call the `sqrt()` function from the standard library, which handles all the nasty NaN, Infinity, negative arguments.

2018-03-31 03:54:52 UTC  

okay. so the chip has its own primitive math

2018-03-31 03:56:29 UTC  

Yeah, it's a CISC architecture.

2018-03-31 03:56:58 UTC  

Switch to the MIPS gcc, and you'll get a very different result.

2018-03-31 03:57:13 UTC  

RISC dont have its own maths intructions?

2018-03-31 03:57:22 UTC  

https://cdn.discordapp.com/attachments/423219052849397773/429489359289319424/sqrt-test-3.png

2018-03-31 03:57:58 UTC  

ive only read a couple pages about MIPS so far

2018-03-31 03:59:18 UTC  

Reduced Instruction Set Computer, the whole point is to have so few instructions in the architecture that the circuitry is very small.

2018-03-31 03:59:59 UTC  

Being small means there's less need for synchronization, thus it can run faster, and there are more transistors that can be used for caches.

2018-03-31 04:00:36 UTC  

PowerISA stands for Performance Optimized With Enhanced Reduced Instruction Set Computer Instruction Set Architecture

2018-03-31 04:01:02 UTC  

So a typical RISC arch won't have any advanced instructions. No specialized math, no instructions that mix register operands with memory, etc.

2018-03-31 04:01:28 UTC  

they dont use the same design pillars when picking acronyms

2018-03-31 04:01:28 UTC  

If course, at some point, you end up with extra room in the silicon, so some complex instructions sneak back in, just because they can.

2018-03-31 04:02:26 UTC  

so all risc programmers need to have all their maths in standard libraries?

2018-03-31 04:03:14 UTC  

It's not like there's a circuit that does math functions in Intel chips. It also runs some software to calculate it.

2018-03-31 04:03:27 UTC  

It's just that it's built into the chip.

2018-03-31 04:04:01 UTC  

Downside is, if the manufacturer didn't pay much attention to details, you can get bad results. Fast, but wrong.

2018-03-31 04:04:02 UTC  

what do you call that? firmware? embedded process??

2018-03-31 04:04:12 UTC  

That would be the CPU's microcode.

2018-03-31 04:04:15 UTC  

ok

2018-03-31 04:04:58 UTC  

Intel CPUs were notorious for having bad trig instructions, when outside the normalized range.

2018-03-31 04:05:38 UTC  

"Bad" meaning they didn't calculate all the bits they promised.

2018-03-31 04:06:00 UTC  

I remember seeing a paper a while back, about how those math functions in CPUs had some unexpected precision problems that didn't even match what the manual promised.

2018-03-31 04:07:29 UTC  

IIRC, for sine/cosine, Intel uses a lookup table, then interpolates the values.

2018-03-31 04:07:39 UTC  

wild guess, did this come to light during the early 3D era?