0007-j2.patch 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364
  1. From 474d0fc7a5b32523218587cd6e79963dbc9b99c4 Mon Sep 17 00:00:00 2001
  2. From: Szabolcs Nagy <nsz@port70.net>
  3. Date: Fri, 26 Jan 2018 20:29:56 +0000
  4. Subject: [PATCH 07/13] j2
  5. ---
  6. gcc/config.gcc | 26 ++++++++++++---------
  7. gcc/config/sh/sh.c | 7 ++++++
  8. gcc/config/sh/sh.h | 15 +++++++++---
  9. gcc/config/sh/sh.opt | 4 ++++
  10. gcc/config/sh/sync.md | 54 +++++++++++++++++++++++++++++++++++++++++++
  11. gcc/config/sh/t-sh | 10 ++++----
  12. 6 files changed, 98 insertions(+), 18 deletions(-)
  13. diff --git a/gcc/config.gcc b/gcc/config.gcc
  14. index 09fb9ecd2cd..79ac206d10e 100644
  15. --- a/gcc/config.gcc
  16. +++ b/gcc/config.gcc
  17. @@ -536,7 +536,7 @@ s390*-*-*)
  18. extra_headers="s390intrin.h htmintrin.h htmxlintrin.h vecintrin.h"
  19. ;;
  20. # Note the 'l'; we need to be able to match e.g. "shle" or "shl".
  21. -sh[123456789lbe]*-*-* | sh-*-*)
  22. +sh[123456789lbej]*-*-* | sh-*-*)
  23. cpu_type=sh
  24. extra_options="${extra_options} fused-madd.opt"
  25. extra_objs="${extra_objs} sh_treg_combine.o sh-mem.o sh_optimize_sett_clrt.o"
  26. @@ -2834,18 +2834,18 @@ s390x-ibm-tpf*)
  27. extra_options="${extra_options} s390/tpf.opt"
  28. tmake_file="${tmake_file} s390/t-s390"
  29. ;;
  30. -sh-*-elf* | sh[12346l]*-*-elf* | \
  31. - sh-*-linux* | sh[2346lbe]*-*-linux* | \
  32. +sh-*-elf* | sh[12346lj]*-*-elf* | \
  33. + sh-*-linux* | sh[2346lbej]*-*-linux* | \
  34. sh-*-netbsdelf* | shl*-*-netbsdelf*)
  35. tmake_file="${tmake_file} sh/t-sh sh/t-elf"
  36. if test x${with_endian} = x; then
  37. case ${target} in
  38. - sh[1234]*be-*-* | sh[1234]*eb-*-*) with_endian=big ;;
  39. + sh[j1234]*be-*-* | sh[j1234]*eb-*-*) with_endian=big ;;
  40. shbe-*-* | sheb-*-*) with_endian=big,little ;;
  41. sh[1234]l* | sh[34]*-*-linux*) with_endian=little ;;
  42. shl* | sh*-*-linux* | \
  43. sh-superh-elf) with_endian=little,big ;;
  44. - sh[1234]*-*-*) with_endian=big ;;
  45. + sh[j1234]*-*-*) with_endian=big ;;
  46. *) with_endian=big,little ;;
  47. esac
  48. fi
  49. @@ -2912,6 +2912,7 @@ sh-*-elf* | sh[12346l]*-*-elf* | \
  50. sh2a_nofpu*) sh_cpu_target=sh2a-nofpu ;;
  51. sh2a*) sh_cpu_target=sh2a ;;
  52. sh2e*) sh_cpu_target=sh2e ;;
  53. + shj2*) sh_cpu_target=shj2;;
  54. sh2*) sh_cpu_target=sh2 ;;
  55. *) sh_cpu_target=sh1 ;;
  56. esac
  57. @@ -2933,7 +2934,7 @@ sh-*-elf* | sh[12346l]*-*-elf* | \
  58. sh2a-single-only | sh2a-single | sh2a-nofpu | sh2a | \
  59. sh4a-single-only | sh4a-single | sh4a-nofpu | sh4a | sh4al | \
  60. sh4-single-only | sh4-single | sh4-nofpu | sh4 | sh4-300 | \
  61. - sh3e | sh3 | sh2e | sh2 | sh1) ;;
  62. + sh3e | sh3 | sh2e | sh2 | sh1 | shj2) ;;
  63. "") sh_cpu_default=${sh_cpu_target} ;;
  64. *) echo "with_cpu=$with_cpu not supported"; exit 1 ;;
  65. esac
  66. @@ -2942,9 +2943,9 @@ sh-*-elf* | sh[12346l]*-*-elf* | \
  67. case ${target} in
  68. sh[1234]*) sh_multilibs=${sh_cpu_target} ;;
  69. sh-superh-*) sh_multilibs=m4,m4-single,m4-single-only,m4-nofpu ;;
  70. - sh*-*-linux*) sh_multilibs=m1,m2,m2a,m3e,m4 ;;
  71. + sh*-*-linux*) sh_multilibs=m1,m2,m2a,m3e,m4,mj2 ;;
  72. sh*-*-netbsd*) sh_multilibs=m3,m3e,m4 ;;
  73. - *) sh_multilibs=m1,m2,m2e,m4,m4-single,m4-single-only,m2a,m2a-single ;;
  74. + *) sh_multilibs=m1,m2,m2e,m4,m4-single,m4-single-only,m2a,m2a-single,mj2 ;;
  75. esac
  76. if test x$with_fp = xno; then
  77. sh_multilibs="`echo $sh_multilibs|sed -e s/m4/sh4-nofpu/ -e s/,m4-[^,]*//g -e s/,m[23]e// -e s/m2a,m2a-single/m2a-nofpu/ -e s/m5-..m....,//g`"
  78. @@ -2959,7 +2960,8 @@ sh-*-elf* | sh[12346l]*-*-elf* | \
  79. m1 | m2 | m2e | m3 | m3e | \
  80. m4 | m4-single | m4-single-only | m4-nofpu | m4-300 |\
  81. m4a | m4a-single | m4a-single-only | m4a-nofpu | m4al | \
  82. - m2a | m2a-single | m2a-single-only | m2a-nofpu)
  83. + m2a | m2a-single | m2a-single-only | m2a-nofpu | \
  84. + mj2)
  85. # TM_MULTILIB_CONFIG is used by t-sh for the non-endian multilib definition
  86. # It is passed to MULTIILIB_OPTIONS verbatim.
  87. TM_MULTILIB_CONFIG="${TM_MULTILIB_CONFIG}/${sh_multilib}"
  88. @@ -2976,7 +2978,7 @@ sh-*-elf* | sh[12346l]*-*-elf* | \
  89. done
  90. TM_MULTILIB_CONFIG=`echo $TM_MULTILIB_CONFIG | sed 's:^/::'`
  91. if test x${enable_incomplete_targets} = xyes ; then
  92. - tm_defines="$tm_defines SUPPORT_SH1=1 SUPPORT_SH2E=1 SUPPORT_SH4=1 SUPPORT_SH4_SINGLE=1 SUPPORT_SH2A=1 SUPPORT_SH2A_SINGLE=1"
  93. + tm_defines="$tm_defines SUPPORT_SH1=1 SUPPORT_SH2E=1 SUPPORT_SH4=1 SUPPORT_SH4_SINGLE=1 SUPPORT_SH2A=1 SUPPORT_SH2A_SINGLE=1 SUPPORT_SHJ2=1"
  94. fi
  95. tm_file="$tm_file ./sysroot-suffix.h"
  96. tmake_file="$tmake_file t-sysroot-suffix"
  97. @@ -4760,6 +4762,8 @@ case "${target}" in
  98. ;;
  99. m4a | m4a-single | m4a-single-only | m4a-nofpu | m4al)
  100. ;;
  101. + mj2)
  102. + ;;
  103. *)
  104. echo "Unknown CPU used in --with-cpu=$with_cpu, known values:" 1>&2
  105. echo "m1 m2 m2e m3 m3e m4 m4-single m4-single-only m4-nofpu" 1>&2
  106. @@ -4984,7 +4988,7 @@ case ${target} in
  107. tmake_file="${cpu_type}/t-${cpu_type} ${tmake_file}"
  108. ;;
  109. - sh[123456ble]*-*-* | sh-*-*)
  110. + sh[123456blej]*-*-* | sh-*-*)
  111. c_target_objs="${c_target_objs} sh-c.o"
  112. cxx_target_objs="${cxx_target_objs} sh-c.o"
  113. ;;
  114. diff --git a/gcc/config/sh/sh.c b/gcc/config/sh/sh.c
  115. index 8dc79a764df..36683614277 100644
  116. --- a/gcc/config/sh/sh.c
  117. +++ b/gcc/config/sh/sh.c
  118. @@ -686,6 +686,7 @@ parse_validate_atomic_model_option (const char* str)
  119. model_names[sh_atomic_model::hard_llcs] = "hard-llcs";
  120. model_names[sh_atomic_model::soft_tcb] = "soft-tcb";
  121. model_names[sh_atomic_model::soft_imask] = "soft-imask";
  122. + model_names[sh_atomic_model::hard_cas] = "hard-cas";
  123. const char* model_cdef_names[sh_atomic_model::num_models];
  124. model_cdef_names[sh_atomic_model::none] = "NONE";
  125. @@ -693,6 +694,7 @@ parse_validate_atomic_model_option (const char* str)
  126. model_cdef_names[sh_atomic_model::hard_llcs] = "HARD_LLCS";
  127. model_cdef_names[sh_atomic_model::soft_tcb] = "SOFT_TCB";
  128. model_cdef_names[sh_atomic_model::soft_imask] = "SOFT_IMASK";
  129. + model_cdef_names[sh_atomic_model::hard_cas] = "HARD_CAS";
  130. sh_atomic_model ret;
  131. ret.type = sh_atomic_model::none;
  132. @@ -771,6 +773,9 @@ got_mode_name:;
  133. if (ret.type == sh_atomic_model::soft_imask && TARGET_USERMODE)
  134. err_ret ("cannot use atomic model %s in user mode", ret.name);
  135. + if (ret.type == sh_atomic_model::hard_cas && !TARGET_SHJ2)
  136. + err_ret ("atomic model %s is only available J2 targets", ret.name);
  137. +
  138. return ret;
  139. #undef err_ret
  140. @@ -827,6 +832,8 @@ sh_option_override (void)
  141. sh_cpu = PROCESSOR_SH2E;
  142. if (TARGET_SH2A)
  143. sh_cpu = PROCESSOR_SH2A;
  144. + if (TARGET_SHJ2)
  145. + sh_cpu = PROCESSOR_SHJ2;
  146. if (TARGET_SH3)
  147. sh_cpu = PROCESSOR_SH3;
  148. if (TARGET_SH3E)
  149. diff --git a/gcc/config/sh/sh.h b/gcc/config/sh/sh.h
  150. index 0204872eae7..30416a34e30 100644
  151. --- a/gcc/config/sh/sh.h
  152. +++ b/gcc/config/sh/sh.h
  153. @@ -83,6 +83,7 @@ extern int code_for_indirect_jump_scratch;
  154. #define SUPPORT_SH4_SINGLE 1
  155. #define SUPPORT_SH2A 1
  156. #define SUPPORT_SH2A_SINGLE 1
  157. +#define SUPPORT_SHJ2 1
  158. #endif
  159. #define TARGET_DIVIDE_CALL_DIV1 (sh_div_strategy == SH_DIV_CALL_DIV1)
  160. @@ -115,6 +116,7 @@ extern int code_for_indirect_jump_scratch;
  161. #define SELECT_SH4A_SINGLE_ONLY (MASK_SH4A | SELECT_SH4_SINGLE_ONLY)
  162. #define SELECT_SH4A (MASK_SH4A | SELECT_SH4)
  163. #define SELECT_SH4A_SINGLE (MASK_SH4A | SELECT_SH4_SINGLE)
  164. +#define SELECT_SHJ2 (MASK_SHJ2 | SELECT_SH2)
  165. #if SUPPORT_SH1
  166. #define SUPPORT_SH2 1
  167. @@ -122,6 +124,7 @@ extern int code_for_indirect_jump_scratch;
  168. #if SUPPORT_SH2
  169. #define SUPPORT_SH3 1
  170. #define SUPPORT_SH2A_NOFPU 1
  171. +#define SUPPORT_SHJ2 1
  172. #endif
  173. #if SUPPORT_SH3
  174. #define SUPPORT_SH4_NOFPU 1
  175. @@ -154,7 +157,7 @@ extern int code_for_indirect_jump_scratch;
  176. #define MASK_ARCH (MASK_SH1 | MASK_SH2 | MASK_SH3 | MASK_SH_E | MASK_SH4 \
  177. | MASK_HARD_SH2A | MASK_HARD_SH2A_DOUBLE | MASK_SH4A \
  178. | MASK_HARD_SH4 | MASK_FPU_SINGLE \
  179. - | MASK_FPU_SINGLE_ONLY)
  180. + | MASK_FPU_SINGLE_ONLY | MASK_SHJ2)
  181. /* This defaults us to big-endian. */
  182. #ifndef TARGET_ENDIAN_DEFAULT
  183. @@ -229,7 +232,8 @@ extern int code_for_indirect_jump_scratch;
  184. %{m2a-single:--isa=sh2a} \
  185. %{m2a-single-only:--isa=sh2a} \
  186. %{m2a-nofpu:--isa=sh2a-nofpu} \
  187. -%{m4al:-dsp}"
  188. +%{m4al:-dsp} \
  189. +%{mj2:-isa=j2}"
  190. #define ASM_SPEC SH_ASM_SPEC
  191. @@ -345,6 +349,7 @@ struct sh_atomic_model
  192. hard_llcs,
  193. soft_tcb,
  194. soft_imask,
  195. + hard_cas,
  196. num_models
  197. };
  198. @@ -388,6 +393,9 @@ extern const sh_atomic_model& selected_atomic_model (void);
  199. #define TARGET_ATOMIC_SOFT_IMASK \
  200. (selected_atomic_model ().type == sh_atomic_model::soft_imask)
  201. +#define TARGET_ATOMIC_HARD_CAS \
  202. + (selected_atomic_model ().type == sh_atomic_model::hard_cas)
  203. +
  204. #endif // __cplusplus
  205. #define SUBTARGET_OVERRIDE_OPTIONS (void) 0
  206. @@ -1521,7 +1529,7 @@ extern bool current_function_interrupt;
  207. /* Nonzero if the target supports dynamic shift instructions
  208. like shad and shld. */
  209. -#define TARGET_DYNSHIFT (TARGET_SH3 || TARGET_SH2A)
  210. +#define TARGET_DYNSHIFT (TARGET_SH3 || TARGET_SH2A || TARGET_SHJ2)
  211. /* The cost of using the dynamic shift insns (shad, shld) are the same
  212. if they are available. If they are not available a library function will
  213. @@ -1784,6 +1792,7 @@ enum processor_type {
  214. PROCESSOR_SH2,
  215. PROCESSOR_SH2E,
  216. PROCESSOR_SH2A,
  217. + PROCESSOR_SHJ2,
  218. PROCESSOR_SH3,
  219. PROCESSOR_SH3E,
  220. PROCESSOR_SH4,
  221. diff --git a/gcc/config/sh/sh.opt b/gcc/config/sh/sh.opt
  222. index 8eb1a4e121a..9c28ed6b5c0 100644
  223. --- a/gcc/config/sh/sh.opt
  224. +++ b/gcc/config/sh/sh.opt
  225. @@ -65,6 +65,10 @@ m2e
  226. Target RejectNegative Condition(SUPPORT_SH2E)
  227. Generate SH2e code.
  228. +mj2
  229. +Target RejectNegative Mask(SHJ2) Condition(SUPPORT_SHJ2)
  230. +Generate J2 code.
  231. +
  232. m3
  233. Target RejectNegative Mask(SH3) Condition(SUPPORT_SH3)
  234. Generate SH3 code.
  235. diff --git a/gcc/config/sh/sync.md b/gcc/config/sh/sync.md
  236. index 691d9287101..3ffb099195d 100644
  237. --- a/gcc/config/sh/sync.md
  238. +++ b/gcc/config/sh/sync.md
  239. @@ -240,6 +240,9 @@
  240. || (TARGET_SH4A && <MODE>mode == SImode && !TARGET_ATOMIC_STRICT))
  241. atomic_insn = gen_atomic_compare_and_swap<mode>_hard (old_val, mem,
  242. exp_val, new_val);
  243. + else if (TARGET_ATOMIC_HARD_CAS && <MODE>mode == SImode)
  244. + atomic_insn = gen_atomic_compare_and_swap<mode>_cas (old_val, mem,
  245. + exp_val, new_val);
  246. else if (TARGET_ATOMIC_SOFT_GUSA)
  247. atomic_insn = gen_atomic_compare_and_swap<mode>_soft_gusa (old_val, mem,
  248. exp_val, new_val);
  249. @@ -306,6 +309,57 @@
  250. }
  251. [(set_attr "length" "14")])
  252. +(define_expand "atomic_compare_and_swapsi_cas"
  253. + [(set (match_operand:SI 0 "register_operand" "=r")
  254. + (unspec_volatile:SI
  255. + [(match_operand:SI 1 "atomic_mem_operand_0" "=Sra")
  256. + (match_operand:SI 2 "register_operand" "r")
  257. + (match_operand:SI 3 "register_operand" "r")]
  258. + UNSPECV_CMPXCHG_1))]
  259. + "TARGET_ATOMIC_HARD_CAS"
  260. +{
  261. + rtx mem = gen_rtx_REG (SImode, 0);
  262. + emit_move_insn (mem, force_reg (SImode, XEXP (operands[1], 0)));
  263. + emit_insn (gen_shj2_cas (operands[0], mem, operands[2], operands[3]));
  264. + DONE;
  265. +})
  266. +
  267. +(define_insn "shj2_cas"
  268. + [(set (match_operand:SI 0 "register_operand" "=&r")
  269. + (unspec_volatile:SI
  270. + [(match_operand:SI 1 "register_operand" "=r")
  271. + (match_operand:SI 2 "register_operand" "r")
  272. + (match_operand:SI 3 "register_operand" "0")]
  273. + UNSPECV_CMPXCHG_1))
  274. + (set (reg:SI T_REG)
  275. + (unspec_volatile:SI [(const_int 0)] UNSPECV_CMPXCHG_3))]
  276. + "TARGET_ATOMIC_HARD_CAS"
  277. + "cas.l %2,%0,@%1"
  278. + [(set_attr "length" "2")]
  279. +)
  280. +
  281. +(define_expand "atomic_compare_and_swapqi_cas"
  282. + [(set (match_operand:SI 0 "arith_reg_dest" "=&r")
  283. + (unspec_volatile:SI
  284. + [(match_operand:SI 1 "atomic_mem_operand_0" "=Sra")
  285. + (match_operand:SI 2 "arith_operand" "rI08")
  286. + (match_operand:SI 3 "arith_operand" "rI08")]
  287. + UNSPECV_CMPXCHG_1))]
  288. + "TARGET_ATOMIC_HARD_CAS"
  289. +{FAIL;}
  290. +)
  291. +
  292. +(define_expand "atomic_compare_and_swaphi_cas"
  293. + [(set (match_operand:SI 0 "arith_reg_dest" "=&r")
  294. + (unspec_volatile:SI
  295. + [(match_operand:SI 1 "atomic_mem_operand_0" "=Sra")
  296. + (match_operand:SI 2 "arith_operand" "rI08")
  297. + (match_operand:SI 3 "arith_operand" "rI08")]
  298. + UNSPECV_CMPXCHG_1))]
  299. + "TARGET_ATOMIC_HARD_CAS"
  300. +{FAIL;}
  301. +)
  302. +
  303. ;; The QIHImode llcs patterns modify the address register of the memory
  304. ;; operand. In order to express that, we have to open code the memory
  305. ;; operand. Initially the insn is expanded like every other atomic insn
  306. diff --git a/gcc/config/sh/t-sh b/gcc/config/sh/t-sh
  307. index e1a398319d5..19a6f3f7ea8 100644
  308. --- a/gcc/config/sh/t-sh
  309. +++ b/gcc/config/sh/t-sh
  310. @@ -50,7 +50,8 @@ MULTILIB_MATCHES = $(shell \
  311. m2e,m3e,m4-single-only,m4-100-single-only,m4-200-single-only,m4-300-single-only,m4a-single-only \
  312. m2a-single,m2a-single-only \
  313. m4-single,m4-100-single,m4-200-single,m4-300-single,m4a-single \
  314. - m4,m4-100,m4-200,m4-300,m4a; do \
  315. + m4,m4-100,m4-200,m4-300,m4a \
  316. + mj2; do \
  317. subst= ; \
  318. for lib in `echo $$abi|tr , ' '` ; do \
  319. if test "`echo $$multilibs|sed s/$$lib//`" != "$$multilibs"; then \
  320. @@ -63,9 +64,9 @@ MULTILIB_MATCHES = $(shell \
  321. # SH1 and SH2A support big endian only.
  322. ifeq ($(DEFAULT_ENDIAN),ml)
  323. -MULTILIB_EXCEPTIONS = m1 ml/m1 m2a* ml/m2a* $(TM_MULTILIB_EXCEPTIONS_CONFIG)
  324. +MULTILIB_EXCEPTIONS = m1 ml/m1 m2a* ml/m2a* ml/mj2 $(TM_MULTILIB_EXCEPTIONS_CONFIG)
  325. else
  326. -MULTILIB_EXCEPTIONS = ml/m1 ml/m2a* $(TM_MULTILIB_EXCEPTIONS_CONFIG)
  327. +MULTILIB_EXCEPTIONS = ml/m1 ml/m2a* ml/mj2 $(TM_MULTILIB_EXCEPTIONS_CONFIG)
  328. endif
  329. MULTILIB_OSDIRNAMES = \
  330. @@ -87,7 +88,8 @@ MULTILIB_OSDIRNAMES = \
  331. m4a-single-only=!m4a-single-only $(OTHER_ENDIAN)/m4a-single-only=!$(OTHER_ENDIAN)/m4a-single-only \
  332. m4a-single=!m4a-single $(OTHER_ENDIAN)/m4a-single=!$(OTHER_ENDIAN)/m4a-single \
  333. m4a=!m4a $(OTHER_ENDIAN)/m4a=!$(OTHER_ENDIAN)/m4a \
  334. - m4al=!m4al $(OTHER_ENDIAN)/m4al=!$(OTHER_ENDIAN)/m4al
  335. + m4al=!m4al $(OTHER_ENDIAN)/m4al=!$(OTHER_ENDIAN)/m4al \
  336. + mj2=!j2
  337. $(out_object_file): gt-sh.h
  338. gt-sh.h : s-gtype ; @true
  339. --
  340. 2.21.0