The source code of cpubrand_string.cpp presented in “Mac OSX CPU Information. Terminal and Programmatically” post and tested on Mac with Apple Silicon processor works the same when it was compiled on Mac with Apple Silicon or Intel processors as well. Apple announced new Rosetta system that allows users to run applications that contain x86_64 instructions on Apple Silicon. In the same time Apple warns that Intel-based Mac compute code may not always apply on Apple silicon. I already met these differences of executable behavior running on Apple Silicon machine for some code with Apple Silicon and Intel instruction. May I will present these examples later. Here I just want to present how machine instructions looks like when cpubrand_string.cpp was complied on Macs with Apple Silicon and Intel processors.
Intel processor instructions for cpubrand_string.cpp source file:
(lldb) disassemble –name main cpubrand_stringIntel`main: cpubrand_stringIntel[0x100003e00] <+0>: pushq %rbp cpubrand_stringIntel[0x100003e01] <+1>: movq %rsp, %rbp cpubrand_stringIntel[0x100003e04] <+4>: subq $0x150, %rsp ; imm = 0x150 cpubrand_stringIntel[0x100003e0b] <+11>: leaq -0x11c(%rbp), %rax cpubrand_stringIntel[0x100003e12] <+18>: movq 0x1e7(%rip), %rcx ; (void *)0x0000000000000000 cpubrand_stringIntel[0x100003e19] <+25>: movq (%rcx), %rcx cpubrand_stringIntel[0x100003e1c] <+28>: movq %rcx, -0x8(%rbp) cpubrand_stringIntel[0x100003e20] <+32>: movl $0x0, -0x120(%rbp) cpubrand_stringIntel[0x100003e2a] <+42>: movl %edi, -0x124(%rbp) cpubrand_stringIntel[0x100003e30] <+48>: movq %rsi, -0x130(%rbp) cpubrand_stringIntel[0x100003e37] <+55>: movq $0x3, -0x138(%rbp) cpubrand_stringIntel[0x100003e42] <+66>: leaq 0x117(%rip), %rdi ; “machdep.cpu.brand_string” cpubrand_stringIntel[0x100003e49] <+73>: movq %rax, %rsi cpubrand_stringIntel[0x100003e4c] <+76>: leaq -0x138(%rbp), %rdx cpubrand_stringIntel[0x100003e53] <+83>: callq 0x100003f22 ; symbol stub for: sysctlnametomib cpubrand_stringIntel[0x100003e58] <+88>: xorl %r8d, %r8d cpubrand_stringIntel[0x100003e5b] <+91>: movl %r8d, %ecx cpubrand_stringIntel[0x100003e5e] <+94>: leaq -0x110(%rbp), %rdx cpubrand_stringIntel[0x100003e65] <+101>: leaq -0x11c(%rbp), %rdi cpubrand_stringIntel[0x100003e6c] <+108>: movq $0xff, -0x138(%rbp) cpubrand_stringIntel[0x100003e77] <+119>: movl $0x3, %esi cpubrand_stringIntel[0x100003e7c] <+124>: leaq -0x138(%rbp), %r9 cpubrand_stringIntel[0x100003e83] <+131>: movq %rcx, -0x148(%rbp) cpubrand_stringIntel[0x100003e8a] <+138>: movq %r9, %rcx cpubrand_stringIntel[0x100003e8d] <+141>: movq -0x148(%rbp), %r8 cpubrand_stringIntel[0x100003e94] <+148>: movq -0x148(%rbp), %r9 cpubrand_stringIntel[0x100003e9b] <+155>: movl %eax, -0x14c(%rbp) cpubrand_stringIntel[0x100003ea1] <+161>: callq 0x100003f1c ; symbol stub for: sysctl cpubrand_stringIntel[0x100003ea6] <+166>: movl %eax, -0x13c(%rbp) cpubrand_stringIntel[0x100003eac] <+172>: cmpl $0x0, -0x13c(%rbp) cpubrand_stringIntel[0x100003eb3] <+179>: jne 0x100003ed3 ; <+211> cpubrand_stringIntel[0x100003eb9] <+185>: leaq -0x110(%rbp), %rsi cpubrand_stringIntel[0x100003ec0] <+192>: leaq 0xb2(%rip), %rdi ; “CPU Brand String: %s\n” cpubrand_stringIntel[0x100003ec7] <+199>: movb $0x0, %al cpubrand_stringIntel[0x100003ec9] <+201>: callq 0x100003f16 ; symbol stub for: printf cpubrand_stringIntel[0x100003ece] <+206>: jmp 0x100003ee7 ; <+231> cpubrand_stringIntel[0x100003ed3] <+211>: movl -0x13c(%rbp), %esi cpubrand_stringIntel[0x100003ed9] <+217>: leaq 0xaf(%rip), %rdi ; “Cannot get CPU Brand String. Error: %d\n” cpubrand_stringIntel[0x100003ee0] <+224>: movb $0x0, %al cpubrand_stringIntel[0x100003ee2] <+226>: callq 0x100003f16 ; symbol stub for: printf cpubrand_stringIntel[0x100003ee7] <+231>: movq 0x112(%rip), %rax ; (void *)0x0000000000000000 cpubrand_stringIntel[0x100003eee] <+238>: movq (%rax), %rax cpubrand_stringIntel[0x100003ef1] <+241>: movq -0x8(%rbp), %rcx cpubrand_stringIntel[0x100003ef5] <+245>: cmpq %rcx, %rax cpubrand_stringIntel[0x100003ef8] <+248>: jne 0x100003f09 ; <+265> cpubrand_stringIntel[0x100003efe] <+254>: xorl %eax, %eax cpubrand_stringIntel[0x100003f00] <+256>: addq $0x150, %rsp ; imm = 0x150 cpubrand_stringIntel[0x100003f07] <+263>: popq %rbp cpubrand_stringIntel[0x100003f08] <+264>: retq cpubrand_stringIntel[0x100003f09] <+265>: callq 0x100003f10 ; symbol stub for: __stack_chk_fail cpubrand_stringIntel[0x100003f0e] <+270>: ud2 |
Apple Silicon processor instructions for cpubrand_string.cpp source file:
(lldb) disassemble –name main cpubrand_string`main: cpubrand_string[0x100003de0] <+0>: sub sp, sp, #0x180 ; =0x180 cpubrand_string[0x100003de4] <+4>: stp x28, x27, [sp, #0x160] cpubrand_string[0x100003de8] <+8>: stp x29, x30, [sp, #0x170] cpubrand_string[0x100003dec] <+12>: add x29, sp, #0x170 ; =0x170 cpubrand_string[0x100003df0] <+16>: adrp x8, 1 cpubrand_string[0x100003df4] <+20>: ldr x8, [x8] cpubrand_string[0x100003df8] <+24>: ldr x8, [x8] cpubrand_string[0x100003dfc] <+28>: stur x8, [x29, #-0x18] cpubrand_string[0x100003e00] <+32>: str wzr, [sp, #0x48] cpubrand_string[0x100003e04] <+36>: str w0, [sp, #0x44] cpubrand_string[0x100003e08] <+40>: str x1, [sp, #0x38] cpubrand_string[0x100003e0c] <+44>: add x8, sp, #0x30 ; =0x30 cpubrand_string[0x100003e10] <+48>: mov x9, #0x3 cpubrand_string[0x100003e14] <+52>: str x9, [sp, #0x30] cpubrand_string[0x100003e18] <+56>: adrp x0, 0 cpubrand_string[0x100003e1c] <+60>: add x0, x0, #0xf60 ; =0xf60 cpubrand_string[0x100003e20] <+64>: add x9, sp, #0x4c ; =0x4c cpubrand_string[0x100003e24] <+68>: mov x1, x9 cpubrand_string[0x100003e28] <+72>: mov x2, x8 cpubrand_string[0x100003e2c] <+76>: str x8, [sp, #0x20] cpubrand_string[0x100003e30] <+80>: str x9, [sp, #0x18] cpubrand_string[0x100003e34] <+84>: bl 0x100003f0c ; symbol stub for: sysctlnametomib cpubrand_string[0x100003e38] <+88>: mov x8, #0xff cpubrand_string[0x100003e3c] <+92>: str x8, [sp, #0x30] cpubrand_string[0x100003e40] <+96>: ldr x8, [sp, #0x18] cpubrand_string[0x100003e44] <+100>: mov x0, x8 cpubrand_string[0x100003e48] <+104>: mov w1, #0x3 cpubrand_string[0x100003e4c] <+108>: add x2, sp, #0x59 ; =0x59 cpubrand_string[0x100003e50] <+112>: ldr x3, [sp, #0x20] cpubrand_string[0x100003e54] <+116>: mov x9, #0x0 cpubrand_string[0x100003e58] <+120>: mov x4, x9 cpubrand_string[0x100003e5c] <+124>: mov x5, x9 cpubrand_string[0x100003e60] <+128>: bl 0x100003f00 ; symbol stub for: sysctl cpubrand_string[0x100003e64] <+132>: str w0, [sp, #0x2c] cpubrand_string[0x100003e68] <+136>: ldr w10, [sp, #0x2c] cpubrand_string[0x100003e6c] <+140>: cbnz w10, 0x100003e8c ; <+172> at cpubrand_string.cpp:15:58 cpubrand_string[0x100003e70] <+144>: adrp x0, 0 cpubrand_string[0x100003e74] <+148>: add x0, x0, #0xf79 ; =0xf79 cpubrand_string[0x100003e78] <+152>: mov x8, sp cpubrand_string[0x100003e7c] <+156>: add x9, sp, #0x59 ; =0x59 cpubrand_string[0x100003e80] <+160>: str x9, [x8] cpubrand_string[0x100003e84] <+164>: bl 0x100003ef4 ; symbol stub for: printf cpubrand_string[0x100003e88] <+168>: b 0x100003eb4 ; <+212> at cpubrand_string.cpp cpubrand_string[0x100003e8c] <+172>: ldr w8, [sp, #0x2c] cpubrand_string[0x100003e90] <+176>: mov x0, x8 cpubrand_string[0x100003e94] <+180>: adrp x9, 0 cpubrand_string[0x100003e98] <+184>: add x9, x9, #0xf8f ; =0xf8f cpubrand_string[0x100003e9c] <+188>: str x0, [sp, #0x10] cpubrand_string[0x100003ea0] <+192>: mov x0, x9 cpubrand_string[0x100003ea4] <+196>: mov x9, sp cpubrand_string[0x100003ea8] <+200>: ldr x10, [sp, #0x10] cpubrand_string[0x100003eac] <+204>: str x10, [x9] cpubrand_string[0x100003eb0] <+208>: bl 0x100003ef4 ; symbol stub for: printf cpubrand_string[0x100003eb4] <+212>: adrp x8, 1 cpubrand_string[0x100003eb8] <+216>: ldr x8, [x8] cpubrand_string[0x100003ebc] <+220>: ldr x8, [x8] cpubrand_string[0x100003ec0] <+224>: ldur x9, [x29, #-0x18] cpubrand_string[0x100003ec4] <+228>: cmp x8, x9 cpubrand_string[0x100003ec8] <+232>: b.ne 0x100003ee4 ; <+260> at cpubrand_string.cpp cpubrand_string[0x100003ecc] <+236>: mov w8, #0x0 cpubrand_string[0x100003ed0] <+240>: mov x0, x8 cpubrand_string[0x100003ed4] <+244>: ldp x29, x30, [sp, #0x170] cpubrand_string[0x100003ed8] <+248>: ldp x28, x27, [sp, #0x160] cpubrand_string[0x100003edc] <+252>: add sp, sp, #0x180 ; =0x180 cpubrand_string[0x100003ee0] <+256>: ret cpubrand_string[0x100003ee4] <+260>: bl 0x100003ee8 ; symbol stub for: __stack_chk_fail |