x86-64

Can branch prediction cause illegal instruction?

不问归期 提交于 2019-12-05 01:08:12
In the following pseudo-code: if (rdtscp supported by hardware) { Invoke "rdtscp" instruction } else { Invoke "rdtsc" instruction } Let's say the CPU does not support the rdtscp instruction and so we fallback to the else statement. If CPU mispredicts the branch, is it possible for the instruction pipeline to try to execute rdtscp and throw an Illgal Instruction error? It is explicitly documented for the #UD trap (Invalid Opcode Execution) in the Intel Processor Manuals, Volume 3A, chapter 6.15: In Intel 64 and IA-32 processors that implement out-of-order execution microarchitectures, this

How does Linux support more than 512GB of virtual address range in x86-64?

允我心安 提交于 2019-12-05 00:08:23
问题 The user virtual address space for x86-64 with Linux is 47 bit long. Which essentially means that Linux can map a process with around ~128 TB virtual address range. However, what confuses me that x86-64 architecture supports ISA defined 4-level hierarchical page table (arranged as radix-tree) for each process. The root of the page table can only map up to 512 GB of contiguous virtual address space. So how Linux can support more than 512GB of virtual address range? Does it uses multiple page

How to enter 64-bit mode on a x86_64

孤街醉人 提交于 2019-12-04 23:06:43
问题 I've found a nice bit of assembly in xv6 https://github.com/chrisdew/xv6/blob/master/bootasm.S which shows me how to move from 16 bit to 32 bit protected mode. Does anyone know of a similar example for entering the 64-bit mode? (Either through or without using 32 bit mode.) 回答1: In order to enable 64 bit capabillities, you must switch the CPU to Long Mode. To enter Long Mode on a 64-bit x86 processor (x86-64): If paging is enabled, disable paging. If CR4.PAE is not already set, set it. Set

Python安装和环境配置教程

走远了吗. 提交于 2019-12-04 21:10:01
进官网根据不同的操作系统,下载适合自己的编译环境(在百度里直接输入Python) 选择安装包(我选择的是3.8.0版本) python官方下载目录中有好多种安装方式,一般情况选择Windows x86-64 executable installer Download Windows x86 web-based installer–基于网络安装 Download Windows x86 executable installer–安装文件 Download Windows x86 embeddable zip file–压缩包 Download Windows x86-64 web-based installer–64位基于网络安装 Download Windows x86-64 executable installer–64位安装文件 Download Windows x86-64 embeddable zip file–64位压缩包 安装过程: 为了不去设置环境变量,我选择Customize installation安装,并且勾选Add Python 3.8 to PATH。 选择安装路径,我安装到D:\Program Files\Python3下面。 安装完成: 测试是否安装成功(输入“Python”,如果提示相应的版本号和一些指令,说明你的Python就已经安装好了

Signed saturated add of 64-bit ints?

吃可爱长大的小学妹 提交于 2019-12-04 17:50:51
问题 I'm looking for some C code for signed saturated 64-bit addition that compiles to efficient x86-64 code with the gcc optimizer. Portable code would be ideal, although an asm solution could be used if necessary. static const int64 kint64max = 0x7fffffffffffffffll; static const int64 kint64min = 0x8000000000000000ll; int64 signed_saturated_add(int64 x, int64 y) { bool x_is_negative = (x & kint64min) != 0; bool y_is_negative = (y & kint64min) != 0; int64 sum = x+y; bool sum_is_negative = (sum &

Are there benefits to running X86-64 Python on a 64-bit CPU in a 64-bit OS?

邮差的信 提交于 2019-12-04 16:29:27
问题 What kind of benefits are there to running the amd64 builds of Python and extensions? (Lots of extensions compiled for amd64 here.) I have an i5 processor and Win7 64-bit, so it seems like it would be appropriate. But it also sounds like it is buggy, beta, unsupported, etc. Does it actually provide a performance benefit? In which areas? I'd be running SciPy, NumPy, etc. I occasionally get "out of memory" errors with 32-bit Python and my machine has 4 GiB of RAM. Can win32 packages be

Is mfence for rdtsc necessary on x86_64 platform?

被刻印的时光 ゝ 提交于 2019-12-04 16:09:28
unsigned int lo = 0; unsigned int hi = 0; __asm__ __volatile__ ( "mfence;rdtsc" : "=a"(lo), "=d"(hi) : : "memory" ); mfence in the above code, is it necessary? Based on my test, cpu reorder is not found. The fragment of test code is included below. inline uint64_t clock_cycles() { unsigned int lo = 0; unsigned int hi = 0; __asm__ __volatile__ ( "rdtsc" : "=a"(lo), "=d"(hi) ); return ((uint64_t)hi << 32) | lo; } unsigned t1 = clock_cycles(); unsigned t2 = clock_cycles(); assert(t2 > t1); What you need to perform a sensible measurement with rdtsc is a serializing instruction. As it is well known

Can I make shared library constructors execute before relocations?

风流意气都作罢 提交于 2019-12-04 14:54:45
Background : I'm trying to implement a system like that described in this previous answer . In short, I have an application that links against a shared library (on Linux at present). I would like that shared library to switch between multiple implementations at runtime (for instance, based on whether the host CPU supports a certain instruction set). In its simplest case, I have three distinct shared library files: libtest.so : This is the "vanilla" version of the library that will be used as a fallback case. libtest_variant.so : This is the "optimized" variant of the library that I would like

How to ensure that RDTSC is accurate?

╄→尐↘猪︶ㄣ 提交于 2019-12-04 14:31:47
I've read that RDTSC can gives false readings and should not be relied upon. Is this true and if so what can be done about it? Very old CPU's have a RDTSC that is accurate. The problem However newer CPU's have a problem. Engineers decided that RDTSC would be great for telling time. However if a CPU throttles the frequency RDTSC is useless for telling time. The aforementioned braindead engineers then decided to 'fix' this problem by having the TSC always run at the same frequency, even if the CPU slows down. This has the 'advantage' that TSC can be used for telling elapsed (wall clock) time.

Why am I receiving SIGSEGV when invoking the sys_pause syscall?

…衆ロ難τιáo~ 提交于 2019-12-04 13:43:19
I am trying to create an x86_64 assembly program that displays "SIGTERM received" whenever the SIGTERM signal is sent. My application is using Linux syscalls directly: %define sys_write 0x01 %define sys_rt_sigaction 0x0d %define sys_pause 0x22 %define sys_exit 0x3c %define SIGTERM 0x0f %define STDOUT 0x01 ; Definition of sigaction struct for sys_rt_sigaction struc sigaction .sa_handler resq 1 .sa_flags resq 1 .sa_restorer resq 1 .sa_mask resq 1 endstruc section .data ; Message shown when a syscall fails error_msg db 'syscall error', 0x0a error_msg_len equ $ - error_msg ; Message shown when