sljitLir.c 83 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708
  1. /*
  2. * Stack-less Just-In-Time compiler
  3. *
  4. * Copyright Zoltan Herczeg (hzmester@freemail.hu). All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without modification, are
  7. * permitted provided that the following conditions are met:
  8. *
  9. * 1. Redistributions of source code must retain the above copyright notice, this list of
  10. * conditions and the following disclaimer.
  11. *
  12. * 2. Redistributions in binary form must reproduce the above copyright notice, this list
  13. * of conditions and the following disclaimer in the documentation and/or other materials
  14. * provided with the distribution.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) AND CONTRIBUTORS ``AS IS'' AND ANY
  17. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  18. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
  19. * SHALL THE COPYRIGHT HOLDER(S) OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  20. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
  21. * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
  22. * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  23. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  24. * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  25. */
  26. #include "sljitLir.h"
  27. #ifdef _WIN32
  28. #include <windows.h>
  29. #endif /* _WIN32 */
  30. #if !(defined SLJIT_STD_MACROS_DEFINED && SLJIT_STD_MACROS_DEFINED)
  31. /* These libraries are needed for the macros below. */
  32. #include <stdlib.h>
  33. #include <string.h>
  34. #endif /* SLJIT_STD_MACROS_DEFINED */
  35. #define CHECK_ERROR() \
  36. do { \
  37. if (SLJIT_UNLIKELY(compiler->error)) \
  38. return compiler->error; \
  39. } while (0)
  40. #define CHECK_ERROR_PTR() \
  41. do { \
  42. if (SLJIT_UNLIKELY(compiler->error)) \
  43. return NULL; \
  44. } while (0)
  45. #define FAIL_IF(expr) \
  46. do { \
  47. if (SLJIT_UNLIKELY(expr)) \
  48. return compiler->error; \
  49. } while (0)
  50. #define PTR_FAIL_IF(expr) \
  51. do { \
  52. if (SLJIT_UNLIKELY(expr)) \
  53. return NULL; \
  54. } while (0)
  55. #define FAIL_IF_NULL(ptr) \
  56. do { \
  57. if (SLJIT_UNLIKELY(!(ptr))) { \
  58. compiler->error = SLJIT_ERR_ALLOC_FAILED; \
  59. return SLJIT_ERR_ALLOC_FAILED; \
  60. } \
  61. } while (0)
  62. #define PTR_FAIL_IF_NULL(ptr) \
  63. do { \
  64. if (SLJIT_UNLIKELY(!(ptr))) { \
  65. compiler->error = SLJIT_ERR_ALLOC_FAILED; \
  66. return NULL; \
  67. } \
  68. } while (0)
  69. #define PTR_FAIL_WITH_EXEC_IF(ptr) \
  70. do { \
  71. if (SLJIT_UNLIKELY(!(ptr))) { \
  72. compiler->error = SLJIT_ERR_EX_ALLOC_FAILED; \
  73. return NULL; \
  74. } \
  75. } while (0)
  76. #if !(defined SLJIT_CONFIG_UNSUPPORTED && SLJIT_CONFIG_UNSUPPORTED)
  77. #define VARIABLE_FLAG_SHIFT (10)
  78. #define VARIABLE_FLAG_MASK (0x3f << VARIABLE_FLAG_SHIFT)
  79. #define GET_FLAG_TYPE(op) ((op) >> VARIABLE_FLAG_SHIFT)
  80. #define GET_OPCODE(op) \
  81. ((op) & ~(SLJIT_I32_OP | SLJIT_SET_Z | VARIABLE_FLAG_MASK))
  82. #define HAS_FLAGS(op) \
  83. ((op) & (SLJIT_SET_Z | VARIABLE_FLAG_MASK))
  84. #define GET_ALL_FLAGS(op) \
  85. ((op) & (SLJIT_I32_OP | SLJIT_SET_Z | VARIABLE_FLAG_MASK))
  86. #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
  87. #define TYPE_CAST_NEEDED(op) \
  88. ((op) >= SLJIT_MOV_U8 && (op) <= SLJIT_MOV_S32)
  89. #else
  90. #define TYPE_CAST_NEEDED(op) \
  91. ((op) >= SLJIT_MOV_U8 && (op) <= SLJIT_MOV_S16)
  92. #endif
  93. #define BUF_SIZE 4096
  94. #if (defined SLJIT_32BIT_ARCHITECTURE && SLJIT_32BIT_ARCHITECTURE)
  95. #define ABUF_SIZE 2048
  96. #else
  97. #define ABUF_SIZE 4096
  98. #endif
  99. /* Parameter parsing. */
  100. #define REG_MASK 0x3f
  101. #define OFFS_REG(reg) (((reg) >> 8) & REG_MASK)
  102. #define OFFS_REG_MASK (REG_MASK << 8)
  103. #define TO_OFFS_REG(reg) ((reg) << 8)
  104. /* When reg cannot be unused. */
  105. #define FAST_IS_REG(reg) ((reg) <= REG_MASK)
  106. /* When reg can be unused. */
  107. #define SLOW_IS_REG(reg) ((reg) > 0 && (reg) <= REG_MASK)
  108. /* Mask for argument types. */
  109. #define SLJIT_DEF_MASK ((1 << SLJIT_DEF_SHIFT) - 1)
  110. /* Jump flags. */
  111. #define JUMP_LABEL 0x1
  112. #define JUMP_ADDR 0x2
  113. /* SLJIT_REWRITABLE_JUMP is 0x1000. */
  114. #if (defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86)
  115. # define PATCH_MB 0x4
  116. # define PATCH_MW 0x8
  117. #if (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64)
  118. # define PATCH_MD 0x10
  119. #endif
  120. # define TYPE_SHIFT 13
  121. #endif
  122. #if (defined SLJIT_CONFIG_ARM_V5 && SLJIT_CONFIG_ARM_V5) || (defined SLJIT_CONFIG_ARM_V7 && SLJIT_CONFIG_ARM_V7)
  123. # define IS_BL 0x4
  124. # define PATCH_B 0x8
  125. #endif
  126. #if (defined SLJIT_CONFIG_ARM_V5 && SLJIT_CONFIG_ARM_V5)
  127. # define CPOOL_SIZE 512
  128. #endif
  129. #if (defined SLJIT_CONFIG_ARM_THUMB2 && SLJIT_CONFIG_ARM_THUMB2)
  130. # define IS_COND 0x04
  131. # define IS_BL 0x08
  132. /* conditional + imm8 */
  133. # define PATCH_TYPE1 0x10
  134. /* conditional + imm20 */
  135. # define PATCH_TYPE2 0x20
  136. /* IT + imm24 */
  137. # define PATCH_TYPE3 0x30
  138. /* imm11 */
  139. # define PATCH_TYPE4 0x40
  140. /* imm24 */
  141. # define PATCH_TYPE5 0x50
  142. /* BL + imm24 */
  143. # define PATCH_BL 0x60
  144. /* 0xf00 cc code for branches */
  145. #endif
  146. #if (defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64)
  147. # define IS_COND 0x004
  148. # define IS_CBZ 0x008
  149. # define IS_BL 0x010
  150. # define PATCH_B 0x020
  151. # define PATCH_COND 0x040
  152. # define PATCH_ABS48 0x080
  153. # define PATCH_ABS64 0x100
  154. #endif
  155. #if (defined SLJIT_CONFIG_PPC && SLJIT_CONFIG_PPC)
  156. # define IS_COND 0x004
  157. # define IS_CALL 0x008
  158. # define PATCH_B 0x010
  159. # define PATCH_ABS_B 0x020
  160. #if (defined SLJIT_CONFIG_PPC_64 && SLJIT_CONFIG_PPC_64)
  161. # define PATCH_ABS32 0x040
  162. # define PATCH_ABS48 0x080
  163. #endif
  164. # define REMOVE_COND 0x100
  165. #endif
  166. #if (defined SLJIT_CONFIG_MIPS && SLJIT_CONFIG_MIPS)
  167. # define IS_MOVABLE 0x004
  168. # define IS_JAL 0x008
  169. # define IS_CALL 0x010
  170. # define IS_BIT26_COND 0x020
  171. # define IS_BIT16_COND 0x040
  172. # define IS_BIT23_COND 0x080
  173. # define IS_COND (IS_BIT26_COND | IS_BIT16_COND | IS_BIT23_COND)
  174. # define PATCH_B 0x100
  175. # define PATCH_J 0x200
  176. #if (defined SLJIT_CONFIG_MIPS_64 && SLJIT_CONFIG_MIPS_64)
  177. # define PATCH_ABS32 0x400
  178. # define PATCH_ABS48 0x800
  179. #endif
  180. /* instruction types */
  181. # define MOVABLE_INS 0
  182. /* 1 - 31 last destination register */
  183. /* no destination (i.e: store) */
  184. # define UNMOVABLE_INS 32
  185. /* FPU status register */
  186. # define FCSR_FCC 33
  187. #endif
  188. #if (defined SLJIT_CONFIG_SPARC_32 && SLJIT_CONFIG_SPARC_32)
  189. # define IS_MOVABLE 0x04
  190. # define IS_COND 0x08
  191. # define IS_CALL 0x10
  192. # define PATCH_B 0x20
  193. # define PATCH_CALL 0x40
  194. /* instruction types */
  195. # define MOVABLE_INS 0
  196. /* 1 - 31 last destination register */
  197. /* no destination (i.e: store) */
  198. # define UNMOVABLE_INS 32
  199. # define DST_INS_MASK 0xff
  200. /* ICC_SET is the same as SET_FLAGS. */
  201. # define ICC_IS_SET (1 << 23)
  202. # define FCC_IS_SET (1 << 24)
  203. #endif
  204. /* Stack management. */
  205. #define GET_SAVED_REGISTERS_SIZE(scratches, saveds, extra) \
  206. (((scratches < SLJIT_NUMBER_OF_SCRATCH_REGISTERS ? 0 : (scratches - SLJIT_NUMBER_OF_SCRATCH_REGISTERS)) + \
  207. (saveds < SLJIT_NUMBER_OF_SAVED_REGISTERS ? saveds : SLJIT_NUMBER_OF_SAVED_REGISTERS) + \
  208. extra) * sizeof(sljit_sw))
  209. #define ADJUST_LOCAL_OFFSET(p, i) \
  210. if ((p) == (SLJIT_MEM1(SLJIT_SP))) \
  211. (i) += SLJIT_LOCALS_OFFSET;
  212. #endif /* !(defined SLJIT_CONFIG_UNSUPPORTED && SLJIT_CONFIG_UNSUPPORTED) */
  213. /* Utils can still be used even if SLJIT_CONFIG_UNSUPPORTED is set. */
  214. #include "sljitUtils.c"
  215. #if !(defined SLJIT_CONFIG_UNSUPPORTED && SLJIT_CONFIG_UNSUPPORTED)
  216. #if (defined SLJIT_EXECUTABLE_ALLOCATOR && SLJIT_EXECUTABLE_ALLOCATOR)
  217. #if (defined SLJIT_PROT_EXECUTABLE_ALLOCATOR && SLJIT_PROT_EXECUTABLE_ALLOCATOR)
  218. #include "sljitProtExecAllocator.c"
  219. #elif (defined SLJIT_WX_EXECUTABLE_ALLOCATOR && SLJIT_WX_EXECUTABLE_ALLOCATOR)
  220. #include "sljitWXExecAllocator.c"
  221. #else
  222. #include "sljitExecAllocator.c"
  223. #endif
  224. #endif
  225. #if (defined SLJIT_PROT_EXECUTABLE_ALLOCATOR && SLJIT_PROT_EXECUTABLE_ALLOCATOR)
  226. #define SLJIT_ADD_EXEC_OFFSET(ptr, exec_offset) ((sljit_u8 *)(ptr) + (exec_offset))
  227. #else
  228. #define SLJIT_ADD_EXEC_OFFSET(ptr, exec_offset) ((sljit_u8 *)(ptr))
  229. #endif
  230. #ifndef SLJIT_UPDATE_WX_FLAGS
  231. #define SLJIT_UPDATE_WX_FLAGS(from, to, enable_exec)
  232. #endif
  233. /* Argument checking features. */
  234. #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
  235. /* Returns with error when an invalid argument is passed. */
  236. #define CHECK_ARGUMENT(x) \
  237. do { \
  238. if (SLJIT_UNLIKELY(!(x))) \
  239. return 1; \
  240. } while (0)
  241. #define CHECK_RETURN_TYPE sljit_s32
  242. #define CHECK_RETURN_OK return 0
  243. #define CHECK(x) \
  244. do { \
  245. if (SLJIT_UNLIKELY(x)) { \
  246. compiler->error = SLJIT_ERR_BAD_ARGUMENT; \
  247. return SLJIT_ERR_BAD_ARGUMENT; \
  248. } \
  249. } while (0)
  250. #define CHECK_PTR(x) \
  251. do { \
  252. if (SLJIT_UNLIKELY(x)) { \
  253. compiler->error = SLJIT_ERR_BAD_ARGUMENT; \
  254. return NULL; \
  255. } \
  256. } while (0)
  257. #define CHECK_REG_INDEX(x) \
  258. do { \
  259. if (SLJIT_UNLIKELY(x)) { \
  260. return -2; \
  261. } \
  262. } while (0)
  263. #elif (defined SLJIT_DEBUG && SLJIT_DEBUG)
  264. /* Assertion failure occures if an invalid argument is passed. */
  265. #undef SLJIT_ARGUMENT_CHECKS
  266. #define SLJIT_ARGUMENT_CHECKS 1
  267. #define CHECK_ARGUMENT(x) SLJIT_ASSERT(x)
  268. #define CHECK_RETURN_TYPE void
  269. #define CHECK_RETURN_OK return
  270. #define CHECK(x) x
  271. #define CHECK_PTR(x) x
  272. #define CHECK_REG_INDEX(x) x
  273. #elif (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
  274. /* Arguments are not checked. */
  275. #define CHECK_RETURN_TYPE void
  276. #define CHECK_RETURN_OK return
  277. #define CHECK(x) x
  278. #define CHECK_PTR(x) x
  279. #define CHECK_REG_INDEX(x) x
  280. #else
  281. /* Arguments are not checked. */
  282. #define CHECK(x)
  283. #define CHECK_PTR(x)
  284. #define CHECK_REG_INDEX(x)
  285. #endif /* SLJIT_ARGUMENT_CHECKS */
  286. /* --------------------------------------------------------------------- */
  287. /* Public functions */
  288. /* --------------------------------------------------------------------- */
  289. #if (defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86)
  290. #define SLJIT_NEEDS_COMPILER_INIT 1
  291. static sljit_s32 compiler_initialized = 0;
  292. /* A thread safe initialization. */
  293. static void init_compiler(void);
  294. #endif
  295. SLJIT_API_FUNC_ATTRIBUTE struct sljit_compiler* sljit_create_compiler(void *allocator_data, void *exec_allocator_data)
  296. {
  297. struct sljit_compiler *compiler = (struct sljit_compiler*)SLJIT_MALLOC(sizeof(struct sljit_compiler), allocator_data);
  298. if (!compiler)
  299. return NULL;
  300. SLJIT_ZEROMEM(compiler, sizeof(struct sljit_compiler));
  301. SLJIT_COMPILE_ASSERT(
  302. sizeof(sljit_s8) == 1 && sizeof(sljit_u8) == 1
  303. && sizeof(sljit_s16) == 2 && sizeof(sljit_u16) == 2
  304. && sizeof(sljit_s32) == 4 && sizeof(sljit_u32) == 4
  305. && (sizeof(sljit_p) == 4 || sizeof(sljit_p) == 8)
  306. && sizeof(sljit_p) <= sizeof(sljit_sw)
  307. && (sizeof(sljit_sw) == 4 || sizeof(sljit_sw) == 8)
  308. && (sizeof(sljit_uw) == 4 || sizeof(sljit_uw) == 8),
  309. invalid_integer_types);
  310. SLJIT_COMPILE_ASSERT(SLJIT_I32_OP == SLJIT_F32_OP,
  311. int_op_and_single_op_must_be_the_same);
  312. SLJIT_COMPILE_ASSERT(SLJIT_REWRITABLE_JUMP != SLJIT_F32_OP,
  313. rewritable_jump_and_single_op_must_not_be_the_same);
  314. SLJIT_COMPILE_ASSERT(!(SLJIT_EQUAL & 0x1) && !(SLJIT_LESS & 0x1) && !(SLJIT_EQUAL_F64 & 0x1) && !(SLJIT_JUMP & 0x1),
  315. conditional_flags_must_be_even_numbers);
  316. /* Only the non-zero members must be set. */
  317. compiler->error = SLJIT_SUCCESS;
  318. compiler->allocator_data = allocator_data;
  319. compiler->exec_allocator_data = exec_allocator_data;
  320. compiler->buf = (struct sljit_memory_fragment*)SLJIT_MALLOC(BUF_SIZE, allocator_data);
  321. compiler->abuf = (struct sljit_memory_fragment*)SLJIT_MALLOC(ABUF_SIZE, allocator_data);
  322. if (!compiler->buf || !compiler->abuf) {
  323. if (compiler->buf)
  324. SLJIT_FREE(compiler->buf, allocator_data);
  325. if (compiler->abuf)
  326. SLJIT_FREE(compiler->abuf, allocator_data);
  327. SLJIT_FREE(compiler, allocator_data);
  328. return NULL;
  329. }
  330. compiler->buf->next = NULL;
  331. compiler->buf->used_size = 0;
  332. compiler->abuf->next = NULL;
  333. compiler->abuf->used_size = 0;
  334. compiler->scratches = -1;
  335. compiler->saveds = -1;
  336. compiler->fscratches = -1;
  337. compiler->fsaveds = -1;
  338. compiler->local_size = -1;
  339. #if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32)
  340. compiler->args = -1;
  341. #endif
  342. #if (defined SLJIT_CONFIG_ARM_V5 && SLJIT_CONFIG_ARM_V5)
  343. compiler->cpool = (sljit_uw*)SLJIT_MALLOC(CPOOL_SIZE * sizeof(sljit_uw)
  344. + CPOOL_SIZE * sizeof(sljit_u8), allocator_data);
  345. if (!compiler->cpool) {
  346. SLJIT_FREE(compiler->buf, allocator_data);
  347. SLJIT_FREE(compiler->abuf, allocator_data);
  348. SLJIT_FREE(compiler, allocator_data);
  349. return NULL;
  350. }
  351. compiler->cpool_unique = (sljit_u8*)(compiler->cpool + CPOOL_SIZE);
  352. compiler->cpool_diff = 0xffffffff;
  353. #endif
  354. #if (defined SLJIT_CONFIG_MIPS && SLJIT_CONFIG_MIPS)
  355. compiler->delay_slot = UNMOVABLE_INS;
  356. #endif
  357. #if (defined SLJIT_CONFIG_SPARC_32 && SLJIT_CONFIG_SPARC_32)
  358. compiler->delay_slot = UNMOVABLE_INS;
  359. #endif
  360. #if (defined SLJIT_NEEDS_COMPILER_INIT && SLJIT_NEEDS_COMPILER_INIT)
  361. if (!compiler_initialized) {
  362. init_compiler();
  363. compiler_initialized = 1;
  364. }
  365. #endif
  366. return compiler;
  367. }
  368. SLJIT_API_FUNC_ATTRIBUTE void sljit_free_compiler(struct sljit_compiler *compiler)
  369. {
  370. struct sljit_memory_fragment *buf;
  371. struct sljit_memory_fragment *curr;
  372. void *allocator_data = compiler->allocator_data;
  373. SLJIT_UNUSED_ARG(allocator_data);
  374. buf = compiler->buf;
  375. while (buf) {
  376. curr = buf;
  377. buf = buf->next;
  378. SLJIT_FREE(curr, allocator_data);
  379. }
  380. buf = compiler->abuf;
  381. while (buf) {
  382. curr = buf;
  383. buf = buf->next;
  384. SLJIT_FREE(curr, allocator_data);
  385. }
  386. #if (defined SLJIT_CONFIG_ARM_V5 && SLJIT_CONFIG_ARM_V5)
  387. SLJIT_FREE(compiler->cpool, allocator_data);
  388. #endif
  389. SLJIT_FREE(compiler, allocator_data);
  390. }
  391. SLJIT_API_FUNC_ATTRIBUTE void sljit_set_compiler_memory_error(struct sljit_compiler *compiler)
  392. {
  393. if (compiler->error == SLJIT_SUCCESS)
  394. compiler->error = SLJIT_ERR_ALLOC_FAILED;
  395. }
  396. #if (defined SLJIT_CONFIG_ARM_THUMB2 && SLJIT_CONFIG_ARM_THUMB2)
  397. SLJIT_API_FUNC_ATTRIBUTE void sljit_free_code(void* code, void *exec_allocator_data)
  398. {
  399. SLJIT_UNUSED_ARG(exec_allocator_data);
  400. /* Remove thumb mode flag. */
  401. SLJIT_FREE_EXEC((void*)((sljit_uw)code & ~0x1), exec_allocator_data);
  402. }
  403. #elif (defined SLJIT_INDIRECT_CALL && SLJIT_INDIRECT_CALL)
  404. SLJIT_API_FUNC_ATTRIBUTE void sljit_free_code(void* code, void *exec_allocator_data)
  405. {
  406. SLJIT_UNUSED_ARG(exec_allocator_data);
  407. /* Resolve indirection. */
  408. code = (void*)(*(sljit_uw*)code);
  409. SLJIT_FREE_EXEC(code, exec_allocator_data);
  410. }
  411. #else
  412. SLJIT_API_FUNC_ATTRIBUTE void sljit_free_code(void* code, void *exec_allocator_data)
  413. {
  414. SLJIT_UNUSED_ARG(exec_allocator_data);
  415. SLJIT_FREE_EXEC(code, exec_allocator_data);
  416. }
  417. #endif
  418. SLJIT_API_FUNC_ATTRIBUTE void sljit_set_label(struct sljit_jump *jump, struct sljit_label* label)
  419. {
  420. if (SLJIT_LIKELY(!!jump) && SLJIT_LIKELY(!!label)) {
  421. jump->flags &= ~JUMP_ADDR;
  422. jump->flags |= JUMP_LABEL;
  423. jump->u.label = label;
  424. }
  425. }
  426. SLJIT_API_FUNC_ATTRIBUTE void sljit_set_target(struct sljit_jump *jump, sljit_uw target)
  427. {
  428. if (SLJIT_LIKELY(!!jump)) {
  429. jump->flags &= ~JUMP_LABEL;
  430. jump->flags |= JUMP_ADDR;
  431. jump->u.target = target;
  432. }
  433. }
  434. SLJIT_API_FUNC_ATTRIBUTE void sljit_set_put_label(struct sljit_put_label *put_label, struct sljit_label *label)
  435. {
  436. if (SLJIT_LIKELY(!!put_label))
  437. put_label->label = label;
  438. }
  439. #define SLJIT_CURRENT_FLAGS_ALL \
  440. (SLJIT_CURRENT_FLAGS_I32_OP | SLJIT_CURRENT_FLAGS_ADD_SUB | SLJIT_CURRENT_FLAGS_COMPARE)
  441. SLJIT_API_FUNC_ATTRIBUTE void sljit_set_current_flags(struct sljit_compiler *compiler, sljit_s32 current_flags)
  442. {
  443. SLJIT_UNUSED_ARG(compiler);
  444. SLJIT_UNUSED_ARG(current_flags);
  445. #if (defined SLJIT_HAS_STATUS_FLAGS_STATE && SLJIT_HAS_STATUS_FLAGS_STATE)
  446. compiler->status_flags_state = current_flags;
  447. #endif
  448. #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
  449. compiler->last_flags = 0;
  450. if ((current_flags & ~(VARIABLE_FLAG_MASK | SLJIT_SET_Z | SLJIT_CURRENT_FLAGS_ALL)) == 0) {
  451. compiler->last_flags = GET_FLAG_TYPE(current_flags) | (current_flags & (SLJIT_I32_OP | SLJIT_SET_Z));
  452. }
  453. #endif
  454. }
  455. /* --------------------------------------------------------------------- */
  456. /* Private functions */
  457. /* --------------------------------------------------------------------- */
  458. static void* ensure_buf(struct sljit_compiler *compiler, sljit_uw size)
  459. {
  460. sljit_u8 *ret;
  461. struct sljit_memory_fragment *new_frag;
  462. SLJIT_ASSERT(size <= 256);
  463. if (compiler->buf->used_size + size <= (BUF_SIZE - (sljit_uw)SLJIT_OFFSETOF(struct sljit_memory_fragment, memory))) {
  464. ret = compiler->buf->memory + compiler->buf->used_size;
  465. compiler->buf->used_size += size;
  466. return ret;
  467. }
  468. new_frag = (struct sljit_memory_fragment*)SLJIT_MALLOC(BUF_SIZE, compiler->allocator_data);
  469. PTR_FAIL_IF_NULL(new_frag);
  470. new_frag->next = compiler->buf;
  471. compiler->buf = new_frag;
  472. new_frag->used_size = size;
  473. return new_frag->memory;
  474. }
  475. static void* ensure_abuf(struct sljit_compiler *compiler, sljit_uw size)
  476. {
  477. sljit_u8 *ret;
  478. struct sljit_memory_fragment *new_frag;
  479. SLJIT_ASSERT(size <= 256);
  480. if (compiler->abuf->used_size + size <= (ABUF_SIZE - (sljit_uw)SLJIT_OFFSETOF(struct sljit_memory_fragment, memory))) {
  481. ret = compiler->abuf->memory + compiler->abuf->used_size;
  482. compiler->abuf->used_size += size;
  483. return ret;
  484. }
  485. new_frag = (struct sljit_memory_fragment*)SLJIT_MALLOC(ABUF_SIZE, compiler->allocator_data);
  486. PTR_FAIL_IF_NULL(new_frag);
  487. new_frag->next = compiler->abuf;
  488. compiler->abuf = new_frag;
  489. new_frag->used_size = size;
  490. return new_frag->memory;
  491. }
  492. SLJIT_API_FUNC_ATTRIBUTE void* sljit_alloc_memory(struct sljit_compiler *compiler, sljit_s32 size)
  493. {
  494. CHECK_ERROR_PTR();
  495. #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
  496. if (size <= 0 || size > 128)
  497. return NULL;
  498. size = (size + 7) & ~7;
  499. #else
  500. if (size <= 0 || size > 64)
  501. return NULL;
  502. size = (size + 3) & ~3;
  503. #endif
  504. return ensure_abuf(compiler, size);
  505. }
  506. static SLJIT_INLINE void reverse_buf(struct sljit_compiler *compiler)
  507. {
  508. struct sljit_memory_fragment *buf = compiler->buf;
  509. struct sljit_memory_fragment *prev = NULL;
  510. struct sljit_memory_fragment *tmp;
  511. do {
  512. tmp = buf->next;
  513. buf->next = prev;
  514. prev = buf;
  515. buf = tmp;
  516. } while (buf != NULL);
  517. compiler->buf = prev;
  518. }
  519. static SLJIT_INLINE sljit_s32 get_arg_count(sljit_s32 arg_types)
  520. {
  521. sljit_s32 arg_count = 0;
  522. arg_types >>= SLJIT_DEF_SHIFT;
  523. while (arg_types) {
  524. arg_count++;
  525. arg_types >>= SLJIT_DEF_SHIFT;
  526. }
  527. return arg_count;
  528. }
  529. /* Only used in RISC architectures where the instruction size is constant */
  530. #if !(defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86) \
  531. && !(defined SLJIT_CONFIG_S390X && SLJIT_CONFIG_S390X)
  532. static SLJIT_INLINE sljit_uw compute_next_addr(struct sljit_label *label, struct sljit_jump *jump,
  533. struct sljit_const *const_, struct sljit_put_label *put_label)
  534. {
  535. sljit_uw result = ~(sljit_uw)0;
  536. if (label)
  537. result = label->size;
  538. if (jump && jump->addr < result)
  539. result = jump->addr;
  540. if (const_ && const_->addr < result)
  541. result = const_->addr;
  542. if (put_label && put_label->addr < result)
  543. result = put_label->addr;
  544. return result;
  545. }
  546. #endif /* !SLJIT_CONFIG_X86 && !SLJIT_CONFIG_S390X */
  547. static SLJIT_INLINE void set_emit_enter(struct sljit_compiler *compiler,
  548. sljit_s32 options, sljit_s32 args, sljit_s32 scratches, sljit_s32 saveds,
  549. sljit_s32 fscratches, sljit_s32 fsaveds, sljit_s32 local_size)
  550. {
  551. SLJIT_UNUSED_ARG(args);
  552. SLJIT_UNUSED_ARG(local_size);
  553. compiler->options = options;
  554. compiler->scratches = scratches;
  555. compiler->saveds = saveds;
  556. compiler->fscratches = fscratches;
  557. compiler->fsaveds = fsaveds;
  558. #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
  559. compiler->logical_local_size = local_size;
  560. #endif
  561. }
  562. static SLJIT_INLINE void set_set_context(struct sljit_compiler *compiler,
  563. sljit_s32 options, sljit_s32 args, sljit_s32 scratches, sljit_s32 saveds,
  564. sljit_s32 fscratches, sljit_s32 fsaveds, sljit_s32 local_size)
  565. {
  566. SLJIT_UNUSED_ARG(args);
  567. SLJIT_UNUSED_ARG(local_size);
  568. compiler->options = options;
  569. compiler->scratches = scratches;
  570. compiler->saveds = saveds;
  571. compiler->fscratches = fscratches;
  572. compiler->fsaveds = fsaveds;
  573. #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
  574. compiler->logical_local_size = local_size;
  575. #endif
  576. }
  577. static SLJIT_INLINE void set_label(struct sljit_label *label, struct sljit_compiler *compiler)
  578. {
  579. label->next = NULL;
  580. label->size = compiler->size;
  581. if (compiler->last_label)
  582. compiler->last_label->next = label;
  583. else
  584. compiler->labels = label;
  585. compiler->last_label = label;
  586. }
  587. static SLJIT_INLINE void set_jump(struct sljit_jump *jump, struct sljit_compiler *compiler, sljit_s32 flags)
  588. {
  589. jump->next = NULL;
  590. jump->flags = flags;
  591. if (compiler->last_jump)
  592. compiler->last_jump->next = jump;
  593. else
  594. compiler->jumps = jump;
  595. compiler->last_jump = jump;
  596. }
  597. static SLJIT_INLINE void set_const(struct sljit_const *const_, struct sljit_compiler *compiler)
  598. {
  599. const_->next = NULL;
  600. const_->addr = compiler->size;
  601. if (compiler->last_const)
  602. compiler->last_const->next = const_;
  603. else
  604. compiler->consts = const_;
  605. compiler->last_const = const_;
  606. }
  607. static SLJIT_INLINE void set_put_label(struct sljit_put_label *put_label, struct sljit_compiler *compiler, sljit_uw offset)
  608. {
  609. put_label->next = NULL;
  610. put_label->label = NULL;
  611. put_label->addr = compiler->size - offset;
  612. put_label->flags = 0;
  613. if (compiler->last_put_label)
  614. compiler->last_put_label->next = put_label;
  615. else
  616. compiler->put_labels = put_label;
  617. compiler->last_put_label = put_label;
  618. }
  619. #define ADDRESSING_DEPENDS_ON(exp, reg) \
  620. (((exp) & SLJIT_MEM) && (((exp) & REG_MASK) == reg || OFFS_REG(exp) == reg))
  621. #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
  622. #define FUNCTION_CHECK_IS_REG(r) \
  623. (((r) >= SLJIT_R0 && (r) < (SLJIT_R0 + compiler->scratches)) \
  624. || ((r) > (SLJIT_S0 - compiler->saveds) && (r) <= SLJIT_S0))
  625. #define FUNCTION_CHECK_IS_FREG(fr) \
  626. (((fr) >= SLJIT_FR0 && (fr) < (SLJIT_FR0 + compiler->fscratches)) \
  627. || ((fr) > (SLJIT_FS0 - compiler->fsaveds) && (fr) <= SLJIT_FS0))
  628. #if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32)
  629. #define CHECK_IF_VIRTUAL_REGISTER(p) ((p) <= SLJIT_S3 && (p) >= SLJIT_S8)
  630. #else
  631. #define CHECK_IF_VIRTUAL_REGISTER(p) 0
  632. #endif
  633. static sljit_s32 function_check_src_mem(struct sljit_compiler *compiler, sljit_s32 p, sljit_sw i)
  634. {
  635. if (compiler->scratches == -1 || compiler->saveds == -1)
  636. return 0;
  637. if (!(p & SLJIT_MEM))
  638. return 0;
  639. if (!((p & REG_MASK) == SLJIT_UNUSED || FUNCTION_CHECK_IS_REG(p & REG_MASK)))
  640. return 0;
  641. if (CHECK_IF_VIRTUAL_REGISTER(p & REG_MASK))
  642. return 0;
  643. if (p & OFFS_REG_MASK) {
  644. if ((p & REG_MASK) == SLJIT_UNUSED)
  645. return 0;
  646. if (!(FUNCTION_CHECK_IS_REG(OFFS_REG(p))))
  647. return 0;
  648. if (CHECK_IF_VIRTUAL_REGISTER(OFFS_REG(p)))
  649. return 0;
  650. if ((i & ~0x3) != 0)
  651. return 0;
  652. }
  653. return (p & ~(SLJIT_MEM | REG_MASK | OFFS_REG_MASK)) == 0;
  654. }
  655. #define FUNCTION_CHECK_SRC_MEM(p, i) \
  656. CHECK_ARGUMENT(function_check_src_mem(compiler, p, i));
  657. static sljit_s32 function_check_src(struct sljit_compiler *compiler, sljit_s32 p, sljit_sw i)
  658. {
  659. if (compiler->scratches == -1 || compiler->saveds == -1)
  660. return 0;
  661. if (FUNCTION_CHECK_IS_REG(p))
  662. return (i == 0);
  663. if (p == SLJIT_IMM)
  664. return 1;
  665. if (p == SLJIT_MEM1(SLJIT_SP))
  666. return (i >= 0 && i < compiler->logical_local_size);
  667. return function_check_src_mem(compiler, p, i);
  668. }
  669. #define FUNCTION_CHECK_SRC(p, i) \
  670. CHECK_ARGUMENT(function_check_src(compiler, p, i));
  671. static sljit_s32 function_check_dst(struct sljit_compiler *compiler, sljit_s32 p, sljit_sw i, sljit_s32 unused)
  672. {
  673. if (compiler->scratches == -1 || compiler->saveds == -1)
  674. return 0;
  675. if (FUNCTION_CHECK_IS_REG(p) || ((unused) && (p) == SLJIT_UNUSED))
  676. return (i == 0);
  677. if (p == SLJIT_MEM1(SLJIT_SP))
  678. return (i >= 0 && i < compiler->logical_local_size);
  679. return function_check_src_mem(compiler, p, i);
  680. }
  681. #define FUNCTION_CHECK_DST(p, i, unused) \
  682. CHECK_ARGUMENT(function_check_dst(compiler, p, i, unused));
  683. static sljit_s32 function_fcheck(struct sljit_compiler *compiler, sljit_s32 p, sljit_sw i)
  684. {
  685. if (compiler->scratches == -1 || compiler->saveds == -1)
  686. return 0;
  687. if (FUNCTION_CHECK_IS_FREG(p))
  688. return (i == 0);
  689. if (p == SLJIT_MEM1(SLJIT_SP))
  690. return (i >= 0 && i < compiler->logical_local_size);
  691. return function_check_src_mem(compiler, p, i);
  692. }
  693. #define FUNCTION_FCHECK(p, i) \
  694. CHECK_ARGUMENT(function_fcheck(compiler, p, i));
  695. #endif /* SLJIT_ARGUMENT_CHECKS */
  696. #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
  697. SLJIT_API_FUNC_ATTRIBUTE void sljit_compiler_verbose(struct sljit_compiler *compiler, FILE* verbose)
  698. {
  699. compiler->verbose = verbose;
  700. }
  701. #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
  702. #ifdef _WIN64
  703. # define SLJIT_PRINT_D "I64"
  704. #else
  705. # define SLJIT_PRINT_D "l"
  706. #endif
  707. #else
  708. # define SLJIT_PRINT_D ""
  709. #endif
  710. static void sljit_verbose_reg(struct sljit_compiler *compiler, sljit_s32 r)
  711. {
  712. if (r < (SLJIT_R0 + compiler->scratches))
  713. fprintf(compiler->verbose, "r%d", r - SLJIT_R0);
  714. else if (r != SLJIT_SP)
  715. fprintf(compiler->verbose, "s%d", SLJIT_NUMBER_OF_REGISTERS - r);
  716. else
  717. fprintf(compiler->verbose, "sp");
  718. }
  719. static void sljit_verbose_freg(struct sljit_compiler *compiler, sljit_s32 r)
  720. {
  721. if (r < (SLJIT_FR0 + compiler->fscratches))
  722. fprintf(compiler->verbose, "fr%d", r - SLJIT_FR0);
  723. else
  724. fprintf(compiler->verbose, "fs%d", SLJIT_NUMBER_OF_FLOAT_REGISTERS - r);
  725. }
  726. static void sljit_verbose_param(struct sljit_compiler *compiler, sljit_s32 p, sljit_sw i)
  727. {
  728. if ((p) & SLJIT_IMM)
  729. fprintf(compiler->verbose, "#%" SLJIT_PRINT_D "d", (i));
  730. else if ((p) & SLJIT_MEM) {
  731. if ((p) & REG_MASK) {
  732. fputc('[', compiler->verbose);
  733. sljit_verbose_reg(compiler, (p) & REG_MASK);
  734. if ((p) & OFFS_REG_MASK) {
  735. fprintf(compiler->verbose, " + ");
  736. sljit_verbose_reg(compiler, OFFS_REG(p));
  737. if (i)
  738. fprintf(compiler->verbose, " * %d", 1 << (i));
  739. }
  740. else if (i)
  741. fprintf(compiler->verbose, " + %" SLJIT_PRINT_D "d", (i));
  742. fputc(']', compiler->verbose);
  743. }
  744. else
  745. fprintf(compiler->verbose, "[#%" SLJIT_PRINT_D "d]", (i));
  746. } else if (p)
  747. sljit_verbose_reg(compiler, p);
  748. else
  749. fprintf(compiler->verbose, "unused");
  750. }
  751. static void sljit_verbose_fparam(struct sljit_compiler *compiler, sljit_s32 p, sljit_sw i)
  752. {
  753. if ((p) & SLJIT_MEM) {
  754. if ((p) & REG_MASK) {
  755. fputc('[', compiler->verbose);
  756. sljit_verbose_reg(compiler, (p) & REG_MASK);
  757. if ((p) & OFFS_REG_MASK) {
  758. fprintf(compiler->verbose, " + ");
  759. sljit_verbose_reg(compiler, OFFS_REG(p));
  760. if (i)
  761. fprintf(compiler->verbose, "%d", 1 << (i));
  762. }
  763. else if (i)
  764. fprintf(compiler->verbose, " + %" SLJIT_PRINT_D "d", (i));
  765. fputc(']', compiler->verbose);
  766. }
  767. else
  768. fprintf(compiler->verbose, "[#%" SLJIT_PRINT_D "d]", (i));
  769. }
  770. else
  771. sljit_verbose_freg(compiler, p);
  772. }
  773. static const char* op0_names[] = {
  774. (char*)"breakpoint", (char*)"nop", (char*)"lmul.uw", (char*)"lmul.sw",
  775. (char*)"divmod.u", (char*)"divmod.s", (char*)"div.u", (char*)"div.s",
  776. (char*)"endbr", (char*)"skip_frames_before_return"
  777. };
  778. static const char* op1_names[] = {
  779. (char*)"", (char*)".u8", (char*)".s8", (char*)".u16",
  780. (char*)".s16", (char*)".u32", (char*)".s32", (char*)".p",
  781. (char*)"", (char*)".u8", (char*)".s8", (char*)".u16",
  782. (char*)".s16", (char*)".u32", (char*)".s32", (char*)".p",
  783. (char*)"not", (char*)"neg", (char*)"clz",
  784. };
  785. static const char* op2_names[] = {
  786. (char*)"add", (char*)"addc", (char*)"sub", (char*)"subc",
  787. (char*)"mul", (char*)"and", (char*)"or", (char*)"xor",
  788. (char*)"shl", (char*)"lshr", (char*)"ashr",
  789. };
  790. static const char* op_src_names[] = {
  791. (char*)"fast_return", (char*)"skip_frames_before_fast_return",
  792. (char*)"prefetch_l1", (char*)"prefetch_l2",
  793. (char*)"prefetch_l3", (char*)"prefetch_once",
  794. };
  795. static const char* fop1_names[] = {
  796. (char*)"mov", (char*)"conv", (char*)"conv", (char*)"conv",
  797. (char*)"conv", (char*)"conv", (char*)"cmp", (char*)"neg",
  798. (char*)"abs",
  799. };
  800. static const char* fop2_names[] = {
  801. (char*)"add", (char*)"sub", (char*)"mul", (char*)"div"
  802. };
  803. #define JUMP_POSTFIX(type) \
  804. ((type & 0xff) <= SLJIT_NOT_OVERFLOW ? ((type & SLJIT_I32_OP) ? "32" : "") \
  805. : ((type & 0xff) <= SLJIT_ORDERED_F64 ? ((type & SLJIT_F32_OP) ? ".f32" : ".f64") : ""))
  806. static char* jump_names[] = {
  807. (char*)"equal", (char*)"not_equal",
  808. (char*)"less", (char*)"greater_equal",
  809. (char*)"greater", (char*)"less_equal",
  810. (char*)"sig_less", (char*)"sig_greater_equal",
  811. (char*)"sig_greater", (char*)"sig_less_equal",
  812. (char*)"overflow", (char*)"not_overflow",
  813. (char*)"carry", (char*)"",
  814. (char*)"equal", (char*)"not_equal",
  815. (char*)"less", (char*)"greater_equal",
  816. (char*)"greater", (char*)"less_equal",
  817. (char*)"unordered", (char*)"ordered",
  818. (char*)"jump", (char*)"fast_call",
  819. (char*)"call", (char*)"call.cdecl"
  820. };
  821. static char* call_arg_names[] = {
  822. (char*)"void", (char*)"sw", (char*)"uw", (char*)"s32", (char*)"u32", (char*)"f32", (char*)"f64"
  823. };
  824. #endif /* SLJIT_VERBOSE */
  825. /* --------------------------------------------------------------------- */
  826. /* Arch dependent */
  827. /* --------------------------------------------------------------------- */
  828. #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) \
  829. || (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
  830. static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_generate_code(struct sljit_compiler *compiler)
  831. {
  832. #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
  833. struct sljit_jump *jump;
  834. #endif
  835. SLJIT_UNUSED_ARG(compiler);
  836. #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
  837. CHECK_ARGUMENT(compiler->size > 0);
  838. jump = compiler->jumps;
  839. while (jump) {
  840. /* All jumps have target. */
  841. CHECK_ARGUMENT(jump->flags & (JUMP_LABEL | JUMP_ADDR));
  842. jump = jump->next;
  843. }
  844. #endif
  845. CHECK_RETURN_OK;
  846. }
  847. static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_enter(struct sljit_compiler *compiler,
  848. sljit_s32 options, sljit_s32 arg_types, sljit_s32 scratches, sljit_s32 saveds,
  849. sljit_s32 fscratches, sljit_s32 fsaveds, sljit_s32 local_size)
  850. {
  851. #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
  852. sljit_s32 types, arg_count, curr_type;
  853. #endif
  854. SLJIT_UNUSED_ARG(compiler);
  855. #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
  856. CHECK_ARGUMENT(!(options & ~SLJIT_F64_ALIGNMENT));
  857. CHECK_ARGUMENT(scratches >= 0 && scratches <= SLJIT_NUMBER_OF_REGISTERS);
  858. CHECK_ARGUMENT(saveds >= 0 && saveds <= SLJIT_NUMBER_OF_REGISTERS);
  859. CHECK_ARGUMENT(scratches + saveds <= SLJIT_NUMBER_OF_REGISTERS);
  860. CHECK_ARGUMENT(fscratches >= 0 && fscratches <= SLJIT_NUMBER_OF_FLOAT_REGISTERS);
  861. CHECK_ARGUMENT(fsaveds >= 0 && fsaveds <= SLJIT_NUMBER_OF_FLOAT_REGISTERS);
  862. CHECK_ARGUMENT(fscratches + fsaveds <= SLJIT_NUMBER_OF_FLOAT_REGISTERS);
  863. CHECK_ARGUMENT(local_size >= 0 && local_size <= SLJIT_MAX_LOCAL_SIZE);
  864. CHECK_ARGUMENT((arg_types & SLJIT_DEF_MASK) == 0);
  865. types = (arg_types >> SLJIT_DEF_SHIFT);
  866. arg_count = 0;
  867. while (types != 0 && arg_count < 3) {
  868. curr_type = (types & SLJIT_DEF_MASK);
  869. CHECK_ARGUMENT(curr_type == SLJIT_ARG_TYPE_SW || curr_type == SLJIT_ARG_TYPE_UW);
  870. arg_count++;
  871. types >>= SLJIT_DEF_SHIFT;
  872. }
  873. CHECK_ARGUMENT(arg_count <= saveds && types == 0);
  874. compiler->last_flags = 0;
  875. #endif
  876. #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
  877. if (SLJIT_UNLIKELY(!!compiler->verbose)) {
  878. fprintf(compiler->verbose, " enter options:%s args[", (options & SLJIT_F64_ALIGNMENT) ? "f64_align" : "");
  879. arg_types >>= SLJIT_DEF_SHIFT;
  880. while (arg_types) {
  881. fprintf(compiler->verbose, "%s", call_arg_names[arg_types & SLJIT_DEF_MASK]);
  882. arg_types >>= SLJIT_DEF_SHIFT;
  883. if (arg_types)
  884. fprintf(compiler->verbose, ",");
  885. }
  886. fprintf(compiler->verbose, "] scratches:%d saveds:%d fscratches:%d fsaveds:%d local_size:%d\n",
  887. scratches, saveds, fscratches, fsaveds, local_size);
  888. }
  889. #endif
  890. CHECK_RETURN_OK;
  891. }
  892. static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_set_context(struct sljit_compiler *compiler,
  893. sljit_s32 options, sljit_s32 arg_types, sljit_s32 scratches, sljit_s32 saveds,
  894. sljit_s32 fscratches, sljit_s32 fsaveds, sljit_s32 local_size)
  895. {
  896. #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
  897. sljit_s32 types, arg_count, curr_type;
  898. #endif
  899. SLJIT_UNUSED_ARG(compiler);
  900. #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
  901. CHECK_ARGUMENT(!(options & ~SLJIT_F64_ALIGNMENT));
  902. CHECK_ARGUMENT(scratches >= 0 && scratches <= SLJIT_NUMBER_OF_REGISTERS);
  903. CHECK_ARGUMENT(saveds >= 0 && saveds <= SLJIT_NUMBER_OF_REGISTERS);
  904. CHECK_ARGUMENT(scratches + saveds <= SLJIT_NUMBER_OF_REGISTERS);
  905. CHECK_ARGUMENT(fscratches >= 0 && fscratches <= SLJIT_NUMBER_OF_FLOAT_REGISTERS);
  906. CHECK_ARGUMENT(fsaveds >= 0 && fsaveds <= SLJIT_NUMBER_OF_FLOAT_REGISTERS);
  907. CHECK_ARGUMENT(fscratches + fsaveds <= SLJIT_NUMBER_OF_FLOAT_REGISTERS);
  908. CHECK_ARGUMENT(local_size >= 0 && local_size <= SLJIT_MAX_LOCAL_SIZE);
  909. types = (arg_types >> SLJIT_DEF_SHIFT);
  910. arg_count = 0;
  911. while (types != 0 && arg_count < 3) {
  912. curr_type = (types & SLJIT_DEF_MASK);
  913. CHECK_ARGUMENT(curr_type == SLJIT_ARG_TYPE_SW || curr_type == SLJIT_ARG_TYPE_UW);
  914. arg_count++;
  915. types >>= SLJIT_DEF_SHIFT;
  916. }
  917. CHECK_ARGUMENT(arg_count <= saveds && types == 0);
  918. compiler->last_flags = 0;
  919. #endif
  920. #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
  921. if (SLJIT_UNLIKELY(!!compiler->verbose)) {
  922. fprintf(compiler->verbose, " set_context options:%s args[", (options & SLJIT_F64_ALIGNMENT) ? "f64_align" : "");
  923. arg_types >>= SLJIT_DEF_SHIFT;
  924. while (arg_types) {
  925. fprintf(compiler->verbose, "%s", call_arg_names[arg_types & SLJIT_DEF_MASK]);
  926. arg_types >>= SLJIT_DEF_SHIFT;
  927. if (arg_types)
  928. fprintf(compiler->verbose, ",");
  929. }
  930. fprintf(compiler->verbose, "] scratches:%d saveds:%d fscratches:%d fsaveds:%d local_size:%d\n",
  931. scratches, saveds, fscratches, fsaveds, local_size);
  932. }
  933. #endif
  934. CHECK_RETURN_OK;
  935. }
  936. static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_return(struct sljit_compiler *compiler, sljit_s32 op, sljit_s32 src, sljit_sw srcw)
  937. {
  938. #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
  939. CHECK_ARGUMENT(compiler->scratches >= 0);
  940. if (op != SLJIT_UNUSED) {
  941. CHECK_ARGUMENT(op >= SLJIT_MOV && op <= SLJIT_MOV_P);
  942. FUNCTION_CHECK_SRC(src, srcw);
  943. }
  944. else
  945. CHECK_ARGUMENT(src == 0 && srcw == 0);
  946. compiler->last_flags = 0;
  947. #endif
  948. #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
  949. if (SLJIT_UNLIKELY(!!compiler->verbose)) {
  950. if (op == SLJIT_UNUSED)
  951. fprintf(compiler->verbose, " return\n");
  952. else {
  953. fprintf(compiler->verbose, " return%s ", op1_names[op - SLJIT_OP1_BASE]);
  954. sljit_verbose_param(compiler, src, srcw);
  955. fprintf(compiler->verbose, "\n");
  956. }
  957. }
  958. #endif
  959. CHECK_RETURN_OK;
  960. }
  961. static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_fast_enter(struct sljit_compiler *compiler, sljit_s32 dst, sljit_sw dstw)
  962. {
  963. #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
  964. FUNCTION_CHECK_DST(dst, dstw, 0);
  965. compiler->last_flags = 0;
  966. #endif
  967. #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
  968. if (SLJIT_UNLIKELY(!!compiler->verbose)) {
  969. fprintf(compiler->verbose, " fast_enter ");
  970. sljit_verbose_param(compiler, dst, dstw);
  971. fprintf(compiler->verbose, "\n");
  972. }
  973. #endif
  974. CHECK_RETURN_OK;
  975. }
  976. static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_op0(struct sljit_compiler *compiler, sljit_s32 op)
  977. {
  978. #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
  979. CHECK_ARGUMENT((op >= SLJIT_BREAKPOINT && op <= SLJIT_LMUL_SW)
  980. || ((op & ~SLJIT_I32_OP) >= SLJIT_DIVMOD_UW && (op & ~SLJIT_I32_OP) <= SLJIT_DIV_SW)
  981. || (op >= SLJIT_ENDBR && op <= SLJIT_SKIP_FRAMES_BEFORE_RETURN));
  982. CHECK_ARGUMENT(GET_OPCODE(op) < SLJIT_LMUL_UW || GET_OPCODE(op) >= SLJIT_ENDBR || compiler->scratches >= 2);
  983. if ((GET_OPCODE(op) >= SLJIT_LMUL_UW && GET_OPCODE(op) <= SLJIT_DIV_SW) || op == SLJIT_SKIP_FRAMES_BEFORE_RETURN)
  984. compiler->last_flags = 0;
  985. #endif
  986. #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
  987. if (SLJIT_UNLIKELY(!!compiler->verbose))
  988. {
  989. fprintf(compiler->verbose, " %s", op0_names[GET_OPCODE(op) - SLJIT_OP0_BASE]);
  990. if (GET_OPCODE(op) >= SLJIT_DIVMOD_UW && GET_OPCODE(op) <= SLJIT_DIV_SW) {
  991. fprintf(compiler->verbose, (op & SLJIT_I32_OP) ? "32" : "w");
  992. }
  993. fprintf(compiler->verbose, "\n");
  994. }
  995. #endif
  996. CHECK_RETURN_OK;
  997. }
  998. static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_op1(struct sljit_compiler *compiler, sljit_s32 op,
  999. sljit_s32 dst, sljit_sw dstw,
  1000. sljit_s32 src, sljit_sw srcw)
  1001. {
  1002. if (SLJIT_UNLIKELY(compiler->skip_checks)) {
  1003. compiler->skip_checks = 0;
  1004. CHECK_RETURN_OK;
  1005. }
  1006. #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
  1007. CHECK_ARGUMENT(GET_OPCODE(op) >= SLJIT_MOV && GET_OPCODE(op) <= SLJIT_CLZ);
  1008. switch (GET_OPCODE(op)) {
  1009. case SLJIT_NOT:
  1010. /* Only SLJIT_I32_OP and SLJIT_SET_Z are allowed. */
  1011. CHECK_ARGUMENT(!(op & VARIABLE_FLAG_MASK));
  1012. break;
  1013. case SLJIT_NEG:
  1014. CHECK_ARGUMENT(!(op & VARIABLE_FLAG_MASK)
  1015. || GET_FLAG_TYPE(op) == SLJIT_OVERFLOW);
  1016. break;
  1017. case SLJIT_MOV:
  1018. case SLJIT_MOV_U32:
  1019. case SLJIT_MOV_P:
  1020. /* Nothing allowed */
  1021. CHECK_ARGUMENT(!(op & (SLJIT_I32_OP | SLJIT_SET_Z | VARIABLE_FLAG_MASK)));
  1022. break;
  1023. default:
  1024. /* Only SLJIT_I32_OP is allowed. */
  1025. CHECK_ARGUMENT(!(op & (SLJIT_SET_Z | VARIABLE_FLAG_MASK)));
  1026. break;
  1027. }
  1028. FUNCTION_CHECK_DST(dst, dstw, HAS_FLAGS(op));
  1029. FUNCTION_CHECK_SRC(src, srcw);
  1030. if (GET_OPCODE(op) >= SLJIT_NOT) {
  1031. CHECK_ARGUMENT(src != SLJIT_IMM);
  1032. compiler->last_flags = GET_FLAG_TYPE(op) | (op & (SLJIT_I32_OP | SLJIT_SET_Z));
  1033. }
  1034. #endif
  1035. #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
  1036. if (SLJIT_UNLIKELY(!!compiler->verbose)) {
  1037. if (GET_OPCODE(op) <= SLJIT_MOV_P)
  1038. {
  1039. fprintf(compiler->verbose, " mov%s%s ", !(op & SLJIT_I32_OP) ? "" : "32",
  1040. (op != SLJIT_MOV32) ? op1_names[GET_OPCODE(op) - SLJIT_OP1_BASE] : "");
  1041. }
  1042. else
  1043. {
  1044. fprintf(compiler->verbose, " %s%s%s%s%s ", op1_names[GET_OPCODE(op) - SLJIT_OP1_BASE], !(op & SLJIT_I32_OP) ? "" : "32",
  1045. !(op & SLJIT_SET_Z) ? "" : ".z", !(op & VARIABLE_FLAG_MASK) ? "" : ".",
  1046. !(op & VARIABLE_FLAG_MASK) ? "" : jump_names[GET_FLAG_TYPE(op)]);
  1047. }
  1048. sljit_verbose_param(compiler, dst, dstw);
  1049. fprintf(compiler->verbose, ", ");
  1050. sljit_verbose_param(compiler, src, srcw);
  1051. fprintf(compiler->verbose, "\n");
  1052. }
  1053. #endif
  1054. CHECK_RETURN_OK;
  1055. }
  1056. static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_op2(struct sljit_compiler *compiler, sljit_s32 op,
  1057. sljit_s32 dst, sljit_sw dstw,
  1058. sljit_s32 src1, sljit_sw src1w,
  1059. sljit_s32 src2, sljit_sw src2w)
  1060. {
  1061. if (SLJIT_UNLIKELY(compiler->skip_checks)) {
  1062. compiler->skip_checks = 0;
  1063. CHECK_RETURN_OK;
  1064. }
  1065. #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
  1066. CHECK_ARGUMENT(GET_OPCODE(op) >= SLJIT_ADD && GET_OPCODE(op) <= SLJIT_ASHR);
  1067. switch (GET_OPCODE(op)) {
  1068. case SLJIT_AND:
  1069. case SLJIT_OR:
  1070. case SLJIT_XOR:
  1071. case SLJIT_SHL:
  1072. case SLJIT_LSHR:
  1073. case SLJIT_ASHR:
  1074. CHECK_ARGUMENT(!(op & VARIABLE_FLAG_MASK));
  1075. break;
  1076. case SLJIT_MUL:
  1077. CHECK_ARGUMENT(!(op & SLJIT_SET_Z));
  1078. CHECK_ARGUMENT(!(op & VARIABLE_FLAG_MASK)
  1079. || GET_FLAG_TYPE(op) == SLJIT_OVERFLOW);
  1080. break;
  1081. case SLJIT_ADD:
  1082. CHECK_ARGUMENT(!(op & VARIABLE_FLAG_MASK)
  1083. || GET_FLAG_TYPE(op) == GET_FLAG_TYPE(SLJIT_SET_CARRY)
  1084. || GET_FLAG_TYPE(op) == SLJIT_OVERFLOW);
  1085. break;
  1086. case SLJIT_SUB:
  1087. CHECK_ARGUMENT(!(op & VARIABLE_FLAG_MASK)
  1088. || (GET_FLAG_TYPE(op) >= SLJIT_LESS && GET_FLAG_TYPE(op) <= SLJIT_OVERFLOW)
  1089. || GET_FLAG_TYPE(op) == GET_FLAG_TYPE(SLJIT_SET_CARRY));
  1090. break;
  1091. case SLJIT_ADDC:
  1092. case SLJIT_SUBC:
  1093. CHECK_ARGUMENT(!(op & VARIABLE_FLAG_MASK)
  1094. || GET_FLAG_TYPE(op) == GET_FLAG_TYPE(SLJIT_SET_CARRY));
  1095. CHECK_ARGUMENT((compiler->last_flags & 0xff) == GET_FLAG_TYPE(SLJIT_SET_CARRY));
  1096. CHECK_ARGUMENT((op & SLJIT_I32_OP) == (compiler->last_flags & SLJIT_I32_OP));
  1097. break;
  1098. default:
  1099. SLJIT_UNREACHABLE();
  1100. break;
  1101. }
  1102. FUNCTION_CHECK_DST(dst, dstw, HAS_FLAGS(op));
  1103. FUNCTION_CHECK_SRC(src1, src1w);
  1104. FUNCTION_CHECK_SRC(src2, src2w);
  1105. compiler->last_flags = GET_FLAG_TYPE(op) | (op & (SLJIT_I32_OP | SLJIT_SET_Z));
  1106. #endif
  1107. #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
  1108. if (SLJIT_UNLIKELY(!!compiler->verbose)) {
  1109. fprintf(compiler->verbose, " %s%s%s%s%s ", op2_names[GET_OPCODE(op) - SLJIT_OP2_BASE], !(op & SLJIT_I32_OP) ? "" : "32",
  1110. !(op & SLJIT_SET_Z) ? "" : ".z", !(op & VARIABLE_FLAG_MASK) ? "" : ".",
  1111. !(op & VARIABLE_FLAG_MASK) ? "" : jump_names[GET_FLAG_TYPE(op)]);
  1112. sljit_verbose_param(compiler, dst, dstw);
  1113. fprintf(compiler->verbose, ", ");
  1114. sljit_verbose_param(compiler, src1, src1w);
  1115. fprintf(compiler->verbose, ", ");
  1116. sljit_verbose_param(compiler, src2, src2w);
  1117. fprintf(compiler->verbose, "\n");
  1118. }
  1119. #endif
  1120. CHECK_RETURN_OK;
  1121. }
  1122. static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_op_src(struct sljit_compiler *compiler, sljit_s32 op,
  1123. sljit_s32 src, sljit_sw srcw)
  1124. {
  1125. #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
  1126. CHECK_ARGUMENT(op >= SLJIT_FAST_RETURN && op <= SLJIT_PREFETCH_ONCE);
  1127. FUNCTION_CHECK_SRC(src, srcw);
  1128. if (op == SLJIT_FAST_RETURN || op == SLJIT_SKIP_FRAMES_BEFORE_FAST_RETURN)
  1129. {
  1130. CHECK_ARGUMENT(src != SLJIT_IMM);
  1131. compiler->last_flags = 0;
  1132. }
  1133. else if (op >= SLJIT_PREFETCH_L1 && op <= SLJIT_PREFETCH_ONCE)
  1134. {
  1135. CHECK_ARGUMENT(src & SLJIT_MEM);
  1136. }
  1137. #endif
  1138. #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
  1139. if (SLJIT_UNLIKELY(!!compiler->verbose)) {
  1140. fprintf(compiler->verbose, " %s ", op_src_names[op - SLJIT_OP_SRC_BASE]);
  1141. sljit_verbose_param(compiler, src, srcw);
  1142. fprintf(compiler->verbose, "\n");
  1143. }
  1144. #endif
  1145. CHECK_RETURN_OK;
  1146. }
  1147. static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_get_register_index(sljit_s32 reg)
  1148. {
  1149. SLJIT_UNUSED_ARG(reg);
  1150. #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
  1151. CHECK_ARGUMENT(reg > 0 && reg <= SLJIT_NUMBER_OF_REGISTERS);
  1152. #endif
  1153. CHECK_RETURN_OK;
  1154. }
  1155. static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_get_float_register_index(sljit_s32 reg)
  1156. {
  1157. SLJIT_UNUSED_ARG(reg);
  1158. #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
  1159. CHECK_ARGUMENT(reg > 0 && reg <= SLJIT_NUMBER_OF_FLOAT_REGISTERS);
  1160. #endif
  1161. CHECK_RETURN_OK;
  1162. }
  1163. static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_op_custom(struct sljit_compiler *compiler,
  1164. void *instruction, sljit_s32 size)
  1165. {
  1166. #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
  1167. int i;
  1168. #endif
  1169. SLJIT_UNUSED_ARG(compiler);
  1170. #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
  1171. CHECK_ARGUMENT(instruction);
  1172. #if (defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86)
  1173. CHECK_ARGUMENT(size > 0 && size < 16);
  1174. #elif (defined SLJIT_CONFIG_ARM_THUMB2 && SLJIT_CONFIG_ARM_THUMB2)
  1175. CHECK_ARGUMENT((size == 2 && (((sljit_sw)instruction) & 0x1) == 0)
  1176. || (size == 4 && (((sljit_sw)instruction) & 0x3) == 0));
  1177. #elif (defined SLJIT_CONFIG_S390X && SLJIT_CONFIG_S390X)
  1178. CHECK_ARGUMENT(size == 2 || size == 4 || size == 6);
  1179. #else
  1180. CHECK_ARGUMENT(size == 4 && (((sljit_sw)instruction) & 0x3) == 0);
  1181. #endif
  1182. compiler->last_flags = 0;
  1183. #endif
  1184. #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
  1185. if (SLJIT_UNLIKELY(!!compiler->verbose)) {
  1186. fprintf(compiler->verbose, " op_custom");
  1187. for (i = 0; i < size; i++)
  1188. fprintf(compiler->verbose, " 0x%x", ((sljit_u8*)instruction)[i]);
  1189. fprintf(compiler->verbose, "\n");
  1190. }
  1191. #endif
  1192. CHECK_RETURN_OK;
  1193. }
  1194. static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_fop1(struct sljit_compiler *compiler, sljit_s32 op,
  1195. sljit_s32 dst, sljit_sw dstw,
  1196. sljit_s32 src, sljit_sw srcw)
  1197. {
  1198. if (SLJIT_UNLIKELY(compiler->skip_checks)) {
  1199. compiler->skip_checks = 0;
  1200. CHECK_RETURN_OK;
  1201. }
  1202. #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
  1203. CHECK_ARGUMENT(sljit_has_cpu_feature(SLJIT_HAS_FPU));
  1204. CHECK_ARGUMENT(GET_OPCODE(op) >= SLJIT_MOV_F64 && GET_OPCODE(op) <= SLJIT_ABS_F64);
  1205. CHECK_ARGUMENT(!(op & (SLJIT_SET_Z | VARIABLE_FLAG_MASK)));
  1206. FUNCTION_FCHECK(src, srcw);
  1207. FUNCTION_FCHECK(dst, dstw);
  1208. #endif
  1209. #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
  1210. if (SLJIT_UNLIKELY(!!compiler->verbose)) {
  1211. if (GET_OPCODE(op) == SLJIT_CONV_F64_FROM_F32)
  1212. fprintf(compiler->verbose, " %s%s ", fop1_names[SLJIT_CONV_F64_FROM_F32 - SLJIT_FOP1_BASE],
  1213. (op & SLJIT_F32_OP) ? ".f32.from.f64" : ".f64.from.f32");
  1214. else
  1215. fprintf(compiler->verbose, " %s%s ", fop1_names[GET_OPCODE(op) - SLJIT_FOP1_BASE],
  1216. (op & SLJIT_F32_OP) ? ".f32" : ".f64");
  1217. sljit_verbose_fparam(compiler, dst, dstw);
  1218. fprintf(compiler->verbose, ", ");
  1219. sljit_verbose_fparam(compiler, src, srcw);
  1220. fprintf(compiler->verbose, "\n");
  1221. }
  1222. #endif
  1223. CHECK_RETURN_OK;
  1224. }
  1225. static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_fop1_cmp(struct sljit_compiler *compiler, sljit_s32 op,
  1226. sljit_s32 src1, sljit_sw src1w,
  1227. sljit_s32 src2, sljit_sw src2w)
  1228. {
  1229. #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
  1230. compiler->last_flags = GET_FLAG_TYPE(op) | (op & (SLJIT_I32_OP | SLJIT_SET_Z));
  1231. #endif
  1232. if (SLJIT_UNLIKELY(compiler->skip_checks)) {
  1233. compiler->skip_checks = 0;
  1234. CHECK_RETURN_OK;
  1235. }
  1236. #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
  1237. CHECK_ARGUMENT(sljit_has_cpu_feature(SLJIT_HAS_FPU));
  1238. CHECK_ARGUMENT(GET_OPCODE(op) == SLJIT_CMP_F64);
  1239. CHECK_ARGUMENT(!(op & SLJIT_SET_Z));
  1240. CHECK_ARGUMENT((op & VARIABLE_FLAG_MASK)
  1241. || (GET_FLAG_TYPE(op) >= SLJIT_EQUAL_F64 && GET_FLAG_TYPE(op) <= SLJIT_ORDERED_F64));
  1242. FUNCTION_FCHECK(src1, src1w);
  1243. FUNCTION_FCHECK(src2, src2w);
  1244. #endif
  1245. #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
  1246. if (SLJIT_UNLIKELY(!!compiler->verbose)) {
  1247. fprintf(compiler->verbose, " %s%s", fop1_names[SLJIT_CMP_F64 - SLJIT_FOP1_BASE], (op & SLJIT_F32_OP) ? ".f32" : ".f64");
  1248. if (op & VARIABLE_FLAG_MASK) {
  1249. fprintf(compiler->verbose, ".%s_f", jump_names[GET_FLAG_TYPE(op)]);
  1250. }
  1251. fprintf(compiler->verbose, " ");
  1252. sljit_verbose_fparam(compiler, src1, src1w);
  1253. fprintf(compiler->verbose, ", ");
  1254. sljit_verbose_fparam(compiler, src2, src2w);
  1255. fprintf(compiler->verbose, "\n");
  1256. }
  1257. #endif
  1258. CHECK_RETURN_OK;
  1259. }
  1260. static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_fop1_conv_sw_from_f64(struct sljit_compiler *compiler, sljit_s32 op,
  1261. sljit_s32 dst, sljit_sw dstw,
  1262. sljit_s32 src, sljit_sw srcw)
  1263. {
  1264. if (SLJIT_UNLIKELY(compiler->skip_checks)) {
  1265. compiler->skip_checks = 0;
  1266. CHECK_RETURN_OK;
  1267. }
  1268. #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
  1269. CHECK_ARGUMENT(sljit_has_cpu_feature(SLJIT_HAS_FPU));
  1270. CHECK_ARGUMENT(GET_OPCODE(op) >= SLJIT_CONV_SW_FROM_F64 && GET_OPCODE(op) <= SLJIT_CONV_S32_FROM_F64);
  1271. CHECK_ARGUMENT(!(op & (SLJIT_SET_Z | VARIABLE_FLAG_MASK)));
  1272. FUNCTION_FCHECK(src, srcw);
  1273. FUNCTION_CHECK_DST(dst, dstw, 0);
  1274. #endif
  1275. #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
  1276. if (SLJIT_UNLIKELY(!!compiler->verbose)) {
  1277. fprintf(compiler->verbose, " %s%s.from%s ", fop1_names[GET_OPCODE(op) - SLJIT_FOP1_BASE],
  1278. (GET_OPCODE(op) == SLJIT_CONV_S32_FROM_F64) ? ".s32" : ".sw",
  1279. (op & SLJIT_F32_OP) ? ".f32" : ".f64");
  1280. sljit_verbose_param(compiler, dst, dstw);
  1281. fprintf(compiler->verbose, ", ");
  1282. sljit_verbose_fparam(compiler, src, srcw);
  1283. fprintf(compiler->verbose, "\n");
  1284. }
  1285. #endif
  1286. CHECK_RETURN_OK;
  1287. }
  1288. static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_fop1_conv_f64_from_sw(struct sljit_compiler *compiler, sljit_s32 op,
  1289. sljit_s32 dst, sljit_sw dstw,
  1290. sljit_s32 src, sljit_sw srcw)
  1291. {
  1292. if (SLJIT_UNLIKELY(compiler->skip_checks)) {
  1293. compiler->skip_checks = 0;
  1294. CHECK_RETURN_OK;
  1295. }
  1296. #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
  1297. CHECK_ARGUMENT(sljit_has_cpu_feature(SLJIT_HAS_FPU));
  1298. CHECK_ARGUMENT(GET_OPCODE(op) >= SLJIT_CONV_F64_FROM_SW && GET_OPCODE(op) <= SLJIT_CONV_F64_FROM_S32);
  1299. CHECK_ARGUMENT(!(op & (SLJIT_SET_Z | VARIABLE_FLAG_MASK)));
  1300. FUNCTION_CHECK_SRC(src, srcw);
  1301. FUNCTION_FCHECK(dst, dstw);
  1302. #endif
  1303. #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
  1304. if (SLJIT_UNLIKELY(!!compiler->verbose)) {
  1305. fprintf(compiler->verbose, " %s%s.from%s ", fop1_names[GET_OPCODE(op) - SLJIT_FOP1_BASE],
  1306. (op & SLJIT_F32_OP) ? ".f32" : ".f64",
  1307. (GET_OPCODE(op) == SLJIT_CONV_F64_FROM_S32) ? ".s32" : ".sw");
  1308. sljit_verbose_fparam(compiler, dst, dstw);
  1309. fprintf(compiler->verbose, ", ");
  1310. sljit_verbose_param(compiler, src, srcw);
  1311. fprintf(compiler->verbose, "\n");
  1312. }
  1313. #endif
  1314. CHECK_RETURN_OK;
  1315. }
  1316. static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_fop2(struct sljit_compiler *compiler, sljit_s32 op,
  1317. sljit_s32 dst, sljit_sw dstw,
  1318. sljit_s32 src1, sljit_sw src1w,
  1319. sljit_s32 src2, sljit_sw src2w)
  1320. {
  1321. #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
  1322. CHECK_ARGUMENT(sljit_has_cpu_feature(SLJIT_HAS_FPU));
  1323. CHECK_ARGUMENT(GET_OPCODE(op) >= SLJIT_ADD_F64 && GET_OPCODE(op) <= SLJIT_DIV_F64);
  1324. CHECK_ARGUMENT(!(op & (SLJIT_SET_Z | VARIABLE_FLAG_MASK)));
  1325. FUNCTION_FCHECK(src1, src1w);
  1326. FUNCTION_FCHECK(src2, src2w);
  1327. FUNCTION_FCHECK(dst, dstw);
  1328. #endif
  1329. #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
  1330. if (SLJIT_UNLIKELY(!!compiler->verbose)) {
  1331. fprintf(compiler->verbose, " %s%s ", fop2_names[GET_OPCODE(op) - SLJIT_FOP2_BASE], (op & SLJIT_F32_OP) ? ".f32" : ".f64");
  1332. sljit_verbose_fparam(compiler, dst, dstw);
  1333. fprintf(compiler->verbose, ", ");
  1334. sljit_verbose_fparam(compiler, src1, src1w);
  1335. fprintf(compiler->verbose, ", ");
  1336. sljit_verbose_fparam(compiler, src2, src2w);
  1337. fprintf(compiler->verbose, "\n");
  1338. }
  1339. #endif
  1340. CHECK_RETURN_OK;
  1341. }
  1342. static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_label(struct sljit_compiler *compiler)
  1343. {
  1344. SLJIT_UNUSED_ARG(compiler);
  1345. if (SLJIT_UNLIKELY(compiler->skip_checks)) {
  1346. compiler->skip_checks = 0;
  1347. CHECK_RETURN_OK;
  1348. }
  1349. #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
  1350. compiler->last_flags = 0;
  1351. #endif
  1352. #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
  1353. if (SLJIT_UNLIKELY(!!compiler->verbose))
  1354. fprintf(compiler->verbose, "label:\n");
  1355. #endif
  1356. CHECK_RETURN_OK;
  1357. }
  1358. static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_jump(struct sljit_compiler *compiler, sljit_s32 type)
  1359. {
  1360. if (SLJIT_UNLIKELY(compiler->skip_checks)) {
  1361. compiler->skip_checks = 0;
  1362. CHECK_RETURN_OK;
  1363. }
  1364. #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
  1365. CHECK_ARGUMENT(!(type & ~(0xff | SLJIT_REWRITABLE_JUMP | SLJIT_I32_OP)));
  1366. CHECK_ARGUMENT((type & 0xff) != GET_FLAG_TYPE(SLJIT_SET_CARRY) && (type & 0xff) != (GET_FLAG_TYPE(SLJIT_SET_CARRY) + 1));
  1367. CHECK_ARGUMENT((type & 0xff) >= SLJIT_EQUAL && (type & 0xff) <= SLJIT_FAST_CALL);
  1368. CHECK_ARGUMENT((type & 0xff) < SLJIT_JUMP || !(type & SLJIT_I32_OP));
  1369. if ((type & 0xff) < SLJIT_JUMP) {
  1370. if ((type & 0xff) <= SLJIT_NOT_ZERO)
  1371. CHECK_ARGUMENT(compiler->last_flags & SLJIT_SET_Z);
  1372. else
  1373. CHECK_ARGUMENT((type & 0xff) == (compiler->last_flags & 0xff)
  1374. || ((type & 0xff) == SLJIT_NOT_OVERFLOW && (compiler->last_flags & 0xff) == SLJIT_OVERFLOW));
  1375. }
  1376. #endif
  1377. #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
  1378. if (SLJIT_UNLIKELY(!!compiler->verbose))
  1379. fprintf(compiler->verbose, " jump%s %s%s\n", !(type & SLJIT_REWRITABLE_JUMP) ? "" : ".r",
  1380. jump_names[type & 0xff], JUMP_POSTFIX(type));
  1381. #endif
  1382. CHECK_RETURN_OK;
  1383. }
  1384. static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_call(struct sljit_compiler *compiler, sljit_s32 type,
  1385. sljit_s32 arg_types)
  1386. {
  1387. #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
  1388. sljit_s32 i, types, curr_type, scratches, fscratches;
  1389. CHECK_ARGUMENT(!(type & ~(0xff | SLJIT_REWRITABLE_JUMP)));
  1390. CHECK_ARGUMENT((type & 0xff) == SLJIT_CALL || (type & 0xff) == SLJIT_CALL_CDECL);
  1391. types = arg_types;
  1392. scratches = 0;
  1393. fscratches = 0;
  1394. for (i = 0; i < 5; i++) {
  1395. curr_type = (types & SLJIT_DEF_MASK);
  1396. CHECK_ARGUMENT(curr_type <= SLJIT_ARG_TYPE_F64);
  1397. if (i > 0) {
  1398. if (curr_type == 0) {
  1399. break;
  1400. }
  1401. if (curr_type >= SLJIT_ARG_TYPE_F32)
  1402. fscratches++;
  1403. else
  1404. scratches++;
  1405. } else {
  1406. if (curr_type >= SLJIT_ARG_TYPE_F32) {
  1407. CHECK_ARGUMENT(compiler->fscratches > 0);
  1408. } else if (curr_type >= SLJIT_ARG_TYPE_SW) {
  1409. CHECK_ARGUMENT(compiler->scratches > 0);
  1410. }
  1411. }
  1412. types >>= SLJIT_DEF_SHIFT;
  1413. }
  1414. CHECK_ARGUMENT(compiler->scratches >= scratches);
  1415. CHECK_ARGUMENT(compiler->fscratches >= fscratches);
  1416. CHECK_ARGUMENT(types == 0);
  1417. #endif
  1418. #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
  1419. if (SLJIT_UNLIKELY(!!compiler->verbose)) {
  1420. fprintf(compiler->verbose, " %s%s ret[%s", jump_names[type & 0xff],
  1421. !(type & SLJIT_REWRITABLE_JUMP) ? "" : ".r", call_arg_names[arg_types & SLJIT_DEF_MASK]);
  1422. arg_types >>= SLJIT_DEF_SHIFT;
  1423. if (arg_types) {
  1424. fprintf(compiler->verbose, "], args[");
  1425. do {
  1426. fprintf(compiler->verbose, "%s", call_arg_names[arg_types & SLJIT_DEF_MASK]);
  1427. arg_types >>= SLJIT_DEF_SHIFT;
  1428. if (arg_types)
  1429. fprintf(compiler->verbose, ",");
  1430. } while (arg_types);
  1431. }
  1432. fprintf(compiler->verbose, "]\n");
  1433. }
  1434. #endif
  1435. CHECK_RETURN_OK;
  1436. }
  1437. static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_cmp(struct sljit_compiler *compiler, sljit_s32 type,
  1438. sljit_s32 src1, sljit_sw src1w,
  1439. sljit_s32 src2, sljit_sw src2w)
  1440. {
  1441. #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
  1442. CHECK_ARGUMENT(!(type & ~(0xff | SLJIT_REWRITABLE_JUMP | SLJIT_I32_OP)));
  1443. CHECK_ARGUMENT((type & 0xff) >= SLJIT_EQUAL && (type & 0xff) <= SLJIT_SIG_LESS_EQUAL);
  1444. FUNCTION_CHECK_SRC(src1, src1w);
  1445. FUNCTION_CHECK_SRC(src2, src2w);
  1446. compiler->last_flags = 0;
  1447. #endif
  1448. #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
  1449. if (SLJIT_UNLIKELY(!!compiler->verbose)) {
  1450. fprintf(compiler->verbose, " cmp%s %s%s, ", !(type & SLJIT_REWRITABLE_JUMP) ? "" : ".r",
  1451. jump_names[type & 0xff], (type & SLJIT_I32_OP) ? "32" : "");
  1452. sljit_verbose_param(compiler, src1, src1w);
  1453. fprintf(compiler->verbose, ", ");
  1454. sljit_verbose_param(compiler, src2, src2w);
  1455. fprintf(compiler->verbose, "\n");
  1456. }
  1457. #endif
  1458. CHECK_RETURN_OK;
  1459. }
  1460. static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_fcmp(struct sljit_compiler *compiler, sljit_s32 type,
  1461. sljit_s32 src1, sljit_sw src1w,
  1462. sljit_s32 src2, sljit_sw src2w)
  1463. {
  1464. #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
  1465. CHECK_ARGUMENT(sljit_has_cpu_feature(SLJIT_HAS_FPU));
  1466. CHECK_ARGUMENT(!(type & ~(0xff | SLJIT_REWRITABLE_JUMP | SLJIT_F32_OP)));
  1467. CHECK_ARGUMENT((type & 0xff) >= SLJIT_EQUAL_F64 && (type & 0xff) <= SLJIT_ORDERED_F64);
  1468. FUNCTION_FCHECK(src1, src1w);
  1469. FUNCTION_FCHECK(src2, src2w);
  1470. compiler->last_flags = 0;
  1471. #endif
  1472. #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
  1473. if (SLJIT_UNLIKELY(!!compiler->verbose)) {
  1474. fprintf(compiler->verbose, " fcmp%s %s%s, ", !(type & SLJIT_REWRITABLE_JUMP) ? "" : ".r",
  1475. jump_names[type & 0xff], (type & SLJIT_F32_OP) ? ".f32" : ".f64");
  1476. sljit_verbose_fparam(compiler, src1, src1w);
  1477. fprintf(compiler->verbose, ", ");
  1478. sljit_verbose_fparam(compiler, src2, src2w);
  1479. fprintf(compiler->verbose, "\n");
  1480. }
  1481. #endif
  1482. CHECK_RETURN_OK;
  1483. }
  1484. static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_ijump(struct sljit_compiler *compiler, sljit_s32 type,
  1485. sljit_s32 src, sljit_sw srcw)
  1486. {
  1487. if (SLJIT_UNLIKELY(compiler->skip_checks)) {
  1488. compiler->skip_checks = 0;
  1489. CHECK_RETURN_OK;
  1490. }
  1491. #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
  1492. CHECK_ARGUMENT(type >= SLJIT_JUMP && type <= SLJIT_FAST_CALL);
  1493. FUNCTION_CHECK_SRC(src, srcw);
  1494. #endif
  1495. #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
  1496. if (SLJIT_UNLIKELY(!!compiler->verbose)) {
  1497. fprintf(compiler->verbose, " ijump.%s ", jump_names[type]);
  1498. sljit_verbose_param(compiler, src, srcw);
  1499. fprintf(compiler->verbose, "\n");
  1500. }
  1501. #endif
  1502. CHECK_RETURN_OK;
  1503. }
  1504. static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_icall(struct sljit_compiler *compiler, sljit_s32 type,
  1505. sljit_s32 arg_types,
  1506. sljit_s32 src, sljit_sw srcw)
  1507. {
  1508. #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
  1509. sljit_s32 i, types, curr_type, scratches, fscratches;
  1510. CHECK_ARGUMENT(type == SLJIT_CALL || type == SLJIT_CALL_CDECL);
  1511. FUNCTION_CHECK_SRC(src, srcw);
  1512. types = arg_types;
  1513. scratches = 0;
  1514. fscratches = 0;
  1515. for (i = 0; i < 5; i++) {
  1516. curr_type = (types & SLJIT_DEF_MASK);
  1517. CHECK_ARGUMENT(curr_type <= SLJIT_ARG_TYPE_F64);
  1518. if (i > 0) {
  1519. if (curr_type == 0) {
  1520. break;
  1521. }
  1522. if (curr_type >= SLJIT_ARG_TYPE_F32)
  1523. fscratches++;
  1524. else
  1525. scratches++;
  1526. } else {
  1527. if (curr_type >= SLJIT_ARG_TYPE_F32) {
  1528. CHECK_ARGUMENT(compiler->fscratches > 0);
  1529. } else if (curr_type >= SLJIT_ARG_TYPE_SW) {
  1530. CHECK_ARGUMENT(compiler->scratches > 0);
  1531. }
  1532. }
  1533. types >>= SLJIT_DEF_SHIFT;
  1534. }
  1535. CHECK_ARGUMENT(compiler->scratches >= scratches);
  1536. CHECK_ARGUMENT(compiler->fscratches >= fscratches);
  1537. CHECK_ARGUMENT(types == 0);
  1538. #endif
  1539. #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
  1540. if (SLJIT_UNLIKELY(!!compiler->verbose)) {
  1541. fprintf(compiler->verbose, " i%s%s ret[%s", jump_names[type & 0xff],
  1542. !(type & SLJIT_REWRITABLE_JUMP) ? "" : ".r", call_arg_names[arg_types & SLJIT_DEF_MASK]);
  1543. arg_types >>= SLJIT_DEF_SHIFT;
  1544. if (arg_types) {
  1545. fprintf(compiler->verbose, "], args[");
  1546. do {
  1547. fprintf(compiler->verbose, "%s", call_arg_names[arg_types & SLJIT_DEF_MASK]);
  1548. arg_types >>= SLJIT_DEF_SHIFT;
  1549. if (arg_types)
  1550. fprintf(compiler->verbose, ",");
  1551. } while (arg_types);
  1552. }
  1553. fprintf(compiler->verbose, "], ");
  1554. sljit_verbose_param(compiler, src, srcw);
  1555. fprintf(compiler->verbose, "\n");
  1556. }
  1557. #endif
  1558. CHECK_RETURN_OK;
  1559. }
  1560. static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_op_flags(struct sljit_compiler *compiler, sljit_s32 op,
  1561. sljit_s32 dst, sljit_sw dstw,
  1562. sljit_s32 type)
  1563. {
  1564. #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
  1565. CHECK_ARGUMENT(!(type & ~(0xff | SLJIT_I32_OP)));
  1566. CHECK_ARGUMENT((type & 0xff) >= SLJIT_EQUAL && (type & 0xff) <= SLJIT_ORDERED_F64);
  1567. CHECK_ARGUMENT((type & 0xff) != GET_FLAG_TYPE(SLJIT_SET_CARRY) && (type & 0xff) != (GET_FLAG_TYPE(SLJIT_SET_CARRY) + 1));
  1568. CHECK_ARGUMENT(op == SLJIT_MOV || op == SLJIT_MOV32
  1569. || (GET_OPCODE(op) >= SLJIT_AND && GET_OPCODE(op) <= SLJIT_XOR));
  1570. CHECK_ARGUMENT(!(op & VARIABLE_FLAG_MASK));
  1571. if ((type & 0xff) <= SLJIT_NOT_ZERO)
  1572. CHECK_ARGUMENT(compiler->last_flags & SLJIT_SET_Z);
  1573. else
  1574. CHECK_ARGUMENT((type & 0xff) == (compiler->last_flags & 0xff)
  1575. || ((type & 0xff) == SLJIT_NOT_OVERFLOW && (compiler->last_flags & 0xff) == SLJIT_OVERFLOW));
  1576. FUNCTION_CHECK_DST(dst, dstw, 0);
  1577. if (GET_OPCODE(op) >= SLJIT_ADD)
  1578. compiler->last_flags = GET_FLAG_TYPE(op) | (op & (SLJIT_I32_OP | SLJIT_SET_Z));
  1579. #endif
  1580. #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
  1581. if (SLJIT_UNLIKELY(!!compiler->verbose)) {
  1582. fprintf(compiler->verbose, " flags%s %s%s, ",
  1583. !(op & SLJIT_SET_Z) ? "" : ".z",
  1584. GET_OPCODE(op) < SLJIT_OP2_BASE ? "mov" : op2_names[GET_OPCODE(op) - SLJIT_OP2_BASE],
  1585. GET_OPCODE(op) < SLJIT_OP2_BASE ? op1_names[GET_OPCODE(op) - SLJIT_OP1_BASE] : ((op & SLJIT_I32_OP) ? "32" : ""));
  1586. sljit_verbose_param(compiler, dst, dstw);
  1587. fprintf(compiler->verbose, ", %s%s\n", jump_names[type & 0xff], JUMP_POSTFIX(type));
  1588. }
  1589. #endif
  1590. CHECK_RETURN_OK;
  1591. }
  1592. static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_cmov(struct sljit_compiler *compiler, sljit_s32 type,
  1593. sljit_s32 dst_reg,
  1594. sljit_s32 src, sljit_sw srcw)
  1595. {
  1596. #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
  1597. CHECK_ARGUMENT(!(type & ~(0xff | SLJIT_I32_OP)));
  1598. CHECK_ARGUMENT((type & 0xff) >= SLJIT_EQUAL && (type & 0xff) <= SLJIT_ORDERED_F64);
  1599. CHECK_ARGUMENT(compiler->scratches != -1 && compiler->saveds != -1);
  1600. CHECK_ARGUMENT(FUNCTION_CHECK_IS_REG(dst_reg & ~SLJIT_I32_OP));
  1601. if (src != SLJIT_IMM) {
  1602. CHECK_ARGUMENT(FUNCTION_CHECK_IS_REG(src));
  1603. CHECK_ARGUMENT(srcw == 0);
  1604. }
  1605. if ((type & 0xff) <= SLJIT_NOT_ZERO)
  1606. CHECK_ARGUMENT(compiler->last_flags & SLJIT_SET_Z);
  1607. else
  1608. CHECK_ARGUMENT((type & 0xff) == (compiler->last_flags & 0xff)
  1609. || ((type & 0xff) == SLJIT_NOT_OVERFLOW && (compiler->last_flags & 0xff) == SLJIT_OVERFLOW));
  1610. #endif
  1611. #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
  1612. if (SLJIT_UNLIKELY(!!compiler->verbose)) {
  1613. fprintf(compiler->verbose, " cmov%s %s%s, ",
  1614. !(dst_reg & SLJIT_I32_OP) ? "" : "32",
  1615. jump_names[type & 0xff], JUMP_POSTFIX(type));
  1616. sljit_verbose_reg(compiler, dst_reg & ~SLJIT_I32_OP);
  1617. fprintf(compiler->verbose, ", ");
  1618. sljit_verbose_param(compiler, src, srcw);
  1619. fprintf(compiler->verbose, "\n");
  1620. }
  1621. #endif
  1622. CHECK_RETURN_OK;
  1623. }
  1624. static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_mem(struct sljit_compiler *compiler, sljit_s32 type,
  1625. sljit_s32 reg,
  1626. sljit_s32 mem, sljit_sw memw)
  1627. {
  1628. #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
  1629. CHECK_ARGUMENT((type & 0xff) >= SLJIT_MOV && (type & 0xff) <= SLJIT_MOV_P);
  1630. CHECK_ARGUMENT(!(type & SLJIT_I32_OP) || ((type & 0xff) != SLJIT_MOV && (type & 0xff) != SLJIT_MOV_U32 && (type & 0xff) != SLJIT_MOV_P));
  1631. CHECK_ARGUMENT((type & SLJIT_MEM_PRE) || (type & SLJIT_MEM_POST));
  1632. CHECK_ARGUMENT((type & (SLJIT_MEM_PRE | SLJIT_MEM_POST)) != (SLJIT_MEM_PRE | SLJIT_MEM_POST));
  1633. CHECK_ARGUMENT((type & ~(0xff | SLJIT_I32_OP | SLJIT_MEM_STORE | SLJIT_MEM_SUPP | SLJIT_MEM_PRE | SLJIT_MEM_POST)) == 0);
  1634. FUNCTION_CHECK_SRC_MEM(mem, memw);
  1635. CHECK_ARGUMENT(FUNCTION_CHECK_IS_REG(reg));
  1636. CHECK_ARGUMENT((mem & REG_MASK) != SLJIT_UNUSED && (mem & REG_MASK) != reg);
  1637. #endif
  1638. #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
  1639. if (!(type & SLJIT_MEM_SUPP) && SLJIT_UNLIKELY(!!compiler->verbose)) {
  1640. if (sljit_emit_mem(compiler, type | SLJIT_MEM_SUPP, reg, mem, memw) == SLJIT_ERR_UNSUPPORTED)
  1641. fprintf(compiler->verbose, " //");
  1642. fprintf(compiler->verbose, " mem%s.%s%s%s ",
  1643. !(type & SLJIT_I32_OP) ? "" : "32",
  1644. (type & SLJIT_MEM_STORE) ? "st" : "ld",
  1645. op1_names[(type & 0xff) - SLJIT_OP1_BASE],
  1646. (type & SLJIT_MEM_PRE) ? ".pre" : ".post");
  1647. sljit_verbose_reg(compiler, reg);
  1648. fprintf(compiler->verbose, ", ");
  1649. sljit_verbose_param(compiler, mem, memw);
  1650. fprintf(compiler->verbose, "\n");
  1651. }
  1652. #endif
  1653. CHECK_RETURN_OK;
  1654. }
  1655. static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_fmem(struct sljit_compiler *compiler, sljit_s32 type,
  1656. sljit_s32 freg,
  1657. sljit_s32 mem, sljit_sw memw)
  1658. {
  1659. #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
  1660. CHECK_ARGUMENT((type & 0xff) == SLJIT_MOV_F64);
  1661. CHECK_ARGUMENT((type & SLJIT_MEM_PRE) || (type & SLJIT_MEM_POST));
  1662. CHECK_ARGUMENT((type & (SLJIT_MEM_PRE | SLJIT_MEM_POST)) != (SLJIT_MEM_PRE | SLJIT_MEM_POST));
  1663. CHECK_ARGUMENT((type & ~(0xff | SLJIT_I32_OP | SLJIT_MEM_STORE | SLJIT_MEM_SUPP | SLJIT_MEM_PRE | SLJIT_MEM_POST)) == 0);
  1664. FUNCTION_CHECK_SRC_MEM(mem, memw);
  1665. CHECK_ARGUMENT(FUNCTION_CHECK_IS_FREG(freg));
  1666. #endif
  1667. #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
  1668. if (!(type & SLJIT_MEM_SUPP) && SLJIT_UNLIKELY(!!compiler->verbose)) {
  1669. if (sljit_emit_fmem(compiler, type | SLJIT_MEM_SUPP, freg, mem, memw) == SLJIT_ERR_UNSUPPORTED)
  1670. fprintf(compiler->verbose, " //");
  1671. fprintf(compiler->verbose, " fmem.%s%s%s ",
  1672. (type & SLJIT_MEM_STORE) ? "st" : "ld",
  1673. !(type & SLJIT_I32_OP) ? ".f64" : ".f32",
  1674. (type & SLJIT_MEM_PRE) ? ".pre" : ".post");
  1675. sljit_verbose_freg(compiler, freg);
  1676. fprintf(compiler->verbose, ", ");
  1677. sljit_verbose_param(compiler, mem, memw);
  1678. fprintf(compiler->verbose, "\n");
  1679. }
  1680. #endif
  1681. CHECK_RETURN_OK;
  1682. }
  1683. static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_get_local_base(struct sljit_compiler *compiler, sljit_s32 dst, sljit_sw dstw, sljit_sw offset)
  1684. {
  1685. /* Any offset is allowed. */
  1686. SLJIT_UNUSED_ARG(offset);
  1687. #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
  1688. FUNCTION_CHECK_DST(dst, dstw, 0);
  1689. #endif
  1690. #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
  1691. if (SLJIT_UNLIKELY(!!compiler->verbose)) {
  1692. fprintf(compiler->verbose, " local_base ");
  1693. sljit_verbose_param(compiler, dst, dstw);
  1694. fprintf(compiler->verbose, ", #%" SLJIT_PRINT_D "d\n", offset);
  1695. }
  1696. #endif
  1697. CHECK_RETURN_OK;
  1698. }
  1699. static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_const(struct sljit_compiler *compiler, sljit_s32 dst, sljit_sw dstw, sljit_sw init_value)
  1700. {
  1701. SLJIT_UNUSED_ARG(init_value);
  1702. #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
  1703. FUNCTION_CHECK_DST(dst, dstw, 0);
  1704. #endif
  1705. #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
  1706. if (SLJIT_UNLIKELY(!!compiler->verbose)) {
  1707. fprintf(compiler->verbose, " const ");
  1708. sljit_verbose_param(compiler, dst, dstw);
  1709. fprintf(compiler->verbose, ", #%" SLJIT_PRINT_D "d\n", init_value);
  1710. }
  1711. #endif
  1712. CHECK_RETURN_OK;
  1713. }
  1714. static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_put_label(struct sljit_compiler *compiler, sljit_s32 dst, sljit_sw dstw)
  1715. {
  1716. #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
  1717. FUNCTION_CHECK_DST(dst, dstw, 0);
  1718. #endif
  1719. #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
  1720. if (SLJIT_UNLIKELY(!!compiler->verbose)) {
  1721. fprintf(compiler->verbose, " put_label ");
  1722. sljit_verbose_param(compiler, dst, dstw);
  1723. fprintf(compiler->verbose, "\n");
  1724. }
  1725. #endif
  1726. CHECK_RETURN_OK;
  1727. }
  1728. #endif /* SLJIT_ARGUMENT_CHECKS || SLJIT_VERBOSE */
  1729. #define SELECT_FOP1_OPERATION_WITH_CHECKS(compiler, op, dst, dstw, src, srcw) \
  1730. SLJIT_COMPILE_ASSERT(!(SLJIT_CONV_SW_FROM_F64 & 0x1) && !(SLJIT_CONV_F64_FROM_SW & 0x1), \
  1731. invalid_float_opcodes); \
  1732. if (GET_OPCODE(op) >= SLJIT_CONV_SW_FROM_F64 && GET_OPCODE(op) <= SLJIT_CMP_F64) { \
  1733. if (GET_OPCODE(op) == SLJIT_CMP_F64) { \
  1734. CHECK(check_sljit_emit_fop1_cmp(compiler, op, dst, dstw, src, srcw)); \
  1735. ADJUST_LOCAL_OFFSET(dst, dstw); \
  1736. ADJUST_LOCAL_OFFSET(src, srcw); \
  1737. return sljit_emit_fop1_cmp(compiler, op, dst, dstw, src, srcw); \
  1738. } \
  1739. if ((GET_OPCODE(op) | 0x1) == SLJIT_CONV_S32_FROM_F64) { \
  1740. CHECK(check_sljit_emit_fop1_conv_sw_from_f64(compiler, op, dst, dstw, src, srcw)); \
  1741. ADJUST_LOCAL_OFFSET(dst, dstw); \
  1742. ADJUST_LOCAL_OFFSET(src, srcw); \
  1743. return sljit_emit_fop1_conv_sw_from_f64(compiler, op, dst, dstw, src, srcw); \
  1744. } \
  1745. CHECK(check_sljit_emit_fop1_conv_f64_from_sw(compiler, op, dst, dstw, src, srcw)); \
  1746. ADJUST_LOCAL_OFFSET(dst, dstw); \
  1747. ADJUST_LOCAL_OFFSET(src, srcw); \
  1748. return sljit_emit_fop1_conv_f64_from_sw(compiler, op, dst, dstw, src, srcw); \
  1749. } \
  1750. CHECK(check_sljit_emit_fop1(compiler, op, dst, dstw, src, srcw)); \
  1751. ADJUST_LOCAL_OFFSET(dst, dstw); \
  1752. ADJUST_LOCAL_OFFSET(src, srcw);
  1753. static SLJIT_INLINE sljit_s32 emit_mov_before_return(struct sljit_compiler *compiler, sljit_s32 op, sljit_s32 src, sljit_sw srcw)
  1754. {
  1755. /* Return if don't need to do anything. */
  1756. if (op == SLJIT_UNUSED)
  1757. return SLJIT_SUCCESS;
  1758. #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
  1759. /* At the moment the pointer size is always equal to sljit_sw. May be changed in the future. */
  1760. if (src == SLJIT_RETURN_REG && (op == SLJIT_MOV || op == SLJIT_MOV_P))
  1761. return SLJIT_SUCCESS;
  1762. #else
  1763. if (src == SLJIT_RETURN_REG && (op == SLJIT_MOV || op == SLJIT_MOV_U32 || op == SLJIT_MOV_S32 || op == SLJIT_MOV_P))
  1764. return SLJIT_SUCCESS;
  1765. #endif
  1766. #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) \
  1767. || (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
  1768. compiler->skip_checks = 1;
  1769. #endif
  1770. return sljit_emit_op1(compiler, op, SLJIT_RETURN_REG, 0, src, srcw);
  1771. }
  1772. #if (defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86) \
  1773. || (defined SLJIT_CONFIG_PPC && SLJIT_CONFIG_PPC) \
  1774. || (defined SLJIT_CONFIG_SPARC_32 && SLJIT_CONFIG_SPARC_32) \
  1775. || ((defined SLJIT_CONFIG_MIPS && SLJIT_CONFIG_MIPS) && !(defined SLJIT_MIPS_REV && SLJIT_MIPS_REV >= 1 && SLJIT_MIPS_REV < 6))
  1776. static SLJIT_INLINE sljit_s32 sljit_emit_cmov_generic(struct sljit_compiler *compiler, sljit_s32 type,
  1777. sljit_s32 dst_reg,
  1778. sljit_s32 src, sljit_sw srcw)
  1779. {
  1780. struct sljit_label *label;
  1781. struct sljit_jump *jump;
  1782. sljit_s32 op = (dst_reg & SLJIT_I32_OP) ? SLJIT_MOV32 : SLJIT_MOV;
  1783. #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) \
  1784. || (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
  1785. compiler->skip_checks = 1;
  1786. #endif
  1787. jump = sljit_emit_jump(compiler, type ^ 0x1);
  1788. FAIL_IF(!jump);
  1789. #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) \
  1790. || (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
  1791. compiler->skip_checks = 1;
  1792. #endif
  1793. FAIL_IF(sljit_emit_op1(compiler, op, dst_reg & ~SLJIT_I32_OP, 0, src, srcw));
  1794. #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) \
  1795. || (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
  1796. compiler->skip_checks = 1;
  1797. #endif
  1798. label = sljit_emit_label(compiler);
  1799. FAIL_IF(!label);
  1800. sljit_set_label(jump, label);
  1801. return SLJIT_SUCCESS;
  1802. }
  1803. #endif
  1804. /* CPU description section */
  1805. #if (defined SLJIT_32BIT_ARCHITECTURE && SLJIT_32BIT_ARCHITECTURE)
  1806. #define SLJIT_CPUINFO_PART1 " 32bit ("
  1807. #elif (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
  1808. #define SLJIT_CPUINFO_PART1 " 64bit ("
  1809. #else
  1810. #error "Internal error: CPU type info missing"
  1811. #endif
  1812. #if (defined SLJIT_LITTLE_ENDIAN && SLJIT_LITTLE_ENDIAN)
  1813. #define SLJIT_CPUINFO_PART2 "little endian + "
  1814. #elif (defined SLJIT_BIG_ENDIAN && SLJIT_BIG_ENDIAN)
  1815. #define SLJIT_CPUINFO_PART2 "big endian + "
  1816. #else
  1817. #error "Internal error: CPU type info missing"
  1818. #endif
  1819. #if (defined SLJIT_UNALIGNED && SLJIT_UNALIGNED)
  1820. #define SLJIT_CPUINFO_PART3 "unaligned)"
  1821. #else
  1822. #define SLJIT_CPUINFO_PART3 "aligned)"
  1823. #endif
  1824. #define SLJIT_CPUINFO SLJIT_CPUINFO_PART1 SLJIT_CPUINFO_PART2 SLJIT_CPUINFO_PART3
  1825. #if (defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86)
  1826. # include "sljitNativeX86_common.c"
  1827. #elif (defined SLJIT_CONFIG_ARM_V5 && SLJIT_CONFIG_ARM_V5)
  1828. # include "sljitNativeARM_32.c"
  1829. #elif (defined SLJIT_CONFIG_ARM_V7 && SLJIT_CONFIG_ARM_V7)
  1830. # include "sljitNativeARM_32.c"
  1831. #elif (defined SLJIT_CONFIG_ARM_THUMB2 && SLJIT_CONFIG_ARM_THUMB2)
  1832. # include "sljitNativeARM_T2_32.c"
  1833. #elif (defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64)
  1834. # include "sljitNativeARM_64.c"
  1835. #elif (defined SLJIT_CONFIG_PPC && SLJIT_CONFIG_PPC)
  1836. # include "sljitNativePPC_common.c"
  1837. #elif (defined SLJIT_CONFIG_MIPS && SLJIT_CONFIG_MIPS)
  1838. # include "sljitNativeMIPS_common.c"
  1839. #elif (defined SLJIT_CONFIG_SPARC && SLJIT_CONFIG_SPARC)
  1840. # include "sljitNativeSPARC_common.c"
  1841. #elif (defined SLJIT_CONFIG_S390X && SLJIT_CONFIG_S390X)
  1842. # include "sljitNativeS390X.c"
  1843. #endif
  1844. #if !(defined SLJIT_CONFIG_MIPS && SLJIT_CONFIG_MIPS)
  1845. SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_cmp(struct sljit_compiler *compiler, sljit_s32 type,
  1846. sljit_s32 src1, sljit_sw src1w,
  1847. sljit_s32 src2, sljit_sw src2w)
  1848. {
  1849. /* Default compare for most architectures. */
  1850. sljit_s32 flags, tmp_src, condition;
  1851. sljit_sw tmp_srcw;
  1852. CHECK_ERROR_PTR();
  1853. CHECK_PTR(check_sljit_emit_cmp(compiler, type, src1, src1w, src2, src2w));
  1854. condition = type & 0xff;
  1855. #if (defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64)
  1856. if ((condition == SLJIT_EQUAL || condition == SLJIT_NOT_EQUAL)) {
  1857. if ((src1 & SLJIT_IMM) && !src1w) {
  1858. src1 = src2;
  1859. src1w = src2w;
  1860. src2 = SLJIT_IMM;
  1861. src2w = 0;
  1862. }
  1863. if ((src2 & SLJIT_IMM) && !src2w)
  1864. return emit_cmp_to0(compiler, type, src1, src1w);
  1865. }
  1866. #endif
  1867. if (SLJIT_UNLIKELY((src1 & SLJIT_IMM) && !(src2 & SLJIT_IMM))) {
  1868. /* Immediate is preferred as second argument by most architectures. */
  1869. switch (condition) {
  1870. case SLJIT_LESS:
  1871. condition = SLJIT_GREATER;
  1872. break;
  1873. case SLJIT_GREATER_EQUAL:
  1874. condition = SLJIT_LESS_EQUAL;
  1875. break;
  1876. case SLJIT_GREATER:
  1877. condition = SLJIT_LESS;
  1878. break;
  1879. case SLJIT_LESS_EQUAL:
  1880. condition = SLJIT_GREATER_EQUAL;
  1881. break;
  1882. case SLJIT_SIG_LESS:
  1883. condition = SLJIT_SIG_GREATER;
  1884. break;
  1885. case SLJIT_SIG_GREATER_EQUAL:
  1886. condition = SLJIT_SIG_LESS_EQUAL;
  1887. break;
  1888. case SLJIT_SIG_GREATER:
  1889. condition = SLJIT_SIG_LESS;
  1890. break;
  1891. case SLJIT_SIG_LESS_EQUAL:
  1892. condition = SLJIT_SIG_GREATER_EQUAL;
  1893. break;
  1894. }
  1895. type = condition | (type & (SLJIT_I32_OP | SLJIT_REWRITABLE_JUMP));
  1896. tmp_src = src1;
  1897. src1 = src2;
  1898. src2 = tmp_src;
  1899. tmp_srcw = src1w;
  1900. src1w = src2w;
  1901. src2w = tmp_srcw;
  1902. }
  1903. if (condition <= SLJIT_NOT_ZERO)
  1904. flags = SLJIT_SET_Z;
  1905. else
  1906. flags = condition << VARIABLE_FLAG_SHIFT;
  1907. #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) \
  1908. || (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
  1909. compiler->skip_checks = 1;
  1910. #endif
  1911. PTR_FAIL_IF(sljit_emit_op2(compiler, SLJIT_SUB | flags | (type & SLJIT_I32_OP),
  1912. SLJIT_UNUSED, 0, src1, src1w, src2, src2w));
  1913. #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) \
  1914. || (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
  1915. compiler->skip_checks = 1;
  1916. #endif
  1917. return sljit_emit_jump(compiler, condition | (type & (SLJIT_REWRITABLE_JUMP | SLJIT_I32_OP)));
  1918. }
  1919. #endif
  1920. SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_fcmp(struct sljit_compiler *compiler, sljit_s32 type,
  1921. sljit_s32 src1, sljit_sw src1w,
  1922. sljit_s32 src2, sljit_sw src2w)
  1923. {
  1924. CHECK_ERROR_PTR();
  1925. CHECK_PTR(check_sljit_emit_fcmp(compiler, type, src1, src1w, src2, src2w));
  1926. #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) \
  1927. || (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
  1928. compiler->skip_checks = 1;
  1929. #endif
  1930. sljit_emit_fop1(compiler, SLJIT_CMP_F64 | ((type & 0xff) << VARIABLE_FLAG_SHIFT) | (type & SLJIT_I32_OP), src1, src1w, src2, src2w);
  1931. #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) \
  1932. || (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
  1933. compiler->skip_checks = 1;
  1934. #endif
  1935. return sljit_emit_jump(compiler, type);
  1936. }
  1937. #if !(defined SLJIT_CONFIG_ARM_32 && SLJIT_CONFIG_ARM_32) \
  1938. && !(defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64) \
  1939. && !(defined SLJIT_CONFIG_PPC && SLJIT_CONFIG_PPC)
  1940. SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_mem(struct sljit_compiler *compiler, sljit_s32 type,
  1941. sljit_s32 reg,
  1942. sljit_s32 mem, sljit_sw memw)
  1943. {
  1944. SLJIT_UNUSED_ARG(compiler);
  1945. SLJIT_UNUSED_ARG(type);
  1946. SLJIT_UNUSED_ARG(reg);
  1947. SLJIT_UNUSED_ARG(mem);
  1948. SLJIT_UNUSED_ARG(memw);
  1949. CHECK_ERROR();
  1950. CHECK(check_sljit_emit_mem(compiler, type, reg, mem, memw));
  1951. return SLJIT_ERR_UNSUPPORTED;
  1952. }
  1953. #endif
  1954. #if !(defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64) \
  1955. && !(defined SLJIT_CONFIG_PPC && SLJIT_CONFIG_PPC)
  1956. SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_fmem(struct sljit_compiler *compiler, sljit_s32 type,
  1957. sljit_s32 freg,
  1958. sljit_s32 mem, sljit_sw memw)
  1959. {
  1960. SLJIT_UNUSED_ARG(compiler);
  1961. SLJIT_UNUSED_ARG(type);
  1962. SLJIT_UNUSED_ARG(freg);
  1963. SLJIT_UNUSED_ARG(mem);
  1964. SLJIT_UNUSED_ARG(memw);
  1965. CHECK_ERROR();
  1966. CHECK(check_sljit_emit_fmem(compiler, type, freg, mem, memw));
  1967. return SLJIT_ERR_UNSUPPORTED;
  1968. }
  1969. #endif
  1970. #if !(defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86) \
  1971. && !(defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64)
  1972. SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_get_local_base(struct sljit_compiler *compiler, sljit_s32 dst, sljit_sw dstw, sljit_sw offset)
  1973. {
  1974. CHECK_ERROR();
  1975. CHECK(check_sljit_get_local_base(compiler, dst, dstw, offset));
  1976. ADJUST_LOCAL_OFFSET(SLJIT_MEM1(SLJIT_SP), offset);
  1977. #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) \
  1978. || (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
  1979. compiler->skip_checks = 1;
  1980. #endif
  1981. if (offset != 0)
  1982. return sljit_emit_op2(compiler, SLJIT_ADD, dst, dstw, SLJIT_SP, 0, SLJIT_IMM, offset);
  1983. return sljit_emit_op1(compiler, SLJIT_MOV, dst, dstw, SLJIT_SP, 0);
  1984. }
  1985. #endif
  1986. #else /* SLJIT_CONFIG_UNSUPPORTED */
  1987. /* Empty function bodies for those machines, which are not (yet) supported. */
  1988. SLJIT_API_FUNC_ATTRIBUTE const char* sljit_get_platform_name(void)
  1989. {
  1990. return "unsupported";
  1991. }
  1992. SLJIT_API_FUNC_ATTRIBUTE struct sljit_compiler* sljit_create_compiler(void *allocator_data, void *exec_allocator_data)
  1993. {
  1994. SLJIT_UNUSED_ARG(allocator_data);
  1995. SLJIT_UNUSED_ARG(exec_allocator_data);
  1996. SLJIT_UNREACHABLE();
  1997. return NULL;
  1998. }
  1999. SLJIT_API_FUNC_ATTRIBUTE void sljit_free_compiler(struct sljit_compiler *compiler)
  2000. {
  2001. SLJIT_UNUSED_ARG(compiler);
  2002. SLJIT_UNREACHABLE();
  2003. }
  2004. SLJIT_API_FUNC_ATTRIBUTE void sljit_set_compiler_memory_error(struct sljit_compiler *compiler)
  2005. {
  2006. SLJIT_UNUSED_ARG(compiler);
  2007. SLJIT_UNREACHABLE();
  2008. }
  2009. SLJIT_API_FUNC_ATTRIBUTE void* sljit_alloc_memory(struct sljit_compiler *compiler, sljit_s32 size)
  2010. {
  2011. SLJIT_UNUSED_ARG(compiler);
  2012. SLJIT_UNUSED_ARG(size);
  2013. SLJIT_UNREACHABLE();
  2014. return NULL;
  2015. }
  2016. #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
  2017. SLJIT_API_FUNC_ATTRIBUTE void sljit_compiler_verbose(struct sljit_compiler *compiler, FILE* verbose)
  2018. {
  2019. SLJIT_UNUSED_ARG(compiler);
  2020. SLJIT_UNUSED_ARG(verbose);
  2021. SLJIT_UNREACHABLE();
  2022. }
  2023. #endif
  2024. SLJIT_API_FUNC_ATTRIBUTE void* sljit_generate_code(struct sljit_compiler *compiler)
  2025. {
  2026. SLJIT_UNUSED_ARG(compiler);
  2027. SLJIT_UNREACHABLE();
  2028. return NULL;
  2029. }
  2030. SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_has_cpu_feature(sljit_s32 feature_type)
  2031. {
  2032. SLJIT_UNUSED_ARG(feature_type);
  2033. SLJIT_UNREACHABLE();
  2034. return 0;
  2035. }
  2036. SLJIT_API_FUNC_ATTRIBUTE void sljit_free_code(void* code, void *exec_allocator_data)
  2037. {
  2038. SLJIT_UNUSED_ARG(code);
  2039. SLJIT_UNUSED_ARG(exec_allocator_data);
  2040. SLJIT_UNREACHABLE();
  2041. }
  2042. SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_enter(struct sljit_compiler *compiler,
  2043. sljit_s32 options, sljit_s32 arg_types, sljit_s32 scratches, sljit_s32 saveds,
  2044. sljit_s32 fscratches, sljit_s32 fsaveds, sljit_s32 local_size)
  2045. {
  2046. SLJIT_UNUSED_ARG(compiler);
  2047. SLJIT_UNUSED_ARG(options);
  2048. SLJIT_UNUSED_ARG(arg_types);
  2049. SLJIT_UNUSED_ARG(scratches);
  2050. SLJIT_UNUSED_ARG(saveds);
  2051. SLJIT_UNUSED_ARG(fscratches);
  2052. SLJIT_UNUSED_ARG(fsaveds);
  2053. SLJIT_UNUSED_ARG(local_size);
  2054. SLJIT_UNREACHABLE();
  2055. return SLJIT_ERR_UNSUPPORTED;
  2056. }
  2057. SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_set_context(struct sljit_compiler *compiler,
  2058. sljit_s32 options, sljit_s32 arg_types, sljit_s32 scratches, sljit_s32 saveds,
  2059. sljit_s32 fscratches, sljit_s32 fsaveds, sljit_s32 local_size)
  2060. {
  2061. SLJIT_UNUSED_ARG(compiler);
  2062. SLJIT_UNUSED_ARG(options);
  2063. SLJIT_UNUSED_ARG(arg_types);
  2064. SLJIT_UNUSED_ARG(scratches);
  2065. SLJIT_UNUSED_ARG(saveds);
  2066. SLJIT_UNUSED_ARG(fscratches);
  2067. SLJIT_UNUSED_ARG(fsaveds);
  2068. SLJIT_UNUSED_ARG(local_size);
  2069. SLJIT_UNREACHABLE();
  2070. return SLJIT_ERR_UNSUPPORTED;
  2071. }
  2072. SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_return(struct sljit_compiler *compiler, sljit_s32 op, sljit_s32 src, sljit_sw srcw)
  2073. {
  2074. SLJIT_UNUSED_ARG(compiler);
  2075. SLJIT_UNUSED_ARG(op);
  2076. SLJIT_UNUSED_ARG(src);
  2077. SLJIT_UNUSED_ARG(srcw);
  2078. SLJIT_UNREACHABLE();
  2079. return SLJIT_ERR_UNSUPPORTED;
  2080. }
  2081. SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_fast_enter(struct sljit_compiler *compiler, sljit_s32 dst, sljit_sw dstw)
  2082. {
  2083. SLJIT_UNUSED_ARG(compiler);
  2084. SLJIT_UNUSED_ARG(dst);
  2085. SLJIT_UNUSED_ARG(dstw);
  2086. SLJIT_UNREACHABLE();
  2087. return SLJIT_ERR_UNSUPPORTED;
  2088. }
  2089. SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op0(struct sljit_compiler *compiler, sljit_s32 op)
  2090. {
  2091. SLJIT_UNUSED_ARG(compiler);
  2092. SLJIT_UNUSED_ARG(op);
  2093. SLJIT_UNREACHABLE();
  2094. return SLJIT_ERR_UNSUPPORTED;
  2095. }
  2096. SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op1(struct sljit_compiler *compiler, sljit_s32 op,
  2097. sljit_s32 dst, sljit_sw dstw,
  2098. sljit_s32 src, sljit_sw srcw)
  2099. {
  2100. SLJIT_UNUSED_ARG(compiler);
  2101. SLJIT_UNUSED_ARG(op);
  2102. SLJIT_UNUSED_ARG(dst);
  2103. SLJIT_UNUSED_ARG(dstw);
  2104. SLJIT_UNUSED_ARG(src);
  2105. SLJIT_UNUSED_ARG(srcw);
  2106. SLJIT_UNREACHABLE();
  2107. return SLJIT_ERR_UNSUPPORTED;
  2108. }
  2109. SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op2(struct sljit_compiler *compiler, sljit_s32 op,
  2110. sljit_s32 dst, sljit_sw dstw,
  2111. sljit_s32 src1, sljit_sw src1w,
  2112. sljit_s32 src2, sljit_sw src2w)
  2113. {
  2114. SLJIT_UNUSED_ARG(compiler);
  2115. SLJIT_UNUSED_ARG(op);
  2116. SLJIT_UNUSED_ARG(dst);
  2117. SLJIT_UNUSED_ARG(dstw);
  2118. SLJIT_UNUSED_ARG(src1);
  2119. SLJIT_UNUSED_ARG(src1w);
  2120. SLJIT_UNUSED_ARG(src2);
  2121. SLJIT_UNUSED_ARG(src2w);
  2122. SLJIT_UNREACHABLE();
  2123. return SLJIT_ERR_UNSUPPORTED;
  2124. }
  2125. SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op_src(struct sljit_compiler *compiler, sljit_s32 op,
  2126. sljit_s32 src, sljit_sw srcw)
  2127. {
  2128. SLJIT_UNUSED_ARG(compiler);
  2129. SLJIT_UNUSED_ARG(op);
  2130. SLJIT_UNUSED_ARG(src);
  2131. SLJIT_UNUSED_ARG(srcw);
  2132. SLJIT_UNREACHABLE();
  2133. return SLJIT_ERR_UNSUPPORTED;
  2134. }
  2135. SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_get_register_index(sljit_s32 reg)
  2136. {
  2137. SLJIT_UNREACHABLE();
  2138. return reg;
  2139. }
  2140. SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op_custom(struct sljit_compiler *compiler,
  2141. void *instruction, sljit_s32 size)
  2142. {
  2143. SLJIT_UNUSED_ARG(compiler);
  2144. SLJIT_UNUSED_ARG(instruction);
  2145. SLJIT_UNUSED_ARG(size);
  2146. SLJIT_UNREACHABLE();
  2147. return SLJIT_ERR_UNSUPPORTED;
  2148. }
  2149. SLJIT_API_FUNC_ATTRIBUTE void sljit_set_current_flags(struct sljit_compiler *compiler, sljit_s32 current_flags)
  2150. {
  2151. SLJIT_UNUSED_ARG(compiler);
  2152. SLJIT_UNUSED_ARG(current_flags);
  2153. }
  2154. SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_fop1(struct sljit_compiler *compiler, sljit_s32 op,
  2155. sljit_s32 dst, sljit_sw dstw,
  2156. sljit_s32 src, sljit_sw srcw)
  2157. {
  2158. SLJIT_UNUSED_ARG(compiler);
  2159. SLJIT_UNUSED_ARG(op);
  2160. SLJIT_UNUSED_ARG(dst);
  2161. SLJIT_UNUSED_ARG(dstw);
  2162. SLJIT_UNUSED_ARG(src);
  2163. SLJIT_UNUSED_ARG(srcw);
  2164. SLJIT_UNREACHABLE();
  2165. return SLJIT_ERR_UNSUPPORTED;
  2166. }
  2167. SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_fop2(struct sljit_compiler *compiler, sljit_s32 op,
  2168. sljit_s32 dst, sljit_sw dstw,
  2169. sljit_s32 src1, sljit_sw src1w,
  2170. sljit_s32 src2, sljit_sw src2w)
  2171. {
  2172. SLJIT_UNUSED_ARG(compiler);
  2173. SLJIT_UNUSED_ARG(op);
  2174. SLJIT_UNUSED_ARG(dst);
  2175. SLJIT_UNUSED_ARG(dstw);
  2176. SLJIT_UNUSED_ARG(src1);
  2177. SLJIT_UNUSED_ARG(src1w);
  2178. SLJIT_UNUSED_ARG(src2);
  2179. SLJIT_UNUSED_ARG(src2w);
  2180. SLJIT_UNREACHABLE();
  2181. return SLJIT_ERR_UNSUPPORTED;
  2182. }
  2183. SLJIT_API_FUNC_ATTRIBUTE struct sljit_label* sljit_emit_label(struct sljit_compiler *compiler)
  2184. {
  2185. SLJIT_UNUSED_ARG(compiler);
  2186. SLJIT_UNREACHABLE();
  2187. return NULL;
  2188. }
  2189. SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_jump(struct sljit_compiler *compiler, sljit_s32 type)
  2190. {
  2191. SLJIT_UNUSED_ARG(compiler);
  2192. SLJIT_UNUSED_ARG(type);
  2193. SLJIT_UNREACHABLE();
  2194. return NULL;
  2195. }
  2196. SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_call(struct sljit_compiler *compiler, sljit_s32 type,
  2197. sljit_s32 arg_types)
  2198. {
  2199. SLJIT_UNUSED_ARG(compiler);
  2200. SLJIT_UNUSED_ARG(type);
  2201. SLJIT_UNUSED_ARG(arg_types);
  2202. SLJIT_UNREACHABLE();
  2203. return NULL;
  2204. }
  2205. SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_cmp(struct sljit_compiler *compiler, sljit_s32 type,
  2206. sljit_s32 src1, sljit_sw src1w,
  2207. sljit_s32 src2, sljit_sw src2w)
  2208. {
  2209. SLJIT_UNUSED_ARG(compiler);
  2210. SLJIT_UNUSED_ARG(type);
  2211. SLJIT_UNUSED_ARG(src1);
  2212. SLJIT_UNUSED_ARG(src1w);
  2213. SLJIT_UNUSED_ARG(src2);
  2214. SLJIT_UNUSED_ARG(src2w);
  2215. SLJIT_UNREACHABLE();
  2216. return NULL;
  2217. }
  2218. SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_fcmp(struct sljit_compiler *compiler, sljit_s32 type,
  2219. sljit_s32 src1, sljit_sw src1w,
  2220. sljit_s32 src2, sljit_sw src2w)
  2221. {
  2222. SLJIT_UNUSED_ARG(compiler);
  2223. SLJIT_UNUSED_ARG(type);
  2224. SLJIT_UNUSED_ARG(src1);
  2225. SLJIT_UNUSED_ARG(src1w);
  2226. SLJIT_UNUSED_ARG(src2);
  2227. SLJIT_UNUSED_ARG(src2w);
  2228. SLJIT_UNREACHABLE();
  2229. return NULL;
  2230. }
  2231. SLJIT_API_FUNC_ATTRIBUTE void sljit_set_label(struct sljit_jump *jump, struct sljit_label* label)
  2232. {
  2233. SLJIT_UNUSED_ARG(jump);
  2234. SLJIT_UNUSED_ARG(label);
  2235. SLJIT_UNREACHABLE();
  2236. }
  2237. SLJIT_API_FUNC_ATTRIBUTE void sljit_set_target(struct sljit_jump *jump, sljit_uw target)
  2238. {
  2239. SLJIT_UNUSED_ARG(jump);
  2240. SLJIT_UNUSED_ARG(target);
  2241. SLJIT_UNREACHABLE();
  2242. }
  2243. SLJIT_API_FUNC_ATTRIBUTE void sljit_set_put_label(struct sljit_put_label *put_label, struct sljit_label *label)
  2244. {
  2245. SLJIT_UNUSED_ARG(put_label);
  2246. SLJIT_UNUSED_ARG(label);
  2247. SLJIT_UNREACHABLE();
  2248. }
  2249. SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_ijump(struct sljit_compiler *compiler, sljit_s32 type, sljit_s32 src, sljit_sw srcw)
  2250. {
  2251. SLJIT_UNUSED_ARG(compiler);
  2252. SLJIT_UNUSED_ARG(type);
  2253. SLJIT_UNUSED_ARG(src);
  2254. SLJIT_UNUSED_ARG(srcw);
  2255. SLJIT_UNREACHABLE();
  2256. return SLJIT_ERR_UNSUPPORTED;
  2257. }
  2258. SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_icall(struct sljit_compiler *compiler, sljit_s32 type,
  2259. sljit_s32 arg_types,
  2260. sljit_s32 src, sljit_sw srcw)
  2261. {
  2262. SLJIT_UNUSED_ARG(compiler);
  2263. SLJIT_UNUSED_ARG(type);
  2264. SLJIT_UNUSED_ARG(arg_types);
  2265. SLJIT_UNUSED_ARG(src);
  2266. SLJIT_UNUSED_ARG(srcw);
  2267. SLJIT_UNREACHABLE();
  2268. return SLJIT_ERR_UNSUPPORTED;
  2269. }
  2270. SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op_flags(struct sljit_compiler *compiler, sljit_s32 op,
  2271. sljit_s32 dst, sljit_sw dstw,
  2272. sljit_s32 type)
  2273. {
  2274. SLJIT_UNUSED_ARG(compiler);
  2275. SLJIT_UNUSED_ARG(op);
  2276. SLJIT_UNUSED_ARG(dst);
  2277. SLJIT_UNUSED_ARG(dstw);
  2278. SLJIT_UNUSED_ARG(type);
  2279. SLJIT_UNREACHABLE();
  2280. return SLJIT_ERR_UNSUPPORTED;
  2281. }
  2282. SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_cmov(struct sljit_compiler *compiler, sljit_s32 type,
  2283. sljit_s32 dst_reg,
  2284. sljit_s32 src, sljit_sw srcw)
  2285. {
  2286. SLJIT_UNUSED_ARG(compiler);
  2287. SLJIT_UNUSED_ARG(type);
  2288. SLJIT_UNUSED_ARG(dst_reg);
  2289. SLJIT_UNUSED_ARG(src);
  2290. SLJIT_UNUSED_ARG(srcw);
  2291. SLJIT_UNREACHABLE();
  2292. return SLJIT_ERR_UNSUPPORTED;
  2293. }
  2294. SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_mem(struct sljit_compiler *compiler, sljit_s32 type, sljit_s32 reg, sljit_s32 mem, sljit_sw memw)
  2295. {
  2296. SLJIT_UNUSED_ARG(compiler);
  2297. SLJIT_UNUSED_ARG(type);
  2298. SLJIT_UNUSED_ARG(reg);
  2299. SLJIT_UNUSED_ARG(mem);
  2300. SLJIT_UNUSED_ARG(memw);
  2301. SLJIT_UNREACHABLE();
  2302. return SLJIT_ERR_UNSUPPORTED;
  2303. }
  2304. SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_fmem(struct sljit_compiler *compiler, sljit_s32 type, sljit_s32 freg, sljit_s32 mem, sljit_sw memw)
  2305. {
  2306. SLJIT_UNUSED_ARG(compiler);
  2307. SLJIT_UNUSED_ARG(type);
  2308. SLJIT_UNUSED_ARG(freg);
  2309. SLJIT_UNUSED_ARG(mem);
  2310. SLJIT_UNUSED_ARG(memw);
  2311. SLJIT_UNREACHABLE();
  2312. return SLJIT_ERR_UNSUPPORTED;
  2313. }
  2314. SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_get_local_base(struct sljit_compiler *compiler, sljit_s32 dst, sljit_sw dstw, sljit_sw offset)
  2315. {
  2316. SLJIT_UNUSED_ARG(compiler);
  2317. SLJIT_UNUSED_ARG(dst);
  2318. SLJIT_UNUSED_ARG(dstw);
  2319. SLJIT_UNUSED_ARG(offset);
  2320. SLJIT_UNREACHABLE();
  2321. return SLJIT_ERR_UNSUPPORTED;
  2322. }
  2323. SLJIT_API_FUNC_ATTRIBUTE struct sljit_const* sljit_emit_const(struct sljit_compiler *compiler, sljit_s32 dst, sljit_sw dstw, sljit_sw initval)
  2324. {
  2325. SLJIT_UNUSED_ARG(compiler);
  2326. SLJIT_UNUSED_ARG(dst);
  2327. SLJIT_UNUSED_ARG(dstw);
  2328. SLJIT_UNUSED_ARG(initval);
  2329. SLJIT_UNREACHABLE();
  2330. return NULL;
  2331. }
  2332. SLJIT_API_FUNC_ATTRIBUTE struct sljit_put_label* sljit_emit_put_label(struct sljit_compiler *compiler, sljit_s32 dst, sljit_sw dstw)
  2333. {
  2334. SLJIT_UNUSED_ARG(compiler);
  2335. SLJIT_UNUSED_ARG(dst);
  2336. SLJIT_UNUSED_ARG(dstw);
  2337. return NULL;
  2338. }
  2339. SLJIT_API_FUNC_ATTRIBUTE void sljit_set_jump_addr(sljit_uw addr, sljit_uw new_target, sljit_sw executable_offset)
  2340. {
  2341. SLJIT_UNUSED_ARG(addr);
  2342. SLJIT_UNUSED_ARG(new_target);
  2343. SLJIT_UNUSED_ARG(executable_offset);
  2344. SLJIT_UNREACHABLE();
  2345. }
  2346. SLJIT_API_FUNC_ATTRIBUTE void sljit_set_const(sljit_uw addr, sljit_sw new_constant, sljit_sw executable_offset)
  2347. {
  2348. SLJIT_UNUSED_ARG(addr);
  2349. SLJIT_UNUSED_ARG(new_constant);
  2350. SLJIT_UNUSED_ARG(executable_offset);
  2351. SLJIT_UNREACHABLE();
  2352. }
  2353. #endif /* !SLJIT_CONFIG_UNSUPPORTED */