@@ -64,14 +64,14 @@ unsafe extern "unadjusted" {
6464#[ inline( always) ]
6565#[ unstable( feature = "stdarch_loongarch" , issue = "117427" ) ]
6666pub fn crc_w_b_w ( a : i8 , b : i32 ) -> i32 {
67- unsafe { __crc_w_b_w ( a as i32 , b) }
67+ unsafe { __crc_w_b_w ( a. cast_unsigned ( ) as i32 , b) }
6868}
6969
7070/// Calculate the CRC value using the IEEE 802.3 polynomial (0xEDB88320)
7171#[ inline( always) ]
7272#[ unstable( feature = "stdarch_loongarch" , issue = "117427" ) ]
7373pub fn crc_w_h_w ( a : i16 , b : i32 ) -> i32 {
74- unsafe { __crc_w_h_w ( a as i32 , b) }
74+ unsafe { __crc_w_h_w ( a. cast_unsigned ( ) as i32 , b) }
7575}
7676
7777/// Calculate the CRC value using the IEEE 802.3 polynomial (0xEDB88320)
@@ -92,14 +92,14 @@ pub fn crc_w_d_w(a: i64, b: i32) -> i32 {
9292#[ inline( always) ]
9393#[ unstable( feature = "stdarch_loongarch" , issue = "117427" ) ]
9494pub fn crcc_w_b_w ( a : i8 , b : i32 ) -> i32 {
95- unsafe { __crcc_w_b_w ( a as i32 , b) }
95+ unsafe { __crcc_w_b_w ( a. cast_unsigned ( ) as i32 , b) }
9696}
9797
9898/// Calculate the CRC value using the Castagnoli polynomial (0x82F63B78)
9999#[ inline( always) ]
100100#[ unstable( feature = "stdarch_loongarch" , issue = "117427" ) ]
101101pub fn crcc_w_h_w ( a : i16 , b : i32 ) -> i32 {
102- unsafe { __crcc_w_h_w ( a as i32 , b) }
102+ unsafe { __crcc_w_h_w ( a. cast_unsigned ( ) as i32 , b) }
103103}
104104
105105/// Calculate the CRC value using the Castagnoli polynomial (0x82F63B78)
@@ -163,14 +163,14 @@ pub unsafe fn iocsrwr_d(a: i64, b: i32) {
163163 __iocsrwr_d ( a, b)
164164}
165165
166- /// Generates the less-than-or-equal asseration instruction
166+ /// Generates the less-than-or-equal assertion instruction
167167#[ inline( always) ]
168168#[ unstable( feature = "stdarch_loongarch" , issue = "117427" ) ]
169169pub unsafe fn asrtle ( a : i64 , b : i64 ) {
170170 __asrtle ( a, b) ;
171171}
172172
173- /// Generates the greater-than asseration instruction
173+ /// Generates the greater-than assertion instruction
174174#[ inline( always) ]
175175#[ unstable( feature = "stdarch_loongarch" , issue = "117427" ) ]
176176pub unsafe fn asrtgt ( a : i64 , b : i64 ) {
@@ -194,3 +194,21 @@ pub unsafe fn ldpte<const IMM8: i64>(a: i64) {
194194 static_assert_uimm_bits ! ( IMM8 , 8 ) ;
195195 __ldpte ( a, IMM8 )
196196}
197+
198+ #[ cfg( test) ]
199+ mod tests {
200+ use super :: * ;
201+
202+ #[ test]
203+ fn crc32 ( ) {
204+ assert_eq ! ( crc_w_b_w( -1 , -1 ) , 16777215 ) ;
205+ assert_eq ! ( crc_w_h_w( -1 , -1 ) , 65535 ) ;
206+ assert_eq ! ( crc_w_w_w( -1 , -1 ) , 0 ) ;
207+ assert_eq ! ( crc_w_d_w( -1 , -1 ) , 3736805603u32 . cast_signed( ) ) ;
208+
209+ assert_eq ! ( crcc_w_b_w( -1 , -1 ) , 16777215 ) ;
210+ assert_eq ! ( crcc_w_h_w( -1 , -1 ) , 65535 ) ;
211+ assert_eq ! ( crcc_w_w_w( -1 , -1 ) , 0 ) ;
212+ assert_eq ! ( crcc_w_d_w( -1 , -1 ) , 3080238136u32 . cast_signed( ) ) ;
213+ }
214+ }
0 commit comments