aboutsummaryrefslogtreecommitdiffstats
path: root/devel/msp430-gcc/files/patch-gcc-config-msp430-msp430-builtins.c
blob: fc7018cf4d55e714e0973eb0b2f79e8caa191f9c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
--- gcc/config/msp430/msp430-builtins.c 2012-09-26 12:24:42.000000000 +0800
+++ gcc/config/msp430/msp430-builtins.c 2012-09-26 12:28:31.000000000 +0800
@@ -59,6 +59,7 @@
   MSP430_BUILTIN_GET_WATCHDOG_CLEAR_VALUE,
   MSP430_BUILTIN_SET_WATCHDOG_CLEAR_VALUE,
   MSP430_BUILTIN_WATCHDOG_CLEAR,
+  MSP430_BUILTIN_EVEN_IN_RANGE,
   MSP430_BUILTIN_last_enum
 };
 
@@ -153,6 +154,13 @@
   add_builtin_function ("__watchdog_clear",
            build_function_type_list (void_type_node, NULL_TREE),
            MSP430_BUILTIN_WATCHDOG_CLEAR, BUILT_IN_MD, NULL, NULL_TREE);
+  add_builtin_function ("__even_in_range",
+           build_function_type_list (unsigned_type_node,
+                         unsigned_type_node,
+                         unsigned_type_node,
+                         NULL_TREE),
+           MSP430_BUILTIN_EVEN_IN_RANGE, BUILT_IN_MD,
+           NULL, NULL_TREE);
 }
 
 rtx
@@ -432,6 +440,30 @@
       emit_move_insn (retval, arg);
       insn = gen_bswaphi1 (retval);
       break;
+    case MSP430_BUILTIN_EVEN_IN_RANGE:
+      {
+   tree key_tree = CALL_EXPR_ARG (exp, 0);
+   tree limit_tree = CALL_EXPR_ARG (exp, 1);
+   rtx key;
+   HOST_WIDE_INT limit_val;
+   
+   need_insn = false;
+   if (!cst_and_fits_in_hwi (limit_tree)
+       || (0 > ((limit_val = int_cst_value (limit_tree)))))
+     {
+       error
+         ("__even_in_range second argument must be non-negative integer constant");
+       break;
+     }
+   key = expand_expr (key_tree, NULL_RTX, VOIDmode, EXPAND_NORMAL);
+   retval = gen_reg_rtx (HImode);
+   /* This is a stub.  To complete this, we need to attach notes
+    * that assert that the value is, in fact, even and between 0
+    * and the second argument.  No idea how to do that in a way
+    * that gcc's tablejump will pay any attention to. */
+   emit_move_insn (retval, key);
+   break;
+      }
     }
 
   if (insn)