i65 is super weird

This commit is contained in:
Artemis Tosini 2018-12-10 00:33:34 +00:00
parent 0ddb1f8dc5
commit a8d4c65179
Signed by: artemist
GPG key ID: 094FBF1D31E6C1BB
3 changed files with 30 additions and 32 deletions

View file

@ -2,9 +2,9 @@
#include <stdint.h>
int main(int argc, char **argv) {
uint64_t i = (uint64_t)(-1LL);
uint64_t j = (uint64_t)(-1LL);
uint64_t k = i + j;
printf("%lu + %lu = %lu\n", i, j, k);
uint64_t i = 1UL << 63;
uint64_t j = 1UL << 63;
uint64_t k = (i + j) >> 1;
printf("(%lu + %lu) >> 1 = %lu\n", i, j, k);
return 0;
}

View file

@ -3,7 +3,7 @@ source_filename = "i65.c"
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-pc-linux-gnu"
@.str = private unnamed_addr constant [17 x i8] c"%lu + %lu = %lu\0A\00", align 1
@.str = private unnamed_addr constant [24 x i8] c"(%lu + %lu) >> 1 = %lu\0A\00", align 1
; Function Attrs: noinline nounwind optnone sspstrong uwtable
define dso_local i32 @main(i32, i8**) #0 {
@ -16,19 +16,20 @@ define dso_local i32 @main(i32, i8**) #0 {
store i32 0, i32* %3, align 4
store i32 %0, i32* %4, align 4
store i8** %1, i8*** %5, align 8
store i65 -1, i65* %6, align 8
store i65 -1, i65* %7, align 8
store i65 -9223372036854775808, i65* %6, align 8
store i65 -9223372036854775808, i65* %7, align 8
%9 = load i65, i65* %6, align 8
%10 = load i65, i65* %7, align 8
%11 = add i65 %9, %10
store i65 %11, i65* %8, align 8
%12 = load i65, i65* %6, align 8
%13 = load i65, i65* %7, align 8
%14 = load i65, i65* %8, align 8
%15 = trunc i65 %12 to i64
%12 = lshr i65 %11, 1
store i65 %12, i65* %8, align 8
%13 = load i65, i65* %6, align 8
%14 = load i65, i65* %7, align 8
%15 = load i65, i65* %8, align 8
%16 = trunc i65 %13 to i64
%17 = trunc i65 %14 to i64
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i32 0, i32 0), i64 %15, i64 %16, i64 %17)
%18 = trunc i65 %15 to i64
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i32 0, i32 0), i64 %16, i64 %17, i64 %18)
ret i32 0
}

View file

@ -12,35 +12,32 @@ main: # @main
.cfi_offset rbp, -16
mov rbp, rsp
.cfi_def_cfa_register rbp
sub rsp, 80
mov dword ptr [rbp - 56], 0
mov dword ptr [rbp - 52], edi
sub rsp, 64
mov dword ptr [rbp - 40], 0
mov dword ptr [rbp - 36], edi
mov qword ptr [rbp - 64], rsi
movabs rax, -9223372036854775808
mov qword ptr [rbp - 32], rax
mov byte ptr [rbp - 24], 1
mov qword ptr [rbp - 32], -1
mov qword ptr [rbp - 16], rax
mov byte ptr [rbp - 8], 1
mov qword ptr [rbp - 16], -1
movzx eax, byte ptr [rbp - 24]
mov rcx, qword ptr [rbp - 32]
movzx edx, byte ptr [rbp - 8]
mov rsi, qword ptr [rbp - 16]
add rcx, rsi
adc rax, rdx
mov qword ptr [rbp - 48], rcx
and eax, 1
mov byte ptr [rbp - 40], al
movzx edx, byte ptr [rbp - 24]
shld rax, rcx, 63
mov qword ptr [rbp - 56], rax
mov byte ptr [rbp - 48], 0
mov rsi, qword ptr [rbp - 32]
movzx r8d, byte ptr [rbp - 8]
mov rcx, qword ptr [rbp - 16]
movzx eax, byte ptr [rbp - 40]
mov r9, qword ptr [rbp - 48]
mov qword ptr [rsp], rax
mov edi, offset .L.str
xor eax, eax
mov rdx, qword ptr [rbp - 16]
mov rcx, qword ptr [rbp - 56]
movabs rdi, offset .L.str
mov al, 0
call printf
xor eax, eax
add rsp, 80
add rsp, 64
pop rbp
.cfi_def_cfa rsp, 8
ret
@ -51,8 +48,8 @@ main: # @main
.type .L.str,@object # @.str
.section .rodata.str1.1,"aMS",@progbits,1
.L.str:
.asciz "%lu + %lu = %lu\n"
.size .L.str, 17
.asciz "(%lu + %lu) >> 1 = %lu\n"
.size .L.str, 24
.ident "clang version 7.0.0 (tags/RELEASE_700/final)"