riscfetch-core 2.2.0

RISC-V system information library - ISA extensions, hart count, hardware IDs
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
//! ISA string parsing functions

use crate::extensions::{
    STANDARD_EXTENSIONS, S_CATEGORY_NAMES, S_EXTENSIONS, Z_CATEGORY_NAMES, Z_EXTENSIONS,
};

/// Extension info with category and support status
#[derive(Debug, Clone)]
pub struct ExtensionInfo {
    pub name: String,
    pub description: String,
    pub category: String,
    pub supported: bool,
}

/// Strip rv32/rv64 prefix from ISA base part to get extension letters only
#[must_use]
pub fn strip_rv_prefix(base: &str) -> &str {
    base.strip_prefix("rv64")
        .or_else(|| base.strip_prefix("rv32"))
        .unwrap_or(base)
}

/// Check if an ISA string contains a multi-letter extension by exact part matching.
/// Extensions are underscore-separated; this avoids false positives from substring
/// matching (e.g. "zk" matching inside "zkn", or "sha" inside "shvstvala").
fn isa_has_extension(isa: &str, pattern: &str) -> bool {
    isa.split('_').any(|part| part == pattern)
}

/// Parse extensions from ISA string (pure function for testing)
#[must_use]
pub fn parse_extensions_compact(isa: &str) -> String {
    let isa = isa.to_lowercase();
    let mut exts = Vec::new();

    // Get the base part before any underscore
    let base = isa.split('_').next().unwrap_or(&isa);
    let ext_part = strip_rv_prefix(base);

    // G is shorthand for IMAFD (per RISC-V spec)
    let has_g = ext_part.contains('g');

    // Standard extensions in canonical order
    // Note: E and I are mutually exclusive
    let standard = [
        ('i', "I", false), // (char, name, implied_by_g)
        ('e', "E", false), // E = embedded (16 registers)
        ('m', "M", true),
        ('a', "A", true),
        ('f', "F", true),
        ('d', "D", true),
        ('q', "Q", false),
        ('c', "C", false),
        ('b', "B", false),
        ('v', "V", false),
        ('h', "H", false),
    ];

    for (ch, name, implied_by_g) in standard {
        if ext_part.contains(ch) || (has_g && implied_by_g) {
            exts.push(name);
        }
    }

    // If G is present but I wasn't explicitly added, add I (G implies IMAFD)
    if has_g && !exts.contains(&"I") && !exts.contains(&"E") {
        exts.insert(0, "I");
    }

    exts.join(" ")
}

/// Parse Z-extensions from ISA string (pure function for testing)
#[must_use]
pub fn parse_z_extensions(isa: &str) -> String {
    let isa = isa.to_lowercase();
    let mut z_exts = Vec::new();

    // Check if G is present (G implies Zicsr_Zifencei per RISC-V spec)
    let base = isa.split('_').next().unwrap_or(&isa);
    let ext_part = strip_rv_prefix(base);
    let has_g = ext_part.contains('g');

    // Add implied Z-extensions from G
    if has_g {
        z_exts.push("zicsr".to_string());
        z_exts.push("zifencei".to_string());
    }

    // Add explicit Z-extensions (z prefix only)
    for part in isa.split('_') {
        if part.starts_with('z') && !z_exts.contains(&part.to_string()) {
            z_exts.push(part.to_string());
        }
    }

    z_exts.join(" ")
}

/// Parse S-extensions from ISA string (pure function for testing)
#[must_use]
pub fn parse_s_extensions(isa: &str) -> String {
    let isa = isa.to_lowercase();
    let mut s_exts = Vec::new();

    // Add explicit S-extensions (s prefix only)
    for part in isa.split('_') {
        if part.starts_with('s') && !s_exts.contains(&part.to_string()) {
            s_exts.push(part.to_string());
        }
    }

    s_exts.join(" ")
}

/// Parse extensions with explanations (pure function for testing)
#[must_use]
pub fn parse_extensions_explained(isa: &str) -> Vec<(String, String)> {
    let isa = isa.to_lowercase();
    let base = isa.split('_').next().unwrap_or(&isa);
    let ext_part = strip_rv_prefix(base);
    let mut exts = Vec::new();

    for &(ch, name, desc) in STANDARD_EXTENSIONS {
        if ext_part.contains(ch) {
            exts.push((name.to_string(), desc.to_string()));
        }
    }

    exts
}

/// Parse Z-extensions with explanations (pure function for testing)
#[must_use]
pub fn parse_z_extensions_explained(isa: &str) -> Vec<(String, String)> {
    let isa = isa.to_lowercase();
    let mut z_exts = Vec::new();

    for &(pattern, name, desc, _category) in Z_EXTENSIONS {
        if isa_has_extension(&isa, pattern) {
            z_exts.push((name.to_string(), desc.to_string()));
        }
    }

    z_exts
}

/// Parse S-extensions with explanations (pure function for testing)
#[must_use]
pub fn parse_s_extensions_explained(isa: &str) -> Vec<(String, String)> {
    let isa = isa.to_lowercase();
    let mut s_exts = Vec::new();

    for &(pattern, name, desc, _category) in S_EXTENSIONS {
        if isa_has_extension(&isa, pattern) {
            s_exts.push((name.to_string(), desc.to_string()));
        }
    }

    s_exts
}

/// Parse Z-extensions with category info
#[must_use]
pub fn parse_z_extensions_with_category(isa: &str) -> Vec<ExtensionInfo> {
    let isa = isa.to_lowercase();
    let mut z_exts = Vec::new();

    // Check if G is present (G implies Zicsr_Zifencei per RISC-V spec)
    let base = isa.split('_').next().unwrap_or(&isa);
    let ext_part = strip_rv_prefix(base);
    let has_g = ext_part.contains('g');

    // Add implied Z-extensions from G
    if has_g {
        z_exts.push(ExtensionInfo {
            name: "Zicsr".to_string(),
            description: "CSR Instructions".to_string(),
            category: "base".to_string(),
            supported: true,
        });
        z_exts.push(ExtensionInfo {
            name: "Zifencei".to_string(),
            description: "Instruction-Fetch Fence".to_string(),
            category: "base".to_string(),
            supported: true,
        });
    }

    for &(pattern, name, desc, category) in Z_EXTENSIONS {
        if isa_has_extension(&isa, pattern) {
            // Skip if already added (implied by G)
            if !z_exts.iter().any(|e| e.name.eq_ignore_ascii_case(name)) {
                z_exts.push(ExtensionInfo {
                    name: name.to_string(),
                    description: desc.to_string(),
                    category: category.to_string(),
                    supported: true,
                });
            }
        }
    }

    z_exts
}

/// Parse S-extensions with category info
#[must_use]
pub fn parse_s_extensions_with_category(isa: &str) -> Vec<ExtensionInfo> {
    let isa = isa.to_lowercase();
    let mut s_exts = Vec::new();

    for &(pattern, name, desc, category) in S_EXTENSIONS {
        if isa_has_extension(&isa, pattern) {
            s_exts.push(ExtensionInfo {
                name: name.to_string(),
                description: desc.to_string(),
                category: category.to_string(),
                supported: true,
            });
        }
    }

    s_exts
}

/// Get category display name for Z-extensions
#[must_use]
pub fn get_z_category_name(category: &str) -> &'static str {
    Z_CATEGORY_NAMES
        .iter()
        .find(|(id, _)| *id == category)
        .map_or("Other", |(_, name)| *name)
}

/// Get category display name for S-extensions
#[must_use]
pub fn get_s_category_name(category: &str) -> &'static str {
    S_CATEGORY_NAMES
        .iter()
        .find(|(id, _)| *id == category)
        .map_or("Other", |(_, name)| *name)
}

/// Group extensions by category
#[must_use]
pub fn group_by_category(extensions: &[ExtensionInfo]) -> Vec<(String, Vec<&ExtensionInfo>)> {
    use std::collections::BTreeMap;
    let mut groups: BTreeMap<String, Vec<&ExtensionInfo>> = BTreeMap::new();

    for ext in extensions {
        groups.entry(ext.category.clone()).or_default().push(ext);
    }

    groups.into_iter().collect()
}

/// Get ALL Z-extensions with support status based on ISA string
#[must_use]
pub fn get_all_z_extensions_with_status(isa: &str) -> Vec<ExtensionInfo> {
    let isa = isa.to_lowercase();
    let base = isa.split('_').next().unwrap_or(&isa);
    let ext_part = strip_rv_prefix(base);
    let has_g = ext_part.contains('g');

    Z_EXTENSIONS
        .iter()
        .map(|&(pattern, name, desc, category)| {
            let supported = isa_has_extension(&isa, pattern)
                || (has_g && (pattern == "zicsr" || pattern == "zifencei"));
            ExtensionInfo {
                name: name.to_string(),
                description: desc.to_string(),
                category: category.to_string(),
                supported,
            }
        })
        .collect()
}

/// Get ALL S-extensions with support status based on ISA string
#[must_use]
pub fn get_all_s_extensions_with_status(isa: &str) -> Vec<ExtensionInfo> {
    let isa = isa.to_lowercase();

    S_EXTENSIONS
        .iter()
        .map(|&(pattern, name, desc, category)| {
            let supported = isa_has_extension(&isa, pattern);
            ExtensionInfo {
                name: name.to_string(),
                description: desc.to_string(),
                category: category.to_string(),
                supported,
            }
        })
        .collect()
}

/// Get ALL standard extensions with support status
#[must_use]
pub fn get_all_standard_extensions_with_status(isa: &str) -> Vec<(String, String, bool)> {
    let isa = isa.to_lowercase();
    let base = isa.split('_').next().unwrap_or(&isa);
    let ext_part = strip_rv_prefix(base);
    let has_g = ext_part.contains('g');

    STANDARD_EXTENSIONS
        .iter()
        .map(|&(char, name, desc)| {
            let supported =
                ext_part.contains(char) || (has_g && matches!(char, 'i' | 'm' | 'a' | 'f' | 'd'));
            (name.to_string(), desc.to_string(), supported)
        })
        .collect()
}

/// Parse vector details from ISA string (pure function for testing)
/// Returns None if no vector extension, Some(details) otherwise
#[must_use]
pub fn parse_vector_from_isa(isa: &str) -> Option<String> {
    let isa = isa.to_lowercase();
    let base = isa.split('_').next().unwrap_or(&isa);
    let ext_part = strip_rv_prefix(base);

    // Check for V extension in the extension part, or zve* in Z-extensions
    let has_zve = isa.split('_').any(|part| part.starts_with("zve"));
    if !ext_part.contains('v') && !has_zve {
        return None;
    }

    let mut details = vec!["Enabled".to_string()];

    // Detect VLEN from zvl* extensions (use largest value)
    // If no zvl* specified, VLEN is implementation-defined (do not display)
    if isa_has_extension(&isa, "zvl65536b") {
        details.push("VLEN>=65536".to_string());
    } else if isa_has_extension(&isa, "zvl32768b") {
        details.push("VLEN>=32768".to_string());
    } else if isa_has_extension(&isa, "zvl16384b") {
        details.push("VLEN>=16384".to_string());
    } else if isa_has_extension(&isa, "zvl8192b") {
        details.push("VLEN>=8192".to_string());
    } else if isa_has_extension(&isa, "zvl4096b") {
        details.push("VLEN>=4096".to_string());
    } else if isa_has_extension(&isa, "zvl2048b") {
        details.push("VLEN>=2048".to_string());
    } else if isa_has_extension(&isa, "zvl1024b") {
        details.push("VLEN>=1024".to_string());
    } else if isa_has_extension(&isa, "zvl512b") {
        details.push("VLEN>=512".to_string());
    } else if isa_has_extension(&isa, "zvl256b") {
        details.push("VLEN>=256".to_string());
    } else if isa_has_extension(&isa, "zvl128b") {
        details.push("VLEN>=128".to_string());
    } else if isa_has_extension(&isa, "zvl64b") {
        details.push("VLEN>=64".to_string());
    } else if isa_has_extension(&isa, "zvl32b") {
        details.push("VLEN>=32".to_string());
    }
    // No default VLEN - it's implementation-defined per RISC-V spec

    Some(details.join(", "))
}

#[cfg(test)]
mod tests {
    use super::*;

    // Real ISA strings from actual RISC-V systems
    const ISA_VISIONFIVE2: &str = "rv64imafdc_zicntr_zicsr_zifencei_zihpm_zba_zbb";
    const ISA_SPACEMIT_K1: &str = "rv64imafdcv_zicbom_zicboz_zicntr_zicsr_zifencei_zihintpause_zihpm_zba_zbb_zbc_zbs_zkt_zvkt_zvl128b_zvl256b_zvl32b_zvl64b";
    const ISA_MINIMAL: &str = "rv64imac";
    const ISA_RV32: &str = "rv32imc";

    // === parse_extensions_compact tests ===

    #[test]
    fn test_visionfive2() {
        assert_eq!(parse_extensions_compact(ISA_VISIONFIVE2), "I M A F D C");
    }

    #[test]
    fn test_spacemit() {
        assert_eq!(parse_extensions_compact(ISA_SPACEMIT_K1), "I M A F D C V");
    }

    #[test]
    fn test_minimal() {
        assert_eq!(parse_extensions_compact(ISA_MINIMAL), "I M A C");
    }

    #[test]
    fn test_rv32() {
        assert_eq!(parse_extensions_compact(ISA_RV32), "I M C");
    }

    #[test]
    fn test_unknown() {
        assert_eq!(parse_extensions_compact("unknown"), "");
    }

    #[test]
    fn test_case_insensitive() {
        assert_eq!(
            parse_extensions_compact("RV64IMAFDC"),
            parse_extensions_compact("rv64imafdc")
        );
    }

    #[test]
    fn test_empty() {
        assert_eq!(parse_extensions_compact(""), "");
    }

    // === Specification-based tests (from SPEC.md) ===

    #[test]
    fn spec_g_expansion() {
        assert_eq!(parse_extensions_compact("rv64gc"), "I M A F D C");
    }

    #[test]
    fn spec_g_expansion_uppercase() {
        assert_eq!(parse_extensions_compact("RV64GC"), "I M A F D C");
    }

    #[test]
    fn spec_e_extension() {
        assert_eq!(parse_extensions_compact("rv32e"), "E");
    }

    #[test]
    fn spec_e_with_c() {
        assert_eq!(parse_extensions_compact("rv32ec"), "E C");
    }

    #[test]
    fn spec_with_vector() {
        assert_eq!(parse_extensions_compact("rv64imafdcv"), "I M A F D C V");
    }

    #[test]
    fn spec_rv64_prefix_not_vector() {
        let result = parse_extensions_compact("rv64imafdc");
        assert!(!result.contains('V'));
    }

    #[test]
    fn spec_z_extensions_ignored() {
        assert_eq!(
            parse_extensions_compact("rv64imafdc_zba_zbb"),
            "I M A F D C"
        );
    }

    #[test]
    fn spec_rv64_only() {
        assert_eq!(parse_extensions_compact("rv64"), "");
    }

    // === parse_z_extensions tests ===

    #[test]
    fn test_z_extensions_visionfive2() {
        let result = parse_z_extensions(ISA_VISIONFIVE2);
        assert!(result.contains("zicntr"));
        assert!(result.contains("zicsr"));
        assert!(result.contains("zifencei"));
        assert!(result.contains("zba"));
        assert!(result.contains("zbb"));
    }

    #[test]
    fn test_z_extensions_spacemit() {
        let result = parse_z_extensions(ISA_SPACEMIT_K1);
        assert!(result.contains("zicbom"));
        assert!(result.contains("zicboz"));
        assert!(result.contains("zbc"));
        assert!(result.contains("zbs"));
        assert!(result.contains("zvl256b"));
    }

    #[test]
    fn test_z_extensions_minimal() {
        assert!(parse_z_extensions(ISA_MINIMAL).is_empty());
    }

    #[test]
    fn spec_z_extensions_basic() {
        assert_eq!(parse_z_extensions("rv64i_zicsr_zifencei"), "zicsr zifencei");
    }

    #[test]
    fn spec_z_extensions_order() {
        assert_eq!(parse_z_extensions("rv64i_zba_zbb_zbc"), "zba zbb zbc");
    }

    #[test]
    fn spec_z_extensions_none() {
        assert_eq!(parse_z_extensions("rv64imafdc"), "");
    }

    #[test]
    fn spec_z_extensions_g_implies() {
        assert_eq!(parse_z_extensions("rv64gc"), "zicsr zifencei");
    }

    #[test]
    fn spec_z_extensions_case() {
        assert_eq!(parse_z_extensions("rv64i_Zicsr"), "zicsr");
    }

    // === parse_s_extensions tests ===

    #[test]
    fn spec_s_extensions() {
        let result = parse_s_extensions("rv64i_sstc");
        assert!(result.contains("sstc"));
    }

    // === parse_extensions_explained tests ===

    #[test]
    fn test_explained_visionfive2() {
        let result = parse_extensions_explained(ISA_VISIONFIVE2);
        assert_eq!(result.len(), 6); // I M A F D C
        assert!(result.iter().any(|(n, _)| n == "I"));
        assert!(result.iter().any(|(n, _)| n == "M"));
        assert!(result.iter().any(|(n, _)| n == "F"));
        assert!(result.iter().any(|(n, _)| n == "D"));
        assert!(result.iter().any(|(n, _)| n == "C"));
    }

    #[test]
    fn test_z_explained_spacemit() {
        let result = parse_z_extensions_explained(ISA_SPACEMIT_K1);
        assert!(result
            .iter()
            .any(|(n, d)| n == "Zba" && d == "Address Generation"));
        assert!(result
            .iter()
            .any(|(n, d)| n == "Zbb" && d == "Basic Bit Manipulation"));
        assert!(result
            .iter()
            .any(|(n, d)| n == "Zbc" && d == "Carry-less Multiply"));
    }

    // === parse_vector_from_isa tests ===

    #[test]
    fn test_vector_no_vector() {
        assert!(parse_vector_from_isa(ISA_VISIONFIVE2).is_none());
    }

    #[test]
    fn test_vector_with_v() {
        let result = parse_vector_from_isa(ISA_SPACEMIT_K1);
        assert!(result.is_some());
        let detail = result.unwrap();
        assert!(detail.contains("Enabled"));
        assert!(detail.contains("VLEN>=256"));
    }

    #[test]
    fn test_vector_zve_only() {
        let result = parse_vector_from_isa("rv64imac_zve32x");
        assert!(result.is_some());
        assert!(result.unwrap().contains("Enabled"));
    }

    #[test]
    fn spec_vector_with_v() {
        let result = parse_vector_from_isa("rv64imafdcv");
        assert!(result.is_some());
        assert!(result.unwrap().contains("Enabled"));
    }

    #[test]
    fn spec_vector_none() {
        assert!(parse_vector_from_isa("rv64imafdc").is_none());
    }

    #[test]
    fn spec_vector_vlen_256() {
        let result = parse_vector_from_isa("rv64imafdcv_zvl256b");
        assert!(result.is_some());
        assert!(result.unwrap().contains("VLEN>=256"));
    }

    #[test]
    fn spec_vector_vlen_largest() {
        let result = parse_vector_from_isa("rv64imafdcv_zvl128b_zvl256b");
        assert!(result.is_some());
        assert!(result.unwrap().contains("VLEN>=256"));
    }

    // === False positive prevention tests ===

    #[test]
    fn test_zk_does_not_false_match_zkn() {
        // "zk" (Scalar Crypto All) must not be reported when only "zkn" is present
        let isa = "rv64i_zkn";
        let result = parse_z_extensions_explained(isa);
        assert!(
            result.iter().any(|(n, _)| n == "Zkn"),
            "Zkn should be found"
        );
        assert!(
            !result.iter().any(|(n, _)| n == "Zk"),
            "Zk should NOT be found (false positive)"
        );
    }

    #[test]
    fn test_zks_does_not_false_match_zksed() {
        // "zks" must not be reported when only "zksed" is present
        let isa = "rv64i_zksed";
        let result = parse_z_extensions_explained(isa);
        assert!(
            result.iter().any(|(n, _)| n == "Zksed"),
            "Zksed should be found"
        );
        assert!(
            !result.iter().any(|(n, _)| n == "Zks"),
            "Zks should NOT be found (false positive)"
        );
        assert!(
            !result.iter().any(|(n, _)| n == "Zk"),
            "Zk should NOT be found (false positive)"
        );
    }

    #[test]
    fn test_s_extension_no_collision_with_z() {
        // S-extensions should not appear when only Z-extensions with 's' in name are present
        let isa = "rv64i_zbs_zks";
        let result = parse_s_extensions_explained(isa);
        assert!(
            result.is_empty(),
            "No S-extensions should be found in Z-only ISA: {:?}",
            result
        );
    }

    #[test]
    fn test_s_extension_exact_match() {
        // "sstc" should match exactly, not as substring
        let isa = "rv64i_sstc_svnapot";
        let result = parse_s_extensions_explained(isa);
        assert!(
            result.iter().any(|(n, _)| n == "Sstc"),
            "Sstc should be found"
        );
        assert!(
            result.iter().any(|(n, _)| n == "Svnapot"),
            "Svnapot should be found"
        );
    }

    #[test]
    fn test_zvks_does_not_false_match_zvksc() {
        // "zvks" must not be reported when only "zvksc" is present
        let isa = "rv64iv_zvksc";
        let result = parse_z_extensions_explained(isa);
        assert!(
            result.iter().any(|(n, _)| n == "Zvksc"),
            "Zvksc should be found"
        );
        assert!(
            !result.iter().any(|(n, _)| n == "Zvks"),
            "Zvks should NOT be found (false positive)"
        );
    }

    #[test]
    fn test_zicsr_not_false_positive_for_c() {
        // Having "zicsr" in the ISA should not cause "C" to appear in standard extensions
        // (C should only come from the base part before underscores)
        let isa = "rv64ima_zicsr";
        let result = parse_extensions_compact(isa);
        assert_eq!(result, "I M A", "C should not appear from zicsr");
    }

    #[test]
    fn spec_vector_no_default_vlen() {
        let result = parse_vector_from_isa("rv64imafdcv");
        assert!(result.is_some());
        let detail = result.unwrap();
        assert!(detail.contains("Enabled"));
        assert!(!detail.contains("VLEN"));
    }
}