Play more with strange bit sizes

This commit is contained in:
Artemis Tosini 2018-12-10 00:24:05 +00:00
parent cdab9d90a1
commit 0ddb1f8dc5
Signed by: artemist
GPG key ID: 094FBF1D31E6C1BB
6 changed files with 115 additions and 0 deletions

10
C/strange_size/i65.c Normal file
View file

@ -0,0 +1,10 @@
#include <stdio.h>
#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);
return 0;
}

46
C/strange_size/i65.s Normal file
View file

@ -0,0 +1,46 @@
; ModuleID = 'i65.c'
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
; Function Attrs: noinline nounwind optnone sspstrong uwtable
define dso_local i32 @main(i32, i8**) #0 {
%3 = alloca i32, align 4
%4 = alloca i32, align 4
%5 = alloca i8**, align 8
%6 = alloca i65, align 8
%7 = alloca i65, align 8
%8 = alloca i65, align 8
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
%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
%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)
ret i32 0
}
declare i32 @printf(i8*, ...) #1
attributes #0 = { noinline nounwind optnone sspstrong uwtable "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" }
attributes #1 = { "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" }
!llvm.module.flags = !{!0, !1, !2}
!llvm.ident = !{!3}
!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 7, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{!"clang version 7.0.0 (tags/RELEASE_700/final)"}

59
C/strange_size/i65.s.s Normal file
View file

@ -0,0 +1,59 @@
.text
.intel_syntax noprefix
.file "i65.c"
.globl main # -- Begin function main
.p2align 4, 0x90
.type main,@function
main: # @main
.cfi_startproc
# %bb.0:
push rbp
.cfi_def_cfa_offset 16
.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
mov qword ptr [rbp - 64], rsi
mov byte ptr [rbp - 24], 1
mov qword ptr [rbp - 32], -1
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]
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
call printf
xor eax, eax
add rsp, 80
pop rbp
.cfi_def_cfa rsp, 8
ret
.Lfunc_end0:
.size main, .Lfunc_end0-main
.cfi_endproc
# -- End function
.type .L.str,@object # @.str
.section .rodata.str1.1,"aMS",@progbits,1
.L.str:
.asciz "%lu + %lu = %lu\n"
.size .L.str, 17
.ident "clang version 7.0.0 (tags/RELEASE_700/final)"
.section ".note.GNU-stack","",@progbits