• R/O
  • HTTP
  • SSH
  • HTTPS

コミット

タグ
未設定

よく使われているワード(クリックで追加)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

コミットメタ情報

リビジョン90ff95c1a8fb1b1a851046785a76cc95c3304313 (tree)
日時2015-12-23 02:55:30
作者Yoshinori Sato <ysato@sa76...>
コミッターYoshinori Sato

ログメッセージ

RXv2 instructions support.

変更サマリ

差分

--- a/gcc/config/rx/constraints.md
+++ b/gcc/config/rx/constraints.md
@@ -106,3 +106,10 @@
106106 )
107107 )
108108 )
109+
110+(define_memory_constraint "q"
111+ "A MEM which only uses REG addressing."
112+ (and (match_code "mem")
113+ (match_code "reg" "0")
114+ )
115+)
--- a/gcc/config/rx/rx-opts.h
+++ b/gcc/config/rx/rx-opts.h
@@ -25,7 +25,8 @@ enum rx_cpu_types
2525 RX600,
2626 RX610,
2727 RX200,
28- RX100
28+ RX100,
29+ RXV2
2930 };
3031
3132 #endif
--- a/gcc/config/rx/rx.c
+++ b/gcc/config/rx/rx.c
@@ -639,6 +639,19 @@ rx_print_operand (FILE * file, rtx op, int letter)
639639 case 0xa: fprintf (file, "isp"); break;
640640 case 0xb: fprintf (file, "fintv"); break;
641641 case 0xc: fprintf (file, "intb"); break;
642+ case 0xd:
643+ if (ALLOW_RXV2_INSNS)
644+ {
645+ fprintf (file, "extb"); break;
646+ }
647+ goto invalid_register;
648+ case 0x40:
649+ case 0x41:
650+ if (ALLOW_RXV2_INSNS)
651+ {
652+ fprintf (file, "a%ld", INTVAL(op) - 0x40); break;
653+ } /* RXv1 fall through */
654+ invalid_register:
642655 default:
643656 warning (0, "unrecognized control register number: %d - using 'psw'",
644657 (int) INTVAL (op));
@@ -731,6 +744,11 @@ rx_print_operand (FILE * file, rtx op, int letter)
731744 fprintf (file, "%s", reg_names [rx_pid_base_regnum ()]);
732745 break;
733746
747+ case 'V':
748+ gcc_assert (CONST_INT_P (op));
749+ fprintf (file, "a%ld", INTVAL(op));
750+ break;
751+
734752 case 'R':
735753 gcc_assert (GET_MODE_SIZE (GET_MODE (op)) <= 4);
736754 unsigned_load = true;
@@ -1776,12 +1794,32 @@ rx_expand_prologue (void)
17761794 /* We have assumed that there are at least two registers pushed... */
17771795 gcc_assert (acc_high != 0);
17781796
1779- /* Note - the bottom 16 bits of the accumulator are inaccessible.
1780- We just assume that they are zero. */
1781- emit_insn (gen_mvfacmi (gen_rtx_REG (SImode, acc_low)));
1782- emit_insn (gen_mvfachi (gen_rtx_REG (SImode, acc_high)));
1783- emit_insn (gen_stack_push (gen_rtx_REG (SImode, acc_low)));
1784- emit_insn (gen_stack_push (gen_rtx_REG (SImode, acc_high)));
1797+ if (!ALLOW_RXV2_INSNS)
1798+ {
1799+ /* Note - the bottom 16 bits of the accumulator are inaccessible.
1800+ We just assume that they are zero. */
1801+ emit_insn ( gen_mvfacmi (
1802+ gen_rtx_REG (SImode, acc_low), GEN_INT(0), GEN_INT(64)));
1803+ emit_insn (gen_mvfachi (
1804+ gen_rtx_REG (SImode, acc_high), GEN_INT(0), GEN_INT(64)));
1805+ emit_insn (gen_stack_push (gen_rtx_REG (SImode, acc_low)));
1806+ emit_insn (gen_stack_push (gen_rtx_REG (SImode, acc_high)));
1807+ }
1808+ else
1809+ {
1810+ emit_insn ( gen_mvfaclo (
1811+ gen_rtx_REG (SImode, acc_low), GEN_INT(0), GEN_INT(64)));
1812+ emit_insn (gen_mvfachi (
1813+ gen_rtx_REG (SImode, acc_high), GEN_INT(0), GEN_INT(64)));
1814+ emit_insn (gen_stack_push (gen_rtx_REG (SImode, acc_low)));
1815+ emit_insn (gen_stack_push (gen_rtx_REG (SImode, acc_high)));
1816+ emit_insn ( gen_mvfaclo (
1817+ gen_rtx_REG (SImode, acc_low), GEN_INT(0), GEN_INT(65)));
1818+ emit_insn (gen_mvfachi (
1819+ gen_rtx_REG (SImode, acc_high), GEN_INT(0), GEN_INT(65)));
1820+ emit_insn (gen_stack_push (gen_rtx_REG (SImode, acc_low)));
1821+ emit_insn (gen_stack_push (gen_rtx_REG (SImode, acc_high)));
1822+ }
17851823 }
17861824 else
17871825 {
@@ -1791,10 +1829,30 @@ rx_expand_prologue (void)
17911829 /* We have assumed that there are at least two registers pushed... */
17921830 gcc_assert (acc_high <= high);
17931831
1794- emit_insn (gen_mvfacmi (gen_rtx_REG (SImode, acc_low)));
1795- emit_insn (gen_mvfachi (gen_rtx_REG (SImode, acc_high)));
1796- emit_insn (gen_stack_pushm (GEN_INT (2 * UNITS_PER_WORD),
1797- gen_rx_store_vector (acc_low, acc_high)));
1832+ if (!ALLOW_RXV2_INSNS)
1833+ {
1834+ emit_insn (gen_mvfacmi (
1835+ gen_rtx_REG (SImode, acc_low), GEN_INT(0), GEN_INT(64)));
1836+ emit_insn (gen_mvfachi (
1837+ gen_rtx_REG (SImode, acc_high), GEN_INT(0), GEN_INT(64)));
1838+ emit_insn (gen_stack_pushm (GEN_INT (2 * UNITS_PER_WORD),
1839+ gen_rx_store_vector (acc_low, acc_high)));
1840+ }
1841+ else
1842+ {
1843+ emit_insn (gen_mvfacmi (
1844+ gen_rtx_REG (SImode, acc_low), GEN_INT(0), GEN_INT(64)));
1845+ emit_insn (gen_mvfachi (
1846+ gen_rtx_REG (SImode, acc_high), GEN_INT(0), GEN_INT(64)));
1847+ emit_insn (gen_stack_pushm (GEN_INT (2 * UNITS_PER_WORD),
1848+ gen_rx_store_vector (acc_low, acc_high)));
1849+ emit_insn (gen_mvfacmi (
1850+ gen_rtx_REG (SImode, acc_low), GEN_INT(0), GEN_INT(65)));
1851+ emit_insn (gen_mvfachi (
1852+ gen_rtx_REG (SImode, acc_high), GEN_INT(0), GEN_INT(65)));
1853+ emit_insn (gen_stack_pushm (GEN_INT (2 * UNITS_PER_WORD),
1854+ gen_rx_store_vector (acc_low, acc_high)));
1855+ }
17981856 }
17991857 }
18001858
@@ -2104,41 +2162,83 @@ rx_expand_epilogue (bool is_sibcall)
21042162 if (MUST_SAVE_ACC_REGISTER)
21052163 {
21062164 unsigned int acc_low, acc_high;
2107-
2108- /* Reverse the saving of the accumulator register onto the stack.
2109- Note we must adjust the saved "low" accumulator value as it
2110- is really the middle 32-bits of the accumulator. */
2111- if (register_mask)
2165+ if (!ALLOW_RXV2_INSNS)
21122166 {
2113- acc_low = acc_high = 0;
2167+ /* Reverse the saving of the accumulator register onto the stack.
2168+ Note we must adjust the saved "low" accumulator value as it
2169+ is really the middle 32-bits of the accumulator. */
2170+ if (register_mask)
2171+ {
2172+ acc_low = acc_high = 0;
21142173
2115- for (reg = 1; reg < CC_REGNUM; reg ++)
2116- if (register_mask & (1 << reg))
2117- {
2118- if (acc_low == 0)
2119- acc_low = reg;
2120- else
2174+ for (reg = 1; reg < CC_REGNUM; reg ++)
2175+ if (register_mask & (1 << reg))
21212176 {
2122- acc_high = reg;
2123- break;
2177+ if (acc_low == 0)
2178+ acc_low = reg;
2179+ else
2180+ {
2181+ acc_high = reg;
2182+ break;
2183+ }
21242184 }
2125- }
2126- emit_insn (gen_stack_pop (gen_rtx_REG (SImode, acc_high)));
2127- emit_insn (gen_stack_pop (gen_rtx_REG (SImode, acc_low)));
2185+ emit_insn (gen_stack_pop (gen_rtx_REG (SImode, acc_high)));
2186+ emit_insn (gen_stack_pop (gen_rtx_REG (SImode, acc_low)));
2187+ }
2188+ else
2189+ {
2190+ acc_low = low;
2191+ acc_high = low + 1;
2192+ emit_insn (gen_stack_popm (GEN_INT (2 * UNITS_PER_WORD),
2193+ gen_rx_popm_vector (acc_low, acc_high)));
2194+ }
2195+
2196+ emit_insn (gen_ashlsi3 (gen_rtx_REG (SImode, acc_low),
2197+ gen_rtx_REG (SImode, acc_low),
2198+ GEN_INT (16)));
2199+ emit_insn (gen_mvtaclo (gen_rtx_REG (SImode, acc_low), GEN_INT(0)));
2200+ emit_insn (gen_mvtachi (gen_rtx_REG (SImode, acc_high), GEN_INT(0)));
21282201 }
21292202 else
21302203 {
2131- acc_low = low;
2132- acc_high = low + 1;
2133- emit_insn (gen_stack_popm (GEN_INT (2 * UNITS_PER_WORD),
2134- gen_rx_popm_vector (acc_low, acc_high)));
2135- }
2204+ if (register_mask)
2205+ {
2206+ acc_low = acc_high = 0;
21362207
2137- emit_insn (gen_ashlsi3 (gen_rtx_REG (SImode, acc_low),
2138- gen_rtx_REG (SImode, acc_low),
2139- GEN_INT (16)));
2140- emit_insn (gen_mvtaclo (gen_rtx_REG (SImode, acc_low)));
2141- emit_insn (gen_mvtachi (gen_rtx_REG (SImode, acc_high)));
2208+ for (reg = 1; reg < CC_REGNUM; reg ++)
2209+ if (register_mask & (1 << reg))
2210+ {
2211+ if (acc_low == 0)
2212+ acc_low = reg;
2213+ else
2214+ {
2215+ acc_high = reg;
2216+ break;
2217+ }
2218+ }
2219+ emit_insn (gen_stack_pop (gen_rtx_REG (SImode, acc_high)));
2220+ emit_insn (gen_stack_pop (gen_rtx_REG (SImode, acc_low)));
2221+ emit_insn (gen_mvtaclo (gen_rtx_REG (SImode, acc_low), GEN_INT(0)));
2222+ emit_insn (gen_mvtachi (gen_rtx_REG (SImode, acc_high), GEN_INT(0)));
2223+ emit_insn (gen_stack_pop (gen_rtx_REG (SImode, acc_high)));
2224+ emit_insn (gen_stack_pop (gen_rtx_REG (SImode, acc_low)));
2225+ emit_insn (gen_mvtaclo (gen_rtx_REG (SImode, acc_low), GEN_INT(1)));
2226+ emit_insn (gen_mvtachi (gen_rtx_REG (SImode, acc_high), GEN_INT(1)));
2227+ }
2228+ else
2229+ {
2230+ acc_low = low;
2231+ acc_high = low + 1;
2232+ emit_insn (gen_stack_popm (GEN_INT (2 * UNITS_PER_WORD),
2233+ gen_rx_popm_vector (acc_low, acc_high)));
2234+ emit_insn (gen_mvtaclo (gen_rtx_REG (SImode, acc_low), GEN_INT(0)));
2235+ emit_insn (gen_mvtachi (gen_rtx_REG (SImode, acc_high), GEN_INT(0)));
2236+ emit_insn (gen_stack_popm (GEN_INT (2 * UNITS_PER_WORD),
2237+ gen_rx_popm_vector (acc_low, acc_high)));
2238+ emit_insn (gen_mvtaclo (gen_rtx_REG (SImode, acc_low), GEN_INT(1)));
2239+ emit_insn (gen_mvtachi (gen_rtx_REG (SImode, acc_high), GEN_INT(1)));
2240+ }
2241+ }
21422242 }
21432243
21442244 if (register_mask)
@@ -2354,6 +2454,28 @@ enum rx_builtin
23542454 RX_BUILTIN_ROUND,
23552455 RX_BUILTIN_SETPSW,
23562456 RX_BUILTIN_WAIT,
2457+ RX_BUILTIN_MACHI2,
2458+ RX_BUILTIN_MACLO2,
2459+ RX_BUILTIN_MULHI2,
2460+ RX_BUILTIN_MULLO2,
2461+ RX_BUILTIN_MVFACHI2,
2462+ RX_BUILTIN_MVFACMI2,
2463+ RX_BUILTIN_MVTACHI2,
2464+ RX_BUILTIN_MVTACLO2,
2465+ RX_BUILTIN_RACW2,
2466+ RX_BUILTIN_EMACA,
2467+ RX_BUILTIN_EMSBA,
2468+ RX_BUILTIN_EMULA,
2469+ RX_BUILTIN_MACLH,
2470+ RX_BUILTIN_MSBHI,
2471+ RX_BUILTIN_MSBLO,
2472+ RX_BUILTIN_MSBLH,
2473+ RX_BUILTIN_MVFACGU,
2474+ RX_BUILTIN_MVFACLO,
2475+ RX_BUILTIN_MVTACGU,
2476+ RX_BUILTIN_RACL,
2477+ RX_BUILTIN_RDACL,
2478+ RX_BUILTIN_RDACW,
23572479 RX_BUILTIN_max
23582480 };
23592481
@@ -2420,6 +2542,26 @@ rx_init_builtins (void)
24202542 ADD_RX_BUILTIN1 (ROUND, "round", intSI, float);
24212543 ADD_RX_BUILTIN1 (REVW, "revw", intSI, intSI);
24222544 ADD_RX_BUILTIN0 (WAIT, "wait", void);
2545+ ADD_RX_BUILTIN3 (MACHI2, "machi2", void, intSI, intSI, integer);
2546+ ADD_RX_BUILTIN3 (MACLO2, "maclo2", void, intSI, intSI, integer);
2547+ ADD_RX_BUILTIN3 (MULHI2, "mulhi2", void, intSI, intSI, integer);
2548+ ADD_RX_BUILTIN3 (MULLO2, "mullo2", void, intSI, intSI, integer);
2549+ ADD_RX_BUILTIN2 (MVFACHI2,"mvfachi2",intSI, integer, integer);
2550+ ADD_RX_BUILTIN2 (MVFACMI2,"mvfacmi2",intSI, integer, integer);
2551+ ADD_RX_BUILTIN2 (MVTACHI2,"mvtachi2",void, intSI, integer);
2552+ ADD_RX_BUILTIN2 (MVTACLO2,"mvtaclo2",void, intSI, integer);
2553+ ADD_RX_BUILTIN3 (EMACA, "emaca", void, intSI, intSI, integer);
2554+ ADD_RX_BUILTIN3 (EMSBA, "emsba", void, intSI, intSI, integer);
2555+ ADD_RX_BUILTIN3 (MACLH, "maclh", void, intSI, intSI, integer);
2556+ ADD_RX_BUILTIN3 (MSBHI, "msbhi", void, intSI, intSI, integer);
2557+ ADD_RX_BUILTIN3 (MSBLO, "msblo", void, intSI, intSI, integer);
2558+ ADD_RX_BUILTIN3 (MSBLH, "msblh", void, intSI, intSI, integer);
2559+ ADD_RX_BUILTIN2 (MVFACGU, "mvfacgu", intSI, intSI, integer);
2560+ ADD_RX_BUILTIN2 (MVFACLO, "mvfaclo", intSI, intSI, integer);
2561+ ADD_RX_BUILTIN2 (MVTACGU, "mvtacgu", void, intSI, integer);
2562+ ADD_RX_BUILTIN2 (RACL, "racl", void, intSI, integer);
2563+ ADD_RX_BUILTIN2 (RDACL, "rdacl", void, intSI, integer);
2564+ ADD_RX_BUILTIN2 (RDACW, "rdacw", void, intSI, integer);
24232565 }
24242566
24252567 /* Return the RX builtin for CODE. */
@@ -2496,7 +2638,7 @@ rx_expand_builtin_mvtipl (rtx arg)
24962638 }
24972639
24982640 static rtx
2499-rx_expand_builtin_mac (tree exp, rtx (* gen_func)(rtx, rtx))
2641+rx_expand_builtin_mac (tree exp, rtx (* gen_func)(rtx, rtx, rtx))
25002642 {
25012643 rtx arg1 = expand_normal (CALL_EXPR_ARG (exp, 0));
25022644 rtx arg2 = expand_normal (CALL_EXPR_ARG (exp, 1));
@@ -2507,36 +2649,172 @@ rx_expand_builtin_mac (tree exp, rtx (* gen_func)(rtx, rtx))
25072649 if (! REG_P (arg2))
25082650 arg2 = force_reg (SImode, arg2);
25092651
2510- emit_insn (gen_func (arg1, arg2));
2652+ emit_insn (gen_func (arg1, arg2, GEN_INT(64)));
25112653
25122654 return NULL_RTX;
25132655 }
25142656
25152657 static rtx
2516-rx_expand_int_builtin_1_arg (rtx arg,
2517- rtx target,
2518- rtx (* gen_func)(rtx, rtx),
2519- bool mem_ok)
2658+rx_expand_builtin_mac2 (tree exp, rtx (* gen_func)(rtx, rtx, rtx))
25202659 {
2521- if (! REG_P (arg))
2522- if (!mem_ok || ! MEM_P (arg))
2523- arg = force_reg (SImode, arg);
2660+ rtx arg1 = expand_normal (CALL_EXPR_ARG (exp, 0));
2661+ rtx arg2 = expand_normal (CALL_EXPR_ARG (exp, 1));
2662+ rtx arg3 = expand_normal (CALL_EXPR_ARG (exp, 2));
2663+ int acc;
2664+
2665+ if (!ALLOW_RXV2_INSNS)
2666+ {
2667+ error("Required RXv2 instructions.");
2668+ return NULL_RTX;
2669+ }
2670+
2671+ if (! REG_P (arg1))
2672+ arg1 = force_reg (SImode, arg1);
2673+
2674+ if (! REG_P (arg2))
2675+ arg2 = force_reg (SImode, arg2);
25242676
2677+ if (! CONST_INT_P (arg3))
2678+ return NULL_RTX;
2679+
2680+ acc = INTVAL(arg3);
2681+ if (acc < 0 || acc > 1)
2682+ {
2683+ error("Invalid register number.");
2684+ return NULL_RTX;
2685+ }
2686+
2687+ emit_insn (gen_func (arg1, arg2, GEN_INT(acc + 64)));
2688+
2689+ return NULL_RTX;
2690+}
2691+
2692+static rtx
2693+rx_expand_builtin_fromacc (rtx target, rtx (* gen_func)(rtx, rtx, rtx))
2694+{
25252695 if (target == NULL_RTX || ! REG_P (target))
25262696 target = gen_reg_rtx (SImode);
25272697
2528- emit_insn (gen_func (target, arg));
2698+ emit_insn (gen_func (target, GEN_INT(0), GEN_INT(64)));
2699+
2700+ return target;
2701+}
2702+
2703+static rtx
2704+rx_expand_builtin_fromacc2 (rtx target, tree exp, rtx (* gen_func)(rtx, rtx, rtx))
2705+{
2706+ rtx arg1 = expand_normal (CALL_EXPR_ARG (exp, 0));
2707+ rtx arg2 = expand_normal (CALL_EXPR_ARG (exp, 1));
2708+ int acc;
2709+
2710+ if (!ALLOW_RXV2_INSNS)
2711+ {
2712+ error("Required RXv2 instructions.");
2713+ return NULL_RTX;
2714+ }
2715+
2716+ if (target == NULL_RTX || ! REG_P (target))
2717+ target = gen_reg_rtx (SImode);
2718+
2719+ if (! CONST_INT_P (arg1) || ! CONST_INT_P (arg2))
2720+ return NULL_RTX;
2721+
2722+ acc = INTVAL(arg2);
2723+ if (acc < 0 || acc > 1)
2724+ {
2725+ error("Invalid accumlator number.");
2726+ return NULL_RTX;
2727+ }
2728+
2729+ if (INTVAL(arg1) < 0 || INTVAL(arg1) > 2)
2730+ {
2731+ error("Invalid shift count.");
2732+ return NULL_RTX;
2733+ }
2734+
2735+ emit_insn (gen_func (target, arg1, GEN_INT(acc+64)));
25292736
25302737 return target;
25312738 }
25322739
25332740 static rtx
2534-rx_expand_int_builtin_0_arg (rtx target, rtx (* gen_func)(rtx))
2741+rx_expand_builtin_toacc (rtx arg, rtx (* gen_func)(rtx, rtx))
25352742 {
2743+ if (! REG_P (arg))
2744+ arg = force_reg (SImode, arg);
2745+
2746+ emit_insn (gen_func (arg, GEN_INT(64)));
2747+
2748+ return NULL_RTX;
2749+}
2750+
2751+static rtx
2752+rx_expand_builtin_toacc2 (tree exp, rtx (* gen_func)(rtx, rtx))
2753+{
2754+ rtx arg1 = expand_normal (CALL_EXPR_ARG (exp, 0));
2755+ rtx arg2 = expand_normal (CALL_EXPR_ARG (exp, 1));
2756+ int acc;
2757+
2758+ if (!ALLOW_RXV2_INSNS)
2759+ {
2760+ error("Required RXv2 instructions.");
2761+ return NULL_RTX;
2762+ }
2763+
2764+ if (! REG_P (arg1))
2765+ arg1 = force_reg (SImode, arg1);
2766+
2767+ acc = INTVAL(arg2);
2768+ if (acc < 0 || acc > 1)
2769+ {
2770+ error("Invalid accumlator number.");
2771+ return NULL_RTX;
2772+ }
2773+
2774+ emit_insn (gen_func (arg1, GEN_INT(acc + 64)));
2775+
2776+ return NULL_RTX;
2777+}
2778+
2779+static rtx
2780+rx_expand_builtin_rac (tree exp, rtx (* gen_func)(rtx, rtx))
2781+{
2782+ rtx arg1 = expand_normal (CALL_EXPR_ARG (exp, 0));
2783+ rtx arg2 = expand_normal (CALL_EXPR_ARG (exp, 1));
2784+ int acc;
2785+
2786+ if (!ALLOW_RXV2_INSNS)
2787+ {
2788+ error("Required RXv2 instructions.");
2789+ return NULL_RTX;
2790+ }
2791+
2792+ acc = INTVAL(arg2);
2793+ if (acc < 0 || acc > 1)
2794+ {
2795+ error("Invalid accumlator number.");
2796+ return NULL_RTX;
2797+ }
2798+
2799+ emit_insn (gen_func (arg1, GEN_INT(acc + 64)));
2800+
2801+ return NULL_RTX;
2802+}
2803+
2804+static rtx
2805+rx_expand_int_builtin_1_arg (rtx arg,
2806+ rtx target,
2807+ rtx (* gen_func)(rtx, rtx),
2808+ bool mem_ok)
2809+{
2810+ if (! REG_P (arg))
2811+ if (!mem_ok || ! MEM_P (arg))
2812+ arg = force_reg (SImode, arg);
2813+
25362814 if (target == NULL_RTX || ! REG_P (target))
25372815 target = gen_reg_rtx (SImode);
25382816
2539- emit_insn (gen_func (target));
2817+ emit_insn (gen_func (target, arg));
25402818
25412819 return target;
25422820 }
@@ -2610,14 +2888,14 @@ rx_expand_builtin (tree exp,
26102888 case RX_BUILTIN_MACLO: return rx_expand_builtin_mac (exp, gen_maclo);
26112889 case RX_BUILTIN_MULHI: return rx_expand_builtin_mac (exp, gen_mulhi);
26122890 case RX_BUILTIN_MULLO: return rx_expand_builtin_mac (exp, gen_mullo);
2613- case RX_BUILTIN_MVFACHI: return rx_expand_int_builtin_0_arg
2891+ case RX_BUILTIN_MVFACHI: return rx_expand_builtin_fromacc
26142892 (target, gen_mvfachi);
2615- case RX_BUILTIN_MVFACMI: return rx_expand_int_builtin_0_arg
2893+ case RX_BUILTIN_MVFACMI: return rx_expand_builtin_fromacc
26162894 (target, gen_mvfacmi);
2617- case RX_BUILTIN_MVTACHI: return rx_expand_void_builtin_1_arg
2618- (op, gen_mvtachi, true);
2619- case RX_BUILTIN_MVTACLO: return rx_expand_void_builtin_1_arg
2620- (op, gen_mvtaclo, true);
2895+ case RX_BUILTIN_MVTACHI: return rx_expand_builtin_toacc
2896+ (op, gen_mvtachi);
2897+ case RX_BUILTIN_MVTACLO: return rx_expand_builtin_toacc
2898+ (op, gen_mvtaclo);
26212899 case RX_BUILTIN_RMPA:
26222900 if (rx_allow_string_insns)
26232901 emit_insn (gen_rmpa ());
@@ -2627,13 +2905,44 @@ rx_expand_builtin (tree exp,
26272905 case RX_BUILTIN_MVFC: return rx_expand_builtin_mvfc (arg, target);
26282906 case RX_BUILTIN_MVTC: return rx_expand_builtin_mvtc (exp);
26292907 case RX_BUILTIN_MVTIPL: return rx_expand_builtin_mvtipl (op);
2630- case RX_BUILTIN_RACW: return rx_expand_void_builtin_1_arg
2631- (op, gen_racw, false);
2908+ case RX_BUILTIN_RACW:
2909+ emit_insn (gen_racw (op, GEN_INT(64))); return NULL_RTX;
26322910 case RX_BUILTIN_ROUND: return rx_expand_builtin_round (op, target);
26332911 case RX_BUILTIN_REVW: return rx_expand_int_builtin_1_arg
26342912 (op, target, gen_revw, false);
26352913 case RX_BUILTIN_WAIT: emit_insn (gen_wait ()); return NULL_RTX;
2636-
2914+ case RX_BUILTIN_MACHI2: return rx_expand_builtin_mac2 (exp, gen_machi);
2915+ case RX_BUILTIN_MACLO2: return rx_expand_builtin_mac2 (exp, gen_maclo);
2916+ case RX_BUILTIN_MULHI2: return rx_expand_builtin_mac2 (exp, gen_mulhi);
2917+ case RX_BUILTIN_MULLO2: return rx_expand_builtin_mac2 (exp, gen_mullo);
2918+ case RX_BUILTIN_MVFACHI2: return rx_expand_builtin_fromacc2
2919+ (target, exp, gen_mvfachi);
2920+ case RX_BUILTIN_MVFACMI2: return rx_expand_builtin_fromacc2
2921+ (target, exp, gen_mvfacmi);
2922+ case RX_BUILTIN_MVTACHI2: return rx_expand_builtin_toacc2
2923+ (exp, gen_mvtachi);
2924+ case RX_BUILTIN_MVTACLO2: return rx_expand_builtin_toacc2
2925+ (exp, gen_mvtaclo);
2926+ case RX_BUILTIN_RACW2: return rx_expand_builtin_rac (exp, gen_racw);
2927+ case RX_BUILTIN_EMACA: return rx_expand_builtin_fromacc2
2928+ (target, exp, gen_emaca);
2929+ case RX_BUILTIN_EMSBA: return rx_expand_builtin_fromacc2
2930+ (target, exp, gen_emsba);
2931+ case RX_BUILTIN_MACLH: return rx_expand_builtin_fromacc2
2932+ (target, exp, gen_maclh);
2933+ case RX_BUILTIN_MSBHI: return rx_expand_builtin_fromacc2
2934+ (target, exp, gen_msbhi);
2935+ case RX_BUILTIN_MSBLO: return rx_expand_builtin_fromacc2
2936+ (target, exp, gen_msblo);
2937+ case RX_BUILTIN_MSBLH: return rx_expand_builtin_fromacc2
2938+ (target, exp, gen_msblh);
2939+ case RX_BUILTIN_MVFACGU: return rx_expand_builtin_fromacc2
2940+ (target, exp, gen_mvfacgu);
2941+ case RX_BUILTIN_MVFACLO: return rx_expand_builtin_fromacc2
2942+ (target, exp, gen_mvfaclo);
2943+ case RX_BUILTIN_RACL: return rx_expand_builtin_rac (exp, gen_racl);
2944+ case RX_BUILTIN_RDACL: return rx_expand_builtin_rac (exp, gen_rdacl);
2945+ case RX_BUILTIN_RDACW: return rx_expand_builtin_rac (exp, gen_rdacw);
26372946 default:
26382947 internal_error ("bad builtin code");
26392948 break;
--- a/gcc/config/rx/rx.h
+++ b/gcc/config/rx/rx.h
@@ -44,6 +44,11 @@
4444 builtin_define ("__RX600__"); \
4545 builtin_assert ("machine=RX600"); \
4646 } \
47+ else if (rx_cpu_type == RXV2) \
48+ { \
49+ builtin_define ("__RXv2__"); \
50+ builtin_assert ("machine=RXv2"); \
51+ } \
4752 \
4853 if (TARGET_BIG_ENDIAN_DATA) \
4954 builtin_define ("__RX_BIG_ENDIAN__"); \
@@ -652,6 +657,8 @@ typedef unsigned int CUMULATIVE_ARGS;
652657 /* This macro is used to decide when RX FPU instructions can be used. */
653658 #define ALLOW_RX_FPU_INSNS (TARGET_USE_FPU)
654659
660+#define ALLOW_RXV2_INSNS (rx_cpu_type == RXV2)
661+
655662 #define BRANCH_COST(SPEED,PREDICT) 1
656663 #define REGISTER_MOVE_COST(MODE,FROM,TO) 2
657664
--- a/gcc/config/rx/rx.md
+++ b/gcc/config/rx/rx.md
@@ -35,6 +35,7 @@
3535 (define_constants
3636 [
3737 (SP_REG 0)
38+ (R1_REG 1)
3839 (CC_REG 16)
3940
4041 (UNSPEC_LOW_REG 0)
@@ -73,8 +74,22 @@
7374 (UNSPEC_BUILTIN_SAT 49)
7475 (UNSPEC_BUILTIN_SETPSW 50)
7576 (UNSPEC_BUILTIN_WAIT 51)
76-
77- (UNSPEC_PID_ADDR 52)
77+ (UNSPEC_BUILTIN_MOVCO 52)
78+ (UNSPEC_BUILTIN_MOVLI 53)
79+ (UNSPEC_BUILTIN_EMACA 54)
80+ (UNSPEC_BUILTIN_EMSBA 55)
81+ (UNSPEC_BUILTIN_MACLH 56)
82+ (UNSPEC_BUILTIN_MSBHI 57)
83+ (UNSPEC_BUILTIN_MSBLO 58)
84+ (UNSPEC_BUILTIN_MSBLH 59)
85+ (UNSPEC_BUILTIN_MVFACGU 60)
86+ (UNSPEC_BUILTIN_MVFACLO 61)
87+ (UNSPEC_BUILTIN_MVTACGU 62)
88+ (UNSPEC_BUILTIN_RACL 63)
89+ (UNSPEC_BUILTIN_RDACL 64)
90+ (UNSPEC_BUILTIN_RDACW 65)
91+
92+ (UNSPEC_PID_ADDR 66)
7893 ]
7994 )
8095
@@ -1877,7 +1892,40 @@
18771892
18781893 ;; Floating Point Instructions
18791894
1880-(define_insn "addsf3"
1895+(define_expand "addsf3"
1896+ [(set (match_operand:SF 0 "register_operand" "=r")
1897+ (plus:SF (match_operand:SF 1 "register_operand" "r")
1898+ (match_operand:SF 2 "rx_source_operand" "FQr")))
1899+ (clobber (reg:CC CC_REG))]
1900+"ALLOW_RX_FPU_INSNS "
1901+{ if(!ALLOW_RXV2_INSNS) {
1902+ emit_insn(gen_addsf3_rx(operands[0],
1903+ operands[1],
1904+ operands[2]));
1905+ } else {
1906+ emit_insn(gen_addsf3_rxv2(operands[0],
1907+ operands[1],
1908+ operands[2]));
1909+ }
1910+ DONE;
1911+})
1912+
1913+(define_insn "addsf3_rxv2"
1914+ [(set (match_operand:SF 0 "register_operand" "=r,r,r,r")
1915+ (plus:SF (match_operand:SF 1 "register_operand" "%r,0,0,0")
1916+ (match_operand:SF 2 "register_operand" "r,r,F,Q")))
1917+ (clobber (reg:CC CC_REG))]
1918+ "ALLOW_RXV2_INSNS"
1919+ "@
1920+ fadd\t%2, %1, %0
1921+ fadd\t%2, %0
1922+ fadd\t%2, %0
1923+ fadd\t%2, %0"
1924+ [(set_attr "timings" "44,44,44,66")
1925+ (set_attr "length" "3,3,7,5")]
1926+)
1927+
1928+(define_insn "addsf3_rx"
18811929 [(set (match_operand:SF 0 "register_operand" "=r,r,r")
18821930 (plus:SF (match_operand:SF 1 "register_operand" "%0,0,0")
18831931 (match_operand:SF 2 "rx_source_operand" "r,F,Q")))
@@ -1899,7 +1947,40 @@
18991947 (set_attr "length" "3,7,5")]
19001948 )
19011949
1902-(define_insn "mulsf3"
1950+(define_expand "mulsf3"
1951+ [(set (match_operand:SF 0 "register_operand" "=r,r,r")
1952+ (mult:SF (match_operand:SF 1 "register_operand" "%0,0,0")
1953+ (match_operand:SF 2 "rx_source_operand" "r,F,Q")))
1954+ (clobber (reg:CC CC_REG))]
1955+"ALLOW_RX_FPU_INSNS || ALLOW_RXV2_INSNS"
1956+{ if(!ALLOW_RXV2_INSNS) {
1957+ emit_insn(gen_mulsf3_rx(operands[0],
1958+ operands[1],
1959+ operands[2]));
1960+ } else {
1961+ emit_insn(gen_mulsf3_rxv2(operands[0],
1962+ operands[1],
1963+ operands[2]));
1964+ }
1965+ DONE;
1966+})
1967+
1968+(define_insn "mulsf3_rxv2"
1969+ [(set (match_operand:SF 0 "register_operand" "=r,r,r,r")
1970+ (mult:SF (match_operand:SF 1 "register_operand" "%r,0,0,0")
1971+ (match_operand:SF 2 "rx_source_operand" "r,r,F,Q")))
1972+ (clobber (reg:CC CC_REG))]
1973+ "ALLOW_RXV2_INSNS"
1974+ "@
1975+ fmul\t%2, %1, %0
1976+ fmul\t%2, %0
1977+ fmul\t%2, %0
1978+ fmul\t%2, %0"
1979+ [(set_attr "timings" "33,33,33,55")
1980+ (set_attr "length" "3,3,7,5")]
1981+)
1982+
1983+(define_insn "mulsf3_rx"
19031984 [(set (match_operand:SF 0 "register_operand" "=r,r,r")
19041985 (mult:SF (match_operand:SF 1 "register_operand" "%0,0,0")
19051986 (match_operand:SF 2 "rx_source_operand" "r,F,Q")))
@@ -1910,7 +1991,40 @@
19101991 (set_attr "length" "3,7,5")]
19111992 )
19121993
1913-(define_insn "subsf3"
1994+(define_expand "subsf3"
1995+ [(set (match_operand:SF 0 "register_operand" "=r")
1996+ (minus:SF (match_operand:SF 1 "register_operand" "r")
1997+ (match_operand:SF 2 "rx_source_operand" "FQr")))
1998+ (clobber (reg:CC CC_REG))]
1999+"ALLOW_RX_FPU_INSNS || ALLOW_RXV2_INSNS"
2000+{ if(!ALLOW_RXV2_INSNS) {
2001+ emit_insn(gen_subsf3_rx(operands[0],
2002+ operands[1],
2003+ operands[2]));
2004+ } else {
2005+ emit_insn(gen_subsf3_rxv2(operands[0],
2006+ operands[1],
2007+ operands[2]));
2008+ }
2009+ DONE;
2010+})
2011+
2012+(define_insn "subsf3_rxv2"
2013+ [(set (match_operand:SF 0 "register_operand" "=r,r,r,r")
2014+ (minus:SF (match_operand:SF 1 "register_operand" "r,0,0,0")
2015+ (match_operand:SF 2 "rx_source_operand" "r,r,F,Q")))
2016+ (clobber (reg:CC CC_REG))]
2017+ "ALLOW_RXV2_INSNS"
2018+ "@
2019+ fsub\t%1, %2, %0
2020+ fsub\t%Q2, %0
2021+ fsub\t%Q2, %0
2022+ fsub\t%Q2, %0"
2023+ [(set_attr "timings" "44,44,44,66")
2024+ (set_attr "length" "3,3,7,5")]
2025+)
2026+
2027+(define_insn "subsf3_rx"
19142028 [(set (match_operand:SF 0 "register_operand" "=r,r,r")
19152029 (minus:SF (match_operand:SF 1 "register_operand" "0,0,0")
19162030 (match_operand:SF 2 "rx_source_operand" "r,F,Q")))
@@ -1940,6 +2054,36 @@
19402054 [(set_attr "timings" "22,44")
19412055 (set_attr "length" "3,6")]
19422056 )
2057+
2058+(define_insn "fixuns_truncsfsi2"
2059+ [(set (match_operand:SI 0 "register_operand" "=r,r")
2060+ (fix:SI (match_operand:SF 1 "rx_compare_operand" "r,Q")))
2061+ (clobber (reg:CC CC_REG))]
2062+ "ALLOW_RX_FPU_INSNS && ALLOW_RXV2_INSNS"
2063+ "ftou\t%Q1, %0"
2064+ [(set_attr "timings" "22,44")
2065+ (set_attr "length" "3,5")]
2066+)
2067+
2068+(define_insn "floatunssisf2"
2069+ [(set (match_operand:SF 0 "register_operand" "=r,r")
2070+ (float:SF (match_operand:SI 1 "rx_compare_operand" "r,Q")))
2071+ (clobber (reg:CC CC_REG))]
2072+ "ALLOW_RX_FPU_INSNS && ALLOW_RXV2_INSNS"
2073+ "utof\t%Q1, %0"
2074+ [(set_attr "timings" "22,44")
2075+ (set_attr "length" "3,6")]
2076+)
2077+
2078+(define_insn "sqrtsf2"
2079+ [(set (match_operand:SF 0 "register_operand" "=r,r")
2080+ (sqrt:SF (match_operand:SF 1 "rx_source_operand" "r,Q")))
2081+ (clobber (reg:CC CC_REG))]
2082+ "ALLOW_RX_FPU_INSNS && ALLOW_RXV2_INSNS"
2083+ "fsqrt\t%Q1, %0"
2084+ [(set_attr "timings" "22,44")
2085+ (set_attr "length" "3,5")]
2086+)
19432087
19442088 ;; Bit manipulation instructions.
19452089
@@ -2379,87 +2523,185 @@
23792523 ;; Multiply & Accumulate (high)
23802524 (define_insn "machi"
23812525 [(unspec:SI [(match_operand:SI 0 "register_operand" "r")
2382- (match_operand:SI 1 "register_operand" "r")]
2526+ (match_operand:SI 1 "register_operand" "r")
2527+ (match_operand:SI 2 "immediate_operand" "i")]
23832528 UNSPEC_BUILTIN_MACHI)]
2384- ""
2385- "machi\t%0, %1"
2386- [(set_attr "length" "3")]
2529+""
2530+{
2531+ if(ALLOW_RXV2_INSNS)
2532+ return "machi\t%0,%1,%C2";
2533+ else
2534+ return "machi\t%0, %1";
2535+ }
2536+ [(set_attr "length" "3")]
23872537 )
23882538
23892539 ;; Multiply & Accumulate (low)
23902540 (define_insn "maclo"
23912541 [(unspec:SI [(match_operand:SI 0 "register_operand" "r")
2392- (match_operand:SI 1 "register_operand" "r")]
2542+ (match_operand:SI 1 "register_operand" "r")
2543+ (match_operand:SI 2 "immediate_operand" "i")]
23932544 UNSPEC_BUILTIN_MACLO)]
23942545 ""
2395- "maclo\t%0, %1"
2546+{if(ALLOW_RXV2_INSNS)
2547+ return "machi\t%0,%1,%a2";
2548+else
2549+ return "machi\t%0, %1";
2550+}
23962551 [(set_attr "length" "3")]
23972552 )
23982553
23992554 ;; Multiply (high)
24002555 (define_insn "mulhi"
24012556 [(unspec:SI [(match_operand:SI 0 "register_operand" "r")
2402- (match_operand:SI 1 "register_operand" "r")]
2557+ (match_operand:SI 1 "register_operand" "r")
2558+ (match_operand:SI 2 "immediate_operand" "i")]
24032559 UNSPEC_BUILTIN_MULHI)]
24042560 ""
2405- "mulhi\t%0, %1"
2561+{if(ALLOW_RXV2_INSNS)
2562+ return "mulhi\t%0,%1,%C2";
2563+else
2564+ return "mulhi\t%0, %1";
2565+}
24062566 [(set_attr "length" "3")]
24072567 )
24082568
24092569 ;; Multiply (low)
24102570 (define_insn "mullo"
2411- [(unspec:SI [(match_operand:SI 0 "register_operand" "r")
2412- (match_operand:SI 1 "register_operand" "r")]
2413- UNSPEC_BUILTIN_MULLO)]
2414- ""
2415- "mullo\t%0, %1"
2571+ [(set (match_operand:SI 0 "register_operand" "=r")
2572+ (unspec:SI [(match_operand:SI 1 "immediate_operand" "i")
2573+ (match_operand:SI 2 "immediate_operand" "i")]
2574+ UNSPEC_BUILTIN_MULLO))]
2575+ ""
2576+{if(ALLOW_RXV2_INSNS)
2577+ return "mullo\t%0,%1,%a2";
2578+else
2579+ return "mullo\t%0, %1";
2580+}
24162581 [(set_attr "length" "3")]
24172582 )
24182583
24192584 ;; Move from Accumulator (high)
24202585 (define_insn "mvfachi"
24212586 [(set (match_operand:SI 0 "register_operand" "=r")
2422- (unspec:SI [(const_int 0)]
2587+ (unspec:SI [(match_operand:SI 1 "immediate_operand" "i")
2588+ (match_operand:SI 2 "immediate_operand" "i")]
24232589 UNSPEC_BUILTIN_MVFACHI))]
24242590 ""
2425- "mvfachi\t%0"
2591+{if(ALLOW_RXV2_INSNS)
2592+ return "mvfachi\t%1,%C2,%0";
2593+else
2594+ return "movfachi\t%0";
2595+}
24262596 [(set_attr "length" "3")]
24272597 )
24282598
2429-;; Move from Accumulator (middle)
2599+;; Move from Accumulator (midlle)
24302600 (define_insn "mvfacmi"
24312601 [(set (match_operand:SI 0 "register_operand" "=r")
2432- (unspec:SI [(const_int 0)]
2602+ (unspec:SI [(match_operand:SI 1 "immediate_operand" "i")
2603+ (match_operand:SI 2 "immediate_operand" "i")]
24332604 UNSPEC_BUILTIN_MVFACMI))]
24342605 ""
2435- "mvfacmi\t%0"
2606+{if(ALLOW_RXV2_INSNS)
2607+ return "mvfacmi\t%1,%C2,%0";
2608+else
2609+ return "movfacmi\t%0";
2610+}
24362611 [(set_attr "length" "3")]
24372612 )
24382613
24392614 ;; Move to Accumulator (high)
24402615 (define_insn "mvtachi"
2441- [(unspec_volatile:SI [(match_operand:SI 0 "register_operand" "r")]
2616+ [(unspec_volatile:SI [(match_operand:SI 0 "register_operand" "r")
2617+ (match_operand:SI 1 "immediate_operand" "i")]
24422618 UNSPEC_BUILTIN_MVTACHI)]
24432619 ""
2444- "mvtachi\t%0"
2620+{if(ALLOW_RXV2_INSNS)
2621+ return "mvtachi\t%0,%C1";
2622+else
2623+ return "mvtachi\t%0";
2624+}
24452625 [(set_attr "length" "3")]
24462626 )
24472627
24482628 ;; Move to Accumulator (low)
24492629 (define_insn "mvtaclo"
2450- [(unspec_volatile:SI [(match_operand:SI 0 "register_operand" "r")]
2630+ [(unspec_volatile:SI [(match_operand:SI 0 "register_operand" "r")
2631+ (match_operand:SI 1 "immediate_operand" "i")]
24512632 UNSPEC_BUILTIN_MVTACLO)]
24522633 ""
2453- "mvtaclo\t%0"
2634+{if(ALLOW_RXV2_INSNS)
2635+ return "mvtaclo\t%0,%C1";
2636+else
2637+ return "mvtaclo\t%0";
2638+}
2639+ [(set_attr "length" "3")]
2640+)
2641+
2642+;; Move from Accumulator (gurd)
2643+(define_insn "mvfacgu"
2644+ [(set (match_operand:SI 0 "register_operand" "=r")
2645+ (unspec:SI [(match_operand:SI 1 "immediate_operand" "i")
2646+ (match_operand:SI 2 "immediate_operand" "i")]
2647+ UNSPEC_BUILTIN_MVFACGU))]
2648+ "ALLOW_RXV2_INSNS"
2649+ "mvfacgu\t%1,%C2,%0"
2650+ [(set_attr "length" "3")]
2651+)
2652+
2653+;; Move from Accumulator (low)
2654+(define_insn "mvfaclo"
2655+ [(set (match_operand:SI 0 "register_operand" "=r")
2656+ (unspec:SI [(match_operand:SI 1 "immediate_operand" "i")
2657+ (match_operand:SI 2 "immediate_operand" "i")]
2658+ UNSPEC_BUILTIN_MVFACLO))]
2659+ "ALLOW_RXV2_INSNS"
2660+ "mvfaclo\t%1,%C2,%0"
24542661 [(set_attr "length" "3")]
24552662 )
24562663
24572664 ;; Round Accumulator
24582665 (define_insn "racw"
2459- [(unspec_volatile:SI [(match_operand:SI 0 "immediate_operand" "i")]
2666+ [(unspec_volatile:SI [(match_operand:SI 0 "immediate_operand" "i")
2667+ (match_operand:SI 1 "immediate_operand" "i")]
24602668 UNSPEC_BUILTIN_RACW)]
24612669 ""
2462- "racw\t%0"
2670+{if(ALLOW_RXV2_INSNS)
2671+ return "racw\t%0,%C1";
2672+else
2673+ return "racw\t%0";
2674+}
2675+ [(set_attr "length" "3")]
2676+)
2677+
2678+;; Round Accumulator
2679+(define_insn "racl"
2680+ [(unspec_volatile:SI [(match_operand:SI 0 "immediate_operand" "i")
2681+ (match_operand:SI 1 "immediate_operand" "i")]
2682+ UNSPEC_BUILTIN_RACL)]
2683+ "ALLOW_RXV2_INSNS"
2684+ "racl\t%0,%C1"
2685+ [(set_attr "length" "3")]
2686+)
2687+
2688+;; Round Accumulator
2689+(define_insn "rdacl"
2690+ [(unspec_volatile:SI [(match_operand:SI 0 "immediate_operand" "i")
2691+ (match_operand:SI 1 "immediate_operand" "i")]
2692+ UNSPEC_BUILTIN_RDACL)]
2693+ "ALLOW_RXV2_INSNS"
2694+ "rdacl\t%0,%C1"
2695+ [(set_attr "length" "3")]
2696+)
2697+
2698+;; Round Accumulator
2699+(define_insn "rdacw"
2700+ [(unspec_volatile:SI [(match_operand:SI 0 "immediate_operand" "i")
2701+ (match_operand:SI 1 "immediate_operand" "i")]
2702+ UNSPEC_BUILTIN_RDACW)]
2703+ "ALLOW_RXV2_INSNS"
2704+ "rdacw\t%0,%C1"
24632705 [(set_attr "length" "3")]
24642706 )
24652707
@@ -2477,6 +2719,67 @@
24772719 (set_attr "timings" "1010")]
24782720 )
24792721
2722+;; Multiply & Accumulate (low)
2723+(define_insn "emaca"
2724+ [(unspec:SI [(match_operand:SI 0 "register_operand" "r")
2725+ (match_operand:SI 1 "register_operand" "r")
2726+ (match_operand:SI 2 "immediate_operand" "i")]
2727+ UNSPEC_BUILTIN_EMACA)]
2728+ "ALLOW_RXV2_INSNS"
2729+ "emacs\t%0,%1,%a2";
2730+ [(set_attr "length" "3")]
2731+)
2732+
2733+(define_insn "emsba"
2734+ [(unspec:SI [(match_operand:SI 0 "register_operand" "r")
2735+ (match_operand:SI 1 "register_operand" "r")
2736+ (match_operand:SI 2 "immediate_operand" "i")]
2737+ UNSPEC_BUILTIN_EMSBA)]
2738+ "ALLOW_RXV2_INSNS"
2739+ "emsbs\t%0,%1,%a2";
2740+ [(set_attr "length" "3")]
2741+)
2742+
2743+(define_insn "maclh"
2744+ [(unspec:SI [(match_operand:SI 0 "register_operand" "r")
2745+ (match_operand:SI 1 "register_operand" "r")
2746+ (match_operand:SI 2 "immediate_operand" "i")]
2747+ UNSPEC_BUILTIN_MACLH)]
2748+ "ALLOW_RXV2_INSNS"
2749+ "maclh\t%0,%1,%a2";
2750+ [(set_attr "length" "3")]
2751+)
2752+
2753+(define_insn "msbhi"
2754+ [(unspec:SI [(match_operand:SI 0 "register_operand" "r")
2755+ (match_operand:SI 1 "register_operand" "r")
2756+ (match_operand:SI 2 "immediate_operand" "i")]
2757+ UNSPEC_BUILTIN_MSBHI)]
2758+ "ALLOW_RXV2_INSNS"
2759+ "msbhi\t%0,%1,%a2";
2760+ [(set_attr "length" "3")]
2761+)
2762+
2763+(define_insn "msblo"
2764+ [(unspec:SI [(match_operand:SI 0 "register_operand" "r")
2765+ (match_operand:SI 1 "register_operand" "r")
2766+ (match_operand:SI 2 "immediate_operand" "i")]
2767+ UNSPEC_BUILTIN_MSBLO)]
2768+ "ALLOW_RXV2_INSNS"
2769+ "msblo\t%0,%1,%a2";
2770+ [(set_attr "length" "3")]
2771+)
2772+
2773+(define_insn "msblh"
2774+ [(unspec:SI [(match_operand:SI 0 "register_operand" "r")
2775+ (match_operand:SI 1 "register_operand" "r")
2776+ (match_operand:SI 2 "immediate_operand" "i")]
2777+ UNSPEC_BUILTIN_MSBLH)]
2778+ "ALLOW_RXV2_INSNS"
2779+ "msblh\t%0,%1,%a2";
2780+ [(set_attr "length" "3")]
2781+)
2782+
24802783 ;;---------- Arithmetic ------------------------
24812784
24822785 ;; Byte swap (two 16-bit values).
@@ -2639,3 +2942,5 @@
26392942 [(set_attr "length" "16")
26402943 (set_attr "timings" "22")]
26412944 )
2945+
2946+(include "sync.md")
--- a/gcc/config/rx/rx.opt
+++ b/gcc/config/rx/rx.opt
@@ -64,6 +64,9 @@ Enum(rx_cpu_types) String(rx600) Value(RX600)
6464 EnumValue
6565 Enum(rx_cpu_types) String(rx100) Value(RX100)
6666
67+EnumValue
68+Enum(rx_cpu_types) String(rxv2) Value(RXV2)
69+
6770 ;---------------------------------------------------
6871
6972 mbig-endian-data
--- /dev/null
+++ b/gcc/config/rx/sync.md
@@ -0,0 +1,191 @@
1+;; GCC machine description for RXv2 synchronization instructions.
2+;; Copyright (C) 2011-2015 Free Software Foundation, Inc.
3+;;
4+;; This file is part of GCC.
5+;;
6+;; GCC is free software; you can redistribute it and/or modify
7+;; it under the terms of the GNU General Public License as published by
8+;; the Free Software Foundation; either version 3, or (at your option)
9+;; any later version.
10+;;
11+;; GCC is distributed in the hope that it will be useful,
12+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
13+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+;; GNU General Public License for more details.
15+;;
16+;; You should have received a copy of the GNU General Public License
17+;; along with GCC; see the file COPYING3. If not see
18+;; <http://www.gnu.org/licenses/>.
19+;;
20+;;
21+
22+(define_c_enum "unspec" [
23+ UNSPEC_ATOMIC
24+])
25+
26+(define_c_enum "unspecv" [
27+ UNSPECV_CMPXCHG_1
28+ UNSPECV_CMPXCHG_2
29+ UNSPECV_CMPXCHG_3
30+])
31+
32+(define_code_iterator FETCHOP [plus minus ior xor and])
33+(define_code_attr fetchop_name
34+ [(plus "add") (minus "sub") (ior "or") (xor "xor") (and "and")])
35+
36+(define_code_attr fetchop_constraint_1_llcs
37+ [(plus "ri") (minus "r") (ior "ri") (xor "ri") (and "ri")])
38+
39+;;------------------------------------------------------------------------------
40+;; comapre and swap
41+
42+(define_expand "atomic_compare_and_swapsi"
43+ [(match_operand:SI 0 "register_operand") ;; bool success output
44+ (match_operand:SI 1 "register_operand") ;; oldval output
45+ (match_operand:SI 2 "memory_operand") ;; memory
46+ (match_operand:SI 3 "general_operand") ;; expected input
47+ (match_operand:SI 4 "general_operand") ;; newval input
48+ (match_operand:SI 5 "const_int_operand") ;; is_weak
49+ (match_operand:SI 6 "const_int_operand") ;; success model
50+ (match_operand:SI 7 "const_int_operand")] ;; failure model
51+ ""
52+{
53+ rtx mem = operands[2];
54+ rtx old_val = gen_lowpart (SImode, operands[1]);
55+ rtx exp_val = operands[3];
56+ rtx new_val = operands[4];
57+
58+ if (ALLOW_RXV2_INSNS) {
59+ emit_insn (gen_atomic_compare_and_swapsi_1 (old_val, mem,
60+ exp_val, new_val));
61+
62+ DONE;
63+ } else {
64+ FAIL;
65+ }
66+})
67+
68+(define_insn "atomic_compare_and_swapsi_1"
69+ [(set (match_operand:SI 0 "register_operand" "=&r")
70+ (unspec_volatile:SI
71+ [(match_operand:SI 1 "memory_operand" "=q")
72+ (match_operand:SI 2 "general_operand" "ri")
73+ (match_operand:SI 3 "general_operand" "ri")]
74+ UNSPECV_CMPXCHG_1))
75+ (set (match_dup 1)
76+ (unspec_volatile:SI [(const_int 0)] UNSPECV_CMPXCHG_2))
77+ (set (reg:SI CC_REG)
78+ (unspec_volatile:SI [(const_int 0)] UNSPECV_CMPXCHG_3))
79+ (clobber (reg:SI CC_REG))
80+ (clobber (reg:SI R1_REG))]
81+ "ALLOW_RXV2_INSNS"
82+ "\r0: movli %1,r1
83+ cmp %2,r1
84+ bne 0f
85+ mov r1,%0
86+ mov %3,r1
87+ movco r1,%1
88+ tst r1,r1
89+ bne 0b
90+0:"
91+ [(set_attr "length" "19")])
92+
93+;;------------------------------------------------------------------------------
94+;; read - write - return old value
95+(define_insn "atomic_exchangesi"
96+ [(set (match_operand:SI 0 "register_operand" "=&r") ;; oldval output
97+ (match_operand:SI 1 "memory_operand" "=m")) ;; memory
98+ (match_operand:SI 3 "const_int_operand") ;; memory model
99+ (set (match_dup 1)
100+ (match_operand:SI 2 "register_operand" "0"))] ;; input
101+ ""
102+ "xchg %1,%0"
103+ [(set_attr "length" "4")])
104+
105+;;------------------------------------------------------------------------------
106+;; read - add|sub|or|and|xor|nand - write - return old value
107+
108+(define_insn "atomic_fetch_<fetchop_name>si"
109+ [(set (match_operand:SI 0 "register_operand" "=&mr")
110+ (match_operand:SI 1 "memory_operand" "=mr"))
111+ (set (match_dup 1)
112+ (unspec:SI
113+ [(FETCHOP:SI (match_dup 1)
114+ (match_operand:SI 2 "general_operand" "g"))]
115+ UNSPEC_ATOMIC))
116+ (match_operand:SI 3 "const_int_operand")
117+ (clobber (reg:SI CC_REG))
118+ (clobber (reg:SI R1_REG))]
119+ "ALLOW_RXV2_INSNS"
120+ "\r0: movli %1,r1
121+ mov r1,%0
122+ <fetchop_name> %2,r1
123+ movco r1,%1
124+ tst r1,r1
125+ beq 0b";
126+ [(set_attr "length" "15")])
127+
128+(define_insn "atomic_fetch_nandsi"
129+ [(set (match_operand:SI 0 "register_operand" "=&r")
130+ (match_operand:SI 1 "memory_operand" "=q"))
131+ (set (match_dup 1)
132+ (unspec:SI
133+ [(not:SI (and:SI (match_dup 1)
134+ (match_operand:SI 2 "general_operand" "ri")))]
135+ UNSPEC_ATOMIC))
136+ (match_operand:SI 3 "const_int_operand")
137+ (clobber (reg:SI CC_REG))
138+ (clobber (reg:SI R1_REG))]
139+ "ALLOW_RXV2_INSNS"
140+ "\r0: movli %1,r1
141+ mov r1,%0
142+ and %2,r1
143+ not r1
144+ movco r1,%1
145+ tst r1,r1
146+ beq 0b"
147+ [(set_attr "length" "16")])
148+
149+;;------------------------------------------------------------------------------
150+;; read - add|sub|or|and|xor|nand - write - return new value
151+
152+(define_insn "atomic_<fetchop_name>_fetchsi"
153+ [(set (match_operand:SI 0 "register_operand" "=&r")
154+ (FETCHOP:SI
155+ (match_operand:SI 1 "memory_operand" "=m")
156+ (match_operand:SI 2 "general_operand" "ri")))
157+ (set (match_dup 1)
158+ (unspec:SI
159+ [(FETCHOP:SI (match_dup 1) (match_dup 2))]
160+ UNSPEC_ATOMIC))
161+ (match_operand:SI 3 "const_int_operand" "")
162+ (clobber (reg:SI CC_REG))]
163+ "ALLOW_RXV2_INSNS"
164+ "\r0: movli %1,%0
165+ <fetchop_name> %2,%0
166+ movco %0,%1
167+ tst %0,%0
168+ beq 0b
169+ mov.L %1,%0"
170+ [(set_attr "length" "15")])
171+
172+(define_insn "atomic_nand_fetchsi"
173+ [(set (match_operand:SI 0 "register_operand" "=&r")
174+ (not:SI (and:SI
175+ (match_operand:SI 1 "memory_operand" "=q")
176+ (match_operand:SI 2 "general_operand" "ri"))))
177+ (set (match_dup 1)
178+ (unspec:SI
179+ [(not:SI (and:SI (match_dup 1) (match_dup 2)))]
180+ UNSPEC_ATOMIC))
181+ (match_operand:SI 3 "const_int_operand")
182+ (clobber (reg:SI CC_REG))]
183+ "ALLOW_RXV2_INSNS"
184+ "\r0: movli %1,%0
185+ and %2,%0
186+ not %0
187+ movco %0,%1
188+ tst %0,%0
189+ bf 0b
190+ mov.L %1,%0"
191+ [(set_attr "length" "16")])
--- a/gcc/config/rx/t-rx
+++ b/gcc/config/rx/t-rx
@@ -30,6 +30,8 @@ MULTILIB_DIRNAMES = 64-bit-double no-fpu-libs big-endian-data pid
3030
3131 MULTILIB_OPTIONS += mno-allow-string-insns
3232 MULTILIB_DIRNAMES += no-strings
33+MULTILIB_OPTIONS += mcpu=rxv2
34+MULTILIB_DIRNAMES += v2
3335
3436 MULTILIB_MATCHES = nofpu=mnofpu nofpu=mcpu?rx200 nofpu=mcpu?rx100
3537
--- a/gcc/doc/md.texi
+++ b/gcc/doc/md.texi
@@ -3445,6 +3445,8 @@ A constant in the range @minus{}8388608 to 8388607, inclusive.
34453445 @item Uint04
34463446 A constant in the range 0 to 15, inclusive.
34473447
3448+@item q
3449+A register indirect adressing.
34483450 @end table
34493451
34503452 @item S/390 and zSeries---@file{config/s390/s390.h}