Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[clang] Resolve FIXME in altivec.h #78905

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft

Conversation

AtariDreams
Copy link
Contributor

treat parameter as a 5-bit signed literal.

@llvmbot llvmbot added clang Clang issues not falling into any other category backend:X86 clang:headers Headers provided by Clang, e.g. for intrinsics labels Jan 21, 2024
@llvmbot
Copy link
Collaborator

llvmbot commented Jan 21, 2024

@llvm/pr-subscribers-backend-x86

@llvm/pr-subscribers-clang

Author: AtariDreams (AtariDreams)

Changes

treat parameter as a 5-bit signed literal.


Full diff: https://github.com/llvm/llvm-project/pull/78905.diff

1 Files Affected:

  • (modified) clang/lib/Headers/altivec.h (+34-30)
diff --git a/clang/lib/Headers/altivec.h b/clang/lib/Headers/altivec.h
index 4971631c50f412..8693ef61571d8c 100644
--- a/clang/lib/Headers/altivec.h
+++ b/clang/lib/Headers/altivec.h
@@ -10311,78 +10311,82 @@ static __inline__ vector float __ATTRS_o_ai vec_vspltw(vector float __a,
                                          b1, b2, b3, __b, b1, b2, b3));
 }
 
+typedef union {
+  struct {
+    signed int value:5; // 5-bit signed integer
+  } field;
+  signed char byte;
+} FiveBitSigned;
+
 /* vec_splat_s8 */
 
 #define __builtin_altivec_vspltisb vec_splat_s8
 
-// FIXME: parameter should be treated as 5-bit signed literal
 static __inline__ vector signed char __ATTRS_o_ai
 vec_splat_s8(signed char __a) {
-  return (vector signed char)(__a);
+  FiveBitSigned fbs;
+  fbs.byte = __a;
+  return (vector signed char)(fbs.field.value);
 }
 
 /* vec_vspltisb */
-
-// FIXME: parameter should be treated as 5-bit signed literal
 static __inline__ vector signed char __ATTRS_o_ai
 vec_vspltisb(signed char __a) {
-  return (vector signed char)(__a);
+  FiveBitSigned fbs;
+  fbs.byte = __a;
+  return (vector signed char)(fbs.field.value);
 }
 
 /* vec_splat_s16 */
-
-#define __builtin_altivec_vspltish vec_splat_s16
-
-// FIXME: parameter should be treated as 5-bit signed literal
 static __inline__ vector short __ATTRS_o_ai vec_splat_s16(signed char __a) {
-  return (vector short)(__a);
+  FiveBitSigned fbs;
+  fbs.byte = __a;
+  return (vector short)(fbs.field.value);
 }
 
 /* vec_vspltish */
-
-// FIXME: parameter should be treated as 5-bit signed literal
 static __inline__ vector short __ATTRS_o_ai vec_vspltish(signed char __a) {
-  return (vector short)(__a);
+  FiveBitSigned fbs;
+  fbs.byte = __a;
+  return (vector short)(fbs.field.value);
 }
 
 /* vec_splat_s32 */
-
-#define __builtin_altivec_vspltisw vec_splat_s32
-
-// FIXME: parameter should be treated as 5-bit signed literal
 static __inline__ vector int __ATTRS_o_ai vec_splat_s32(signed char __a) {
-  return (vector int)(__a);
+  FiveBitSigned fbs;
+  fbs.byte = __a;
+  return (vector int)(fbs.field.value);
 }
 
 /* vec_vspltisw */
-
-// FIXME: parameter should be treated as 5-bit signed literal
 static __inline__ vector int __ATTRS_o_ai vec_vspltisw(signed char __a) {
-  return (vector int)(__a);
+  FiveBitSigned fbs;
+  fbs.byte = __a;
+  return (vector int)(fbs.field.value);
 }
 
 /* vec_splat_u8 */
-
-// FIXME: parameter should be treated as 5-bit signed literal
 static __inline__ vector unsigned char __ATTRS_o_ai
 vec_splat_u8(unsigned char __a) {
-  return (vector unsigned char)(__a);
+  FiveBitSigned fbs;
+  fbs.byte = __a;
+  return (vector unsigned char)(fbs.field.value);
 }
 
 /* vec_splat_u16 */
-
-// FIXME: parameter should be treated as 5-bit signed literal
 static __inline__ vector unsigned short __ATTRS_o_ai
 vec_splat_u16(signed char __a) {
-  return (vector unsigned short)(__a);
+  FiveBitSigned fbs;
+  fbs.byte = __a;
+  return (vector unsigned short)(fbs.field.value);
 }
 
 /* vec_splat_u32 */
-
-// FIXME: parameter should be treated as 5-bit signed literal
 static __inline__ vector unsigned int __ATTRS_o_ai
 vec_splat_u32(signed char __a) {
-  return (vector unsigned int)(__a);
+  FiveBitSigned fbs;
+  fbs.byte = __a;
+  return (vector unsigned int)(fbs.field.value);
 }
 
 /* vec_sr */

treat parameter as a 5-bit signed literal.
@asl
Copy link
Collaborator

asl commented Jan 27, 2024

I do not thing this is a proper fix and that it actually improves anything. "Treat as signed 5-bit literal" means that:

  • Only allow literal parameters
  • Only allow integers that would fit into 5-bit signed immediate

@AtariDreams AtariDreams marked this pull request as draft March 25, 2024 01:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend:PowerPC backend:X86 clang:headers Headers provided by Clang, e.g. for intrinsics clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants