Subversion Repositories Kolibri OS

Rev

Rev 5191 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

  1. /* Basic semantics ops support for CGEN.
  2.    Copyright (C) 2005-2015 Free Software Foundation, Inc.
  3.    Contributed by Red Hat.
  4.  
  5.    This file is part of the GNU opcodes library.
  6.  
  7.    This library is free software; you can redistribute it and/or modify
  8.    it under the terms of the GNU General Public License as published by
  9.    the Free Software Foundation; either version 3, or (at your option)
  10.    any later version.
  11.  
  12.    It is distributed in the hope that it will be useful,
  13.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15.    GNU General Public License for more details.
  16.  
  17.    You should have received a copy of the GNU General Public License
  18.    along with this library; see the file COPYING3.  If not, write to the
  19.    Free Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
  20.    02110-1301, USA.  */
  21.  
  22. #ifndef CGEN_BASIC_OPS_H
  23. #define CGEN_BASIC_OPS_H
  24.  
  25. #include <assert.h>
  26.  
  27. #if defined (__GNUC__) && ! defined (SEMOPS_DEFINE_INLINE)
  28. #define SEMOPS_DEFINE_INLINE
  29. #define SEMOPS_INLINE extern inline
  30. #else
  31. #define SEMOPS_INLINE
  32. #endif
  33.  
  34. /* These don't really have a mode.  */
  35. #define ANDIF(x, y) ((x) && (y))
  36. #define ORIF(x, y) ((x) || (y))
  37.  
  38. #define SUBBI(x, y) ((x) - (y))
  39. #define ANDBI(x, y) ((x) & (y))
  40. #define ORBI(x, y) ((x) | (y))
  41. #define XORBI(x, y) ((x) ^ (y))
  42. #define NEGBI(x) (- (x))
  43. #define NOTBI(x) (! (BI) (x))
  44. #define INVBI(x) (~ (x))
  45. #define EQBI(x, y) ((BI) (x) == (BI) (y))
  46. #define NEBI(x, y) ((BI) (x) != (BI) (y))
  47. #define LTBI(x, y) ((BI) (x) < (BI) (y))
  48. #define LEBI(x, y) ((BI) (x) <= (BI) (y))
  49. #define GTBI(x, y) ((BI) (x) > (BI) (y))
  50. #define GEBI(x, y) ((BI) (x) >= (BI) (y))
  51. #define LTUBI(x, y) ((BI) (x) < (BI) (y))
  52. #define LEUBI(x, y) ((BI) (x) <= (BI) (y))
  53. #define GTUBI(x, y) ((BI) (x) > (BI) (y))
  54. #define GEUBI(x, y) ((BI) (x) >= (BI) (y))
  55. #define ADDQI(x, y) ((x) + (y))
  56. #define SUBQI(x, y) ((x) - (y))
  57. #define MULQI(x, y) ((x) * (y))
  58. #define DIVQI(x, y) ((QI) (x) / (QI) (y))
  59. #define UDIVQI(x, y) ((UQI) (x) / (UQI) (y))
  60. #define MODQI(x, y) ((QI) (x) % (QI) (y))
  61. #define UMODQI(x, y) ((UQI) (x) % (UQI) (y))
  62. #define SRAQI(x, y) ((QI) (x) >> (y))
  63. #define SRLQI(x, y) ((UQI) (x) >> (y))
  64. #define SLLQI(x, y) ((UQI) (x) << (y))
  65. extern QI RORQI (QI, int);
  66. extern QI ROLQI (QI, int);
  67. #define ANDQI(x, y) ((x) & (y))
  68. #define ORQI(x, y) ((x) | (y))
  69. #define XORQI(x, y) ((x) ^ (y))
  70. #define NEGQI(x) (- (x))
  71. #define NOTQI(x) (! (QI) (x))
  72. #define INVQI(x) (~ (x))
  73. #define ABSQI(x) ((x) < 0 ? -(x) : (x))
  74. #define EQQI(x, y) ((QI) (x) == (QI) (y))
  75. #define NEQI(x, y) ((QI) (x) != (QI) (y))
  76. #define LTQI(x, y) ((QI) (x) < (QI) (y))
  77. #define LEQI(x, y) ((QI) (x) <= (QI) (y))
  78. #define GTQI(x, y) ((QI) (x) > (QI) (y))
  79. #define GEQI(x, y) ((QI) (x) >= (QI) (y))
  80. #define LTUQI(x, y) ((UQI) (x) < (UQI) (y))
  81. #define LEUQI(x, y) ((UQI) (x) <= (UQI) (y))
  82. #define GTUQI(x, y) ((UQI) (x) > (UQI) (y))
  83. #define GEUQI(x, y) ((UQI) (x) >= (UQI) (y))
  84. #define ADDHI(x, y) ((x) + (y))
  85. #define SUBHI(x, y) ((x) - (y))
  86. #define MULHI(x, y) ((x) * (y))
  87. #define DIVHI(x, y) ((HI) (x) / (HI) (y))
  88. #define UDIVHI(x, y) ((UHI) (x) / (UHI) (y))
  89. #define MODHI(x, y) ((HI) (x) % (HI) (y))
  90. #define UMODHI(x, y) ((UHI) (x) % (UHI) (y))
  91. #define SRAHI(x, y) ((HI) (x) >> (y))
  92. #define SRLHI(x, y) ((UHI) (x) >> (y))
  93. #define SLLHI(x, y) ((UHI) (x) << (y))
  94. extern HI RORHI (HI, int);
  95. extern HI ROLHI (HI, int);
  96. #define ANDHI(x, y) ((x) & (y))
  97. #define ORHI(x, y) ((x) | (y))
  98. #define XORHI(x, y) ((x) ^ (y))
  99. #define NEGHI(x) (- (x))
  100. #define NOTHI(x) (! (HI) (x))
  101. #define INVHI(x) (~ (x))
  102. #define ABSHI(x) ((x) < 0 ? -(x) : (x))
  103. #define EQHI(x, y) ((HI) (x) == (HI) (y))
  104. #define NEHI(x, y) ((HI) (x) != (HI) (y))
  105. #define LTHI(x, y) ((HI) (x) < (HI) (y))
  106. #define LEHI(x, y) ((HI) (x) <= (HI) (y))
  107. #define GTHI(x, y) ((HI) (x) > (HI) (y))
  108. #define GEHI(x, y) ((HI) (x) >= (HI) (y))
  109. #define LTUHI(x, y) ((UHI) (x) < (UHI) (y))
  110. #define LEUHI(x, y) ((UHI) (x) <= (UHI) (y))
  111. #define GTUHI(x, y) ((UHI) (x) > (UHI) (y))
  112. #define GEUHI(x, y) ((UHI) (x) >= (UHI) (y))
  113. #define ADDSI(x, y) ((x) + (y))
  114. #define SUBSI(x, y) ((x) - (y))
  115. #define MULSI(x, y) ((x) * (y))
  116. #define DIVSI(x, y) ((SI) (x) / (SI) (y))
  117. #define UDIVSI(x, y) ((USI) (x) / (USI) (y))
  118. #define MODSI(x, y) ((SI) (x) % (SI) (y))
  119. #define UMODSI(x, y) ((USI) (x) % (USI) (y))
  120. #define SRASI(x, y) ((SI) (x) >> (y))
  121. #define SRLSI(x, y) ((USI) (x) >> (y))
  122. #define SLLSI(x, y) ((USI) (x) << (y))
  123. extern SI RORSI (SI, int);
  124. extern SI ROLSI (SI, int);
  125. #define ANDSI(x, y) ((x) & (y))
  126. #define ORSI(x, y) ((x) | (y))
  127. #define XORSI(x, y) ((x) ^ (y))
  128. #define NEGSI(x) (- (x))
  129. #define NOTSI(x) (! (SI) (x))
  130. #define INVSI(x) (~ (x))
  131. #define ABSSI(x) ((x) < 0 ? -(x) : (x))
  132. #define EQSI(x, y) ((SI) (x) == (SI) (y))
  133. #define NESI(x, y) ((SI) (x) != (SI) (y))
  134. #define LTSI(x, y) ((SI) (x) < (SI) (y))
  135. #define LESI(x, y) ((SI) (x) <= (SI) (y))
  136. #define GTSI(x, y) ((SI) (x) > (SI) (y))
  137. #define GESI(x, y) ((SI) (x) >= (SI) (y))
  138. #define LTUSI(x, y) ((USI) (x) < (USI) (y))
  139. #define LEUSI(x, y) ((USI) (x) <= (USI) (y))
  140. #define GTUSI(x, y) ((USI) (x) > (USI) (y))
  141. #define GEUSI(x, y) ((USI) (x) >= (USI) (y))
  142. #ifdef DI_FN_SUPPORT
  143. extern DI ADDDI (DI, DI);
  144. extern DI SUBDI (DI, DI);
  145. extern DI MULDI (DI, DI);
  146. extern DI DIVDI (DI, DI);
  147. extern DI UDIVDI (DI, DI);
  148. extern DI MODDI (DI, DI);
  149. extern DI UMODDI (DI, DI);
  150. extern DI SRADI (DI, int);
  151. extern UDI SRLDI (UDI, int);
  152. extern UDI SLLDI (UDI, int);
  153. extern DI RORDI (DI, int);
  154. extern DI ROLDI (DI, int);
  155. extern DI ANDDI (DI, DI);
  156. extern DI ORDI (DI, DI);
  157. extern DI XORDI (DI, DI);
  158. extern DI NEGDI (DI);
  159. extern int NOTDI (DI);
  160. extern DI INVDI (DI);
  161. extern int EQDI (DI, DI);
  162. extern int NEDI (DI, DI);
  163. extern int LTDI (DI, DI);
  164. extern int LEDI (DI, DI);
  165. extern int GTDI (DI, DI);
  166. extern int GEDI (DI, DI);
  167. extern int LTUDI (UDI, UDI);
  168. extern int LEUDI (UDI, UDI);
  169. extern int GTUDI (UDI, UDI);
  170. extern int GEUDI (UDI, UDI);
  171. #else /* ! DI_FN_SUPPORT */
  172. #define ADDDI(x, y) ((x) + (y))
  173. #define SUBDI(x, y) ((x) - (y))
  174. #define MULDI(x, y) ((x) * (y))
  175. #define DIVDI(x, y) ((DI) (x) / (DI) (y))
  176. #define UDIVDI(x, y) ((UDI) (x) / (UDI) (y))
  177. #define MODDI(x, y) ((DI) (x) % (DI) (y))
  178. #define UMODDI(x, y) ((UDI) (x) % (UDI) (y))
  179. #define SRADI(x, y) ((DI) (x) >> (y))
  180. #define SRLDI(x, y) ((UDI) (x) >> (y))
  181. #define SLLDI(x, y) ((UDI) (x) << (y))
  182. extern DI RORDI (DI, int);
  183. extern DI ROLDI (DI, int);
  184. #define ANDDI(x, y) ((x) & (y))
  185. #define ORDI(x, y) ((x) | (y))
  186. #define XORDI(x, y) ((x) ^ (y))
  187. #define NEGDI(x) (- (x))
  188. #define NOTDI(x) (! (DI) (x))
  189. #define INVDI(x) (~ (x))
  190. #define ABSDI(x) ((x) < 0 ? -(x) : (x))
  191. #define EQDI(x, y) ((DI) (x) == (DI) (y))
  192. #define NEDI(x, y) ((DI) (x) != (DI) (y))
  193. #define LTDI(x, y) ((DI) (x) < (DI) (y))
  194. #define LEDI(x, y) ((DI) (x) <= (DI) (y))
  195. #define GTDI(x, y) ((DI) (x) > (DI) (y))
  196. #define GEDI(x, y) ((DI) (x) >= (DI) (y))
  197. #define LTUDI(x, y) ((UDI) (x) < (UDI) (y))
  198. #define LEUDI(x, y) ((UDI) (x) <= (UDI) (y))
  199. #define GTUDI(x, y) ((UDI) (x) > (UDI) (y))
  200. #define GEUDI(x, y) ((UDI) (x) >= (UDI) (y))
  201. #endif /* DI_FN_SUPPORT */
  202. #define EXTBIQI(x) ((QI) (BI) (x))
  203. #define EXTBIHI(x) ((HI) (BI) (x))
  204. #define EXTBISI(x) ((SI) (BI) (x))
  205. #if defined (DI_FN_SUPPORT)
  206. extern DI EXTBIDI (BI);
  207. #else
  208. #define EXTBIDI(x) ((DI) (BI) (x))
  209. #endif
  210. #define EXTQIHI(x) ((HI) (QI) (x))
  211. #define EXTQISI(x) ((SI) (QI) (x))
  212. #if defined (DI_FN_SUPPORT)
  213. extern DI EXTQIDI (QI);
  214. #else
  215. #define EXTQIDI(x) ((DI) (QI) (x))
  216. #endif
  217. #define EXTHIHI(x) ((HI) (HI) (x))
  218. #define EXTHISI(x) ((SI) (HI) (x))
  219. #define EXTSISI(x) ((SI) (SI) (x))
  220. #if defined (DI_FN_SUPPORT)
  221. extern DI EXTHIDI (HI);
  222. #else
  223. #define EXTHIDI(x) ((DI) (HI) (x))
  224. #endif
  225. #if defined (DI_FN_SUPPORT)
  226. extern DI EXTSIDI (SI);
  227. #else
  228. #define EXTSIDI(x) ((DI) (SI) (x))
  229. #endif
  230. #define ZEXTBIQI(x) ((QI) (BI) (x))
  231. #define ZEXTBIHI(x) ((HI) (BI) (x))
  232. #define ZEXTBISI(x) ((SI) (BI) (x))
  233. #if defined (DI_FN_SUPPORT)
  234. extern DI ZEXTBIDI (BI);
  235. #else
  236. #define ZEXTBIDI(x) ((DI) (BI) (x))
  237. #endif
  238. #define ZEXTQIHI(x) ((HI) (UQI) (x))
  239. #define ZEXTQISI(x) ((SI) (UQI) (x))
  240. #if defined (DI_FN_SUPPORT)
  241. extern DI ZEXTQIDI (QI);
  242. #else
  243. #define ZEXTQIDI(x) ((DI) (UQI) (x))
  244. #endif
  245. #define ZEXTHISI(x) ((SI) (UHI) (x))
  246. #define ZEXTHIHI(x) ((HI) (UHI) (x))
  247. #define ZEXTSISI(x) ((SI) (USI) (x))
  248. #if defined (DI_FN_SUPPORT)
  249. extern DI ZEXTHIDI (HI);
  250. #else
  251. #define ZEXTHIDI(x) ((DI) (UHI) (x))
  252. #endif
  253. #if defined (DI_FN_SUPPORT)
  254. extern DI ZEXTSIDI (SI);
  255. #else
  256. #define ZEXTSIDI(x) ((DI) (USI) (x))
  257. #endif
  258. #define TRUNCQIBI(x) ((BI) (QI) (x))
  259. #define TRUNCHIBI(x) ((BI) (HI) (x))
  260. #define TRUNCHIQI(x) ((QI) (HI) (x))
  261. #define TRUNCSIBI(x) ((BI) (SI) (x))
  262. #define TRUNCSIQI(x) ((QI) (SI) (x))
  263. #define TRUNCSIHI(x) ((HI) (SI) (x))
  264. #define TRUNCSISI(x) ((SI) (SI) (x))
  265. #if defined (DI_FN_SUPPORT)
  266. extern BI TRUNCDIBI (DI);
  267. #else
  268. #define TRUNCDIBI(x) ((BI) (DI) (x))
  269. #endif
  270. #if defined (DI_FN_SUPPORT)
  271. extern QI TRUNCDIQI (DI);
  272. #else
  273. #define TRUNCDIQI(x) ((QI) (DI) (x))
  274. #endif
  275. #if defined (DI_FN_SUPPORT)
  276. extern HI TRUNCDIHI (DI);
  277. #else
  278. #define TRUNCDIHI(x) ((HI) (DI) (x))
  279. #endif
  280. #if defined (DI_FN_SUPPORT)
  281. extern SI TRUNCDISI (DI);
  282. #else
  283. #define TRUNCDISI(x) ((SI) (DI) (x))
  284. #endif
  285. /* Composing/decomposing the various types.
  286.    Word ordering is endian-independent.  Words are specified most to least
  287.    significant and word number 0 is the most significant word.
  288.    ??? May also wish an endian-dependent version.  Later.  */
  289.  
  290. static QI SUBWORDSIQI (SI, int);
  291. static HI SUBWORDSIHI (SI, int);
  292. static QI SUBWORDDIQI (DI, int);
  293. static HI SUBWORDDIHI (DI, int);
  294. static SI SUBWORDDISI (DI, int);
  295.  
  296. #ifdef SEMOPS_DEFINE_INLINE
  297.  
  298. SEMOPS_INLINE QI
  299. SUBWORDSIQI (SI in, int byte)
  300. {
  301.   assert (byte >= 0 && byte <= 3);
  302.   return (UQI) (in >> (8 * (3 - byte))) & 0xFF;
  303. }
  304.  
  305. SEMOPS_INLINE HI
  306. SUBWORDSIHI (SI in, int word)
  307. {
  308.   if (word == 0)
  309.     return (USI) in >> 16;
  310.   else
  311.     return in;
  312. }
  313.  
  314. SEMOPS_INLINE QI
  315. SUBWORDDIQI (DI in, int byte)
  316. {
  317.   assert (byte >= 0 && byte <= 7);
  318.   return (UQI) (in >> (8 * (7 - byte))) & 0xFF;
  319. }
  320.  
  321. SEMOPS_INLINE HI
  322. SUBWORDDIHI (DI in, int word)
  323. {
  324.   assert (word >= 0 && word <= 3);
  325.   return (UHI) (in >> (16 * (3 - word))) & 0xFFFF;
  326. }
  327.  
  328. SEMOPS_INLINE SI
  329. SUBWORDDISI (DI in, int word)
  330. {
  331.   if (word == 0)
  332.     return (UDI) in >> 32;
  333.   else
  334.     return in;
  335. }
  336.  
  337. #endif /* SUBWORD,JOIN */
  338.  
  339. #endif /* CGEN_BASIC_OPS_H */
  340.