1use crate::enums::builtin_impl_type::BuiltinImplType;
2use crate::enums::int_64_binary::Int64Binary;
3use crate::enums::ir_cmd::IrCmd;
4use crate::enums::ir_condition::IrCondition;
5use crate::enums::ir_const_kind::IrConstKind;
6use crate::enums::ir_op_kind::IrOpKind;
7use crate::functions::is_compatible_constant::is_compatible_constant;
8use crate::functions::translate_builtin_2_number_to_number_libm::translate_builtin_2_number_to_number_libm;
9use crate::functions::translate_builtin_assert::translate_builtin_assert;
10use crate::functions::translate_builtin_bit_32_bnot::translate_builtin_bit_32_bnot;
11use crate::functions::translate_builtin_bit_32_extract::translate_builtin_bit_32_extract;
12use crate::functions::translate_builtin_bit_32_extract_k::translate_builtin_bit_32_extract_k;
13use crate::functions::translate_builtin_bit_32_multiarg_op::translate_builtin_bit_32_multiarg_op;
14use crate::functions::translate_builtin_bit_32_replace::translate_builtin_bit_32_replace;
15use crate::functions::translate_builtin_bit_32_rotate::translate_builtin_bit_32_rotate;
16use crate::functions::translate_builtin_bit_32_shift::translate_builtin_bit_32_shift;
17use crate::functions::translate_builtin_bit_32_unary::translate_builtin_bit_32_unary;
18use crate::functions::translate_builtin_buffer_read::translate_builtin_buffer_read;
19use crate::functions::translate_builtin_buffer_write::translate_builtin_buffer_write;
20use crate::functions::translate_builtin_int_64_binary::translate_builtin_int_64_binary;
21use crate::functions::translate_builtin_int_64_bnot::translate_builtin_int_64_bnot;
22use crate::functions::translate_builtin_int_64_clamp::translate_builtin_int_64_clamp;
23use crate::functions::translate_builtin_int_64_compare::translate_builtin_int_64_compare;
24use crate::functions::translate_builtin_int_64_create::translate_builtin_int_64_create;
25use crate::functions::translate_builtin_int_64_extract::translate_builtin_int_64_extract;
26use crate::functions::translate_builtin_int_64_min_max::translate_builtin_int_64_min_max;
27use crate::functions::translate_builtin_int_64_multiarg_op::translate_builtin_int_64_multiarg_op;
28use crate::functions::translate_builtin_int_64_neg::translate_builtin_int_64_neg;
29use crate::functions::translate_builtin_int_64_rotate::translate_builtin_int_64_rotate;
30use crate::functions::translate_builtin_int_64_shift::translate_builtin_int_64_shift;
31use crate::functions::translate_builtin_int_64_to_number::translate_builtin_int_64_to_number;
32use crate::functions::translate_builtin_int_64_unary::translate_builtin_int_64_unary;
33use crate::functions::translate_builtin_math_clamp::translate_builtin_math_clamp;
34use crate::functions::translate_builtin_math_deg_rad::translate_builtin_math_deg_rad;
35use crate::functions::translate_builtin_math_is_nan::translate_builtin_math_is_nan;
36use crate::functions::translate_builtin_math_lerp::translate_builtin_math_lerp;
37use crate::functions::translate_builtin_math_log::translate_builtin_math_log;
38use crate::functions::translate_builtin_math_min_max::translate_builtin_math_min_max;
39use crate::functions::translate_builtin_math_unary::translate_builtin_math_unary;
40use crate::functions::translate_builtin_number_to_2_number::translate_builtin_number_to_2_number;
41use crate::functions::translate_builtin_number_to_number_libm::translate_builtin_number_to_number_libm;
42use crate::functions::translate_builtin_string_len::translate_builtin_string_len;
43use crate::functions::translate_builtin_table_insert::translate_builtin_table_insert;
44use crate::functions::translate_builtin_type::translate_builtin_type;
45use crate::functions::translate_builtin_typeof::translate_builtin_typeof;
46use crate::functions::translate_builtin_vector::translate_builtin_vector;
47use crate::functions::translate_builtin_vector_clamp::translate_builtin_vector_clamp;
48use crate::functions::translate_builtin_vector_cross::translate_builtin_vector_cross;
49use crate::functions::translate_builtin_vector_dot::translate_builtin_vector_dot;
50use crate::functions::translate_builtin_vector_lerp::translate_builtin_vector_lerp;
51use crate::functions::translate_builtin_vector_magnitude::translate_builtin_vector_magnitude;
52use crate::functions::translate_builtin_vector_map_1::translate_builtin_vector_map_1;
53use crate::functions::translate_builtin_vector_map_1_x_4::translate_builtin_vector_map_1_x_4;
54use crate::functions::translate_builtin_vector_min_max::translate_builtin_vector_min_max;
55use crate::functions::translate_builtin_vector_normalize::translate_builtin_vector_normalize;
56use crate::records::builtin_impl_result::BuiltinImplResult;
57use crate::records::ir_builder::IrBuilder;
58use crate::records::ir_op::IrOp;
59use luaur_common::enums::luau_builtin_function::LuauBuiltinFunction as LBF;
60use luaur_common::FFlag;
61use luaur_vm::enums::lua_type::lua_Type;
62use luaur_vm::macros::lua_multret::LUA_MULTRET;
63
64fn no_builtin() -> BuiltinImplResult {
65 BuiltinImplResult {
66 r#type: BuiltinImplType::None,
67 actual_result_count: -1,
68 }
69}
70
71pub fn translate_builtin(
72 build: &mut IrBuilder,
73 bfid: i32,
74 ra: i32,
75 arg: i32,
76 args: IrOp,
77 arg3: IrOp,
78 nparams: i32,
79 nresults: i32,
80 fallback: IrOp,
81 pcpos: i32,
82) -> BuiltinImplResult {
83 if nparams == LUA_MULTRET {
84 return no_builtin();
85 }
86
87 if FFlag::LuauCodegenInteger2.get()
88 && (args.kind() == IrOpKind::Constant || arg3.kind() == IrOpKind::Constant)
89 {
90 match bfid {
91 x if x == LBF::LBF_MATH_MIN as i32
92 || x == LBF::LBF_MATH_MAX as i32
93 || x == LBF::LBF_MATH_POW as i32
94 || x == LBF::LBF_MATH_FMOD as i32
95 || x == LBF::LBF_MATH_ATAN2 as i32
96 || x == LBF::LBF_MATH_LDEXP as i32
97 || x == LBF::LBF_MATH_LERP as i32
98 || x == LBF::LBF_MATH_CLAMP as i32
99 || x == LBF::LBF_BIT32_BAND as i32
100 || x == LBF::LBF_BIT32_BOR as i32
101 || x == LBF::LBF_BIT32_BXOR as i32
102 || x == LBF::LBF_BIT32_BTEST as i32
103 || x == LBF::LBF_BIT32_LSHIFT as i32
104 || x == LBF::LBF_BIT32_RSHIFT as i32
105 || x == LBF::LBF_BIT32_ARSHIFT as i32
106 || x == LBF::LBF_BIT32_LROTATE as i32
107 || x == LBF::LBF_BIT32_RROTATE as i32
108 || x == LBF::LBF_BIT32_EXTRACT as i32
109 || x == LBF::LBF_BIT32_EXTRACTK as i32
110 || x == LBF::LBF_BIT32_REPLACE as i32
111 || x == LBF::LBF_VECTOR as i32
112 || x == LBF::LBF_TABLE_INSERT as i32
113 || x == LBF::LBF_BUFFER_READI8 as i32
114 || x == LBF::LBF_BUFFER_READU8 as i32
115 || x == LBF::LBF_BUFFER_WRITEU8 as i32
116 || x == LBF::LBF_BUFFER_READI16 as i32
117 || x == LBF::LBF_BUFFER_READU16 as i32
118 || x == LBF::LBF_BUFFER_WRITEU16 as i32
119 || x == LBF::LBF_BUFFER_READI32 as i32
120 || x == LBF::LBF_BUFFER_READU32 as i32
121 || x == LBF::LBF_BUFFER_WRITEU32 as i32
122 || x == LBF::LBF_BUFFER_READF32 as i32
123 || x == LBF::LBF_BUFFER_WRITEF32 as i32
124 || x == LBF::LBF_BUFFER_READF64 as i32
125 || x == LBF::LBF_BUFFER_WRITEF64 as i32
126 || x == LBF::LBF_BUFFER_READINTEGER as i32 =>
127 {
128 if !is_compatible_constant(build, args, IrConstKind::Double) {
129 return no_builtin();
130 }
131 if !is_compatible_constant(build, arg3, IrConstKind::Double) {
132 return no_builtin();
133 }
134 }
135 x if x == LBF::LBF_BUFFER_WRITEINTEGER as i32 => {
136 if !is_compatible_constant(build, args, IrConstKind::Double) {
137 return no_builtin();
138 }
139 if !is_compatible_constant(build, arg3, IrConstKind::Int64) {
140 return no_builtin();
141 }
142 }
143 x if x == LBF::LBF_INTEGER_ADD as i32
144 || x == LBF::LBF_INTEGER_SUB as i32
145 || x == LBF::LBF_INTEGER_MUL as i32
146 || x == LBF::LBF_INTEGER_DIV as i32
147 || x == LBF::LBF_INTEGER_IDIV as i32
148 || x == LBF::LBF_INTEGER_UDIV as i32
149 || x == LBF::LBF_INTEGER_REM as i32
150 || x == LBF::LBF_INTEGER_UREM as i32
151 || x == LBF::LBF_INTEGER_MOD as i32
152 || x == LBF::LBF_INTEGER_MIN as i32
153 || x == LBF::LBF_INTEGER_MAX as i32
154 || x == LBF::LBF_INTEGER_CLAMP as i32
155 || x == LBF::LBF_INTEGER_LT as i32
156 || x == LBF::LBF_INTEGER_LE as i32
157 || x == LBF::LBF_INTEGER_GT as i32
158 || x == LBF::LBF_INTEGER_GE as i32
159 || x == LBF::LBF_INTEGER_ULT as i32
160 || x == LBF::LBF_INTEGER_ULE as i32
161 || x == LBF::LBF_INTEGER_UGT as i32
162 || x == LBF::LBF_INTEGER_UGE as i32
163 || x == LBF::LBF_INTEGER_BAND as i32
164 || x == LBF::LBF_INTEGER_BOR as i32
165 || x == LBF::LBF_INTEGER_BXOR as i32
166 || x == LBF::LBF_INTEGER_BNOT as i32
167 || x == LBF::LBF_INTEGER_BTEST as i32
168 || x == LBF::LBF_INTEGER_LSHIFT as i32
169 || x == LBF::LBF_INTEGER_RSHIFT as i32
170 || x == LBF::LBF_INTEGER_ARSHIFT as i32
171 || x == LBF::LBF_INTEGER_LROTATE as i32
172 || x == LBF::LBF_INTEGER_RROTATE as i32
173 || x == LBF::LBF_INTEGER_EXTRACT as i32 =>
174 {
175 if !is_compatible_constant(build, args, IrConstKind::Int64) {
176 return no_builtin();
177 }
178 if !is_compatible_constant(build, arg3, IrConstKind::Int64) {
179 return no_builtin();
180 }
181 }
182 _ => {}
183 }
184 }
185
186 match bfid {
187 x if x == LBF::LBF_ASSERT as i32 => {
188 translate_builtin_assert(build, nparams, ra, arg, args, nresults, pcpos)
189 }
190 x if x == LBF::LBF_MATH_DEG as i32 => translate_builtin_math_deg_rad(
191 build,
192 IrCmd::DIV_NUM,
193 nparams,
194 ra,
195 arg,
196 args,
197 nresults,
198 pcpos,
199 ),
200 x if x == LBF::LBF_MATH_RAD as i32 => translate_builtin_math_deg_rad(
201 build,
202 IrCmd::MUL_NUM,
203 nparams,
204 ra,
205 arg,
206 args,
207 nresults,
208 pcpos,
209 ),
210 x if x == LBF::LBF_MATH_LOG as i32 => {
211 translate_builtin_math_log(build, nparams, ra, arg, args, nresults, pcpos)
212 }
213 x if x == LBF::LBF_MATH_MIN as i32 => translate_builtin_math_min_max(
214 build,
215 IrCmd::MIN_NUM,
216 nparams,
217 ra,
218 arg,
219 args,
220 arg3,
221 nresults,
222 pcpos,
223 ),
224 x if x == LBF::LBF_MATH_MAX as i32 => translate_builtin_math_min_max(
225 build,
226 IrCmd::MAX_NUM,
227 nparams,
228 ra,
229 arg,
230 args,
231 arg3,
232 nresults,
233 pcpos,
234 ),
235 x if x == LBF::LBF_MATH_CLAMP as i32 => translate_builtin_math_clamp(
236 build, nparams, ra, arg, args, arg3, nresults, fallback, pcpos,
237 ),
238 x if x == LBF::LBF_MATH_FLOOR as i32 => {
239 translate_builtin_math_unary(build, IrCmd::FLOOR_NUM, nparams, ra, arg, nresults, pcpos)
240 }
241 x if x == LBF::LBF_MATH_CEIL as i32 => {
242 translate_builtin_math_unary(build, IrCmd::CEIL_NUM, nparams, ra, arg, nresults, pcpos)
243 }
244 x if x == LBF::LBF_MATH_SQRT as i32 => {
245 translate_builtin_math_unary(build, IrCmd::SQRT_NUM, nparams, ra, arg, nresults, pcpos)
246 }
247 x if x == LBF::LBF_MATH_ABS as i32 => {
248 translate_builtin_math_unary(build, IrCmd::ABS_NUM, nparams, ra, arg, nresults, pcpos)
249 }
250 x if x == LBF::LBF_MATH_ROUND as i32 => {
251 translate_builtin_math_unary(build, IrCmd::ROUND_NUM, nparams, ra, arg, nresults, pcpos)
252 }
253 x if x == LBF::LBF_MATH_EXP as i32
254 || x == LBF::LBF_MATH_ASIN as i32
255 || x == LBF::LBF_MATH_SIN as i32
256 || x == LBF::LBF_MATH_SINH as i32
257 || x == LBF::LBF_MATH_ACOS as i32
258 || x == LBF::LBF_MATH_COS as i32
259 || x == LBF::LBF_MATH_COSH as i32
260 || x == LBF::LBF_MATH_ATAN as i32
261 || x == LBF::LBF_MATH_TAN as i32
262 || x == LBF::LBF_MATH_TANH as i32
263 || x == LBF::LBF_MATH_LOG10 as i32 =>
264 {
265 translate_builtin_number_to_number_libm(
266 build,
267 unsafe { core::mem::transmute(bfid as u8) },
268 nparams,
269 ra,
270 arg,
271 nresults,
272 pcpos,
273 )
274 }
275 x if x == LBF::LBF_MATH_SIGN as i32 => {
276 translate_builtin_math_unary(build, IrCmd::SIGN_NUM, nparams, ra, arg, nresults, pcpos)
277 }
278 x if x == LBF::LBF_MATH_POW as i32
279 || x == LBF::LBF_MATH_FMOD as i32
280 || x == LBF::LBF_MATH_ATAN2 as i32
281 || x == LBF::LBF_MATH_LDEXP as i32 =>
282 {
283 translate_builtin_2_number_to_number_libm(
284 build,
285 unsafe { core::mem::transmute(bfid as u8) },
286 nparams,
287 ra,
288 arg,
289 args,
290 nresults,
291 pcpos,
292 )
293 }
294 x if x == LBF::LBF_MATH_FREXP as i32 || x == LBF::LBF_MATH_MODF as i32 => {
295 translate_builtin_number_to_2_number(
296 build,
297 unsafe { core::mem::transmute(bfid as u8) },
298 nparams,
299 ra,
300 arg,
301 args,
302 nresults,
303 pcpos,
304 )
305 }
306 x if x == LBF::LBF_BIT32_BAND as i32 => translate_builtin_bit_32_multiarg_op(
307 build,
308 IrCmd::BITAND_UINT,
309 false,
310 nparams,
311 ra,
312 arg,
313 args,
314 arg3,
315 nresults,
316 pcpos,
317 ),
318 x if x == LBF::LBF_BIT32_BOR as i32 => translate_builtin_bit_32_multiarg_op(
319 build,
320 IrCmd::BITOR_UINT,
321 false,
322 nparams,
323 ra,
324 arg,
325 args,
326 arg3,
327 nresults,
328 pcpos,
329 ),
330 x if x == LBF::LBF_BIT32_BXOR as i32 => translate_builtin_bit_32_multiarg_op(
331 build,
332 IrCmd::BITXOR_UINT,
333 false,
334 nparams,
335 ra,
336 arg,
337 args,
338 arg3,
339 nresults,
340 pcpos,
341 ),
342 x if x == LBF::LBF_BIT32_BTEST as i32 => translate_builtin_bit_32_multiarg_op(
343 build,
344 IrCmd::BITAND_UINT,
345 true,
346 nparams,
347 ra,
348 arg,
349 args,
350 arg3,
351 nresults,
352 pcpos,
353 ),
354 x if x == LBF::LBF_BIT32_BNOT as i32 => {
355 translate_builtin_bit_32_bnot(build, nparams, ra, arg, args, nresults, pcpos)
356 }
357 x if x == LBF::LBF_BIT32_LSHIFT as i32 => translate_builtin_bit_32_shift(
358 build,
359 IrCmd::BITLSHIFT_UINT,
360 nparams,
361 ra,
362 arg,
363 args,
364 nresults,
365 pcpos,
366 ),
367 x if x == LBF::LBF_BIT32_RSHIFT as i32 => translate_builtin_bit_32_shift(
368 build,
369 IrCmd::BITRSHIFT_UINT,
370 nparams,
371 ra,
372 arg,
373 args,
374 nresults,
375 pcpos,
376 ),
377 x if x == LBF::LBF_BIT32_ARSHIFT as i32 => translate_builtin_bit_32_shift(
378 build,
379 IrCmd::BITARSHIFT_UINT,
380 nparams,
381 ra,
382 arg,
383 args,
384 nresults,
385 pcpos,
386 ),
387 x if x == LBF::LBF_BIT32_LROTATE as i32 => translate_builtin_bit_32_rotate(
388 build,
389 IrCmd::BITLROTATE_UINT,
390 nparams,
391 ra,
392 arg,
393 args,
394 nresults,
395 pcpos,
396 ),
397 x if x == LBF::LBF_BIT32_RROTATE as i32 => translate_builtin_bit_32_rotate(
398 build,
399 IrCmd::BITRROTATE_UINT,
400 nparams,
401 ra,
402 arg,
403 args,
404 nresults,
405 pcpos,
406 ),
407 x if x == LBF::LBF_BIT32_EXTRACT as i32 => {
408 translate_builtin_bit_32_extract(build, nparams, ra, arg, args, arg3, nresults, pcpos)
409 }
410 x if x == LBF::LBF_BIT32_EXTRACTK as i32 => {
411 translate_builtin_bit_32_extract_k(build, nparams, ra, arg, args, nresults, pcpos)
412 }
413 x if x == LBF::LBF_BIT32_COUNTLZ as i32 => translate_builtin_bit_32_unary(
414 build,
415 IrCmd::BITCOUNTLZ_UINT,
416 nparams,
417 ra,
418 arg,
419 args,
420 nresults,
421 pcpos,
422 ),
423 x if x == LBF::LBF_BIT32_COUNTRZ as i32 => translate_builtin_bit_32_unary(
424 build,
425 IrCmd::BITCOUNTRZ_UINT,
426 nparams,
427 ra,
428 arg,
429 args,
430 nresults,
431 pcpos,
432 ),
433 x if x == LBF::LBF_BIT32_REPLACE as i32 => {
434 translate_builtin_bit_32_replace(build, nparams, ra, arg, args, arg3, nresults, pcpos)
435 }
436 x if x == LBF::LBF_TYPE as i32 => {
437 translate_builtin_type(build, nparams, ra, arg, args, nresults)
438 }
439 x if x == LBF::LBF_TYPEOF as i32 => {
440 translate_builtin_typeof(build, nparams, ra, arg, args, nresults)
441 }
442 x if x == LBF::LBF_VECTOR as i32 => {
443 translate_builtin_vector(build, nparams, ra, arg, args, arg3, nresults, pcpos)
444 }
445 x if x == LBF::LBF_TABLE_INSERT as i32 => {
446 translate_builtin_table_insert(build, nparams, ra, arg, args, nresults, pcpos)
447 }
448 x if x == LBF::LBF_STRING_LEN as i32 => {
449 translate_builtin_string_len(build, nparams, ra, arg, args, nresults, pcpos)
450 }
451 x if x == LBF::LBF_BIT32_BYTESWAP as i32 => translate_builtin_bit_32_unary(
452 build,
453 IrCmd::BYTESWAP_UINT,
454 nparams,
455 ra,
456 arg,
457 args,
458 nresults,
459 pcpos,
460 ),
461 x if x == LBF::LBF_BUFFER_READI8 as i32 => translate_builtin_buffer_read(
462 build,
463 nparams,
464 ra,
465 arg,
466 args,
467 arg3,
468 nresults,
469 pcpos,
470 IrCmd::BUFFER_READI8,
471 1,
472 IrCmd::INT_TO_NUM,
473 IrCmd::STORE_DOUBLE,
474 lua_Type::LUA_TNUMBER as u8,
475 ),
476 x if x == LBF::LBF_BUFFER_READU8 as i32 => translate_builtin_buffer_read(
477 build,
478 nparams,
479 ra,
480 arg,
481 args,
482 arg3,
483 nresults,
484 pcpos,
485 IrCmd::BUFFER_READU8,
486 1,
487 IrCmd::INT_TO_NUM,
488 IrCmd::STORE_DOUBLE,
489 lua_Type::LUA_TNUMBER as u8,
490 ),
491 x if x == LBF::LBF_BUFFER_WRITEU8 as i32 => translate_builtin_buffer_write(
492 build,
493 nparams,
494 ra,
495 arg,
496 args,
497 arg3,
498 nresults,
499 pcpos,
500 IrCmd::BUFFER_WRITEI8,
501 1,
502 IrCmd::NUM_TO_UINT,
503 false,
504 ),
505 x if x == LBF::LBF_BUFFER_READI16 as i32 => translate_builtin_buffer_read(
506 build,
507 nparams,
508 ra,
509 arg,
510 args,
511 arg3,
512 nresults,
513 pcpos,
514 IrCmd::BUFFER_READI16,
515 2,
516 IrCmd::INT_TO_NUM,
517 IrCmd::STORE_DOUBLE,
518 lua_Type::LUA_TNUMBER as u8,
519 ),
520 x if x == LBF::LBF_BUFFER_READU16 as i32 => translate_builtin_buffer_read(
521 build,
522 nparams,
523 ra,
524 arg,
525 args,
526 arg3,
527 nresults,
528 pcpos,
529 IrCmd::BUFFER_READU16,
530 2,
531 IrCmd::INT_TO_NUM,
532 IrCmd::STORE_DOUBLE,
533 lua_Type::LUA_TNUMBER as u8,
534 ),
535 x if x == LBF::LBF_BUFFER_WRITEU16 as i32 => translate_builtin_buffer_write(
536 build,
537 nparams,
538 ra,
539 arg,
540 args,
541 arg3,
542 nresults,
543 pcpos,
544 IrCmd::BUFFER_WRITEI16,
545 2,
546 IrCmd::NUM_TO_UINT,
547 false,
548 ),
549 x if x == LBF::LBF_BUFFER_READI32 as i32 => translate_builtin_buffer_read(
550 build,
551 nparams,
552 ra,
553 arg,
554 args,
555 arg3,
556 nresults,
557 pcpos,
558 IrCmd::BUFFER_READI32,
559 4,
560 IrCmd::INT_TO_NUM,
561 IrCmd::STORE_DOUBLE,
562 lua_Type::LUA_TNUMBER as u8,
563 ),
564 x if x == LBF::LBF_BUFFER_READU32 as i32 => translate_builtin_buffer_read(
565 build,
566 nparams,
567 ra,
568 arg,
569 args,
570 arg3,
571 nresults,
572 pcpos,
573 IrCmd::BUFFER_READI32,
574 4,
575 IrCmd::UINT_TO_NUM,
576 IrCmd::STORE_DOUBLE,
577 lua_Type::LUA_TNUMBER as u8,
578 ),
579 x if x == LBF::LBF_BUFFER_WRITEU32 as i32 => translate_builtin_buffer_write(
580 build,
581 nparams,
582 ra,
583 arg,
584 args,
585 arg3,
586 nresults,
587 pcpos,
588 IrCmd::BUFFER_WRITEI32,
589 4,
590 IrCmd::NUM_TO_UINT,
591 false,
592 ),
593 x if x == LBF::LBF_BUFFER_READF32 as i32 => translate_builtin_buffer_read(
594 build,
595 nparams,
596 ra,
597 arg,
598 args,
599 arg3,
600 nresults,
601 pcpos,
602 IrCmd::BUFFER_READF32,
603 4,
604 IrCmd::FLOAT_TO_NUM,
605 IrCmd::STORE_DOUBLE,
606 lua_Type::LUA_TNUMBER as u8,
607 ),
608 x if x == LBF::LBF_BUFFER_WRITEF32 as i32 => translate_builtin_buffer_write(
609 build,
610 nparams,
611 ra,
612 arg,
613 args,
614 arg3,
615 nresults,
616 pcpos,
617 IrCmd::BUFFER_WRITEF32,
618 4,
619 IrCmd::NUM_TO_FLOAT,
620 false,
621 ),
622 x if x == LBF::LBF_BUFFER_READF64 as i32 => translate_builtin_buffer_read(
623 build,
624 nparams,
625 ra,
626 arg,
627 args,
628 arg3,
629 nresults,
630 pcpos,
631 IrCmd::BUFFER_READF64,
632 8,
633 IrCmd::NOP,
634 IrCmd::STORE_DOUBLE,
635 lua_Type::LUA_TNUMBER as u8,
636 ),
637 x if x == LBF::LBF_BUFFER_WRITEF64 as i32 => translate_builtin_buffer_write(
638 build,
639 nparams,
640 ra,
641 arg,
642 args,
643 arg3,
644 nresults,
645 pcpos,
646 IrCmd::BUFFER_WRITEF64,
647 8,
648 IrCmd::NOP,
649 false,
650 ),
651 x if x == LBF::LBF_BUFFER_READINTEGER as i32 => {
652 if FFlag::LuauCodegenBufferInteger.get() {
653 translate_builtin_buffer_read(
654 build,
655 nparams,
656 ra,
657 arg,
658 args,
659 arg3,
660 nresults,
661 pcpos,
662 IrCmd::BUFFER_READI64,
663 8,
664 IrCmd::NOP,
665 IrCmd::STORE_INT64,
666 lua_Type::LUA_TINTEGER as u8,
667 )
668 } else {
669 no_builtin()
670 }
671 }
672 x if x == LBF::LBF_BUFFER_WRITEINTEGER as i32 => {
673 if FFlag::LuauCodegenBufferInteger.get() {
674 translate_builtin_buffer_write(
675 build,
676 nparams,
677 ra,
678 arg,
679 args,
680 arg3,
681 nresults,
682 pcpos,
683 IrCmd::BUFFER_WRITEI64,
684 8,
685 IrCmd::NOP,
686 true,
687 )
688 } else {
689 no_builtin()
690 }
691 }
692 x if x == LBF::LBF_VECTOR_MAGNITUDE as i32 => {
693 translate_builtin_vector_magnitude(build, nparams, ra, arg, args, arg3, nresults, pcpos)
694 }
695 x if x == LBF::LBF_VECTOR_NORMALIZE as i32 => {
696 translate_builtin_vector_normalize(build, nparams, ra, arg, args, arg3, nresults, pcpos)
697 }
698 x if x == LBF::LBF_VECTOR_CROSS as i32 => {
699 translate_builtin_vector_cross(build, nparams, ra, arg, args, arg3, nresults, pcpos)
700 }
701 x if x == LBF::LBF_VECTOR_DOT as i32 => {
702 translate_builtin_vector_dot(build, nparams, ra, arg, args, arg3, nresults, pcpos)
703 }
704 x if x == LBF::LBF_VECTOR_FLOOR as i32 => translate_builtin_vector_map_1_x_4(
705 build,
706 IrCmd::FLOOR_VEC,
707 nparams,
708 ra,
709 arg,
710 args,
711 arg3,
712 nresults,
713 pcpos,
714 ),
715 x if x == LBF::LBF_VECTOR_CEIL as i32 => translate_builtin_vector_map_1_x_4(
716 build,
717 IrCmd::CEIL_VEC,
718 nparams,
719 ra,
720 arg,
721 args,
722 arg3,
723 nresults,
724 pcpos,
725 ),
726 x if x == LBF::LBF_VECTOR_ABS as i32 => translate_builtin_vector_map_1_x_4(
727 build,
728 IrCmd::ABS_VEC,
729 nparams,
730 ra,
731 arg,
732 args,
733 arg3,
734 nresults,
735 pcpos,
736 ),
737 x if x == LBF::LBF_VECTOR_SIGN as i32 => translate_builtin_vector_map_1(
738 build,
739 IrCmd::SIGN_FLOAT,
740 nparams,
741 ra,
742 arg,
743 args,
744 arg3,
745 nresults,
746 pcpos,
747 ),
748 x if x == LBF::LBF_VECTOR_CLAMP as i32 => translate_builtin_vector_clamp(
749 build, nparams, ra, arg, args, arg3, nresults, fallback, pcpos,
750 ),
751 x if x == LBF::LBF_VECTOR_MIN as i32 => translate_builtin_vector_min_max(
752 build,
753 IrCmd::MIN_VEC,
754 nparams,
755 ra,
756 arg,
757 args,
758 arg3,
759 nresults,
760 pcpos,
761 ),
762 x if x == LBF::LBF_VECTOR_MAX as i32 => translate_builtin_vector_min_max(
763 build,
764 IrCmd::MAX_VEC,
765 nparams,
766 ra,
767 arg,
768 args,
769 arg3,
770 nresults,
771 pcpos,
772 ),
773 x if x == LBF::LBF_VECTOR_LERP as i32 => {
774 translate_builtin_vector_lerp(build, nparams, ra, arg, args, arg3, nresults, pcpos)
775 }
776 x if x == LBF::LBF_MATH_LERP as i32 => translate_builtin_math_lerp(
777 build, nparams, ra, arg, args, arg3, nresults, fallback, pcpos,
778 ),
779 x if x == LBF::LBF_MATH_ISNAN as i32 => {
780 translate_builtin_math_is_nan(build, nparams, ra, arg, args, nresults, pcpos)
781 }
782 x if x == LBF::LBF_INTEGER_CREATE as i32 => {
783 if FFlag::LuauCodegenInteger2.get() {
784 translate_builtin_int_64_create(build, nparams, ra, arg, nresults, pcpos)
785 } else {
786 no_builtin()
787 }
788 }
789 x if x == LBF::LBF_INTEGER_TONUMBER as i32 => {
790 if FFlag::LuauCodegenInteger2.get() {
791 translate_builtin_int_64_to_number(build, nparams, ra, arg, nresults, pcpos)
792 } else {
793 no_builtin()
794 }
795 }
796 x if x == LBF::LBF_INTEGER_ADD as i32 => int2_binary(
797 build,
798 nparams,
799 ra,
800 arg,
801 args,
802 nresults,
803 pcpos,
804 Int64Binary::Add,
805 ),
806 x if x == LBF::LBF_INTEGER_SUB as i32 => int2_binary(
807 build,
808 nparams,
809 ra,
810 arg,
811 args,
812 nresults,
813 pcpos,
814 Int64Binary::Sub,
815 ),
816 x if x == LBF::LBF_INTEGER_MUL as i32 => int2_binary(
817 build,
818 nparams,
819 ra,
820 arg,
821 args,
822 nresults,
823 pcpos,
824 Int64Binary::Mul,
825 ),
826 x if x == LBF::LBF_INTEGER_DIV as i32 => int2_binary(
827 build,
828 nparams,
829 ra,
830 arg,
831 args,
832 nresults,
833 pcpos,
834 Int64Binary::Div,
835 ),
836 x if x == LBF::LBF_INTEGER_IDIV as i32 => int2_binary(
837 build,
838 nparams,
839 ra,
840 arg,
841 args,
842 nresults,
843 pcpos,
844 Int64Binary::Idiv,
845 ),
846 x if x == LBF::LBF_INTEGER_UDIV as i32 => int2_binary(
847 build,
848 nparams,
849 ra,
850 arg,
851 args,
852 nresults,
853 pcpos,
854 Int64Binary::Udiv,
855 ),
856 x if x == LBF::LBF_INTEGER_REM as i32 => int2_binary(
857 build,
858 nparams,
859 ra,
860 arg,
861 args,
862 nresults,
863 pcpos,
864 Int64Binary::Rem,
865 ),
866 x if x == LBF::LBF_INTEGER_UREM as i32 => int2_binary(
867 build,
868 nparams,
869 ra,
870 arg,
871 args,
872 nresults,
873 pcpos,
874 Int64Binary::Urem,
875 ),
876 x if x == LBF::LBF_INTEGER_MOD as i32 => int2_binary(
877 build,
878 nparams,
879 ra,
880 arg,
881 args,
882 nresults,
883 pcpos,
884 Int64Binary::Mod,
885 ),
886 x if x == LBF::LBF_INTEGER_MIN as i32 => {
887 if FFlag::LuauCodegenInteger2.get() {
888 translate_builtin_int_64_min_max(
889 build, nparams, ra, arg, args, arg3, nresults, pcpos, true,
890 )
891 } else {
892 no_builtin()
893 }
894 }
895 x if x == LBF::LBF_INTEGER_MAX as i32 => {
896 if FFlag::LuauCodegenInteger2.get() {
897 translate_builtin_int_64_min_max(
898 build, nparams, ra, arg, args, arg3, nresults, pcpos, false,
899 )
900 } else {
901 no_builtin()
902 }
903 }
904 x if x == LBF::LBF_INTEGER_NEG as i32 => {
905 if FFlag::LuauCodegenInteger2.get() {
906 translate_builtin_int_64_neg(build, nparams, ra, arg, nresults, pcpos)
907 } else {
908 no_builtin()
909 }
910 }
911 x if x == LBF::LBF_INTEGER_CLAMP as i32 => {
912 if FFlag::LuauCodegenInteger2.get() {
913 translate_builtin_int_64_clamp(build, nparams, ra, arg, args, arg3, nresults, pcpos)
914 } else {
915 no_builtin()
916 }
917 }
918 x if x == LBF::LBF_INTEGER_LT as i32 => int2_compare(
919 build,
920 nparams,
921 ra,
922 arg,
923 args,
924 nresults,
925 pcpos,
926 IrCondition::Less,
927 ),
928 x if x == LBF::LBF_INTEGER_LE as i32 => int2_compare(
929 build,
930 nparams,
931 ra,
932 arg,
933 args,
934 nresults,
935 pcpos,
936 IrCondition::LessEqual,
937 ),
938 x if x == LBF::LBF_INTEGER_GT as i32 => int2_compare(
939 build,
940 nparams,
941 ra,
942 arg,
943 args,
944 nresults,
945 pcpos,
946 IrCondition::Greater,
947 ),
948 x if x == LBF::LBF_INTEGER_GE as i32 => int2_compare(
949 build,
950 nparams,
951 ra,
952 arg,
953 args,
954 nresults,
955 pcpos,
956 IrCondition::GreaterEqual,
957 ),
958 x if x == LBF::LBF_INTEGER_ULT as i32 => int2_compare(
959 build,
960 nparams,
961 ra,
962 arg,
963 args,
964 nresults,
965 pcpos,
966 IrCondition::UnsignedLess,
967 ),
968 x if x == LBF::LBF_INTEGER_ULE as i32 => int2_compare(
969 build,
970 nparams,
971 ra,
972 arg,
973 args,
974 nresults,
975 pcpos,
976 IrCondition::UnsignedLessEqual,
977 ),
978 x if x == LBF::LBF_INTEGER_UGT as i32 => int2_compare(
979 build,
980 nparams,
981 ra,
982 arg,
983 args,
984 nresults,
985 pcpos,
986 IrCondition::UnsignedGreater,
987 ),
988 x if x == LBF::LBF_INTEGER_UGE as i32 => int2_compare(
989 build,
990 nparams,
991 ra,
992 arg,
993 args,
994 nresults,
995 pcpos,
996 IrCondition::UnsignedGreaterEqual,
997 ),
998 x if x == LBF::LBF_INTEGER_BAND as i32 => int2_multiarg(
999 build,
1000 IrCmd::BITAND_INT64,
1001 false,
1002 -1,
1003 nparams,
1004 ra,
1005 arg,
1006 args,
1007 arg3,
1008 nresults,
1009 pcpos,
1010 ),
1011 x if x == LBF::LBF_INTEGER_BOR as i32 => int2_multiarg(
1012 build,
1013 IrCmd::BITOR_INT64,
1014 false,
1015 0,
1016 nparams,
1017 ra,
1018 arg,
1019 args,
1020 arg3,
1021 nresults,
1022 pcpos,
1023 ),
1024 x if x == LBF::LBF_INTEGER_BXOR as i32 => int2_multiarg(
1025 build,
1026 IrCmd::BITXOR_INT64,
1027 false,
1028 0,
1029 nparams,
1030 ra,
1031 arg,
1032 args,
1033 arg3,
1034 nresults,
1035 pcpos,
1036 ),
1037 x if x == LBF::LBF_INTEGER_BNOT as i32 => {
1038 if FFlag::LuauCodegenInteger2.get() {
1039 translate_builtin_int_64_bnot(build, nparams, ra, arg, nresults, pcpos)
1040 } else {
1041 no_builtin()
1042 }
1043 }
1044 x if x == LBF::LBF_INTEGER_BTEST as i32 => int2_multiarg(
1045 build,
1046 IrCmd::BITAND_INT64,
1047 true,
1048 -1,
1049 nparams,
1050 ra,
1051 arg,
1052 args,
1053 arg3,
1054 nresults,
1055 pcpos,
1056 ),
1057 x if x == LBF::LBF_INTEGER_LSHIFT as i32 => int2_shift(
1058 build,
1059 IrCmd::BITLSHIFT_INT64,
1060 nparams,
1061 ra,
1062 arg,
1063 args,
1064 nresults,
1065 pcpos,
1066 ),
1067 x if x == LBF::LBF_INTEGER_RSHIFT as i32 => int2_shift(
1068 build,
1069 IrCmd::BITRSHIFT_INT64,
1070 nparams,
1071 ra,
1072 arg,
1073 args,
1074 nresults,
1075 pcpos,
1076 ),
1077 x if x == LBF::LBF_INTEGER_ARSHIFT as i32 => int2_shift(
1078 build,
1079 IrCmd::BITARSHIFT_INT64,
1080 nparams,
1081 ra,
1082 arg,
1083 args,
1084 nresults,
1085 pcpos,
1086 ),
1087 x if x == LBF::LBF_INTEGER_LROTATE as i32 => int2_rotate(
1088 build,
1089 IrCmd::BITLROTATE_INT64,
1090 nparams,
1091 ra,
1092 arg,
1093 args,
1094 nresults,
1095 pcpos,
1096 ),
1097 x if x == LBF::LBF_INTEGER_RROTATE as i32 => int2_rotate(
1098 build,
1099 IrCmd::BITRROTATE_INT64,
1100 nparams,
1101 ra,
1102 arg,
1103 args,
1104 nresults,
1105 pcpos,
1106 ),
1107 x if x == LBF::LBF_INTEGER_COUNTLZ as i32 => int2_unary(
1108 build,
1109 IrCmd::BITCOUNTLZ_INT64,
1110 nparams,
1111 ra,
1112 arg,
1113 nresults,
1114 pcpos,
1115 ),
1116 x if x == LBF::LBF_INTEGER_COUNTRZ as i32 => int2_unary(
1117 build,
1118 IrCmd::BITCOUNTRZ_INT64,
1119 nparams,
1120 ra,
1121 arg,
1122 nresults,
1123 pcpos,
1124 ),
1125 x if x == LBF::LBF_INTEGER_BSWAP as i32 => int2_unary(
1126 build,
1127 IrCmd::BYTESWAP_INT64,
1128 nparams,
1129 ra,
1130 arg,
1131 nresults,
1132 pcpos,
1133 ),
1134 x if x == LBF::LBF_INTEGER_EXTRACT as i32 => {
1135 if FFlag::LuauCodegenInteger2.get() {
1136 translate_builtin_int_64_extract(
1137 build, nparams, ra, arg, args, arg3, nresults, pcpos,
1138 )
1139 } else {
1140 no_builtin()
1141 }
1142 }
1143 _ => no_builtin(),
1144 }
1145}
1146
1147fn int2_binary(
1148 build: &mut IrBuilder,
1149 nparams: i32,
1150 ra: i32,
1151 arg: i32,
1152 args: IrOp,
1153 nresults: i32,
1154 pcpos: i32,
1155 op: Int64Binary,
1156) -> BuiltinImplResult {
1157 if FFlag::LuauCodegenInteger2.get() {
1158 translate_builtin_int_64_binary(build, nparams, ra, arg, args, nresults, pcpos, op)
1159 } else {
1160 no_builtin()
1161 }
1162}
1163
1164fn int2_compare(
1165 build: &mut IrBuilder,
1166 nparams: i32,
1167 ra: i32,
1168 arg: i32,
1169 args: IrOp,
1170 nresults: i32,
1171 pcpos: i32,
1172 cond: IrCondition,
1173) -> BuiltinImplResult {
1174 if FFlag::LuauCodegenInteger2.get() {
1175 translate_builtin_int_64_compare(build, nparams, ra, arg, args, nresults, pcpos, cond)
1176 } else {
1177 no_builtin()
1178 }
1179}
1180
1181fn int2_multiarg(
1182 build: &mut IrBuilder,
1183 cmd: IrCmd,
1184 btest: bool,
1185 identity: i64,
1186 nparams: i32,
1187 ra: i32,
1188 arg: i32,
1189 args: IrOp,
1190 arg3: IrOp,
1191 nresults: i32,
1192 pcpos: i32,
1193) -> BuiltinImplResult {
1194 if FFlag::LuauCodegenInteger2.get() {
1195 translate_builtin_int_64_multiarg_op(
1196 build, cmd, btest, identity, nparams, ra, arg, args, arg3, nresults, pcpos,
1197 )
1198 } else {
1199 no_builtin()
1200 }
1201}
1202
1203fn int2_shift(
1204 build: &mut IrBuilder,
1205 cmd: IrCmd,
1206 nparams: i32,
1207 ra: i32,
1208 arg: i32,
1209 args: IrOp,
1210 nresults: i32,
1211 pcpos: i32,
1212) -> BuiltinImplResult {
1213 if FFlag::LuauCodegenInteger2.get() {
1214 translate_builtin_int_64_shift(build, cmd, nparams, ra, arg, args, nresults, pcpos)
1215 } else {
1216 no_builtin()
1217 }
1218}
1219
1220fn int2_rotate(
1221 build: &mut IrBuilder,
1222 cmd: IrCmd,
1223 nparams: i32,
1224 ra: i32,
1225 arg: i32,
1226 args: IrOp,
1227 nresults: i32,
1228 pcpos: i32,
1229) -> BuiltinImplResult {
1230 if FFlag::LuauCodegenInteger2.get() {
1231 translate_builtin_int_64_rotate(build, cmd, nparams, ra, arg, args, nresults, pcpos)
1232 } else {
1233 no_builtin()
1234 }
1235}
1236
1237fn int2_unary(
1238 build: &mut IrBuilder,
1239 cmd: IrCmd,
1240 nparams: i32,
1241 ra: i32,
1242 arg: i32,
1243 nresults: i32,
1244 pcpos: i32,
1245) -> BuiltinImplResult {
1246 if FFlag::LuauCodegenInteger2.get() {
1247 translate_builtin_int_64_unary(build, cmd, nparams, ra, arg, nresults, pcpos)
1248 } else {
1249 no_builtin()
1250 }
1251}