x86-64

Understanding GCC's floating point constants in assembly listing output

陌路散爱 提交于 2021-02-16 13:45:08
问题 Just out of curiosity, I'm using Compiler Explorer to see the assembly output of some simple C++ codes. Consider the following example int main(void){ double x = -5.3; } Assembly output main: push rbp mov rbp, rsp movsd xmm0, QWORD PTR .LC0[rip] movsd QWORD PTR [rbp-8], xmm0 mov eax, 0 pop rbp ret .LC0: .long 858993459 .long -1072352461 I would like to understand how to use .LC0: .long 858993459 .long -1072352461 to get back my -5.3 . My uninformed guess is that I need to merge the bit

How to implement sign function with SSE3?

一世执手 提交于 2021-02-16 13:08:38
问题 1) Is there a way to efficiently implement sign function using SSE3 (no SSE4) with the following characteristics? the input is a float vector __m128 . the output should be also __m128 with [-1.0f, 0.0f, 1.0f] as its values I tried this, but it didn't work (though I think it should): inputVal = _mm_set_ps(-0.5, 0.5, 0.0, 3.0); comp1 = _mm_cmpgt_ps(_mm_setzero_ps(), inputVal); comp2 = _mm_cmpgt_ps(inputVal, _mm_setzero_ps()); comp1 = _mm_castsi128_ps(_mm_castps_si128(comp1)); comp2 = _mm

how are barriers/fences and acquire, release semantics implemented microarchitecturally?

半腔热情 提交于 2021-02-16 12:57:07
问题 A lot of questions SO and articles/books such as https://mirrors.edge.kernel.org/pub/linux/kernel/people/paulmck/perfbook/perfbook.2018.12.08a.pdf, Preshing's articles such as https://preshing.com/20120710/memory-barriers-are-like-source-control-operations/ and his entire series of articles, talk about memory ordering abstractly, in terms of the ordering and visibility guarantees provided by different barriers types. My question is how are these barriers and memory ordering semantics

How to rewrite a files content? Linux x86_64, assembly, GAS

╄→尐↘猪︶ㄣ 提交于 2021-02-11 12:29:31
问题 Hi ive got this exciting task, almost done actually.. but it fails in a funny aspect. The mission is to load a file with integers, sort them and write them to a file. Yay... Well my program is doing that, but it keeps the original content. ie: lets say 45 32 Should get the ordered content 32 45 Well my program is keeping the original content and adds the new: 45 32 32 45. So any sugestions on solving this? Though of deleting the original file and creating a new one in the same name. But thats

Linux sys_open in 64-bit NASM returns negative value

耗尽温柔 提交于 2021-02-11 08:52:29
问题 I am opening an existing file to write into it, using sys_open and sys_write. The sys_write works correctly when I create a new file as shown below. But if I use sys_open, the return value is negative (-13, which is "Permission denied") and the write doesn't work (of course). This works: section .data File_Name: db '/opt/Test_Output_Files/Linux_File_Test',0 File_Mode: dq 754q Write_Buffer: db 'This is what I want to write',0 section .text ; Create file mov rax,85 ; sys_creat mov rdi,File_Name

In GDB how do I print 0xc(%rsp)?

╄→гoц情女王★ 提交于 2021-02-11 07:31:29
问题 I'm trying to debug some code for a project and I've come up against this line cmpl $0x7,0xc(%rsp) . What is 0xc(%rsp), and how do I print it? 回答1: What is 0xc(%rsp) The memory location 12 bytes above current stack pointer. The value at that location is being compared with 7 . and how do I print it? (gdb) print $rsp+0xc 来源: https://stackoverflow.com/questions/16212339/in-gdb-how-do-i-print-0xcrsp

In GDB how do I print 0xc(%rsp)?

喜欢而已 提交于 2021-02-11 07:31:10
问题 I'm trying to debug some code for a project and I've come up against this line cmpl $0x7,0xc(%rsp) . What is 0xc(%rsp), and how do I print it? 回答1: What is 0xc(%rsp) The memory location 12 bytes above current stack pointer. The value at that location is being compared with 7 . and how do I print it? (gdb) print $rsp+0xc 来源: https://stackoverflow.com/questions/16212339/in-gdb-how-do-i-print-0xcrsp

Passing parameters from C to GNU Assembly function in 64bit

坚强是说给别人听的谎言 提交于 2021-02-11 07:09:02
问题 I have main function in C that runs code in assembly. I just want to make simple sum: main.c #include <stdio.h> extern int addByAssembly(int first_number, int second_number); int main (int argc, char **argv) { int sum=0; sum = addByAssembly(5,4); printf ("%d\n",sum); return 0; } addByAssembly.s .data SYSREAD = 0 SYSWRITE = 1 SYSEXIT = 60 STDOUT = 1 STDIN = 0 EXIT_SUCCESS = 0 .text #.global main #main: #call write #movq $SYSEXIT, %rax #movq $EXIT_SUCCESS, %rdi #syscall #******** .globl

What does the D flag in the code segment descriptor do for x86-64 instructions?

谁说我不能喝 提交于 2021-02-10 18:14:50
问题 I'm trying to understand the workings of the D flag in the code segment descriptor when used in the x86-64 code. It's set in the D/B bit 22 of the code segment descriptor as shown on this diagram: The Intel documentation (from section 3.4.5 Segment Descriptors) states the following: D/B (default operation size/default stack pointer size and/or upper bound) flag Performs different functions depending on whether the segment descriptor is an executable code segment, an expand-down data segment,

Why are there no NAND, NOR and XNOR instructions in X86?

﹥>﹥吖頭↗ 提交于 2021-02-10 17:48:01
问题 They're one of the simplest "instructions" you could perform on a computer (they're the first ones I'd personally implement) Performing NOT(AND(x, y)) doubles execution time AND dependency chain length AND code size BMI1 introduced "andnot" which is a meaningful addition that is a unique operation - why not the ones in the title of this question? You usually read answers among the lines of "they take up valuable op-code space" but then I look at all of the kmask operations introduced with