You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

fixed_generic_pkg.vhdl 65KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439
  1. -- -----------------------------------------------------------------
  2. --
  3. -- Copyright 2019 IEEE P1076 WG Authors
  4. --
  5. -- See the LICENSE file distributed with this work for copyright and
  6. -- licensing information and the AUTHORS file.
  7. --
  8. -- This file to you under the Apache License, Version 2.0 (the "License").
  9. -- You may obtain a copy of the License at
  10. --
  11. -- http://www.apache.org/licenses/LICENSE-2.0
  12. --
  13. -- Unless required by applicable law or agreed to in writing, software
  14. -- distributed under the License is distributed on an "AS IS" BASIS,
  15. -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
  16. -- implied. See the License for the specific language governing
  17. -- permissions and limitations under the License.
  18. --
  19. -- Title : Fixed-point package (Generic package declaration)
  20. -- :
  21. -- Library : This package shall be compiled into a library
  22. -- : symbolically named IEEE.
  23. -- :
  24. -- Developers: Accellera VHDL-TC and IEEE P1076 Working Group
  25. -- :
  26. -- Purpose : This packages defines basic binary fixed point
  27. -- : arithmetic functions
  28. -- :
  29. -- Note : This package may be modified to include additional data
  30. -- : required by tools, but it must in no way change the
  31. -- : external interfaces or simulation behavior of the
  32. -- : description. It is permissible to add comments and/or
  33. -- : attributes to the package declarations, but not to change
  34. -- : or delete any original lines of the package declaration.
  35. -- : The package body may be changed only in accordance with
  36. -- : the terms of Clause 16 of this standard.
  37. -- :
  38. -- --------------------------------------------------------------------
  39. -- $Revision: 1220 $
  40. -- $Date: 2008-04-10 17:16:09 +0930 (Thu, 10 Apr 2008) $
  41. -- --------------------------------------------------------------------
  42. use STD.TEXTIO.all;
  43. library IEEE;
  44. use IEEE.STD_LOGIC_1164.all;
  45. use IEEE.NUMERIC_STD.all;
  46. use IEEE.fixed_float_types.all;
  47. package fixed_generic_pkg is
  48. generic (
  49. -- Rounding routine to use in fixed point, fixed_round or fixed_truncate
  50. fixed_round_style : fixed_round_style_type := fixed_round;
  51. -- Overflow routine to use in fixed point, fixed_saturate or fixed_wrap
  52. fixed_overflow_style : fixed_overflow_style_type := fixed_saturate;
  53. -- Extra bits used in divide routines
  54. fixed_guard_bits : NATURAL := 3;
  55. -- If TRUE, then turn off warnings on "X" propagation
  56. no_warning : BOOLEAN := false
  57. );
  58. -- Author David Bishop (dbishop@vhdl.org)
  59. constant CopyRightNotice : STRING :=
  60. "Copyright IEEE P1076 WG. Licensed Apache 2.0";
  61. -- base Unsigned fixed point type, downto direction assumed
  62. type UNRESOLVED_ufixed is array (INTEGER range <>) of STD_ULOGIC;
  63. -- base Signed fixed point type, downto direction assumed
  64. type UNRESOLVED_sfixed is array (INTEGER range <>) of STD_ULOGIC;
  65. alias U_ufixed is UNRESOLVED_ufixed;
  66. alias U_sfixed is UNRESOLVED_sfixed;
  67. subtype ufixed is (resolved) UNRESOLVED_ufixed;
  68. subtype sfixed is (resolved) UNRESOLVED_sfixed;
  69. --===========================================================================
  70. -- Arithmetic Operators:
  71. --===========================================================================
  72. -- Absolute value, 2's complement
  73. -- abs sfixed(a downto b) = sfixed(a+1 downto b)
  74. function "abs" (arg : UNRESOLVED_sfixed) return UNRESOLVED_sfixed;
  75. -- Negation, 2's complement
  76. -- - sfixed(a downto b) = sfixed(a+1 downto b)
  77. function "-" (arg : UNRESOLVED_sfixed)return UNRESOLVED_sfixed;
  78. -- Addition
  79. -- ufixed(a downto b) + ufixed(c downto d)
  80. -- = ufixed(maximum(a,c)+1 downto minimum(b,d))
  81. function "+" (l, r : UNRESOLVED_ufixed) return UNRESOLVED_ufixed;
  82. -- sfixed(a downto b) + sfixed(c downto d)
  83. -- = sfixed(maximum(a,c)+1 downto minimum(b,d))
  84. function "+" (l, r : UNRESOLVED_sfixed) return UNRESOLVED_sfixed;
  85. -- Subtraction
  86. -- ufixed(a downto b) - ufixed(c downto d)
  87. -- = ufixed(maximum(a,c)+1 downto minimum(b,d))
  88. function "-" (l, r : UNRESOLVED_ufixed) return UNRESOLVED_ufixed;
  89. -- sfixed(a downto b) - sfixed(c downto d)
  90. -- = sfixed(maximum(a,c)+1 downto minimum(b,d))
  91. function "-" (l, r : UNRESOLVED_sfixed) return UNRESOLVED_sfixed;
  92. -- Multiplication
  93. -- ufixed(a downto b) * ufixed(c downto d) = ufixed(a+c+1 downto b+d)
  94. function "*" (l, r : UNRESOLVED_ufixed) return UNRESOLVED_ufixed;
  95. -- sfixed(a downto b) * sfixed(c downto d) = sfixed(a+c+1 downto b+d)
  96. function "*" (l, r : UNRESOLVED_sfixed) return UNRESOLVED_sfixed;
  97. -- Division
  98. -- ufixed(a downto b) / ufixed(c downto d) = ufixed(a-d downto b-c-1)
  99. function "/" (l, r : UNRESOLVED_ufixed) return UNRESOLVED_ufixed;
  100. -- sfixed(a downto b) / sfixed(c downto d) = sfixed(a-d+1 downto b-c)
  101. function "/" (l, r : UNRESOLVED_sfixed) return UNRESOLVED_sfixed;
  102. -- Remainder
  103. -- ufixed (a downto b) rem ufixed (c downto d)
  104. -- = ufixed (minimum(a,c) downto minimum(b,d))
  105. function "rem" (l, r : UNRESOLVED_ufixed) return UNRESOLVED_ufixed;
  106. -- sfixed (a downto b) rem sfixed (c downto d)
  107. -- = sfixed (minimum(a,c) downto minimum(b,d))
  108. function "rem" (l, r : UNRESOLVED_sfixed) return UNRESOLVED_sfixed;
  109. -- Modulo
  110. -- ufixed (a downto b) mod ufixed (c downto d)
  111. -- = ufixed (minimum(a,c) downto minimum(b, d))
  112. function "mod" (l, r : UNRESOLVED_ufixed) return UNRESOLVED_ufixed;
  113. -- sfixed (a downto b) mod sfixed (c downto d)
  114. -- = sfixed (c downto minimum(b, d))
  115. function "mod" (l, r : UNRESOLVED_sfixed) return UNRESOLVED_sfixed;
  116. ----------------------------------------------------------------------------
  117. -- In these routines the "real" or "natural" (integer)
  118. -- are converted into a fixed point number and then the operation is
  119. -- performed. It is assumed that the array will be large enough.
  120. -- If the input is "real" then the real number is converted into a fixed of
  121. -- the same size as the fixed point input. If the number is an "integer"
  122. -- then it is converted into fixed with the range (l'high downto 0).
  123. ----------------------------------------------------------------------------
  124. -- ufixed(a downto b) + ufixed(a downto b) = ufixed(a+1 downto b)
  125. function "+" (l : UNRESOLVED_ufixed; r : REAL) return UNRESOLVED_ufixed;
  126. -- ufixed(c downto d) + ufixed(c downto d) = ufixed(c+1 downto d)
  127. function "+" (l : REAL; r : UNRESOLVED_ufixed) return UNRESOLVED_ufixed;
  128. -- ufixed(a downto b) + ufixed(a downto 0) = ufixed(a+1 downto minimum(0,b))
  129. function "+" (l : UNRESOLVED_ufixed; r : NATURAL) return UNRESOLVED_ufixed;
  130. -- ufixed(a downto 0) + ufixed(c downto d) = ufixed(c+1 downto minimum(0,d))
  131. function "+" (l : NATURAL; r : UNRESOLVED_ufixed) return UNRESOLVED_ufixed;
  132. -- ufixed(a downto b) - ufixed(a downto b) = ufixed(a+1 downto b)
  133. function "-" (l : UNRESOLVED_ufixed; r : REAL) return UNRESOLVED_ufixed;
  134. -- ufixed(c downto d) - ufixed(c downto d) = ufixed(c+1 downto d)
  135. function "-" (l : REAL; r : UNRESOLVED_ufixed) return UNRESOLVED_ufixed;
  136. -- ufixed(a downto b) - ufixed(a downto 0) = ufixed(a+1 downto minimum(0,b))
  137. function "-" (l : UNRESOLVED_ufixed; r : NATURAL) return UNRESOLVED_ufixed;
  138. -- ufixed(a downto 0) + ufixed(c downto d) = ufixed(c+1 downto minimum(0,d))
  139. function "-" (l : NATURAL; r : UNRESOLVED_ufixed) return UNRESOLVED_ufixed;
  140. -- ufixed(a downto b) * ufixed(a downto b) = ufixed(2a+1 downto 2b)
  141. function "*" (l : UNRESOLVED_ufixed; r : REAL) return UNRESOLVED_ufixed;
  142. -- ufixed(c downto d) * ufixed(c downto d) = ufixed(2c+1 downto 2d)
  143. function "*" (l : REAL; r : UNRESOLVED_ufixed) return UNRESOLVED_ufixed;
  144. -- ufixed (a downto b) * ufixed (a downto 0) = ufixed (2a+1 downto b)
  145. function "*" (l : UNRESOLVED_ufixed; r : NATURAL) return UNRESOLVED_ufixed;
  146. -- ufixed (a downto b) * ufixed (a downto 0) = ufixed (2a+1 downto b)
  147. function "*" (l : NATURAL; r : UNRESOLVED_ufixed) return UNRESOLVED_ufixed;
  148. -- ufixed(a downto b) / ufixed(a downto b) = ufixed(a-b downto b-a-1)
  149. function "/" (l : UNRESOLVED_ufixed; r : REAL) return UNRESOLVED_ufixed;
  150. -- ufixed(a downto b) / ufixed(a downto b) = ufixed(a-b downto b-a-1)
  151. function "/" (l : REAL; r : UNRESOLVED_ufixed) return UNRESOLVED_ufixed;
  152. -- ufixed(a downto b) / ufixed(a downto 0) = ufixed(a downto b-a-1)
  153. function "/" (l : UNRESOLVED_ufixed; r : NATURAL) return UNRESOLVED_ufixed;
  154. -- ufixed(c downto 0) / ufixed(c downto d) = ufixed(c-d downto -c-1)
  155. function "/" (l : NATURAL; r : UNRESOLVED_ufixed) return UNRESOLVED_ufixed;
  156. -- ufixed (a downto b) rem ufixed (a downto b) = ufixed (a downto b)
  157. function "rem" (l : UNRESOLVED_ufixed; r : REAL) return UNRESOLVED_ufixed;
  158. -- ufixed (c downto d) rem ufixed (c downto d) = ufixed (c downto d)
  159. function "rem" (l : REAL; r : UNRESOLVED_ufixed) return UNRESOLVED_ufixed;
  160. -- ufixed (a downto b) rem ufixed (a downto 0) = ufixed (a downto minimum(b,0))
  161. function "rem" (l : UNRESOLVED_ufixed; r : NATURAL) return UNRESOLVED_ufixed;
  162. -- ufixed (c downto 0) rem ufixed (c downto d) = ufixed (c downto minimum(d,0))
  163. function "rem" (l : NATURAL; r : UNRESOLVED_ufixed) return UNRESOLVED_ufixed;
  164. -- ufixed (a downto b) mod ufixed (a downto b) = ufixed (a downto b)
  165. function "mod" (l : UNRESOLVED_ufixed; r : REAL) return UNRESOLVED_ufixed;
  166. -- ufixed (c downto d) mod ufixed (c downto d) = ufixed (c downto d)
  167. function "mod" (l : REAL; r : UNRESOLVED_ufixed) return UNRESOLVED_ufixed;
  168. -- ufixed (a downto b) mod ufixed (a downto 0) = ufixed (a downto minimum(b,0))
  169. function "mod" (l : UNRESOLVED_ufixed; r : NATURAL) return UNRESOLVED_ufixed;
  170. -- ufixed (c downto 0) mod ufixed (c downto d) = ufixed (c downto minimum(d,0))
  171. function "mod" (l : NATURAL; r : UNRESOLVED_ufixed) return UNRESOLVED_ufixed;
  172. -- sfixed(a downto b) + sfixed(a downto b) = sfixed(a+1 downto b)
  173. function "+" (l : UNRESOLVED_sfixed; r : REAL) return UNRESOLVED_sfixed;
  174. -- sfixed(c downto d) + sfixed(c downto d) = sfixed(c+1 downto d)
  175. function "+" (l : REAL; r : UNRESOLVED_sfixed) return UNRESOLVED_sfixed;
  176. -- sfixed(a downto b) + sfixed(a downto 0) = sfixed(a+1 downto minimum(0,b))
  177. function "+" (l : UNRESOLVED_sfixed; r : INTEGER) return UNRESOLVED_sfixed;
  178. -- sfixed(c downto 0) + sfixed(c downto d) = sfixed(c+1 downto minimum(0,d))
  179. function "+" (l : INTEGER; r : UNRESOLVED_sfixed) return UNRESOLVED_sfixed;
  180. -- sfixed(a downto b) - sfixed(a downto b) = sfixed(a+1 downto b)
  181. function "-" (l : UNRESOLVED_sfixed; r : REAL) return UNRESOLVED_sfixed;
  182. -- sfixed(c downto d) - sfixed(c downto d) = sfixed(c+1 downto d)
  183. function "-" (l : REAL; r : UNRESOLVED_sfixed) return UNRESOLVED_sfixed;
  184. -- sfixed(a downto b) - sfixed(a downto 0) = sfixed(a+1 downto minimum(0,b))
  185. function "-" (l : UNRESOLVED_sfixed; r : INTEGER) return UNRESOLVED_sfixed;
  186. -- sfixed(c downto 0) - sfixed(c downto d) = sfixed(c+1 downto minimum(0,d))
  187. function "-" (l : INTEGER; r : UNRESOLVED_sfixed) return UNRESOLVED_sfixed;
  188. -- sfixed(a downto b) * sfixed(a downto b) = sfixed(2a+1 downto 2b)
  189. function "*" (l : UNRESOLVED_sfixed; r : REAL) return UNRESOLVED_sfixed;
  190. -- sfixed(c downto d) * sfixed(c downto d) = sfixed(2c+1 downto 2d)
  191. function "*" (l : REAL; r : UNRESOLVED_sfixed) return UNRESOLVED_sfixed;
  192. -- sfixed(a downto b) * sfixed(a downto 0) = sfixed(2a+1 downto b)
  193. function "*" (l : UNRESOLVED_sfixed; r : INTEGER) return UNRESOLVED_sfixed;
  194. -- sfixed(c downto 0) * sfixed(c downto d) = sfixed(2c+1 downto d)
  195. function "*" (l : INTEGER; r : UNRESOLVED_sfixed) return UNRESOLVED_sfixed;
  196. -- sfixed(a downto b) / sfixed(a downto b) = sfixed(a-b+1 downto b-a)
  197. function "/" (l : UNRESOLVED_sfixed; r : REAL) return UNRESOLVED_sfixed;
  198. -- sfixed(c downto d) / sfixed(c downto d) = sfixed(c-d+1 downto d-c)
  199. function "/" (l : REAL; r : UNRESOLVED_sfixed) return UNRESOLVED_sfixed;
  200. -- sfixed(a downto b) / sfixed(a downto 0) = sfixed(a+1 downto b-a)
  201. function "/" (l : UNRESOLVED_sfixed; r : INTEGER) return UNRESOLVED_sfixed;
  202. -- sfixed(c downto 0) / sfixed(c downto d) = sfixed(c-d+1 downto -c)
  203. function "/" (l : INTEGER; r : UNRESOLVED_sfixed) return UNRESOLVED_sfixed;
  204. -- sfixed (a downto b) rem sfixed (a downto b) = sfixed (a downto b)
  205. function "rem" (l : UNRESOLVED_sfixed; r : REAL) return UNRESOLVED_sfixed;
  206. -- sfixed (c downto d) rem sfixed (c downto d) = sfixed (c downto d)
  207. function "rem" (l : REAL; r : UNRESOLVED_sfixed) return UNRESOLVED_sfixed;
  208. -- sfixed (a downto b) rem sfixed (a downto 0) = sfixed (a downto minimum(b,0))
  209. function "rem" (l : UNRESOLVED_sfixed; r : INTEGER) return UNRESOLVED_sfixed;
  210. -- sfixed (c downto 0) rem sfixed (c downto d) = sfixed (c downto minimum(d,0))
  211. function "rem" (l : INTEGER; r : UNRESOLVED_sfixed) return UNRESOLVED_sfixed;
  212. -- sfixed (a downto b) mod sfixed (a downto b) = sfixed (a downto b)
  213. function "mod" (l : UNRESOLVED_sfixed; r : REAL) return UNRESOLVED_sfixed;
  214. -- sfixed (c downto d) mod sfixed (c downto d) = sfixed (c downto d)
  215. function "mod" (l : REAL; r : UNRESOLVED_sfixed) return UNRESOLVED_sfixed;
  216. -- sfixed (a downto b) mod sfixed (a downto 0) = sfixed (a downto minimum(b,0))
  217. function "mod" (l : UNRESOLVED_sfixed; r : INTEGER) return UNRESOLVED_sfixed;
  218. -- sfixed (c downto 0) mod sfixed (c downto d) = sfixed (c downto minimum(d,0))
  219. function "mod" (l : INTEGER; r : UNRESOLVED_sfixed) return UNRESOLVED_sfixed;
  220. -- This version of divide gives the user more control
  221. -- ufixed(a downto b) / ufixed(c downto d) = ufixed(a-d downto b-c-1)
  222. function divide (
  223. l, r : UNRESOLVED_ufixed;
  224. constant round_style : fixed_round_style_type := fixed_round_style;
  225. constant guard_bits : NATURAL := fixed_guard_bits)
  226. return UNRESOLVED_ufixed;
  227. -- This version of divide gives the user more control
  228. -- sfixed(a downto b) / sfixed(c downto d) = sfixed(a-d+1 downto b-c)
  229. function divide (
  230. l, r : UNRESOLVED_sfixed;
  231. constant round_style : fixed_round_style_type := fixed_round_style;
  232. constant guard_bits : NATURAL := fixed_guard_bits)
  233. return UNRESOLVED_sfixed;
  234. -- These functions return 1/X
  235. -- 1 / ufixed(a downto b) = ufixed(-b downto -a-1)
  236. function reciprocal (
  237. arg : UNRESOLVED_ufixed; -- fixed point input
  238. constant round_style : fixed_round_style_type := fixed_round_style;
  239. constant guard_bits : NATURAL := fixed_guard_bits)
  240. return UNRESOLVED_ufixed;
  241. -- 1 / sfixed(a downto b) = sfixed(-b+1 downto -a)
  242. function reciprocal (
  243. arg : UNRESOLVED_sfixed; -- fixed point input
  244. constant round_style : fixed_round_style_type := fixed_round_style;
  245. constant guard_bits : NATURAL := fixed_guard_bits)
  246. return UNRESOLVED_sfixed;
  247. -- REM function
  248. -- ufixed (a downto b) rem ufixed (c downto d)
  249. -- = ufixed (minimum(a,c) downto minimum(b,d))
  250. function remainder (
  251. l, r : UNRESOLVED_ufixed;
  252. constant round_style : fixed_round_style_type := fixed_round_style;
  253. constant guard_bits : NATURAL := fixed_guard_bits)
  254. return UNRESOLVED_ufixed;
  255. -- sfixed (a downto b) rem sfixed (c downto d)
  256. -- = sfixed (minimum(a,c) downto minimum(b,d))
  257. function remainder (
  258. l, r : UNRESOLVED_sfixed;
  259. constant round_style : fixed_round_style_type := fixed_round_style;
  260. constant guard_bits : NATURAL := fixed_guard_bits)
  261. return UNRESOLVED_sfixed;
  262. -- mod function
  263. -- ufixed (a downto b) mod ufixed (c downto d)
  264. -- = ufixed (minimum(a,c) downto minimum(b, d))
  265. function modulo (
  266. l, r : UNRESOLVED_ufixed;
  267. constant round_style : fixed_round_style_type := fixed_round_style;
  268. constant guard_bits : NATURAL := fixed_guard_bits)
  269. return UNRESOLVED_ufixed;
  270. -- sfixed (a downto b) mod sfixed (c downto d)
  271. -- = sfixed (c downto minimum(b, d))
  272. function modulo (
  273. l, r : UNRESOLVED_sfixed;
  274. constant overflow_style : fixed_overflow_style_type := fixed_overflow_style;
  275. constant round_style : fixed_round_style_type := fixed_round_style;
  276. constant guard_bits : NATURAL := fixed_guard_bits)
  277. return UNRESOLVED_sfixed;
  278. -- Procedure for those who need an "accumulator" function.
  279. -- add_carry (ufixed(a downto b), ufixed (c downto d))
  280. -- = ufixed (maximum(a,c) downto minimum(b,d))
  281. procedure add_carry (
  282. L, R : in UNRESOLVED_ufixed;
  283. c_in : in STD_ULOGIC;
  284. result : out UNRESOLVED_ufixed;
  285. c_out : out STD_ULOGIC);
  286. -- add_carry (sfixed(a downto b), sfixed (c downto d))
  287. -- = sfixed (maximum(a,c) downto minimum(b,d))
  288. procedure add_carry (
  289. L, R : in UNRESOLVED_sfixed;
  290. c_in : in STD_ULOGIC;
  291. result : out UNRESOLVED_sfixed;
  292. c_out : out STD_ULOGIC);
  293. -- Scales the result by a power of 2. Width of input = width of output with
  294. -- the binary point moved.
  295. function scalb (y : UNRESOLVED_ufixed; N : INTEGER) return UNRESOLVED_ufixed;
  296. function scalb (y : UNRESOLVED_ufixed; N : UNRESOLVED_SIGNED) return UNRESOLVED_ufixed;
  297. function scalb (y : UNRESOLVED_sfixed; N : INTEGER) return UNRESOLVED_sfixed;
  298. function scalb (y : UNRESOLVED_sfixed; N : UNRESOLVED_SIGNED) return UNRESOLVED_sfixed;
  299. function Is_Negative (arg : UNRESOLVED_sfixed) return BOOLEAN;
  300. --===========================================================================
  301. -- Comparison Operators
  302. --===========================================================================
  303. function ">" (l, r : UNRESOLVED_ufixed) return BOOLEAN;
  304. function ">" (l, r : UNRESOLVED_sfixed) return BOOLEAN;
  305. function "<" (l, r : UNRESOLVED_ufixed) return BOOLEAN;
  306. function "<" (l, r : UNRESOLVED_sfixed) return BOOLEAN;
  307. function "<=" (l, r : UNRESOLVED_ufixed) return BOOLEAN;
  308. function "<=" (l, r : UNRESOLVED_sfixed) return BOOLEAN;
  309. function ">=" (l, r : UNRESOLVED_ufixed) return BOOLEAN;
  310. function ">=" (l, r : UNRESOLVED_sfixed) return BOOLEAN;
  311. function "=" (l, r : UNRESOLVED_ufixed) return BOOLEAN;
  312. function "=" (l, r : UNRESOLVED_sfixed) return BOOLEAN;
  313. function "/=" (l, r : UNRESOLVED_ufixed) return BOOLEAN;
  314. function "/=" (l, r : UNRESOLVED_sfixed) return BOOLEAN;
  315. function "?=" (l, r : UNRESOLVED_ufixed) return STD_ULOGIC;
  316. function "?/=" (l, r : UNRESOLVED_ufixed) return STD_ULOGIC;
  317. function "?>" (l, r : UNRESOLVED_ufixed) return STD_ULOGIC;
  318. function "?>=" (l, r : UNRESOLVED_ufixed) return STD_ULOGIC;
  319. function "?<" (l, r : UNRESOLVED_ufixed) return STD_ULOGIC;
  320. function "?<=" (l, r : UNRESOLVED_ufixed) return STD_ULOGIC;
  321. function "?=" (l, r : UNRESOLVED_sfixed) return STD_ULOGIC;
  322. function "?/=" (l, r : UNRESOLVED_sfixed) return STD_ULOGIC;
  323. function "?>" (l, r : UNRESOLVED_sfixed) return STD_ULOGIC;
  324. function "?>=" (l, r : UNRESOLVED_sfixed) return STD_ULOGIC;
  325. function "?<" (l, r : UNRESOLVED_sfixed) return STD_ULOGIC;
  326. function "?<=" (l, r : UNRESOLVED_sfixed) return STD_ULOGIC;
  327. function std_match (l, r : UNRESOLVED_ufixed) return BOOLEAN;
  328. function std_match (l, r : UNRESOLVED_sfixed) return BOOLEAN;
  329. -- Overloads the default "maximum" and "minimum" function
  330. function maximum (l, r : UNRESOLVED_ufixed) return UNRESOLVED_ufixed;
  331. function minimum (l, r : UNRESOLVED_ufixed) return UNRESOLVED_ufixed;
  332. function maximum (l, r : UNRESOLVED_sfixed) return UNRESOLVED_sfixed;
  333. function minimum (l, r : UNRESOLVED_sfixed) return UNRESOLVED_sfixed;
  334. ----------------------------------------------------------------------------
  335. -- In these compare functions a natural is converted into a
  336. -- fixed point number of the bounds "maximum(l'high,0) downto 0"
  337. ----------------------------------------------------------------------------
  338. function "=" (l : UNRESOLVED_ufixed; r : NATURAL) return BOOLEAN;
  339. function "/=" (l : UNRESOLVED_ufixed; r : NATURAL) return BOOLEAN;
  340. function ">=" (l : UNRESOLVED_ufixed; r : NATURAL) return BOOLEAN;
  341. function "<=" (l : UNRESOLVED_ufixed; r : NATURAL) return BOOLEAN;
  342. function ">" (l : UNRESOLVED_ufixed; r : NATURAL) return BOOLEAN;
  343. function "<" (l : UNRESOLVED_ufixed; r : NATURAL) return BOOLEAN;
  344. function "=" (l : NATURAL; r : UNRESOLVED_ufixed) return BOOLEAN;
  345. function "/=" (l : NATURAL; r : UNRESOLVED_ufixed) return BOOLEAN;
  346. function ">=" (l : NATURAL; r : UNRESOLVED_ufixed) return BOOLEAN;
  347. function "<=" (l : NATURAL; r : UNRESOLVED_ufixed) return BOOLEAN;
  348. function ">" (l : NATURAL; r : UNRESOLVED_ufixed) return BOOLEAN;
  349. function "<" (l : NATURAL; r : UNRESOLVED_ufixed) return BOOLEAN;
  350. function "?=" (l : UNRESOLVED_ufixed; r : NATURAL) return STD_ULOGIC;
  351. function "?/=" (l : UNRESOLVED_ufixed; r : NATURAL) return STD_ULOGIC;
  352. function "?>=" (l : UNRESOLVED_ufixed; r : NATURAL) return STD_ULOGIC;
  353. function "?<=" (l : UNRESOLVED_ufixed; r : NATURAL) return STD_ULOGIC;
  354. function "?>" (l : UNRESOLVED_ufixed; r : NATURAL) return STD_ULOGIC;
  355. function "?<" (l : UNRESOLVED_ufixed; r : NATURAL) return STD_ULOGIC;
  356. function "?=" (l : NATURAL; r : UNRESOLVED_ufixed) return STD_ULOGIC;
  357. function "?/=" (l : NATURAL; r : UNRESOLVED_ufixed) return STD_ULOGIC;
  358. function "?>=" (l : NATURAL; r : UNRESOLVED_ufixed) return STD_ULOGIC;
  359. function "?<=" (l : NATURAL; r : UNRESOLVED_ufixed) return STD_ULOGIC;
  360. function "?>" (l : NATURAL; r : UNRESOLVED_ufixed) return STD_ULOGIC;
  361. function "?<" (l : NATURAL; r : UNRESOLVED_ufixed) return STD_ULOGIC;
  362. function maximum (l : UNRESOLVED_ufixed; r : NATURAL)
  363. return UNRESOLVED_ufixed;
  364. function minimum (l : UNRESOLVED_ufixed; r : NATURAL)
  365. return UNRESOLVED_ufixed;
  366. function maximum (l : NATURAL; r : UNRESOLVED_ufixed)
  367. return UNRESOLVED_ufixed;
  368. function minimum (l : NATURAL; r : UNRESOLVED_ufixed)
  369. return UNRESOLVED_ufixed;
  370. ----------------------------------------------------------------------------
  371. -- In these compare functions a real is converted into a
  372. -- fixed point number of the bounds "l'high+1 downto l'low"
  373. ----------------------------------------------------------------------------
  374. function "=" (l : UNRESOLVED_ufixed; r : REAL) return BOOLEAN;
  375. function "/=" (l : UNRESOLVED_ufixed; r : REAL) return BOOLEAN;
  376. function ">=" (l : UNRESOLVED_ufixed; r : REAL) return BOOLEAN;
  377. function "<=" (l : UNRESOLVED_ufixed; r : REAL) return BOOLEAN;
  378. function ">" (l : UNRESOLVED_ufixed; r : REAL) return BOOLEAN;
  379. function "<" (l : UNRESOLVED_ufixed; r : REAL) return BOOLEAN;
  380. function "=" (l : REAL; r : UNRESOLVED_ufixed) return BOOLEAN;
  381. function "/=" (l : REAL; r : UNRESOLVED_ufixed) return BOOLEAN;
  382. function ">=" (l : REAL; r : UNRESOLVED_ufixed) return BOOLEAN;
  383. function "<=" (l : REAL; r : UNRESOLVED_ufixed) return BOOLEAN;
  384. function ">" (l : REAL; r : UNRESOLVED_ufixed) return BOOLEAN;
  385. function "<" (l : REAL; r : UNRESOLVED_ufixed) return BOOLEAN;
  386. function "?=" (l : UNRESOLVED_ufixed; r : REAL) return STD_ULOGIC;
  387. function "?/=" (l : UNRESOLVED_ufixed; r : REAL) return STD_ULOGIC;
  388. function "?>=" (l : UNRESOLVED_ufixed; r : REAL) return STD_ULOGIC;
  389. function "?<=" (l : UNRESOLVED_ufixed; r : REAL) return STD_ULOGIC;
  390. function "?>" (l : UNRESOLVED_ufixed; r : REAL) return STD_ULOGIC;
  391. function "?<" (l : UNRESOLVED_ufixed; r : REAL) return STD_ULOGIC;
  392. function "?=" (l : REAL; r : UNRESOLVED_ufixed) return STD_ULOGIC;
  393. function "?/=" (l : REAL; r : UNRESOLVED_ufixed) return STD_ULOGIC;
  394. function "?>=" (l : REAL; r : UNRESOLVED_ufixed) return STD_ULOGIC;
  395. function "?<=" (l : REAL; r : UNRESOLVED_ufixed) return STD_ULOGIC;
  396. function "?>" (l : REAL; r : UNRESOLVED_ufixed) return STD_ULOGIC;
  397. function "?<" (l : REAL; r : UNRESOLVED_ufixed) return STD_ULOGIC;
  398. function maximum (l : UNRESOLVED_ufixed; r : REAL) return UNRESOLVED_ufixed;
  399. function maximum (l : REAL; r : UNRESOLVED_ufixed) return UNRESOLVED_ufixed;
  400. function minimum (l : UNRESOLVED_ufixed; r : REAL) return UNRESOLVED_ufixed;
  401. function minimum (l : REAL; r : UNRESOLVED_ufixed) return UNRESOLVED_ufixed;
  402. ----------------------------------------------------------------------------
  403. -- In these compare functions an integer is converted into a
  404. -- fixed point number of the bounds "maximum(l'high,1) downto 0"
  405. ----------------------------------------------------------------------------
  406. function "=" (l : UNRESOLVED_sfixed; r : INTEGER) return BOOLEAN;
  407. function "/=" (l : UNRESOLVED_sfixed; r : INTEGER) return BOOLEAN;
  408. function ">=" (l : UNRESOLVED_sfixed; r : INTEGER) return BOOLEAN;
  409. function "<=" (l : UNRESOLVED_sfixed; r : INTEGER) return BOOLEAN;
  410. function ">" (l : UNRESOLVED_sfixed; r : INTEGER) return BOOLEAN;
  411. function "<" (l : UNRESOLVED_sfixed; r : INTEGER) return BOOLEAN;
  412. function "=" (l : INTEGER; r : UNRESOLVED_sfixed) return BOOLEAN;
  413. function "/=" (l : INTEGER; r : UNRESOLVED_sfixed) return BOOLEAN;
  414. function ">=" (l : INTEGER; r : UNRESOLVED_sfixed) return BOOLEAN;
  415. function "<=" (l : INTEGER; r : UNRESOLVED_sfixed) return BOOLEAN;
  416. function ">" (l : INTEGER; r : UNRESOLVED_sfixed) return BOOLEAN;
  417. function "<" (l : INTEGER; r : UNRESOLVED_sfixed) return BOOLEAN;
  418. function "?=" (l : UNRESOLVED_sfixed; r : INTEGER) return STD_ULOGIC;
  419. function "?/=" (l : UNRESOLVED_sfixed; r : INTEGER) return STD_ULOGIC;
  420. function "?>=" (l : UNRESOLVED_sfixed; r : INTEGER) return STD_ULOGIC;
  421. function "?<=" (l : UNRESOLVED_sfixed; r : INTEGER) return STD_ULOGIC;
  422. function "?>" (l : UNRESOLVED_sfixed; r : INTEGER) return STD_ULOGIC;
  423. function "?<" (l : UNRESOLVED_sfixed; r : INTEGER) return STD_ULOGIC;
  424. function "?=" (l : INTEGER; r : UNRESOLVED_sfixed) return STD_ULOGIC;
  425. function "?/=" (l : INTEGER; r : UNRESOLVED_sfixed) return STD_ULOGIC;
  426. function "?>=" (l : INTEGER; r : UNRESOLVED_sfixed) return STD_ULOGIC;
  427. function "?<=" (l : INTEGER; r : UNRESOLVED_sfixed) return STD_ULOGIC;
  428. function "?>" (l : INTEGER; r : UNRESOLVED_sfixed) return STD_ULOGIC;
  429. function "?<" (l : INTEGER; r : UNRESOLVED_sfixed) return STD_ULOGIC;
  430. function maximum (l : UNRESOLVED_sfixed; r : INTEGER)
  431. return UNRESOLVED_sfixed;
  432. function maximum (l : INTEGER; r : UNRESOLVED_sfixed)
  433. return UNRESOLVED_sfixed;
  434. function minimum (l : UNRESOLVED_sfixed; r : INTEGER)
  435. return UNRESOLVED_sfixed;
  436. function minimum (l : INTEGER; r : UNRESOLVED_sfixed)
  437. return UNRESOLVED_sfixed;
  438. ----------------------------------------------------------------------------
  439. -- In these compare functions a real is converted into a
  440. -- fixed point number of the bounds "l'high+1 downto l'low"
  441. ----------------------------------------------------------------------------
  442. function "=" (l : UNRESOLVED_sfixed; r : REAL) return BOOLEAN;
  443. function "/=" (l : UNRESOLVED_sfixed; r : REAL) return BOOLEAN;
  444. function ">=" (l : UNRESOLVED_sfixed; r : REAL) return BOOLEAN;
  445. function "<=" (l : UNRESOLVED_sfixed; r : REAL) return BOOLEAN;
  446. function ">" (l : UNRESOLVED_sfixed; r : REAL) return BOOLEAN;
  447. function "<" (l : UNRESOLVED_sfixed; r : REAL) return BOOLEAN;
  448. function "=" (l : REAL; r : UNRESOLVED_sfixed) return BOOLEAN;
  449. function "/=" (l : REAL; r : UNRESOLVED_sfixed) return BOOLEAN;
  450. function ">=" (l : REAL; r : UNRESOLVED_sfixed) return BOOLEAN;
  451. function "<=" (l : REAL; r : UNRESOLVED_sfixed) return BOOLEAN;
  452. function ">" (l : REAL; r : UNRESOLVED_sfixed) return BOOLEAN;
  453. function "<" (l : REAL; r : UNRESOLVED_sfixed) return BOOLEAN;
  454. function "?=" (l : UNRESOLVED_sfixed; r : REAL) return STD_ULOGIC;
  455. function "?/=" (l : UNRESOLVED_sfixed; r : REAL) return STD_ULOGIC;
  456. function "?>=" (l : UNRESOLVED_sfixed; r : REAL) return STD_ULOGIC;
  457. function "?<=" (l : UNRESOLVED_sfixed; r : REAL) return STD_ULOGIC;
  458. function "?>" (l : UNRESOLVED_sfixed; r : REAL) return STD_ULOGIC;
  459. function "?<" (l : UNRESOLVED_sfixed; r : REAL) return STD_ULOGIC;
  460. function "?=" (l : REAL; r : UNRESOLVED_sfixed) return STD_ULOGIC;
  461. function "?/=" (l : REAL; r : UNRESOLVED_sfixed) return STD_ULOGIC;
  462. function "?>=" (l : REAL; r : UNRESOLVED_sfixed) return STD_ULOGIC;
  463. function "?<=" (l : REAL; r : UNRESOLVED_sfixed) return STD_ULOGIC;
  464. function "?>" (l : REAL; r : UNRESOLVED_sfixed) return STD_ULOGIC;
  465. function "?<" (l : REAL; r : UNRESOLVED_sfixed) return STD_ULOGIC;
  466. function maximum (l : UNRESOLVED_sfixed; r : REAL) return UNRESOLVED_sfixed;
  467. function maximum (l : REAL; r : UNRESOLVED_sfixed) return UNRESOLVED_sfixed;
  468. function minimum (l : UNRESOLVED_sfixed; r : REAL) return UNRESOLVED_sfixed;
  469. function minimum (l : REAL; r : UNRESOLVED_sfixed) return UNRESOLVED_sfixed;
  470. --===========================================================================
  471. -- Shift and Rotate Functions.
  472. -- Note that sra and sla are not the same as the BIT_VECTOR version
  473. --===========================================================================
  474. function "sll" (ARG : UNRESOLVED_ufixed; COUNT : INTEGER)
  475. return UNRESOLVED_ufixed;
  476. function "srl" (ARG : UNRESOLVED_ufixed; COUNT : INTEGER)
  477. return UNRESOLVED_ufixed;
  478. function "rol" (ARG : UNRESOLVED_ufixed; COUNT : INTEGER)
  479. return UNRESOLVED_ufixed;
  480. function "ror" (ARG : UNRESOLVED_ufixed; COUNT : INTEGER)
  481. return UNRESOLVED_ufixed;
  482. function "sla" (ARG : UNRESOLVED_ufixed; COUNT : INTEGER)
  483. return UNRESOLVED_ufixed;
  484. function "sra" (ARG : UNRESOLVED_ufixed; COUNT : INTEGER)
  485. return UNRESOLVED_ufixed;
  486. function "sll" (ARG : UNRESOLVED_sfixed; COUNT : INTEGER)
  487. return UNRESOLVED_sfixed;
  488. function "srl" (ARG : UNRESOLVED_sfixed; COUNT : INTEGER)
  489. return UNRESOLVED_sfixed;
  490. function "rol" (ARG : UNRESOLVED_sfixed; COUNT : INTEGER)
  491. return UNRESOLVED_sfixed;
  492. function "ror" (ARG : UNRESOLVED_sfixed; COUNT : INTEGER)
  493. return UNRESOLVED_sfixed;
  494. function "sla" (ARG : UNRESOLVED_sfixed; COUNT : INTEGER)
  495. return UNRESOLVED_sfixed;
  496. function "sra" (ARG : UNRESOLVED_sfixed; COUNT : INTEGER)
  497. return UNRESOLVED_sfixed;
  498. function SHIFT_LEFT (ARG : UNRESOLVED_ufixed; COUNT : NATURAL)
  499. return UNRESOLVED_ufixed;
  500. function SHIFT_RIGHT (ARG : UNRESOLVED_ufixed; COUNT : NATURAL)
  501. return UNRESOLVED_ufixed;
  502. function SHIFT_LEFT (ARG : UNRESOLVED_sfixed; COUNT : NATURAL)
  503. return UNRESOLVED_sfixed;
  504. function SHIFT_RIGHT (ARG : UNRESOLVED_sfixed; COUNT : NATURAL)
  505. return UNRESOLVED_sfixed;
  506. ----------------------------------------------------------------------------
  507. -- logical functions
  508. ----------------------------------------------------------------------------
  509. function "not" (l : UNRESOLVED_ufixed) return UNRESOLVED_ufixed;
  510. function "and" (l, r : UNRESOLVED_ufixed) return UNRESOLVED_ufixed;
  511. function "or" (l, r : UNRESOLVED_ufixed) return UNRESOLVED_ufixed;
  512. function "nand" (l, r : UNRESOLVED_ufixed) return UNRESOLVED_ufixed;
  513. function "nor" (l, r : UNRESOLVED_ufixed) return UNRESOLVED_ufixed;
  514. function "xor" (l, r : UNRESOLVED_ufixed) return UNRESOLVED_ufixed;
  515. function "xnor" (l, r : UNRESOLVED_ufixed) return UNRESOLVED_ufixed;
  516. function "not" (l : UNRESOLVED_sfixed) return UNRESOLVED_sfixed;
  517. function "and" (l, r : UNRESOLVED_sfixed) return UNRESOLVED_sfixed;
  518. function "or" (l, r : UNRESOLVED_sfixed) return UNRESOLVED_sfixed;
  519. function "nand" (l, r : UNRESOLVED_sfixed) return UNRESOLVED_sfixed;
  520. function "nor" (l, r : UNRESOLVED_sfixed) return UNRESOLVED_sfixed;
  521. function "xor" (l, r : UNRESOLVED_sfixed) return UNRESOLVED_sfixed;
  522. function "xnor" (l, r : UNRESOLVED_sfixed) return UNRESOLVED_sfixed;
  523. -- Vector and std_ulogic functions, same as functions in numeric_std
  524. function "and" (l : STD_ULOGIC; r : UNRESOLVED_ufixed)
  525. return UNRESOLVED_ufixed;
  526. function "and" (l : UNRESOLVED_ufixed; r : STD_ULOGIC)
  527. return UNRESOLVED_ufixed;
  528. function "or" (l : STD_ULOGIC; r : UNRESOLVED_ufixed)
  529. return UNRESOLVED_ufixed;
  530. function "or" (l : UNRESOLVED_ufixed; r : STD_ULOGIC)
  531. return UNRESOLVED_ufixed;
  532. function "nand" (l : STD_ULOGIC; r : UNRESOLVED_ufixed)
  533. return UNRESOLVED_ufixed;
  534. function "nand" (l : UNRESOLVED_ufixed; r : STD_ULOGIC)
  535. return UNRESOLVED_ufixed;
  536. function "nor" (l : STD_ULOGIC; r : UNRESOLVED_ufixed)
  537. return UNRESOLVED_ufixed;
  538. function "nor" (l : UNRESOLVED_ufixed; r : STD_ULOGIC)
  539. return UNRESOLVED_ufixed;
  540. function "xor" (l : STD_ULOGIC; r : UNRESOLVED_ufixed)
  541. return UNRESOLVED_ufixed;
  542. function "xor" (l : UNRESOLVED_ufixed; r : STD_ULOGIC)
  543. return UNRESOLVED_ufixed;
  544. function "xnor" (l : STD_ULOGIC; r : UNRESOLVED_ufixed)
  545. return UNRESOLVED_ufixed;
  546. function "xnor" (l : UNRESOLVED_ufixed; r : STD_ULOGIC)
  547. return UNRESOLVED_ufixed;
  548. function "and" (l : STD_ULOGIC; r : UNRESOLVED_sfixed)
  549. return UNRESOLVED_sfixed;
  550. function "and" (l : UNRESOLVED_sfixed; r : STD_ULOGIC)
  551. return UNRESOLVED_sfixed;
  552. function "or" (l : STD_ULOGIC; r : UNRESOLVED_sfixed)
  553. return UNRESOLVED_sfixed;
  554. function "or" (l : UNRESOLVED_sfixed; r : STD_ULOGIC)
  555. return UNRESOLVED_sfixed;
  556. function "nand" (l : STD_ULOGIC; r : UNRESOLVED_sfixed)
  557. return UNRESOLVED_sfixed;
  558. function "nand" (l : UNRESOLVED_sfixed; r : STD_ULOGIC)
  559. return UNRESOLVED_sfixed;
  560. function "nor" (l : STD_ULOGIC; r : UNRESOLVED_sfixed)
  561. return UNRESOLVED_sfixed;
  562. function "nor" (l : UNRESOLVED_sfixed; r : STD_ULOGIC)
  563. return UNRESOLVED_sfixed;
  564. function "xor" (l : STD_ULOGIC; r : UNRESOLVED_sfixed)
  565. return UNRESOLVED_sfixed;
  566. function "xor" (l : UNRESOLVED_sfixed; r : STD_ULOGIC)
  567. return UNRESOLVED_sfixed;
  568. function "xnor" (l : STD_ULOGIC; r : UNRESOLVED_sfixed)
  569. return UNRESOLVED_sfixed;
  570. function "xnor" (l : UNRESOLVED_sfixed; r : STD_ULOGIC)
  571. return UNRESOLVED_sfixed;
  572. -- Reduction operators, same as numeric_std functions
  573. function "and" (l : UNRESOLVED_ufixed) return STD_ULOGIC;
  574. function "nand" (l : UNRESOLVED_ufixed) return STD_ULOGIC;
  575. function "or" (l : UNRESOLVED_ufixed) return STD_ULOGIC;
  576. function "nor" (l : UNRESOLVED_ufixed) return STD_ULOGIC;
  577. function "xor" (l : UNRESOLVED_ufixed) return STD_ULOGIC;
  578. function "xnor" (l : UNRESOLVED_ufixed) return STD_ULOGIC;
  579. function "and" (l : UNRESOLVED_sfixed) return STD_ULOGIC;
  580. function "nand" (l : UNRESOLVED_sfixed) return STD_ULOGIC;
  581. function "or" (l : UNRESOLVED_sfixed) return STD_ULOGIC;
  582. function "nor" (l : UNRESOLVED_sfixed) return STD_ULOGIC;
  583. function "xor" (l : UNRESOLVED_sfixed) return STD_ULOGIC;
  584. function "xnor" (l : UNRESOLVED_sfixed) return STD_ULOGIC;
  585. -- returns arg'low-1 if not found
  586. function find_leftmost (arg : UNRESOLVED_ufixed; y : STD_ULOGIC)
  587. return INTEGER;
  588. function find_leftmost (arg : UNRESOLVED_sfixed; y : STD_ULOGIC)
  589. return INTEGER;
  590. -- returns arg'high+1 if not found
  591. function find_rightmost (arg : UNRESOLVED_ufixed; y : STD_ULOGIC)
  592. return INTEGER;
  593. function find_rightmost (arg : UNRESOLVED_sfixed; y : STD_ULOGIC)
  594. return INTEGER;
  595. --===========================================================================
  596. -- RESIZE Functions
  597. --===========================================================================
  598. -- resizes the number (larger or smaller)
  599. -- The returned result will be ufixed (left_index downto right_index)
  600. -- If "round_style" is fixed_round, then the result will be rounded.
  601. -- If the MSB of the remainder is a "1" AND the LSB of the unrounded result
  602. -- is a '1' or the lower bits of the remainder include a '1' then the result
  603. -- will be increased by the smallest representable number for that type.
  604. -- "overflow_style" can be fixed_saturate or fixed_wrap.
  605. -- In saturate mode, if the number overflows then the largest possible
  606. -- representable number is returned. If wrap mode, then the upper bits
  607. -- of the number are truncated.
  608. function resize (
  609. arg : UNRESOLVED_ufixed; -- input
  610. constant left_index : INTEGER; -- integer portion
  611. constant right_index : INTEGER; -- size of fraction
  612. constant overflow_style : fixed_overflow_style_type := fixed_overflow_style;
  613. constant round_style : fixed_round_style_type := fixed_round_style)
  614. return UNRESOLVED_ufixed;
  615. -- "size_res" functions create the size of the output from the indices
  616. -- of the "size_res" input. The actual value of "size_res" is not used.
  617. function resize (
  618. arg : UNRESOLVED_ufixed; -- input
  619. size_res : UNRESOLVED_ufixed; -- for size only
  620. constant overflow_style : fixed_overflow_style_type := fixed_overflow_style;
  621. constant round_style : fixed_round_style_type := fixed_round_style)
  622. return UNRESOLVED_ufixed;
  623. -- Note that in "wrap" mode the sign bit is not replicated. Thus the
  624. -- resize of a negative number can have a positive result in wrap mode.
  625. function resize (
  626. arg : UNRESOLVED_sfixed; -- input
  627. constant left_index : INTEGER; -- integer portion
  628. constant right_index : INTEGER; -- size of fraction
  629. constant overflow_style : fixed_overflow_style_type := fixed_overflow_style;
  630. constant round_style : fixed_round_style_type := fixed_round_style)
  631. return UNRESOLVED_sfixed;
  632. function resize (
  633. arg : UNRESOLVED_sfixed; -- input
  634. size_res : UNRESOLVED_sfixed; -- for size only
  635. constant overflow_style : fixed_overflow_style_type := fixed_overflow_style;
  636. constant round_style : fixed_round_style_type := fixed_round_style)
  637. return UNRESOLVED_sfixed;
  638. --===========================================================================
  639. -- Conversion Functions
  640. --===========================================================================
  641. -- integer (natural) to unsigned fixed point.
  642. -- arguments are the upper and lower bounds of the number, thus
  643. -- ufixed (7 downto -3) <= to_ufixed (int, 7, -3);
  644. function to_ufixed (
  645. arg : NATURAL; -- integer
  646. constant left_index : INTEGER; -- left index (high index)
  647. constant right_index : INTEGER := 0; -- right index
  648. constant overflow_style : fixed_overflow_style_type := fixed_overflow_style;
  649. constant round_style : fixed_round_style_type := fixed_round_style)
  650. return UNRESOLVED_ufixed;
  651. function to_ufixed (
  652. arg : NATURAL; -- integer
  653. size_res : UNRESOLVED_ufixed; -- for size only
  654. constant overflow_style : fixed_overflow_style_type := fixed_overflow_style;
  655. constant round_style : fixed_round_style_type := fixed_round_style)
  656. return UNRESOLVED_ufixed;
  657. -- real to unsigned fixed point
  658. function to_ufixed (
  659. arg : REAL; -- real
  660. constant left_index : INTEGER; -- left index (high index)
  661. constant right_index : INTEGER; -- right index
  662. constant overflow_style : fixed_overflow_style_type := fixed_overflow_style;
  663. constant round_style : fixed_round_style_type := fixed_round_style;
  664. constant guard_bits : NATURAL := fixed_guard_bits)
  665. return UNRESOLVED_ufixed;
  666. function to_ufixed (
  667. arg : REAL; -- real
  668. size_res : UNRESOLVED_ufixed; -- for size only
  669. constant overflow_style : fixed_overflow_style_type := fixed_overflow_style;
  670. constant round_style : fixed_round_style_type := fixed_round_style;
  671. constant guard_bits : NATURAL := fixed_guard_bits)
  672. return UNRESOLVED_ufixed;
  673. -- unsigned to unsigned fixed point
  674. function to_ufixed (
  675. arg : UNRESOLVED_UNSIGNED; -- unsigned
  676. constant left_index : INTEGER; -- left index (high index)
  677. constant right_index : INTEGER := 0; -- right index
  678. constant overflow_style : fixed_overflow_style_type := fixed_overflow_style;
  679. constant round_style : fixed_round_style_type := fixed_round_style)
  680. return UNRESOLVED_ufixed;
  681. function to_ufixed (
  682. arg : UNRESOLVED_UNSIGNED; -- unsigned
  683. size_res : UNRESOLVED_ufixed; -- for size only
  684. constant overflow_style : fixed_overflow_style_type := fixed_overflow_style;
  685. constant round_style : fixed_round_style_type := fixed_round_style)
  686. return UNRESOLVED_ufixed;
  687. -- Performs a conversion. ufixed (arg'range) is returned
  688. function to_ufixed (
  689. arg : UNRESOLVED_UNSIGNED) -- unsigned
  690. return UNRESOLVED_ufixed;
  691. -- unsigned fixed point to unsigned
  692. function to_unsigned (
  693. arg : UNRESOLVED_ufixed; -- fixed point input
  694. constant size : NATURAL; -- length of output
  695. constant overflow_style : fixed_overflow_style_type := fixed_overflow_style;
  696. constant round_style : fixed_round_style_type := fixed_round_style)
  697. return UNRESOLVED_UNSIGNED;
  698. -- unsigned fixed point to unsigned
  699. function to_unsigned (
  700. arg : UNRESOLVED_ufixed; -- fixed point input
  701. size_res : UNRESOLVED_UNSIGNED; -- used for length of output
  702. constant overflow_style : fixed_overflow_style_type := fixed_overflow_style;
  703. constant round_style : fixed_round_style_type := fixed_round_style)
  704. return UNRESOLVED_UNSIGNED;
  705. -- unsigned fixed point to real
  706. function to_real (
  707. arg : UNRESOLVED_ufixed) -- fixed point input
  708. return REAL;
  709. -- unsigned fixed point to integer
  710. function to_integer (
  711. arg : UNRESOLVED_ufixed; -- fixed point input
  712. constant overflow_style : fixed_overflow_style_type := fixed_overflow_style;
  713. constant round_style : fixed_round_style_type := fixed_round_style)
  714. return NATURAL;
  715. -- Integer to UNRESOLVED_sfixed
  716. function to_sfixed (
  717. arg : INTEGER; -- integer
  718. constant left_index : INTEGER; -- left index (high index)
  719. constant right_index : INTEGER := 0; -- right index
  720. constant overflow_style : fixed_overflow_style_type := fixed_overflow_style;
  721. constant round_style : fixed_round_style_type := fixed_round_style)
  722. return UNRESOLVED_sfixed;
  723. function to_sfixed (
  724. arg : INTEGER; -- integer
  725. size_res : UNRESOLVED_sfixed; -- for size only
  726. constant overflow_style : fixed_overflow_style_type := fixed_overflow_style;
  727. constant round_style : fixed_round_style_type := fixed_round_style)
  728. return UNRESOLVED_sfixed;
  729. -- Real to sfixed
  730. function to_sfixed (
  731. arg : REAL; -- real
  732. constant left_index : INTEGER; -- left index (high index)
  733. constant right_index : INTEGER; -- right index
  734. constant overflow_style : fixed_overflow_style_type := fixed_overflow_style;
  735. constant round_style : fixed_round_style_type := fixed_round_style;
  736. constant guard_bits : NATURAL := fixed_guard_bits)
  737. return UNRESOLVED_sfixed;
  738. function to_sfixed (
  739. arg : REAL; -- real
  740. size_res : UNRESOLVED_sfixed; -- for size only
  741. constant overflow_style : fixed_overflow_style_type := fixed_overflow_style;
  742. constant round_style : fixed_round_style_type := fixed_round_style;
  743. constant guard_bits : NATURAL := fixed_guard_bits)
  744. return UNRESOLVED_sfixed;
  745. -- signed to sfixed
  746. function to_sfixed (
  747. arg : UNRESOLVED_SIGNED; -- signed
  748. constant left_index : INTEGER; -- left index (high index)
  749. constant right_index : INTEGER := 0; -- right index
  750. constant overflow_style : fixed_overflow_style_type := fixed_overflow_style;
  751. constant round_style : fixed_round_style_type := fixed_round_style)
  752. return UNRESOLVED_sfixed;
  753. function to_sfixed (
  754. arg : UNRESOLVED_SIGNED; -- signed
  755. size_res : UNRESOLVED_sfixed; -- for size only
  756. constant overflow_style : fixed_overflow_style_type := fixed_overflow_style;
  757. constant round_style : fixed_round_style_type := fixed_round_style)
  758. return UNRESOLVED_sfixed;
  759. -- signed to sfixed (output assumed to be size of signed input)
  760. function to_sfixed (
  761. arg : UNRESOLVED_SIGNED) -- signed
  762. return UNRESOLVED_sfixed;
  763. -- Conversion from ufixed to sfixed
  764. function to_sfixed (
  765. arg : UNRESOLVED_ufixed)
  766. return UNRESOLVED_sfixed;
  767. -- signed fixed point to signed
  768. function to_signed (
  769. arg : UNRESOLVED_sfixed; -- fixed point input
  770. constant size : NATURAL; -- length of output
  771. constant overflow_style : fixed_overflow_style_type := fixed_overflow_style;
  772. constant round_style : fixed_round_style_type := fixed_round_style)
  773. return UNRESOLVED_SIGNED;
  774. -- signed fixed point to signed
  775. function to_signed (
  776. arg : UNRESOLVED_sfixed; -- fixed point input
  777. size_res : UNRESOLVED_SIGNED; -- used for length of output
  778. constant overflow_style : fixed_overflow_style_type := fixed_overflow_style;
  779. constant round_style : fixed_round_style_type := fixed_round_style)
  780. return UNRESOLVED_SIGNED;
  781. -- signed fixed point to real
  782. function to_real (
  783. arg : UNRESOLVED_sfixed) -- fixed point input
  784. return REAL;
  785. -- signed fixed point to integer
  786. function to_integer (
  787. arg : UNRESOLVED_sfixed; -- fixed point input
  788. constant overflow_style : fixed_overflow_style_type := fixed_overflow_style;
  789. constant round_style : fixed_round_style_type := fixed_round_style)
  790. return INTEGER;
  791. -- Because of the fairly complicated sizing rules in the fixed point
  792. -- packages these functions are provided to compute the result ranges
  793. -- Example:
  794. -- signal uf1 : ufixed (3 downto -3);
  795. -- signal uf2 : ufixed (4 downto -2);
  796. -- signal uf1multuf2 : ufixed (ufixed_high (3, -3, '*', 4, -2) downto
  797. -- ufixed_low (3, -3, '*', 4, -2));
  798. -- uf1multuf2 <= uf1 * uf2;
  799. -- Valid characters: '+', '-', '*', '/', 'r' or 'R' (rem), 'm' or 'M' (mod),
  800. -- '1' (reciprocal), 'a' or 'A' (abs), 'n' or 'N' (unary -)
  801. function ufixed_high (left_index, right_index : INTEGER;
  802. operation : CHARACTER := 'X';
  803. left_index2, right_index2 : INTEGER := 0)
  804. return INTEGER;
  805. function ufixed_low (left_index, right_index : INTEGER;
  806. operation : CHARACTER := 'X';
  807. left_index2, right_index2 : INTEGER := 0)
  808. return INTEGER;
  809. function sfixed_high (left_index, right_index : INTEGER;
  810. operation : CHARACTER := 'X';
  811. left_index2, right_index2 : INTEGER := 0)
  812. return INTEGER;
  813. function sfixed_low (left_index, right_index : INTEGER;
  814. operation : CHARACTER := 'X';
  815. left_index2, right_index2 : INTEGER := 0)
  816. return INTEGER;
  817. -- Same as above, but using the "size_res" input only for their ranges:
  818. -- signal uf1multuf2 : ufixed (ufixed_high (uf1, '*', uf2) downto
  819. -- ufixed_low (uf1, '*', uf2));
  820. -- uf1multuf2 <= uf1 * uf2;
  821. --
  822. function ufixed_high (size_res : UNRESOLVED_ufixed;
  823. operation : CHARACTER := 'X';
  824. size_res2 : UNRESOLVED_ufixed)
  825. return INTEGER;
  826. function ufixed_low (size_res : UNRESOLVED_ufixed;
  827. operation : CHARACTER := 'X';
  828. size_res2 : UNRESOLVED_ufixed)
  829. return INTEGER;
  830. function sfixed_high (size_res : UNRESOLVED_sfixed;
  831. operation : CHARACTER := 'X';
  832. size_res2 : UNRESOLVED_sfixed)
  833. return INTEGER;
  834. function sfixed_low (size_res : UNRESOLVED_sfixed;
  835. operation : CHARACTER := 'X';
  836. size_res2 : UNRESOLVED_sfixed)
  837. return INTEGER;
  838. -- purpose: returns a saturated number
  839. function saturate (
  840. constant left_index : INTEGER;
  841. constant right_index : INTEGER)
  842. return UNRESOLVED_ufixed;
  843. -- purpose: returns a saturated number
  844. function saturate (
  845. constant left_index : INTEGER;
  846. constant right_index : INTEGER)
  847. return UNRESOLVED_sfixed;
  848. function saturate (
  849. size_res : UNRESOLVED_ufixed) -- only the size of this is used
  850. return UNRESOLVED_ufixed;
  851. function saturate (
  852. size_res : UNRESOLVED_sfixed) -- only the size of this is used
  853. return UNRESOLVED_sfixed;
  854. --===========================================================================
  855. -- Translation Functions
  856. --===========================================================================
  857. -- maps meta-logical values
  858. function to_01 (
  859. s : UNRESOLVED_ufixed; -- fixed point input
  860. constant XMAP : STD_ULOGIC := '0') -- Map x to
  861. return UNRESOLVED_ufixed;
  862. -- maps meta-logical values
  863. function to_01 (
  864. s : UNRESOLVED_sfixed; -- fixed point input
  865. constant XMAP : STD_ULOGIC := '0') -- Map x to
  866. return UNRESOLVED_sfixed;
  867. function Is_X (arg : UNRESOLVED_ufixed) return BOOLEAN;
  868. function Is_X (arg : UNRESOLVED_sfixed) return BOOLEAN;
  869. function to_X01 (arg : UNRESOLVED_ufixed) return UNRESOLVED_ufixed;
  870. function to_X01 (arg : UNRESOLVED_sfixed) return UNRESOLVED_sfixed;
  871. function to_X01Z (arg : UNRESOLVED_ufixed) return UNRESOLVED_ufixed;
  872. function to_X01Z (arg : UNRESOLVED_sfixed) return UNRESOLVED_sfixed;
  873. function to_UX01 (arg : UNRESOLVED_ufixed) return UNRESOLVED_ufixed;
  874. function to_UX01 (arg : UNRESOLVED_sfixed) return UNRESOLVED_sfixed;
  875. -- straight vector conversion routines, needed for synthesis.
  876. -- These functions are here so that a std_logic_vector can be
  877. -- converted to and from sfixed and ufixed. Note that you can
  878. -- not convert these vectors because of their negative index.
  879. function to_slv (
  880. arg : UNRESOLVED_ufixed) -- fixed point vector
  881. return STD_LOGIC_VECTOR;
  882. alias to_StdLogicVector is to_slv [UNRESOLVED_ufixed
  883. return STD_LOGIC_VECTOR];
  884. alias to_Std_Logic_Vector is to_slv [UNRESOLVED_ufixed
  885. return STD_LOGIC_VECTOR];
  886. function to_slv (
  887. arg : UNRESOLVED_sfixed) -- fixed point vector
  888. return STD_LOGIC_VECTOR;
  889. alias to_StdLogicVector is to_slv [UNRESOLVED_sfixed
  890. return STD_LOGIC_VECTOR];
  891. alias to_Std_Logic_Vector is to_slv [UNRESOLVED_sfixed
  892. return STD_LOGIC_VECTOR];
  893. function to_sulv (
  894. arg : UNRESOLVED_ufixed) -- fixed point vector
  895. return STD_ULOGIC_VECTOR;
  896. alias to_StdULogicVector is to_sulv [UNRESOLVED_ufixed
  897. return STD_ULOGIC_VECTOR];
  898. alias to_Std_ULogic_Vector is to_sulv [UNRESOLVED_ufixed
  899. return STD_ULOGIC_VECTOR];
  900. function to_sulv (
  901. arg : UNRESOLVED_sfixed) -- fixed point vector
  902. return STD_ULOGIC_VECTOR;
  903. alias to_StdULogicVector is to_sulv [UNRESOLVED_sfixed
  904. return STD_ULOGIC_VECTOR];
  905. alias to_Std_ULogic_Vector is to_sulv [UNRESOLVED_sfixed
  906. return STD_ULOGIC_VECTOR];
  907. function to_ufixed (
  908. arg : STD_ULOGIC_VECTOR; -- shifted vector
  909. constant left_index : INTEGER;
  910. constant right_index : INTEGER)
  911. return UNRESOLVED_ufixed;
  912. function to_ufixed (
  913. arg : STD_ULOGIC_VECTOR; -- shifted vector
  914. size_res : UNRESOLVED_ufixed) -- for size only
  915. return UNRESOLVED_ufixed;
  916. function to_sfixed (
  917. arg : STD_ULOGIC_VECTOR; -- shifted vector
  918. constant left_index : INTEGER;
  919. constant right_index : INTEGER)
  920. return UNRESOLVED_sfixed;
  921. function to_sfixed (
  922. arg : STD_ULOGIC_VECTOR; -- shifted vector
  923. size_res : UNRESOLVED_sfixed) -- for size only
  924. return UNRESOLVED_sfixed;
  925. -- As a concession to those who use a graphical DSP environment,
  926. -- these functions take parameters in those tools format and create
  927. -- fixed point numbers. These functions are designed to convert from
  928. -- a std_logic_vector to the VHDL fixed point format using the conventions
  929. -- of these packages. In a pure VHDL environment you should use the
  930. -- "to_ufixed" and "to_sfixed" routines.
  931. -- unsigned fixed point
  932. function to_UFix (
  933. arg : STD_ULOGIC_VECTOR;
  934. width : NATURAL; -- width of vector
  935. fraction : NATURAL) -- width of fraction
  936. return UNRESOLVED_ufixed;
  937. -- signed fixed point
  938. function to_SFix (
  939. arg : STD_ULOGIC_VECTOR;
  940. width : NATURAL; -- width of vector
  941. fraction : NATURAL) -- width of fraction
  942. return UNRESOLVED_sfixed;
  943. -- finding the bounds of a number. These functions can be used like this:
  944. -- signal xxx : ufixed (7 downto -3);
  945. -- -- Which is the same as "ufixed (UFix_high (11,3) downto UFix_low(11,3))"
  946. -- signal yyy : ufixed (UFix_high (11, 3, "+", 11, 3)
  947. -- downto UFix_low(11, 3, "+", 11, 3));
  948. -- Where "11" is the width of xxx (xxx'length),
  949. -- and 3 is the lower bound (abs (xxx'low))
  950. -- In a pure VHDL environment use "ufixed_high" and "ufixed_low"
  951. function UFix_high (width, fraction : NATURAL;
  952. operation : CHARACTER := 'X';
  953. width2, fraction2 : NATURAL := 0)
  954. return INTEGER;
  955. function UFix_low (width, fraction : NATURAL;
  956. operation : CHARACTER := 'X';
  957. width2, fraction2 : NATURAL := 0)
  958. return INTEGER;
  959. -- Same as above but for signed fixed point. Note that the width
  960. -- of a signed fixed point number ignores the sign bit, thus
  961. -- width = sxxx'length-1
  962. function SFix_high (width, fraction : NATURAL;
  963. operation : CHARACTER := 'X';
  964. width2, fraction2 : NATURAL := 0)
  965. return INTEGER;
  966. function SFix_low (width, fraction : NATURAL;
  967. operation : CHARACTER := 'X';
  968. width2, fraction2 : NATURAL := 0)
  969. return INTEGER;
  970. --===========================================================================
  971. -- string and textio Functions
  972. --===========================================================================
  973. -- purpose: writes fixed point into a line
  974. procedure WRITE (
  975. L : inout LINE; -- input line
  976. VALUE : in UNRESOLVED_ufixed; -- fixed point input
  977. JUSTIFIED : in SIDE := right;
  978. FIELD : in WIDTH := 0);
  979. -- purpose: writes fixed point into a line
  980. procedure WRITE (
  981. L : inout LINE; -- input line
  982. VALUE : in UNRESOLVED_sfixed; -- fixed point input
  983. JUSTIFIED : in SIDE := right;
  984. FIELD : in WIDTH := 0);
  985. procedure READ(L : inout LINE;
  986. VALUE : out UNRESOLVED_ufixed);
  987. procedure READ(L : inout LINE;
  988. VALUE : out UNRESOLVED_ufixed;
  989. GOOD : out BOOLEAN);
  990. procedure READ(L : inout LINE;
  991. VALUE : out UNRESOLVED_sfixed);
  992. procedure READ(L : inout LINE;
  993. VALUE : out UNRESOLVED_sfixed;
  994. GOOD : out BOOLEAN);
  995. alias bwrite is WRITE [LINE, UNRESOLVED_ufixed, SIDE, width];
  996. alias bwrite is WRITE [LINE, UNRESOLVED_sfixed, SIDE, width];
  997. alias bread is READ [LINE, UNRESOLVED_ufixed];
  998. alias bread is READ [LINE, UNRESOLVED_ufixed, BOOLEAN];
  999. alias bread is READ [LINE, UNRESOLVED_sfixed];
  1000. alias bread is READ [LINE, UNRESOLVED_sfixed, BOOLEAN];
  1001. alias BINARY_WRITE is WRITE [LINE, UNRESOLVED_ufixed, SIDE, width];
  1002. alias BINARY_WRITE is WRITE [LINE, UNRESOLVED_sfixed, SIDE, width];
  1003. alias BINARY_READ is READ [LINE, UNRESOLVED_ufixed, BOOLEAN];
  1004. alias BINARY_READ is READ [LINE, UNRESOLVED_ufixed];
  1005. alias BINARY_READ is READ [LINE, UNRESOLVED_sfixed, BOOLEAN];
  1006. alias BINARY_READ is READ [LINE, UNRESOLVED_sfixed];
  1007. -- octal read and write
  1008. procedure OWRITE (
  1009. L : inout LINE; -- input line
  1010. VALUE : in UNRESOLVED_ufixed; -- fixed point input
  1011. JUSTIFIED : in SIDE := right;
  1012. FIELD : in WIDTH := 0);
  1013. procedure OWRITE (
  1014. L : inout LINE; -- input line
  1015. VALUE : in UNRESOLVED_sfixed; -- fixed point input
  1016. JUSTIFIED : in SIDE := right;
  1017. FIELD : in WIDTH := 0);
  1018. procedure OREAD(L : inout LINE;
  1019. VALUE : out UNRESOLVED_ufixed);
  1020. procedure OREAD(L : inout LINE;
  1021. VALUE : out UNRESOLVED_ufixed;
  1022. GOOD : out BOOLEAN);
  1023. procedure OREAD(L : inout LINE;
  1024. VALUE : out UNRESOLVED_sfixed);
  1025. procedure OREAD(L : inout LINE;
  1026. VALUE : out UNRESOLVED_sfixed;
  1027. GOOD : out BOOLEAN);
  1028. alias OCTAL_READ is OREAD [LINE, UNRESOLVED_ufixed, BOOLEAN];
  1029. alias OCTAL_READ is OREAD [LINE, UNRESOLVED_ufixed];
  1030. alias OCTAL_READ is OREAD [LINE, UNRESOLVED_sfixed, BOOLEAN];
  1031. alias OCTAL_READ is OREAD [LINE, UNRESOLVED_sfixed];
  1032. alias OCTAL_WRITE is OWRITE [LINE, UNRESOLVED_ufixed, SIDE, WIDTH];
  1033. alias OCTAL_WRITE is OWRITE [LINE, UNRESOLVED_sfixed, SIDE, WIDTH];
  1034. -- hex read and write
  1035. procedure HWRITE (
  1036. L : inout LINE; -- input line
  1037. VALUE : in UNRESOLVED_ufixed; -- fixed point input
  1038. JUSTIFIED : in SIDE := right;
  1039. FIELD : in WIDTH := 0);
  1040. -- purpose: writes fixed point into a line
  1041. procedure HWRITE (
  1042. L : inout LINE; -- input line
  1043. VALUE : in UNRESOLVED_sfixed; -- fixed point input
  1044. JUSTIFIED : in SIDE := right;
  1045. FIELD : in WIDTH := 0);
  1046. procedure HREAD(L : inout LINE;
  1047. VALUE : out UNRESOLVED_ufixed);
  1048. procedure HREAD(L : inout LINE;
  1049. VALUE : out UNRESOLVED_ufixed;
  1050. GOOD : out BOOLEAN);
  1051. procedure HREAD(L : inout LINE;
  1052. VALUE : out UNRESOLVED_sfixed);
  1053. procedure HREAD(L : inout LINE;
  1054. VALUE : out UNRESOLVED_sfixed;
  1055. GOOD : out BOOLEAN);
  1056. alias HEX_READ is HREAD [LINE, UNRESOLVED_ufixed, BOOLEAN];
  1057. alias HEX_READ is HREAD [LINE, UNRESOLVED_sfixed, BOOLEAN];
  1058. alias HEX_READ is HREAD [LINE, UNRESOLVED_ufixed];
  1059. alias HEX_READ is HREAD [LINE, UNRESOLVED_sfixed];
  1060. alias HEX_WRITE is HWRITE [LINE, UNRESOLVED_ufixed, SIDE, WIDTH];
  1061. alias HEX_WRITE is HWRITE [LINE, UNRESOLVED_sfixed, SIDE, WIDTH];
  1062. -- returns a string, useful for:
  1063. -- assert (x = y) report "error found " & TO_STRING(x) severity error;
  1064. function TO_STRING (value : UNRESOLVED_ufixed) return STRING;
  1065. alias TO_BSTRING is TO_STRING [UNRESOLVED_ufixed return STRING];
  1066. alias TO_BINARY_STRING is TO_STRING [UNRESOLVED_ufixed return STRING];
  1067. function TO_OSTRING (value : UNRESOLVED_ufixed) return STRING;
  1068. alias TO_OCTAL_STRING is TO_OSTRING [UNRESOLVED_ufixed return STRING];
  1069. function TO_HSTRING (value : UNRESOLVED_ufixed) return STRING;
  1070. alias TO_HEX_STRING is TO_HSTRING [UNRESOLVED_ufixed return STRING];
  1071. function TO_STRING (value : UNRESOLVED_sfixed) return STRING;
  1072. alias TO_BSTRING is TO_STRING [UNRESOLVED_sfixed return STRING];
  1073. alias TO_BINARY_STRING is TO_STRING [UNRESOLVED_sfixed return STRING];
  1074. function TO_OSTRING (value : UNRESOLVED_sfixed) return STRING;
  1075. alias TO_OCTAL_STRING is TO_OSTRING [UNRESOLVED_sfixed return STRING];
  1076. function TO_HSTRING (value : UNRESOLVED_sfixed) return STRING;
  1077. alias TO_HEX_STRING is TO_HSTRING [UNRESOLVED_sfixed return STRING];
  1078. -- From string functions allow you to convert a string into a fixed
  1079. -- point number. Example:
  1080. -- signal uf1 : ufixed (3 downto -3);
  1081. -- uf1 <= from_string ("0110.100", uf1'high, uf1'low); -- 6.5
  1082. -- The "." is optional in this syntax, however it exist and is
  1083. -- in the wrong location an error is produced. Overflow will
  1084. -- result in saturation.
  1085. function from_string (
  1086. bstring : STRING; -- binary string
  1087. constant left_index : INTEGER;
  1088. constant right_index : INTEGER)
  1089. return UNRESOLVED_ufixed;
  1090. alias from_bstring is from_string [STRING, INTEGER, INTEGER
  1091. return UNRESOLVED_ufixed];
  1092. alias from_binary_string is from_string [STRING, INTEGER, INTEGER
  1093. return UNRESOLVED_ufixed];
  1094. -- Octal and hex conversions work as follows:
  1095. -- uf1 <= from_hstring ("6.8", 3, -3); -- 6.5 (bottom zeros dropped)
  1096. -- uf1 <= from_ostring ("06.4", 3, -3); -- 6.5 (top zeros dropped)
  1097. function from_ostring (
  1098. ostring : STRING; -- Octal string
  1099. constant left_index : INTEGER;
  1100. constant right_index : INTEGER)
  1101. return UNRESOLVED_ufixed;
  1102. alias from_octal_string is from_ostring [STRING, INTEGER, INTEGER
  1103. return UNRESOLVED_ufixed];
  1104. function from_hstring (
  1105. hstring : STRING; -- hex string
  1106. constant left_index : INTEGER;
  1107. constant right_index : INTEGER)
  1108. return UNRESOLVED_ufixed;
  1109. alias from_hex_string is from_hstring [STRING, INTEGER, INTEGER
  1110. return UNRESOLVED_ufixed];
  1111. function from_string (
  1112. bstring : STRING; -- binary string
  1113. constant left_index : INTEGER;
  1114. constant right_index : INTEGER)
  1115. return UNRESOLVED_sfixed;
  1116. alias from_bstring is from_string [STRING, INTEGER, INTEGER
  1117. return UNRESOLVED_sfixed];
  1118. alias from_binary_string is from_string [STRING, INTEGER, INTEGER
  1119. return UNRESOLVED_sfixed];
  1120. function from_ostring (
  1121. ostring : STRING; -- Octal string
  1122. constant left_index : INTEGER;
  1123. constant right_index : INTEGER)
  1124. return UNRESOLVED_sfixed;
  1125. alias from_octal_string is from_ostring [STRING, INTEGER, INTEGER
  1126. return UNRESOLVED_sfixed];
  1127. function from_hstring (
  1128. hstring : STRING; -- hex string
  1129. constant left_index : INTEGER;
  1130. constant right_index : INTEGER)
  1131. return UNRESOLVED_sfixed;
  1132. alias from_hex_string is from_hstring [STRING, INTEGER, INTEGER
  1133. return UNRESOLVED_sfixed];
  1134. -- Same as above, "size_res" is used for it's range only.
  1135. function from_string (
  1136. bstring : STRING; -- binary string
  1137. size_res : UNRESOLVED_ufixed)
  1138. return UNRESOLVED_ufixed;
  1139. alias from_bstring is from_string [STRING, UNRESOLVED_ufixed
  1140. return UNRESOLVED_ufixed];
  1141. alias from_binary_string is from_string [STRING, UNRESOLVED_ufixed
  1142. return UNRESOLVED_ufixed];
  1143. function from_ostring (
  1144. ostring : STRING; -- Octal string
  1145. size_res : UNRESOLVED_ufixed)
  1146. return UNRESOLVED_ufixed;
  1147. alias from_octal_string is from_ostring [STRING, UNRESOLVED_ufixed
  1148. return UNRESOLVED_ufixed];
  1149. function from_hstring (
  1150. hstring : STRING; -- hex string
  1151. size_res : UNRESOLVED_ufixed)
  1152. return UNRESOLVED_ufixed;
  1153. alias from_hex_string is from_hstring [STRING, UNRESOLVED_ufixed
  1154. return UNRESOLVED_ufixed];
  1155. function from_string (
  1156. bstring : STRING; -- binary string
  1157. size_res : UNRESOLVED_sfixed)
  1158. return UNRESOLVED_sfixed;
  1159. alias from_bstring is from_string [STRING, UNRESOLVED_sfixed
  1160. return UNRESOLVED_sfixed];
  1161. alias from_binary_string is from_string [STRING, UNRESOLVED_sfixed
  1162. return UNRESOLVED_sfixed];
  1163. function from_ostring (
  1164. ostring : STRING; -- Octal string
  1165. size_res : UNRESOLVED_sfixed)
  1166. return UNRESOLVED_sfixed;
  1167. alias from_octal_string is from_ostring [STRING, UNRESOLVED_sfixed
  1168. return UNRESOLVED_sfixed];
  1169. function from_hstring (
  1170. hstring : STRING; -- hex string
  1171. size_res : UNRESOLVED_sfixed)
  1172. return UNRESOLVED_sfixed;
  1173. alias from_hex_string is from_hstring [STRING, UNRESOLVED_sfixed
  1174. return UNRESOLVED_sfixed];
  1175. -- Direct conversion functions. Example:
  1176. -- signal uf1 : ufixed (3 downto -3);
  1177. -- uf1 <= from_string ("0110.100"); -- 6.5
  1178. -- In this case the "." is not optional, and the size of
  1179. -- the output must match exactly.
  1180. function from_string (
  1181. bstring : STRING) -- binary string
  1182. return UNRESOLVED_ufixed;
  1183. alias from_bstring is from_string [STRING return UNRESOLVED_ufixed];
  1184. alias from_binary_string is from_string [STRING return UNRESOLVED_ufixed];
  1185. -- Direct octal and hex conversion functions. In this case
  1186. -- the string lengths must match. Example:
  1187. -- signal sf1 := sfixed (5 downto -3);
  1188. -- sf1 <= from_ostring ("71.4") -- -6.5
  1189. function from_ostring (
  1190. ostring : STRING) -- Octal string
  1191. return UNRESOLVED_ufixed;
  1192. alias from_octal_string is from_ostring [STRING return UNRESOLVED_ufixed];
  1193. function from_hstring (
  1194. hstring : STRING) -- hex string
  1195. return UNRESOLVED_ufixed;
  1196. alias from_hex_string is from_hstring [STRING return UNRESOLVED_ufixed];
  1197. function from_string (
  1198. bstring : STRING) -- binary string
  1199. return UNRESOLVED_sfixed;
  1200. alias from_bstring is from_string [STRING return UNRESOLVED_sfixed];
  1201. alias from_binary_string is from_string [STRING return UNRESOLVED_sfixed];
  1202. function from_ostring (
  1203. ostring : STRING) -- Octal string
  1204. return UNRESOLVED_sfixed;
  1205. alias from_octal_string is from_ostring [STRING return UNRESOLVED_sfixed];
  1206. function from_hstring (
  1207. hstring : STRING) -- hex string
  1208. return UNRESOLVED_sfixed;
  1209. alias from_hex_string is from_hstring [STRING return UNRESOLVED_sfixed];
  1210. end package fixed_generic_pkg;