C int type for 48bits cpu

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

C int type for 48bits cpu

gamma_chen
Hi,

LLVM only support primitive type i32 and i64, no i48. The clang translate "C int type" to i32 too. My question is if a cpu is 48 bits register size, how to write the backend for 48 bits register architecture. Can someone help me with this problem?

Jonathan


_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Reply | Threaded
Open this post in threaded view
|

Re: C int type for 48bits cpu

Stephen Checkoway

On Sep 5, 2013, at 3:37 AM, gamma_chen <[hidden email]> wrote:

> LLVM only support primitive type i32 and i64, no i48. The clang translate "C int type" to i32 too. My question is if a cpu is 48 bits register size, how to write the backend for 48 bits register architecture. Can someone help me with this problem?


I'm not LLVM expert, but I'm pretty sure your initial sentence is false. For example:

steve$ cat a.ll
; ModuleID = 'a.c'
target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
target triple = "x86_64-apple-macosx10.8.0"

define i48 @foo() nounwind uwtable ssp {
  ret i48 3
}
steve$ clang -S a.ll
steve$ cat a.s
        .section __TEXT,__text,regular,pure_instructions
        .globl _foo
        .align 4, 0x90
_foo:                                   ## @foo
        .cfi_startproc
## BB#0:
        pushq %rbp
Ltmp2:
        .cfi_def_cfa_offset 16
Ltmp3:
        .cfi_offset %rbp, -16
        movq %rsp, %rbp
Ltmp4:
        .cfi_def_cfa_register %rbp
        movl $3, %eax
        popq %rbp
        ret
        .cfi_endproc


.subsections_via_symbols

As you can see, i48 was a perfectly valid LLVM type.

Without having written a backend, I'd imagine you specify what types are legal and then either generic code or target-dependent code is going to legalize the type. In my example, I imagine the i48 was legalized to an i64 which is legal for my target architecture.

--
Stephen Checkoway




_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Reply | Threaded
Open this post in threaded view
|

Re: C int type for 48bits cpu

Tim Northover-2
Hi Jonathan

> As you can see, i48 was a perfectly valid LLVM type.
>
> Without having written a backend, I'd imagine you specify what
> types are legal and then either generic code or target-dependent
> code is going to legalize the type. In my example, I imagine the
> i48 was legalized to an i64 which is legal for my target architecture.

Only certain types can be legal in a normal backend, everything gets
mapped to the MVT enum. Currently the only backend integer types
allowed are i1, i8, i16, i32, i64 and i128. To support i48 properly
you'd have to add it to that list of types. Running a "grep -r i128"
should give you a very rough indication of what's involved. Less than
I expected, actually.

There are three possible outcomes after doing that:

1. Everything works perfectly.
2. Code expects power-of-2 widths and breaks when your backend starts
feeding it i48 (in particular it may expect to be able to reach a
legal type by doubling or halving the width repeatedly)
3. Code expects power-of-2 widths and every existing backend breaks
horribly because of this new i48.

I'd hope for 2, but fear 3.

Clang should be flexible about what int maps to, though. MSP430, for
example, uses i16. Of course, you shouldn't be surprised if there are
extra bugs to deal with there too.

Cheers.

Tim.
_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Reply | Threaded
Open this post in threaded view
|

Re: C int type for 48bits cpu

gamma_chen
In reply to this post by Stephen Checkoway
Stephen,

Thank you. The llvm IR accept the i48 but it will fail if I use i48 as data type in *.td file. Do you know how to add i48 type in *.td, or it is not allowed.
The other question is "Is it possible to make clang compiler generate i48 for "C int type varialbe?". If you don't know the answer of this clang question I will post it on clang development list.

Best regards

Jonathan


寄件者: Stephen Checkoway <[hidden email]>
收件者: gamma_chen <[hidden email]>
副本: "[hidden email]" <[hidden email]>; Vijay Daultani <[hidden email]>
寄件日期: 2013/9/5 (週四) 3:59 PM
主旨: Re: [LLVMdev] C int type for 48bits cpu


On Sep 5, 2013, at 3:37 AM, gamma_chen <[hidden email]> wrote:

> LLVM only support primitive type i32 and i64, no i48. The clang translate "C int type" to i32 too. My question is if a cpu is 48 bits register size, how to write the backend for 48 bits register architecture. Can someone help me with this problem?


I'm not LLVM expert, but I'm pretty sure your initial sentence is false. For example:

steve$ cat a.ll
; ModuleID = 'a.c'
target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
target triple = "x86_64-apple-macosx10.8.0"

define i48 @foo() nounwind uwtable ssp {
  ret i48 3
}
steve$ clang -S a.ll
steve$ cat a.s
    .section    __TEXT,__text,regular,pure_instructions
    .globl    _foo
    .align    4, 0x90
_foo:                                  ## @foo
    .cfi_startproc
## BB#0:
    pushq    %rbp
Ltmp2:
    .cfi_def_cfa_offset 16
Ltmp3:
    .cfi_offset %rbp, -16
    movq    %rsp, %rbp
Ltmp4:
    .cfi_def_cfa_register %rbp
    movl    $3, %eax
    popq    %rbp
    ret
    .cfi_endproc


.subsections_via_symbols

As you can see, i48 was a perfectly valid LLVM type.

Without having written a backend, I'd imagine you specify what types are legal and then either generic code or target-dependent code is going to legalize the type. In my example, I imagine the i48 was legalized to an i64 which is legal for my target architecture.

--
Stephen Checkoway






_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Reply | Threaded
Open this post in threaded view
|

Re: C int type for 48bits cpu

Duncan Sands
In reply to this post by gamma_chen
Hi Jonathan,

> LLVM only support primitive type i32 and i64, no i48. The clang translate "C int
> type" to i32 too. My question is if a cpu is 48 bits register size, how to write
> the backend for 48 bits register architecture. Can someone help me with this
> problem?

the type legalizer expects legal integer types to have a power of 2 size.
For someone who knows what they are doing it wouldn't be too hard to generalize
this to allow arbitrary sizes, such as 48, but unfortunately no-one did this
yet.

Ciao, Duncan.

_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev