x86-64

How expensive is it to convert between int and double?

女生的网名这么多〃 提交于 2019-12-31 18:58:56
问题 I often see code that converts ints to doubles to ints to doubles and back once again (sometimes for good reasons, sometimes not), and it just occurred to me that this seems like a "hidden" cost in my program. Let's assume the conversion method is truncation. So, just how expensive is it? I'm sure it varies depending on hardware, so let's assume a newish Intel processor (Haswell, if you like, though I'll take anything). Some metrics I'd be interested in (though a good answer needn't have all

How expensive is it to convert between int and double?

微笑、不失礼 提交于 2019-12-31 18:57:45
问题 I often see code that converts ints to doubles to ints to doubles and back once again (sometimes for good reasons, sometimes not), and it just occurred to me that this seems like a "hidden" cost in my program. Let's assume the conversion method is truncation. So, just how expensive is it? I'm sure it varies depending on hardware, so let's assume a newish Intel processor (Haswell, if you like, though I'll take anything). Some metrics I'd be interested in (though a good answer needn't have all

How expensive is it to convert between int and double?

天涯浪子 提交于 2019-12-31 18:57:32
问题 I often see code that converts ints to doubles to ints to doubles and back once again (sometimes for good reasons, sometimes not), and it just occurred to me that this seems like a "hidden" cost in my program. Let's assume the conversion method is truncation. So, just how expensive is it? I'm sure it varies depending on hardware, so let's assume a newish Intel processor (Haswell, if you like, though I'll take anything). Some metrics I'd be interested in (though a good answer needn't have all

Is there an `x86` instruction to tell which core the instruction is being run on?

浪子不回头ぞ 提交于 2019-12-31 12:53:49
问题 When I cat /proc/cpuinfo , I see 8 cores, with ID's from 0 to 7 . Is there an x86 instruction that will report the core id of the core that the instruction itself is running on? I looked at cpuid but that does not seem to return coreid under any parameter setting. 回答1: The Intel® 64 and IA-32 Architectures Software Developer's Manual Volume 3A: System Programming Guide, Part 1 , section 8.4.5 Identifying Logical Processors in an MP System lists, among others: This APIC ID is reported by CPUID

Why is memcmp(a, b, 4) only sometimes optimized to a uint32 comparison?

£可爱£侵袭症+ 提交于 2019-12-31 10:56:58
问题 Given this code: #include <string.h> int equal4(const char* a, const char* b) { return memcmp(a, b, 4) == 0; } int less4(const char* a, const char* b) { return memcmp(a, b, 4) < 0; } GCC 7 on x86_64 introduced an optimization for the first case (Clang has done it for a long time): mov eax, DWORD PTR [rsi] cmp DWORD PTR [rdi], eax sete al movzx eax, al But the second case still calls memcmp() : sub rsp, 8 mov edx, 4 call memcmp add rsp, 8 shr eax, 31 Could a similar optimization be applied to

X86-64 NASM calling extern c functions

…衆ロ難τιáo~ 提交于 2019-12-31 07:54:26
问题 Im very new to assembly but know a bit of c. Im playing around with extern function calls like extern _printf str db "Hello", 0 push str call _printf but cant find any tutorials using extern functions except scanf and printf. For example strcmp? How can i call strcmp in my case? 回答1: Here is my answer. It is specific to x86-64 though. Please know that when pushing arguments to a function, you usually place the first 6 in registers rdi , rsi , rdx , rcx , r8 , and r9 . The rest get pushed to

X86-64 NASM calling extern c functions

混江龙づ霸主 提交于 2019-12-31 07:54:04
问题 Im very new to assembly but know a bit of c. Im playing around with extern function calls like extern _printf str db "Hello", 0 push str call _printf but cant find any tutorials using extern functions except scanf and printf. For example strcmp? How can i call strcmp in my case? 回答1: Here is my answer. It is specific to x86-64 though. Please know that when pushing arguments to a function, you usually place the first 6 in registers rdi , rsi , rdx , rcx , r8 , and r9 . The rest get pushed to

Will playstore reject apps with armeabi-v7a, arm64-v8a, x86 but no x86-64 support?

試著忘記壹切 提交于 2019-12-31 02:59:17
问题 From android developer website, https://developer.android.com/distribute/best-practices/develop/64-bit it is clear that starting August 1, 2019, apps published on Google Play will need to support 64-bit architectures. Our current app has native libraries for armeabi-v7a, arm64-v8a, x86 ABIs but no x86-64. This is because one of the cordova plugins we are using doesn't provide X86-64 support. Will playstore reject the app update or pass it considering there is arm64-v8a support or we will have

Differences in the initialization of the EAX register when calling a function in C and C++

心已入冬 提交于 2019-12-30 17:21:10
问题 There is a curious difference between assemblies of a small program, when compiled as a C-program or as a C++-program (for Linux x86-64). The code in question: int fun(); int main(){ return fun(); } Compiling it as a C-program (with gcc -O2 ) yields: main: xorl %eax, %eax jmp fun But compiling it as a C++-program (with g++ -02 ) yields: main: jmp _Z3funv I find it puzzling, that the C-version initializes the return value of the main-function with 0 ( xorl %eax, %eax ). Which feature of the C

Why does Apple use R8l for the byte registers instead of R8b?

我的未来我决定 提交于 2019-12-30 13:47:10
问题 I saw this in Making Code 64-Bit Clean topic ╔═════════════════════╤══════════════════════════════════════════════════════╗ ║ Register name │ Description ║ ╠═════════════════════╪══════════════════════════════════════════════════════╣ ║ R8 │ A 64-bit register. ║ ╟─────────────────────┼──────────────────────────────────────────────────────╢ ║ R8d │ A 32-bit register containing the bottom half of R8. ║ ╟─────────────────────┼──────────────────────────────────────────────────────╢ ║ R8w │ A 16