void compute_quantized_weights_for_decimation(
	const decimation_info& di,
	float low_bound,
	float high_bound,
	const float* dec_weight_ideal_value,
	float* weight_set_out,
	uint8_t* quantized_weight_set,
	quant_method quant_level
) {
	int weight_count = di.weight_count;
	promise(weight_count > 0);
	const quantization_and_transfer_table *qat = &(quant_and_xfer_tables[quant_level]);

	// The available quant levels, stored with a minus 1 bias
	static const float quant_levels_m1[12] {
		1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 7.0f, 9.0f, 11.0f, 15.0f, 19.0f, 23.0f, 31.0f
	};

	float quant_level_m1 = quant_levels_m1[quant_level];

	// Quantize the weight set using both the specified low/high bounds and standard 0..1 bounds

	// TODO: Oddity to investigate; triggered by test in issue #265.
	if (high_bound < low_bound)
	{
		low_bound = 0.0f;
		high_bound = 1.0f;
	}

	float rscale = high_bound - low_bound;
	float scale = 1.0f / rscale;

	float scaled_low_bound = low_bound * scale;
	rscale *= 1.0f / 64.0f;

	vfloat scalev(scale);
	vfloat scaled_low_boundv(scaled_low_bound);
	vfloat quant_level_m1v(quant_level_m1);
	vfloat rscalev(rscale);
	vfloat low_boundv(low_bound);

	// This runs to the rounded-up SIMD size, which is safe as the loop tail is filled with known
	// safe data in compute_ideal_weights_for_decimation and arrays are always 64 elements
	for (int i = 0; i < weight_count; i += ASTCENC_SIMD_WIDTH)
	{
		vfloat ix = loada(&dec_weight_ideal_value[i]) * scalev - scaled_low_boundv;
		ix = clampzo(ix);

		// Look up the two closest indexes and return the one that was closest
		vfloat ix1 = ix * quant_level_m1v;

		vint weightl = float_to_int(ix1);
		vint weighth = weightl + vint(1);

		vfloat ixl = gatherf(qat->unquantized_value_unsc, weightl);
		vfloat ixh = gatherf(qat->unquantized_value_unsc, weighth);

		vmask mask = (ixl + ixh) < (vfloat(128.0f) * ix);
		vint weight = select(weightl, weighth, mask);
		ixl = select(ixl, ixh, mask);

		// Invert the weight-scaling that was done initially
		storea(ixl * rscalev + low_boundv, &weight_set_out[i]);
		vint scm = gatheri(qat->scramble_map, weight);
		vint scn = pack_low_bytes(scm);
		store_nbytes(scn, &quantized_weight_set[i]);
	}
}
void compute_quantized_weights_for_decimation(
	const decimation_info& di,
	float low_bound,
	float high_bound,
	const float* dec_weight_ideal_value,
	float* weight_set_out,
	uint8_t* quantized_weight_set,
	quant_method quant_level
) {
	int weight_count = di.weight_count;
	promise(weight_count > 0);
	const quantization_and_transfer_table *qat = &(quant_and_xfer_tables[quant_level]);

	 
	static const float quant_levels_m1[12] {
		1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 7.0f, 9.0f, 11.0f, 15.0f, 19.0f, 23.0f, 31.0f
	};

	float quant_level_m1 = quant_levels_m1[quant_level];

	 

	 
	if (high_bound < low_bound)
	{
		low_bound = 0.0f;
		high_bound = 1.0f;
	}

	float rscale = high_bound - low_bound;
	float scale = 1.0f / rscale;

	float scaled_low_bound = low_bound * scale;
	rscale *= 1.0f / 64.0f;

	vfloat scalev(scale);
	vfloat scaled_low_boundv(scaled_low_bound);
	vfloat quant_level_m1v(quant_level_m1);
	vfloat rscalev(rscale);
	vfloat low_boundv(low_bound);

	 
	 
	for (int i = 0; i < weight_count; i += ASTCENC_SIMD_WIDTH)
	{
		vfloat ix = loada(&dec_weight_ideal_value[i]) * scalev - scaled_low_boundv;
		ix = clampzo(ix);

		 
		vfloat ix1 = ix * quant_level_m1v;

		vint weightl = float_to_int(ix1);
		vint weighth = weightl + vint(1);

		vfloat ixl = gatherf(qat->unquantized_value_unsc, weightl);
		vfloat ixh = gatherf(qat->unquantized_value_unsc, weighth);

		vmask mask = (ixl + ixh) < (vfloat(128.0f) * ix);
		vint weight = select(weightl, weighth, mask);
		ixl = select(ixl, ixh, mask);

		 
		storea(ixl * rscalev + low_boundv, &weight_set_out[i]);
		vint scm = gatheri(qat->scramble_map, weight);
		vint scn = pack_low_bytes(scm);
		store_nbytes(scn, &quantized_weight_set[i]);
	}
}