Optimized division operation to shift operation
Subsystems (2)
PATCH 1/1 Optimized division operation to shift operation
On some processors, the / operate will call the compiler`s div lib, which is low efficient, We can replace the / operation with shift, so that we can replace the call of the division library with one shift assembly instruction.
--- drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c | 4 ++-- drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c | 4 ++-- drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-)
drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c +2 -2
@@ -175,10 +175,10 @@ static int gmc_v6_0_mc_load_microcode(struct amdgpu_device *adev)amdgpu_ucode_print_mc_hdr (&hdr->header); adev->gmc.fw_version =le32_to_cpu (hdr->header.ucode_version); - regs_size =le32_to_cpu (hdr->io_debug_size_bytes) / (4 *2 ); + regs_size =le32_to_cpu (hdr->io_debug_size_bytes) >>3 ; new_io_mc_regs = (const __le32 *) (adev->gmc.fw->data +le32_to_cpu (hdr->io_debug_array_offset_bytes)); - ucode_size =le32_to_cpu (hdr->header.ucode_size_bytes) /4 ; + ucode_size =le32_to_cpu (hdr->header.ucode_size_bytes) >>2 ; new_fw_data = (const __le32 *) (adev->gmc.fw->data +le32_to_cpu (hdr->header.ucode_array_offset_bytes));
drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c +2 -2
@@ -193,10 +193,10 @@ static int gmc_v7_0_mc_load_microcode(struct amdgpu_device *adev)amdgpu_ucode_print_mc_hdr (&hdr->header); adev->gmc.fw_version =le32_to_cpu (hdr->header.ucode_version); - regs_size =le32_to_cpu (hdr->io_debug_size_bytes) / (4 *2 ); + regs_size =le32_to_cpu (hdr->io_debug_size_bytes) >>3 ; io_mc_regs = (const __le32 *) (adev->gmc.fw->data +le32_to_cpu (hdr->io_debug_array_offset_bytes)); - ucode_size =le32_to_cpu (hdr->header.ucode_size_bytes) /4 ; + ucode_size =le32_to_cpu (hdr->header.ucode_size_bytes) >>2 ; fw_data = (const __le32 *) (adev->gmc.fw->data +le32_to_cpu (hdr->header.ucode_array_offset_bytes));
drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c +2 -2
@@ -318,10 +318,10 @@ static int gmc_v8_0_tonga_mc_load_microcode(struct amdgpu_device *adev)amdgpu_ucode_print_mc_hdr (&hdr->header); adev->gmc.fw_version =le32_to_cpu (hdr->header.ucode_version); - regs_size =le32_to_cpu (hdr->io_debug_size_bytes) / (4 *2 ); + regs_size =le32_to_cpu (hdr->io_debug_size_bytes) >>3 ; io_mc_regs = (const __le32 *) (adev->gmc.fw->data +le32_to_cpu (hdr->io_debug_array_offset_bytes)); - ucode_size =le32_to_cpu (hdr->header.ucode_size_bytes) /4 ; + ucode_size =le32_to_cpu (hdr->header.ucode_size_bytes) >>2 ; fw_data = (const __le32 *) (adev->gmc.fw->data +le32_to_cpu (hdr->header.ucode_array_offset_bytes));
Signature · 1 line
2.7.4
Alex Deucher
AppliedQuoted 7 lines · Bernard Zhao
On some processors, the / operate will call the compiler`s div lib, which is low efficient, We can replace the / operation with shift, so that we can replace the call of the division library with one shift assembly instruction.
Signed-off-by Bernard Zhao <[email protected]>
Applied. thanks.
Alex
Quoted 60 lines
--- drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c | 4 ++-- drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c | 4 ++-- drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-)drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c +2
-2@@ -175,10 +175,10 @@ static int gmc_v6_0_mc_load_microcode(struct amdgpu_device *adev)amdgpu_ucode_print_mc_hdr (&hdr->header); adev->gmc.fw_version =le32_to_cpu (hdr->header.ucode_version); - regs_size =le32_to_cpu (hdr->io_debug_size_bytes) / (4 *2 ); + regs_size =le32_to_cpu (hdr->io_debug_size_bytes) >>3 ; new_io_mc_regs = (const __le32 *) (adev->gmc.fw->data +le32_to_cpu (hdr->io_debug_array_offset_bytes)); - ucode_size =le32_to_cpu (hdr->header.ucode_size_bytes) /4 ; + ucode_size =le32_to_cpu (hdr->header.ucode_size_bytes) >>2 ; new_fw_data = (const __le32 *) (adev->gmc.fw->data +le32_to_cpu (hdr->header.ucode_array_offset_bytes));drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c +2
-2@@ -193,10 +193,10 @@ static int gmc_v7_0_mc_load_microcode(struct amdgpu_device *adev)amdgpu_ucode_print_mc_hdr (&hdr->header); adev->gmc.fw_version =le32_to_cpu (hdr->header.ucode_version); - regs_size =le32_to_cpu (hdr->io_debug_size_bytes) / (4 *2 ); + regs_size =le32_to_cpu (hdr->io_debug_size_bytes) >>3 ; io_mc_regs = (const __le32 *) (adev->gmc.fw->data +le32_to_cpu (hdr->io_debug_array_offset_bytes)); - ucode_size =le32_to_cpu (hdr->header.ucode_size_bytes) /4 ; + ucode_size =le32_to_cpu (hdr->header.ucode_size_bytes) >>2 ; fw_data = (const __le32 *) (adev->gmc.fw->data +le32_to_cpu (hdr->header.ucode_array_offset_bytes));drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c +2
-3@@ -318,10 +318,10 @@ static int gmc_v8_0_tonga_mc_load_microcode(struct amdgpu_device *adev)amdgpu_ucode_print_mc_hdr (&hdr->header); adev->gmc.fw_version =le32_to_cpu (hdr->header.ucode_version); - regs_size =le32_to_cpu (hdr->io_debug_size_bytes) / (4 *2 ); + regs_size =le32_to_cpu (hdr->io_debug_size_bytes) >>3 ; io_mc_regs = (const __le32 *) (adev->gmc.fw->data +le32_to_cpu (hdr->io_debug_array_offset_bytes)); - ucode_size =le32_to_cpu (hdr->header.ucode_size_bytes) /4 ; + ucode_size =le32_to_cpu (hdr->header.ucode_size_bytes) >>2 ; fw_data = (const __le32 *) (adev->gmc.fw->data +le32_to_cpu (hdr->header.ucode_array_offset_bytes)); --2.7.4
Quoted 4 lines
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Quoted 6 lines · Alex Deucher
Quoted 5 lines · Bernard Zhao
On some processors, the / operate will call the compiler`s div lib, which is low efficient, We can replace the / operation with shift, so that we can replace the call of the division library with one shift assembly instruction.
This was applied already, and it's not in a driver I look after... but to me this feels like something that really should be justified. Using >> instead of / for multiples of 2 division mattered 20 years ago, I'd be surprised if it still did on modern compilers.
BR,
Jani.
Quoted 75 lines
Quoted 2 lines
Signed-off-by Bernard Zhao <[email protected]>Applied. thanks.
Alex
Quoted 60 lines
--- drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c | 4 ++-- drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c | 4 ++-- drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-)drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c +2
-2@@ -175,10 +175,10 @@ static int gmc_v6_0_mc_load_microcode(struct amdgpu_device *adev)amdgpu_ucode_print_mc_hdr (&hdr->header); adev->gmc.fw_version =le32_to_cpu (hdr->header.ucode_version); - regs_size =le32_to_cpu (hdr->io_debug_size_bytes) / (4 *2 ); + regs_size =le32_to_cpu (hdr->io_debug_size_bytes) >>3 ; new_io_mc_regs = (const __le32 *) (adev->gmc.fw->data +le32_to_cpu (hdr->io_debug_array_offset_bytes)); - ucode_size =le32_to_cpu (hdr->header.ucode_size_bytes) /4 ; + ucode_size =le32_to_cpu (hdr->header.ucode_size_bytes) >>2 ; new_fw_data = (const __le32 *) (adev->gmc.fw->data +le32_to_cpu (hdr->header.ucode_array_offset_bytes));drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c +2
-2@@ -193,10 +193,10 @@ static int gmc_v7_0_mc_load_microcode(struct amdgpu_device *adev)amdgpu_ucode_print_mc_hdr (&hdr->header); adev->gmc.fw_version =le32_to_cpu (hdr->header.ucode_version); - regs_size =le32_to_cpu (hdr->io_debug_size_bytes) / (4 *2 ); + regs_size =le32_to_cpu (hdr->io_debug_size_bytes) >>3 ; io_mc_regs = (const __le32 *) (adev->gmc.fw->data +le32_to_cpu (hdr->io_debug_array_offset_bytes)); - ucode_size =le32_to_cpu (hdr->header.ucode_size_bytes) /4 ; + ucode_size =le32_to_cpu (hdr->header.ucode_size_bytes) >>2 ; fw_data = (const __le32 *) (adev->gmc.fw->data +le32_to_cpu (hdr->header.ucode_array_offset_bytes));drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c +2
-3@@ -318,10 +318,10 @@ static int gmc_v8_0_tonga_mc_load_microcode(struct amdgpu_device *adev)amdgpu_ucode_print_mc_hdr (&hdr->header); adev->gmc.fw_version =le32_to_cpu (hdr->header.ucode_version); - regs_size =le32_to_cpu (hdr->io_debug_size_bytes) / (4 *2 ); + regs_size =le32_to_cpu (hdr->io_debug_size_bytes) >>3 ; io_mc_regs = (const __le32 *) (adev->gmc.fw->data +le32_to_cpu (hdr->io_debug_array_offset_bytes)); - ucode_size =le32_to_cpu (hdr->header.ucode_size_bytes) /4 ; + ucode_size =le32_to_cpu (hdr->header.ucode_size_bytes) >>2 ; fw_data = (const __le32 *) (adev->gmc.fw->data +le32_to_cpu (hdr->header.ucode_array_offset_bytes)); --2.7.4
Quoted 4 lines
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Signature · 1 line
Jani Nikula, Intel Open Source Graphics Center
Christian König
maintainerAm 15.04.20 um 09:41 schrieb Jani Nikula:
Quoted 10 lines · Alex Deucher
Quoted 5 lines · Bernard Zhao
Quoted 4 lines
On some processors, the / operate will call the compiler`s div lib, which is low efficient, We can replace the / operation with shift, so that we can replace the call of the division library with one shift assembly instruction.
This was applied already, and it's not in a driver I look after... but to me this feels like something that really should be justified. Using >> instead of / for multiples of 2 division mattered 20 years ago, I'd be surprised if it still did on modern compilers.
I have similar worries, especially since we replace the "/ (4 * 2)" with ">> 3" it's making the code just a bit less readable.
And that the code runs exactly once while loading the driver and pushing the firmware into the hardware. So performance is completely irrelevant here.
Regards,
Christian.
Quoted 78 lines
BR,
Jani.Quoted 73 lines
Quoted 1 line
Signed-off-by Bernard Zhao <[email protected]>Applied. thanks.
Alex
Quoted 60 lines
--- drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c | 4 ++-- drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c | 4 ++-- drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-)drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c +2
-2@@ -175,10 +175,10 @@ static int gmc_v6_0_mc_load_microcode(struct amdgpu_device *adev)amdgpu_ucode_print_mc_hdr (&hdr->header); adev->gmc.fw_version =le32_to_cpu (hdr->header.ucode_version); - regs_size =le32_to_cpu (hdr->io_debug_size_bytes) / (4 *2 ); + regs_size =le32_to_cpu (hdr->io_debug_size_bytes) >>3 ; new_io_mc_regs = (const __le32 *) (adev->gmc.fw->data +le32_to_cpu (hdr->io_debug_array_offset_bytes)); - ucode_size =le32_to_cpu (hdr->header.ucode_size_bytes) /4 ; + ucode_size =le32_to_cpu (hdr->header.ucode_size_bytes) >>2 ; new_fw_data = (const __le32 *) (adev->gmc.fw->data +le32_to_cpu (hdr->header.ucode_array_offset_bytes));drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c +2
-2@@ -193,10 +193,10 @@ static int gmc_v7_0_mc_load_microcode(struct amdgpu_device *adev)amdgpu_ucode_print_mc_hdr (&hdr->header); adev->gmc.fw_version =le32_to_cpu (hdr->header.ucode_version); - regs_size =le32_to_cpu (hdr->io_debug_size_bytes) / (4 *2 ); + regs_size =le32_to_cpu (hdr->io_debug_size_bytes) >>3 ; io_mc_regs = (const __le32 *) (adev->gmc.fw->data +le32_to_cpu (hdr->io_debug_array_offset_bytes)); - ucode_size =le32_to_cpu (hdr->header.ucode_size_bytes) /4 ; + ucode_size =le32_to_cpu (hdr->header.ucode_size_bytes) >>2 ; fw_data = (const __le32 *) (adev->gmc.fw->data +le32_to_cpu (hdr->header.ucode_array_offset_bytes));drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c +2
-3@@ -318,10 +318,10 @@ static int gmc_v8_0_tonga_mc_load_microcode(struct amdgpu_device *adev)amdgpu_ucode_print_mc_hdr (&hdr->header); adev->gmc.fw_version =le32_to_cpu (hdr->header.ucode_version); - regs_size =le32_to_cpu (hdr->io_debug_size_bytes) / (4 *2 ); + regs_size =le32_to_cpu (hdr->io_debug_size_bytes) >>3 ; io_mc_regs = (const __le32 *) (adev->gmc.fw->data +le32_to_cpu (hdr->io_debug_array_offset_bytes)); - ucode_size =le32_to_cpu (hdr->header.ucode_size_bytes) /4 ; + ucode_size =le32_to_cpu (hdr->header.ucode_size_bytes) >>2 ; fw_data = (const __le32 *) (adev->gmc.fw->data +le32_to_cpu (hdr->header.ucode_array_offset_bytes)); --2.7.4
Quoted 4 lines
_______________________________________________
amd-gfx mailing list
[email protected]
https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.freedesktop.org%2Fmailman%2Flistinfo%2Famd-gfx&data=02%7C01%7Cchristian.koenig%40amd.com%7C1e91f7edcfe0473b0d7008d7e11074a8%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637225333103893889&sdata=VDJlEY2%2Bl1SSO8Fw1dYqqPFqQtyHpsxQ0Tm7iVOgJQY%3D&reserved=0_______________________________________________
dri-devel mailing list
[email protected]
https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.freedesktop.org%2Fmailman%2Flistinfo%2Fdri-devel&data=02%7C01%7Cchristian.koenig%40amd.com%7C1e91f7edcfe0473b0d7008d7e11074a8%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637225333103893889&sdata=EpqRRbCiksur%2BjMlVQplExuJsmw6UPODhyBOutOVukw%3D&reserved=0
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Quoted 13 lines · Christian König
Am 15.04.20 um 09:41 schrieb Jani Nikula:
Quoted 10 lines · Alex Deucher
Quoted 5 lines · Bernard Zhao
Quoted 4 lines
On some processors, the / operate will call the compiler`s div lib, which is low efficient, We can replace the / operation with shift, so that we can replace the call of the division library with one shift assembly instruction.
This was applied already, and it's not in a driver I look after... but to me this feels like something that really should be justified. Using >> instead of / for multiples of 2 division mattered 20 years ago, I'd be surprised if it still did on modern compilers.
Quoted 6 lines
I have similar worries, especially since we replace the "/ (4 * 2)" with ">> 3" it's making the code just a bit less readable.
And that the code runs exactly once while loading the driver and pushing the firmware into the hardware. So performance is completely irrelevant here.
Yeah, and even in general I'd really want to see proof that such bad compilers exist first. Doing a peephole pass for stuff like this is like undergrad compiler course stuff. Also I'd trust the compiler's call on which is faster much more than humans doing a manual peephole pass.
Or am I just massively biased from all the layman following of what kind of our gl/vk/compute compiler people are doing on a daily basis? -Daniel
Quoted 87 lines
Regards,
Christian.Quoted 78 lines
BR,
Jani.Quoted 73 lines
Quoted 1 line
Signed-off-by Bernard Zhao <[email protected]>Applied. thanks.
Alex
Quoted 60 lines
--- drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c | 4 ++-- drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c | 4 ++-- drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-)drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c +2
-2@@ -175,10 +175,10 @@ static int gmc_v6_0_mc_load_microcode(struct amdgpu_device *adev)amdgpu_ucode_print_mc_hdr (&hdr->header); adev->gmc.fw_version =le32_to_cpu (hdr->header.ucode_version); - regs_size =le32_to_cpu (hdr->io_debug_size_bytes) / (4 *2 ); + regs_size =le32_to_cpu (hdr->io_debug_size_bytes) >>3 ; new_io_mc_regs = (const __le32 *) (adev->gmc.fw->data +le32_to_cpu (hdr->io_debug_array_offset_bytes)); - ucode_size =le32_to_cpu (hdr->header.ucode_size_bytes) /4 ; + ucode_size =le32_to_cpu (hdr->header.ucode_size_bytes) >>2 ; new_fw_data = (const __le32 *) (adev->gmc.fw->data +le32_to_cpu (hdr->header.ucode_array_offset_bytes));drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c +2
-2@@ -193,10 +193,10 @@ static int gmc_v7_0_mc_load_microcode(struct amdgpu_device *adev)amdgpu_ucode_print_mc_hdr (&hdr->header); adev->gmc.fw_version =le32_to_cpu (hdr->header.ucode_version); - regs_size =le32_to_cpu (hdr->io_debug_size_bytes) / (4 *2 ); + regs_size =le32_to_cpu (hdr->io_debug_size_bytes) >>3 ; io_mc_regs = (const __le32 *) (adev->gmc.fw->data +le32_to_cpu (hdr->io_debug_array_offset_bytes)); - ucode_size =le32_to_cpu (hdr->header.ucode_size_bytes) /4 ; + ucode_size =le32_to_cpu (hdr->header.ucode_size_bytes) >>2 ; fw_data = (const __le32 *) (adev->gmc.fw->data +le32_to_cpu (hdr->header.ucode_array_offset_bytes));drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c +2
-3@@ -318,10 +318,10 @@ static int gmc_v8_0_tonga_mc_load_microcode(struct amdgpu_device *adev)amdgpu_ucode_print_mc_hdr (&hdr->header); adev->gmc.fw_version =le32_to_cpu (hdr->header.ucode_version); - regs_size =le32_to_cpu (hdr->io_debug_size_bytes) / (4 *2 ); + regs_size =le32_to_cpu (hdr->io_debug_size_bytes) >>3 ; io_mc_regs = (const __le32 *) (adev->gmc.fw->data +le32_to_cpu (hdr->io_debug_array_offset_bytes)); - ucode_size =le32_to_cpu (hdr->header.ucode_size_bytes) /4 ; + ucode_size =le32_to_cpu (hdr->header.ucode_size_bytes) >>2 ; fw_data = (const __le32 *) (adev->gmc.fw->data +le32_to_cpu (hdr->header.ucode_array_offset_bytes)); --2.7.4
Quoted 4 lines
_______________________________________________
amd-gfx mailing list
[email protected]
https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.freedesktop.org%2Fmailman%2Flistinfo%2Famd-gfx&data=02%7C01%7Cchristian.koenig%40amd.com%7C1e91f7edcfe0473b0d7008d7e11074a8%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637225333103893889&sdata=VDJlEY2%2Bl1SSO8Fw1dYqqPFqQtyHpsxQ0Tm7iVOgJQY%3D&reserved=0_______________________________________________
dri-devel mailing list
[email protected]
https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.freedesktop.org%2Fmailman%2Flistinfo%2Fdri-devel&data=02%7C01%7Cchristian.koenig%40amd.com%7C1e91f7edcfe0473b0d7008d7e11074a8%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637225333103893889&sdata=EpqRRbCiksur%2BjMlVQplExuJsmw6UPODhyBOutOVukw%3D&reserved=0_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Signature · 7 lines
Daniel Vetter Software Engineer, Intel Corporation +41 (0) 79 365 57 48 - http://blog.ffwll.ch _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
From: Christian König
Quoted 13 lines
Sent: 15 April 2020 08:57
Am 15.04.20 um 09:41 schrieb Jani Nikula:Quoted 10 lines · Alex Deucher
Quoted 5 lines · Bernard Zhao
Quoted 4 lines
On some processors, the / operate will call the compiler`s div lib, which is low efficient, We can replace the / operation with shift, so that we can replace the call of the division library with one shift assembly instruction.
This was applied already, and it's not in a driver I look after... but to me this feels like something that really should be justified. Using >> instead of / for multiples of 2 division mattered 20 years ago, I'd be surprised if it still did on modern compilers.
Quoted 6 lines
I have similar worries, especially since we replace the "/ (4 * 2)" with ">> 3" it's making the code just a bit less readable.
And that the code runs exactly once while loading the driver and pushing the firmware into the hardware. So performance is completely irrelevant here.
Force the division to be unsigned and the compiler will use a shift.
David
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)
Deucher, Alexander
maintainer[AMD Public Use]
I've gone ahead and dropped the patch.
Alex
________________________________
From: Koenig, Christian <[email protected]>
Sent: Wednesday, April 15, 2020 3:57 AM
To: Jani Nikula <[email protected]>; Alex Deucher <[email protected]>; Bernard Zhao <[email protected]>
Cc: Sierra Guiza, Alejandro (Alex) <[email protected]>; Zeng, Oak <[email protected]>; Maling list - DRI developers <[email protected]>; David Airlie <[email protected]>; Kuehling, Felix <[email protected]>; LKML <[email protected]>; amd-gfx list <[email protected]>; [email protected] <[email protected]>; Huang, Ray <[email protected]>; Russell, Kent <[email protected]>; Deucher, Alexander <[email protected]>; Sam Ravnborg <[email protected]>; Yuan, Xiaojie <[email protected]>
Subject: Re: [PATCH] Optimized division operation to shift operation
Am 15.04.20 um 09:41 schrieb Jani Nikula:
Quoted 10 lines · Alex Deucher
Quoted 5 lines · Bernard Zhao
Quoted 4 lines
On some processors, the / operate will call the compiler`s div lib, which is low efficient, We can replace the / operation with shift, so that we can replace the call of the division library with one shift assembly instruction.
This was applied already, and it's not in a driver I look after... but to me this feels like something that really should be justified. Using >> instead of / for multiples of 2 division mattered 20 years ago, I'd be surprised if it still did on modern compilers.
I have similar worries, especially since we replace the "/ (4 * 2)" with ">> 3" it's making the code just a bit less readable.
And that the code runs exactly once while loading the driver and pushing the firmware into the hardware. So performance is completely irrelevant here.
Regards,
Christian.
Quoted 78 lines
BR,
Jani.Quoted 73 lines
Quoted 1 line
Signed-off-by Bernard Zhao <[email protected]>Applied. thanks.
Alex
Quoted 60 lines
--- drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c | 4 ++-- drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c | 4 ++-- drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-)drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c +2
-2@@ -175,10 +175,10 @@ static int gmc_v6_0_mc_load_microcode(struct amdgpu_device *adev)amdgpu_ucode_print_mc_hdr (&hdr->header); adev->gmc.fw_version =le32_to_cpu (hdr->header.ucode_version); - regs_size =le32_to_cpu (hdr->io_debug_size_bytes) / (4 *2 ); + regs_size =le32_to_cpu (hdr->io_debug_size_bytes) >>3 ; new_io_mc_regs = (const __le32 *) (adev->gmc.fw->data +le32_to_cpu (hdr->io_debug_array_offset_bytes)); - ucode_size =le32_to_cpu (hdr->header.ucode_size_bytes) /4 ; + ucode_size =le32_to_cpu (hdr->header.ucode_size_bytes) >>2 ; new_fw_data = (const __le32 *) (adev->gmc.fw->data +le32_to_cpu (hdr->header.ucode_array_offset_bytes));drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c +2
-2@@ -193,10 +193,10 @@ static int gmc_v7_0_mc_load_microcode(struct amdgpu_device *adev)amdgpu_ucode_print_mc_hdr (&hdr->header); adev->gmc.fw_version =le32_to_cpu (hdr->header.ucode_version); - regs_size =le32_to_cpu (hdr->io_debug_size_bytes) / (4 *2 ); + regs_size =le32_to_cpu (hdr->io_debug_size_bytes) >>3 ; io_mc_regs = (const __le32 *) (adev->gmc.fw->data +le32_to_cpu (hdr->io_debug_array_offset_bytes)); - ucode_size =le32_to_cpu (hdr->header.ucode_size_bytes) /4 ; + ucode_size =le32_to_cpu (hdr->header.ucode_size_bytes) >>2 ; fw_data = (const __le32 *) (adev->gmc.fw->data +le32_to_cpu (hdr->header.ucode_array_offset_bytes));drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c +2
-3@@ -318,10 +318,10 @@ static int gmc_v8_0_tonga_mc_load_microcode(struct amdgpu_device *adev)amdgpu_ucode_print_mc_hdr (&hdr->header); adev->gmc.fw_version =le32_to_cpu (hdr->header.ucode_version); - regs_size =le32_to_cpu (hdr->io_debug_size_bytes) / (4 *2 ); + regs_size =le32_to_cpu (hdr->io_debug_size_bytes) >>3 ; io_mc_regs = (const __le32 *) (adev->gmc.fw->data +le32_to_cpu (hdr->io_debug_array_offset_bytes)); - ucode_size =le32_to_cpu (hdr->header.ucode_size_bytes) /4 ; + ucode_size =le32_to_cpu (hdr->header.ucode_size_bytes) >>2 ; fw_data = (const __le32 *) (adev->gmc.fw->data +le32_to_cpu (hdr->header.ucode_array_offset_bytes)); --2.7.4
Quoted 4 lines
_______________________________________________
amd-gfx mailing list
[email protected]
https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.freedesktop.org%2Fmailman%2Flistinfo%2Famd-gfx&data=02%7C01%7Cchristian.koenig%40amd.com%7C1e91f7edcfe0473b0d7008d7e11074a8%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637225333103893889&sdata=VDJlEY2%2Bl1SSO8Fw1dYqqPFqQtyHpsxQ0Tm7iVOgJQY%3D&reserved=0_______________________________________________
dri-devel mailing list
[email protected]
https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.freedesktop.org%2Fmailman%2Flistinfo%2Fdri-devel&data=02%7C01%7Cchristian.koenig%40amd.com%7C1e91f7edcfe0473b0d7008d7e11074a8%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637225333103893889&sdata=EpqRRbCiksur%2BjMlVQplExuJsmw6UPODhyBOutOVukw%3D&reserved=0
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx