GlobOptSimd128.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605
  1. //-------------------------------------------------------------------------------------------------------
  2. // Copyright (C) Microsoft. All rights reserved.
  3. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
  4. //-------------------------------------------------------------------------------------------------------
  5. // SIMD_JS
  6. // GlobOpt bits related to SIMD.js
  7. #include "Backend.h"
  8. #ifdef ENABLE_SIMDJS
  9. /*
  10. Handles all Simd128 type-spec of an instr, if possible.
  11. */
  12. bool
  13. GlobOpt::TypeSpecializeSimd128(
  14. IR::Instr *instr,
  15. Value **pSrc1Val,
  16. Value **pSrc2Val,
  17. Value **pDstVal
  18. )
  19. {
  20. if (func->GetJITFunctionBody()->IsAsmJsMode() || SIMD128_TYPE_SPEC_FLAG == false)
  21. {
  22. // no type-spec for ASMJS code or flag is off.
  23. return false;
  24. }
  25. switch (instr->m_opcode)
  26. {
  27. case Js::OpCode::ArgOut_A_InlineBuiltIn:
  28. if (instr->GetSrc1()->IsRegOpnd())
  29. {
  30. StackSym *sym = instr->GetSrc1()->AsRegOpnd()->m_sym;
  31. if (this->currentBlock->globOptData.IsSimd128TypeSpecialized(sym))
  32. {
  33. ValueType valueType = (*pSrc1Val)->GetValueInfo()->Type();
  34. Assert(valueType.IsSimd128());
  35. ToTypeSpecUse(instr, instr->GetSrc1(), this->currentBlock, *pSrc1Val, nullptr, GetIRTypeFromValueType(valueType), GetBailOutKindFromValueType(valueType));
  36. return true;
  37. }
  38. }
  39. return false;
  40. case Js::OpCode::Ld_A:
  41. if (instr->GetSrc1()->IsRegOpnd())
  42. {
  43. StackSym *sym = instr->GetSrc1()->AsRegOpnd()->m_sym;
  44. IRType type = TyIllegal;
  45. if (this->currentBlock->globOptData.IsSimd128F4TypeSpecialized(sym))
  46. {
  47. type = TySimd128F4;
  48. }
  49. else if (this->currentBlock->globOptData.IsSimd128I4TypeSpecialized(sym))
  50. {
  51. type = TySimd128I4;
  52. }
  53. else
  54. {
  55. return false;
  56. }
  57. ToTypeSpecUse(instr, instr->GetSrc1(), this->currentBlock, *pSrc1Val, nullptr, type, IR::BailOutSimd128F4Only /*not used for Ld_A*/);
  58. TypeSpecializeSimd128Dst(type, instr, *pSrc1Val, *pSrc1Val, pDstVal);
  59. return true;
  60. }
  61. return false;
  62. case Js::OpCode::ExtendArg_A:
  63. if (Simd128DoTypeSpec(instr, *pSrc1Val, *pSrc2Val, *pDstVal))
  64. {
  65. Assert(instr->m_opcode == Js::OpCode::ExtendArg_A);
  66. Assert(instr->GetDst()->GetType() == TyVar);
  67. ValueType valueType = instr->GetDst()->GetValueType();
  68. // Type-spec src1 only based on dst type. Dst type is set by the inliner based on func signature.
  69. ToTypeSpecUse(instr, instr->GetSrc1(), this->currentBlock, *pSrc1Val, nullptr, GetIRTypeFromValueType(valueType), GetBailOutKindFromValueType(valueType), true /*lossy*/);
  70. ToVarRegOpnd(instr->GetDst()->AsRegOpnd(), this->currentBlock);
  71. return true;
  72. }
  73. return false;
  74. }
  75. if (!Js::IsSimd128Opcode(instr->m_opcode))
  76. {
  77. return false;
  78. }
  79. // Simd instr
  80. if (Simd128DoTypeSpec(instr, *pSrc1Val, *pSrc2Val, *pDstVal))
  81. {
  82. ThreadContext::SimdFuncSignature simdFuncSignature;
  83. instr->m_func->GetScriptContext()->GetThreadContext()->GetSimdFuncSignatureFromOpcode(instr->m_opcode, simdFuncSignature);
  84. // type-spec logic
  85. // special handling for load/store
  86. // OptArraySrc will type-spec the array and the index. We type-spec the value here.
  87. if (Js::IsSimd128Load(instr->m_opcode))
  88. {
  89. TypeSpecializeSimd128Dst(GetIRTypeFromValueType(simdFuncSignature.returnType), instr, nullptr, *pSrc1Val, pDstVal);
  90. Simd128SetIndirOpndType(instr->GetSrc1()->AsIndirOpnd(), instr->m_opcode);
  91. return true;
  92. }
  93. if (Js::IsSimd128Store(instr->m_opcode))
  94. {
  95. ToTypeSpecUse(instr, instr->GetSrc1(), this->currentBlock, *pSrc1Val, nullptr, GetIRTypeFromValueType(simdFuncSignature.args[2]), GetBailOutKindFromValueType(simdFuncSignature.args[2]));
  96. Simd128SetIndirOpndType(instr->GetDst()->AsIndirOpnd(), instr->m_opcode);
  97. return true;
  98. }
  99. // For op with ExtendArg. All sources are already type-specialized, just type-specialize dst
  100. if (simdFuncSignature.argCount <= 2)
  101. {
  102. Assert(instr->GetSrc1());
  103. ToTypeSpecUse(instr, instr->GetSrc1(), this->currentBlock, *pSrc1Val, nullptr, GetIRTypeFromValueType(simdFuncSignature.args[0]), GetBailOutKindFromValueType(simdFuncSignature.args[0]));
  104. if (instr->GetSrc2())
  105. {
  106. ToTypeSpecUse(instr, instr->GetSrc2(), this->currentBlock, *pSrc2Val, nullptr, GetIRTypeFromValueType(simdFuncSignature.args[1]), GetBailOutKindFromValueType(simdFuncSignature.args[1]));
  107. }
  108. }
  109. if (instr->GetDst())
  110. {
  111. TypeSpecializeSimd128Dst(GetIRTypeFromValueType(simdFuncSignature.returnType), instr, nullptr, *pSrc1Val, pDstVal);
  112. }
  113. return true;
  114. }
  115. else
  116. {
  117. // We didn't type-spec
  118. if (!IsLoopPrePass())
  119. {
  120. // Emit bailout if not loop prepass.
  121. // The inliner inserts bytecodeUses of original args after the instruction. Bailout is safe.
  122. IR::Instr * bailoutInstr = IR::BailOutInstr::New(Js::OpCode::BailOnNoSimdTypeSpec, IR::BailOutNoSimdTypeSpec, instr, instr->m_func);
  123. bailoutInstr->SetByteCodeOffset(instr);
  124. instr->InsertAfter(bailoutInstr);
  125. instr->m_opcode = Js::OpCode::Nop;
  126. if (instr->GetSrc1())
  127. {
  128. instr->FreeSrc1();
  129. if (instr->GetSrc2())
  130. {
  131. instr->FreeSrc2();
  132. }
  133. }
  134. if (instr->GetDst())
  135. {
  136. instr->FreeDst();
  137. }
  138. if (this->byteCodeUses)
  139. {
  140. // All inlined SIMD ops have jitOptimizedReg srcs
  141. Assert(this->byteCodeUses->IsEmpty());
  142. JitAdelete(this->alloc, this->byteCodeUses);
  143. this->byteCodeUses = nullptr;
  144. }
  145. RemoveCodeAfterNoFallthroughInstr(bailoutInstr);
  146. return true;
  147. }
  148. }
  149. return false;
  150. }
  151. bool
  152. GlobOpt::Simd128DoTypeSpec(IR::Instr *instr, const Value *src1Val, const Value *src2Val, const Value *dstVal)
  153. {
  154. bool doTypeSpec = true;
  155. // TODO: Some operations require additional opnd constraints (e.g. shuffle/swizzle).
  156. if (Js::IsSimd128Opcode(instr->m_opcode))
  157. {
  158. ThreadContext::SimdFuncSignature simdFuncSignature;
  159. instr->m_func->GetScriptContext()->GetThreadContext()->GetSimdFuncSignatureFromOpcode(instr->m_opcode, simdFuncSignature);
  160. if (!simdFuncSignature.valid)
  161. {
  162. // not implemented yet.
  163. return false;
  164. }
  165. // special handling for Load/Store
  166. if (Js::IsSimd128Load(instr->m_opcode) || Js::IsSimd128Store(instr->m_opcode))
  167. {
  168. return Simd128DoTypeSpecLoadStore(instr, src1Val, src2Val, dstVal, &simdFuncSignature);
  169. }
  170. const uint argCount = simdFuncSignature.argCount;
  171. switch (argCount)
  172. {
  173. case 2:
  174. Assert(src2Val);
  175. doTypeSpec = doTypeSpec && Simd128CanTypeSpecOpnd(src2Val->GetValueInfo()->Type(), simdFuncSignature.args[1]) && Simd128ValidateIfLaneIndex(instr, instr->GetSrc2(), 1);
  176. // fall-through
  177. case 1:
  178. Assert(src1Val);
  179. doTypeSpec = doTypeSpec && Simd128CanTypeSpecOpnd(src1Val->GetValueInfo()->Type(), simdFuncSignature.args[0]) && Simd128ValidateIfLaneIndex(instr, instr->GetSrc1(), 0);
  180. break;
  181. default:
  182. {
  183. // extended args
  184. Assert(argCount > 2);
  185. // Check if all args have been type specialized.
  186. int arg = argCount - 1;
  187. IR::Instr * eaInstr = GetExtendedArg(instr);
  188. while (arg>=0)
  189. {
  190. Assert(eaInstr);
  191. Assert(eaInstr->m_opcode == Js::OpCode::ExtendArg_A);
  192. ValueType expectedType = simdFuncSignature.args[arg];
  193. IR::Opnd * opnd = eaInstr->GetSrc1();
  194. StackSym * sym = opnd->GetStackSym();
  195. // In Forward Prepass: Check liveness through liveness bits, not IR type, since in prepass no actual type-spec happens.
  196. // In the Forward Pass: Check IRType since Sym can be null, because of const prop.
  197. if (expectedType.IsSimd128Float32x4())
  198. {
  199. if (sym && !this->currentBlock->globOptData.IsSimd128F4TypeSpecialized(sym) ||
  200. !sym && opnd->GetType() != TySimd128F4)
  201. {
  202. return false;
  203. }
  204. }
  205. else if (expectedType.IsSimd128Int32x4())
  206. {
  207. if (sym && !this->currentBlock->globOptData.IsSimd128I4TypeSpecialized(sym) ||
  208. !sym && opnd->GetType() != TySimd128I4)
  209. {
  210. return false;
  211. }
  212. }
  213. else if (expectedType.IsFloat())
  214. {
  215. if (sym && !this->currentBlock->globOptData.IsFloat64TypeSpecialized(sym) ||
  216. !sym&& opnd->GetType() != TyFloat64)
  217. {
  218. return false;
  219. }
  220. }
  221. else if (expectedType.IsInt())
  222. {
  223. if ((sym && !this->currentBlock->globOptData.IsInt32TypeSpecialized(sym) && !currentBlock->globOptData.liveLossyInt32Syms->Test(sym->m_id)) ||
  224. !sym && opnd->GetType() != TyInt32)
  225. {
  226. return false;
  227. }
  228. // Extra check if arg is a lane index
  229. if (!Simd128ValidateIfLaneIndex(instr, opnd, arg))
  230. {
  231. return false;
  232. }
  233. }
  234. else
  235. {
  236. Assert(UNREACHED);
  237. }
  238. eaInstr = GetExtendedArg(eaInstr);
  239. arg--;
  240. }
  241. // all args are type-spec'd
  242. doTypeSpec = true;
  243. }
  244. }
  245. }
  246. else
  247. {
  248. Assert(instr->m_opcode == Js::OpCode::ExtendArg_A);
  249. // For ExtendArg, the expected type is encoded in the dst(link) operand.
  250. doTypeSpec = doTypeSpec && Simd128CanTypeSpecOpnd(src1Val->GetValueInfo()->Type(), instr->GetDst()->GetValueType());
  251. }
  252. return doTypeSpec;
  253. }
  254. bool
  255. GlobOpt::Simd128DoTypeSpecLoadStore(IR::Instr *instr, const Value *src1Val, const Value *src2Val, const Value *dstVal, const ThreadContext::SimdFuncSignature *simdFuncSignature)
  256. {
  257. IR::Opnd *baseOpnd = nullptr, *indexOpnd = nullptr, *valueOpnd = nullptr;
  258. IR::Opnd *src, *dst;
  259. bool doTypeSpec = true;
  260. // value = Ld [arr + index]
  261. // [arr + index] = St value
  262. src = instr->GetSrc1();
  263. dst = instr->GetDst();
  264. Assert(dst && src && !instr->GetSrc2());
  265. if (Js::IsSimd128Load(instr->m_opcode))
  266. {
  267. Assert(src->IsIndirOpnd());
  268. baseOpnd = instr->GetSrc1()->AsIndirOpnd()->GetBaseOpnd();
  269. indexOpnd = instr->GetSrc1()->AsIndirOpnd()->GetIndexOpnd();
  270. valueOpnd = instr->GetDst();
  271. }
  272. else if (Js::IsSimd128Store(instr->m_opcode))
  273. {
  274. Assert(dst->IsIndirOpnd());
  275. baseOpnd = instr->GetDst()->AsIndirOpnd()->GetBaseOpnd();
  276. indexOpnd = instr->GetDst()->AsIndirOpnd()->GetIndexOpnd();
  277. valueOpnd = instr->GetSrc1();
  278. // St(arr, index, value). Make sure value can be Simd128 type-spec'd
  279. doTypeSpec = doTypeSpec && Simd128CanTypeSpecOpnd(this->currentBlock->globOptData.FindValue(valueOpnd->AsRegOpnd()->m_sym)->GetValueInfo()->Type(), simdFuncSignature->args[2]);
  280. }
  281. else
  282. {
  283. Assert(UNREACHED);
  284. }
  285. // array and index operands should have been type-specialized in OptArraySrc: ValueTypes should be definite at this point. If not, don't type-spec.
  286. // We can be in a loop prepass, where opnd ValueInfo is not set yet. Get the ValueInfo from the Value Table instead.
  287. ValueType baseOpndType = this->currentBlock->globOptData.FindValue(baseOpnd->AsRegOpnd()->m_sym)->GetValueInfo()->Type();
  288. if (IsLoopPrePass())
  289. {
  290. doTypeSpec = doTypeSpec && (baseOpndType.IsObject() && baseOpndType.IsTypedArray());
  291. // indexOpnd might be missing if loading from [0]
  292. if (indexOpnd != nullptr)
  293. {
  294. ValueType indexOpndType = this->currentBlock->globOptData.FindValue(indexOpnd->AsRegOpnd()->m_sym)->GetValueInfo()->Type();
  295. doTypeSpec = doTypeSpec && indexOpndType.IsLikelyInt();
  296. }
  297. }
  298. else
  299. {
  300. doTypeSpec = doTypeSpec && (baseOpndType.IsObject() && baseOpndType.IsTypedArray());
  301. if (indexOpnd != nullptr)
  302. {
  303. ValueType indexOpndType = this->currentBlock->globOptData.FindValue(indexOpnd->AsRegOpnd()->m_sym)->GetValueInfo()->Type();
  304. doTypeSpec = doTypeSpec && indexOpndType.IsInt();
  305. }
  306. }
  307. return doTypeSpec;
  308. }
  309. // We can type spec an opnd if:
  310. // Both profiled/propagated and expected types are not Simd128. e.g. expected type is f64/f32/i32 where there is a conversion logic from the incoming type.
  311. // Opnd type is (Likely) SIMD128 and matches expected type.
  312. // Opnd type is Object. e.g. possibly result of merging different SIMD types. We specialize because we don't know which pass is dynamically taken.
  313. bool GlobOpt::Simd128CanTypeSpecOpnd(const ValueType opndType, ValueType expectedType)
  314. {
  315. if (!opndType.IsSimd128() && !expectedType.IsSimd128())
  316. {
  317. // Non-Simd types can be coerced or we bailout by a FromVar.
  318. return true;
  319. }
  320. // Simd type
  321. if (opndType.HasBeenNull() || opndType.HasBeenUndefined())
  322. {
  323. return false;
  324. }
  325. if (
  326. (opndType.IsLikelyObject() && opndType.ToDefiniteObject() == expectedType) ||
  327. (opndType.IsLikelyObject() && opndType.GetObjectType() == ObjectType::Object)
  328. )
  329. {
  330. return true;
  331. }
  332. return false;
  333. }
  334. /*
  335. Given an instr, opnd and the opnd position. Return true if opnd is a lane index and valid, or not a lane index all-together..
  336. */
  337. bool GlobOpt::Simd128ValidateIfLaneIndex(const IR::Instr * instr, IR::Opnd * opnd, uint argPos)
  338. {
  339. Assert(instr);
  340. Assert(opnd);
  341. uint laneIndex;
  342. uint argPosLo, argPosHi;
  343. uint laneIndexLo, laneIndexHi;
  344. // operation takes a lane index ?
  345. switch (instr->m_opcode)
  346. {
  347. case Js::OpCode::Simd128_Swizzle_F4:
  348. case Js::OpCode::Simd128_Swizzle_I4:
  349. argPosLo = 1; argPosHi = 4;
  350. laneIndexLo = 0; laneIndexHi = 3;
  351. break;
  352. case Js::OpCode::Simd128_Shuffle_F4:
  353. case Js::OpCode::Simd128_Shuffle_I4:
  354. argPosLo = 2; argPosHi = 5;
  355. laneIndexLo = 0; laneIndexHi = 7;
  356. break;
  357. case Js::OpCode::Simd128_ReplaceLane_F4:
  358. case Js::OpCode::Simd128_ReplaceLane_I4:
  359. case Js::OpCode::Simd128_ExtractLane_F4:
  360. case Js::OpCode::Simd128_ExtractLane_I4:
  361. argPosLo = argPosHi = 1;
  362. laneIndexLo = 0; laneIndexHi = 3;
  363. break;
  364. default:
  365. return true; // not a lane index
  366. }
  367. // arg in lane index pos of operation ?
  368. if (argPos < argPosLo || argPos > argPosHi)
  369. {
  370. return true; // not a lane index
  371. }
  372. // It is a lane index ...
  373. // Arg is Int constant (literal or const prop'd) ?
  374. if (!opnd->IsIntConstOpnd())
  375. {
  376. return false;
  377. }
  378. laneIndex = (uint) opnd->AsIntConstOpnd()->GetValue();
  379. // In range ?
  380. if (laneIndex < laneIndexLo|| laneIndex > laneIndexHi)
  381. {
  382. return false;
  383. }
  384. return true;
  385. }
  386. IR::Instr * GlobOpt::GetExtendedArg(IR::Instr *instr)
  387. {
  388. IR::Opnd *src1, *src2;
  389. src1 = instr->GetSrc1();
  390. src2 = instr->GetSrc2();
  391. if (instr->m_opcode == Js::OpCode::ExtendArg_A)
  392. {
  393. if (src2)
  394. {
  395. // mid chain
  396. Assert(src2->GetStackSym()->IsSingleDef());
  397. return src2->GetStackSym()->GetInstrDef();
  398. }
  399. else
  400. {
  401. // end of chain
  402. return nullptr;
  403. }
  404. }
  405. else
  406. {
  407. // start of chain
  408. Assert(Js::IsSimd128Opcode(instr->m_opcode));
  409. Assert(src1);
  410. Assert(src1->GetStackSym()->IsSingleDef());
  411. return src1->GetStackSym()->GetInstrDef();
  412. }
  413. }
  414. #endif
  415. IRType GlobOpt::GetIRTypeFromValueType(const ValueType &valueType)
  416. {
  417. if (valueType.IsFloat())
  418. {
  419. return TyFloat64;
  420. }
  421. else if (valueType.IsInt())
  422. {
  423. return TyInt32;
  424. }
  425. else if (valueType.IsSimd128Float32x4())
  426. {
  427. return TySimd128F4;
  428. }
  429. else
  430. {
  431. Assert(valueType.IsSimd128Int32x4());
  432. return TySimd128I4;
  433. }
  434. }
  435. ValueType GlobOpt::GetValueTypeFromIRType(const IRType &type)
  436. {
  437. switch (type)
  438. {
  439. case TyInt32:
  440. return ValueType::GetInt(false);
  441. case TyFloat64:
  442. return ValueType::Float;
  443. case TySimd128F4:
  444. return ValueType::GetSimd128(ObjectType::Simd128Float32x4);
  445. case TySimd128I4:
  446. return ValueType::GetSimd128(ObjectType::Simd128Int32x4);
  447. default:
  448. Assert(UNREACHED);
  449. }
  450. return ValueType::UninitializedObject;
  451. }
  452. IR::BailOutKind GlobOpt::GetBailOutKindFromValueType(const ValueType &valueType)
  453. {
  454. if (valueType.IsFloat())
  455. {
  456. // if required valueType is Float, then allow coercion from any primitive except String.
  457. return IR::BailOutPrimitiveButString;
  458. }
  459. else if (valueType.IsInt())
  460. {
  461. return IR::BailOutIntOnly;
  462. }
  463. #ifdef ENABLE_SIMDJS
  464. else if (valueType.IsSimd128Float32x4())
  465. {
  466. return IR::BailOutSimd128F4Only;
  467. }
  468. else
  469. {
  470. Assert(valueType.IsSimd128Int32x4());
  471. return IR::BailOutSimd128I4Only;
  472. }
  473. #endif
  474. else
  475. {
  476. AssertOrFailFast(UNREACHED);
  477. return IR::BailOutInvalid;
  478. }
  479. }
  480. #ifdef ENABLE_SIMDJS
  481. void
  482. GlobOpt::UpdateBoundCheckHoistInfoForSimd(ArrayUpperBoundCheckHoistInfo &upperHoistInfo, ValueType arrValueType, const IR::Instr *instr)
  483. {
  484. if (!upperHoistInfo.HasAnyInfo())
  485. {
  486. return;
  487. }
  488. int newOffset = GetBoundCheckOffsetForSimd(arrValueType, instr, upperHoistInfo.Offset());
  489. upperHoistInfo.UpdateOffset(newOffset);
  490. }
  491. #endif
  492. int
  493. GlobOpt::GetBoundCheckOffsetForSimd(ValueType arrValueType, const IR::Instr *instr, const int oldOffset /* = -1 */)
  494. {
  495. #ifdef ENABLE_SIMDJS
  496. if (!(Js::IsSimd128LoadStore(instr->m_opcode)))
  497. {
  498. return oldOffset;
  499. }
  500. if (!arrValueType.IsTypedArray())
  501. {
  502. // no need to adjust for other array types, we will not type-spec (see Simd128DoTypeSpecLoadStore)
  503. return oldOffset;
  504. }
  505. Assert(instr->dataWidth == 4 || instr->dataWidth == 8 || instr->dataWidth == 12 || instr->dataWidth == 16);
  506. int numOfElems = Lowerer::SimdGetElementCountFromBytes(arrValueType, instr->dataWidth);
  507. // we want to make bound checks more conservative. We compute how many extra elements we need to add to the bound check
  508. // e.g. if original bound check is value <= Length + offset, and dataWidth is 16 bytes on Float32 array, then we need room for 4 elements. The bound check guarantees room for 1 element.
  509. // Hence, we need to ensure 3 more: value <= Length + offset - 3
  510. // We round up since dataWidth may span a partial lane (e.g. dataWidth = 12, bpe = 8 bytes)
  511. int offsetBias = -(numOfElems - 1);
  512. // we should always make an existing bound-check more conservative.
  513. Assert(offsetBias <= 0);
  514. return oldOffset + offsetBias;
  515. #else
  516. return oldOffset;
  517. #endif
  518. }
  519. #ifdef ENABLE_SIMDJS
  520. void
  521. GlobOpt::Simd128SetIndirOpndType(IR::IndirOpnd *indirOpnd, Js::OpCode opcode)
  522. {
  523. switch (opcode)
  524. {
  525. case Js::OpCode::Simd128_LdArr_F4:
  526. case Js::OpCode::Simd128_StArr_F4:
  527. indirOpnd->SetType(TySimd128F4);
  528. indirOpnd->SetValueType(ValueType::GetSimd128(ObjectType::Simd128Float32x4));
  529. break;
  530. case Js::OpCode::Simd128_LdArr_I4:
  531. case Js::OpCode::Simd128_StArr_I4:
  532. indirOpnd->SetType(TySimd128I4);
  533. indirOpnd->SetValueType(ValueType::GetSimd128(ObjectType::Simd128Int32x4));
  534. break;
  535. default:
  536. Assert(UNREACHED);
  537. }
  538. }
  539. #endif