assembly

Force a migration of a cache line to another core

天涯浪子 提交于 2021-02-07 22:43:21
问题 In C++ (using any of the low level intrinsics available on the platform) for x86 hardware (say Intel Skylake for example), is it possible to send a cacheline to another core without forcing the thread on that core to load the line explicitly? My usecase is in a concurrent data-structure. In this, for some cases a core goes through some places in memory that might be owned by some other core(s) while probing for spots. The threads on those cores are typically are blocked on a condition

How does processors know the end of program?

血红的双手。 提交于 2021-02-07 19:54:53
问题 I was wondering, how does processors know when to stop executing a program. Or rather, when to stop the "fetch, decode execute" cycle. I have thought of different ways but not sure which is the correct one or if they are all wrong. 1- Maybe there is a special instruction at the end automatically added by the assembler to let the processor know this is the end. 2- When it reach an invalid memory (But how does it recognize that). 3- It loops and re-run the program, but again how does it

Choosing SSE instruction execution domains in mixed contexts

夙愿已清 提交于 2021-02-07 19:43:33
问题 I am playing with a bit of SSE assembly code in which I do not have enough xmm registers to keep all the temporary results and useful constants in registers at the same time. As a workaround, for some constant vectors that have identical components, I “compress” several vectors into a single xmm register, xmm14 below. I use the pshufd instruction to decompress the constant vector I need. This instruction has a bit of latency, but since it takes a source and a destination register, it is

Why does issuing empty asm commands swap variables?

北战南征 提交于 2021-02-07 17:34:30
问题 So I was messing around with inline assembly and compiled this using GCC 9 . The result was that the two variables a and b were swapped without actually issuing any direct commands. #include<cstdio> int main(){ int a(1),b(2),c(3); asm ("": "=r"(c):"r"(a)); asm ("": "=r"(a):"r"(b)); asm ("": "=r"(b):"r"(c)); printf("%d %d %d", a,b,c); } Can somebody explain what is going on here? 回答1: Basically random chance of variable allocation. (Or actually GCC's internal machinery's first choices). You

Why does issuing empty asm commands swap variables?

牧云@^-^@ 提交于 2021-02-07 17:34:22
问题 So I was messing around with inline assembly and compiled this using GCC 9 . The result was that the two variables a and b were swapped without actually issuing any direct commands. #include<cstdio> int main(){ int a(1),b(2),c(3); asm ("": "=r"(c):"r"(a)); asm ("": "=r"(a):"r"(b)); asm ("": "=r"(b):"r"(c)); printf("%d %d %d", a,b,c); } Can somebody explain what is going on here? 回答1: Basically random chance of variable allocation. (Or actually GCC's internal machinery's first choices). You

NASM tutorial uses int 80h, but this isn't working on Windows

孤街醉人 提交于 2021-02-07 14:16:18
问题 I'm starting NASM Assembler after finishing FASM. I'm coding this in a Windows Operating System. My code reads: section.data ;Constant msg: db "Hello World!" msg_L: equ $-msg ; Current - msg1 section.bss ;Varialble section.text ; Code global _WinMain@16 _WinMain@16: mov eax,4 mov ebx,1; Where to wrte it out. Terminal mov ecx, msg mov edx, msg_L int 80h mov eax, 1 ; EXIT COMMAND mov ebx,0 ; No Eror int 80h To compile it and execute I use: nasm -f win32 test.asm -o test.o ld test.o -o test.exe

Getting the caller's Return Address

我们两清 提交于 2021-02-07 13:37:44
问题 I am trying to figure out how to grab the return address of a caller in MSVC. I can use _ReturnAddress() to get the return address of my function, but I can't seem to find a way to get the caller's. I've tried using CaptureStackBackTrace, but for some reason, it crashes after many, many calls. I would also prefer a solution via inline assembly. void my_function(){ cout << "return address of caller_function: " << [GET CALLER'S RETURN VALUE]; } // imaginary return address: 0x15AF7C0 void caller

Linux NASM detect EOF

蹲街弑〆低调 提交于 2021-02-07 13:17:27
问题 I'm trying to learn the basics asm on linux and I can't find a very good reference. The NASM docs seem to assume you already know masm... I found no examples in the documentation of the cmp (outside the Intel instruction reference). I'd written a program that reads a single byte from stdin and writes it to stdout. Below is my modification to try to detect EOF on stdin and exit when EOF is reached. The issue is it never exits. I just keeps printing the last char read from stdin. The issue is

C (or asm): how to execute c code stored in memory (copied from labels)

♀尐吖头ヾ 提交于 2021-02-07 13:12:59
问题 I try to "inline" my VM by copying code segments from C code between labels to memory allocated by malloc. So I have Ops defined with start and end labels, and I want to copy the instruction defined by the following code to a buffer and then get executed (Im not sure if this is even possible) OP_PUSH0_START: sp += 4; *sp = 0; // I WANT THE INSTRUCTIONS OF THIS LINE COPIED TO THE BUFFER OP_PUSH0_END: to do so I thought the following code snippet will work void * ptr0 = &&OP_PUSH0_START; void *

Linux NASM detect EOF

老子叫甜甜 提交于 2021-02-07 13:12:55
问题 I'm trying to learn the basics asm on linux and I can't find a very good reference. The NASM docs seem to assume you already know masm... I found no examples in the documentation of the cmp (outside the Intel instruction reference). I'd written a program that reads a single byte from stdin and writes it to stdout. Below is my modification to try to detect EOF on stdin and exit when EOF is reached. The issue is it never exits. I just keeps printing the last char read from stdin. The issue is