sljitLir.c 81 KB

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