# --- T2-COPYRIGHT-BEGIN --- # t2/package/*/gcc/i860.patch.i860 # Copyright (C) 2026 The T2 SDE Project # SPDX-License-Identifier: GPL-2.0 or patched project license # --- T2-COPYRIGHT-END --- From: René Rebe Subject: [PATCH] i860: restore the backend, port to current GCC, add Linux target Restores the backend removed from GCC: no cc0, LRA, RTL prologue and epilogue, i860-*-sysv4* and i860-*-linux*. PIC and shared libraries, TLS, IEEE division through libgcc, filled delay slots. Against upstream commit ada5b8f08739b26bf76558c9d5157cbbdd16c205 (tree-optimization/128322 - amend PR127377 fix). Branch i860 at 4e4cc2b0c52. Tested in the MAME magicst2 model only, not on real hardware. Signed-off-by: René Rebe Co-Authored-By: Claude Opus 5.5 --- gcc/config.gcc | 14 + gcc/config/i860/constraints.md | 68 + gcc/config/i860/i860-passes.def | 20 + gcc/config/i860/i860-pipe.cc | 1294 ++++++++++ gcc/config/i860/i860-protos.h | 78 + gcc/config/i860/i860.cc | 2167 +++++++++++++++++ gcc/config/i860/i860.h | 288 +++ gcc/config/i860/i860.md | 1271 ++++++++++ gcc/config/i860/i860.opt | 44 + gcc/config/i860/i860.opt.urls | 19 + gcc/config/i860/linux.h | 67 + gcc/config/i860/predicates.md | 94 + gcc/config/i860/sysv4.h | 65 + gcc/config/i860/t-i860 | 23 + gcc/doc/install.texi | 19 + gcc/doc/invoke.texi | 48 + .../gcc.c-torture/execute/20101011-1.c | 3 + libgcc/config.host | 8 + libgcc/config/i860/fdiv-special.c | 54 + libgcc/config/i860/libgcc-i860.ver | 24 + libgcc/config/i860/t-i860 | 27 + 21 files changed, 5695 insertions(+) diff --git a/gcc/config.gcc b/gcc/config.gcc index 01750947c4d..a80d0749af1 100644 --- a/gcc/config.gcc +++ b/gcc/config.gcc @@ -289,6 +289,7 @@ esac case ${target}${target_min} in # Avoid special cases that are not obsolete arm*-*-*eabi* \ + | i860-*-sysv4* \ ) ;; arm*-wince-pe* \ @@ -436,6 +437,10 @@ ft32*) cpu_type=ft32 moxie*) cpu_type=moxie target_has_targetm_common=no ;; +i860*) cpu_type=i860 + target_has_targetm_common=no + extra_objs="i860-pipe.o" + ;; fido-*-*) cpu_type=m68k extra_headers=math-68881.h @@ -2352,6 +2357,15 @@ x86_64-*-fuchsia*) tmake_file="${tmake_file} i386/t-x86_64-elf" tm_file="${tm_file} i386/unix.h i386/att.h elfos.h newlib-stdint.h i386/i386elf.h i386/x86-64.h fuchsia.h" ;; +i860-*-linux*) + tm_file="elfos.h ${tm_file} gnu-user.h linux.h glibc-stdint.h i860/linux.h" + tmake_file="${tmake_file} i860/t-i860" + ;; +i860-*-sysv4*) + tm_file="elfos.h newlib-stdint.h ${tm_file} i860/sysv4.h" + tmake_file="${tmake_file} i860/t-i860" + use_gcc_stdint=wrap + ;; ia64*-*-elf*) tm_file="${tm_file} elfos.h newlib-stdint.h ia64/sysv4.h ia64/elf.h" tmake_file="ia64/t-ia64" diff --git a/gcc/config/i860/constraints.md b/gcc/config/i860/constraints.md new file mode 100644 index 00000000000..57bbe51b94c --- /dev/null +++ b/gcc/config/i860/constraints.md @@ -0,0 +1,68 @@ +;; Constraint definitions for the Intel i860. +;; Copyright (C) 2026 Free Software Foundation, Inc. +;; Copyright (C) 2026 René Rebe +;; +;; This file is part of GCC. +;; +;; GCC is free software; you can redistribute it and/or modify it +;; under the terms of the GNU General Public License as published +;; by the Free Software Foundation; either version 3, or (at your +;; option) any later version. +;; +;; GCC is distributed in the hope that it will be useful, but WITHOUT +;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +;; or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public +;; License for more details. +;; +;; You should have received a copy of the GNU General Public License +;; along with GCC; see the file COPYING3. If not see +;; . + +(define_register_constraint "f" "FP_REGS" + "Floating point registers.") + +;; Not -0x8000: add/subtract immediates are sometimes negated. +(define_constraint "I" + "A signed 16-bit immediate for add/subtract." + (and (match_code "const_int") + (match_test "IN_RANGE (ival, -0x7fff, 0x7fff)"))) + +(define_constraint "J" + "Integer zero." + (and (match_code "const_int") + (match_test "ival == 0"))) + +(define_constraint "K" + "An unsigned 5-bit immediate (bte/btne)." + (and (match_code "const_int") + (match_test "IN_RANGE (ival, 0, 31)"))) + +(define_constraint "L" + "An unsigned 16-bit immediate for logical instructions." + (and (match_code "const_int") + (match_test "IN_RANGE (ival, 0, 0xffff)"))) + +(define_constraint "M" + "A constant with the low 16 bits clear (orh/andh/xorh)." + (and (match_code "const_int") + (match_test "(ival & 0xffff) == 0"))) + +(define_constraint "G" + "Floating point zero." + (and (match_code "const_double") + (match_test "op == CONST0_RTX (GET_MODE (op))"))) + +(define_memory_constraint "Q" + "A memory reference with a register, register + register or + register + offset address (no constant address)." + (and (match_code "mem") + (match_test "i860_q_address_p (XEXP (op, 0), mode)"))) + +(define_memory_constraint "Y" + "A call target: memory at an integer register or symbol address." + (and (match_code "mem") + (match_test "i860_call_address_p (XEXP (op, 0), true)"))) + +(define_constraint "Z" + "A symbol as a direct call target, also valid in PIC code." + (match_code "symbol_ref")) diff --git a/gcc/config/i860/i860-passes.def b/gcc/config/i860/i860-passes.def new file mode 100644 index 00000000000..6afc8284a09 --- /dev/null +++ b/gcc/config/i860/i860-passes.def @@ -0,0 +1,20 @@ +/* Target specific passes of the i860. + Copyright (C) 2026 René Rebe + +This file is part of GCC. + +GCC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 3, or (at your option) +any later version. + +GCC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GCC; see the file COPYING3. If not see +. */ + +INSERT_PASS_BEFORE (pass_reorder_blocks, 1, pass_i860_pipeline); diff --git a/gcc/config/i860/i860-pipe.cc b/gcc/config/i860/i860-pipe.cc new file mode 100644 index 00000000000..ec362839945 --- /dev/null +++ b/gcc/config/i860/i860-pipe.cc @@ -0,0 +1,1294 @@ +/* Pipelined floating point loops for the i860. + Copyright (C) 2026 René Rebe + +This file is part of GCC. + +GCC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 3, or (at your option) +any later version. + +GCC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GCC; see the file COPYING3. If not see +. */ + +/* A pipelined instruction writes to its destination the result of the instruction that + entered its unit some pushes ago. So a whole iteration cannot run at once: each insn of a + counted loop gets a stage, and the data of iteration I is handled by it in the run I + stage + of the loop. With N iterations and D the largest stage there are D prologue runs, N - D of + the loop itself and D more to drain the pipes. Runs in which an operation has no data + push f0 instead, which keeps a unit advancing. + + The accesses of an iteration are spread over runs, which is valid if no two of them can + overlap in a way that changes their order: known for one base register, asked of the alias + oracle or else tested at run time for two. The original loop stays for what fails these + tests and for N <= D. A recurrence stays scalar as its result is needed by the next run. */ + +#define IN_TARGET_CODE 1 + +#include "config.h" +#include "system.h" +#include "coretypes.h" +#include "backend.h" +#include "target.h" +#include "rtl.h" +#include "tree.h" +#include "df.h" +#include "memmodel.h" +#include "tm_p.h" +#include "insn-config.h" +#include "regs.h" +#include "emit-rtl.h" +#include "recog.h" +#include "insn-attr.h" +#include "cfghooks.h" +#include "cfgrtl.h" +#include "cfganal.h" +#include "cfgbuild.h" +#include "alias.h" +#include "explow.h" +#include "optabs.h" +#include "expr.h" +#include "predict.h" +#include "tree-pass.h" +#include "rtl-iter.h" +#include "output.h" + +namespace { + +const int FP0 = 32; +const int MAX_STAGE = 16; +const int MAX_EMITTED = 64; + +enum pipe_kind { PIPE_LOAD, PIPE_STORE, PIPE_OP, PIPE_INCR }; + +struct pipe_insn +{ + rtx_insn *insn; + enum pipe_kind kind; + machine_mode mode; + rtx mem; + int stream; + HOST_WIDE_INT disp; + enum rtx_code code; + int unit; /* 0 multiplier, 1 adder, 2 pipelined loads */ + bool scalar; + int dest; + int src[2]; /* the registers read */ + int val[2]; /* the insns defining them here, or -1 */ + int nsrc; + int pop_to, pop_runs; /* where and how many runs later the result arrives */ + int stage; + int newreg; + bool field_used; +}; + +struct pipe_stream +{ + int reg; + HOST_WIDE_INT stride; + bool autoinc; + int incr_pos; + bool store; + HOST_WIDE_INT maxdisp; +}; + +class pipe_loop +{ +public: + pipe_loop (basic_block, bool); + bool analyze (); + void transform (pipe_loop *); + + int depth; + +private: + bool scan_body (); + bool scan_mem (rtx, int); + bool find_values (); + bool map_units (); + bool solve_stages (); + int ready (int, int); + bool check_memory (); + bool check_displacements (); + bool allocate (); + HOST_WIDE_INT access_disp (int, bool, int); + void emit_run (bool, int); + void emit_flush (); + bool piped (const pipe_insn &p) const + { return (p.kind == PIPE_OP && !p.scalar) || (p.kind == PIPE_LOAD && use_pfld); } + void emit_path (basic_block, int, rtx, basic_block); + rtx real_pattern (int, bool, int); + void item_regs (int, auto_vec &, auto_vec &); + bool items_conflict (int, int); + bool plan_pairs (); + rtx dual_kernel (); + rtx_insn *branch_to_scalar (enum rtx_code, rtx, rtx); + bool after_incr (int i) + { const pipe_stream &s = streams[body[i].stream]; return s.incr_pos >= 0 && i > s.incr_pos; } + int value_reg (int); + HOST_WIDE_INT test_margin (const pipe_stream &a, const pipe_stream &b) + { return (depth + 2) * abs_hwi (a.stride) + 2 * MAX (a.maxdisp, b.maxdisp) + 32; } + + basic_block loop, pre, exit_bb; + rtx_insn *jump, *prime; + rtx count, step; + auto_vec body; + auto_vec streams; + auto_vec > tests; + bool use_pfld; + int minstage[3]; + int lastpop[3]; /* the last drain run in which a unit delivers something */ + struct pair { int fp, core; bool bla; }; + auto_vec pairs; + rtx scalar_label; + int tmp_reg; +}; + +pipe_loop::pipe_loop (basic_block bb, bool pfld) + : depth (0), loop (bb), pre (NULL), exit_bb (NULL), jump (NULL), prime (NULL), count (NULL), + step (NULL), use_pfld (pfld), scalar_label (NULL), tmp_reg (-1) +{ + for (int u = 0; u < 3; u++) + { + minstage[u] = 0; + lastpop[u] = -1; + } +} + +/* A memory reference of insn I: one stream per base register. */ + +bool +pipe_loop::scan_mem (rtx mem, int i) +{ + rtx addr = XEXP (mem, 0); + pipe_insn &p = body[i]; + HOST_WIDE_INT size = GET_MODE_SIZE (GET_MODE (mem)); + HOST_WIDE_INT disp = 0; + bool autoinc = false; + rtx base; + + if (MEM_VOLATILE_P (mem) || MEM_ALIGN (mem) < size * BITS_PER_UNIT) + return false; + if (REG_P (addr)) + base = addr; + else if (GET_CODE (addr) == PLUS && REG_P (XEXP (addr, 0)) && CONST_INT_P (XEXP (addr, 1))) + { + base = XEXP (addr, 0); + disp = INTVAL (XEXP (addr, 1)); + } + else if (GET_CODE (addr) == PRE_INC || GET_CODE (addr) == PRE_DEC) + { + base = XEXP (addr, 0); + autoinc = true; + } + else + return false; + if (disp % size != 0 || rtx_equal_p (base, count) || rtx_equal_p (base, step)) + return false; + + p.mem = mem; + p.disp = disp; + unsigned s; + for (s = 0; s < streams.length (); s++) + if (streams[s].reg == (int) REGNO (base)) + break; + if (s == streams.length ()) + { + pipe_stream n = { (int) REGNO (base), 0, false, -1, false, 0 }; + streams.safe_push (n); + } + else if (autoinc || streams[s].autoinc) + return false; + if (autoinc) + { + streams[s].autoinc = true; + streams[s].stride = GET_CODE (addr) == PRE_INC ? size : -size; + } + streams[s].store |= p.kind == PIPE_STORE; + streams[s].maxdisp = MAX (streams[s].maxdisp, abs_hwi (disp)); + p.stream = s; + return true; +} + +/* Only FP loads, stores and arithmetic, and increments of the base registers. */ + +bool +pipe_loop::scan_body () +{ + rtx_insn *insn; + + FOR_BB_INSNS (loop, insn) + { + if (!NONDEBUG_INSN_P (insn) || insn == jump) + continue; + rtx set = single_set (insn); + if (!set || GET_CODE (PATTERN (insn)) != SET || volatile_insn_p (PATTERN (insn))) + return false; + rtx dst = SET_DEST (set), src = SET_SRC (set); + pipe_insn p = {}; + p.insn = insn; + p.stream = p.dest = p.pop_to = -1; + p.val[0] = p.val[1] = -1; + p.newreg = -1; + p.mode = GET_MODE (dst); + int i = body.length (); + + if (MEM_P (src) || MEM_P (dst)) + if (p.mode != SFmode && p.mode != DFmode) + return false; + if (FP_REG_P (dst) && MEM_P (src)) + { + p.kind = PIPE_LOAD; + p.unit = 2; + p.dest = REGNO (dst); + body.safe_push (p); + if (!scan_mem (src, i)) + return false; + } + else if (MEM_P (dst) && FP_REG_P (src)) + { + p.kind = PIPE_STORE; + p.src[0] = REGNO (src); + p.nsrc = 1; + body.safe_push (p); + if (!scan_mem (dst, i)) + return false; + } + else if (FP_REG_P (dst) + && (GET_CODE (src) == PLUS || GET_CODE (src) == MINUS || GET_CODE (src) == MULT) + && FP_REG_P (XEXP (src, 0)) && FP_REG_P (XEXP (src, 1)) + && GET_MODE (src) == p.mode + && GET_MODE (XEXP (src, 0)) == p.mode && GET_MODE (XEXP (src, 1)) == p.mode) + { + p.kind = PIPE_OP; + p.code = GET_CODE (src); + p.unit = p.code == MULT ? 0 : 1; + p.dest = REGNO (dst); + p.src[0] = REGNO (XEXP (src, 0)); + p.src[1] = REGNO (XEXP (src, 1)); + p.nsrc = 2; + body.safe_push (p); + } + else if (REG_P (dst) && GP_REGNO_P (REGNO (dst)) && GET_CODE (src) == PLUS + && rtx_equal_p (XEXP (src, 0), dst) && CONST_INT_P (XEXP (src, 1)) + && !rtx_equal_p (dst, count) && !rtx_equal_p (dst, step)) + { + p.kind = PIPE_INCR; + p.dest = REGNO (dst); + p.disp = INTVAL (XEXP (src, 1)); + body.safe_push (p); + } + else + return false; + } + + for (unsigned i = 0; i < body.length (); i++) + if (body[i].kind == PIPE_INCR) + { + bool found = false; + for (unsigned s = 0; s < streams.length (); s++) + if (streams[s].reg == body[i].dest) + { + if (streams[s].autoinc || streams[s].incr_pos >= 0) + return false; + streams[s].stride = body[i].disp; + streams[s].incr_pos = i; + found = true; + } + /* a counter nothing here uses: not worth a special case */ + if (!found) + return false; + } + return true; +} + +/* Who defines what each insn reads. */ + +bool +pipe_loop::find_values () +{ + auto_vec def, defs; + def.safe_grow_cleared (FIRST_PSEUDO_REGISTER); + defs.safe_grow_cleared (FIRST_PSEUDO_REGISTER); + for (int r = 0; r < FIRST_PSEUDO_REGISTER; r++) + def[r] = -1; + + for (unsigned i = 0; i < body.length (); i++) + if (body[i].kind == PIPE_LOAD || body[i].kind == PIPE_OP) + { + int words = GET_MODE_SIZE (body[i].mode) / UNITS_PER_WORD; + for (int w = 0; w < words; w++) + defs[body[i].dest + w]++; + } + + bool accum[2] = { false, false }; + bitmap live_out = df_get_live_in (exit_bb); + + for (unsigned i = 0; i < body.length (); i++) + { + pipe_insn &p = body[i]; + if (p.kind == PIPE_INCR) + continue; + int words = GET_MODE_SIZE (p.mode) / UNITS_PER_WORD; + for (int n = 0; n < p.nsrc; n++) + { + int r = p.src[n]; + int d = def[r]; + if (words == 2 && def[r + 1] != d) + return false; + if (d >= 0 && body[d].mode != p.mode) + return false; + if (d >= 0) + p.val[n] = d; + else if (defs[r] || (words == 2 && defs[r + 1])) + { + /* only the update of an accumulator reads an older value */ + if (p.kind != PIPE_OP || p.dest != r || defs[r] != 1 + || (words == 2 && defs[r + 1] != 1)) + return false; + p.scalar = true; + accum[p.unit] = true; + } + } + if (p.kind == PIPE_STORE) + continue; + for (int w = 0; w < words; w++) + def[p.dest + w] = i; + /* the temporaries get other registers */ + if (!p.scalar + && (REGNO_REG_SET_P (live_out, p.dest) + || REGNO_REG_SET_P (live_out, p.dest + words - 1))) + return false; + } + + /* a scalar and a pipelined instruction do not share a unit */ + for (unsigned i = 0; i < body.length (); i++) + if (body[i].kind == PIPE_OP && accum[body[i].unit]) + body[i].scalar = true; + return true; +} + +/* With K pipelined insns on a unit of L stages, each pops the result of L pushes ago. */ + +bool +pipe_loop::map_units () +{ + bool any = false; + + for (int unit = 0; unit < 3; unit++) + { + auto_vec ops; + machine_mode mode = VOIDmode; + + for (unsigned i = 0; i < body.length (); i++) + if (body[i].kind != PIPE_STORE && body[i].kind != PIPE_INCR + && body[i].unit == unit && piped (body[i])) + { + if (mode != VOIDmode && mode != body[i].mode) + return false; + mode = body[i].mode; + ops.safe_push (i); + } + if (ops.is_empty ()) + continue; + any |= unit < 2; + int stages = unit == 0 && mode == DFmode ? 2 : 3; + int k = ops.length (); + for (int j = 0; j < k; j++) + { + body[ops[j]].pop_to = ops[(j + stages) % k]; + body[ops[j]].pop_runs = (j + stages) / k; + } + } + return any; +} + +/* The stage in which insn C can read the value of insn V. */ + +int +pipe_loop::ready (int v, int c) +{ + const pipe_insn &p = body[v]; + + if (piped (p)) + return p.stage + p.pop_runs + (c < p.pop_to ? 1 : 0); + return p.stage; +} + +bool +pipe_loop::solve_stages () +{ + int n = body.length (); + bool changed = true; + + for (int round = 0; changed; round++) + { + changed = false; + if (round > 8 * MAX_STAGE) + return false; + for (int c = 0; c < n; c++) + for (int s = 0; s < body[c].nsrc; s++) + { + int v = body[c].val[s]; + if (v < 0) + continue; + int r = ready (v, c); + if (r > body[c].stage) + { + body[c].stage = r; + changed = true; + } + } + for (int c = n - 1; c >= 0; c--) + for (int s = 0; s < body[c].nsrc; s++) + { + int v = body[c].val[s]; + if (v < 0) + continue; + int r = ready (v, c); + if (r < body[c].stage) + { + body[v].stage += body[c].stage - r; + changed = true; + } + } + for (int i = 0; i < n; i++) + if (body[i].stage > MAX_STAGE) + return false; + } + + /* a pipelined insn must not read the destination it writes */ + depth = 0; + for (int u = 0; u < 3; u++) + { + lastpop[u] = -1; + minstage[u] = MAX_STAGE; + } + for (int c = 0; c < n; c++) + { + pipe_insn &p = body[c]; + for (int s = 0; s < p.nsrc; s++) + if (p.val[s] >= 0) + { + if (ready (p.val[s], c) != p.stage) + return false; + const pipe_insn &d = body[p.val[s]]; + if (piped (d)) + { + if (d.pop_to == c) + return false; + body[d.pop_to].field_used = true; + lastpop[d.unit] = MAX (lastpop[d.unit], d.stage - 1 + d.pop_runs); + } + } + if (p.kind != PIPE_INCR) + depth = MAX (depth, p.stage); + if (piped (p)) + minstage[p.unit] = MIN (minstage[p.unit], p.stage); + } + return depth > 0 && depth * n <= MAX_EMITTED; +} + +/* Whether accesses in iterations DELTA apart reorder. Different base registers go to + the alias oracle, what may alias is tested at run time. */ + +bool +pipe_loop::check_memory () +{ + int n = body.length (); + bool any_store = false; + + for (unsigned s = 0; s < streams.length (); s++) + any_store |= streams[s].store; + for (unsigned s = 0; s < streams.length (); s++) + if (any_store && streams[s].stride == 0) + return false; + + for (int a = 0; a < n; a++) + for (int b = a + 1; b < n; b++) + { + const pipe_insn &pa = body[a], &pb = body[b]; + + if (pa.stream < 0 || pb.stream < 0 + || (pa.kind != PIPE_STORE && pb.kind != PIPE_STORE)) + continue; + const pipe_stream &sa = streams[pa.stream], &sb = streams[pb.stream]; + if (pa.stream == pb.stream) + { + HOST_WIDE_INT oa = pa.disp + (after_incr (a) ? sa.stride : 0); + HOST_WIDE_INT ob = pb.disp + (after_incr (b) ? sa.stride : 0); + HOST_WIDE_INT la = GET_MODE_SIZE (pa.mode), lb = GET_MODE_SIZE (pb.mode); + + for (int d = -depth - 2; d <= depth + 2; d++) + { + HOST_WIDE_INT addr = ob + d * sa.stride; + + if (addr >= oa + la || oa >= addr + lb) + continue; + /* A is before B in the same iteration */ + bool before = d >= 0; + bool after = pa.stage < d + pb.stage || (pa.stage == d + pb.stage); + if (before != after) + return false; + } + continue; + } + if (!may_alias_p (pa.mem, pb.mem)) + continue; + if (abs_hwi (sa.stride) != abs_hwi (sb.stride) || sa.stride == 0 + || test_margin (sa, sb) > 0x3fff) + return false; + std::pair t (MIN (pa.stream, pb.stream), MAX (pa.stream, pb.stream)); + bool dup = false; + for (unsigned i = 0; i < tests.length (); i++) + dup |= tests[i] == t; + if (!dup) + tests.safe_push (t); + } + return tests.length () <= 6; +} + +/* The displacement of the load or store I. In the prologue and the loop the base register + advances every run; in the drain it stands at the value after the last iteration. */ + +HOST_WIDE_INT +pipe_loop::access_disp (int i, bool drain, int run) +{ + const pipe_insn &p = body[i]; + const pipe_stream &s = streams[p.stream]; + + if (!drain) + return p.disp - p.stage * s.stride; + return p.disp + (run - p.stage) * s.stride + (after_incr (i) ? s.stride : 0); +} + +bool +pipe_loop::check_displacements () +{ + for (unsigned i = 0; i < body.length (); i++) + if (body[i].stream >= 0 && !streams[body[i].stream].autoinc) + { + HOST_WIDE_INT size = GET_MODE_SIZE (body[i].mode); + + for (int run = -1; run < body[i].stage; run++) + { + HOST_WIDE_INT d = access_disp (i, run >= 0, run); + if (d % size != 0 || !IN_RANGE (d, -0x8000, 0x7fff - size)) + return false; + } + } + return true; +} + +/* One register for each value: the temporaries of the scalar loop are free here. */ + +bool +pipe_loop::allocate () +{ + HARD_REG_SET taken; + bitmap in = df_get_live_in (loop), out = df_get_live_in (exit_bb); + + CLEAR_HARD_REG_SET (taken); + for (int r = FP0; r < FP0 + 32; r++) + if (REGNO_REG_SET_P (in, r) || REGNO_REG_SET_P (out, r) || fixed_regs[r] + || !call_used_or_fixed_reg_p (r)) + SET_HARD_REG_BIT (taken, r); + + for (unsigned i = 0; i < body.length (); i++) + for (int s = 0; s < body[i].nsrc; s++) + if (body[i].val[s] < 0) + { + int words = GET_MODE_SIZE (body[i].mode) / UNITS_PER_WORD; + for (int w = 0; w < words; w++) + SET_HARD_REG_BIT (taken, body[i].src[s] + w); + } + for (unsigned i = 0; i < body.length (); i++) + if (body[i].kind == PIPE_OP && body[i].scalar) + { + int words = GET_MODE_SIZE (body[i].mode) / UNITS_PER_WORD; + for (int s = 0; s < 2; s++) + if (body[i].val[s] < 0 && body[i].src[s] == body[i].dest) + { + body[i].newreg = body[i].dest; + for (int w = 0; w < words; w++) + SET_HARD_REG_BIT (taken, body[i].dest + w); + } + } + + for (unsigned i = 0; i < body.length (); i++) + { + pipe_insn &p = body[i]; + + if (p.kind != PIPE_LOAD && p.kind != PIPE_OP) + continue; + if (p.newreg >= 0) + continue; + if (piped (p) && !p.field_used) + { + p.newreg = FP0; + continue; + } + int words = GET_MODE_SIZE (p.mode) / UNITS_PER_WORD, r; + for (r = FP0 + 32 - words; r > FP0; r -= words) + if (!TEST_HARD_REG_BIT (taken, r) && (words == 1 || !TEST_HARD_REG_BIT (taken, r + 1))) + break; + if (r <= FP0) + return false; + p.newreg = r; + for (int w = 0; w < words; w++) + SET_HARD_REG_BIT (taken, r + w); + } + + if (!tests.is_empty ()) + { + for (int r = 16; r < 30 && tmp_reg < 0; r++) + if (!REGNO_REG_SET_P (in, r) && !fixed_regs[r] && call_used_or_fixed_reg_p (r) + && r != (int) REGNO (count) && r != (int) REGNO (step)) + tmp_reg = r; + if (tmp_reg < 0) + return false; + } + return true; +} + +bool +pipe_loop::analyze () +{ + jump = BB_END (loop); + if (!JUMP_P (jump) || recog_memoized (jump) != CODE_FOR_i860_bla_loop + || !optimize_bb_for_speed_p (loop) || EDGE_COUNT (loop->succs) != 2 + || EDGE_COUNT (loop->preds) != 2) + return false; + + edge e; + edge_iterator ei; + FOR_EACH_EDGE (e, ei, loop->succs) + if (e->dest != loop) + exit_bb = e->dest; + FOR_EACH_EDGE (e, ei, loop->preds) + if (e->src != loop) + pre = e->src; + if (!exit_bb || !pre || !find_edge (loop, loop) || exit_bb == EXIT_BLOCK_PTR_FOR_FN (cfun) + || pre == ENTRY_BLOCK_PTR_FOR_FN (cfun) || !single_succ_p (pre)) + return false; + + rtx pat = PATTERN (jump); + count = SET_DEST (XVECEXP (pat, 0, 1)); + step = XEXP (XVECEXP (pat, 0, 2), 0); + if (!REG_P (count) || !REG_P (step)) + return false; + + prime = BB_END (pre); + while (prime != BB_HEAD (pre) && !NONDEBUG_INSN_P (prime)) + prime = PREV_INSN (prime); + if (!NONDEBUG_INSN_P (prime) || recog_memoized (prime) != CODE_FOR_i860_bla_prime + || !rtx_equal_p (SET_DEST (PATTERN (prime)), count) + || prime == BB_HEAD (pre)) + return false; + + if (!(scan_body () && find_values () && map_units () && solve_stages () + && check_memory () && check_displacements () && allocate ())) + return false; + if (TARGET_DUAL_FP && !plan_pairs ()) + pairs.truncate (0); + return true; +} + +int +pipe_loop::value_reg (int v) +{ + const pipe_insn &p = body[v]; + + if (piped (p)) + return body[p.pop_to].newreg; + return p.newreg; +} + +rtx +pipe_loop::real_pattern (int i, bool drain, int run) +{ + const pipe_insn &p = body[i]; + + if (p.kind == PIPE_INCR) + { + rtx r = gen_rtx_REG (SImode, p.dest); + return gen_rtx_SET (r, plus_constant (SImode, r, p.disp)); + } + if (p.kind == PIPE_OP) + { + rtx a = gen_rtx_REG (p.mode, p.val[0] >= 0 ? value_reg (p.val[0]) : p.src[0]); + rtx b = gen_rtx_REG (p.mode, p.val[1] >= 0 ? value_reg (p.val[1]) : p.src[1]); + rtx d = gen_rtx_REG (p.mode, p.newreg); + + if (p.scalar) + return gen_rtx_SET (d, gen_rtx_fmt_ee (p.code, p.mode, a, b)); + if (p.mode == DFmode) + return (p.code == MULT ? gen_i860_pfmuldf (d, a, b) + : p.code == PLUS ? gen_i860_pfadddf (d, a, b) + : gen_i860_pfsubdf (d, a, b)); + return (p.code == MULT ? gen_i860_pfmulsf (d, a, b) + : p.code == PLUS ? gen_i860_pfaddsf (d, a, b) + : gen_i860_pfsubsf (d, a, b)); + } + + rtx mem = copy_rtx (p.mem); + if (!streams[p.stream].autoinc) + { + rtx base = gen_rtx_REG (SImode, streams[p.stream].reg); + XEXP (mem, 0) = plus_constant (SImode, base, access_disp (i, drain, run)); + } + set_mem_expr (mem, NULL_TREE); + clear_mem_offset (mem); + if (p.kind == PIPE_LOAD && use_pfld) + return (p.mode == DFmode ? gen_i860_pflddf (gen_rtx_REG (DFmode, p.newreg), mem) + : gen_i860_pfldsf (gen_rtx_REG (SFmode, p.newreg), mem)); + if (p.kind == PIPE_LOAD) + return gen_rtx_SET (gen_rtx_REG (p.mode, p.newreg), mem); + return gen_rtx_SET (mem, gen_rtx_REG (p.mode, p.val[0] >= 0 ? value_reg (p.val[0]) : p.src[0])); +} + +/* The FP registers insn I reads and writes. */ + +void +pipe_loop::item_regs (int i, auto_vec &reads, auto_vec &writes) +{ + const pipe_insn &p = body[i]; + int words = p.kind == PIPE_INCR ? 1 : GET_MODE_SIZE (p.mode) / UNITS_PER_WORD; + + for (int s = 0; s < p.nsrc; s++) + for (int w = 0; w < words; w++) + reads.safe_push ((p.val[s] >= 0 ? value_reg (p.val[s]) : p.src[s]) + w); + if (p.kind == PIPE_LOAD || p.kind == PIPE_OP) + for (int w = 0; w < words; w++) + writes.safe_push (p.newreg + w); +} + +bool +pipe_loop::items_conflict (int a, int b) +{ + auto_vec ra, wa, rb, wb; + + item_regs (a, ra, wa); + item_regs (b, rb, wb); + for (unsigned i = 0; i < wa.length (); i++) + { + if (wa[i] == FP0 || wa[i] == FP0 + 1) + continue; + for (unsigned j = 0; j < rb.length (); j++) + if (wa[i] == rb[j]) + return true; + for (unsigned j = 0; j < wb.length (); j++) + if (wa[i] == wb[j]) + return true; + } + for (unsigned i = 0; i < wb.length (); i++) + { + if (wb[i] == FP0 || wb[i] == FP0 + 1) + continue; + for (unsigned j = 0; j < ra.length (); j++) + if (wb[i] == ra[j]) + return true; + } + return false; +} + +/* FP and core halves of the loop as pairs, each after what it depends on and not in one pair with + it: which half of a pair sees the other's result is not known. The slot of bla holds fnop, as + a real FP half could not run again after a trap there. False if this saves nothing. */ + +bool +pipe_loop::plan_pairs () +{ + auto_vec fps, cores, placed; + int n = body.length (); + + placed.safe_grow_cleared (n); + for (int i = 0; i < n; i++) + { + placed[i] = -1; + if (body[i].kind == PIPE_OP) + fps.safe_push (i); + else + cores.safe_push (i); + } + + unsigned nf = 0, nc = 0; + while (nf < fps.length () || nc < cores.length ()) + { + int f = nf < fps.length () ? fps[nf] : -1; + int c = nc < cores.length () ? cores[nc] : -1; + int now = pairs.length (); + auto ready = [&] (int x) + { + if (x < 0) + return false; + for (int e = 0; e < x; e++) + if ((placed[e] < 0 || placed[e] == now) && items_conflict (e, x)) + return false; + return true; + }; + bool fok = ready (f), cok = ready (c); + + if (fok && cok && items_conflict (f, c)) + { + if (f < c) + cok = false; + else + fok = false; + } + if (!fok && !cok) + return false; + pair p = { fok ? f : -1, cok ? c : -1, false }; + pairs.safe_push (p); + if (fok) + { + placed[f] = now; + nf++; + } + if (cok) + { + placed[c] = now; + nc++; + } + } + + /* bla and its slot at the end */ + pair last = pairs.last (); + if (last.fp >= 0) + { + pairs.last ().core = -1; + pairs.last ().bla = true; + pair slot = { -1, last.core, false }; + pairs.safe_push (slot); + } + else + { + unsigned m = pairs.length (); + if (m >= 2 && pairs[m - 2].core < 0) + pairs[m - 2].bla = true; + else + { + pair b = { -1, -1, true }; + pairs.safe_insert (m - 1, b); + } + } + return (int) pairs.length () < n + 1; +} + +/* The loop as one insn: the first element marks it, then an FP and a core half per pair. */ + +rtx +pipe_loop::dual_kernel () +{ + int m = pairs.length (); + rtvec v = rtvec_alloc (1 + 2 * m); + + RTVEC_ELT (v, 0) = gen_rtx_UNSPEC_VOLATILE (VOIDmode, gen_rtvec (1, const0_rtx), + UNSPECV_DUAL_KERNEL); + for (int i = 0; i < m; i++) + { + const pair &p = pairs[i]; + + RTVEC_ELT (v, 1 + 2 * i) = (p.fp >= 0 ? real_pattern (p.fp, false, 0) + : gen_rtx_USE (VOIDmode, const0_rtx)); + if (p.bla) + RTVEC_ELT (v, 2 + 2 * i) + = gen_rtx_SET (count, gen_rtx_UNSPEC_VOLATILE (SImode, gen_rtvec (2, count, step), + UNSPECV_DUAL_BLA)); + else + RTVEC_ELT (v, 2 + 2 * i) = (p.core >= 0 ? real_pattern (p.core, false, 0) + : gen_rtx_USE (VOIDmode, const0_rtx)); + } + return gen_rtx_PARALLEL (VOIDmode, v); +} + +/* One run outside of the loop. RUN counts from zero in the prologue and in the drain. */ + +void +pipe_loop::emit_run (bool drain, int run) +{ + for (unsigned i = 0; i < body.length (); i++) + { + const pipe_insn &p = body[i]; + bool active = drain ? run < p.stage : run >= p.stage; + + if (p.kind == PIPE_INCR) + active = !drain; + if (active) + emit_insn (real_pattern (i, drain, run)); + else if (piped (p) + && (drain ? run <= lastpop[p.unit] : run >= minstage[p.unit])) + { + rtx z = gen_rtx_REG (p.mode, FP0); + rtx d = gen_rtx_REG (p.mode, p.newreg); + + /* the stack is always there to read */ + if (p.unit == 2) + { + rtx m = gen_frame_mem (p.mode, stack_pointer_rtx); + emit_insn (p.mode == DFmode ? gen_i860_pflddf (d, m) : gen_i860_pfldsf (d, m)); + } + else if (p.mode == DFmode) + emit_insn (p.unit == 0 ? gen_i860_pfmuldf (d, z, z) : gen_i860_pfadddf (d, z, z)); + else + emit_insn (p.unit == 0 ? gen_i860_pfmulsf (d, z, z) : gen_i860_pfaddsf (d, z, z)); + } + } +} + +/* A pop writes what the stage holds in its own precision: a double left by earlier code would + overwrite the neighbour of a single destination. So the old contents go to f0 first. With + double destinations a stale value stays within the register it is meant for. */ + +void +pipe_loop::emit_flush () +{ + for (int unit = 0; unit < 3; unit++) + for (unsigned i = 0; i < body.length (); i++) + if (body[i].kind != PIPE_STORE && body[i].kind != PIPE_INCR + && body[i].unit == unit && piped (body[i])) + { + rtx z = gen_rtx_REG (SFmode, FP0); + + if (body[i].mode == SFmode) + for (int n = 0; n < 3; n++) + emit_insn (unit == 2 ? gen_i860_pfldsf (z, gen_frame_mem (SFmode, stack_pointer_rtx)) + : unit == 0 ? gen_i860_pfmulsf (z, z, z) : gen_i860_pfaddsf (z, z, z)); + break; + } +} + +rtx_insn * +pipe_loop::branch_to_scalar (enum rtx_code code, rtx a, rtx b) +{ + rtx cond = gen_rtx_fmt_ee (code, VOIDmode, a, b); + rtx ref = gen_rtx_LABEL_REF (Pmode, scalar_label); + rtx_insn *j = emit_jump_insn (gen_rtx_SET (pc_rtx, + gen_rtx_IF_THEN_ELSE (VOIDmode, cond, ref, pc_rtx))); + JUMP_LABEL (j) = scalar_label; + LABEL_NUSES (scalar_label)++; + return j; +} + +/* What was emitted before the block NEXT since FIRST becomes a block after PREV. */ + +static basic_block +new_block (rtx_insn *seq, basic_block prev, basic_block next, profile_count cnt) +{ + rtx_insn *first = seq, *last = seq; + + emit_insn_before_noloc (seq, BB_HEAD (next), NULL); + for (rtx_insn *i = first; i != BB_HEAD (next); i = NEXT_INSN (i)) + if (!BARRIER_P (i)) + last = i; + basic_block bb = create_basic_block (first, last, prev); + BB_COPY_PARTITION (bb, prev); + bb->count = cnt; + return bb; +} + +/* One way through the loop, from the block PREV with FLAGS on the edge, up to a jump to the exit. + Its blocks go in front of the scalar loop. */ + +void +pipe_loop::emit_path (basic_block prev, int flags, rtx entry, basic_block scalar) +{ + profile_count cnt = pre->count; + rtx_insn *seq; + edge e; + + start_sequence (); + if (entry) + emit_label (entry); + emit_insn (gen_rtx_SET (count, plus_constant (SImode, count, -depth))); + emit_flush (); + for (int run = 0; run < depth; run++) + emit_run (false, run); + emit_insn (gen_i860_bla_prime (count, step)); + rtx exit_label = block_label (exit_bb); + if (!pairs.is_empty ()) + { + emit_insn (dual_kernel ()); + for (int run = 0; run < depth; run++) + emit_run (true, run); + rtx_insn *dj = emit_jump_insn (gen_jump (exit_label)); + JUMP_LABEL (dj) = exit_label; + LABEL_NUSES (exit_label)++; + emit_barrier (); + } + seq = get_insns (); + end_sequence (); + basic_block setup = new_block (seq, scalar->prev_bb, scalar, cnt); + e = make_edge (prev, setup, flags); + e->probability = profile_probability::likely (); + if (entry) + LABEL_NUSES (entry)++; + if (!pairs.is_empty ()) + { + e = make_edge (setup, exit_bb, 0); + e->probability = profile_probability::always (); + return; + } + + rtx label = gen_label_rtx (); + start_sequence (); + emit_label (label); + for (unsigned i = 0; i < body.length (); i++) + emit_insn (real_pattern (i, false, 0)); + rtx_insn *lj = emit_jump_insn (gen_i860_bla_loop (count, label, step)); + JUMP_LABEL (lj) = label; + LABEL_NUSES (label)++; + seq = get_insns (); + end_sequence (); + basic_block kernel = new_block (seq, setup, scalar, loop->count); + e = make_edge (setup, kernel, EDGE_FALLTHRU); + e->probability = profile_probability::always (); + e = make_edge (kernel, kernel, 0); + e->probability = find_edge (loop, loop)->probability; + + start_sequence (); + for (int run = 0; run < depth; run++) + emit_run (true, run); + rtx_insn *ej = emit_jump_insn (gen_jump (exit_label)); + JUMP_LABEL (ej) = exit_label; + LABEL_NUSES (exit_label)++; + emit_barrier (); + seq = get_insns (); + end_sequence (); + basic_block drain = new_block (seq, kernel, scalar, cnt); + e = make_edge (kernel, drain, EDGE_FALLTHRU); + e->probability = find_edge (loop, loop)->probability.invert (); + e = make_edge (drain, exit_bb, 0); + e->probability = profile_probability::always (); +} + +/* The tests, then the ways through the loop. With BIG, this variant with pipelined loads is for + what does not fit the data cache: pfld does not replace its lines. */ + +void +pipe_loop::transform (pipe_loop *big) +{ + pipe_loop *t = big ? big : this; + edge se = split_block (pre, PREV_INSN (prime)); + basic_block scalar = se->dest; + basic_block last = pre; + profile_count cnt = pre->count; + profile_probability likely = profile_probability::likely (); + + scalar_label = block_label (scalar); + t->scalar_label = scalar_label; + + start_sequence (); + branch_to_scalar (LE, count, GEN_INT (MAX (depth, t->depth))); + rtx_insn *seq = get_insns (); + end_sequence (); + rtx_insn *j = emit_insn_after_noloc (seq, BB_END (pre), pre); + gcc_assert (JUMP_P (j)); + se->flags &= ~EDGE_FALLTHRU; + se->probability = likely.invert (); + + /* every test: if the bases are closer than a reordering can matter, the scalar loop */ + for (unsigned n = 0; n < t->tests.length (); n++) + { + const pipe_stream &a = t->streams[t->tests[n].first], &b = t->streams[t->tests[n].second]; + HOST_WIDE_INT margin = t->test_margin (a, b); + rtx tmp = gen_rtx_REG (SImode, t->tmp_reg); + + start_sequence (); + emit_insn (gen_rtx_SET (tmp, gen_rtx_MINUS (SImode, gen_rtx_REG (SImode, a.reg), + gen_rtx_REG (SImode, b.reg)))); + emit_insn (gen_rtx_SET (tmp, plus_constant (SImode, tmp, margin))); + branch_to_scalar (LTU, tmp, GEN_INT (2 * margin)); + seq = get_insns (); + end_sequence (); + basic_block bb = new_block (seq, last, scalar, cnt); + edge e = make_edge (last, bb, EDGE_FALLTHRU); + e->probability = likely; + e = make_edge (bb, scalar, 0); + e->probability = likely.invert (); + last = bb; + } + + if (!big) + { + emit_path (last, EDGE_FALLTHRU, NULL_RTX, scalar); + return; + } + + /* the bytes all loads of the loop read */ + HOST_WIDE_INT bytes = 0; + for (unsigned n = 0; n < big->body.length (); n++) + if (big->body[n].kind == PIPE_LOAD) + bytes += abs_hwi (big->streams[big->body[n].stream].stride); + HOST_WIDE_INT limit = bytes ? (i860_pfld_min_bytes + bytes - 1) / bytes : 0; + + rtx small = gen_label_rtx (); + start_sequence (); + rtx ref = gen_rtx_LABEL_REF (Pmode, small); + rtx_insn *sj = emit_jump_insn (gen_rtx_SET (pc_rtx, + gen_rtx_IF_THEN_ELSE (VOIDmode, + gen_rtx_fmt_ee (LT, VOIDmode, count, + GEN_INT (limit)), + ref, pc_rtx))); + JUMP_LABEL (sj) = small; + seq = get_insns (); + end_sequence (); + basic_block choose = new_block (seq, last, scalar, cnt); + edge e = make_edge (last, choose, EDGE_FALLTHRU); + e->probability = likely; + + big->emit_path (choose, EDGE_FALLTHRU, NULL_RTX, scalar); + emit_path (choose, 0, small, scalar); +} + +} // anon namespace + +/* The insn made by dual_kernel. */ + +const char * +i860_output_dual_kernel (rtx par) +{ + /* The D bit acts one instruction later: dual mode starts after the entry pair and ends one pair + after the first without it, as in the code of the SVR4 libm. */ + fputs ("\t.balignl 8,0xa0000000\n\td.fnop\n\tnop\n1:\n", asm_out_file); + for (int i = 1; i < XVECLEN (par, 0); i++) + { + rtx x = XVECEXP (par, 0, i); + rtx ops[3]; + char t[64]; + + if (GET_CODE (x) == USE) + { + output_asm_insn (i & 1 ? "d.fnop" : "nop", ops); + continue; + } + rtx dst = SET_DEST (x), src = SET_SRC (x); + ops[0] = dst; + if (MEM_P (dst)) + { + ops[1] = src; + output_asm_insn (GET_MODE (dst) == DFmode ? "fst.d %1,%0" : "fst.l %1,%0", ops); + } + else if (MEM_P (src)) + { + ops[1] = src; + output_asm_insn (GET_MODE (src) == DFmode ? "fld.d %1,%0" : "fld.l %1,%0", ops); + } + else if (GET_CODE (src) == UNSPEC_VOLATILE && XINT (src, 1) == UNSPECV_PFLD) + { + ops[1] = XVECEXP (src, 0, 0); + output_asm_insn (GET_MODE (dst) == DFmode ? "pfld.d %1,%0" : "pfld.l %1,%0", ops); + } + else if (GET_CODE (src) == UNSPEC_VOLATILE && XINT (src, 1) == UNSPECV_DUAL_BLA) + { + ops[1] = XVECEXP (src, 0, 1); + output_asm_insn ("bla %1,%0,1b", ops); + } + else if (GP_REGNO_P (REGNO (dst))) + { + ops[1] = XEXP (src, 1); + output_asm_insn ("addu %1,%0,%0", ops); + } + else + { + const char *sfx = GET_MODE (dst) == DFmode ? "dd" : "ss"; + const char *name; + + if (GET_CODE (src) == UNSPEC_VOLATILE) + { + name = (XINT (src, 1) == UNSPECV_PFADD ? "pfadd" + : XINT (src, 1) == UNSPECV_PFSUB ? "pfsub" : "pfmul"); + ops[1] = XVECEXP (src, 0, 0); + ops[2] = XVECEXP (src, 0, 1); + } + else + { + name = (GET_CODE (src) == PLUS ? "fadd" + : GET_CODE (src) == MINUS ? "fsub" : "fmul"); + ops[1] = XEXP (src, 0); + ops[2] = XEXP (src, 1); + } + snprintf (t, sizeof t, "d.%s.%s %%1,%%2,%%0", name, sfx); + output_asm_insn (t, ops); + } + } + fputs ("\tfnop\n\tnop\n\tfnop\n\tnop\n", asm_out_file); + return ""; +} + +namespace { + +const pass_data pass_data_i860_pipeline = +{ + RTL_PASS, + "i860_pipeline", + OPTGROUP_NONE, + TV_MACH_DEP, + 0, 0, 0, 0, + TODO_df_finish, +}; + +class pass_i860_pipeline : public rtl_opt_pass +{ +public: + pass_i860_pipeline (gcc::context *ctxt) + : rtl_opt_pass (pass_data_i860_pipeline, ctxt) + {} + + bool gate (function *) final override + { + return ((i860_pipelined_fp > 0 || (i860_pipelined_fp < 0 && optimize >= 3)) + && optimize >= 2 && !optimize_size); + } + + unsigned int execute (function *) final override; +}; + +unsigned int +pass_i860_pipeline::execute (function *fun) +{ + auto_vec loops; + basic_block bb; + + df_analyze (); + FOR_EACH_BB_FN (bb, fun) + if (JUMP_P (BB_END (bb)) && recog_memoized (BB_END (bb)) == CODE_FOR_i860_bla_loop) + loops.safe_push (bb); + + /* the analysis needs the liveness of the unchanged function */ + bool changed = false; + for (unsigned i = 0; i < loops.length (); i++) + { + pipe_loop l (loops[i], false); + pipe_loop big (loops[i], true); + bool pfld = i860_pfld > 0 || (i860_pfld < 0 && optimize >= 3); + + if (changed) + df_analyze (); + if (!l.analyze ()) + { + if (dump_file) + fprintf (dump_file, "loop in bb %d stays scalar\n", loops[i]->index); + continue; + } + if (dump_file) + fprintf (dump_file, "loop in bb %d pipelined, %d stages\n", loops[i]->index, l.depth); + l.transform (pfld && big.analyze () ? &big : NULL); + changed = true; + } + return 0; +} + +} // anon namespace + +rtl_opt_pass * +make_pass_i860_pipeline (gcc::context *ctxt) +{ + return new pass_i860_pipeline (ctxt); +} diff --git a/gcc/config/i860/i860-protos.h b/gcc/config/i860/i860-protos.h new file mode 100644 index 00000000000..6698d16e65c --- /dev/null +++ b/gcc/config/i860/i860-protos.h @@ -0,0 +1,78 @@ +/* Prototypes for i860.cc functions used in the md file & elsewhere. + Copyright (C) 2000-2026 Free Software Foundation, Inc. + Copyright (C) 2026 René Rebe + +This file is part of GCC. + +GCC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 3, or (at your option) +any later version. + +GCC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GCC; see the file COPYING3. If not see +. */ + +#ifndef GCC_I860_PROTOS_H +#define GCC_I860_PROTOS_H + +extern HOST_WIDE_INT i860_initial_elimination_offset (int, int); +extern void i860_expand_prologue (void); +extern void i860_expand_epilogue (bool); +extern rtx i860_sibcall_mem (rtx); +extern void i860_output_function_prefix (FILE *, const char *); + +#ifdef RTX_CODE +extern rtx i860_return_addr_rtx (int, rtx); +extern rtx i860_eh_return_handler_rtx (void); +extern void i860_expand_move (machine_mode, rtx *); +extern void i860_expand_floatsidf (rtx, rtx); +extern bool i860_indexed_address_p (rtx, bool); +extern bool i860_q_address_p (rtx, machine_mode); +extern bool i860_call_address_p (rtx, bool); +extern bool i860_mem_aligned8_p (rtx); +extern int i860_mem_move_length (rtx *); +extern int i860_move_double_length (rtx *); +extern int i860_logic_length (enum rtx_code, rtx *); +extern rtx i860_gotoff_mem (rtx, rtx, rtx); +extern const char *i860_output_gotoff_access (rtx *, bool); +extern const char *i860_output_load (rtx *); +extern const char *i860_output_store (rtx *); +extern const char *i860_output_load_ext (rtx *, const char *); +extern const char *i860_output_sf_const (rtx *); +extern const char *i860_output_move_double (rtx *); +extern const char *i860_output_logic (enum rtx_code, rtx *); +extern bool i860_cbranch_operand_p (enum rtx_code, rtx); +extern const char *i860_output_bla (rtx_insn *, rtx *, int); +extern void i860_expand_fdiv (machine_mode, rtx *); +extern bool i860_bte_form_p (rtx *); +extern bool i860_symbolic_p (rtx); +extern rtx i860_legitimize_pic_address (rtx, rtx); +extern int i860_cbranch_length (rtx *, bool); +extern const char *i860_output_cbranch (rtx_insn *, rtx *, bool); +extern const char *i860_output_bit_cbranch (rtx *, bool); +extern const char *i860_output_fp_cbranch (rtx *, machine_mode, bool); +extern bool i860_fp_cbranch_simple_p (rtx *, bool); +extern bool i860_annul_branch_p (rtx_insn *); +extern const char *i860_output_call (rtx *, int); +#endif + +#ifdef TREE_CODE +extern void i860_init_cumulative_args (CUMULATIVE_ARGS *, tree); +#endif + +#ifdef RTX_CODE +extern int i860_sched_class (rtx_insn *); +extern const char *i860_output_dual_kernel (rtx); +#endif + +namespace gcc { class context; } +class rtl_opt_pass; +extern rtl_opt_pass *make_pass_i860_pipeline (gcc::context *); + +#endif /* GCC_I860_PROTOS_H */ diff --git a/gcc/config/i860/i860.cc b/gcc/config/i860/i860.cc new file mode 100644 index 00000000000..4bdf35f96c5 --- /dev/null +++ b/gcc/config/i860/i860.cc @@ -0,0 +1,2167 @@ +/* Subroutines for insn-output.cc for Intel i860. + Copyright (C) 1989-2005, 2026 Free Software Foundation, Inc. + Copyright (C) 2026 René Rebe + Derived from sparc.c. + + Written by Richard Stallman (rms@ai.mit.edu). + + Hacked substantially by Ron Guilmette (rfg@netcom.com) to cater + to the whims of the System V Release 4 assembler. + +This file is part of GCC. + +GCC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 3, or (at your option) +any later version. + +GCC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GCC; see the file COPYING3. If not see +. */ + +#define IN_TARGET_CODE 1 + +#include "config.h" +#include "system.h" +#include "coretypes.h" +#include "backend.h" +#include "target.h" +#include "rtl.h" +#include "tree.h" +#include "stringpool.h" +#include "attribs.h" +#include "df.h" +#include "memmodel.h" +#include "gimple.h" +#include "tm_p.h" +#include "expmed.h" +#include "optabs.h" +#include "regs.h" +#include "emit-rtl.h" +#include "recog.h" +#include "diagnostic-core.h" +#include "output.h" +#include "insn-attr.h" +#include "alias.h" +#include "fold-const.h" +#include "stor-layout.h" +#include "calls.h" +#include "varasm.h" +#include "explow.h" +#include "expr.h" +#include "builtins.h" +#include "gimplify.h" +#include "langhooks.h" +#include "predict.h" +#include "tm-constrs.h" + +/* This file should be included last. */ +#include "cfgloop.h" +#include "tree-cfg.h" +#include "target-def.h" + +/* Frame layout, high to low addresses: + + incoming stack arguments <- old sp (= fp + 16, arg pointer) + unused (8 bytes) + saved r1 fp + 4 + saved fp <- fp + callee-saved registers fp - 4, fp - 8, ... + varargs register save area 8 FP then 12 integer words + local variables <- soft frame pointer + outgoing arguments + <- sp + + This matches the native SVR4 compilers: fp points at the saved fp and + the return address follows it. */ + +struct i860_frame_info +{ + HOST_WIDE_INT regs; /* callee-saved registers, rounded */ + HOST_WIDE_INT va; /* varargs save area */ + HOST_WIDE_INT locals; + HOST_WIDE_INT outgoing; + HOST_WIDE_INT total; + bool save_r1; +}; + +#define I860_VA_SAVE_SIZE \ + ((I860_NUM_FP_ARGS + I860_NUM_INT_ARGS) * UNITS_PER_WORD) + +static bool +i860_save_reg_p (unsigned int regno) +{ + if (crtl->calls_eh_return) + for (unsigned i = 0; EH_RETURN_DATA_REGNO (i) != INVALID_REGNUM; i++) + if (regno == EH_RETURN_DATA_REGNO (i)) + return true; + /* The PIC register is fixed, but callee saved. */ + if (regno == PIC_OFFSET_TABLE_REGNUM) + return crtl->uses_pic_offset_table; + /* has a slot of its own */ + if (regno == HARD_FRAME_POINTER_REGNUM && frame_pointer_needed) + return false; + return df_regs_ever_live_p (regno) && !call_used_or_fixed_reg_p (regno); +} + +static void +i860_compute_frame (struct i860_frame_info *f) +{ + int n = 0; + + for (unsigned r = 0; r < FIRST_PSEUDO_REGISTER; r++) + if (i860_save_reg_p (r)) + n++; + + f->regs = ROUND_UP (n * UNITS_PER_WORD, 16); + f->va = cfun->stdarg ? I860_VA_SAVE_SIZE : 0; + f->locals = ROUND_UP (get_frame_size (), 16); + f->outgoing = ROUND_UP (crtl->outgoing_args_size, 16); + f->total = 16 + f->regs + f->va + f->locals + f->outgoing; + /* Loading the PIC register reads the PC with a call. */ + f->save_r1 = (!crtl->is_leaf || crtl->profile || crtl->calls_eh_return + || crtl->uses_pic_offset_table + || df_regs_ever_live_p (I860_RETURN_REGNUM)); +} + +HOST_WIDE_INT +i860_initial_elimination_offset (int from, int to) +{ + struct i860_frame_info f; + + i860_compute_frame (&f); + if (from == ARG_POINTER_REGNUM && to == HARD_FRAME_POINTER_REGNUM) + return 16; + if (from == ARG_POINTER_REGNUM && to == STACK_POINTER_REGNUM) + return f.total; + if (from == FRAME_POINTER_REGNUM && to == HARD_FRAME_POINTER_REGNUM) + return -(f.regs + f.va); + if (from == FRAME_POINTER_REGNUM && to == STACK_POINTER_REGNUM) + return f.locals + f.outgoing; + gcc_unreachable (); +} + +/* What refers to the frame in ways the stack pointer cannot serve. */ +static bool +i860_frame_pointer_required (void) +{ + return (I860_SVR4_FUNCTION_PREFIX || cfun->stdarg || cfun->calls_alloca + || cfun->has_nonlocal_label || crtl->calls_eh_return || crtl->accesses_prior_frames + || crtl->profile); +} + +static bool +i860_can_eliminate (const int from ATTRIBUTE_UNUSED, const int to) +{ + return to == HARD_FRAME_POINTER_REGNUM || !frame_pointer_needed; +} + +rtx +i860_return_addr_rtx (int count, rtx frame) +{ + if (count == 0) + return get_hard_reg_initial_val (Pmode, I860_RETURN_REGNUM); + return gen_rtx_MEM (Pmode, plus_constant (Pmode, frame, 4)); +} + +rtx +i860_eh_return_handler_rtx (void) +{ + return gen_frame_mem (Pmode, plus_constant (Pmode, hard_frame_pointer_rtx, + 4)); +} + +static rtx_insn * +emit_frame_insn (rtx x) +{ + rtx_insn *insn = emit_insn (x); + RTX_FRAME_RELATED_P (insn) = 1; + return insn; +} + +/* Without a frame pointer the slots of the registers are this far from the stack pointer, with + the top of the frame as the frame pointer would show it. */ +static HOST_WIDE_INT i860_slot_base; + +static rtx +fp_slot (machine_mode mode, HOST_WIDE_INT offset) +{ + rtx base = (frame_pointer_needed ? hard_frame_pointer_rtx + : plus_constant (Pmode, stack_pointer_rtx, i860_slot_base)); + + return gen_frame_mem (mode, plus_constant (Pmode, base, offset)); +} + +/* Save mode for a callee-saved register. */ +static machine_mode +i860_save_mode (unsigned int regno) +{ + if (FP_REGNO_P (regno)) + return SFmode; + return SImode; +} + +/* What the scheduler has to know of INSN. */ +int +i860_sched_class (rtx_insn *insn) +{ + if (JUMP_P (insn) || CALL_P (insn)) + return SCLASS_BRANCH; + if (INSN_CODE (insn) == CODE_FOR_i860_fmlow) + return SCLASS_FMULD; + + rtx set = single_set (insn); + if (!set) + return SCLASS_ALU; + + rtx dst = SET_DEST (set), src = SET_SRC (set); + machine_mode mode = GET_MODE (dst); + bool fp = FLOAT_MODE_P (mode) || FP_REG_P (dst) || FP_REG_P (src); + + if (MEM_P (dst)) + return SCLASS_STORE; + if ((GET_CODE (src) == SIGN_EXTEND || GET_CODE (src) == ZERO_EXTEND) + && MEM_P (XEXP (src, 0))) + return SCLASS_ILOAD; + if (MEM_P (src)) + return fp ? SCLASS_FLOAD : SCLASS_ILOAD; + if (FLOAT_MODE_P (mode)) + switch (GET_CODE (src)) + { + case PLUS: + case MINUS: + return SCLASS_FADD; + case MULT: + return mode == DFmode ? SCLASS_FMULD : SCLASS_FMULS; + case DIV: + case SQRT: + return SCLASS_LONG; + default: + break; + } + return fp ? SCLASS_FPMISC : SCLASS_ALU; +} + +/* A leaf with nothing to save and nothing in memory needs no frame. Decided once, when the + prologue is made: after that the prologue itself would mention the frame pointer. */ +static bool +i860_frameless_p (void) +{ + static int decided_no = -1; + static bool frameless; + + if (decided_no != cfun->funcdef_no) + { + struct i860_frame_info f; + + decided_no = cfun->funcdef_no; + i860_compute_frame (&f); + frameless = (flag_omit_frame_pointer + && f.total == 16 && !f.save_r1 && crtl->is_leaf && !crtl->profile + && !cfun->calls_alloca && !cfun->has_nonlocal_label && !crtl->calls_eh_return + && !crtl->accesses_prior_frames && !cfun->stdarg + && !crtl->uses_pic_offset_table); + /* the expander of the prologue runs in a sequence of its own */ + push_topmost_sequence (); + rtx_insn *first = get_insns (); + pop_topmost_sequence (); + for (rtx_insn *insn = first; frameless && insn; insn = NEXT_INSN (insn)) + if (NONDEBUG_INSN_P (insn) + && (reg_mentioned_p (hard_frame_pointer_rtx, PATTERN (insn)) + || reg_mentioned_p (stack_pointer_rtx, PATTERN (insn)))) + frameless = false; + } + return frameless; +} + +void +i860_expand_prologue (void) +{ + struct i860_frame_info f; + rtx sp = stack_pointer_rtx, fp = hard_frame_pointer_rtx; + + if (i860_frameless_p ()) + return; + + i860_compute_frame (&f); + + /* a large frame: the register slots first, within reach of a displacement */ + HOST_WIDE_INT head = f.total <= 0x7fff ? f.total : 16 + f.regs; + if (!frame_pointer_needed) + { + emit_frame_insn (gen_addsi3 (sp, sp, GEN_INT (-head))); + i860_slot_base = head - 16; + } + else if (f.total <= 0x7fff) + { + emit_frame_insn (gen_addsi3 (sp, sp, GEN_INT (-f.total))); + emit_frame_insn (gen_rtx_SET (gen_frame_mem (SImode, + plus_constant (Pmode, sp, + f.total - 16)), + fp)); + emit_frame_insn (gen_addsi3 (fp, sp, GEN_INT (f.total - 16))); + } + else + { + emit_frame_insn (gen_addsi3 (sp, sp, GEN_INT (-16))); + emit_frame_insn (gen_rtx_SET (gen_frame_mem (SImode, sp), fp)); + emit_frame_insn (gen_rtx_SET (fp, sp)); + /* The CFA is fp based from here on. */ + emit_insn (gen_addsi3 (sp, sp, GEN_INT (-(f.total - 16)))); + } + + if (f.save_r1) + emit_frame_insn (gen_rtx_SET (fp_slot (SImode, 4), + gen_rtx_REG (SImode, I860_RETURN_REGNUM))); + + HOST_WIDE_INT off = 0; + for (unsigned r = 0; r < FIRST_PSEUDO_REGISTER; r++) + if (i860_save_reg_p (r)) + { + machine_mode mode = i860_save_mode (r); + off -= UNITS_PER_WORD; + emit_frame_insn (gen_rtx_SET (fp_slot (mode, off), + gen_rtx_REG (mode, r))); + } + + if (!frame_pointer_needed && head != f.total) + { + emit_frame_insn (gen_addsi3 (sp, sp, GEN_INT (-(f.total - head)))); + i860_slot_base = f.total - 16; + } + + if (f.va) + { + HOST_WIDE_INT base = -(f.regs + f.va); + + for (int i = 0; i < I860_NUM_FP_ARGS; i += 2) + { + rtx mem = fp_slot (DFmode, base + i * UNITS_PER_WORD); + set_mem_align (mem, 64); + emit_move_insn (mem, gen_rtx_REG (DFmode, I860_FIRST_FP_ARG + i)); + } + for (int i = 0; i < I860_NUM_INT_ARGS; i++) + emit_move_insn (fp_slot (SImode, base + (I860_NUM_FP_ARGS + i) + * UNITS_PER_WORD), + gen_rtx_REG (SImode, I860_FIRST_INT_ARG + i)); + } + + if (crtl->uses_pic_offset_table) + { + emit_insn (gen_i860_set_got ()); + if (has_hard_reg_initial_val (Pmode, I860_RETURN_REGNUM)) + emit_move_insn (gen_rtx_REG (SImode, I860_RETURN_REGNUM), + fp_slot (SImode, 4)); + } + + /* below the stack pointer a signal handler would overwrite the frame */ + emit_insn (gen_blockage ()); +} + +/* SIBCALL: restore all but leave the jump to the sibcall pattern, whose delay + slot takes the sp restore. */ +void +i860_expand_epilogue (bool sibcall) +{ + struct i860_frame_info f; + rtx fp = hard_frame_pointer_rtx; + rtx r31 = gen_rtx_REG (SImode, I860_TEMP_REGNUM); + bool sp_from_fp = (cfun->calls_alloca || cfun->has_nonlocal_label + || crtl->calls_eh_return); + + if (i860_frameless_p ()) + { + if (!sibcall) + emit_jump_insn (gen_i860_return_leaf ()); + return; + } + + emit_insn (gen_blockage ()); + i860_compute_frame (&f); + HOST_WIDE_INT rest = f.total; + if (!frame_pointer_needed) + { + if (f.total > 0x7fff) + { + rest = 16 + f.regs; + emit_insn (gen_addsi3 (stack_pointer_rtx, stack_pointer_rtx, GEN_INT (f.total - rest))); + } + i860_slot_base = rest - 16; + } + else if (f.total > 0x7fff) + sp_from_fp = true; + + HOST_WIDE_INT off = 0; + for (unsigned r = 0; r < FIRST_PSEUDO_REGISTER; r++) + if (i860_save_reg_p (r)) + { + machine_mode mode = i860_save_mode (r); + off -= UNITS_PER_WORD; + emit_move_insn (gen_rtx_REG (mode, r), fp_slot (mode, off)); + } + + if (sp_from_fp) + { + emit_insn (gen_addsi3 (r31, fp, GEN_INT (16))); + if (crtl->calls_eh_return) + emit_insn (gen_addsi3 (r31, r31, EH_RETURN_STACKADJ_RTX)); + } + + if (f.save_r1) + emit_move_insn (gen_rtx_REG (SImode, I860_RETURN_REGNUM), + fp_slot (SImode, 4)); + if (frame_pointer_needed) + emit_move_insn (fp, fp_slot (SImode, 0)); + + if (sibcall) + { + if (sp_from_fp) + emit_move_insn (stack_pointer_rtx, r31); + else + emit_insn (gen_addsi3 (stack_pointer_rtx, stack_pointer_rtx, + GEN_INT (rest))); + } + else if (sp_from_fp) + emit_jump_insn (gen_i860_return_reg (r31)); + else + emit_jump_insn (gen_i860_return_adjust (GEN_INT (rest))); +} + +/* The word in front of each function: a nop that also carries the + prologue length for the SVR4 debugger. */ +void +i860_output_function_prefix (FILE *file, const char *name) +{ + fputs ("\t.long\t.ep.", file); + assemble_name (file, name); + fputs ("-", file); + assemble_name (file, name); + fputs ("+0xc8000000\n\tnop\n", file); +} + +static void +i860_function_end_prologue (FILE *file) +{ + const char *name = XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0); + + if (!I860_SVR4_FUNCTION_PREFIX) + return; + fputs (".ep.", file); + assemble_name (file, name); + fputs (":\n", file); +} + +/* Argument passing. */ + +void +i860_init_cumulative_args (CUMULATIVE_ARGS *cum, tree fntype) +{ + /* A structure return address occupies r16. */ + cum->ints = (fntype && aggregate_value_p (TREE_TYPE (fntype), fntype) + ? UNITS_PER_WORD : 0); + cum->floats = 0; +} + +enum i860_arg_class { ARG_MEM, ARG_INT, ARG_FP }; + +static enum i860_arg_class +i860_arg_class (machine_mode mode, const_tree type) +{ + if (type && AGGREGATE_TYPE_P (type)) + return ARG_MEM; + if (GET_MODE_CLASS (mode) == MODE_FLOAT + || (mode == DImode && !I860_DIMODE_ARGS_IN_GPRS)) + return ARG_FP; + if (GET_MODE_CLASS (mode) == MODE_INT) + return ARG_INT; + return ARG_MEM; +} + +static rtx +i860_function_arg (cumulative_args_t cum_v, const function_arg_info &arg) +{ + CUMULATIVE_ARGS *cum = get_cumulative_args (cum_v); + int size = GET_MODE_SIZE (arg.mode); + int off; + + if (arg.end_marker_p ()) + return NULL_RTX; + + switch (i860_arg_class (arg.mode, arg.type)) + { + case ARG_FP: + off = ROUND_UP (cum->floats, size); + if (off + size <= I860_NUM_FP_ARGS * UNITS_PER_WORD) + return gen_rtx_REG (arg.mode, I860_FIRST_FP_ARG + off / UNITS_PER_WORD); + break; + case ARG_INT: + /* integer register pairs are not aligned */ + off = cum->ints; + if (off + size <= I860_NUM_INT_ARGS * UNITS_PER_WORD) + return gen_rtx_REG (arg.mode, + I860_FIRST_INT_ARG + off / UNITS_PER_WORD); + break; + default: + break; + } + return NULL_RTX; +} + +static void +i860_function_arg_advance (cumulative_args_t cum_v, + const function_arg_info &arg) +{ + CUMULATIVE_ARGS *cum = get_cumulative_args (cum_v); + int size = GET_MODE_SIZE (arg.mode); + + switch (i860_arg_class (arg.mode, arg.type)) + { + case ARG_FP: + cum->floats = ROUND_UP (cum->floats, size) + ROUND_UP (size, 4); + break; + case ARG_INT: + cum->ints += ROUND_UP (size, 4); + break; + default: + break; + } +} + +static unsigned int +i860_function_arg_boundary (machine_mode mode, const_tree type) +{ + unsigned int align = type ? TYPE_ALIGN (type) : GET_MODE_ALIGNMENT (mode); + + return MIN (MAX (align, PARM_BOUNDARY), STACK_BOUNDARY); +} + +static rtx +i860_function_value (const_tree type, const_tree fn ATTRIBUTE_UNUSED, + bool outgoing ATTRIBUTE_UNUSED) +{ + machine_mode mode = TYPE_MODE (type); + + return gen_rtx_REG (mode, GET_MODE_CLASS (mode) == MODE_FLOAT + ? I860_FIRST_FP_ARG : I860_FIRST_INT_ARG); +} + +static rtx +i860_libcall_value (machine_mode mode, const_rtx fun ATTRIBUTE_UNUSED) +{ + return gen_rtx_REG (mode, GET_MODE_CLASS (mode) == MODE_FLOAT + ? I860_FIRST_FP_ARG : I860_FIRST_INT_ARG); +} + +static bool +i860_function_value_regno_p (const unsigned int regno) +{ + return regno == I860_FIRST_INT_ARG || regno == I860_FIRST_FP_ARG; +} + +static rtx +i860_struct_value_rtx (tree fntype ATTRIBUTE_UNUSED, + int incoming ATTRIBUTE_UNUSED) +{ + return gen_rtx_REG (Pmode, I860_STRUCT_VALUE_REGNUM); +} + +/* Varargs. The SVR4 ABI va_list is + + typedef struct { + unsigned ireg_used; integer registers consumed + unsigned freg_used; FP registers (words) consumed + long *reg_base; 8 FP words, then 12 integer words + long *mem_ptr; next stack argument + } va_list; + + The prologue of a stdarg function stores all argument registers in + the register save area right above the local variables. */ + +static void +i860_setup_incoming_varargs (cumulative_args_t, const function_arg_info &, + int *, int) +{ +} + +static tree +i860_build_builtin_va_list (void) +{ + tree record = lang_hooks.types.make_type (RECORD_TYPE); + tree type_decl = build_decl (BUILTINS_LOCATION, TYPE_DECL, + get_identifier ("__va_list_tag"), record); + tree f_gpr = build_decl (BUILTINS_LOCATION, FIELD_DECL, + get_identifier ("__ireg_used"), unsigned_type_node); + tree f_fpr = build_decl (BUILTINS_LOCATION, FIELD_DECL, + get_identifier ("__freg_used"), unsigned_type_node); + tree f_sav = build_decl (BUILTINS_LOCATION, FIELD_DECL, + get_identifier ("__reg_base"), ptr_type_node); + tree f_mem = build_decl (BUILTINS_LOCATION, FIELD_DECL, + get_identifier ("__mem_ptr"), ptr_type_node); + + DECL_FIELD_CONTEXT (f_gpr) = record; + DECL_FIELD_CONTEXT (f_fpr) = record; + DECL_FIELD_CONTEXT (f_sav) = record; + DECL_FIELD_CONTEXT (f_mem) = record; + + TYPE_STUB_DECL (record) = type_decl; + TYPE_NAME (record) = type_decl; + TYPE_FIELDS (record) = f_gpr; + DECL_CHAIN (f_gpr) = f_fpr; + DECL_CHAIN (f_fpr) = f_sav; + DECL_CHAIN (f_sav) = f_mem; + + layout_type (record); + return record; +} + +static void +i860_va_fields (tree valist, tree *gpr, tree *fpr, tree *sav, tree *mem) +{ + tree f_gpr = TYPE_FIELDS (va_list_type_node); + tree f_fpr = DECL_CHAIN (f_gpr); + tree f_sav = DECL_CHAIN (f_fpr); + tree f_mem = DECL_CHAIN (f_sav); + + *gpr = build3 (COMPONENT_REF, TREE_TYPE (f_gpr), unshare_expr (valist), + f_gpr, NULL_TREE); + *fpr = build3 (COMPONENT_REF, TREE_TYPE (f_fpr), unshare_expr (valist), + f_fpr, NULL_TREE); + *sav = build3 (COMPONENT_REF, TREE_TYPE (f_sav), unshare_expr (valist), + f_sav, NULL_TREE); + *mem = build3 (COMPONENT_REF, TREE_TYPE (f_mem), unshare_expr (valist), + f_mem, NULL_TREE); +} + +static void +i860_va_assign (tree lhs, tree rhs) +{ + tree t = build2 (MODIFY_EXPR, TREE_TYPE (lhs), lhs, rhs); + TREE_SIDE_EFFECTS (t) = 1; + expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL); +} + +static void +i860_va_start (tree valist, rtx nextarg) +{ + tree gpr, fpr, sav, mem; + + i860_va_fields (valist, &gpr, &fpr, &sav, &mem); + i860_va_assign (gpr, build_int_cst (TREE_TYPE (gpr), + crtl->args.info.ints / UNITS_PER_WORD)); + i860_va_assign (fpr, build_int_cst (TREE_TYPE (fpr), + crtl->args.info.floats / UNITS_PER_WORD)); + /* The save area sits right above the soft frame pointer. */ + i860_va_assign (sav, make_tree (TREE_TYPE (sav), virtual_stack_vars_rtx)); + i860_va_assign (mem, make_tree (TREE_TYPE (mem), nextarg)); +} + +static tree +i860_gimplify_va_arg_expr (tree valist, tree type, gimple_seq *pre_p, + gimple_seq *post_p ATTRIBUTE_UNUSED) +{ + tree gpr, fpr, sav, mem, t; + /* variable sized types arrive as a pointer */ + bool indirect = pass_va_arg_by_reference (type); + if (indirect) + type = build_pointer_type (type); + machine_mode mode = TYPE_MODE (type); + HOST_WIDE_INT size = int_size_in_bytes (type); + enum i860_arg_class cls = i860_arg_class (mode, type); + tree addr = create_tmp_var (ptr_type_node, "va_addr"); + tree lab_over = NULL_TREE; + + i860_va_fields (valist, &gpr, &fpr, &sav, &mem); + + if (cls != ARG_MEM && size > 0) + { + tree reg = cls == ARG_FP ? fpr : gpr; + HOST_WIDE_INT nregs = CEIL (size, UNITS_PER_WORD); + HOST_WIDE_INT limit = cls == ARG_FP ? I860_NUM_FP_ARGS + : I860_NUM_INT_ARGS; + HOST_WIDE_INT base = cls == ARG_FP ? 0 + : I860_NUM_FP_ARGS * UNITS_PER_WORD; + tree utype = TREE_TYPE (reg); + tree lab_mem = create_artificial_label (UNKNOWN_LOCATION); + + lab_over = create_artificial_label (UNKNOWN_LOCATION); + + /* FP register pairs start at an even register, as in function_arg. */ + if (nregs > 1 && cls == ARG_FP) + { + t = build2 (PLUS_EXPR, utype, reg, build_int_cst (utype, nregs - 1)); + t = build2 (BIT_AND_EXPR, utype, t, build_int_cst (utype, -nregs)); + gimplify_assign (unshare_expr (reg), t, pre_p); + } + + t = build2 (GT_EXPR, boolean_type_node, unshare_expr (reg), + build_int_cst (utype, limit - nregs)); + t = build3 (COND_EXPR, void_type_node, t, + build1 (GOTO_EXPR, void_type_node, lab_mem), NULL_TREE); + gimplify_and_add (t, pre_p); + + t = fold_convert (sizetype, unshare_expr (reg)); + t = size_binop (MULT_EXPR, t, size_int (UNITS_PER_WORD)); + t = size_binop (PLUS_EXPR, t, size_int (base)); + t = fold_build_pointer_plus (unshare_expr (sav), t); + gimplify_assign (addr, t, pre_p); + + t = build2 (PLUS_EXPR, utype, unshare_expr (reg), + build_int_cst (utype, nregs)); + gimplify_assign (unshare_expr (reg), t, pre_p); + gimple_seq_add_stmt (pre_p, gimple_build_goto (lab_over)); + gimple_seq_add_stmt (pre_p, gimple_build_label (lab_mem)); + + /* Once in memory, later arguments of this class follow there. */ + t = build2 (PLUS_EXPR, utype, unshare_expr (reg), + build_int_cst (utype, nregs)); + gimplify_assign (unshare_expr (reg), t, pre_p); + } + + /* Stack argument, aligned like function_arg_boundary. */ + HOST_WIDE_INT align = i860_function_arg_boundary (mode, type) + / BITS_PER_UNIT; + t = unshare_expr (mem); + if (align > UNITS_PER_WORD) + { + t = fold_build_pointer_plus_hwi (t, align - 1); + t = build2 (BIT_AND_EXPR, TREE_TYPE (mem), t, + build_int_cst (TREE_TYPE (mem), -align)); + } + gimplify_assign (addr, t, pre_p); + t = fold_build_pointer_plus_hwi (addr, ROUND_UP (size, UNITS_PER_WORD)); + gimplify_assign (unshare_expr (mem), t, pre_p); + + if (lab_over) + gimple_seq_add_stmt (pre_p, gimple_build_label (lab_over)); + + addr = fold_convert (build_pointer_type (type), addr); + addr = build_va_arg_indirect_ref (addr); + return indirect ? build_va_arg_indirect_ref (addr) : addr; +} + +/* Addressing. Valid addresses are reg, reg + 16-bit offset suitably + aligned for the access, and constant addresses (output through r31). + reg + reg is valid for loads only, see indexed_memory_operand. */ + +static bool +i860_base_reg_p (rtx x, bool strict) +{ + if (!REG_P (x)) + return false; + unsigned int regno = REGNO (x); + if (strict) + return REGNO_OK_FOR_BASE_P (regno); + return regno >= FIRST_PSEUDO_REGISTER || I860_BASE_HARD_REGNO_P (regno); +} + +/* True for an address only known at link time. */ +bool +i860_symbolic_p (rtx x) +{ + return (GET_CODE (x) == SYMBOL_REF || GET_CODE (x) == LABEL_REF + || GET_CODE (x) == CONST); +} + +#ifdef I860_THREAD_POINTER_REGNUM +#define I860_TP_REGNUM I860_THREAD_POINTER_REGNUM +#else +#define I860_TP_REGNUM 30 /* never reached: this target has no TLS */ +#endif + +/* True for the address of a thread local symbol, plus maybe an offset. */ +static bool +i860_tls_address_p (rtx x) +{ + rtx sym, off; + + if (!i860_symbolic_p (x)) + return false; + split_const (x, &sym, &off); + return GET_CODE (sym) == SYMBOL_REF && SYMBOL_REF_TLS_MODEL (sym) != TLS_MODEL_NONE; +} + +static bool +i860_constant_address_p (rtx x) +{ + return CONST_INT_P (x) + || (!flag_pic && i860_symbolic_p (x) && !i860_tls_address_p (x)); +} + +static bool +i860_legitimate_constant_p (machine_mode mode ATTRIBUTE_UNUSED, rtx x) +{ + return (!flag_pic || !i860_symbolic_p (x)) && !i860_tls_address_p (x); +} + +static bool +i860_cannot_force_const_mem (machine_mode mode ATTRIBUTE_UNUSED, rtx x) +{ + return (flag_pic && i860_symbolic_p (x)) || i860_tls_address_p (x); +} + +/* The address of the thread local X in a new register. Local dynamic is plain + general dynamic; non-PIC code has no r15 and does not need general dynamic. */ +static rtx +i860_legitimize_tls_address (rtx x) +{ + rtx sym, off_rtx, dest = gen_reg_rtx (Pmode), tmp; + HOST_WIDE_INT off; + enum tls_model model; + + split_const (x, &sym, &off_rtx); + off = INTVAL (off_rtx); + model = SYMBOL_REF_TLS_MODEL (sym); + if (model == TLS_MODEL_LOCAL_DYNAMIC) + model = TLS_MODEL_GLOBAL_DYNAMIC; + if (!flag_pic && model == TLS_MODEL_GLOBAL_DYNAMIC) + model = TLS_MODEL_INITIAL_EXEC; + + switch (model) + { + case TLS_MODEL_GLOBAL_DYNAMIC: + tmp = gen_reg_rtx (Pmode); + crtl->uses_pic_offset_table = 1; + emit_insn (gen_i860_tls_gd (tmp, sym)); + tmp = emit_library_call_value (init_one_libfunc ("__tls_get_addr"), + NULL_RTX, LCT_NORMAL, Pmode, tmp, Pmode); + emit_move_insn (dest, tmp); + break; + + case TLS_MODEL_INITIAL_EXEC: + tmp = gen_reg_rtx (Pmode); + if (flag_pic) + { + crtl->uses_pic_offset_table = 1; + emit_insn (gen_i860_tls_ie (tmp, sym)); + } + else + emit_insn (gen_i860_tls_ie_abs (tmp, sym)); + emit_insn (gen_addsi3 (dest, tmp, gen_rtx_REG (Pmode, I860_TP_REGNUM))); + break; + + case TLS_MODEL_LOCAL_EXEC: + emit_insn (gen_i860_tls_le (dest, sym)); + break; + + default: + gcc_unreachable (); + } + + if (off != 0) + { + tmp = expand_simple_binop (Pmode, PLUS, dest, GEN_INT (off), dest, 0, + OPTAB_LIB_WIDEN); + if (tmp != dest) + emit_move_insn (dest, tmp); + } + return dest; +} + +/* Load the symbolic address X into REG, or a new register: through a GOT + offset if it binds locally, else from its GOT entry. */ +rtx +i860_legitimize_pic_address (rtx x, rtx reg) +{ + rtx sym, off_rtx; + HOST_WIDE_INT off; + + if (reg == NULL_RTX) + reg = gen_reg_rtx (Pmode); + split_const (x, &sym, &off_rtx); + off = INTVAL (off_rtx); + + crtl->uses_pic_offset_table = 1; + if (GET_CODE (sym) == LABEL_REF || SYMBOL_REF_LOCAL_P (sym)) + emit_insn (gen_i860_load_gotoff (reg, x)); + else + { + emit_insn (gen_i860_load_got (reg, sym)); + if (off != 0) + { + rtx t = expand_simple_binop (Pmode, PLUS, reg, GEN_INT (off), reg, + 0, OPTAB_LIB_WIDEN); + if (t != reg) + emit_move_insn (reg, t); + } + } + return reg; +} + +static bool +i860_legitimate_address_p (machine_mode mode, rtx x, bool strict, + code_helper = ERROR_MARK) +{ + HOST_WIDE_INT size = GET_MODE_SIZE (mode); + + if (i860_base_reg_p (x, strict)) + return true; + /* fld and fst only: the integer alternatives of the moves take offsettable memory */ + if ((GET_CODE (x) == PRE_INC || GET_CODE (x) == PRE_DEC) + && (mode == SFmode || mode == DFmode) + && i860_base_reg_p (XEXP (x, 0), strict)) + return true; + if (GET_CODE (x) == PLUS && i860_base_reg_p (XEXP (x, 0), strict) + && CONST_INT_P (XEXP (x, 1))) + { + HOST_WIDE_INT d = INTVAL (XEXP (x, 1)); + HOST_WIDE_INT unit = size <= 0 ? 1 : MIN (size, UNITS_PER_WORD); + HOST_WIDE_INT last = d + MAX (size, 1) - unit; + + return (d % unit) == 0 && IN_RANGE (d, -0x8000, 0x7fff) + && IN_RANGE (last, -0x8000, 0x7fff); + } + return i860_constant_address_p (x); +} + +bool +i860_indexed_address_p (rtx x, bool strict) +{ + return (GET_CODE (x) == PLUS && i860_base_reg_p (XEXP (x, 0), strict) + && i860_base_reg_p (XEXP (x, 1), strict)); +} + +bool +i860_mem_aligned8_p (rtx mem) +{ + return MEM_ALIGN (mem) >= 64; +} + +/* Addresses accepted by the "Q" constraint. */ +bool +i860_q_address_p (rtx x, machine_mode mode) +{ + /* Non-strict: LRA assigns base registers to the address pseudos. */ + if (i860_indexed_address_p (x, false)) + return true; + return (!i860_constant_address_p (x) + && i860_legitimate_address_p (mode, x, false)); +} + +/* Call targets: a symbol or an integer register. STRICT rejects pseudos + not (yet) allocated to one, so LRA reloads them into GENERAL_REGS. */ +bool +i860_call_address_p (rtx x, bool strict) +{ + if (GET_CODE (x) == SYMBOL_REF) + return true; + if (!REG_P (x)) + return false; + if (HARD_REGISTER_P (x)) + return GP_REGNO_P (REGNO (x)); + return !strict || (reg_renumber && GP_REGNO_P (reg_renumber[REGNO (x)])); +} + +static rtx +i860_legitimize_address (rtx x, rtx oldx ATTRIBUTE_UNUSED, machine_mode mode) +{ + if (i860_tls_address_p (x)) + return i860_legitimize_tls_address (x); + if (flag_pic && i860_symbolic_p (x)) + return i860_legitimize_pic_address (x, NULL_RTX); + if (GET_CODE (x) == PLUS) + { + rtx a = XEXP (x, 0), b = XEXP (x, 1); + + if (!REG_P (a)) + a = force_reg (Pmode, a); + if (!REG_P (b) && !CONST_INT_P (b)) + b = force_reg (Pmode, b); + x = gen_rtx_PLUS (Pmode, a, b); + if (!i860_legitimate_address_p (mode, x, false)) + x = force_reg (Pmode, x); + } + return x; +} + +/* Division: the Newton-Raphson pattern, and libgcc for what it gets wrong. */ +void +i860_expand_fdiv (machine_mode mode, rtx *operands) +{ + rtx res = gen_reg_rtx (mode); + rtx_code_label *done = gen_label_rtx (); + rtx val; + + emit_insn (mode == DFmode + ? gen_i860_divdf3 (res, operands[1], operands[2]) + : gen_i860_divsf3 (res, operands[1], operands[2])); + if (HONOR_NANS (mode) || HONOR_INFINITIES (mode)) + { + emit_cmp_and_jump_insns (res, res, EQ, NULL_RTX, mode, 0, done); + val = emit_library_call_value + (init_one_libfunc (mode == DFmode ? "__i860_fdiv_special" + : "__i860_fdivs_special"), + res, LCT_CONST, mode, operands[1], mode, operands[2], mode); + if (val != res) + emit_move_insn (res, val); + emit_label (done); + } + emit_move_insn (operands[0], res); +} + +/* Registers and modes. */ + +/* 0: not in FP registers, otherwise the unit size in words. */ +static int +i860_fp_unit_words (machine_mode mode) +{ + enum mode_class cls = GET_MODE_CLASS (mode); + + if (cls != MODE_FLOAT && cls != MODE_INT && cls != MODE_COMPLEX_FLOAT) + return 0; + int unit = GET_MODE_UNIT_SIZE (mode); + if ((unit != 4 && unit != 8) || GET_MODE_SIZE (mode) > 16) + return 0; + return unit / UNITS_PER_WORD; +} + +static bool +i860_hard_regno_mode_ok (unsigned int regno, machine_mode mode) +{ + unsigned int nregs = CEIL (GET_MODE_SIZE (mode), UNITS_PER_WORD); + + if (regno == ARG_POINTER_REGNUM || regno == FRAME_POINTER_REGNUM) + return mode == Pmode; + if (GP_REGNO_P (regno)) + return regno + nregs <= 32; + int unit = i860_fp_unit_words (mode); + return (unit != 0 && (regno - 32) % unit == 0 && regno + nregs <= 64); +} + +static bool +i860_modes_tieable_p (machine_mode mode1, machine_mode mode2) +{ + return (mode1 == mode2 || GET_MODE_CLASS (mode1) == GET_MODE_CLASS (mode2)); +} + +static bool +i860_can_change_mode_class (machine_mode from, machine_mode to, + reg_class_t rclass) +{ + if (reg_classes_intersect_p (rclass, FP_REGS) + && GET_MODE_SIZE (from) != GET_MODE_SIZE (to)) + return i860_fp_unit_words (from) && i860_fp_unit_words (to); + return true; +} + +static reg_class_t +i860_preferred_reload_class (rtx x, reg_class_t rclass) +{ + machine_mode mode = GET_MODE (x); + + if (rclass == ALL_REGS + && (CONST_INT_P (x) || mode == QImode || mode == HImode)) + return GENERAL_REGS; + if (CONST_DOUBLE_P (x) && x != CONST0_RTX (mode)) + { + if (rclass == FP_REGS) + return NO_REGS; + if (rclass == ALL_REGS) + return GENERAL_REGS; + } + return rclass; +} + +static int +i860_register_move_cost (machine_mode mode ATTRIBUTE_UNUSED, + reg_class_t from, reg_class_t to) +{ + if ((from == FP_REGS) != (to == FP_REGS)) + return 4; + return 2; +} + +/* Moves. */ + +void +i860_expand_move (machine_mode mode, rtx *operands) +{ + for (int i = 0; i < 2; i++) + if (MEM_P (operands[i]) && i860_tls_address_p (XEXP (operands[i], 0))) + operands[i] + = replace_equiv_address (operands[i], + i860_legitimize_tls_address (XEXP (operands[i], 0))); + if (i860_tls_address_p (operands[1])) + operands[1] = i860_legitimize_tls_address (operands[1]); + + if (flag_pic) + { + for (int i = 0; i < 2; i++) + if (MEM_P (operands[i]) && i860_symbolic_p (XEXP (operands[i], 0))) + operands[i] + = replace_equiv_address (operands[i], + i860_legitimize_pic_address + (XEXP (operands[i], 0), NULL_RTX)); + if (i860_symbolic_p (operands[1])) + operands[1] + = i860_legitimize_pic_address (operands[1], + (can_create_pseudo_p () + || !REG_P (operands[0]) + ? NULL_RTX : operands[0])); + } + if (MEM_P (operands[0]) && !reg_or_0_operand (operands[1], mode)) + operands[1] = force_reg (mode, operands[1]); +} + +static const char * +i860_load_mnemonic (machine_mode mode, rtx reg) +{ + switch (GET_MODE_SIZE (mode)) + { + case 1: + return "ld.b"; + case 2: + return "ld.s"; + case 4: + return FP_REG_P (reg) ? "fld.l" : "ld.l"; + default: + gcc_unreachable (); + } +} + +static const char * +i860_store_mnemonic (machine_mode mode, rtx reg) +{ + switch (GET_MODE_SIZE (mode)) + { + case 1: + return "st.b"; + case 2: + return "st.s"; + case 4: + return FP_REG_P (reg) ? "fst.l" : "st.l"; + default: + gcc_unreachable (); + } +} + +static char i860_template[128]; + +/* Length of a load or store of a register: a constant address takes an + extra orh. */ +int +i860_mem_move_length (rtx *operands) +{ + rtx mem = MEM_P (operands[0]) ? operands[0] : operands[1]; + + return MEM_P (mem) && i860_constant_address_p (XEXP (mem, 0)) ? 8 : 4; +} + +/* Load operands[1] (a MEM) into operands[0]. */ +const char * +i860_output_load (rtx *operands) +{ + rtx mem = operands[1]; + const char *op = i860_load_mnemonic (GET_MODE (mem), operands[0]); + + if (i860_constant_address_p (XEXP (mem, 0))) + { + output_asm_insn ("orh %h1,%?r0,%?r31", operands); + snprintf (i860_template, sizeof i860_template, + "%s %%S1(%%?r31),%%0", op); + } + else + snprintf (i860_template, sizeof i860_template, "%s %%1,%%0", op); + return i860_template; +} + +/* Store operands[1] (a register or zero) into operands[0] (a MEM). */ +const char * +i860_output_store (rtx *operands) +{ + rtx mem = operands[0]; + const char *op = i860_store_mnemonic (GET_MODE (mem), operands[1]); + + if (i860_constant_address_p (XEXP (mem, 0))) + { + output_asm_insn ("orh %h0,%?r0,%?r31", operands); + snprintf (i860_template, sizeof i860_template, + "%s %%r1,%%S0(%%?r31)", op); + } + else + snprintf (i860_template, sizeof i860_template, "%s %%r1,%%0", op); + return i860_template; +} + +/* MEM with an address REG or REG + constant, with REG holding the address + of SYM: return it with the address replaced by the GOT offset form. */ +rtx +i860_gotoff_mem (rtx mem, rtx reg, rtx sym) +{ + rtx addr = XEXP (mem, 0); + HOST_WIDE_INT off = 0; + + if (GET_CODE (addr) == PLUS && CONST_INT_P (XEXP (addr, 1))) + { + off = INTVAL (XEXP (addr, 1)); + addr = XEXP (addr, 0); + } + if (!rtx_equal_p (addr, reg)) + return NULL_RTX; + + rtx pic = gen_rtx_REG (Pmode, I860_PIC_REGNUM); + rtvec vec = gen_rtvec (2, plus_constant (Pmode, sym, off), pic); + + return replace_equiv_address_nv (mem, gen_rtx_UNSPEC (Pmode, vec, + UNSPEC_GOTOFF)); +} + +/* Output a *gotoff_load or *gotoff_store. r31 holds the upper address. */ +const char * +i860_output_gotoff_access (rtx *operands, bool load) +{ + rtx mem = operands[load ? 1 : 0]; + rtx xops[2] = { operands[load ? 0 : 1], XVECEXP (XEXP (mem, 0), 0, 0) }; + + output_asm_insn ("orh [%G1]@gotoff@ha,%?r0,%?r31\n\t" + "addu %?r15,%?r31,%?r31", xops); + if (load) + snprintf (i860_template, sizeof i860_template, + "%s [%%G1]@gotoff@l(%%?r31),%%0", + i860_load_mnemonic (GET_MODE (mem), xops[0])); + else + snprintf (i860_template, sizeof i860_template, + "%s %%r0,[%%G1]@gotoff@l(%%?r31)", + i860_store_mnemonic (GET_MODE (mem), xops[0])); + output_asm_insn (i860_template, xops); + return ""; +} + +/* Load and extend; POST is applied to the loaded register. */ +const char * +i860_output_load_ext (rtx *operands, const char *post) +{ + output_asm_insn (i860_output_load (operands), operands); + return post ? post : ""; +} + +const char * +i860_output_sf_const (rtx *operands) +{ + long l; + + REAL_VALUE_TO_TARGET_SINGLE (*CONST_DOUBLE_REAL_VALUE (operands[1]), l); + operands[2] = gen_int_mode (l, SImode); + if ((l & 0xffff) == 0) + return "orh %H2,%?r0,%0"; + if ((l & 0xffff0000) == 0) + return "or %L2,%?r0,%0"; + return "orh %H2,%?r0,%0\n\tor %L2,%0,%0"; +} + +/* Move the SImode constant SRC into register DST. */ +static void +i860_output_const_word (rtx dst, rtx src) +{ + rtx xops[2] = { dst, src }; + HOST_WIDE_INT v = INTVAL (src); + + if (satisfies_constraint_I (src)) + output_asm_insn ("adds %1,%?r0,%0", xops); + else if (satisfies_constraint_L (src)) + output_asm_insn ("or %L1,%?r0,%0", xops); + else if ((v & 0xffff) == 0) + output_asm_insn ("orh %H1,%?r0,%0", xops); + else + output_asm_insn ("orh %H1,%?r0,%0\n\tor %L1,%0,%0", xops); +} + +/* Put the address of MEM into r31 and return the r31 based MEMs for both + words. */ +static void +i860_r31_address (rtx mem, rtx *lo, rtx *hi) +{ + rtx r31 = gen_rtx_REG (SImode, I860_TEMP_REGNUM); + rtx xops[1] = { XEXP (mem, 0) }; + + output_asm_insn ("orh %H0,%?r0,%?r31\n\tor %L0,%?r31,%?r31", xops); + *lo = gen_rtx_MEM (SImode, r31); + *hi = gen_rtx_MEM (SImode, plus_constant (SImode, r31, 4)); +} + +static void +i860_word_mems (rtx mem, rtx *lo, rtx *hi) +{ + if (i860_constant_address_p (XEXP (mem, 0))) + i860_r31_address (mem, lo, hi); + else + { + *lo = adjust_address_nv (mem, SImode, 0); + *hi = adjust_address_nv (mem, SImode, 4); + } +} + +/* True if fld.d/fst.d can access MEM. */ +static bool +i860_fp_double_aligned_p (rtx mem) +{ + rtx addr = XEXP (mem, 0); + + if (GET_CODE (addr) == PLUS && CONST_INT_P (XEXP (addr, 1)) + && (INTVAL (XEXP (addr, 1)) & 7) != 0) + return false; + return MEM_ALIGN (mem) >= 64; +} + +/* FP register pair to or from memory: fld.d/fst.d when the address is + known to be 8-byte aligned, two word accesses otherwise. */ +static const char * +i860_output_fp_double_mem (rtx reg, rtx mem, bool load) +{ + rtx addr = XEXP (mem, 0); + rtx xops[3]; + + xops[0] = reg; + xops[1] = mem; + if (i860_fp_double_aligned_p (mem)) + { + if (i860_constant_address_p (addr)) + { + output_asm_insn ("orh %h1,%?r0,%?r31", xops); + output_asm_insn (load ? "fld.d %S1(%?r31),%0" : "fst.d %0,%S1(%?r31)", + xops); + } + else + output_asm_insn (load ? "fld.d %1,%0" : "fst.d %0,%1", xops); + return ""; + } + + if (GET_CODE (addr) == PRE_INC || GET_CODE (addr) == PRE_DEC) + { + xops[2] = XEXP (addr, 0); + xops[1] = GEN_INT (GET_CODE (addr) == PRE_INC ? 8 : -8); + output_asm_insn (load ? "fld.l %1(%2)++,%0\n\tfld.l 4(%2),%R0" + : "fst.l %0,%1(%2)++\n\tfst.l %R0,4(%2)", xops); + return ""; + } + + rtx lo, hi; + i860_word_mems (mem, &lo, &hi); + xops[1] = lo; + xops[2] = hi; + output_asm_insn (load ? "fld.l %1,%0\n\tfld.l %2,%R0" + : "fst.l %0,%1\n\tfst.l %R0,%2", xops); + return ""; +} + +/* Exact where it is one instruction, otherwise an upper bound. */ +int +i860_move_double_length (rtx *operands) +{ + rtx dst = operands[0], src = operands[1]; + + /* fmov.dd from a register or f0 */ + if (FP_REG_P (dst) && (FP_REG_P (src) || !(REG_P (src) || MEM_P (src)))) + return 4; + if (FP_REG_P (dst) || FP_REG_P (src)) + { + rtx mem = MEM_P (dst) ? dst : src; + + if (!MEM_P (mem)) + return 8; + if (i860_fp_double_aligned_p (mem) + && !i860_constant_address_p (XEXP (mem, 0))) + return 4; + } + return 16; +} + +const char * +i860_output_move_double (rtx *operands) +{ + rtx dst = operands[0], src = operands[1]; + + if (FP_REG_P (dst)) + { + if (FP_REG_P (src)) + return "fmov.dd %1,%0"; + if (REG_P (src)) + return "ixfr %1,%0\n\tixfr %R1,%R0"; + if (MEM_P (src)) + return i860_output_fp_double_mem (dst, src, true); + return "fmov.dd %?f0,%0"; + } + + if (FP_REG_P (src)) + { + if (REG_P (dst)) + return "fxfr %1,%0\n\tfxfr %R1,%R0"; + return i860_output_fp_double_mem (src, dst, false); + } + + if (REG_P (dst)) + { + rtx dlo = gen_rtx_REG (SImode, REGNO (dst)); + rtx dhi = gen_rtx_REG (SImode, REGNO (dst) + 1); + + if (REG_P (src)) + { + if (REGNO (dst) == REGNO (src) + 1) + return "mov %R1,%R0\n\tmov %1,%0"; + return "mov %1,%0\n\tmov %R1,%R0"; + } + if (MEM_P (src)) + { + rtx lo, hi, xops[4]; + + i860_word_mems (src, &lo, &hi); + xops[0] = dlo; + xops[1] = dhi; + xops[2] = lo; + xops[3] = hi; + if (reg_overlap_mentioned_p (dlo, XEXP (lo, 0))) + output_asm_insn ("ld.l %3,%1\n\tld.l %2,%0", xops); + else + output_asm_insn ("ld.l %2,%0\n\tld.l %3,%1", xops); + return ""; + } + + rtx lo, hi; + split_double (src, &lo, &hi); + i860_output_const_word (dlo, gen_int_mode (INTVAL (lo), SImode)); + i860_output_const_word (dhi, gen_int_mode (INTVAL (hi), SImode)); + return ""; + } + + /* Store of a GPR pair or zero. */ + rtx lo, hi, xops[3]; + i860_word_mems (dst, &lo, &hi); + xops[0] = lo; + xops[1] = hi; + xops[2] = src; + if (REG_P (src)) + output_asm_insn ("st.l %2,%0\n\tst.l %R2,%1", xops); + else + output_asm_insn ("st.l %?r0,%0\n\tst.l %?r0,%1", xops); + return ""; +} + +/* Length of i860_output_logic. */ +int +i860_logic_length (enum rtx_code code, rtx *operands) +{ + if (!CONST_INT_P (operands[2])) + return 4; + + unsigned HOST_WIDE_INT u = UINTVAL (operands[2]) & 0xffffffff; + unsigned HOST_WIDE_INT n = ~u & 0xffffffff; + + if ((u >> 16) == 0 || (u & 0xffff) == 0) + return 4; + if (code == AND && ((n >> 16) == 0 || (n & 0xffff) == 0)) + return 4; + return 8; +} + +/* and/ior/xor with a register or any constant. */ +const char * +i860_output_logic (enum rtx_code code, rtx *operands) +{ + static const char *const ops[3][2] = { + { "and", "andh" }, { "or", "orh" }, { "xor", "xorh" } + }; + int k = code == AND ? 0 : code == IOR ? 1 : 2; + char buf[96]; + + if (!CONST_INT_P (operands[2])) + { + snprintf (i860_template, sizeof i860_template, "%s %%2,%%1,%%0", + ops[k][0]); + return i860_template; + } + + unsigned HOST_WIDE_INT u = UINTVAL (operands[2]) & 0xffffffff; + rtx xops[4] = { operands[0], operands[1], GEN_INT (u & 0xffff), + GEN_INT (u >> 16) }; + + if (code == AND) + { + /* andnot/andnoth clear the bits set in the inverted mask. */ + unsigned HOST_WIDE_INT n = ~u & 0xffffffff; + const char *tmpl; + + if ((u >> 16) == 0) + tmpl = "and %2,%1,%0"; + else if ((u & 0xffff) == 0) + tmpl = "andh %3,%1,%0"; + else + { + xops[2] = GEN_INT (n & 0xffff); + xops[3] = GEN_INT (n >> 16); + if ((n >> 16) == 0) + tmpl = "andnot %2,%1,%0"; + else if ((n & 0xffff) == 0) + tmpl = "andnoth %3,%1,%0"; + else + tmpl = "andnot %2,%1,%0\n\tandnoth %3,%0,%0"; + } + output_asm_insn (tmpl, xops); + return ""; + } + + if ((u >> 16) == 0) + snprintf (buf, sizeof buf, "%s %%2,%%1,%%0", ops[k][0]); + else if ((u & 0xffff) == 0) + snprintf (buf, sizeof buf, "%s %%3,%%1,%%0", ops[k][1]); + else + snprintf (buf, sizeof buf, "%s %%2,%%1,%%0\n\t%s %%3,%%0,%%0", + ops[k][0], ops[k][1]); + output_asm_insn (buf, xops); + return ""; +} + +/* Compare and branch. */ + +bool +i860_cbranch_operand_p (enum rtx_code code, rtx op) +{ + if (!CONST_INT_P (op)) + return register_operand (op, SImode); + if (code == EQ || code == NE) + return satisfies_constraint_L (op); + return satisfies_constraint_I (op); +} + +/* Length of a compare and branch that is not in the bte form. */ +int +i860_cbranch_length (rtx *operands, bool reversed) +{ + enum rtx_code code = GET_CODE (operands[0]); + + if (reversed) + code = reverse_condition (code); + if (CONST_INT_P (operands[2]) && !i860_cbranch_operand_p (code, operands[2])) + return 16; + return 8; +} + +bool +i860_bte_form_p (rtx *operands) +{ + enum rtx_code code = GET_CODE (operands[0]); + + return ((code == EQ || code == NE) + && (REG_P (operands[2]) || satisfies_constraint_K (operands[2]))); +} + +const char * +i860_output_cbranch (rtx_insn *insn, rtx *operands, bool reversed) +{ + enum rtx_code code = GET_CODE (operands[0]); + bool is_const = CONST_INT_P (operands[2]); + bool set; /* branch when CC is set */ + + if (reversed) + code = reverse_condition (code); + + if (i860_bte_form_p (operands) && get_attr_length (insn) == 4) + return code == EQ ? "bte %2,%1,%l3" : "btne %2,%1,%l3"; + + /* Constants the compare cannot encode go through r31 (see the length). */ + if (is_const && !i860_cbranch_operand_p (code, operands[2])) + { + rtx xops[2] = { gen_rtx_REG (SImode, I860_TEMP_REGNUM), operands[2] }; + + output_asm_insn ("orh %H1,%?r0,%0\n\tor %L1,%0,%0", xops); + operands[2] = xops[0]; + is_const = false; + } + + switch (code) + { + case EQ: + case NE: + output_asm_insn ("xor %2,%1,%?r0", operands); + set = code == EQ; + break; + case LT: + case GE: + output_asm_insn (is_const ? "adds %n2,%1,%?r0" : "subs %1,%2,%?r0", + operands); + set = code == LT; + break; + case GT: + case LE: + output_asm_insn ("subs %2,%1,%?r0", operands); + set = code == GT; + break; + case GEU: + case LTU: + if (!is_const) + output_asm_insn ("subu %1,%2,%?r0", operands); + else if (INTVAL (operands[2]) == 0) + output_asm_insn ("subu %1,%?r0,%?r0", operands); + else + output_asm_insn ("addu %n2,%1,%?r0", operands); + set = code == GEU; + break; + case LEU: + case GTU: + output_asm_insn ("subu %2,%1,%?r0", operands); + set = code == LEU; + break; + default: + gcc_unreachable (); + } + return set ? "bc%* %l3" : "bnc%* %l3"; +} + +const char * +i860_output_bit_cbranch (rtx *operands, bool reversed) +{ + enum rtx_code code = GET_CODE (operands[0]); + + if (reversed) + code = reverse_condition (code); + if (CONST_INT_P (operands[2]) && !satisfies_constraint_L (operands[2])) + output_asm_insn ("andh %H2,%1,%?r0", operands); + else + output_asm_insn ("and %2,%1,%?r0", operands); + return code == EQ ? "bc%* %l3" : "bnc%* %l3"; +} + +/* pfgt sets CC if a > b, pfle clears CC if a <= b, pfeq sets CC if + a == b; unordered operands clear the pfgt/pfeq result and set the + pfle one. */ +const char * +i860_output_fp_cbranch (rtx *operands, machine_mode mode, bool reversed) +{ + enum rtx_code code = GET_CODE (operands[0]); + const char *s = mode == SFmode ? "ss" : "dd"; + char buf[160]; + + if (reversed) + code = reverse_condition_maybe_unordered (code); + +#define FCMP(OP, A, B, BR) \ + snprintf (buf, sizeof buf, "pf" OP ".%s %%z" A ",%%z" B ",%%?f0\n\t" \ + BR "%%* %%l3", s) + + switch (code) + { + case EQ: FCMP ("eq", "1", "2", "bc"); break; + case NE: FCMP ("eq", "1", "2", "bnc"); break; + case GT: FCMP ("gt", "1", "2", "bc"); break; + case LT: FCMP ("gt", "2", "1", "bc"); break; + case LE: FCMP ("le", "1", "2", "bnc"); break; + case GE: FCMP ("le", "2", "1", "bnc"); break; + case UNGT: FCMP ("le", "1", "2", "bc"); break; + case UNLT: FCMP ("le", "2", "1", "bc"); break; + case UNLE: FCMP ("gt", "1", "2", "bnc"); break; + case UNGE: FCMP ("gt", "2", "1", "bnc"); break; + case UNORDERED: + snprintf (buf, sizeof buf, "pfeq.%s %%z1,%%z1,%%?f0\n\tbnc %%l3\n\t" + "pfeq.%s %%z2,%%z2,%%?f0\n\tbnc %%l3", s, s); + break; + case ORDERED: + snprintf (buf, sizeof buf, "pfeq.%s %%z1,%%z1,%%?f0\n\tbnc .Lfc%%=\n\t" + "pfeq.%s %%z2,%%z2,%%?f0\n\tbc %%l3\n.Lfc%%=:", s, s); + break; + case LTGT: + snprintf (buf, sizeof buf, "pfgt.%s %%z2,%%z1,%%?f0\n\tbc %%l3\n\t" + "pfgt.%s %%z1,%%z2,%%?f0\n\tbc %%l3", s, s); + break; + case UNEQ: + snprintf (buf, sizeof buf, "pfgt.%s %%z2,%%z1,%%?f0\n\tbc .Lfc%%=\n\t" + "pfgt.%s %%z1,%%z2,%%?f0\n\tbnc %%l3\n.Lfc%%=:", s, s); + break; + default: + gcc_unreachable (); + } +#undef FCMP + output_asm_insn (buf, operands); + return ""; +} + +/* One compare and one branch, as opposed to the two pairs of the codes + a single FP compare cannot express. */ +bool +i860_fp_cbranch_simple_p (rtx *operands, bool reversed) +{ + enum rtx_code code = GET_CODE (operands[0]); + + if (reversed) + code = reverse_condition_maybe_unordered (code); + return !(code == UNORDERED || code == ORDERED || code == LTGT + || code == UNEQ); +} + +/* bla compares as signed, and there is one LCC. */ +static bool +i860_can_use_doloop_p (const widest_int &, const widest_int &iterations_max, + unsigned int loop_depth, bool entered_at_top) +{ + if (loop_depth > 1 || !entered_at_top) + return false; + return iterations_max != 0 && wi::ltu_p (iterations_max, widest_int (0x7ffffff0)); +} + +static bool +i860_predict_doloop_p (class loop *loop) +{ + return !loop->inner && single_exit (loop) && optimize_loop_for_speed_p (loop); +} + +static const char * +i860_invalid_within_doloop (const rtx_insn *insn) +{ + if (CALL_P (insn)) + return "function call in the loop"; + if (tablejump_p (insn, NULL, NULL) || computed_jump_p (insn)) + return "computed branch in the loop"; + if (NONJUMP_INSN_P (insn) + && (GET_CODE (PATTERN (insn)) == ASM_INPUT || asm_noperands (PATTERN (insn)) >= 0)) + return "asm in the loop, it could use bla"; + return NULL; +} + +const char * +i860_output_bla (rtx_insn *insn, rtx *operands, int alternative) +{ + if (alternative == 1) + { + /* the signed test of bla: the count before the add, taken from zero on */ + /* without LCC: on while the count before the add was not negative */ + output_asm_insn ("ld.l %0,%?r31\n\tadds -1,%?r31,%?r31\n\tst.l %?r31,%0\n\t" + "subs -2,%?r31,%?r0\n\tbnc 1f\n\tbr %l1\n\tnop\n1:", operands); + return ""; + } + if (get_attr_length (insn) <= 8) + return "bla %2,%0,%l1%#"; + /* bla comes last for the slot that final prints after this */ + output_asm_insn ("br 2f\n\tnop\n1:\tbr %l1\n\tnop\n2:", operands); + return "bla %2,%0,1b%#"; +} + +/* Taken-branch forms where they cost no code: jumping over one insn, or + moving the only way into the target up. The slot is skipped if not taken, + so the latter only for branches predicted taken. */ +bool +i860_annul_branch_p (rtx_insn *insn) +{ + rtx_insn *label = JUMP_LABEL_AS_INSN (insn); + rtx_insn *next = next_active_insn (insn); + rtx_insn *prev = prev_nonnote_insn (label); + rtx note = find_reg_note (insn, REG_BR_PROB, NULL_RTX); + + if (next && next_active_insn (next) == next_active_insn (label)) + return true; + return (LABEL_NUSES (label) == 1 && prev && BARRIER_P (prev) && note + && (profile_probability::from_reg_br_prob_note (XINT (note, 0)) + >= profile_probability::even ())); +} + +const char * +i860_output_call (rtx *operands, int n) +{ + if (MEM_P (operands[n])) + operands[n] = XEXP (operands[n], 0); + if (REG_P (operands[n])) + return n ? "calli %1%#" : "calli %0%#"; + if (flag_pic && !SYMBOL_REF_LOCAL_P (operands[n])) + return n ? "call %1@plt%#" : "call %0@plt%#"; + return n ? "call %1%#" : "call %0%#"; +} + +/* int -> double: the pair (0x43300000, x ^ 0x80000000) is + 2^52 + 2^31 + x. */ +void +i860_expand_floatsidf (rtx target, rtx src) +{ + rtx lo = gen_reg_rtx (SImode); + rtx hi = force_reg (SImode, gen_int_mode (0x43300000, SImode)); + rtx d = gen_reg_rtx (DFmode); + REAL_VALUE_TYPE r; + + emit_insn (gen_xorsi3 (lo, force_reg (SImode, src), + gen_int_mode (0x80000000, SImode))); + emit_clobber (d); + emit_move_insn (simplify_gen_subreg (SImode, d, DFmode, 0), lo); + emit_move_insn (simplify_gen_subreg (SImode, d, DFmode, 4), hi); + real_from_integer (&r, DFmode, HOST_WIDE_INT_C (0x10000080000000), SIGNED); + rtx magic = force_reg (DFmode, const_double_from_real_value (r, DFmode)); + emit_insn (gen_subdf3 (target, d, magic)); +} + +/* Operand output. + + %? register prefix + %# nop in an unfilled delay slot + %* .t on a conditional branch with a filled delay slot + %r zero as r0 + %z zero as f0 + %R the register following a register (high word of a pair) + %H high 16 bits of a constant, symbol or MEM address + %h high 16 bits adjusted for a following signed low part + %L low 16 bits, unsigned (logical immediates) + %S low 16 bits, signed (displacements) */ + +static void +i860_print_part (FILE *file, rtx x, int code) +{ + if (MEM_P (x)) + x = XEXP (x, 0); + if (CONST_DOUBLE_P (x) && GET_MODE (x) == SFmode) + { + long l; + REAL_VALUE_TO_TARGET_SINGLE (*CONST_DOUBLE_REAL_VALUE (x), l); + x = gen_int_mode (l, SImode); + } + if (CONST_INT_P (x)) + { + unsigned HOST_WIDE_INT v = UINTVAL (x) & 0xffffffff; + switch (code) + { + case 'H': + fprintf (file, "0x%x", (unsigned) (v >> 16)); + break; + case 'h': + fprintf (file, "0x%x", (unsigned) (((v + 0x8000) >> 16) & 0xffff)); + break; + case 'L': + fprintf (file, "0x%x", (unsigned) (v & 0xffff)); + break; + default: + fprintf (file, "%d", (int) ((v & 0xffff) ^ 0x8000) - 0x8000); + break; + } + return; + } + fputc ('[', file); + output_addr_const (file, x); + fprintf (file, "]@%s", code == 'H' ? "h" : code == 'h' ? "ha" : "l"); +} + +static void +i860_print_operand (FILE *file, rtx x, int code) +{ + switch (code) + { + case '?': + fputs (REGISTER_PREFIX, file); + return; + case '#': + if (dbr_sequence_length () == 0) + fputs ("\n\tnop", file); + return; + case '*': + if (dbr_sequence_length () != 0) + fputs (".t", file); + return; + case 'R': + fprintf (file, "%s%s", REGISTER_PREFIX, reg_names[REGNO (x) + 1]); + return; + case 'H': + case 'h': + case 'L': + case 'S': + i860_print_part (file, x, code); + return; + case 'G': + output_addr_const (file, x); + return; + case 'r': + case 'z': + if (x == CONST0_RTX (GET_MODE (x))) + { + fprintf (file, "%s%s", REGISTER_PREFIX, code == 'r' ? "r0" : "f0"); + return; + } + break; + case 0: + break; + default: + output_operand_lossage ("invalid operand code '%c'", code); + return; + } + + if (REG_P (x)) + fprintf (file, "%s%s", REGISTER_PREFIX, reg_names[REGNO (x)]); + else if (MEM_P (x)) + output_address (GET_MODE (x), XEXP (x, 0)); + else if (CONST_DOUBLE_P (x) && GET_MODE (x) == SFmode) + { + long l; + REAL_VALUE_TO_TARGET_SINGLE (*CONST_DOUBLE_REAL_VALUE (x), l); + fprintf (file, "0x%lx", l & 0xffffffffUL); + } + else if (CONST_INT_P (x)) + fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (x)); + else + output_addr_const (file, x); +} + +static void +i860_print_operand_address (FILE *file, machine_mode mode, + rtx addr) +{ + if (REG_P (addr)) + fprintf (file, "0(%s%s)", REGISTER_PREFIX, reg_names[REGNO (addr)]); + else if (GET_CODE (addr) == PRE_INC || GET_CODE (addr) == PRE_DEC) + fprintf (file, "%d(%s%s)++", + GET_CODE (addr) == PRE_INC ? (int) GET_MODE_SIZE (mode) + : -(int) GET_MODE_SIZE (mode), + REGISTER_PREFIX, reg_names[REGNO (XEXP (addr, 0))]); + else if (GET_CODE (addr) == PLUS && REG_P (XEXP (addr, 0)) + && CONST_INT_P (XEXP (addr, 1))) + fprintf (file, HOST_WIDE_INT_PRINT_DEC "(%s%s)", INTVAL (XEXP (addr, 1)), + REGISTER_PREFIX, reg_names[REGNO (XEXP (addr, 0))]); + else if (GET_CODE (addr) == PLUS && REG_P (XEXP (addr, 0)) + && REG_P (XEXP (addr, 1))) + fprintf (file, "%s%s(%s%s)", REGISTER_PREFIX, + reg_names[REGNO (XEXP (addr, 1))], REGISTER_PREFIX, + reg_names[REGNO (XEXP (addr, 0))]); + else + output_addr_const (file, addr); +} + +static bool +i860_print_operand_punct_valid_p (unsigned char code) +{ + return code == '?' || code == '#' || code == '*'; +} + +/* Trampolines. */ + +static void +i860_asm_trampoline_template (FILE *file ATTRIBUTE_UNUSED) +{ + assemble_aligned_integer (UNITS_PER_WORD, GEN_INT (0xec1f0000)); + assemble_aligned_integer (UNITS_PER_WORD, GEN_INT (0xe7ff0000)); + assemble_aligned_integer (UNITS_PER_WORD, GEN_INT (0xec1d0000)); + assemble_aligned_integer (UNITS_PER_WORD, GEN_INT (0x4000f800)); + assemble_aligned_integer (UNITS_PER_WORD, GEN_INT (0xe7bd0000)); +} + +/* Patch the 16-bit immediates: fn high/low at +0/+4, chain high/low + at +8/+16. */ +static void +i860_trampoline_init (rtx m_tramp, tree fndecl, rtx chain) +{ + rtx fn = force_reg (Pmode, XEXP (DECL_RTL (fndecl), 0)); + rtx cxt = force_reg (Pmode, chain); + rtx hi_fn = expand_shift (RSHIFT_EXPR, SImode, fn, 16, NULL_RTX, 1); + rtx hi_cxt = expand_shift (RSHIFT_EXPR, SImode, cxt, 16, NULL_RTX, 1); + + emit_block_move (m_tramp, assemble_trampoline_template (), + GEN_INT (TRAMPOLINE_SIZE), BLOCK_OP_NORMAL); + emit_move_insn (adjust_address (m_tramp, HImode, 0), + gen_lowpart (HImode, hi_fn)); + emit_move_insn (adjust_address (m_tramp, HImode, 4), + gen_lowpart (HImode, fn)); + emit_move_insn (adjust_address (m_tramp, HImode, 8), + gen_lowpart (HImode, hi_cxt)); + emit_move_insn (adjust_address (m_tramp, HImode, 16), + gen_lowpart (HImode, cxt)); + + /* Fetches read memory, and the new code is still in the data cache. */ + rtx addr = force_reg (Pmode, XEXP (m_tramp, 0)); + maybe_emit_call_builtin___clear_cache (addr, + plus_constant (Pmode, addr, + TRAMPOLINE_SIZE)); +} + +/* The target of a sibcall MEM in r28, if not a symbol. */ +rtx +i860_sibcall_mem (rtx mem) +{ + rtx addr = XEXP (mem, 0); + + if (GET_CODE (addr) == SYMBOL_REF) + return mem; + rtx reg = gen_rtx_REG (Pmode, I860_SIBCALL_REGNUM); + emit_move_insn (reg, addr); + return replace_equiv_address (mem, reg); +} + +/* Any call may be a sibcall: the target is a symbol or in r28, and the generic + code checks the stack arguments. An epilogue with an EH stack + adjustment never gets here, tree-tailcall skips __builtin_eh_return users. */ +static bool +i860_function_ok_for_sibcall (tree decl ATTRIBUTE_UNUSED, + tree exp ATTRIBUTE_UNUSED) +{ + return true; +} + +/* Costs. */ + +static bool +i860_rtx_costs (rtx x, machine_mode mode, int outer_code ATTRIBUTE_UNUSED, + int opno ATTRIBUTE_UNUSED, int *total, + bool speed ATTRIBUTE_UNUSED) +{ + switch (GET_CODE (x)) + { + case CONST_INT: + if (satisfies_constraint_I (x) || satisfies_constraint_L (x) + || satisfies_constraint_M (x)) + *total = 0; + else + *total = COSTS_N_INSNS (1); + return true; + case CONST: + case LABEL_REF: + case SYMBOL_REF: + *total = COSTS_N_INSNS (2); + return true; + case CONST_DOUBLE: + *total = x == CONST0_RTX (mode) ? 0 : COSTS_N_INSNS (3); + return true; + case MULT: + if (mode == SImode) + { + *total = COSTS_N_INSNS (5); + return false; + } + *total = COSTS_N_INSNS (2); + return false; + case DIV: + if (FLOAT_MODE_P (mode)) + { + *total = COSTS_N_INSNS (mode == SFmode ? 10 : 14); + return false; + } + return false; + default: + return false; + } +} + +/* Reserve the thread pointer register where the OS ABI has one. */ +static void +i860_conditional_register_usage (void) +{ + /* r3 is free where a function does not need it, not in the SVR4 ABI */ + if (I860_SVR4_FUNCTION_PREFIX) + fixed_regs[HARD_FRAME_POINTER_REGNUM] = 1; +#ifdef I860_THREAD_POINTER_REGNUM + fixed_regs[I860_THREAD_POINTER_REGNUM] = 1; + call_used_regs[I860_THREAD_POINTER_REGNUM] = 1; +#endif + if (flag_pic) + { + fixed_regs[I860_PIC_REGNUM] = 1; + call_used_regs[I860_PIC_REGNUM] = 0; + } +} + +static void +i860_option_override (void) +{ +#ifndef I860_PIC_SUPPORTED + if (flag_pic) + { + sorry ("position-independent code is not supported for this i860 target"); + flag_pic = 0; + } +#endif +} + +static void +i860_init_libfuncs (void) +{ +#ifdef I860_SVR4_DIVMOD_NAMES + /* The SVR4 libc division helpers. */ + set_optab_libfunc (sdiv_optab, SImode, "*.div"); + set_optab_libfunc (udiv_optab, SImode, "*.udiv"); + set_optab_libfunc (smod_optab, SImode, "*.rem"); + set_optab_libfunc (umod_optab, SImode, "*.urem"); +#endif +} + +#undef TARGET_CONDITIONAL_REGISTER_USAGE +#define TARGET_CONDITIONAL_REGISTER_USAGE i860_conditional_register_usage +#undef TARGET_PREDICT_DOLOOP_P +#define TARGET_PREDICT_DOLOOP_P i860_predict_doloop_p +#undef TARGET_CAN_USE_DOLOOP_P +#define TARGET_CAN_USE_DOLOOP_P i860_can_use_doloop_p +#undef TARGET_INVALID_WITHIN_DOLOOP +#define TARGET_INVALID_WITHIN_DOLOOP i860_invalid_within_doloop + +#undef TARGET_OPTION_OVERRIDE +#define TARGET_OPTION_OVERRIDE i860_option_override +#undef TARGET_INIT_LIBFUNCS +#define TARGET_INIT_LIBFUNCS i860_init_libfuncs + +#undef TARGET_RTX_COSTS +#define TARGET_RTX_COSTS i860_rtx_costs +#undef TARGET_REGISTER_MOVE_COST +#define TARGET_REGISTER_MOVE_COST i860_register_move_cost + +#undef TARGET_ASM_FUNCTION_END_PROLOGUE +#define TARGET_ASM_FUNCTION_END_PROLOGUE i860_function_end_prologue +#undef TARGET_ASM_ALIGNED_DI_OP +#define TARGET_ASM_ALIGNED_DI_OP "\t.quad\t" + +#undef TARGET_FRAME_POINTER_REQUIRED +#define TARGET_FRAME_POINTER_REQUIRED i860_frame_pointer_required +#undef TARGET_CAN_ELIMINATE +#define TARGET_CAN_ELIMINATE i860_can_eliminate + +#undef TARGET_FUNCTION_OK_FOR_SIBCALL +#define TARGET_FUNCTION_OK_FOR_SIBCALL i860_function_ok_for_sibcall +#undef TARGET_FUNCTION_ARG +#define TARGET_FUNCTION_ARG i860_function_arg +#undef TARGET_FUNCTION_ARG_ADVANCE +#define TARGET_FUNCTION_ARG_ADVANCE i860_function_arg_advance +#undef TARGET_FUNCTION_ARG_BOUNDARY +#define TARGET_FUNCTION_ARG_BOUNDARY i860_function_arg_boundary +#undef TARGET_FUNCTION_VALUE +#define TARGET_FUNCTION_VALUE i860_function_value +#undef TARGET_LIBCALL_VALUE +#define TARGET_LIBCALL_VALUE i860_libcall_value +#undef TARGET_FUNCTION_VALUE_REGNO_P +#define TARGET_FUNCTION_VALUE_REGNO_P i860_function_value_regno_p +#undef TARGET_STRUCT_VALUE_RTX +#define TARGET_STRUCT_VALUE_RTX i860_struct_value_rtx + +#undef TARGET_SETUP_INCOMING_VARARGS +#define TARGET_SETUP_INCOMING_VARARGS i860_setup_incoming_varargs +#undef TARGET_BUILD_BUILTIN_VA_LIST +#define TARGET_BUILD_BUILTIN_VA_LIST i860_build_builtin_va_list +#undef TARGET_EXPAND_BUILTIN_VA_START +#define TARGET_EXPAND_BUILTIN_VA_START i860_va_start +#undef TARGET_GIMPLIFY_VA_ARG_EXPR +#define TARGET_GIMPLIFY_VA_ARG_EXPR i860_gimplify_va_arg_expr + +#undef TARGET_LEGITIMATE_ADDRESS_P +#define TARGET_LEGITIMATE_ADDRESS_P i860_legitimate_address_p +#undef TARGET_LEGITIMIZE_ADDRESS +#define TARGET_LEGITIMIZE_ADDRESS i860_legitimize_address +#ifdef I860_THREAD_POINTER_REGNUM +#undef TARGET_HAVE_TLS +#define TARGET_HAVE_TLS true +#endif + +#undef TARGET_LEGITIMATE_CONSTANT_P +#define TARGET_LEGITIMATE_CONSTANT_P i860_legitimate_constant_p +#undef TARGET_CANNOT_FORCE_CONST_MEM +#define TARGET_CANNOT_FORCE_CONST_MEM i860_cannot_force_const_mem + +#undef TARGET_HARD_REGNO_MODE_OK +#define TARGET_HARD_REGNO_MODE_OK i860_hard_regno_mode_ok +#undef TARGET_MODES_TIEABLE_P +#define TARGET_MODES_TIEABLE_P i860_modes_tieable_p +#undef TARGET_CAN_CHANGE_MODE_CLASS +#define TARGET_CAN_CHANGE_MODE_CLASS i860_can_change_mode_class +#undef TARGET_PREFERRED_RELOAD_CLASS +#define TARGET_PREFERRED_RELOAD_CLASS i860_preferred_reload_class + +#undef TARGET_PRINT_OPERAND +#define TARGET_PRINT_OPERAND i860_print_operand +#undef TARGET_PRINT_OPERAND_ADDRESS +#define TARGET_PRINT_OPERAND_ADDRESS i860_print_operand_address +#undef TARGET_PRINT_OPERAND_PUNCT_VALID_P +#define TARGET_PRINT_OPERAND_PUNCT_VALID_P i860_print_operand_punct_valid_p + +#undef TARGET_ASM_TRAMPOLINE_TEMPLATE +#define TARGET_ASM_TRAMPOLINE_TEMPLATE i860_asm_trampoline_template +#undef TARGET_TRAMPOLINE_INIT +#define TARGET_TRAMPOLINE_INIT i860_trampoline_init + +struct gcc_target targetm = TARGET_INITIALIZER; diff --git a/gcc/config/i860/i860.h b/gcc/config/i860/i860.h new file mode 100644 index 00000000000..d49c417781b --- /dev/null +++ b/gcc/config/i860/i860.h @@ -0,0 +1,288 @@ +/* Definitions of target machine for GNU compiler, for Intel 860. + Copyright (C) 1989-2005, 2026 Free Software Foundation, Inc. + Copyright (C) 2026 René Rebe + Hacked substantially by Ron Guilmette (rfg@monkeys.com) to cater to + the whims of the System V Release 4 assembler. + +This file is part of GCC. + +GCC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 3, or (at your option) +any later version. + +GCC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GCC; see the file COPYING3. If not see +. */ + +#ifndef GCC_I860_H +#define GCC_I860_H + +#define TARGET_CPU_CPP_BUILTINS() \ + do \ + { \ + builtin_define_std ("i860"); \ + builtin_define ("__i860__"); \ + builtin_define ("__LITTLE_ENDIAN__"); \ + builtin_assert ("cpu=i860"); \ + builtin_assert ("machine=i860"); \ + if (TARGET_XP) \ + builtin_define ("__i860XP__"); \ + } \ + while (0) + +/* Storage layout. The i860 is used little-endian only. */ +#define BITS_BIG_ENDIAN 0 +#define BYTES_BIG_ENDIAN 0 +#define WORDS_BIG_ENDIAN 0 + +#define UNITS_PER_WORD 4 +#define PARM_BOUNDARY 32 +/* The SVR4 i860 ABI keeps sp and fp 16-byte aligned. */ +#define STACK_BOUNDARY 128 +#define FUNCTION_BOUNDARY 64 +#define EMPTY_FIELD_BOUNDARY 32 +#define STRUCTURE_SIZE_BOUNDARY 8 +#define BIGGEST_ALIGNMENT 128 +#define STRICT_ALIGNMENT 1 +#define PCC_BITFIELD_TYPE_MATTERS 1 + +#define DEFAULT_SIGNED_CHAR 1 +#define SIZE_TYPE "unsigned int" +#define PTRDIFF_TYPE "int" +#define WCHAR_TYPE "long int" +#define WCHAR_TYPE_SIZE 32 + +/* Registers. 0-31 are the integer registers, 32-63 the floating point + registers; 64 and 65 are the eliminated argument and frame pointers. + r0 and f0/f1 always read as zero, r1 holds the return address, r31 is + reserved as assembler temporary for constant addresses. */ +#define FIRST_PSEUDO_REGISTER 66 + +#define FIXED_REGISTERS \ + {1, 1, 1, 1, 0, 0, 0, 0, \ + 0, 0, 0, 0, 0, 0, 0, 0, \ + 0, 0, 0, 0, 0, 0, 0, 0, \ + 0, 0, 0, 0, 0, 0, 0, 1, \ + 1, 1, 0, 0, 0, 0, 0, 0, \ + 0, 0, 0, 0, 0, 0, 0, 0, \ + 0, 0, 0, 0, 0, 0, 0, 0, \ + 0, 0, 0, 0, 0, 0, 0, 0, \ + 1, 1} + +/* r4-r15 and f2-f7 are preserved across calls. */ +#define CALL_USED_REGISTERS \ + {1, 1, 1, 0, 0, 0, 0, 0, \ + 0, 0, 0, 0, 0, 0, 0, 0, \ + 1, 1, 1, 1, 1, 1, 1, 1, \ + 1, 1, 1, 1, 1, 1, 1, 1, \ + 1, 1, 0, 0, 0, 0, 0, 0, \ + 1, 1, 1, 1, 1, 1, 1, 1, \ + 1, 1, 1, 1, 1, 1, 1, 1, \ + 1, 1, 1, 1, 1, 1, 1, 1, \ + 1, 1} + +#define REG_ALLOC_ORDER \ + {30, 29, 28, 27, 26, 25, 24, 23, \ + 22, 21, 20, 19, 18, 17, 16, 15, \ + 14, 13, 12, 11, 10, 9, 8, 7, \ + 6, 5, 4, 3, \ + 63, 62, 61, 60, 59, 58, 57, 56, \ + 55, 54, 53, 52, 51, 50, 49, 48, \ + 47, 46, 45, 44, 43, 42, 41, 40, \ + 39, 38, 37, 36, 35, 34, \ + 31, 2, 1, 0, 32, 33, 64, 65} + +#define STACK_POINTER_REGNUM 2 +/* fld.y and fst.y with "size(reg)++". */ +#define HAVE_PRE_INCREMENT 1 +#define HAVE_PRE_DECREMENT 1 +#define USE_LOAD_PRE_INCREMENT(MODE) ((MODE) == SFmode || (MODE) == DFmode) +#define USE_LOAD_PRE_DECREMENT(MODE) ((MODE) == SFmode || (MODE) == DFmode) +#define USE_STORE_PRE_INCREMENT(MODE) ((MODE) == SFmode || (MODE) == DFmode) +#define USE_STORE_PRE_DECREMENT(MODE) ((MODE) == SFmode || (MODE) == DFmode) + +#define HARD_FRAME_POINTER_REGNUM 3 +#define ARG_POINTER_REGNUM 64 +#define FRAME_POINTER_REGNUM 65 +#define STATIC_CHAIN_REGNUM 29 + +/* r15 points at _GLOBAL_OFFSET_TABLE_ in functions that need it; callers + do not rely on it, so calls through the PLT do not load it. */ +#define I860_PIC_REGNUM 15 +#define PIC_OFFSET_TABLE_REGNUM (flag_pic ? I860_PIC_REGNUM : INVALID_REGNUM) +#define LEGITIMATE_PIC_OPERAND_P(X) (!i860_symbolic_p (X)) + +/* A table in .text of label differences needs no relocation. */ +#define CASE_VECTOR_PC_RELATIVE flag_pic +#define JUMP_TABLES_IN_TEXT_SECTION flag_pic +#define I860_RETURN_REGNUM 1 +/* Holds an indirect sibcall target: no argument, not the static chain or the + sp in r31, not restored by the epilogue. A PLT entry clobbers it after the + jump. */ +#define I860_SIBCALL_REGNUM 28 +#define I860_TEMP_REGNUM 31 +#define I860_STRUCT_VALUE_REGNUM 16 +#define F0_REGNUM 32 +#define I860_FIRST_INT_ARG 16 +#define I860_FIRST_FP_ARG 40 +#define I860_NUM_INT_ARGS 12 +#define I860_NUM_FP_ARGS 8 + +/* Where 64-bit integer arguments go: FP register pairs (the old SVR4 + port), or consecutive integer registers (Linux, as in its syscall ABI). */ +#ifndef I860_DIMODE_ARGS_IN_GPRS +#define I860_DIMODE_ARGS_IN_GPRS 0 +#endif + +#define GP_REGNO_P(N) ((unsigned) (N) < 32) +#define FP_REGNO_P(N) ((unsigned) ((N) - 32) < 32) +#define FP_REG_P(X) (REG_P (X) && FP_REGNO_P (REGNO (X))) + +enum reg_class { NO_REGS, GENERAL_REGS, FP_REGS, ALL_REGS, LIM_REG_CLASSES }; + +#define N_REG_CLASSES (int) LIM_REG_CLASSES +#define REG_CLASS_NAMES { "NO_REGS", "GENERAL_REGS", "FP_REGS", "ALL_REGS" } +#define REG_CLASS_CONTENTS \ + { { 0x00000000, 0x00000000, 0x0 }, \ + { 0xffffffff, 0x00000000, 0x3 }, \ + { 0x00000000, 0xffffffff, 0x0 }, \ + { 0xffffffff, 0xffffffff, 0x3 } } + +#define REGNO_REG_CLASS(N) (FP_REGNO_P (N) ? FP_REGS : GENERAL_REGS) + +#define BASE_REG_CLASS GENERAL_REGS +/* Indexed addresses are only valid for loads, see indexed_memory_operand; + the index class lets LRA keep them for the "Q" constraint. */ +#define INDEX_REG_CLASS GENERAL_REGS +#define I860_BASE_HARD_REGNO_P(N) \ + ((N) < 32 || (N) == ARG_POINTER_REGNUM || (N) == FRAME_POINTER_REGNUM) +#define REGNO_OK_FOR_BASE_P(N) \ + (I860_BASE_HARD_REGNO_P (N) \ + || (reg_renumber && (unsigned) reg_renumber[N] < 32)) +#define REGNO_OK_FOR_INDEX_P(N) REGNO_OK_FOR_BASE_P (N) + +#define MAX_REGS_PER_ADDRESS 2 + +/* Frame layout, see i860_compute_frame for the details. */ +#define STACK_GROWS_DOWNWARD 1 +#define FRAME_GROWS_DOWNWARD 1 +#define FIRST_PARM_OFFSET(FNDECL) 0 +#define ACCUMULATE_OUTGOING_ARGS 1 +#define EXIT_IGNORE_STACK 1 +/* A sibcall passes on the return address the epilogue restored. */ +#define EPILOGUE_USES(REGNO) (epilogue_completed && (REGNO) == I860_RETURN_REGNUM) + +#define ELIMINABLE_REGS \ + { { ARG_POINTER_REGNUM, STACK_POINTER_REGNUM }, \ + { ARG_POINTER_REGNUM, HARD_FRAME_POINTER_REGNUM }, \ + { FRAME_POINTER_REGNUM, STACK_POINTER_REGNUM }, \ + { FRAME_POINTER_REGNUM, HARD_FRAME_POINTER_REGNUM } } + +#define INITIAL_ELIMINATION_OFFSET(FROM, TO, OFFSET) \ + ((OFFSET) = i860_initial_elimination_offset ((FROM), (TO))) + +#define INCOMING_RETURN_ADDR_RTX gen_rtx_REG (Pmode, I860_RETURN_REGNUM) +#define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGNUM (I860_RETURN_REGNUM) +#define RETURN_ADDR_RTX(COUNT, FRAME) i860_return_addr_rtx ((COUNT), (FRAME)) + +/* Exception data registers must not overlap the r16 return value. */ +#define EH_RETURN_DATA_REGNO(N) ((N) < 4 ? (N) + 20 : INVALID_REGNUM) +#define EH_RETURN_STACKADJ_RTX gen_rtx_REG (Pmode, 28) +#define EH_RETURN_HANDLER_RTX i860_eh_return_handler_rtx () + +/* Argument passing: the first 12 integer words go in r16-r27, the first + 8 floating point words (and long long) in f8-f15, aggregates on the + stack. */ +struct i860_args { int ints, floats; }; +#define CUMULATIVE_ARGS struct i860_args +#define INIT_CUMULATIVE_ARGS(CUM, FNTYPE, LIBNAME, INDIRECT, N_NAMED_ARGS) \ + i860_init_cumulative_args (&(CUM), (FNTYPE)) + +#define FUNCTION_ARG_REGNO_P(N) \ + (((N) >= I860_FIRST_INT_ARG && (N) < I860_FIRST_INT_ARG + I860_NUM_INT_ARGS) \ + || ((N) >= I860_FIRST_FP_ARG && (N) < I860_FIRST_FP_ARG + I860_NUM_FP_ARGS)) + +#define DEFAULT_PCC_STRUCT_RETURN 1 + +#define FUNCTION_PROFILER(FILE, LABELNO) \ + fprintf ((FILE), "\tcall\tmcount\n\tnop\n") + +/* orh hi(fn),r0,r31; or lo(fn),r31,r31; orh hi(cxt),r0,r29; + bri r31; or lo(cxt),r29,r29 */ +#define TRAMPOLINE_SIZE 20 +#define TRAMPOLINE_ALIGNMENT 64 + +#define Pmode SImode +#define FUNCTION_MODE SImode +#define CASE_VECTOR_MODE SImode +#define MOVE_MAX 4 +#define SLOW_BYTE_ACCESS 0 +#define LOAD_EXTEND_OP(MODE) \ + (((MODE) == QImode || (MODE) == HImode) ? SIGN_EXTEND : UNKNOWN) +#define NO_FUNCTION_CSE 1 +#define BRANCH_COST(SPEED_P, PREDICTABLE_P) 3 + +/* Assembler output, AT&T/SVR4 syntax as used by the native assembler and + GNU as. */ +#define ASM_COMMENT_START "#" +#define ASM_APP_ON "" +#define ASM_APP_OFF "" +#define TEXT_SECTION_ASM_OP "\t.text" +#define DATA_SECTION_ASM_OP "\t.data" +#undef GLOBAL_ASM_OP +#define GLOBAL_ASM_OP "\t.globl\t" +#undef ASM_DOUBLE +#define ASM_DOUBLE "\t.double" + +#define REGISTER_NAMES \ +{"r0", "r1", "sp", "fp", "r4", "r5", "r6", "r7", "r8", "r9", \ + "r10", "r11", "r12", "r13", "r14", "r15", "r16", "r17", "r18", "r19", \ + "r20", "r21", "r22", "r23", "r24", "r25", "r26", "r27", "r28", "r29", \ + "r30", "r31", \ + "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7", "f8", "f9", \ + "f10", "f11", "f12", "f13", "f14", "f15", "f16", "f17", "f18", "f19", \ + "f20", "f21", "f22", "f23", "f24", "f25", "f26", "f27", "f28", "f29", \ + "f30", "f31", "ap", "sfp" } + +#define ADDITIONAL_REGISTER_NAMES { { "r2", 2 }, { "r3", 3 } } + +#define REGISTER_PREFIX "%" + +/* .align takes a byte count. */ +#define ASM_OUTPUT_ALIGN(FILE, LOG) \ + do \ + { \ + if ((LOG) != 0) \ + fprintf ((FILE), "\t.align\t%d\n", 1 << (LOG)); \ + } \ + while (0) + +#define ASM_OUTPUT_ADDR_VEC_ELT(FILE, VALUE) \ + fprintf ((FILE), "\t.long\t.L%d\n", (VALUE)) +#define ASM_OUTPUT_ADDR_DIFF_ELT(FILE, BODY, VALUE, REL) \ + fprintf ((FILE), "\t.long\t.L%d-.L%d\n", (VALUE), (REL)) + +/* Each function is preceded by a word looking like a nop + (shr r0,r0,r0 + prologue length) followed by a real nop, as emitted by + the native compilers: trap handlers inspect the instruction before the + entry point for delayed branches, and the SVR4 debugger reads the + prologue length. */ +#undef ASM_DECLARE_FUNCTION_NAME +#define ASM_DECLARE_FUNCTION_NAME(FILE, NAME, DECL) \ + do \ + { \ + ASM_OUTPUT_TYPE_DIRECTIVE (FILE, NAME, "function"); \ + ASM_DECLARE_RESULT (FILE, DECL_RESULT (DECL)); \ + if (I860_SVR4_FUNCTION_PREFIX) \ + i860_output_function_prefix (FILE, NAME); \ + ASM_OUTPUT_FUNCTION_LABEL (FILE, NAME, DECL); \ + } \ + while (0) + +#endif /* GCC_I860_H */ diff --git a/gcc/config/i860/i860.md b/gcc/config/i860/i860.md new file mode 100644 index 00000000000..9108fb5a6d2 --- /dev/null +++ b/gcc/config/i860/i860.md @@ -0,0 +1,1271 @@ +;; GCC machine description for the Intel i860 microprocessor +;; Copyright (C) 1989-2005, 2026 Free Software Foundation, Inc. +;; Copyright (C) 2026 René Rebe + +;; This file is part of GCC. + +;; GCC is free software; you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation; either version 3, or (at your option) +;; any later version. + +;; GCC is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with GCC; see the file COPYING3. If not see +;; . + +;; The i860 has a single condition code bit (PSR.CC), set by compares, +;; add/subtract and all logical instructions. It is not modelled as a +;; register: every insn that tests it also emits the instruction setting +;; it, so the bit is never live between insns. r31 is likewise only used +;; as a scratch register inside the output of a single insn. + +(define_constants + [(R0_REGNUM 0) + (R1_REGNUM 1) + (SP_REGNUM 2) + (FP_REGNUM 3) + (PIC_REGNUM 15) + (SIBCALL_REGNUM 28) + (R31_REGNUM 31) + (F0_REGNUM 32)]) + +(define_c_enum "unspec" [ + UNSPEC_FMLOW + UNSPEC_FTRUNC + UNSPEC_GOT + UNSPEC_GOTOFF + UNSPEC_TLS_GD + UNSPEC_TLS_IE + UNSPEC_TLS_IE_ABS + UNSPEC_TLS_LE +]) + +(define_c_enum "unspecv" [ + UNSPECV_BLOCKAGE + UNSPECV_SET_GOT + UNSPECV_CAS + UNSPECV_BLA_PRIME + UNSPECV_PFADD + UNSPECV_PFSUB + UNSPECV_PFMUL + UNSPECV_DUAL_KERNEL + UNSPECV_DUAL_BLA + UNSPECV_PFLD +]) + +;; Length 4 means exactly one machine instruction, as delay slots require. +;; Everything else is an upper bound: only bte/btne need branch distances. +(define_attr "type" + "move,load,store,alu,fpu,branch,cbranch,bla,call,return,nop,trap,multi" + (const_string "multi")) + +;; For the scheduler, see i860_sched_class. Independent of the alternatives, as these do not +;; yet decide anything before register allocation. +(define_attr "sclass" "alu,iload,fload,store,fadd,fmuls,fmuld,fpmisc,long,branch" + (symbol_ref "(enum attr_sclass) i860_sched_class (insn)")) + +;; No manual is at hand. The load latencies follow the distances to the first use in the SVR4 +;; libraries (tmp/gcc/perf/latency.py), the FP ones are from memory: unverified, as long as +;; they are, they can only cost speed, not correctness. Scalar FP blocks its unit. +(define_automaton "i860") +(define_cpu_unit "i860_issue,i860_fadd,i860_fmul" "i860") + +(define_insn_reservation "i860_alu" 1 (eq_attr "sclass" "alu,branch,store") "i860_issue") +(define_insn_reservation "i860_iload" 2 (eq_attr "sclass" "iload") "i860_issue") +(define_insn_reservation "i860_fload" 3 (eq_attr "sclass" "fload") "i860_issue") +(define_insn_reservation "i860_fpmisc" 2 (eq_attr "sclass" "fpmisc") "i860_issue") +(define_insn_reservation "i860_fadd" 3 (eq_attr "sclass" "fadd") + "i860_issue+i860_fadd,i860_fadd*2") +(define_insn_reservation "i860_fmuls" 3 (eq_attr "sclass" "fmuls") + "i860_issue+i860_fmul,i860_fmul*2") +(define_insn_reservation "i860_fmuld" 4 (eq_attr "sclass" "fmuld") + "i860_issue+i860_fmul,i860_fmul*3") +;; Division is a Newton-Raphson sequence in one insn. +(define_insn_reservation "i860_long" 24 (eq_attr "sclass" "long") + "i860_issue+i860_fmul+i860_fadd,(i860_fmul+i860_fadd)*23") + +(define_attr "length" "" + (cond [(eq_attr "type" "load,store") + (symbol_ref "i860_mem_move_length (operands)") + (eq_attr "type" "move,alu,fpu,nop,trap") + (const_int 4)] + (const_int 16))) + +;; After a fault in the slot the kernel resumes at the branch, so the slot +;; must not write what the branch reads: reorg sees that in the RTL of the +;; branch. r1 is clobbered by the call patterns, which keeps it out too. +(define_attr "in_delay_slot" "no,yes" + (if_then_else (and (eq_attr "type" "move,load,store,alu,fpu") + (match_test "get_attr_length (insn) == 4")) + (const_string "yes") + (const_string "no"))) + +(define_delay (eq_attr "type" "branch,call,bla") + [(eq_attr "in_delay_slot" "yes") (nil) (nil)]) + +;; bc.t and bnc.t run the slot only if taken, and bte/btne have no such form. +(define_delay (and (eq_attr "type" "cbranch") + (match_test "i860_annul_branch_p (insn)")) + [(nil) (nil) (eq_attr "in_delay_slot" "yes")]) + +(include "predicates.md") +(include "constraints.md") + +(define_mode_iterator MOVE [QI HI SI SF DI DF]) +(define_mode_iterator FMODE [SF DF]) +(define_mode_iterator SISF [SI SF]) +(define_mode_iterator DIDF [DI DF]) +(define_mode_attr fldsfx [(SF "l") (DF "d")]) +(define_mode_attr fsfx [(SF "ss") (DF "dd")]) +(define_mode_attr ftrunc [(SF "sd") (DF "dd")]) + +;; ------------------------------------------------------------------------ +;; Moves +;; ------------------------------------------------------------------------ + +(define_expand "mov" + [(set (match_operand:MOVE 0 "nonimmediate_operand") + (match_operand:MOVE 1 "general_operand"))] + "" +{ + i860_expand_move (mode, operands); +}) + +(define_insn "*movqi_insn" + [(set (match_operand:QI 0 "nonimmediate_operand" "=r,r,r,m") + (match_operand:QI 1 "general_operand" " r,n,m,rJ"))] + "register_operand (operands[0], QImode) + || reg_or_0_operand (operands[1], QImode)" + "@ + mov %1,%0 + or %L1,%?r0,%0 + * return i860_output_load (operands); + * return i860_output_store (operands);" + [(set_attr "type" "move,alu,load,store")]) + +(define_insn "*movhi_insn" + [(set (match_operand:HI 0 "nonimmediate_operand" "=r,r,r,m") + (match_operand:HI 1 "general_operand" " r,n,m,rJ"))] + "register_operand (operands[0], HImode) + || reg_or_0_operand (operands[1], HImode)" + "@ + mov %1,%0 + or %L1,%?r0,%0 + * return i860_output_load (operands); + * return i860_output_store (operands);" + [(set_attr "type" "move,alu,load,store")]) + +(define_insn "*movsi_insn" + [(set (match_operand:SI 0 "nonimmediate_operand" + "=r,r,r,r,r,r,m, f,f,r,f,m,f") + (match_operand:SI 1 "general_operand" + " r,I,L,M,i,m,rJ,f,r,f,m,f,J"))] + "register_operand (operands[0], SImode) + || reg_or_0_operand (operands[1], SImode)" + "@ + mov %1,%0 + adds %1,%?r0,%0 + or %L1,%?r0,%0 + orh %H1,%?r0,%0 + orh %H1,%?r0,%0\;or %L1,%0,%0 + * return i860_output_load (operands); + * return i860_output_store (operands); + fmov.ss %1,%0 + ixfr %1,%0 + fxfr %1,%0 + * return i860_output_load (operands); + * return i860_output_store (operands); + fmov.ss %?f0,%0" + [(set_attr "type" + "move,alu,alu,alu,multi,load,store,move,move,move,load,store,move")]) + +(define_insn "*movsf_insn" + [(set (match_operand:SF 0 "nonimmediate_operand" + "=r,r,r,r,o, f,f,r,f,m,f") + (match_operand:SF 1 "general_operand" + " r,G,F,o,rG,f,r,f,m,f,G"))] + "register_operand (operands[0], SFmode) + || reg_or_0_operand (operands[1], SFmode)" + "@ + mov %1,%0 + mov %?r0,%0 + * return i860_output_sf_const (operands); + * return i860_output_load (operands); + * return i860_output_store (operands); + fmov.ss %1,%0 + ixfr %1,%0 + fxfr %1,%0 + * return i860_output_load (operands); + * return i860_output_store (operands); + fmov.ss %?f0,%0" + [(set_attr "type" + "move,move,multi,load,store,move,move,move,load,store,move")]) + +(define_insn "*movdi_insn" + [(set (match_operand:DI 0 "nonimmediate_operand" "=r,r,r,m, f,f,r,f,m,f") + (match_operand:DI 1 "general_operand" " r,i,m,rJ,f,r,f,m,f,J"))] + "register_operand (operands[0], DImode) + || reg_or_0_operand (operands[1], DImode)" + "* return i860_output_move_double (operands);" + [(set_attr "type" "move") + (set (attr "length") (symbol_ref "i860_move_double_length (operands)"))]) + +(define_insn "*movdf_insn" + [(set (match_operand:DF 0 "nonimmediate_operand" "=r,r,r,o, f,f,r,f,m,f") + (match_operand:DF 1 "general_operand" " r,F,o,rG,f,r,f,m,f,G"))] + "register_operand (operands[0], DFmode) + || reg_or_0_operand (operands[1], DFmode)" + "* return i860_output_move_double (operands);" + [(set_attr "type" "move") + (set (attr "length") (symbol_ref "i860_move_double_length (operands)"))]) + +;; Loads with reg+reg addresses, made by combine. Integer stores have no +;; such addressing mode, so these addresses are not legitimate in general. + +(define_insn "*load_indexed_qi" + [(set (match_operand:QI 0 "register_operand" "=r") + (match_operand:QI 1 "indexed_memory_operand" "Q"))] + "" + "ld.b %1,%0" + [(set_attr "type" "load")]) + +(define_insn "*load_indexed_hi" + [(set (match_operand:HI 0 "register_operand" "=r") + (match_operand:HI 1 "indexed_memory_operand" "Q"))] + "" + "ld.s %1,%0" + [(set_attr "type" "load")]) + +(define_insn "*load_indexed_" + [(set (match_operand:SISF 0 "register_operand" "=r,f") + (match_operand:SISF 1 "indexed_memory_operand" "Q,Q"))] + "" + "@ + ld.l %1,%0 + fld.l %1,%0" + [(set_attr "type" "load")]) + +(define_insn "*load_indexed__d" + [(set (match_operand:DIDF 0 "register_operand" "=f") + (match_operand:DIDF 1 "indexed_memory_operand" "Q"))] + "i860_mem_aligned8_p (operands[1])" + "fld.d %1,%0" + [(set_attr "type" "load")]) + +(define_insn "*store_indexed_" + [(set (match_operand:SISF 0 "indexed_memory_operand" "=Q") + (match_operand:SISF 1 "register_operand" "f"))] + "" + "fst.l %1,%0" + [(set_attr "type" "store")]) + +(define_insn "*store_indexed__d" + [(set (match_operand:DIDF 0 "indexed_memory_operand" "=Q") + (match_operand:DIDF 1 "register_operand" "f"))] + "i860_mem_aligned8_p (operands[0])" + "fst.d %1,%0" + [(set_attr "type" "store")]) + +;; ------------------------------------------------------------------------ +;; Extensions. ld.b and ld.s sign-extend. +;; ------------------------------------------------------------------------ + +(define_insn "zero_extendqisi2" + [(set (match_operand:SI 0 "register_operand" "=r,r") + (zero_extend:SI (match_operand:QI 1 "reg_or_load_operand" "r,Qm")))] + "" + "@ + and 0xff,%1,%0 + * return i860_output_load_ext (operands, \"and 0xff,%0,%0\");" + [(set_attr "type" "alu,multi")]) + +(define_insn "zero_extendqihi2" + [(set (match_operand:HI 0 "register_operand" "=r,r") + (zero_extend:HI (match_operand:QI 1 "reg_or_load_operand" "r,Qm")))] + "" + "@ + and 0xff,%1,%0 + * return i860_output_load_ext (operands, \"and 0xff,%0,%0\");" + [(set_attr "type" "alu,multi")]) + +(define_insn "zero_extendhisi2" + [(set (match_operand:SI 0 "register_operand" "=r,r") + (zero_extend:SI (match_operand:HI 1 "reg_or_load_operand" "r,Qm")))] + "" + "@ + and 0xffff,%1,%0 + * return i860_output_load_ext (operands, \"and 0xffff,%0,%0\");" + [(set_attr "type" "alu,multi")]) + +(define_insn "extendqisi2" + [(set (match_operand:SI 0 "register_operand" "=r,r") + (sign_extend:SI (match_operand:QI 1 "reg_or_load_operand" "r,Qm")))] + "" + "@ + shl 24,%1,%0\;shra 24,%0,%0 + * return i860_output_load_ext (operands, NULL);" + [(set_attr "type" "multi,load")]) + +(define_insn "extendqihi2" + [(set (match_operand:HI 0 "register_operand" "=r,r") + (sign_extend:HI (match_operand:QI 1 "reg_or_load_operand" "r,Qm")))] + "" + "@ + shl 24,%1,%0\;shra 24,%0,%0 + * return i860_output_load_ext (operands, NULL);" + [(set_attr "type" "multi,load")]) + +(define_insn "extendhisi2" + [(set (match_operand:SI 0 "register_operand" "=r,r") + (sign_extend:SI (match_operand:HI 1 "reg_or_load_operand" "r,Qm")))] + "" + "@ + shl 16,%1,%0\;shra 16,%0,%0 + * return i860_output_load_ext (operands, NULL);" + [(set_attr "type" "multi,load")]) + +;; ------------------------------------------------------------------------ +;; Integer arithmetic +;; ------------------------------------------------------------------------ + +;; Constants outside the immediate range are built in r31. +(define_insn "addsi3" + [(set (match_operand:SI 0 "register_operand" "=r,r") + (plus:SI (match_operand:SI 1 "register_operand" "%r,r") + (match_operand:SI 2 "nonmemory_operand" "rI,i")))] + "" + "@ + addu %2,%1,%0 + orh %H2,%?r0,%?r31\;or %L2,%?r31,%?r31\;addu %?r31,%1,%0" + [(set_attr "type" "alu,multi")]) + +(define_insn "subsi3" + [(set (match_operand:SI 0 "register_operand" "=r,r") + (minus:SI (match_operand:SI 1 "arith_operand" "rI,r") + (match_operand:SI 2 "arith_operand" "r,I")))] + "" + "@ + subu %1,%2,%0 + addu %n2,%1,%0" + [(set_attr "type" "alu")]) + +(define_insn "negsi2" + [(set (match_operand:SI 0 "register_operand" "=r") + (neg:SI (match_operand:SI 1 "register_operand" "r")))] + "" + "subu %?r0,%1,%0" + [(set_attr "type" "alu")]) + +(define_insn "one_cmplsi2" + [(set (match_operand:SI 0 "register_operand" "=r") + (not:SI (match_operand:SI 1 "register_operand" "r")))] + "" + "subu -1,%1,%0" + [(set_attr "type" "alu")]) + +;; 32x32->32 multiply through the FP multiplier (fmlow.dd uses the low +;; words of two register pairs). +(define_expand "mulsi3" + [(match_operand:SI 0 "register_operand") + (match_operand:SI 1 "register_operand") + (match_operand:SI 2 "register_operand")] + "" +{ + rtx a = gen_reg_rtx (DImode); + rtx b = gen_reg_rtx (DImode); + rtx r = gen_reg_rtx (DImode); + + emit_clobber (a); + emit_clobber (b); + emit_move_insn (gen_lowpart (SImode, a), operands[1]); + emit_move_insn (gen_lowpart (SImode, b), operands[2]); + emit_insn (gen_i860_fmlow (r, a, b)); + emit_move_insn (operands[0], gen_lowpart (SImode, r)); + DONE; +}) + +(define_insn "i860_fmlow" + [(set (match_operand:DI 0 "register_operand" "=f") + (unspec:DI [(match_operand:DI 1 "register_operand" "f") + (match_operand:DI 2 "register_operand" "f")] + UNSPEC_FMLOW))] + "" + "fmlow.dd %2,%1,%0" + [(set_attr "type" "fpu")]) + +;; 64-bit integer add/subtract in the graphics unit. +(define_insn "adddi3" + [(set (match_operand:DI 0 "register_operand" "=f") + (plus:DI (match_operand:DI 1 "register_operand" "%f") + (match_operand:DI 2 "register_operand" "f")))] + "" + "fiadd.dd %1,%2,%0" + [(set_attr "type" "fpu")]) + +(define_insn "subdi3" + [(set (match_operand:DI 0 "register_operand" "=f") + (minus:DI (match_operand:DI 1 "register_operand" "f") + (match_operand:DI 2 "register_operand" "f")))] + "" + "fisub.dd %1,%2,%0" + [(set_attr "type" "fpu")]) + +;; ------------------------------------------------------------------------ +;; Logical operations. Any constant takes at most two instructions. +;; ------------------------------------------------------------------------ + +(define_insn "andsi3" + [(set (match_operand:SI 0 "register_operand" "=r") + (and:SI (match_operand:SI 1 "register_operand" "%r") + (match_operand:SI 2 "logic_or_const_operand" "rn")))] + "" + "* return i860_output_logic (AND, operands);" + [(set_attr "type" "alu") + (set (attr "length") (symbol_ref "i860_logic_length (AND, operands)"))]) + +(define_insn "iorsi3" + [(set (match_operand:SI 0 "register_operand" "=r") + (ior:SI (match_operand:SI 1 "register_operand" "%r") + (match_operand:SI 2 "logic_or_const_operand" "rn")))] + "" + "* return i860_output_logic (IOR, operands);" + [(set_attr "type" "alu") + (set (attr "length") (symbol_ref "i860_logic_length (IOR, operands)"))]) + +(define_insn "xorsi3" + [(set (match_operand:SI 0 "register_operand" "=r") + (xor:SI (match_operand:SI 1 "register_operand" "%r") + (match_operand:SI 2 "logic_or_const_operand" "rn")))] + "" + "* return i860_output_logic (XOR, operands);" + [(set_attr "type" "alu") + (set (attr "length") (symbol_ref "i860_logic_length (XOR, operands)"))]) + +(define_insn "*andnotsi3" + [(set (match_operand:SI 0 "register_operand" "=r") + (and:SI (not:SI (match_operand:SI 1 "register_operand" "r")) + (match_operand:SI 2 "register_operand" "r")))] + "" + "andnot %1,%2,%0" + [(set_attr "type" "alu")]) + +;; ------------------------------------------------------------------------ +;; Shifts +;; ------------------------------------------------------------------------ + +(define_insn "ashlsi3" + [(set (match_operand:SI 0 "register_operand" "=r") + (ashift:SI (match_operand:SI 1 "register_operand" "r") + (match_operand:SI 2 "shift_operand" "rK")))] + "" + "shl %2,%1,%0" + [(set_attr "type" "alu")]) + +(define_insn "ashrsi3" + [(set (match_operand:SI 0 "register_operand" "=r") + (ashiftrt:SI (match_operand:SI 1 "register_operand" "r") + (match_operand:SI 2 "shift_operand" "rK")))] + "" + "shra %2,%1,%0" + [(set_attr "type" "alu")]) + +(define_insn "lshrsi3" + [(set (match_operand:SI 0 "register_operand" "=r") + (lshiftrt:SI (match_operand:SI 1 "register_operand" "r") + (match_operand:SI 2 "shift_operand" "rK")))] + "" + "shr %2,%1,%0" + [(set_attr "type" "alu")]) + +;; ------------------------------------------------------------------------ +;; Floating point +;; ------------------------------------------------------------------------ + +(define_insn "add3" + [(set (match_operand:FMODE 0 "register_operand" "=f") + (plus:FMODE (match_operand:FMODE 1 "register_operand" "%f") + (match_operand:FMODE 2 "register_operand" "f")))] + "" + "fadd. %1,%2,%0" + [(set_attr "type" "fpu")]) + +(define_insn "sub3" + [(set (match_operand:FMODE 0 "register_operand" "=f") + (minus:FMODE (match_operand:FMODE 1 "fp_reg_or_0_operand" "fG") + (match_operand:FMODE 2 "register_operand" "f")))] + "" + "fsub. %z1,%2,%0" + [(set_attr "type" "fpu")]) + +(define_insn "mul3" + [(set (match_operand:FMODE 0 "register_operand" "=f") + (mult:FMODE (match_operand:FMODE 1 "register_operand" "%f") + (match_operand:FMODE 2 "register_operand" "f")))] + "" + "fmul. %1,%2,%0" + [(set_attr "type" "fpu")]) + +;; 0 - x is not a negation for x = +0 or NaN. +(define_insn "neg2" + [(set (match_operand:FMODE 0 "register_operand" "=f") + (neg:FMODE (match_operand:FMODE 1 "register_operand" "f")))] + "!HONOR_SIGNED_ZEROS (mode) && !HONOR_NANS (mode)" + "fsub. %?f0,%1,%0" + [(set_attr "type" "fpu")]) + +;; Division by Newton-Raphson refinement of frcp; r31 holds the high +;; word of 2.0. +;; The sequence gives a NaN for a zero or infinite divisor, in 2 - y / y with an +;; infinite reciprocal, while the correct result is not one. So a NaN goes to libgcc: +;; the normal path only pays for one compare. +(define_expand "div3" + [(set (match_operand:FMODE 0 "register_operand") + (div:FMODE (match_operand:FMODE 1 "register_operand") + (match_operand:FMODE 2 "register_operand")))] + "" +{ + i860_expand_fdiv (mode, operands); + DONE; +}) + +(define_insn "i860_divdf3" + [(set (match_operand:DF 0 "register_operand" "=&f") + (div:DF (match_operand:DF 1 "register_operand" "f") + (match_operand:DF 2 "register_operand" "f"))) + (clobber (match_scratch:DF 3 "=&f")) + (clobber (match_scratch:DF 4 "=&f"))] + "" + "frcp.dd %2,%3\;fmul.dd %2,%3,%0\;fmov.dd %?f0,%4\;\ +orh 0x4000,%?r0,%?r31\;ixfr %?r31,%R4\;fsub.dd %4,%0,%0\;\ +fmul.dd %3,%0,%3\;fmul.dd %2,%3,%0\;fsub.dd %4,%0,%0\;\ +fmul.dd %3,%0,%3\;fmul.dd %2,%3,%0\;fsub.dd %4,%0,%0\;\ +fmul.dd %3,%1,%3\;fmul.dd %0,%3,%0" + [(set_attr "length" "56")]) + +(define_insn "i860_divsf3" + [(set (match_operand:SF 0 "register_operand" "=&f") + (div:SF (match_operand:SF 1 "register_operand" "f") + (match_operand:SF 2 "register_operand" "f"))) + (clobber (match_scratch:SF 3 "=&f")) + (clobber (match_scratch:SF 4 "=&f"))] + "" + "orh 0x4000,%?r0,%?r31\;ixfr %?r31,%4\;frcp.ss %2,%0\;\ +fmul.ss %2,%0,%3\;fsub.ss %4,%3,%3\;fmul.ss %0,%3,%0\;\ +fmul.ss %2,%0,%3\;fsub.ss %4,%3,%3\;\ +fmul.ss %1,%0,%4\;fmul.ss %3,%4,%0" + [(set_attr "length" "40")]) + +(define_insn "extendsfdf2" + [(set (match_operand:DF 0 "register_operand" "=f") + (float_extend:DF (match_operand:SF 1 "register_operand" "f")))] + "" + "fmov.sd %1,%0" + [(set_attr "type" "fpu")]) + +(define_insn "truncdfsf2" + [(set (match_operand:SF 0 "register_operand" "=f") + (float_truncate:SF (match_operand:DF 1 "register_operand" "f")))] + "" + "fmov.ds %1,%0" + [(set_attr "type" "fpu")]) + +;; int -> double: build 2^52 + 2^31 + x in a register pair and subtract +;; the magic constant. +(define_expand "floatsidf2" + [(match_operand:DF 0 "register_operand") + (match_operand:SI 1 "register_operand")] + "" +{ + i860_expand_floatsidf (operands[0], operands[1]); + DONE; +}) + +;; ftrunc leaves the result in the low word of a register pair. +(define_expand "fix_truncsi2" + [(match_operand:SI 0 "register_operand") + (match_operand:FMODE 1 "register_operand")] + "" +{ + rtx t = gen_reg_rtx (DImode); + + emit_insn (gen_i860_ftrunc (t, operands[1])); + emit_move_insn (operands[0], gen_lowpart (SImode, t)); + DONE; +}) + +(define_insn "i860_ftrunc" + [(set (match_operand:DI 0 "register_operand" "=f") + (unspec:DI [(match_operand:FMODE 1 "register_operand" "f")] + UNSPEC_FTRUNC))] + "" + "ftrunc. %1,%0" + [(set_attr "type" "fpu")]) + +;; ------------------------------------------------------------------------ +;; Compare and branch +;; ------------------------------------------------------------------------ + +(define_expand "cbranchsi4" + [(set (pc) + (if_then_else (match_operator 0 "ordered_comparison_operator" + [(match_operand:SI 1 "register_operand") + (match_operand:SI 2 "nonmemory_operand")]) + (label_ref (match_operand 3 "")) + (pc)))] + "" +{ + if (!i860_cbranch_operand_p (GET_CODE (operands[0]), operands[2])) + operands[2] = force_reg (SImode, operands[2]); +}) + +(define_insn "*cbranchsi4" + [(set (pc) + (if_then_else (match_operator 0 "ordered_comparison_operator" + [(match_operand:SI 1 "register_operand" "r") + (match_operand:SI 2 "nonmemory_operand" "rn")]) + (label_ref (match_operand 3 "")) + (pc)))] + "lra_in_progress || reload_completed + || i860_cbranch_operand_p (GET_CODE (operands[0]), operands[2])" + "* return i860_output_cbranch (insn, operands, false);" + [(set (attr "length") + (if_then_else + (and (match_test "i860_bte_form_p (operands)") + (ge (minus (match_dup 3) (pc)) (const_int -131000)) + (le (minus (match_dup 3) (pc)) (const_int 131000))) + (const_int 4) + (symbol_ref "i860_cbranch_length (operands, false)"))) + (set (attr "type") + (if_then_else (match_test "i860_bte_form_p (operands)") + (const_string "multi") + (const_string "cbranch")))]) + +(define_insn "*cbranchsi4_rev" + [(set (pc) + (if_then_else (match_operator 0 "ordered_comparison_operator" + [(match_operand:SI 1 "register_operand" "r") + (match_operand:SI 2 "nonmemory_operand" "rn")]) + (pc) + (label_ref (match_operand 3 ""))))] + "lra_in_progress || reload_completed + || i860_cbranch_operand_p (reverse_condition (GET_CODE (operands[0])), + operands[2])" + "* return i860_output_cbranch (insn, operands, true);" + [(set (attr "length") + (if_then_else + (and (match_test "i860_bte_form_p (operands)") + (ge (minus (match_dup 3) (pc)) (const_int -131000)) + (le (minus (match_dup 3) (pc)) (const_int 131000))) + (const_int 4) + (symbol_ref "i860_cbranch_length (operands, true)"))) + (set (attr "type") + (if_then_else (match_test "i860_bte_form_p (operands)") + (const_string "multi") + (const_string "cbranch")))]) + +;; Bit tests: logical instructions set CC when the result is zero. +(define_insn "*cbranch_and" + [(set (pc) + (if_then_else (match_operator 0 "i860_eqne_operator" + [(and:SI (match_operand:SI 1 "register_operand" "r") + (match_operand:SI 2 "logic_or_const_operand" "rn")) + (const_int 0)]) + (label_ref (match_operand 3 "")) + (pc)))] + "!CONST_INT_P (operands[2]) || satisfies_constraint_L (operands[2]) + || satisfies_constraint_M (operands[2])" + "* return i860_output_bit_cbranch (operands, false);" + [(set_attr "type" "cbranch") + (set_attr "length" "8")]) + +(define_insn "*cbranch_and_rev" + [(set (pc) + (if_then_else (match_operator 0 "i860_eqne_operator" + [(and:SI (match_operand:SI 1 "register_operand" "r") + (match_operand:SI 2 "logic_or_const_operand" "rn")) + (const_int 0)]) + (pc) + (label_ref (match_operand 3 ""))))] + "!CONST_INT_P (operands[2]) || satisfies_constraint_L (operands[2]) + || satisfies_constraint_M (operands[2])" + "* return i860_output_bit_cbranch (operands, true);" + [(set_attr "type" "cbranch") + (set_attr "length" "8")]) + +(define_expand "cbranch4" + [(set (pc) + (if_then_else (match_operator 0 "i860_fp_comparison_operator" + [(match_operand:FMODE 1 "fp_reg_or_0_operand") + (match_operand:FMODE 2 "fp_reg_or_0_operand")]) + (label_ref (match_operand 3 "")) + (pc)))] + "" +{ + if (!fp_reg_or_0_operand (operands[1], mode)) + operands[1] = force_reg (mode, operands[1]); + if (!fp_reg_or_0_operand (operands[2], mode)) + operands[2] = force_reg (mode, operands[2]); +}) + +(define_insn "*cbranch4" + [(set (pc) + (if_then_else (match_operator 0 "i860_fp_comparison_operator" + [(match_operand:FMODE 1 "fp_reg_or_0_operand" "fG") + (match_operand:FMODE 2 "fp_reg_or_0_operand" "fG")]) + (label_ref (match_operand 3 "")) + (pc)))] + "" + "* return i860_output_fp_cbranch (operands, mode, false);" + [(set (attr "type") + (if_then_else (match_test "i860_fp_cbranch_simple_p (operands, false)") + (const_string "cbranch") + (const_string "multi")))]) + +(define_insn "*cbranch4_rev" + [(set (pc) + (if_then_else (match_operator 0 "i860_fp_comparison_operator" + [(match_operand:FMODE 1 "fp_reg_or_0_operand" "fG") + (match_operand:FMODE 2 "fp_reg_or_0_operand" "fG")]) + (pc) + (label_ref (match_operand 3 ""))))] + "" + "* return i860_output_fp_cbranch (operands, mode, true);" + [(set (attr "type") + (if_then_else (match_test "i860_fp_cbranch_simple_p (operands, true)") + (const_string "cbranch") + (const_string "multi")))]) + +;; ------------------------------------------------------------------------ +;; Jumps and calls. br/bri/call/calli have a delay slot. +;; ------------------------------------------------------------------------ + +(define_insn "jump" + [(set (pc) (label_ref (match_operand 0 "" "")))] + "" + "br %l0%#" + [(set_attr "type" "branch") + (set_attr "length" "8")]) + +(define_insn "indirect_jump" + [(set (pc) (match_operand:SI 0 "register_operand" "r"))] + "" + "bri %0%#" + [(set_attr "type" "branch") + (set_attr "length" "8")]) + +(define_expand "tablejump" + [(parallel [(set (pc) (match_operand:SI 0 "register_operand")) + (use (label_ref (match_operand 1 "")))])] + "" +{ + /* The table holds offsets from its own label. */ + if (CASE_VECTOR_PC_RELATIVE) + { + rtx base = i860_legitimize_pic_address (gen_rtx_LABEL_REF (Pmode, + operands[1]), + NULL_RTX); + operands[0] = expand_simple_binop (Pmode, PLUS, base, operands[0], + NULL_RTX, 0, OPTAB_DIRECT); + } +}) + +(define_insn "*tablejump" + [(set (pc) (match_operand:SI 0 "register_operand" "r")) + (use (label_ref (match_operand 1 "" "")))] + "" + "bri %0%#" + [(set_attr "type" "branch") + (set_attr "length" "8")]) + +;; ------------------------------------------------------------------------ +;; Position independent code. r31 is the per-insn temporary. + +(define_insn "i860_load_got" + [(set (match_operand:SI 0 "register_operand" "=r") + (unspec:SI [(match_operand:SI 1 "" "") + (reg:SI PIC_REGNUM)] UNSPEC_GOT))] + "flag_pic" + "orh [%G1]@got@ha,%?r0,%?r31\;addu %?r15,%?r31,%?r31\;ld.l [%G1]@got@l(%?r31),%0" + [(set_attr "length" "12")]) + +(define_insn "i860_load_gotoff" + [(set (match_operand:SI 0 "register_operand" "=r") + (unspec:SI [(match_operand:SI 1 "" "") + (reg:SI PIC_REGNUM)] UNSPEC_GOTOFF))] + "flag_pic" + "orh [%G1]@gotoff@h,%?r0,%?r31\;or [%G1]@gotoff@l,%?r31,%?r31\;addu %?r15,%?r31,%0" + [(set_attr "length" "12")]) + +;; TLS, variant II: the blocks end at the thread pointer in r30. The address of the +;; DTPMOD, DTPOFF pair for __tls_get_addr; an offset from the thread pointer from the +;; GOT, relative to r15 or absolute in non-PIC code; the address itself. +(define_insn "i860_tls_gd" + [(set (match_operand:SI 0 "register_operand" "=r") + (unspec:SI [(match_operand:SI 1 "" "") + (reg:SI PIC_REGNUM)] UNSPEC_TLS_GD))] + "flag_pic" + "orh [%G1]@tlsgd@h,%?r0,%?r31\;or [%G1]@tlsgd@l,%?r31,%?r31\;addu %?r15,%?r31,%0" + [(set_attr "length" "12")]) + +(define_insn "i860_tls_ie" + [(set (match_operand:SI 0 "register_operand" "=r") + (unspec:SI [(match_operand:SI 1 "" "") + (reg:SI PIC_REGNUM)] UNSPEC_TLS_IE))] + "flag_pic" + "orh [%G1]@gottpoff@ha,%?r0,%?r31\;addu %?r15,%?r31,%?r31\;ld.l [%G1]@gottpoff@l(%?r31),%0" + [(set_attr "length" "12")]) + +(define_insn "i860_tls_ie_abs" + [(set (match_operand:SI 0 "register_operand" "=r") + (unspec:SI [(match_operand:SI 1 "" "")] UNSPEC_TLS_IE_ABS))] + "!flag_pic" + "orh [%G1]@gottpoffabs@ha,%?r0,%?r31\;ld.l [%G1]@gottpoffabs@l(%?r31),%0" + [(set_attr "length" "8")]) + +(define_insn "i860_tls_le" + [(set (match_operand:SI 0 "register_operand" "=r") + (unspec:SI [(match_operand:SI 1 "" "")] UNSPEC_TLS_LE))] + "" + "orh [%G1]@tpoff@h,%?r0,%?r31\;or [%G1]@tpoff@l,%?r31,%?r31\;addu %?r30,%?r31,%0" + [(set_attr "length" "12")]) + +;; Access to a local object: the GOT offset goes into the displacement of the +;; load or store instead of a register, one instruction less. Only after +;; reload, these addresses are not legitimate: see the peepholes below. +(define_mode_iterator GOTOFF_MEM [QI HI SI SF]) + +(define_insn "*gotoff_load" + [(set (match_operand:GOTOFF_MEM 0 "register_operand" "=rf") + (match_operand:GOTOFF_MEM 1 "gotoff_memory_operand" "X"))] + "flag_pic && reload_completed" + "* return i860_output_gotoff_access (operands, true);" + [(set_attr "length" "12")]) + +(define_insn "*gotoff_store" + [(set (match_operand:GOTOFF_MEM 0 "gotoff_memory_operand" "=X") + (match_operand:GOTOFF_MEM 1 "reg_or_0_operand" "rfGJ"))] + "flag_pic && reload_completed" + "* return i860_output_gotoff_access (operands, false);" + [(set_attr "length" "12")]) + +(define_peephole2 + [(set (match_operand:SI 0 "register_operand") + (unspec:SI [(match_operand:SI 1 "") (reg:SI PIC_REGNUM)] UNSPEC_GOTOFF)) + (set (match_operand:GOTOFF_MEM 2 "register_operand") + (match_operand:GOTOFF_MEM 3 "memory_operand"))] + "(REGNO (operands[0]) == REGNO (operands[2]) + || peep2_reg_dead_p (2, operands[0])) + && i860_gotoff_mem (operands[3], operands[0], operands[1])" + [(set (match_dup 2) (match_dup 4))] +{ + operands[4] = i860_gotoff_mem (operands[3], operands[0], operands[1]); +}) + +(define_peephole2 + [(set (match_operand:SI 0 "register_operand") + (unspec:SI [(match_operand:SI 1 "") (reg:SI PIC_REGNUM)] UNSPEC_GOTOFF)) + (set (match_operand:GOTOFF_MEM 2 "memory_operand") + (match_operand:GOTOFF_MEM 3 "reg_or_0_operand"))] + "peep2_reg_dead_p (2, operands[0]) + && !reg_overlap_mentioned_p (operands[0], operands[3]) + && i860_gotoff_mem (operands[2], operands[0], operands[1])" + [(set (match_dup 4) (match_dup 3))] +{ + operands[4] = i860_gotoff_mem (operands[2], operands[0], operands[1]); +}) + +;; The i860 reads the PC only through a call: r1 is the label after its +;; delay slot. The low part relocation sits one word later, thus the +4. +(define_insn "i860_set_got" + [(set (reg:SI PIC_REGNUM) + (unspec_volatile:SI [(const_int 0)] UNSPECV_SET_GOT)) + (clobber (reg:SI R1_REGNUM))] + "flag_pic" + "call 1f\;nop\n1:\torh [_GLOBAL_OFFSET_TABLE_]@pc@ha,%?r0,%?r15\;adds [_GLOBAL_OFFSET_TABLE_+4]@pc@l,%?r15,%?r15\;addu %?r1,%?r15,%?r15" + [(set_attr "length" "20")]) + +(define_expand "call" + [(parallel [(call (match_operand:SI 0 "memory_operand") + (match_operand 1 "")) + (clobber (reg:SI R1_REGNUM))])] + "" +{ + if (!call_insn_operand (operands[0], SImode)) + operands[0] = replace_equiv_address (operands[0], + force_reg (Pmode, + XEXP (operands[0], 0))); +}) + +;; A bare symbol: LRA must not reload it as the address of a memory operand, +;; PIC code would then load it from the GOT for an indirect call. +(define_insn "*call_symbol" + [(call (mem:SI (match_operand:SI 0 "symbol_ref_operand" "Z")) + (match_operand 1 "" "")) + (clobber (reg:SI R1_REGNUM))] + "" + "* return i860_output_call (operands, 0);" + [(set_attr "type" "call") + (set_attr "length" "8")]) + +(define_insn "*call" + [(call (match_operand:SI 0 "call_insn_operand" "Y") + (match_operand 1 "" "")) + (clobber (reg:SI R1_REGNUM))] + "" + "* return i860_output_call (operands, 0);" + [(set_attr "type" "call") + (set_attr "length" "8")]) + +(define_expand "call_value" + [(parallel [(set (match_operand 0 "") + (call (match_operand:SI 1 "memory_operand") + (match_operand 2 ""))) + (clobber (reg:SI R1_REGNUM))])] + "" +{ + if (!call_insn_operand (operands[1], SImode)) + operands[1] = replace_equiv_address (operands[1], + force_reg (Pmode, + XEXP (operands[1], 0))); +}) + +(define_insn "*call_value_symbol" + [(set (match_operand 0 "" "") + (call (mem:SI (match_operand:SI 1 "symbol_ref_operand" "Z")) + (match_operand 2 "" ""))) + (clobber (reg:SI R1_REGNUM))] + "" + "* return i860_output_call (operands, 1);" + [(set_attr "type" "call") + (set_attr "length" "8")]) + +(define_insn "*call_value" + [(set (match_operand 0 "" "") + (call (match_operand:SI 1 "call_insn_operand" "Y") + (match_operand 2 "" ""))) + (clobber (reg:SI R1_REGNUM))] + "" + "* return i860_output_call (operands, 1);" + [(set_attr "type" "call") + (set_attr "length" "8")]) + +;; Sibling calls: entered with the epilogue done and sp restored by the slot. +;; The PLT keeps r1 for the callee and neither form needs r15. After a fault in +;; the slot the kernel resumes at the br or bri, so the jump is repeated. The +;; return address stays live through EPILOGUE_USES. +(define_expand "sibcall" + [(parallel [(call (match_operand:SI 0 "memory_operand") + (match_operand 1 "")) + (return)])] + "" +{ + operands[0] = i860_sibcall_mem (operands[0]); +}) + +(define_insn "*sibcall_symbol" + [(call (mem:SI (match_operand:SI 0 "symbol_ref_operand" "Z")) + (match_operand 1 "" "")) + (return)] + "SIBLING_CALL_P (insn)" +{ + return (flag_pic && !SYMBOL_REF_LOCAL_P (operands[0]) + ? "br %0@plt%#" : "br %0%#"); +} + [(set_attr "type" "branch") + (set_attr "length" "8")]) + +(define_insn "*sibcall" + [(call (mem:SI (reg:SI SIBCALL_REGNUM)) + (match_operand 0 "" "")) + (return)] + "SIBLING_CALL_P (insn)" + "bri %?r28%#" + [(set_attr "type" "branch") + (set_attr "length" "8")]) + +(define_expand "sibcall_value" + [(parallel [(set (match_operand 0 "") + (call (match_operand:SI 1 "memory_operand") + (match_operand 2 ""))) + (return)])] + "" +{ + operands[1] = i860_sibcall_mem (operands[1]); +}) + +(define_insn "*sibcall_value_symbol" + [(set (match_operand 0 "" "") + (call (mem:SI (match_operand:SI 1 "symbol_ref_operand" "Z")) + (match_operand 2 "" ""))) + (return)] + "SIBLING_CALL_P (insn)" +{ + return (flag_pic && !SYMBOL_REF_LOCAL_P (operands[1]) + ? "br %1@plt%#" : "br %1%#"); +} + [(set_attr "type" "branch") + (set_attr "length" "8")]) + +(define_insn "*sibcall_value" + [(set (match_operand 0 "" "") + (call (mem:SI (reg:SI SIBCALL_REGNUM)) + (match_operand 1 "" ""))) + (return)] + "SIBLING_CALL_P (insn)" + "bri %?r28%#" + [(set_attr "type" "branch") + (set_attr "length" "8")]) + +(define_expand "untyped_call" + [(parallel [(call (match_operand 0 "") + (const_int 0)) + (match_operand 1 "") + (match_operand 2 "")])] + "" +{ + emit_call_insn (gen_call (operands[0], const0_rtx)); + + for (int i = 0; i < XVECLEN (operands[2], 0); i++) + { + rtx set = XVECEXP (operands[2], 0, i); + emit_move_insn (SET_DEST (set), SET_SRC (set)); + } + + /* The call sets the value registers stored in the result block. */ + emit_insn (gen_blockage ()); + DONE; +}) + +;; ------------------------------------------------------------------------ +;; Prologue, epilogue and miscellaneous +;; ------------------------------------------------------------------------ + +(define_expand "prologue" + [(const_int 0)] + "" +{ + i860_expand_prologue (); + DONE; +}) + +(define_expand "epilogue" + [(const_int 0)] + "" +{ + i860_expand_epilogue (false); + DONE; +}) + +(define_expand "sibcall_epilogue" + [(const_int 0)] + "" +{ + i860_expand_epilogue (true); + DONE; +}) + +;; A leaf without a frame. +(define_insn "i860_return_leaf" + [(return) + (use (reg:SI R1_REGNUM))] + "reload_completed" + "bri %?r1%#" + [(set_attr "type" "branch") + (set_attr "length" "8")]) + +;; The stack pointer is restored in the delay slot of the return. +(define_insn "i860_return_reg" + [(return) + (use (reg:SI R1_REGNUM)) + (set (reg:SI SP_REGNUM) (match_operand:SI 0 "register_operand" "r"))] + "reload_completed" + "bri %?r1\;mov %0,%?sp" + [(set_attr "type" "return") + (set_attr "length" "8")]) + +(define_insn "i860_return_adjust" + [(return) + (use (reg:SI R1_REGNUM)) + (set (reg:SI SP_REGNUM) + (plus:SI (reg:SI SP_REGNUM) + (match_operand:SI 0 "const_int_operand" "I")))] + "reload_completed" + "bri %?r1\;addu %0,%?sp,%?sp" + [(set_attr "type" "return") + (set_attr "length" "8")]) + +(define_insn "blockage" + [(unspec_volatile [(const_int 0)] UNSPECV_BLOCKAGE)] + "" + "" + [(set_attr "type" "nop") + (set_attr "length" "0")]) + +(define_insn "nop" + [(const_int 0)] + "" + "nop" + [(set_attr "type" "nop")]) + +(define_insn "trap" + [(trap_if (const_int 1) (const_int 0))] + "" + "trap %?r0,%?r0,%?r0" + [(set_attr "type" "trap")]) + +;; Atomics: everything else derives from this. The bus stays locked and interrupts are held +;; off up to the access after unlock; a trap inside makes the kernel restart at the lock, so +;; the operands must survive: old is earlyclobber. In user mode at most 32 instructions. +(define_mode_iterator ATOMIC [QI HI SI]) +(define_mode_attr lsfx [(QI "b") (HI "s") (SI "l")]) + +(define_expand "atomic_compare_and_swap" + [(match_operand:SI 0 "register_operand") + (match_operand:ATOMIC 1 "register_operand") + (match_operand:ATOMIC 2 "memory_operand") + (match_operand:ATOMIC 3 "general_operand") + (match_operand:ATOMIC 4 "general_operand") + (match_operand:SI 5 "const_int_operand") + (match_operand:SI 6 "const_int_operand") + (match_operand:SI 7 "const_int_operand")] + "" +{ + rtx old = gen_reg_rtx (SImode); + rtx addr = force_reg (Pmode, XEXP (operands[2], 0)); + /* ld.b and ld.s sign extend */ + rtx expected = force_reg (SImode, convert_modes (SImode, mode, operands[3], 0)); + rtx desired = force_reg (SImode, convert_modes (SImode, mode, operands[4], 0)); + rtx ok; + + emit_insn (gen_i860_cas (old, addr, expected, desired)); + emit_move_insn (operands[1], gen_lowpart (mode, old)); + ok = emit_store_flag_force (operands[0], EQ, old, expected, SImode, 0, 1); + if (ok != operands[0]) + emit_move_insn (operands[0], ok); + DONE; +}) + +(define_insn "i860_cas" + [(set (match_operand:SI 0 "register_operand" "=&r") + (unspec_volatile:SI [(mem:ATOMIC (match_operand:SI 1 "register_operand" "r")) + (match_operand:SI 2 "register_operand" "r") + (match_operand:SI 3 "register_operand" "r")] UNSPECV_CAS)) + (set (mem:ATOMIC (match_dup 1)) + (unspec_volatile:ATOMIC [(const_int 0)] UNSPECV_CAS)) + (clobber (mem:BLK (scratch)))] + "" + "lock\;ld. 0(%1),%0\;xor %0,%2,%?r0\;bnc 1f\;unlock\;st. %3,0(%1)\;br 2f\;nop\;1:\;unlock\;ld. 0(%1),%?r0\;2:" + [(set_attr "type" "multi") + (set_attr "length" "40")]) + +;; Counted loops. bla tests the flag LCC from its previous execution and sets it from the +;; count before adding: so the count is two below the iterations left, and the first +;; bla, branching to the next instruction, sets LCC. As RTL the loop is the usual +;; test against 1: the priming hides what the count really holds. A single LCC: only +;; innermost loops without calls and asm, see i860_can_use_doloop_p. +(define_expand "doloop_end" + [(use (match_operand 0 "" "")) + (use (label_ref (match_operand 1 "" "")))] + "optimize" +{ + /* setting it up takes more than it saves */ + if (GET_MODE (operands[0]) != SImode || !optimize_function_for_speed_p (cfun)) + FAIL; + emit_jump_insn (gen_i860_bla_loop (operands[0], operands[1], gen_reg_rtx (SImode))); + DONE; +}) + +(define_expand "doloop_begin" + [(use (match_operand 0 "" "")) + (use (match_operand 1 "" ""))] + "optimize" +{ + rtx step = XEXP (XVECEXP (PATTERN (operands[1]), 0, 2), 0); + + emit_move_insn (step, constm1_rtx); + emit_insn (gen_i860_bla_prime (operands[0], step)); + DONE; +}) + +(define_insn "i860_bla_prime" + [(set (match_operand:SI 0 "register_operand" "+r") + (unspec_volatile:SI [(match_dup 0) + (match_operand:SI 1 "register_operand" "r")] + UNSPECV_BLA_PRIME))] + "" + "adds -1,%0,%0\;bla %1,%0,1f\;nop\;1:" + [(set_attr "type" "multi") + (set_attr "length" "12")]) + +;; A count in memory cannot be reloaded around a jump: then r31 does it all. +(define_insn "i860_bla_loop" + [(set (pc) + (if_then_else (ne (match_operand:SI 0 "nonimmediate_operand" "+r,*m") + (const_int 1)) + (label_ref (match_operand 1 "" "")) + (pc))) + (set (match_dup 0) (plus:SI (match_dup 0) (const_int -1))) + (use (match_operand:SI 2 "register_operand" "r,X")) + (clobber (reg:SI R31_REGNUM))] + "" + "* return i860_output_bla (insn, operands, which_alternative);" + [(set_attr "type" "bla,multi") + (set (attr "length") + (if_then_else + (and (eq_attr "alternative" "0") + (ge (minus (match_dup 1) (pc)) (const_int -131000)) + (le (minus (match_dup 1) (pc)) (const_int 131000))) + (const_int 8) + (const_int 28)))]) + +;; Made by i860-pipe.cc. The result is that of an earlier instruction of the unit. +(define_insn "i860_pfadd" + [(set (match_operand:FMODE 0 "register_operand" "=f") + (unspec_volatile:FMODE [(match_operand:FMODE 1 "register_operand" "f") + (match_operand:FMODE 2 "register_operand" "f")] + UNSPECV_PFADD))] + "" + "pfadd. %1,%2,%0" + [(set_attr "type" "fpu")]) + +(define_insn "i860_pfsub" + [(set (match_operand:FMODE 0 "register_operand" "=f") + (unspec_volatile:FMODE [(match_operand:FMODE 1 "register_operand" "f") + (match_operand:FMODE 2 "register_operand" "f")] + UNSPECV_PFSUB))] + "" + "pfsub. %1,%2,%0" + [(set_attr "type" "fpu")]) + +(define_insn "i860_pfmul" + [(set (match_operand:FMODE 0 "register_operand" "=f") + (unspec_volatile:FMODE [(match_operand:FMODE 1 "register_operand" "f") + (match_operand:FMODE 2 "register_operand" "f")] + UNSPECV_PFMUL))] + "" + "pfmul. %1,%2,%0" + [(set_attr "type" "fpu")]) + +(define_insn "i860_pfld" + [(set (match_operand:FMODE 0 "register_operand" "=f") + (unspec_volatile:FMODE [(match_operand:FMODE 1 "memory_operand" "m")] UNSPECV_PFLD))] + "" + "pfld. %1,%0" + [(set_attr "type" "fpu")]) + +;; A pipelined loop in dual-instruction mode as one insn: alignment and pairing must survive, +;; and no delay slot filling or block reordering may split it. The body holds an FP and a core +;; half per pair, see i860-pipe.cc. +(define_insn "i860_dual_kernel" + [(match_parallel 0 "i860_dual_kernel_operation" + [(unspec_volatile [(const_int 0)] UNSPECV_DUAL_KERNEL)])] + "" + "* return i860_output_dual_kernel (operands[0]);" + [(set_attr "type" "multi") + (set (attr "length") (symbol_ref "4 * XVECLEN (PATTERN (insn), 0) + 28"))]) + diff --git a/gcc/config/i860/i860.opt b/gcc/config/i860/i860.opt new file mode 100644 index 00000000000..2433741e2b0 --- /dev/null +++ b/gcc/config/i860/i860.opt @@ -0,0 +1,44 @@ +; Options for the Intel i860 port of the compiler. + +; Copyright (C) 2005-2026 Free Software Foundation, Inc. +; Copyright (C) 2026 René Rebe +; +; This file is part of GCC. +; +; GCC is free software; you can redistribute it and/or modify it under +; the terms of the GNU General Public License as published by the Free +; Software Foundation; either version 3, or (at your option) any later +; version. +; +; GCC is distributed in the hope that it will be useful, but WITHOUT ANY +; WARRANTY; without even the implied warranty of MERCHANTABILITY or +; FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +; for more details. +; +; You should have received a copy of the GNU General Public License +; along with GCC; see the file COPYING3. If not see +; . + +mxp +Target RejectNegative Mask(XP) +Generate code for the i860XP. + +mxr +Target RejectNegative InverseMask(XP) +Generate code for the i860XR (default). + +mpipelined-fp +Target Var(i860_pipelined_fp) Init(-1) +Use the pipelined floating point instructions in counted loops; on at -O3, needs -O2. + +mdual-fp +Target Var(TARGET_DUAL_FP) Init(1) +Run pipelined floating point loops in dual-instruction mode. + +mpfld +Target Var(i860_pfld) Init(-1) +Use pipelined loads in the loops of -mpipelined-fp for arrays larger than the data cache; on at -O3. + +mpfld-min-bytes= +Target RejectNegative Joined UInteger Var(i860_pfld_min_bytes) Init(8192) +Read at least this many bytes in a loop to use pipelined loads. diff --git a/gcc/config/i860/i860.opt.urls b/gcc/config/i860/i860.opt.urls new file mode 100644 index 00000000000..f0068cab850 --- /dev/null +++ b/gcc/config/i860/i860.opt.urls @@ -0,0 +1,19 @@ +; Autogenerated by regenerate-opt-urls.py from gcc/config/i860/i860.opt and generated HTML + +mxp +UrlSuffix(gcc/i860-Options.html#index-mxp) + +mxr +UrlSuffix(gcc/i860-Options.html#index-mxr) + +mpipelined-fp +UrlSuffix(gcc/i860-Options.html#index-mpipelined-fp) + +mdual-fp +UrlSuffix(gcc/i860-Options.html#index-mdual-fp) + +mpfld +UrlSuffix(gcc/i860-Options.html#index-mpfld) + +mpfld-min-bytes= +UrlSuffix(gcc/i860-Options.html#index-mpfld-min-bytes) diff --git a/gcc/config/i860/linux.h b/gcc/config/i860/linux.h new file mode 100644 index 00000000000..371d5107c9a --- /dev/null +++ b/gcc/config/i860/linux.h @@ -0,0 +1,67 @@ +/* Definitions for Intel i860 running GNU/Linux. + Copyright (C) 2026 Free Software Foundation, Inc. + Copyright (C) 2026 René Rebe + +This file is part of GCC. + +GCC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 3, or (at your option) +any later version. + +GCC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GCC; see the file COPYING3. If not see +. */ + +#ifndef GCC_I860_LINUX_H +#define GCC_I860_LINUX_H + +#define TARGET_OS_CPP_BUILTINS() GNU_USER_TARGET_OS_CPP_BUILTINS () + +/* Linux ABI: 64-bit integers in integer register pairs, and r30 is the + thread pointer (never allocated, set by the C library and clone). */ +#define I860_DIMODE_ARGS_IN_GPRS 1 +#define I860_THREAD_POINTER_REGNUM 30 +#define I860_PIC_SUPPORTED 1 + +/* The caches are only reachable through dirbase, so this takes the kernel's + cacheflush syscall. It flushes everything, the range is only checked. */ +#define I860_NR_CACHEFLUSH 244 +#define CLEAR_INSN_CACHE(BEG, END) \ + do \ + { \ + register long r28_ __asm__ ("r28") = I860_NR_CACHEFLUSH; \ + register long r16_ __asm__ ("r16") = (long) (BEG); \ + register long r17_ __asm__ ("r17") = (long) (END) - (long) (BEG); \ + register long r18_ __asm__ ("r18") = 0; \ + __asm__ __volatile__ ("trap %%r0,%%r0,%%r0" \ + : "+r" (r28_), "+r" (r16_) \ + : "r" (r17_), "r" (r18_) \ + : "memory"); \ + } \ + while (0) + +#define GLIBC_DYNAMIC_LINKER "/lib/ld-linux-i860.so.1" +#undef MUSL_DYNAMIC_LINKER +#define MUSL_DYNAMIC_LINKER "/lib/ld-musl-i860.so.1" + +#undef CPP_SPEC +#define CPP_SPEC "%{posix:-D_POSIX_SOURCE} %{pthread:-D_REENTRANT}" + +#undef LINK_SPEC +#define LINK_SPEC \ + "%{shared:-shared} " \ + "%{!shared:%{!static:%{!static-pie:" \ + "%{rdynamic:-export-dynamic} " \ + "-dynamic-linker " GNU_USER_DYNAMIC_LINKER "}}} " \ + "%{static:-static} %{static-pie:-static -pie --no-dynamic-linker}" + +#endif /* GCC_I860_LINUX_H */ + +/* Nothing on Linux reads it, and the word before an entry point is never a delayed branch. */ +#define I860_SVR4_FUNCTION_PREFIX 0 diff --git a/gcc/config/i860/predicates.md b/gcc/config/i860/predicates.md new file mode 100644 index 00000000000..a944c091c27 --- /dev/null +++ b/gcc/config/i860/predicates.md @@ -0,0 +1,94 @@ +;; Predicate definitions for the Intel i860. +;; Copyright (C) 2026 Free Software Foundation, Inc. +;; Copyright (C) 2026 René Rebe +;; +;; This file is part of GCC. +;; +;; GCC is free software; you can redistribute it and/or modify it +;; under the terms of the GNU General Public License as published +;; by the Free Software Foundation; either version 3, or (at your +;; option) any later version. +;; +;; GCC is distributed in the hope that it will be useful, but WITHOUT +;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +;; or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public +;; License for more details. +;; +;; You should have received a copy of the GNU General Public License +;; along with GCC; see the file COPYING3. If not see +;; . + +(define_predicate "reg_or_0_operand" + (ior (match_operand 0 "register_operand") + (and (match_code "const_int,const_double") + (match_test "op == CONST0_RTX (mode)")))) + +(define_predicate "arith_operand" + (ior (match_operand 0 "register_operand") + (and (match_code "const_int") + (match_test "satisfies_constraint_I (op)")))) + +(define_predicate "logic_operand" + (ior (match_operand 0 "register_operand") + (and (match_code "const_int") + (match_test "satisfies_constraint_L (op)")))) + +;; Anything an and/or/xor pattern can output in at most two insns. +(define_predicate "logic_or_const_operand" + (ior (match_operand 0 "register_operand") + (match_code "const_int"))) + +(define_predicate "shift_operand" + (ior (match_operand 0 "register_operand") + (and (match_code "const_int") + (match_test "IN_RANGE (INTVAL (op), 0, 31)")))) + +(define_predicate "bte_operand" + (ior (match_operand 0 "register_operand") + (and (match_code "const_int") + (match_test "satisfies_constraint_K (op)")))) + +;; A memory reference with a reg+reg address: valid for loads only. +(define_predicate "indexed_memory_operand" + (and (match_code "mem") + (match_test "i860_indexed_address_p (XEXP (op, 0), false)"))) + +;; An access through a GOT offset in the displacement, see *gotoff_load. +(define_predicate "gotoff_memory_operand" + (and (match_code "mem") + (match_test "GET_CODE (XEXP (op, 0)) == UNSPEC + && XINT (XEXP (op, 0), 1) == UNSPEC_GOTOFF"))) + +;; Any operand a load instruction can read. +(define_predicate "reg_or_load_operand" + (ior (match_operand 0 "nonimmediate_operand") + (match_operand 0 "indexed_memory_operand"))) + +(define_predicate "symbol_ref_operand" + (match_code "symbol_ref")) + +(define_predicate "call_insn_operand" + (and (match_code "mem") + (match_test "i860_call_address_p (XEXP (op, 0), false)"))) + +(define_predicate "fp_reg_or_0_operand" + (ior (match_operand 0 "register_operand") + (and (match_code "const_double") + (match_test "op == CONST0_RTX (mode)")))) + +(define_predicate "i860_fp_comparison_operator" + (match_code "eq,ne,lt,gt,le,ge,unlt,ungt,unle,unge,uneq,ltgt, + ordered,unordered")) + +(define_predicate "i860_eqne_operator" + (match_code "eq,ne")) + +(define_special_predicate "i860_dual_kernel_operation" + (match_code "parallel") +{ + rtx first = XVECEXP (op, 0, 0); + + return (GET_CODE (first) == UNSPEC_VOLATILE + && XINT (first, 1) == UNSPECV_DUAL_KERNEL); +}) + diff --git a/gcc/config/i860/sysv4.h b/gcc/config/i860/sysv4.h new file mode 100644 index 00000000000..f25bc09af3b --- /dev/null +++ b/gcc/config/i860/sysv4.h @@ -0,0 +1,65 @@ +/* Target definitions for GCC for Intel 80860 running System V.4 + Copyright (C) 1991-2005, 2026 Free Software Foundation, Inc. + Copyright (C) 2026 René Rebe + + Written by Ron Guilmette (rfg@netcom.com). + +This file is part of GCC. + +GCC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 3, or (at your option) +any later version. + +GCC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GCC; see the file COPYING3. If not see +. */ + +#define TARGET_OS_CPP_BUILTINS() \ + do \ + { \ + builtin_define_std ("unix"); \ + builtin_define ("SVR4"); \ + builtin_define ("__svr4__"); \ + builtin_assert ("system=unix"); \ + builtin_assert ("system=svr4"); \ + } \ + while (0) + +/* Integer division comes from the native libc (.div, .udiv, ...). */ +#define I860_SVR4_DIVMOD_NAMES 1 + +/* Startup files and libraries of the native /usr/ccs/lib. */ +#undef STARTFILE_SPEC +#define STARTFILE_SPEC \ + "%{!shared:%{pg:pcrt1.o%s}%{!pg:%{p:mcrt1.o%s}%{!p:crt1.o%s}}} " \ + "%{pg:pcrti.o%s}%{!pg:crti.o%s} " \ + "%{ansi:values-Xc.o%s} %{!ansi:values-Xa.o%s} crtbegin.o%s" + +#undef ENDFILE_SPEC +#define ENDFILE_SPEC "crtend.o%s %{pg:pcrtn.o%s}%{!pg:crtn.o%s}" + +#undef LIB_SPEC +#define LIB_SPEC "%{!shared:%{!symbolic:-lc}}" + +#undef LINK_SPEC +#define LINK_SPEC \ + "%{h*} %{v:-V} %{b} " \ + "%{static:-dn -Bstatic} " \ + "%{shared:-G -dy -z text} " \ + "%{symbolic:-Bsymbolic -G -dy -z text} " \ + "%{G:-G} " \ + "%{YP,*} " \ + "%{!YP,*:%{p:-Y P,/usr/ccs/lib/libp:/usr/lib/libp:/usr/ccs/lib:/usr/lib} " \ + "%{!p:-Y P,/usr/ccs/lib:/usr/lib}} " \ + "%{Qy:} %{!Qn:-Qy}" + +#undef MD_STARTFILE_PREFIX +#define MD_STARTFILE_PREFIX "/usr/ccs/lib/" + +#define I860_SVR4_FUNCTION_PREFIX 1 diff --git a/gcc/config/i860/t-i860 b/gcc/config/i860/t-i860 new file mode 100644 index 00000000000..cf987c5fdb5 --- /dev/null +++ b/gcc/config/i860/t-i860 @@ -0,0 +1,23 @@ +# Copyright (C) 2026 René Rebe +# +# This file is part of GCC. +# +# GCC is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# GCC is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GCC; see the file COPYING3. If not see +# . + +PASSES_EXTRA += $(srcdir)/config/i860/i860-passes.def + +i860-pipe.o: $(srcdir)/config/i860/i860-pipe.cc + $(COMPILE) $< + $(POSTCOMPILE) diff --git a/gcc/doc/install.texi b/gcc/doc/install.texi index 2be38423c79..93250acf50e 100644 --- a/gcc/doc/install.texi +++ b/gcc/doc/install.texi @@ -4342,6 +4342,25 @@ If you receive Signal 11 errors when building on GNU/Linux, then it is possible you have a hardware problem. Further information on this can be found on @uref{https://www.bitwizard.nl/sig11/,,www.bitwizard.nl}. +@html +
+@end html +@anchor{i860-x-linux} +@heading i860-*-linux +Intel i860 running GNU/Linux. Requires GNU binutils 2.30 or older, +the last release supporting the i860. Only non-PIC code is generated, +so configure with @option{--disable-shared}. + +@html +
+@end html +@anchor{i860-x-sysv4} +@heading i860-*-sysv4 +Intel i860 running UNIX System V Release 4, e.g.@: Stardent/Kubota +UNIX System V/i860. Integer division uses the native @code{.div}, +@code{.udiv}, @code{.rem} and @code{.urem} helpers of the system C +library. + @html
@end html diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index 60d7163eee3..3d946a66767 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -1134,6 +1134,9 @@ Objective-C and Objective-C++ Dialects}. -mschedule=@var{cpu-type} -msoft-mult -msio -mwsio -munix=@var{unix-std} -nolibdld -static -threads} +@emph{i860 Options} (@ref{i860 Options}) +@gccoptlist{-mxp -mxr -mpipelined-fp -mdual-fp -mpfld -mpfld-min-bytes=@var{n}} + @emph{IA-64 Options} (@ref{IA-64 Options}) @gccoptlist{-mbig-endian -mlittle-endian -mgnu-as -mgnu-ld -mno-pic -mvolatile-asm-stop -mregister-names -msdata @@ -21416,6 +21419,7 @@ other compilers on the same platform. * GNU/Linux Options:: * H8/300 Options:: * HPPA Options:: +* i860 Options:: * IA-64 Options:: * LM32 Options:: * LoongArch Options:: @@ -27554,6 +27558,50 @@ under HP-UX@. This option sets flags for both the preprocessor and linker. @end table +@node i860 Options +@subsection Intel 860 Options +@cindex i860 Options + +These @samp{-m} options are defined for the Intel i860 processor +(@samp{i860-*-linux*} and @samp{i860-*-sysv4*} configurations). + +@table @gcctabopt +@opindex mxp +@item -mxp +Generate code for the i860XP and define the macro @code{__i860XP__}. + +@opindex mxr +@item -mxr +Generate code for the i860XR. This is the default. + +@opindex mpipelined-fp +@opindex mno-pipelined-fp +@item -mpipelined-fp +@itemx -mno-pipelined-fp +Use the pipelined floating point instructions in counted loops. This is +enabled at @option{-O3}, and needs @option{-O2} when given explicitly; it grows +these loops about threefold. It does not apply when optimizing for size. The loops +keep their scalar form for short iteration counts and for arrays found at +run time to overlap. + +@opindex mdual-fp +@opindex mno-dual-fp +@item -mdual-fp +@itemx -mno-dual-fp +Run the loops of @option{-mpipelined-fp} in dual-instruction mode where this +takes fewer pairs than instructions. Enabled by default. + +@opindex mpfld +@opindex mno-pfld +@opindex mpfld-min-bytes +@item -mpfld +@itemx -mno-pfld +@itemx -mpfld-min-bytes=@var{n} +Give the loops of @option{-mpipelined-fp} another form with pipelined loads, +for iteration counts that read at least @var{n} bytes (default 8192, the size +of the data cache). Enabled at @option{-O3}. +@end table + @node IA-64 Options @subsection IA-64 Options @cindex IA-64 Options diff --git a/gcc/testsuite/gcc.c-torture/execute/20101011-1.c b/gcc/testsuite/gcc.c-torture/execute/20101011-1.c index 9fdfb5265be..47c0efd0a77 100644 --- a/gcc/testsuite/gcc.c-torture/execute/20101011-1.c +++ b/gcc/testsuite/gcc.c-torture/execute/20101011-1.c @@ -97,6 +97,9 @@ __aeabi_idiv0 (int return_value) #elif defined (__moxie__) /* Not all moxie configurations may raise exceptions. */ # define DO_TEST 0 +#elif defined (__i860__) + /* No divide instruction, and __divsi3 does not trap. */ +# define DO_TEST 0 #elif defined (__or1k__) /* On OpenRISC division by zero does not trap. */ # define DO_TEST 0 diff --git a/libgcc/config.host b/libgcc/config.host index 319d6cfe0ef..9b3dbf14be7 100644 --- a/libgcc/config.host +++ b/libgcc/config.host @@ -1,5 +1,6 @@ # libgcc host-specific configuration file. # Copyright (C) 1997-2026 Free Software Foundation, Inc. +# Copyright (C) 2026 René Rebe #This file is part of GCC. @@ -946,6 +947,13 @@ x86_64-*-mingw*) extra_parts="$extra_parts vtv_start.o vtv_end.o vtv_start_preinit.o vtv_end_preinit.o" fi ;; +i860-*-linux*) + tmake_file="$tmake_file i860/t-i860" + ;; +i860-*-sysv4*) + tmake_file="$tmake_file i860/t-i860" + extra_parts="$extra_parts crtbegin.o crtend.o" + ;; ia64*-*-elf*) extra_parts="$extra_parts crtbeginS.o crtendS.o crtfastmath.o" tmake_file="ia64/t-ia64 ia64/t-ia64-elf ia64/t-eh-ia64 t-crtfm t-softfp-tf ia64/t-softfp t-softfp ia64/t-softfp-compat" diff --git a/libgcc/config/i860/fdiv-special.c b/libgcc/config/i860/fdiv-special.c new file mode 100644 index 00000000000..7c2b64a04d4 --- /dev/null +++ b/libgcc/config/i860/fdiv-special.c @@ -0,0 +1,54 @@ +/* IEEE results of a division where the Newton-Raphson sequence gave a NaN: + a NaN operand, a zero or infinite divisor, or a reciprocal that overflowed. + Copyright (C) 2026 Free Software Foundation, Inc. + Copyright (C) 2026 René Rebe + +This file is part of GCC. + +GCC is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free +Software Foundation; either version 3, or (at your option) any later +version. + +GCC is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +Under Section 7 of GPL version 3, you are granted additional +permissions described in the GCC Runtime Library Exception, version +3.1, as published by the Free Software Foundation. + +You should have received a copy of the GNU General Public License and +a copy of the GCC Runtime Library Exception along with this program; +see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +. */ + +extern double __i860_fdiv_special (double, double); +extern float __i860_fdivs_special (float, float); + +#define BIG 18446744073709551616.0 /* 2^64 */ + +double +__i860_fdiv_special (double x, double y) +{ + double inf = __builtin_inf (); + double sign = __builtin_copysign (1.0, x) * __builtin_copysign (1.0, y); + + if (x != x) + return x; + if (y != y) + return y; + if (y == 0) + return x == 0 ? __builtin_nan ("") : __builtin_copysign (inf, sign); + if (__builtin_isinf (y)) + return __builtin_isinf (x) ? __builtin_nan ("") : __builtin_copysign (0.0, sign); + /* The divisor is so small that its reciprocal is out of range. */ + return (x / (y * BIG)) * BIG; +} + +float +__i860_fdivs_special (float x, float y) +{ + return (float) __i860_fdiv_special (x, y); +} diff --git a/libgcc/config/i860/libgcc-i860.ver b/libgcc/config/i860/libgcc-i860.ver new file mode 100644 index 00000000000..c5ebf98de0d --- /dev/null +++ b/libgcc/config/i860/libgcc-i860.ver @@ -0,0 +1,24 @@ +# Copyright (C) 2026 Free Software Foundation, Inc. +# Copyright (C) 2026 René Rebe +# +# This file is part of GCC. +# +# GCC is free software; you can redistribute it and/or modify it under +# the terms of the GNU General Public License as published by the Free +# Software Foundation; either version 3, or (at your option) any later +# version. +# +# GCC is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +# for more details. +# +# You should have received a copy of the GNU General Public License +# along with GCC; see the file COPYING3. If not see +# . + +# Division calls these, also from shared libraries. +GCC_4.0.0 { + __i860_fdiv_special + __i860_fdivs_special +} diff --git a/libgcc/config/i860/t-i860 b/libgcc/config/i860/t-i860 new file mode 100644 index 00000000000..b078f037e30 --- /dev/null +++ b/libgcc/config/i860/t-i860 @@ -0,0 +1,27 @@ +# Copyright (C) 2026 Free Software Foundation, Inc. +# Copyright (C) 2026 René Rebe +# +# This file is part of GCC. +# +# GCC is free software; you can redistribute it and/or modify it under +# the terms of the GNU General Public License as published by the Free +# Software Foundation; either version 3, or (at your option) any later +# version. +# +# GCC is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +# for more details. +# +# You should have received a copy of the GNU General Public License +# along with GCC; see the file COPYING3. If not see +# . + +# The i860 has no integer divide instruction. +LIB2ADD += $(srcdir)/divmod.c \ + $(srcdir)/udivmod.c \ + $(srcdir)/udivmodsi4.c \ + $(srcdir)/config/i860/fdiv-special.c + +# Division calls these, also from shared libraries. +SHLIB_MAPFILES += $(srcdir)/config/i860/libgcc-i860.ver