1use crate::ArmEncoder;
7use synth_core::backend::{
8 Backend, BackendCapabilities, BackendError, CodeRelocation, CompilationResult, CompileConfig,
9 CompiledFunction, SafetyBounds,
10};
11use synth_core::target::{IsaVariant, TargetSpec};
12use synth_core::wasm_decoder::DecodedModule;
13use synth_core::wasm_op::WasmOp;
14use synth_synthesis::{
15 ArmInstruction, ArmOp, BoundsCheckConfig, InstructionSelector, OptimizationConfig,
16 OptimizerBridge, RuleDatabase, validate_instructions,
17};
18
19pub struct ArmBackend;
21
22impl ArmBackend {
23 pub fn new() -> Self {
24 Self
25 }
26}
27
28impl Default for ArmBackend {
29 fn default() -> Self {
30 Self::new()
31 }
32}
33
34impl Backend for ArmBackend {
35 fn name(&self) -> &str {
36 "arm"
37 }
38
39 fn capabilities(&self) -> BackendCapabilities {
40 BackendCapabilities {
41 produces_elf: false,
42 supports_rule_verification: true,
43 supports_binary_verification: true,
44 is_external: false,
45 }
46 }
47
48 fn supported_targets(&self) -> Vec<TargetSpec> {
49 vec![
50 TargetSpec::cortex_m3(),
51 TargetSpec::cortex_m4(),
52 TargetSpec::cortex_m4f(),
53 TargetSpec::cortex_m7(),
54 TargetSpec::cortex_m7dp(),
55 ]
56 }
57
58 fn compile_module(
59 &self,
60 module: &DecodedModule,
61 config: &CompileConfig,
62 ) -> Result<CompilationResult, BackendError> {
63 let exports: Vec<_> = module
64 .functions
65 .iter()
66 .filter(|f| f.export_name.is_some())
67 .collect();
68
69 if exports.is_empty() {
70 return Err(BackendError::CompilationFailed(
71 "no exported functions found".into(),
72 ));
73 }
74
75 let mut functions = Vec::new();
76 for func in &exports {
77 let name = func.export_name.clone().unwrap();
78 let compiled = self.compile_function(&name, &func.ops, config)?;
79 functions.push(compiled);
80 }
81
82 Ok(CompilationResult {
83 functions,
84 elf: None,
85 backend_name: self.name().to_string(),
86 })
87 }
88
89 fn compile_function(
90 &self,
91 name: &str,
92 ops: &[WasmOp],
93 config: &CompileConfig,
94 ) -> Result<CompiledFunction, BackendError> {
95 let (code, relocations) =
96 compile_wasm_to_arm(ops, config).map_err(BackendError::CompilationFailed)?;
97
98 Ok(CompiledFunction {
99 name: name.to_string(),
100 code,
101 wasm_ops: ops.to_vec(),
102 relocations,
103 })
104 }
105
106 fn is_available(&self) -> bool {
107 true }
109}
110
111fn count_params(wasm_ops: &[WasmOp]) -> u32 {
113 let mut first_access: std::collections::HashMap<u32, bool> = std::collections::HashMap::new();
114 for op in wasm_ops {
115 match op {
116 WasmOp::LocalGet(idx) => {
117 first_access.entry(*idx).or_insert(true);
118 }
119 WasmOp::LocalSet(idx) | WasmOp::LocalTee(idx) => {
120 first_access.entry(*idx).or_insert(false);
121 }
122 _ => {}
123 }
124 }
125
126 first_access
127 .iter()
128 .filter_map(
129 |(&idx, &is_read_first)| {
130 if is_read_first { Some(idx + 1) } else { None }
131 },
132 )
133 .max()
134 .unwrap_or(0)
135}
136
137fn compile_wasm_to_arm(
142 wasm_ops: &[WasmOp],
143 config: &CompileConfig,
144) -> Result<(Vec<u8>, Vec<CodeRelocation>), String> {
145 let num_params = count_params(wasm_ops);
146
147 let bounds_config = match config.effective_safety_bounds() {
148 SafetyBounds::None => BoundsCheckConfig::None,
149 SafetyBounds::Mpu => BoundsCheckConfig::Mpu,
150 SafetyBounds::Software => BoundsCheckConfig::Software,
151 SafetyBounds::Mask => BoundsCheckConfig::Masking,
152 };
153
154 let select_direct = || -> Result<Vec<ArmInstruction>, String> {
158 let db = RuleDatabase::with_standard_rules();
159 let mut selector =
160 InstructionSelector::with_bounds_check(db.rules().to_vec(), bounds_config);
161 selector.set_target(config.target.fpu, &config.target.triple);
162 if config.num_imports > 0 {
163 selector.set_num_imports(config.num_imports);
164 }
165 selector.set_func_arg_counts(
168 config.func_arg_counts.clone(),
169 config.type_arg_counts.clone(),
170 );
171 selector.set_relocatable(config.relocatable);
175 selector.set_native_pointer_abi(config.native_pointer_abi, config.linear_memory_bytes);
177 if config.native_pointer_abi
181 && let Some((sp_idx, sp_init)) = config.stack_pointer_global
182 {
183 selector.set_native_pointer_stack(sp_idx, sp_init);
184 }
185 selector
186 .select_with_stack(wasm_ops, num_params)
187 .map_err(|e| format!("instruction selection failed: {}", e))
188 };
189
190 let arm_instrs = if config.no_optimize || config.relocatable {
199 select_direct()?
200 } else {
201 let opt_config = if config.loom_compat {
202 OptimizationConfig::loom_compat()
203 } else {
204 OptimizationConfig::all()
205 };
206
207 let mut bridge = OptimizerBridge::with_config(opt_config);
208 bridge.set_num_imports(config.num_imports);
212 match bridge
217 .optimize_full(wasm_ops)
218 .and_then(|(opt_ir, _cfg, _stats)| bridge.ir_to_arm(&opt_ir, num_params as usize))
219 {
220 Ok(arm_ops) => arm_ops
221 .into_iter()
222 .map(|op| ArmInstruction {
223 op,
224 source_line: None,
225 })
226 .collect(),
227 Err(_) => select_direct()?,
233 }
234 };
235
236 let arm_instrs = if std::env::var("SYNTH_CONST_CSE").is_ok() {
261 synth_synthesis::liveness::apply_const_cse(&arm_instrs).0
262 } else {
263 arm_instrs
264 };
265
266 if std::env::var("SYNTH_SHADOW_ALLOC").is_ok() {
274 use synth_synthesis::liveness::{
275 AllocationOutcome, allocate_function, function_peak_pressure,
276 };
277 let precolored = std::collections::BTreeMap::from([
280 (synth_synthesis::rules::Reg::R9, 9usize),
281 (synth_synthesis::rules::Reg::R10, 10),
282 (synth_synthesis::rules::Reg::R11, 11),
283 (synth_synthesis::rules::Reg::R12, 12),
284 ]);
285 let peak = function_peak_pressure(&arm_instrs);
289 match allocate_function(&arm_instrs, 9, &precolored) {
290 AllocationOutcome::Allocated {
291 remat_opportunities,
292 coloring,
293 } => eprintln!(
294 "[shadow-alloc] OK: {} pregs coloured within R0-R8 pool, peak value-pressure {}, {} const-CSE/remat opportunities",
295 coloring.len(),
296 peak,
297 remat_opportunities
298 ),
299 AllocationOutcome::NeedsSpill(s) => eprintln!(
300 "[shadow-alloc] physical-graph would spill {:?}, but peak value-pressure is {} (≤9 ⇒ spurious; fits once virtually allocated)",
301 s, peak
302 ),
303 AllocationOutcome::Declined => {
304 eprintln!(
305 "[shadow-alloc] declined (unmodeled construct — calls/i64/fp/offset-branch)"
306 )
307 }
308 }
309 }
310
311 validate_instructions(&arm_instrs, config.target.fpu, &config.target.triple)
315 .map_err(|e| format!("ISA validation failed: {}", e))?;
316
317 let use_thumb2 = matches!(config.target.isa, IsaVariant::Thumb2 | IsaVariant::Thumb);
319
320 let encoder = if use_thumb2 {
321 ArmEncoder::new_thumb2_with_fpu(config.target.fpu)
322 } else {
323 ArmEncoder::new_arm32()
324 };
325
326 let arm_instrs = if use_thumb2 {
333 resolve_label_branches(arm_instrs, &encoder)?
334 } else {
335 arm_instrs
336 };
337
338 let mut code = Vec::new();
339 let mut relocations = Vec::new();
340
341 for instr in &arm_instrs {
342 if let ArmOp::Bl { label } = &instr.op {
349 relocations.push(CodeRelocation {
350 offset: code.len() as u32,
351 symbol: label.clone(),
352 kind: synth_core::backend::RelocKind::ThmCall,
353 });
354 }
355 if let ArmOp::MovwSym { symbol, .. } = &instr.op {
359 relocations.push(CodeRelocation {
360 offset: code.len() as u32,
361 symbol: symbol.clone(),
362 kind: synth_core::backend::RelocKind::MovwAbs,
363 });
364 }
365 if let ArmOp::MovtSym { symbol, .. } = &instr.op {
366 relocations.push(CodeRelocation {
367 offset: code.len() as u32,
368 symbol: symbol.clone(),
369 kind: synth_core::backend::RelocKind::MovtAbs,
370 });
371 }
372
373 let encoded = encoder
374 .encode(&instr.op)
375 .map_err(|e| format!("ARM encoding failed: {}", e))?;
376 code.extend_from_slice(&encoded);
377 }
378
379 Ok((code, relocations))
380}
381
382fn resolve_label_branches(
400 arm_instrs: Vec<ArmInstruction>,
401 encoder: &ArmEncoder,
402) -> Result<Vec<ArmInstruction>, String> {
403 use std::collections::HashMap;
404 use synth_synthesis::Condition;
405
406 enum BKind {
407 Cond(Condition),
408 Uncond,
409 }
410 let mut branches: Vec<(usize, BKind, String)> = Vec::new();
412 for (i, instr) in arm_instrs.iter().enumerate() {
413 match &instr.op {
414 ArmOp::Bcc { cond, label } => branches.push((i, BKind::Cond(*cond), label.clone())),
415 ArmOp::Bhs { label } => branches.push((i, BKind::Cond(Condition::HS), label.clone())),
416 ArmOp::Blo { label } => branches.push((i, BKind::Cond(Condition::LO), label.clone())),
417 ArmOp::B { label } => branches.push((i, BKind::Uncond, label.clone())),
418 _ => {}
419 }
420 }
421 if branches.is_empty() {
422 return Ok(arm_instrs);
423 }
424
425 let mut resolved = arm_instrs;
426 for _ in 0..16 {
428 let mut positions = Vec::with_capacity(resolved.len());
430 let mut pos: i64 = 0;
431 for instr in &resolved {
432 positions.push(pos);
433 pos += encoder
434 .encode(&instr.op)
435 .map_err(|e| format!("branch-resolve size probe failed: {}", e))?
436 .len() as i64;
437 }
438 let mut labels: HashMap<String, i64> = HashMap::new();
440 for (i, instr) in resolved.iter().enumerate() {
441 if let ArmOp::Label { name } = &instr.op {
442 labels.insert(name.clone(), positions[i]);
443 }
444 }
445 let mut changed = false;
447 for (idx, kind, label) in &branches {
448 let Some(&target) = labels.get(label) else {
453 continue;
454 };
455 let halfword_offset = ((target - positions[*idx] - 4) / 2) as i32;
458 let new_op = match kind {
459 BKind::Cond(c) => ArmOp::BCondOffset {
460 cond: *c,
461 offset: halfword_offset,
462 },
463 BKind::Uncond => ArmOp::BOffset {
464 offset: halfword_offset,
465 },
466 };
467 if resolved[*idx].op != new_op {
468 resolved[*idx].op = new_op;
469 changed = true;
470 }
471 }
472 if !changed {
473 break;
474 }
475 }
476 Ok(resolved)
477}
478
479#[cfg(test)]
480mod tests {
481 use super::*;
482
483 #[test]
484 fn test_arm_backend_name() {
485 let backend = ArmBackend::new();
486 assert_eq!(backend.name(), "arm");
487 assert!(backend.is_available());
488 }
489
490 #[test]
491 fn test_arm_backend_capabilities() {
492 let backend = ArmBackend::new();
493 let caps = backend.capabilities();
494 assert!(!caps.produces_elf);
495 assert!(caps.supports_rule_verification);
496 assert!(!caps.is_external);
497 }
498
499 #[test]
500 fn test_compile_add_function() {
501 let backend = ArmBackend::new();
502 let ops = vec![WasmOp::LocalGet(0), WasmOp::LocalGet(1), WasmOp::I32Add];
503 let config = CompileConfig::default();
504
505 let result = backend.compile_function("add", &ops, &config);
506 assert!(result.is_ok());
507
508 let func = result.unwrap();
509 assert_eq!(func.name, "add");
510 assert!(!func.code.is_empty());
511 assert_eq!(func.wasm_ops, ops);
512 }
513
514 #[test]
515 fn test_count_params() {
516 let ops = vec![WasmOp::LocalGet(0), WasmOp::LocalGet(1), WasmOp::I32Add];
517 assert_eq!(count_params(&ops), 2);
518
519 let no_params = vec![WasmOp::I32Const(5), WasmOp::I32Const(3), WasmOp::I32Add];
520 assert_eq!(count_params(&no_params), 0);
521 }
522
523 #[test]
524 fn test_arm_backend_register() {
525 let mut registry = synth_core::BackendRegistry::new();
526 registry.register(Box::new(ArmBackend::new()));
527 assert!(registry.get("arm").is_some());
528 assert_eq!(registry.available().len(), 1);
529 }
530
531 #[test]
532 fn test_compile_import_call_produces_relocations() {
533 let backend = ArmBackend::new();
534 let ops = vec![WasmOp::Call(0)];
537 let config = CompileConfig {
538 num_imports: 1,
539 no_optimize: true, ..CompileConfig::default()
541 };
542
543 let result = backend.compile_function("caller", &ops, &config);
544 assert!(result.is_ok());
545
546 let func = result.unwrap();
547 assert!(!func.code.is_empty());
548 assert_eq!(func.relocations.len(), 1);
549 assert_eq!(func.relocations[0].symbol, "__meld_dispatch_import");
550 assert!(func.relocations[0].offset > 0);
552 }
553
554 #[test]
560 fn test_compile_relocatable_import_uses_direct_func_symbol_197() {
561 let backend = ArmBackend::new();
562 let ops = vec![WasmOp::Call(0)]; let config = CompileConfig {
564 num_imports: 1,
565 relocatable: true,
566 ..CompileConfig::default()
567 };
568
569 let func = backend
570 .compile_function("caller", &ops, &config)
571 .expect("relocatable import call compiles");
572
573 assert_eq!(func.relocations.len(), 1);
574 assert_eq!(
575 func.relocations[0].symbol, "func_0",
576 "#197: relocatable import must relocate against func_0 (→ field name), not Meld dispatch"
577 );
578 }
579
580 #[test]
581 fn test_compile_no_imports_no_relocations() {
582 let backend = ArmBackend::new();
583 let ops = vec![WasmOp::LocalGet(0), WasmOp::LocalGet(1), WasmOp::I32Add];
584 let config = CompileConfig::default();
585
586 let func = backend.compile_function("add", &ops, &config).unwrap();
587 assert!(func.relocations.is_empty());
588 }
589
590 #[test]
597 fn test_compile_internal_call_produces_relocation_167() {
598 let backend = ArmBackend::new();
599 let ops = vec![WasmOp::Call(2)];
601 let config = CompileConfig {
602 num_imports: 1,
603 no_optimize: true,
604 ..CompileConfig::default()
605 };
606
607 let func = backend
608 .compile_function("caller", &ops, &config)
609 .expect("internal call compiles");
610
611 assert_eq!(
612 func.relocations.len(),
613 1,
614 "an internal call must emit exactly one relocation (#167)"
615 );
616 assert_eq!(
617 func.relocations[0].symbol, "func_2",
618 "internal call must relocate against the callee's func_{{index}} symbol (#167)"
619 );
620 }
621
622 #[test]
625 fn arm_safety_bounds_mpu_emits_same_code_as_none() {
626 let backend = ArmBackend::new();
630 let ops = vec![
631 WasmOp::LocalGet(0),
632 WasmOp::I32Load {
633 offset: 0,
634 align: 2,
635 },
636 ];
637 let cfg_none = CompileConfig {
638 no_optimize: true,
639 ..Default::default()
640 };
641 let cfg_mpu = CompileConfig {
642 no_optimize: true,
643 safety_bounds: SafetyBounds::Mpu,
644 ..Default::default()
645 };
646 let n = backend.compile_function("ld", &ops, &cfg_none).unwrap();
647 let m = backend.compile_function("ld", &ops, &cfg_mpu).unwrap();
648 assert_eq!(
649 n.code, m.code,
650 "Mpu and None should produce identical ARM bytes (Mpu relies on hardware)"
651 );
652 }
653
654 #[test]
655 fn arm_legacy_bounds_check_still_emits_software_check() {
656 let backend = ArmBackend::new();
659 let ops = vec![
660 WasmOp::LocalGet(0),
661 WasmOp::I32Load {
662 offset: 0,
663 align: 2,
664 },
665 ];
666 let cfg_legacy = CompileConfig {
667 no_optimize: true,
668 bounds_check: true,
669 ..Default::default()
670 };
671 let cfg_software = CompileConfig {
672 no_optimize: true,
673 safety_bounds: SafetyBounds::Software,
674 ..Default::default()
675 };
676 let l = backend.compile_function("ld", &ops, &cfg_legacy).unwrap();
677 let s = backend.compile_function("ld", &ops, &cfg_software).unwrap();
678 assert_eq!(
679 l.code, s.code,
680 "--bounds-check should produce the same bytes as --safety-bounds=software"
681 );
682 }
683
684 #[test]
690 fn test_f32_rejected_on_cortex_m3_no_fpu() {
691 let backend = ArmBackend::new();
692 let ops = vec![WasmOp::F32Const(1.0), WasmOp::F32Const(2.0), WasmOp::F32Add];
693 let config = CompileConfig {
694 target: TargetSpec::cortex_m3(),
695 no_optimize: true,
696 ..CompileConfig::default()
697 };
698
699 let result = backend.compile_function("fadd", &ops, &config);
700 assert!(
701 result.is_err(),
702 "f32 operations should fail on Cortex-M3 (no FPU)"
703 );
704 }
705
706 #[test]
707 fn test_f32_accepted_on_cortex_m4f() {
708 let backend = ArmBackend::new();
709 let ops = vec![WasmOp::F32Const(1.0), WasmOp::F32Const(2.0), WasmOp::F32Add];
710 let config = CompileConfig {
711 target: TargetSpec::cortex_m4f(),
712 no_optimize: true,
713 ..CompileConfig::default()
714 };
715
716 let result = backend.compile_function("fadd", &ops, &config);
717 assert!(
718 result.is_ok(),
719 "f32 operations should succeed on Cortex-M4F, got: {:?}",
720 result.unwrap_err()
721 );
722 }
723
724 #[test]
725 fn test_i32_works_on_all_targets() {
726 let backend = ArmBackend::new();
727 let ops = vec![WasmOp::LocalGet(0), WasmOp::LocalGet(1), WasmOp::I32Add];
728
729 let config_m3 = CompileConfig {
731 target: TargetSpec::cortex_m3(),
732 no_optimize: true,
733 ..CompileConfig::default()
734 };
735 assert!(
736 backend.compile_function("add", &ops, &config_m3).is_ok(),
737 "i32 ops should work on Cortex-M3"
738 );
739
740 let config_m4f = CompileConfig {
742 target: TargetSpec::cortex_m4f(),
743 no_optimize: true,
744 ..CompileConfig::default()
745 };
746 assert!(
747 backend.compile_function("add", &ops, &config_m4f).is_ok(),
748 "i32 ops should work on Cortex-M4F"
749 );
750
751 let config_m7dp = CompileConfig {
753 target: TargetSpec::cortex_m7dp(),
754 no_optimize: true,
755 ..CompileConfig::default()
756 };
757 assert!(
758 backend.compile_function("add", &ops, &config_m7dp).is_ok(),
759 "i32 ops should work on Cortex-M7DP"
760 );
761 }
762
763 #[test]
764 fn test_f32_rejected_on_cortex_m4_no_fpu() {
765 let backend = ArmBackend::new();
767 let ops = vec![WasmOp::F32Const(1.5), WasmOp::F32Const(2.5), WasmOp::F32Mul];
768 let config = CompileConfig {
769 target: TargetSpec::cortex_m4(),
770 no_optimize: true,
771 ..CompileConfig::default()
772 };
773
774 let result = backend.compile_function("fmul", &ops, &config);
775 assert!(
776 result.is_err(),
777 "f32 operations should fail on Cortex-M4 (no FPU)"
778 );
779 }
780
781 #[test]
803 fn test_issue120_f32_div_compiles_via_optimized_default() {
804 let backend = ArmBackend::new();
805 let ops = vec![WasmOp::LocalGet(0), WasmOp::LocalGet(1), WasmOp::F32Div];
806 let config = CompileConfig {
807 target: TargetSpec::cortex_m4f(),
808 ..CompileConfig::default()
811 };
812
813 let result = backend.compile_function("fdiv", &ops, &config);
814 assert!(
815 result.is_ok(),
816 "f32.div must compile on Cortex-M4F via the optimized->direct \
817 fallback (issue #120), got: {:?}",
818 result.as_ref().err()
819 );
820 assert!(
821 !result.unwrap().code.is_empty(),
822 "f32.div must produce non-empty machine code"
823 );
824 }
825
826 #[test]
829 fn test_issue120_assorted_f32_ops_compile_via_optimized_default() {
830 let backend = ArmBackend::new();
831 let config = CompileConfig {
832 target: TargetSpec::cortex_m4f(),
833 ..CompileConfig::default()
834 };
835
836 let cases: Vec<(&str, Vec<WasmOp>)> = vec![
837 (
838 "fadd",
839 vec![WasmOp::LocalGet(0), WasmOp::LocalGet(1), WasmOp::F32Add],
840 ),
841 (
842 "fmul",
843 vec![WasmOp::LocalGet(0), WasmOp::LocalGet(1), WasmOp::F32Mul],
844 ),
845 (
846 "fsub",
847 vec![WasmOp::LocalGet(0), WasmOp::LocalGet(1), WasmOp::F32Sub],
848 ),
849 ];
850
851 for (name, ops) in cases {
852 let result = backend.compile_function(name, &ops, &config);
853 assert!(
854 result.is_ok(),
855 "{name} must compile via the optimized->direct fallback \
856 (issue #120), got: {:?}",
857 result.as_ref().err()
858 );
859 assert!(
860 !result.unwrap().code.is_empty(),
861 "{name} must produce non-empty machine code"
862 );
863 }
864 }
865
866 #[test]
869 fn test_issue120_f32_div_rejected_on_no_fpu_via_optimized() {
870 let backend = ArmBackend::new();
871 let ops = vec![WasmOp::LocalGet(0), WasmOp::LocalGet(1), WasmOp::F32Div];
872 let config = CompileConfig {
873 target: TargetSpec::cortex_m3(),
874 ..CompileConfig::default()
875 };
876
877 let result = backend.compile_function("fdiv", &ops, &config);
878 assert!(
879 result.is_err(),
880 "f32.div must be rejected on Cortex-M3 (no FPU), not panic"
881 );
882 }
883
884 #[test]
889 fn test_issue94_hi32_extract_is_smaller_than_generic_shift() {
890 let backend = ArmBackend::new();
891 let config = CompileConfig {
892 target: TargetSpec::cortex_m4f(),
893 ..CompileConfig::default()
894 };
895
896 let ops_hi32 = vec![
898 WasmOp::LocalGet(0), WasmOp::I64Const(32),
900 WasmOp::I64ShrU,
901 WasmOp::I32WrapI64,
902 ];
903 let func_hi32 = backend
904 .compile_function("hi32_extract", &ops_hi32, &config)
905 .unwrap();
906
907 let ops_generic = vec![
911 WasmOp::LocalGet(0),
912 WasmOp::I64Const(7),
913 WasmOp::I64ShrU,
914 WasmOp::I32WrapI64,
915 ];
916 let func_generic = backend
917 .compile_function("generic_shr", &ops_generic, &config)
918 .unwrap();
919
920 let bytes_hi32 = func_hi32.code.len();
921 let bytes_generic = func_generic.code.len();
922 println!(
923 "\n[issue #94] hi32 extract: {} bytes (vs generic shift: {} bytes; saved {})",
924 bytes_hi32,
925 bytes_generic,
926 bytes_generic.saturating_sub(bytes_hi32)
927 );
928 let hex: String = func_hi32
929 .code
930 .iter()
931 .map(|b| format!("{:02x}", b))
932 .collect::<Vec<_>>()
933 .join(" ");
934 println!("[issue #94] hi32 bytes: {}", hex);
935 assert!(
938 bytes_hi32 + 30 <= bytes_generic,
939 "issue #94: hi32 extract = {} bytes, generic shift = {} bytes; \
940 expected optimized form to be at least 30 bytes smaller",
941 bytes_hi32,
942 bytes_generic,
943 );
944 }
945}