def get_slice_length(builder, slicestruct):
 start = slicestruct.start
 stop = slicestruct.stop
 step = slicestruct.step
 one = ir.Constant(start.type, 1)
 zero = ir.Constant(start.type, 0)
 is_step_negative = cgutils.is_neg_int(builder, step)
 delta = builder.sub(stop, start)
 pos_dividend = builder.sub(delta, one)
 neg_dividend = builder.add(delta, one)
 dividend = builder.select(is_step_negative, neg_dividend, pos_dividend)
 nominal_length = builder.add(one, builder.sdiv(dividend, step))
 is_zero_length = builder.select(is_step_negative, builder.icmp_signed('>=', delta, zero), builder.icmp_signed('<=', delta, zero))
 return builder.select(is_zero_length, zero, nominal_length)

def get_slice_length ( builder , slicestruct ) : start = slicestruct . start stop = slicestruct . stop step = slicestruct . step one = ir . Constant ( start . type , 1 ) zero = ir . Constant ( start . type , 0 ) is_step_negative = cgutils . is_neg_int ( builder , step ) delta = builder . sub ( stop , start ) pos_dividend = builder . sub ( delta , one ) neg_dividend = builder . add ( delta , one ) dividend = builder . select ( is_step_negative , neg_dividend , pos_dividend ) nominal_length = builder . add ( one , builder . sdiv ( dividend , step ) ) is_zero_length = builder . select ( is_step_negative , builder . icmp_signed ( '>=' , delta , zero ) , builder . icmp_signed ( '<=' , delta , zero ) ) return builder . select ( is_zero_length , zero , nominal_length )
given a slice .