implement more builtins
authorMatthias Braun <matze@braunis.de>
Fri, 17 Feb 2012 16:00:51 +0000 (17:00 +0100)
committerMatthias Braun <matze@braunis.de>
Fri, 17 Feb 2012 16:00:55 +0000 (17:00 +0100)
(bswap, fabs)

builtins.c
types.c
types.h

index c70936d..03d6d27 100644 (file)
@@ -113,29 +113,34 @@ void create_gnu_builtins(void)
 
        entity_t *(*f)(ir_builtin_kind,const char*,type_t*)
                = create_gnu_builtin_firm;
-       f(ir_bk_return_address, "return_address", make_function_1_type(type_void_ptr, type_unsigned_int, DM_NONE));
-       f(ir_bk_frame_address,  "frame_address",  make_function_1_type(type_void_ptr, type_unsigned_int, DM_NONE));
-       f(ir_bk_ffs,            "ffs",            make_function_1_type(type_int, type_unsigned_int, DM_CONST));
-       f(ir_bk_ffs,            "ffsl",           make_function_1_type(type_int, type_unsigned_long, DM_CONST));
-       f(ir_bk_ffs,            "ffsll",          make_function_1_type(type_int, type_unsigned_long_long, DM_CONST));
+       f(ir_bk_bswap,          "bswap32",        make_function_1_type(type_int32_t, type_int32_t, DM_CONST));
+       f(ir_bk_bswap,          "bswap64",        make_function_1_type(type_int64_t, type_int64_t, DM_CONST));
        f(ir_bk_clz,            "clz",            make_function_1_type(type_int, type_unsigned_int, DM_CONST));
        f(ir_bk_clz,            "clzl",           make_function_1_type(type_int, type_unsigned_long, DM_CONST));
        f(ir_bk_clz,            "clzll",          make_function_1_type(type_int, type_unsigned_long_long, DM_CONST));
        f(ir_bk_ctz,            "ctz",            make_function_1_type(type_int, type_unsigned_int, DM_CONST));
        f(ir_bk_ctz,            "ctzl",           make_function_1_type(type_int, type_unsigned_long, DM_CONST));
        f(ir_bk_ctz,            "ctzll",          make_function_1_type(type_int, type_unsigned_long_long, DM_CONST));
-       f(ir_bk_popcount,       "popcount",       make_function_1_type(type_int, type_unsigned_int, DM_CONST));
-       f(ir_bk_popcount,       "popcountl",      make_function_1_type(type_int, type_unsigned_long, DM_CONST));
-       f(ir_bk_popcount,       "popcountll",     make_function_1_type(type_int, type_unsigned_long_long, DM_CONST));
+       f(ir_bk_ffs,            "ffs",            make_function_1_type(type_int, type_unsigned_int, DM_CONST));
+       f(ir_bk_ffs,            "ffsl",           make_function_1_type(type_int, type_unsigned_long, DM_CONST));
+       f(ir_bk_ffs,            "ffsll",          make_function_1_type(type_int, type_unsigned_long_long, DM_CONST));
+       f(ir_bk_frame_address,  "frame_address",  make_function_1_type(type_void_ptr, type_unsigned_int, DM_NONE));
        f(ir_bk_parity,         "parity",         make_function_1_type(type_int, type_unsigned_int, DM_CONST));
        f(ir_bk_parity,         "parityl",        make_function_1_type(type_int, type_unsigned_long, DM_CONST));
        f(ir_bk_parity,         "parityll",       make_function_1_type(type_int, type_unsigned_long_long, DM_CONST));
+       f(ir_bk_popcount,       "popcount",       make_function_1_type(type_int, type_unsigned_int, DM_CONST));
+       f(ir_bk_popcount,       "popcountl",      make_function_1_type(type_int, type_unsigned_long, DM_CONST));
+       f(ir_bk_popcount,       "popcountll",     make_function_1_type(type_int, type_unsigned_long_long, DM_CONST));
        f(ir_bk_prefetch,       "prefetch",       make_function_1_type_variadic(type_float, type_void_ptr, DM_NONE));
+       f(ir_bk_return_address, "return_address", make_function_1_type(type_void_ptr, type_unsigned_int, DM_NONE));
        f(ir_bk_trap,           "trap",           make_function_type(type_void, 0, NULL, DM_NORETURN));
 
        entity_t *(*l)(const char*,type_t*) = create_gnu_builtin_libc;
        l("abort",   make_function_type(type_void, 0, NULL, DM_NORETURN));
        l("abs",     make_function_type(type_int, 1, (type_t *[]) { type_int }, DM_CONST));
+       l("fabs",    make_function_type(type_double, 1, (type_t *[]) { type_double }, DM_CONST));
+       l("fabsf",   make_function_type(type_float, 1, (type_t *[]) { type_float }, DM_CONST));
+       l("fabsl",   make_function_type(type_long_double, 1, (type_t *[]) { type_long_double }, DM_CONST));
        l("labs",    make_function_type(type_long, 1, (type_t *[]) { type_long }, DM_CONST));
        l("llabs",   make_function_type(type_long_long, 1, (type_t *[]) { type_long_long }, DM_CONST));
        l("memcpy",  make_function_type(type_void_ptr, 3, (type_t *[]) { type_void_ptr_restrict, type_const_void_ptr_restrict, type_size_t }, DM_NONE));
diff --git a/types.c b/types.c
index ab6e423..8703386 100644 (file)
--- a/types.c
+++ b/types.c
@@ -70,6 +70,8 @@ type_t *type_uptrdiff_t;
 type_t *type_wchar_t;
 type_t *type_const_wchar_t;
 type_t *type_wint_t;
+type_t *type_int32_t;
+type_t *type_int64_t;
 
 type_t *type_intmax_t_ptr;
 type_t *type_ptrdiff_t_ptr;
@@ -125,15 +127,19 @@ void init_basic_types(void)
        type_void               = make_atomic_type(ATOMIC_TYPE_VOID,        TYPE_QUALIFIER_NONE);
        type_const_void         = make_atomic_type(ATOMIC_TYPE_VOID,        TYPE_QUALIFIER_CONST);
 
+       int8_type_kind  = find_signed_int_atomic_type_kind_for_size(1);
+       int16_type_kind = find_signed_int_atomic_type_kind_for_size(2);
+       int32_type_kind = find_signed_int_atomic_type_kind_for_size(4);
+       int64_type_kind = find_signed_int_atomic_type_kind_for_size(8);
+
+       type_int32_t = make_atomic_type(int32_type_kind, TYPE_QUALIFIER_NONE);
+       type_int64_t = make_atomic_type(int64_type_kind, TYPE_QUALIFIER_NONE);
+
        /* microsoft types */
        if (c_mode & _MS) {
-               int8_type_kind           = find_signed_int_atomic_type_kind_for_size(1);
                type_int8                = make_atomic_type(int8_type_kind, TYPE_QUALIFIER_NONE);
-               int16_type_kind          = find_signed_int_atomic_type_kind_for_size(2);
                type_int16               = make_atomic_type(int16_type_kind, TYPE_QUALIFIER_NONE);
-               int32_type_kind          = find_signed_int_atomic_type_kind_for_size(4);
                type_int32               = make_atomic_type(int32_type_kind, TYPE_QUALIFIER_NONE);
-               int64_type_kind          = find_signed_int_atomic_type_kind_for_size(8);
                type_int64               = make_atomic_type(int64_type_kind, TYPE_QUALIFIER_NONE);
                unsigned_int8_type_kind  = find_unsigned_int_atomic_type_kind_for_size(1);
                type_unsigned_int8       = make_atomic_type(unsigned_int8_type_kind, TYPE_QUALIFIER_NONE);
diff --git a/types.h b/types.h
index 282a067..285974e 100644 (file)
--- a/types.h
+++ b/types.h
@@ -70,6 +70,8 @@ extern type_t *type_wchar_t;
 extern type_t *type_const_wchar_t;
 extern type_t *type_wchar_ptr_t;
 extern type_t *type_wint_t;
+extern type_t *type_int32_t;
+extern type_t *type_int64_t;
 
 extern type_t *type_intmax_t_ptr;
 extern type_t *type_ptrdiff_t_ptr;