sljitLir.c 79 KB

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