@@ -9154,80 +9154,74 @@ pub static ZIA_MAP_512: [[XC2ZIAInput; 78]; INPUTS_PER_ANDTERM] = [
9154
9154
XC2ZIAInput :: IBuf { ibuf : 0 } ] ,
9155
9155
] ;
9156
9156
9157
+ const T : bool = true ;
9158
+ const F : bool = false ;
9159
+
9157
9160
/// Internal function that reads a piece of the ZIA corresponding to one FB and one row
9158
9161
pub fn read_32_zia_fb_row_logical ( fuses : & [ bool ] , block_idx : usize , row_idx : usize )
9159
9162
-> Result < XC2ZIARowPiece , & ' static str > {
9160
9163
9161
- let mut zia_row_fuses = [ false ; 8 ] ;
9162
-
9163
- for i in 0 ..8 {
9164
- zia_row_fuses[ 7 - i] = fuses[ block_idx + row_idx * 8 + i] ;
9165
- }
9166
-
9167
- // 7th bit is active-high unlike the rest
9168
- zia_row_fuses[ 7 ] = !zia_row_fuses[ 7 ] ;
9169
-
9170
- let mut active_bit = 8 ;
9171
- for i in 0 ..8 {
9172
- // active low
9173
- if !zia_row_fuses[ i] {
9174
- if active_bit != 8 {
9175
- return Err ( "multiple ZIA inputs selected!" ) ;
9176
- }
9177
-
9178
- active_bit = i;
9179
- }
9180
- }
9164
+ // This is an ugly workaround for the lack of stable slice patterns
9165
+ let zia_row_fuses = (
9166
+ fuses[ block_idx + row_idx * 8 + 0 ] ,
9167
+ fuses[ block_idx + row_idx * 8 + 1 ] ,
9168
+ fuses[ block_idx + row_idx * 8 + 2 ] ,
9169
+ fuses[ block_idx + row_idx * 8 + 3 ] ,
9170
+ fuses[ block_idx + row_idx * 8 + 4 ] ,
9171
+ fuses[ block_idx + row_idx * 8 + 5 ] ,
9172
+ fuses[ block_idx + row_idx * 8 + 6 ] ,
9173
+ fuses[ block_idx + row_idx * 8 + 7 ] ,
9174
+ ) ;
9181
9175
9182
- if active_bit == 8 {
9183
- // FIXME: Is this an error?
9184
- return Err ( "no ZIA inputs selected!" ) ;
9185
- }
9176
+ let selected_input = match zia_row_fuses {
9177
+ ( F , T , T , T , T , T , T , F ) => ZIA_MAP_32 [ row_idx] [ 0 ] ,
9178
+ ( F , T , T , T , T , T , F , T ) => ZIA_MAP_32 [ row_idx] [ 1 ] ,
9179
+ ( F , T , T , T , T , F , T , T ) => ZIA_MAP_32 [ row_idx] [ 2 ] ,
9180
+ ( F , T , T , T , F , T , T , T ) => ZIA_MAP_32 [ row_idx] [ 3 ] ,
9181
+ ( F , T , T , F , T , T , T , T ) => ZIA_MAP_32 [ row_idx] [ 4 ] ,
9182
+ ( F , T , F , T , T , T , T , T ) => ZIA_MAP_32 [ row_idx] [ 5 ] ,
9183
+ ( T , T , T , T , T , T , T , T ) => XC2ZIAInput :: One ,
9184
+ ( F , F , T , T , T , T , T , T ) => XC2ZIAInput :: Zero ,
9185
+ _ => return Err ( "unknown ZIA input choice" ) ,
9186
+ } ;
9186
9187
9187
9188
Ok ( XC2ZIARowPiece {
9188
- selected : if active_bit == 6 {
9189
- XC2ZIAInput :: Zero
9190
- } else if active_bit == 7 {
9191
- XC2ZIAInput :: One
9192
- } else {
9193
- ZIA_MAP_32 [ row_idx] [ active_bit]
9194
- }
9189
+ selected : selected_input
9195
9190
} )
9196
9191
}
9197
9192
9198
9193
/// Internal function that takes a ZIA row and choice and returns the bit encoding for it
9199
9194
pub fn encode_32_zia_choice ( row : u32 , choice : XC2ZIAInput ) -> Option < [ bool ; 8 ] > {
9200
9195
if choice == XC2ZIAInput :: One {
9201
- Some ( [ true , true , true , true , true , true , true , true ] )
9196
+ Some ( [ T , T , T , T , T , T , T , T ] )
9202
9197
} else if choice == XC2ZIAInput :: Zero {
9203
- Some ( [ true , true , true , true , true , true , false , false ] )
9198
+ Some ( [ F , F , T , T , T , T , T , T ] )
9204
9199
} else {
9205
- let mut ret = [ true ; 8 ] ;
9206
- // This bit is active-high unlike the rest
9207
- ret[ 7 ] = false ;
9208
-
9209
- let mut found_bit = 8 ;
9200
+ let mut found_bit = ZIA_MAP_32 [ 0 ] . len ( ) ;
9210
9201
for i in 0 ..ZIA_MAP_32 [ row as usize ] . len ( ) {
9211
9202
if choice == ZIA_MAP_32 [ row as usize ] [ i] {
9212
9203
found_bit = i;
9213
9204
break ;
9214
9205
}
9215
9206
}
9216
9207
9217
- if found_bit == 8 {
9208
+ if found_bit == ZIA_MAP_32 [ 0 ] . len ( ) {
9218
9209
// Didn't find it
9219
9210
return None ;
9220
9211
}
9221
9212
9222
- ret[ found_bit] = false ;
9223
-
9224
- Some ( ret)
9213
+ match found_bit {
9214
+ 0 => Some ( [ F , T , T , T , T , T , T , F ] ) ,
9215
+ 1 => Some ( [ F , T , T , T , T , T , F , T ] ) ,
9216
+ 2 => Some ( [ F , T , T , T , T , F , T , T ] ) ,
9217
+ 3 => Some ( [ F , T , T , T , F , T , T , T ] ) ,
9218
+ 4 => Some ( [ F , T , T , F , T , T , T , T ] ) ,
9219
+ 5 => Some ( [ F , T , F , T , T , T , T , T ] ) ,
9220
+ _ => unreachable ! ( ) ,
9221
+ }
9225
9222
}
9226
9223
}
9227
9224
9228
- const T : bool = true ;
9229
- const F : bool = false ;
9230
-
9231
9225
/// Internal function that reads a piece of the ZIA corresponding to one FB and one row
9232
9226
pub fn read_64_zia_fb_row_logical ( fuses : & [ bool ] , block_idx : usize , row_idx : usize )
9233
9227
-> Result < XC2ZIARowPiece , & ' static str > {
@@ -9284,15 +9278,15 @@ pub fn encode_64_zia_choice(row: u32, choice: XC2ZIAInput) -> Option<[bool; 16]>
9284
9278
// TODO: This one isn't certain
9285
9279
Some ( [ T , T , T , T , T , T , T , F , F , T , T , T , T , T , T , T ] )
9286
9280
} else {
9287
- let mut found_bit = 12 ;
9281
+ let mut found_bit = ZIA_MAP_64 [ 0 ] . len ( ) ;
9288
9282
for i in 0 ..ZIA_MAP_64 [ row as usize ] . len ( ) {
9289
9283
if choice == ZIA_MAP_64 [ row as usize ] [ i] {
9290
9284
found_bit = i;
9291
9285
break ;
9292
9286
}
9293
9287
}
9294
9288
9295
- if found_bit == 12 {
9289
+ if found_bit == ZIA_MAP_64 [ 0 ] . len ( ) {
9296
9290
// Didn't find it
9297
9291
return None ;
9298
9292
}
@@ -9393,15 +9387,15 @@ pub fn encode_128_zia_choice(row: u32, choice: XC2ZIAInput) -> Option<[bool; 28]
9393
9387
// TODO: This one isn't certain
9394
9388
Some ( [ T , T , T , T , T , T , T , T , F , F , T , T , T , T , T , T , T , T , T , T , T , T , T , T , T , T , T , T ] )
9395
9389
} else {
9396
- let mut found_bit = 22 ;
9390
+ let mut found_bit = ZIA_MAP_128 [ 0 ] . len ( ) ;
9397
9391
for i in 0 ..ZIA_MAP_128 [ row as usize ] . len ( ) {
9398
9392
if choice == ZIA_MAP_128 [ row as usize ] [ i] {
9399
9393
found_bit = i;
9400
9394
break ;
9401
9395
}
9402
9396
}
9403
9397
9404
- if found_bit == 22 {
9398
+ if found_bit == ZIA_MAP_128 [ 0 ] . len ( ) {
9405
9399
// Didn't find it
9406
9400
return None ;
9407
9401
}
@@ -9550,15 +9544,15 @@ pub fn encode_256_zia_choice(row: u32, choice: XC2ZIAInput) -> Option<[bool; 48]
9550
9544
// TODO: This one isn't certain
9551
9545
Some ( [ T , T , T , T , T , T , T , T , T , T , T , T , T , T , T , T , T , T , T , T , T , T , T , T , T , T , T , T , T , T , T , T , T , T , T , T , T , T , T , T , F , F , T , T , T , T , T , T ] )
9552
9546
} else {
9553
- let mut found_bit = 40 ;
9547
+ let mut found_bit = ZIA_MAP_256 [ 0 ] . len ( ) ;
9554
9548
for i in 0 ..ZIA_MAP_256 [ row as usize ] . len ( ) {
9555
9549
if choice == ZIA_MAP_256 [ row as usize ] [ i] {
9556
9550
found_bit = i;
9557
9551
break ;
9558
9552
}
9559
9553
}
9560
9554
9561
- if found_bit == 40 {
9555
+ if found_bit == ZIA_MAP_256 [ 0 ] . len ( ) {
9562
9556
// Didn't find it
9563
9557
return None ;
9564
9558
}
@@ -9773,15 +9767,15 @@ pub fn encode_384_zia_choice(row: u32, choice: XC2ZIAInput) -> Option<[bool; 74]
9773
9767
// TODO: This one isn't certain
9774
9768
Some ( [ T , F , F , T , T , T , T , T , T , T , T , T , T , T , T , T , T , T , T , T , T , T , T , T , T , T , T , T , T , T , T , T , T , T , T , T , T , T , T , T , T , T , T , T , T , T , T , T , T , T , T , T , T , T , T , T , T , T , T , T , T , T , T , T , T , T , T , T , T , T , T , T , T , T ] )
9775
9769
} else {
9776
- let mut found_bit = 62 ;
9770
+ let mut found_bit = ZIA_MAP_384 [ 0 ] . len ( ) ;
9777
9771
for i in 0 ..ZIA_MAP_384 [ row as usize ] . len ( ) {
9778
9772
if choice == ZIA_MAP_384 [ row as usize ] [ i] {
9779
9773
found_bit = i;
9780
9774
break ;
9781
9775
}
9782
9776
}
9783
9777
9784
- if found_bit == 62 {
9778
+ if found_bit == ZIA_MAP_384 [ 0 ] . len ( ) {
9785
9779
// Didn't find it
9786
9780
return None ;
9787
9781
}
@@ -10048,15 +10042,15 @@ pub fn encode_512_zia_choice(row: u32, choice: XC2ZIAInput) -> Option<[bool; 88]
10048
10042
// TODO: This one isn't certain
10049
10043
Some ( [ T , T , T , T , T , T , T , T , T , T , T , T , T , T , T , T , T , T , T , T , T , T , T , T , T , T , T , T , T , T , T , T , T , T , T , T , T , T , T , T , T , T , T , F , F , T , T , T , T , T , T , T , T , T , T , T , T , T , T , T , T , T , T , T , T , T , T , T , T , T , T , T , T , T , T , T , T , T , T , T , T , T , T , T , T , T , T , T ] )
10050
10044
} else {
10051
- let mut found_bit = 78 ;
10045
+ let mut found_bit = ZIA_MAP_512 [ 0 ] . len ( ) ;
10052
10046
for i in 0 ..ZIA_MAP_512 [ row as usize ] . len ( ) {
10053
10047
if choice == ZIA_MAP_512 [ row as usize ] [ i] {
10054
10048
found_bit = i;
10055
10049
break ;
10056
10050
}
10057
10051
}
10058
10052
10059
- if found_bit == 78 {
10053
+ if found_bit == ZIA_MAP_512 [ 0 ] . len ( ) {
10060
10054
// Didn't find it
10061
10055
return None ;
10062
10056
}
0 commit comments