Skip to content

Commit d3d49fb

Browse files
committed
move __tilecfg to tests mod & change void * to *mut u8
1 parent fd48ea1 commit d3d49fb

File tree

2 files changed

+83
-85
lines changed

2 files changed

+83
-85
lines changed

crates/core_arch/src/x86_64/amx.rs

Lines changed: 83 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#[inline]
99
#[target_feature(enable = "amx-tile")]
1010
#[unstable(feature = "x86_amx_intrinsics", issue = "126622")]
11-
pub unsafe fn _tile_loadconfig(mem_addr: *const i8) {
11+
pub unsafe fn _tile_loadconfig(mem_addr: *const u8) {
1212
ldtilecfg(mem_addr);
1313
}
1414

@@ -20,7 +20,7 @@ pub unsafe fn _tile_loadconfig(mem_addr: *const i8) {
2020
#[inline]
2121
#[target_feature(enable = "amx-tile")]
2222
#[unstable(feature = "x86_amx_intrinsics", issue = "126622")]
23-
pub unsafe fn _tile_storeconfig(mem_addr: *mut i8) {
23+
pub unsafe fn _tile_storeconfig(mem_addr: *mut u8) {
2424
sttilecfg(mem_addr);
2525
}
2626

@@ -31,7 +31,7 @@ pub unsafe fn _tile_storeconfig(mem_addr: *mut i8) {
3131
#[rustc_legacy_const_generics(0)]
3232
#[target_feature(enable = "amx-tile")]
3333
#[unstable(feature = "x86_amx_intrinsics", issue = "126622")]
34-
pub unsafe fn _tile_loadd<const DST: i8>(base: *const i8, stride: usize) {
34+
pub unsafe fn _tile_loadd<const DST: i8>(base: *const u8, stride: usize) {
3535
static_assert_uimm_bits!(DST, 3);
3636
tileloadd64(DST, base, stride);
3737
}
@@ -53,7 +53,7 @@ pub unsafe fn _tile_release() {
5353
#[rustc_legacy_const_generics(0)]
5454
#[target_feature(enable = "amx-tile")]
5555
#[unstable(feature = "x86_amx_intrinsics", issue = "126622")]
56-
pub unsafe fn _tile_stored<const DST: i8>(base: *mut i8, stride: usize) {
56+
pub unsafe fn _tile_stored<const DST: i8>(base: *mut u8, stride: usize) {
5757
static_assert_uimm_bits!(DST, 3);
5858
tilestored64(DST, base, stride);
5959
}
@@ -67,7 +67,7 @@ pub unsafe fn _tile_stored<const DST: i8>(base: *mut i8, stride: usize) {
6767
#[rustc_legacy_const_generics(0)]
6868
#[target_feature(enable = "amx-tile")]
6969
#[unstable(feature = "x86_amx_intrinsics", issue = "126622")]
70-
pub unsafe fn _tile_stream_loadd<const DST: i8>(base: *const i8, stride: usize) {
70+
pub unsafe fn _tile_stream_loadd<const DST: i8>(base: *const u8, stride: usize) {
7171
static_assert_uimm_bits!(DST, 3);
7272
tileloaddt164(DST, base, stride);
7373
}
@@ -227,17 +227,17 @@ pub unsafe fn _tile_cmmrlfp16ps<const DST: i8, const A: i8, const B: i8>() {
227227
#[allow(improper_ctypes)]
228228
extern "C" {
229229
#[link_name = "llvm.x86.ldtilecfg"]
230-
fn ldtilecfg(mem_addr: *const i8);
230+
fn ldtilecfg(mem_addr: *const u8);
231231
#[link_name = "llvm.x86.sttilecfg"]
232-
fn sttilecfg(mem_addr: *mut i8);
232+
fn sttilecfg(mem_addr: *mut u8);
233233
#[link_name = "llvm.x86.tileloadd64"]
234-
fn tileloadd64(dst: i8, base: *const i8, stride: usize);
234+
fn tileloadd64(dst: i8, base: *const u8, stride: usize);
235235
#[link_name = "llvm.x86.tileloaddt164"]
236-
fn tileloaddt164(dst: i8, base: *const i8, stride: usize);
236+
fn tileloaddt164(dst: i8, base: *const u8, stride: usize);
237237
#[link_name = "llvm.x86.tilerelease"]
238238
fn tilerelease();
239239
#[link_name = "llvm.x86.tilestored64"]
240-
fn tilestored64(dst: i8, base: *mut i8, stride: usize);
240+
fn tilestored64(dst: i8, base: *mut u8, stride: usize);
241241
#[link_name = "llvm.x86.tilezero"]
242242
fn tilezero(dst: i8);
243243
#[link_name = "llvm.x86.tdpbf16ps"]
@@ -267,6 +267,47 @@ mod tests {
267267
#[cfg(target_os = "linux")]
268268
use syscalls::{syscall, Sysno};
269269

270+
#[allow(non_camel_case_types)]
271+
#[repr(packed)]
272+
#[derive(Copy, Clone, Default, Debug, PartialEq)]
273+
struct __tilecfg {
274+
/// 0 `or` 1
275+
palette: u8,
276+
start_row: u8,
277+
/// reserved, must be zero
278+
reserved_a0: [u8; 14],
279+
/// number of bytes of one row in each tile
280+
colsb: [u16; 8],
281+
/// reserved, must be zero
282+
reserved_b0: [u16; 8],
283+
/// number of rows in each tile
284+
rows: [u8; 8],
285+
/// reserved, must be zero
286+
reserved_c0: [u8; 8],
287+
}
288+
289+
impl __tilecfg {
290+
fn new(palette: u8, start_row: u8, colsb: [u16; 8], rows: [u8; 8]) -> Self {
291+
Self {
292+
palette,
293+
start_row,
294+
reserved_a0: [0u8; 14],
295+
colsb,
296+
reserved_b0: [0u16; 8],
297+
rows,
298+
reserved_c0: [0u8; 8],
299+
}
300+
}
301+
302+
const fn as_ptr(&self) -> *const u8 {
303+
self as *const Self as *const u8
304+
}
305+
306+
fn as_mut_ptr(&mut self) -> *mut u8 {
307+
self as *mut Self as *mut u8
308+
}
309+
}
310+
270311
#[cfg(not(target_os = "linux"))]
271312
#[target_feature(enable = "amx-tile")]
272313
fn _init_amx() {}
@@ -324,7 +365,7 @@ mod tests {
324365
_tile_loadconfig(config.as_ptr());
325366
_tile_zero::<0>();
326367
let mut out = [[1_i8; 64]; 16];
327-
_tile_stored::<0>(&mut out as *mut [i8; 64] as *mut i8, 64);
368+
_tile_stored::<0>(&mut out as *mut [i8; 64] as *mut u8, 64);
328369
_tile_release();
329370
assert_eq!(out, [[0; 64]; 16]);
330371
}
@@ -339,7 +380,7 @@ mod tests {
339380
_tile_loadconfig(config.as_ptr());
340381
_tile_zero::<0>();
341382
let mut out = [[1_i8; 64]; 16];
342-
_tile_stored::<0>(&mut out as *mut [i8; 64] as *mut i8, 64);
383+
_tile_stored::<0>(&mut out as *mut [i8; 64] as *mut u8, 64);
343384
_tile_release();
344385
assert_eq!(out, [[0; 64]; 16]);
345386
}
@@ -354,9 +395,9 @@ mod tests {
354395
_tile_loadconfig(config.as_ptr());
355396
_tile_zero::<0>();
356397
let mat = [1_i8; 1024];
357-
_tile_loadd::<0>(&mat as *const i8, 64);
398+
_tile_loadd::<0>(&mat as *const i8 as *const u8, 64);
358399
let mut out = [[0_i8; 64]; 16];
359-
_tile_stored::<0>(&mut out as *mut [i8; 64] as *mut i8, 64);
400+
_tile_stored::<0>(&mut out as *mut [i8; 64] as *mut u8, 64);
360401
_tile_release();
361402
assert_eq!(out, [[1; 64]; 16]);
362403
}
@@ -371,9 +412,9 @@ mod tests {
371412
_tile_loadconfig(config.as_ptr());
372413
_tile_zero::<0>();
373414
let mat = [1_i8; 1024];
374-
_tile_stream_loadd::<0>(&mat as *const i8, 64);
415+
_tile_stream_loadd::<0>(&mat as *const i8 as *const u8, 64);
375416
let mut out = [[0_i8; 64]; 16];
376-
_tile_stored::<0>(&mut out as *mut [i8; 64] as *mut i8, 64);
417+
_tile_stored::<0>(&mut out as *mut [i8; 64] as *mut u8, 64);
377418
_tile_release();
378419
assert_eq!(out, [[1; 64]; 16]);
379420
}
@@ -388,8 +429,8 @@ mod tests {
388429
_init_amx();
389430
let bf16_1: u16 = _mm_cvtness_sbh(1.0).to_bits();
390431
let bf16_2: u16 = _mm_cvtness_sbh(2.0).to_bits();
391-
let ones: [i8; 1024] = transmute([bf16_1; 512]);
392-
let twos: [i8; 1024] = transmute([bf16_2; 512]);
432+
let ones: [u8; 1024] = transmute([bf16_1; 512]);
433+
let twos: [u8; 1024] = transmute([bf16_2; 512]);
393434
let mut res = [[0f32; 16]; 16];
394435
let mut config = __tilecfg::default();
395436
config.palette = 1;
@@ -399,10 +440,10 @@ mod tests {
399440
});
400441
_tile_loadconfig(config.as_ptr());
401442
_tile_zero::<0>();
402-
_tile_loadd::<1>(&ones as *const i8, 64);
403-
_tile_loadd::<2>(&twos as *const i8, 64);
443+
_tile_loadd::<1>(&ones as *const u8, 64);
444+
_tile_loadd::<2>(&twos as *const u8, 64);
404445
_tile_dpbf16ps::<0, 1, 2>();
405-
_tile_stored::<0>(&mut res as *mut [f32; 16] as *mut i8, 64);
446+
_tile_stored::<0>(&mut res as *mut [f32; 16] as *mut u8, 64);
406447
_tile_release();
407448
assert_eq!(res, [[64f32; 16]; 16]);
408449
}
@@ -421,10 +462,10 @@ mod tests {
421462
});
422463
_tile_loadconfig(config.as_ptr());
423464
_tile_zero::<0>();
424-
_tile_loadd::<1>(&ones as *const i8, 64);
425-
_tile_loadd::<2>(&twos as *const i8, 64);
465+
_tile_loadd::<1>(&ones as *const i8 as *const u8, 64);
466+
_tile_loadd::<2>(&twos as *const i8 as *const u8, 64);
426467
_tile_dpbssd::<0, 1, 2>();
427-
_tile_stored::<0>(&mut res as *mut [i32; 16] as *mut i8, 64);
468+
_tile_stored::<0>(&mut res as *mut [i32; 16] as *mut u8, 64);
428469
_tile_release();
429470
assert_eq!(res, [[128_i32; 16]; 16]);
430471
}
@@ -443,10 +484,10 @@ mod tests {
443484
});
444485
_tile_loadconfig(config.as_ptr());
445486
_tile_zero::<0>();
446-
_tile_loadd::<1>(&ones as *const i8, 64);
447-
_tile_loadd::<2>(&twos as *const u8 as *const i8, 64);
487+
_tile_loadd::<1>(&ones as *const i8 as *const u8, 64);
488+
_tile_loadd::<2>(&twos as *const u8, 64);
448489
_tile_dpbsud::<0, 1, 2>();
449-
_tile_stored::<0>(&mut res as *mut [i32; 16] as *mut i8, 64);
490+
_tile_stored::<0>(&mut res as *mut [i32; 16] as *mut u8, 64);
450491
_tile_release();
451492
assert_eq!(res, [[-128_i32; 16]; 16]);
452493
}
@@ -465,10 +506,10 @@ mod tests {
465506
});
466507
_tile_loadconfig(config.as_ptr());
467508
_tile_zero::<0>();
468-
_tile_loadd::<1>(&ones as *const u8 as *const i8, 64);
469-
_tile_loadd::<2>(&twos as *const i8, 64);
509+
_tile_loadd::<1>(&ones as *const u8, 64);
510+
_tile_loadd::<2>(&twos as *const i8 as *const u8, 64);
470511
_tile_dpbusd::<0, 1, 2>();
471-
_tile_stored::<0>(&mut res as *mut [i32; 16] as *mut i8, 64);
512+
_tile_stored::<0>(&mut res as *mut [i32; 16] as *mut u8, 64);
472513
_tile_release();
473514
assert_eq!(res, [[-128_i32; 16]; 16]);
474515
}
@@ -487,10 +528,10 @@ mod tests {
487528
});
488529
_tile_loadconfig(config.as_ptr());
489530
_tile_zero::<0>();
490-
_tile_loadd::<1>(&ones as *const u8 as *const i8, 64);
491-
_tile_loadd::<2>(&twos as *const u8 as *const i8, 64);
531+
_tile_loadd::<1>(&ones as *const u8, 64);
532+
_tile_loadd::<2>(&twos as *const u8, 64);
492533
_tile_dpbuud::<0, 1, 2>();
493-
_tile_stored::<0>(&mut res as *mut [i32; 16] as *mut i8, 64);
534+
_tile_stored::<0>(&mut res as *mut [i32; 16] as *mut u8, 64);
494535
_tile_release();
495536
assert_eq!(res, [[128_i32; 16]; 16]);
496537
}
@@ -509,10 +550,10 @@ mod tests {
509550
});
510551
_tile_loadconfig(config.as_ptr());
511552
_tile_zero::<0>();
512-
_tile_loadd::<1>(&ones as *const f16 as *const i8, 64);
513-
_tile_loadd::<2>(&twos as *const f16 as *const i8, 64);
553+
_tile_loadd::<1>(&ones as *const f16 as *const u8, 64);
554+
_tile_loadd::<2>(&twos as *const f16 as *const u8, 64);
514555
_tile_dpfp16ps::<0, 1, 2>();
515-
_tile_stored::<0>(&mut res as *mut [f32; 16] as *mut i8, 64);
556+
_tile_stored::<0>(&mut res as *mut [f32; 16] as *mut u8, 64);
516557
_tile_release();
517558
assert_eq!(res, [[64f32; 16]; 16]);
518559
}
@@ -531,10 +572,10 @@ mod tests {
531572
});
532573
_tile_loadconfig(config.as_ptr());
533574
_tile_zero::<0>();
534-
_tile_loadd::<1>(&ones as *const f16 as *const i8, 64);
535-
_tile_loadd::<2>(&twos as *const f16 as *const i8, 64);
575+
_tile_loadd::<1>(&ones as *const f16 as *const u8, 64);
576+
_tile_loadd::<2>(&twos as *const f16 as *const u8, 64);
536577
_tile_cmmimfp16ps::<0, 1, 2>();
537-
_tile_stored::<0>(&mut res as *mut [f32; 16] as *mut i8, 64);
578+
_tile_stored::<0>(&mut res as *mut [f32; 16] as *mut u8, 64);
538579
_tile_release();
539580
assert_eq!(res, [[64f32; 16]; 16]);
540581
}
@@ -553,10 +594,10 @@ mod tests {
553594
});
554595
_tile_loadconfig(config.as_ptr());
555596
_tile_zero::<0>();
556-
_tile_loadd::<1>(&ones as *const f16 as *const i8, 64);
557-
_tile_loadd::<2>(&twos as *const f16 as *const i8, 64);
597+
_tile_loadd::<1>(&ones as *const f16 as *const u8, 64);
598+
_tile_loadd::<2>(&twos as *const f16 as *const u8, 64);
558599
_tile_cmmrlfp16ps::<0, 1, 2>();
559-
_tile_stored::<0>(&mut res as *mut [f32; 16] as *mut i8, 64);
600+
_tile_stored::<0>(&mut res as *mut [f32; 16] as *mut u8, 64);
560601
_tile_release();
561602
assert_eq!(res, [[0f32; 16]; 16]);
562603
}

crates/core_arch/src/x86_64/mod.rs

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -3,49 +3,6 @@
33
#[macro_use]
44
mod macros;
55

6-
#[unstable(feature = "x86_amx_intrinsics", issue = "126622")]
7-
#[allow(non_camel_case_types)]
8-
#[repr(packed)]
9-
#[derive(Copy, Clone, Default, Debug, PartialEq)]
10-
pub struct __tilecfg {
11-
/// 0 `or` 1
12-
pub palette: u8,
13-
pub start_row: u8,
14-
/// reserved, must be zero
15-
reserved_a0: [u8; 14],
16-
/// number of bytes of one row in each tile
17-
pub colsb: [u16; 8],
18-
/// reserved, must be zero
19-
reserved_b0: [u16; 8],
20-
/// number of rows in each tile
21-
pub rows: [u8; 8],
22-
/// reserved, must be zero
23-
reserved_c0: [u8; 8],
24-
}
25-
26-
#[unstable(feature = "x86_amx_intrinsics", issue = "126622")]
27-
impl __tilecfg {
28-
pub fn new(palette: u8, start_row: u8, colsb: [u16; 8], rows: [u8; 8]) -> Self {
29-
Self {
30-
palette,
31-
start_row,
32-
reserved_a0: [0u8; 14],
33-
colsb,
34-
reserved_b0: [0u16; 8],
35-
rows,
36-
reserved_c0: [0u8; 8],
37-
}
38-
}
39-
40-
pub const fn as_ptr(&self) -> *const i8 {
41-
self as *const Self as *const i8
42-
}
43-
44-
pub fn as_mut_ptr(&mut self) -> *mut i8 {
45-
self as *mut Self as *mut i8
46-
}
47-
}
48-
496
mod fxsr;
507
#[stable(feature = "simd_x86", since = "1.27.0")]
518
pub use self::fxsr::*;

0 commit comments

Comments
 (0)