mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
Bitstruct implementation.
This commit is contained in:
committed by
Christoffer Lerno
parent
29e7af843a
commit
4f09b0c351
106
test/test_suite/bitstruct/bitstruct_intcontainer.c3t
Normal file
106
test/test_suite/bitstruct/bitstruct_intcontainer.c3t
Normal file
@@ -0,0 +1,106 @@
|
||||
// #target: x64-darwin
|
||||
|
||||
module foo;
|
||||
|
||||
bitstruct BitFieldCross : uint
|
||||
{
|
||||
uint d : 0..4;
|
||||
int a : 5..22;
|
||||
uint c : 23..31;
|
||||
}
|
||||
|
||||
bitstruct BitFieldCrossU : int
|
||||
{
|
||||
uint d : 0..4;
|
||||
uint a : 5..22;
|
||||
uint c : 23..31;
|
||||
}
|
||||
|
||||
bitstruct BitFieldCrossUL : long
|
||||
{
|
||||
uint d : 0..4;
|
||||
uint a : 5..22;
|
||||
uint c : 23..40;
|
||||
uint e : 41..61;
|
||||
}
|
||||
|
||||
bitstruct BitFieldCrossULBE : long @bigendian
|
||||
{
|
||||
uint d : 0..4;
|
||||
uint a : 5..22;
|
||||
uint c : 23..40;
|
||||
uint e : 41..61;
|
||||
}
|
||||
extern fn void printf(char*, ...);
|
||||
|
||||
fn void main()
|
||||
{
|
||||
BitFieldCross xx = { 0, -177, 0 };
|
||||
printf("%d\n", xx.a);
|
||||
xx = { 0xff, -177, 0xff };
|
||||
printf("%d\n", xx.a);
|
||||
BitFieldCrossU xxu = { 0xff, 0x12345678, 0xffffffff };
|
||||
printf("%x\n", xxu.a);
|
||||
BitFieldCrossUL xxy = { 0xff, 0x12345678, 0xefff_fffe, 0xfdca9597 };
|
||||
printf("%x, %x, %x\n", xxy.a, xxy.c, xxy.e);
|
||||
BitFieldCrossULBE xxybe = { 0xff, 0x12345678, 0xefff_fffe, 0xfdca9597 };
|
||||
printf("%x, %x, %x\n", xxybe.a, xxybe.c, xxybe.e);
|
||||
}
|
||||
|
||||
/* #expect: foo.ll
|
||||
|
||||
define void @main() #0 {
|
||||
entry:
|
||||
%xx = alloca i32, align 4
|
||||
%xxu = alloca i32, align 4
|
||||
%xxy = alloca i64, align 8
|
||||
%xxybe = alloca i64, align 8
|
||||
store i32 8382944, i32* %xx, align 4
|
||||
%0 = load i32, i32* %xx, align 4
|
||||
%1 = shl i32 %0, 9
|
||||
%2 = ashr i32 %1, 14
|
||||
call void (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i32 0, i32 0), i32 %2)
|
||||
store i32 2147478015, i32* %xx, align 4
|
||||
%3 = load i32, i32* %xx, align 4
|
||||
%4 = load i32, i32* %xx, align 4
|
||||
%5 = shl i32 %4, 9
|
||||
%6 = ashr i32 %5, 14
|
||||
call void (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i32 0, i32 0), i32 %6)
|
||||
store i32 -7680225, i32* %xxu, align 4
|
||||
%7 = load i32, i32* %xxu, align 4
|
||||
%8 = lshr i32 %7, 5
|
||||
%9 = and i32 %8, 524287
|
||||
call void (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i32 0, i32 0), i32 %9)
|
||||
store i64 1525365675337109279, i64* %xxy, align 8
|
||||
%10 = load i64, i64* %xxy, align 8
|
||||
%11 = lshr i64 %10, 5
|
||||
%12 = and i64 %11, 524287
|
||||
%13 = trunc i64 %12 to i32
|
||||
%14 = load i64, i64* %xxy, align 8
|
||||
%15 = lshr i64 %14, 23
|
||||
%16 = and i64 %15, 524287
|
||||
%17 = trunc i64 %16 to i32
|
||||
%18 = load i64, i64* %xxy, align 8
|
||||
%19 = lshr i64 %18, 41
|
||||
%20 = and i64 %19, 4194303
|
||||
%21 = trunc i64 %20 to i32
|
||||
call void (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i32 0, i32 0), i32 %13, i32 %17, i32 %21)
|
||||
store i64 2292062829969091349, i64* %xxybe, align 8
|
||||
%22 = load i64, i64* %xxybe, align 8
|
||||
%23 = call i64 @llvm.bswap.i64(i64 %22)
|
||||
%24 = lshr i64 %23, 5
|
||||
%25 = and i64 %24, 524287
|
||||
%26 = trunc i64 %25 to i32
|
||||
%27 = load i64, i64* %xxybe, align 8
|
||||
%28 = call i64 @llvm.bswap.i64(i64 %27)
|
||||
%29 = lshr i64 %28, 23
|
||||
%30 = and i64 %29, 524287
|
||||
%31 = trunc i64 %30 to i32
|
||||
%32 = load i64, i64* %xxybe, align 8
|
||||
%33 = call i64 @llvm.bswap.i64(i64 %32)
|
||||
%34 = lshr i64 %33, 41
|
||||
%35 = and i64 %34, 4194303
|
||||
%36 = trunc i64 %35 to i32
|
||||
call void (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i32 0, i32 0), i32 %26, i32 %31, i32 %36)
|
||||
ret void
|
||||
}
|
||||
Reference in New Issue
Block a user